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