.gitignore: Ignore `makeindex' debris.
[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
fea590fe
MW
60%% Notes for later.
61\def\fixme#1{\leavevmode\marginpar{FIXME}[FIXME: #1]}
62
a4094071
MW
63%% Diagram settings.
64\tikzset{every picture/.style={>=stealth, thick}}
65
1f7d590d
MW
66%% Metavariables are italics without decoration.
67\def\syntleft{\normalfont\itshape}
68\let\syntright\empty
69
70%% Literal code is in sans face.
5f1bbd61 71\def\codeface{\upshape\sffamily}
ddfe4265
MW
72\DeclareRobustCommand\code[1]{%
73 \ifmmode\hbox\else\leavevmode\fi%
74 {\normalfont\codeface\/#1\/}%
75}
1f7d590d
MW
76\def\ulitleft{\normalfont\codeface}
77\let\ulitright\empty
48ab1447 78\def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}}
1f7d590d
MW
79
80%% Conditionally enter maths mode. Can't use \ensuremath here because we
81%% aren't necessarily sure where the maths will actually end.
82\let\m@maybe@end\relax
83\def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
84
85%% Standard syntax shortcuts.
86\atdef <#1>{\synt{#1}\@scripts}
87\atdef "#1"{\lit*{#1}\@scripts}
88\atdef `#1'{\lit{#1}\@scripts}
5f1bbd61 89\atdef |#1|{\lit*{#1}\@scripts}
1f7d590d
MW
90
91%% A handy abbreviation; `\\' itself is too good to steal.
92\atdef \\{\textbackslash}
93
94%% Intercept grammar typesetting and replace the vertical bar with the
95%% maths-font version.
96\let\@@grammar\grammar
97\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
98
99%% Collect super- and subscripts. (Note that underscores are active for the
100%% most part.) When we're done, end maths mode if we entered it
101%% conditionally.
102\def\@scripts{\futurelet\@ch\@scripts@i}
103\begingroup\lccode`\~=`\_\lowercase{\endgroup
104\def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
105 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
106\def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
107
108%% Doubling characters, maybe. Either way, chain onto \@scripts.
109\def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
110\def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
111 \expandafter\@firstoftwo\expandafter\@scripts%
112 \else\@tempa\expandafter\@scripts\fi}
113
114%% Extra syntax for Lisp templates. These produce the maths-font versions of
115%% characters, which should contrast well against the sans face used for
116%% literals.
117\atdef [{\dbl@maybe[}
118\atdef ]{\dbl@maybe]}
119\atdef {{\m@maybe\{\@scripts}
120\atdef }{\m@maybe\}\@scripts}
121\atdef ({\m@maybe(\@scripts}
122\atdef ){\m@maybe)\@scripts}
123\atdef !{\m@maybe|\@scripts}
124\def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
125\atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
a5d80269 126\atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi}
1f7d590d
MW
127
128%% Comment setting.
888d5e58
MW
129\def\comment#1{\mbox{\normalfont\itshape\/#1\/}}
130\atdef /*#1*/{/*\comment{#1}*/}
131\def\@semis{\@ifnextchar;{;\@semis}\@semicomment}
132\def\@semicomment#1\\{\comment{#1}\\}
133\atdef ;#1\\{;\@semis}
1f7d590d
MW
134
135%% Environment for setting programs. Newlines are explicit, because
136%% otherwise I need comments in weird places to make the vertical spacing
137%% come out properly. You can write `\obeylines' if you really want to.
4effe575
MW
138\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
139\def\prog{\quote\@prog}
1f7d590d 140\def\endprog{\endtabbing\endquote}
4effe575
MW
141\let\nprog\@prog
142\let\endnprog\endtabbing
1f7d590d 143\def\ind{\quad\=\+\kill}
ebf5ae2e
MW
144\def\@progcr{\futurelet\@tempa\@progcr@i}
145{\def\:{\gdef\@progcr@sp}\: {\@progcr}}
ca8f5d55 146\atdef~{\textasciitilde}
ebf5ae2e
MW
147\def\@progcr@i{%
148 \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
149 \if1\ifx\@tempa[1\else
150 \ifx\@tempa*1\else
151 0\fi\fi
152 \let\next@\prog@@cr\else
153 \if1\ifx\@tempa+1\else
154 \ifx\@tempa-1\else
155 0\fi\fi
156 \let\next@\@progcr@ii\else
157 \let\next@\@progcr@a\fi\fi\fi
158 \next@}
159\def\@progcr@a{\prog@@cr*{}\ignorespaces}
160\def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
161\@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
162\@namedef{@progcr@-}{\prog@@cr*[\jot]}
5e4a5d53 163\def\macsl{\`\textbackslash\hskip\leftmargin}
1f7d590d
MW
164
165%% Put a chunk of text in a box.
166\newenvironment{boxy}[1][\q@]{%
9eb66c6e 167 \savenotes
1f7d590d
MW
168 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
169 \medskip%
170 \vbox\bgroup\hrule\hbox\bgroup\vrule%
171 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
172 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
173}{%
174 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
175 \vrule\egroup\hrule\egroup%
176 \medskip%
9eb66c6e 177 \spewnotes%
1f7d590d
MW
178}
179
180%% Lisp documentation machinery.
181\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
182\def\describecategoryname#1{%
183 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
184 \ifx\@tempa\relax#1\else\@tempa\fi}
95346c38 185\definedescribecategory{sym}{symbol}
1f7d590d
MW
186\definedescribecategory{fun}{function}
187\definedescribecategory{gf}{generic function}
57bcf70e 188\definedescribecategory{msg}{message}
1f7d590d 189\definedescribecategory{var}{variable}
7cd50210 190\definedescribecategory{modvar}{module variable}
1f7d590d
MW
191\definedescribecategory{const}{constant}
192\definedescribecategory{meth}{primary method}
95346c38
MW
193\definedescribecategory{ar-meth}{around method}
194\definedescribecategory{be-meth}{before method}
195\definedescribecategory{af-meth}{after method}
1f7d590d 196\definedescribecategory{cls}{class}
db6c3279 197\definedescribecategory{rst}{restart}
1f7d590d 198\definedescribecategory{ty}{type}
ddfe4265 199\definedescribecategory{type}{type}
1f7d590d 200\definedescribecategory{mac}{macro}
95346c38
MW
201\definedescribecategory{lmac}{local macro}
202\definedescribecategory{parse}{parser spec}
203\definedescribecategory{parseform}{parser form}
204\definedescribecategory{opt}{option handler}
205\definedescribecategory{optmac}{option macro}
7cd50210 206\definedescribecategory{plug}{pluggable parser}
1f7d590d
MW
207\def\nlret{\\\hspace{4em}\returns}
208
209\def\q@{\q@}
7e94c5fe
MW
210\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
211\def\parse@dhd@a#1[#2]{#1{#2}}
212\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@}
213\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}}
214
215\newif\if@dheadfirst
216\def\dhead{\parse@dhd\dhead@}
217\def\dhead@#1#2#3{%
218 \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
219 {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}%
220 \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}%
ddfe4265
MW
221 {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
222 \protected@edef\@tempa##1{%
223 \noexpand\index{%
224 #1@{\noexpand\code{#1}}!%
225 \csname cat!#2\endcsname%
226 ##1%
227 }%
228 }%
229 \@tempa{|(}%
230 \toks@\expandafter{\after@desc}%
231 \toks\tw@\expandafter{\@tempa{|)}}%
232 \xdef\after@desc{\the\toks@\the\toks\tw@}}%
ac6e7a4e
MW
233 \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries
234 [\describecategoryname{#2}]}}%
7e94c5fe
MW
235 #3%
236}
237
238\def\desc@begin#1{%
ddfe4265
MW
239 \let\saved@after@desc\after@desc%
240 \gdef\after@desc{}%
1f7d590d 241 \normalfont%
7e94c5fe
MW
242 \if@nobreak\else\par\goodbreak\fi%
243 \global\@dheadfirsttrue%
244 \begingroup%
7e94c5fe
MW
245 \let\@endparenv\relax%
246 \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
ebf5ae2e 247 \@prog#1\endtabbing%
7e94c5fe
MW
248 \endgroup%
249 \penalty\@M\@afterheading%
250 \list{}{\rightmargin\z@\topsep\z@}\item%
1f7d590d 251}
ddfe4265 252\def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc}
7e94c5fe
MW
253
254\@namedef{describe*}#1{\desc@begin{#1}}
255\expandafter\let\csname enddescribe*\endcsname\desc@end
256\def\describe{\parse@dhd\desc@}
257\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}}
258\let\enddescribe\desc@end
1f7d590d 259
58f9b400
MW
260\def\descref#1{\@ifnextchar[{\descref@i{#1}}{\descref@ii{#1}{}}}
261\def\descref@i#1[#2]{\descref@ii{#1}{ #2}}
262\def\descref@ii#1#2#3{%
263 \code{#1}#2 (page~%
264 {\let\protect\@empty%
265 \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\pageref{#3:#1}}\@tempa}%
266 )%
267}
268
f1f17867
MW
269%%%----- That's all, folks --------------------------------------------------
270\endinput