chiark / gitweb /
doc/sod.sty: Make spacing in `\lit' be more even.
[sod] / doc / sod.sty
CommitLineData
1f7d590d
MW
1%%% -*-latex-*-
2%%%
3%%% Styles and other hacking for the Sod manual
4%%%
5%%% (c) 2015 Straylight/Edgeware
6%%%
7
8%%%----- Licensing notice ---------------------------------------------------
9%%%
e0808c47 10%%% This file is part of the Sensible Object Design, an object system for C.
1f7d590d
MW
11%%%
12%%% SOD is free software; you can redistribute it and/or modify
13%%% it under the terms of the GNU General Public License as published by
14%%% the Free Software Foundation; either version 2 of the License, or
15%%% (at your option) any later version.
16%%%
17%%% SOD is distributed in the hope that it will be useful,
18%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
19%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20%%% GNU General Public License for more details.
21%%%
22%%% You should have received a copy of the GNU General Public License
23%%% along with SOD; if not, write to the Free Software Foundation,
24%%% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26\ProvidesPackage{sod}
27
28%% More reference types.
29\defxref{p}{part}
30
31%% Other languages with special typesetting.
32\def\Cplusplus{C\kern-\p@++}
33\def\Csharp{C\#}
34
35%% Special maths notation.
36\def\chain#1#2{\mathsf{ch}_{#1}(#2)}
37\def\chainhead#1#2{\mathsf{hd}_{#1}(#2)}
38\def\chaintail#1#2{\mathsf{tl}_{#1}(#2)}
39
40%% Other mathematical tweaks.
41\let\implies\Rightarrow
42\let\epsilon\varepsilon
43
2ba6e0bd
MW
44%% A table heading cell. Clone and hack \multicolumn.
45\def\thd{\omit\@ifnextchar[\thd@{\thd@[l]}}
46\def\thd@[#1]#2{%
47 \begingroup
48 \tab@multicol \tab@initread \let\tab@looped\tab@err@multi
49 \tab@preamble{}\def\tab@midtext{\bfseries#2}\tab@readpreamble{#1}%
50 \the\tab@preamble
51 \endgroup \ignorespaces
52}
53
1f7d590d
MW
54%% Unix manpage references.
55\def\man#1#2{\textbf{#1}(#2)}
56
57%% Listings don't need to be small.
58\let\listingsize\relax
59
60%% Metavariables are italics without decoration.
61\def\syntleft{\normalfont\itshape}
62\let\syntright\empty
63
64%% Literal code is in sans face.
5f1bbd61 65\def\codeface{\upshape\sffamily}
ddfe4265
MW
66\DeclareRobustCommand\code[1]{%
67 \ifmmode\hbox\else\leavevmode\fi%
68 {\normalfont\codeface\/#1\/}%
69}
1f7d590d
MW
70\def\ulitleft{\normalfont\codeface}
71\let\ulitright\empty
48ab1447 72\def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}}
1f7d590d
MW
73
74%% Conditionally enter maths mode. Can't use \ensuremath here because we
75%% aren't necessarily sure where the maths will actually end.
76\let\m@maybe@end\relax
77\def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
78
79%% Standard syntax shortcuts.
80\atdef <#1>{\synt{#1}\@scripts}
81\atdef "#1"{\lit*{#1}\@scripts}
82\atdef `#1'{\lit{#1}\@scripts}
5f1bbd61 83\atdef |#1|{\lit*{#1}\@scripts}
1f7d590d
MW
84
85%% A handy abbreviation; `\\' itself is too good to steal.
86\atdef \\{\textbackslash}
87
88%% Intercept grammar typesetting and replace the vertical bar with the
89%% maths-font version.
90\let\@@grammar\grammar
91\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
92
93%% Collect super- and subscripts. (Note that underscores are active for the
94%% most part.) When we're done, end maths mode if we entered it
95%% conditionally.
96\def\@scripts{\futurelet\@ch\@scripts@i}
97\begingroup\lccode`\~=`\_\lowercase{\endgroup
98\def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
99 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
100\def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
101
102%% Doubling characters, maybe. Either way, chain onto \@scripts.
103\def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
104\def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
105 \expandafter\@firstoftwo\expandafter\@scripts%
106 \else\@tempa\expandafter\@scripts\fi}
107
108%% Extra syntax for Lisp templates. These produce the maths-font versions of
109%% characters, which should contrast well against the sans face used for
110%% literals.
111\atdef [{\dbl@maybe[}
112\atdef ]{\dbl@maybe]}
113\atdef {{\m@maybe\{\@scripts}
114\atdef }{\m@maybe\}\@scripts}
115\atdef ({\m@maybe(\@scripts}
116\atdef ){\m@maybe)\@scripts}
117\atdef !{\m@maybe|\@scripts}
118\def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
119\atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
a5d80269 120\atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi}
1f7d590d
MW
121
122%% Comment setting.
888d5e58
MW
123\def\comment#1{\mbox{\normalfont\itshape\/#1\/}}
124\atdef /*#1*/{/*\comment{#1}*/}
125\def\@semis{\@ifnextchar;{;\@semis}\@semicomment}
126\def\@semicomment#1\\{\comment{#1}\\}
127\atdef ;#1\\{;\@semis}
1f7d590d
MW
128
129%% Environment for setting programs. Newlines are explicit, because
130%% otherwise I need comments in weird places to make the vertical spacing
131%% come out properly. You can write `\obeylines' if you really want to.
4effe575
MW
132\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
133\def\prog{\quote\@prog}
1f7d590d 134\def\endprog{\endtabbing\endquote}
4effe575
MW
135\let\nprog\@prog
136\let\endnprog\endtabbing
1f7d590d 137\def\ind{\quad\=\+\kill}
ebf5ae2e
MW
138\def\@progcr{\futurelet\@tempa\@progcr@i}
139{\def\:{\gdef\@progcr@sp}\: {\@progcr}}
ca8f5d55 140\atdef~{\textasciitilde}
ebf5ae2e
MW
141\def\@progcr@i{%
142 \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
143 \if1\ifx\@tempa[1\else
144 \ifx\@tempa*1\else
145 0\fi\fi
146 \let\next@\prog@@cr\else
147 \if1\ifx\@tempa+1\else
148 \ifx\@tempa-1\else
149 0\fi\fi
150 \let\next@\@progcr@ii\else
151 \let\next@\@progcr@a\fi\fi\fi
152 \next@}
153\def\@progcr@a{\prog@@cr*{}\ignorespaces}
154\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
155\@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
156\@namedef{@progcr@-}{\prog@@cr*[\jot]}
5e4a5d53 157\def\macsl{\`\textbackslash\hskip\leftmargin}
1f7d590d
MW
158
159%% Put a chunk of text in a box.
160\newenvironment{boxy}[1][\q@]{%
9eb66c6e 161 \savenotes
1f7d590d
MW
162 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
163 \medskip%
164 \vbox\bgroup\hrule\hbox\bgroup\vrule%
165 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
166 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
167}{%
168 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
169 \vrule\egroup\hrule\egroup%
170 \medskip%
9eb66c6e 171 \spewnotes%
1f7d590d
MW
172}
173
174%% Lisp documentation machinery.
175\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
176\def\describecategoryname#1{%
177 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
178 \ifx\@tempa\relax#1\else\@tempa\fi}
95346c38 179\definedescribecategory{sym}{symbol}
1f7d590d
MW
180\definedescribecategory{fun}{function}
181\definedescribecategory{gf}{generic function}
57bcf70e 182\definedescribecategory{msg}{message}
1f7d590d 183\definedescribecategory{var}{variable}
7cd50210 184\definedescribecategory{modvar}{module variable}
1f7d590d
MW
185\definedescribecategory{const}{constant}
186\definedescribecategory{meth}{primary method}
95346c38
MW
187\definedescribecategory{ar-meth}{around method}
188\definedescribecategory{be-meth}{before method}
189\definedescribecategory{af-meth}{after method}
1f7d590d 190\definedescribecategory{cls}{class}
db6c3279 191\definedescribecategory{rst}{restart}
1f7d590d 192\definedescribecategory{ty}{type}
ddfe4265 193\definedescribecategory{type}{type}
1f7d590d 194\definedescribecategory{mac}{macro}
95346c38
MW
195\definedescribecategory{lmac}{local macro}
196\definedescribecategory{parse}{parser spec}
197\definedescribecategory{parseform}{parser form}
198\definedescribecategory{opt}{option handler}
199\definedescribecategory{optmac}{option macro}
7cd50210 200\definedescribecategory{plug}{pluggable parser}
1f7d590d
MW
201\def\nlret{\\\hspace{4em}\returns}
202
203\def\q@{\q@}
7e94c5fe
MW
204\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
205\def\parse@dhd@a#1[#2]{#1{#2}}
206\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@}
207\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}}
208
209\newif\if@dheadfirst
210\def\dhead{\parse@dhd\dhead@}
211\def\dhead@#1#2#3{%
212 \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
213 {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}%
214 \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}%
ddfe4265
MW
215 {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
216 \protected@edef\@tempa##1{%
217 \noexpand\index{%
218 #1@{\noexpand\code{#1}}!%
219 \csname cat!#2\endcsname%
220 ##1%
221 }%
222 }%
223 \@tempa{|(}%
224 \toks@\expandafter{\after@desc}%
225 \toks\tw@\expandafter{\@tempa{|)}}%
226 \xdef\after@desc{\the\toks@\the\toks\tw@}}%
ac6e7a4e
MW
227 \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries
228 [\describecategoryname{#2}]}}%
7e94c5fe
MW
229 #3%
230}
231
232\def\desc@begin#1{%
ddfe4265
MW
233 \let\saved@after@desc\after@desc%
234 \gdef\after@desc{}%
1f7d590d 235 \normalfont%
7e94c5fe
MW
236 \if@nobreak\else\par\goodbreak\fi%
237 \global\@dheadfirsttrue%
238 \begingroup%
7e94c5fe
MW
239 \let\@endparenv\relax%
240 \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
ebf5ae2e 241 \@prog#1\endtabbing%
7e94c5fe
MW
242 \endgroup%
243 \penalty\@M\@afterheading%
244 \list{}{\rightmargin\z@\topsep\z@}\item%
1f7d590d 245}
ddfe4265 246\def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc}
7e94c5fe
MW
247
248\@namedef{describe*}#1{\desc@begin{#1}}
249\expandafter\let\csname enddescribe*\endcsname\desc@end
250\def\describe{\parse@dhd\desc@}
251\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}}
252\let\enddescribe\desc@end
1f7d590d 253
58f9b400
MW
254\def\descref#1{\@ifnextchar[{\descref@i{#1}}{\descref@ii{#1}{}}}
255\def\descref@i#1[#2]{\descref@ii{#1}{ #2}}
256\def\descref@ii#1#2#3{%
257 \code{#1}#2 (page~%
258 {\let\protect\@empty%
259 \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\pageref{#3:#1}}\@tempa}%
260 )%
261}
262
f1f17867
MW
263%%%----- That's all, folks --------------------------------------------------
264\endinput