| 1 | %%% -*-latex-*- |
| 2 | %%% |
| 3 | %%% Styles and other hacking for the Sod manual |
| 4 | %%% |
| 5 | %%% (c) 2015 Straylight/Edgeware |
| 6 | %%% |
| 7 | |
| 8 | %%%----- Licensing notice --------------------------------------------------- |
| 9 | %%% |
| 10 | %%% This file is part of the Sensible Object Design, an object system for C. |
| 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 | |
| 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 | |
| 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 | %% Notes for later. |
| 61 | \def\fixme#1{\leavevmode\marginpar{FIXME}\index{FIXME}[FIXME: #1]} |
| 62 | |
| 63 | %% Diagram settings. |
| 64 | \tikzset{ |
| 65 | every picture/.style={>=stealth, thick}, |
| 66 | lit/.style={font=\sffamily} |
| 67 | } |
| 68 | |
| 69 | %% Metavariables are italics without decoration. |
| 70 | \def\syntleft{\normalfont\itshape} |
| 71 | \let\syntright\empty |
| 72 | |
| 73 | %% Literal code is in sans face. |
| 74 | \def\codeface{\upshape\sffamily} |
| 75 | \DeclareRobustCommand\code[1]{% |
| 76 | \ifmmode\hbox\else\leavevmode\fi% |
| 77 | {\normalfont\codeface\/#1\/}% |
| 78 | } |
| 79 | \def\ulitleft{\normalfont\codeface} |
| 80 | \let\ulitright\empty |
| 81 | \def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}} |
| 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} |
| 92 | \atdef |#1|{\lit*{#1}\@scripts} |
| 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} |
| 129 | \atdef -#1{\if>#1\hbox{--\raisebox{.4pt}{>}}\penalty200\relax\fi} |
| 130 | |
| 131 | %% Comment setting. |
| 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} |
| 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. |
| 141 | \def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing} |
| 142 | \def\prog{\quote\@prog} |
| 143 | \def\endprog{\endtabbing\endquote} |
| 144 | \let\nprog\@prog |
| 145 | \let\endnprog\endtabbing |
| 146 | \def\ind{\quad\=\+\kill} |
| 147 | \def\@progcr{\futurelet\@tempa\@progcr@i} |
| 148 | {\def\:{\gdef\@progcr@sp}\: {\@progcr}} |
| 149 | \atdef~{\textasciitilde} |
| 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]} |
| 166 | \def\macsl{\`\textbackslash\hskip\leftmargin} |
| 167 | |
| 168 | %% Put a chunk of text in a box. |
| 169 | \newenvironment{boxy}[1][\q@]{% |
| 170 | \savenotes |
| 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% |
| 180 | \spewnotes% |
| 181 | } |
| 182 | |
| 183 | %% Lisp documentation machinery. |
| 184 | \def\definedescribecategory#1{% |
| 185 | \@ifnextchar[{\def@desc{#1}}{\def@desc{#1}[plain]}} |
| 186 | \def\def@desc#1[#2]#3{\@namedef{cat!#1}##1{#3}\@namedef{catsw!#1}{#2}} |
| 187 | \def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}} |
| 188 | \def\@descname@i[#1]#2{% |
| 189 | \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname% |
| 190 | \expandafter\let\expandafter\@tempb\csname descmod/#1\endcsname% |
| 191 | \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi} |
| 192 | \def\@maybe@modlabel#1#2{\if!#1!\else#1/\fi#2} |
| 193 | |
| 194 | \definedescribecategory{sym}{symbol} |
| 195 | \definedescribecategory{fun}{#1{function}} |
| 196 | \definedescribecategory{gf}{generic #1{function}} |
| 197 | \definedescribecategory{msg}{message} |
| 198 | \definedescribecategory{var}{variable} |
| 199 | \definedescribecategory{modvar}{module variable} |
| 200 | \definedescribecategory{const}{constant} |
| 201 | \definedescribecategory{meth}[method]{primary #1{method}} |
| 202 | \definedescribecategory{ar-meth}[method]{\code{:around} #1{method}} |
| 203 | \definedescribecategory{be-meth}[method]{\code{:before} #1{method}} |
| 204 | \definedescribecategory{af-meth}[method]{\code{:after} #1{method}} |
| 205 | \definedescribecategory{cls}{class} |
| 206 | \definedescribecategory{rst}{restart} |
| 207 | \definedescribecategory{ty}{type} |
| 208 | \definedescribecategory{type}{type} |
| 209 | \definedescribecategory{mac}{#1{macro}} |
| 210 | \definedescribecategory{lmac}{local #1{macro}} |
| 211 | \definedescribecategory{parse}{parser spec} |
| 212 | \definedescribecategory{parseform}{parser form} |
| 213 | \definedescribecategory{opt}{option handler} |
| 214 | \definedescribecategory{optmac}{option macro} |
| 215 | \definedescribecategory{plug}{pluggable parser} |
| 216 | \def\nlret{\\\hspace{4em}\returns} |
| 217 | |
| 218 | \@namedef{descmod/}#1{#1} |
| 219 | |
| 220 | \@namedef{descmod/setf}#1{\code{setf}-#1} |
| 221 | |
| 222 | \@namedef{descargs/plain}#1{#1{}} |
| 223 | \@namedef{desclabel/plain}#1#2#3{#1:\@maybe@modlabel{#2}{#3}} |
| 224 | \@namedef{descindex/plain}#1#2#3{% |
| 225 | #3@\noexpand\code{#3}!% |
| 226 | \protect\describecategoryname[#2]{#1}% |
| 227 | } |
| 228 | |
| 229 | \@namedef{descargs/method}#1#2{#1{{#2}}} |
| 230 | \@namedef{desclabel/method}#1#2#3#4{#1:\@maybe@modlabel{#2}{#3}(#4)} |
| 231 | \@namedef{descindex/method}#1#2#3#4{% |
| 232 | #3@\noexpand\code{#3}!% |
| 233 | \protect\describecategoryname[#2]{#1}% |
| 234 | \protect\fmtspecs{ specialized at }{#4}% |
| 235 | } |
| 236 | |
| 237 | \def\@desc@dispatch#1#2{% |
| 238 | \csname #1/% |
| 239 | \expandafter\ifx\csname catsw!#2\endcsname\relax plain% |
| 240 | \else \csname catsw!#2\endcsname \fi% |
| 241 | \endcsname% |
| 242 | } |
| 243 | |
| 244 | \def\q@{\q@} |
| 245 | \def\@setf{setf} |
| 246 | |
| 247 | \def\fmtspecs#1#2{% |
| 248 | \if!#2!\else\count@\z@\toks@{}#1\@fmtspecs@i#2,\q@,\fi} |
| 249 | \def\@fmtspecs@i#1,{% |
| 250 | \def\@tempa{#1}% |
| 251 | \ifx\@tempa\q@% |
| 252 | \ifcase\count@(no args?!)% |
| 253 | \or% nothin' doin |
| 254 | \or \space and % |
| 255 | \else, and % |
| 256 | \fi% |
| 257 | \the\toks@% |
| 258 | \else% |
| 259 | \ifnum\count@>\@ne, \fi% |
| 260 | \the\toks@% |
| 261 | \toks@{\code{#1}}\advance\count@\@ne% |
| 262 | \expandafter\@fmtspecs@i% |
| 263 | \fi% |
| 264 | } |
| 265 | |
| 266 | %% \parse@dhd{NEXT}[MOD]{CAT}{...}...[NAME]{SYNOPSIS} |
| 267 | %% call NEXT{MOD}{CAT}{{...}...}{NAME}{SYNOPSIS} |
| 268 | %% #1 #2 #3 #4 #5 |
| 269 | \def\@setf{setf} |
| 270 | \def\parse@dhd#1{% {NEXT} |
| 271 | \@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}} |
| 272 | \def\parse@dhd@a#1[#2]#3{% {NEXT}[MOD]{CAT} |
| 273 | \@desc@dispatch{descargs}{#3}{\parse@dhd@ab{#1}{#2}{#3}}} |
| 274 | \def\parse@dhd@ab#1#2#3#4{% {NEXT}{MOD}{CAT}{{...}...} |
| 275 | \@ifnextchar[{\parse@dhd@ac{#1}{#2}{#3}{#4}}{\parse@dhd@ad{#1}{#2}{#3}{#4}}} |
| 276 | \def\parse@dhd@ac#1#2#3#4[#5]#6{% {NEXT}{MOD}{CAT}{{...}...}[NAME]{SYNOPSIS} |
| 277 | #1{#2}{#3}{#4}{#5}{#6}} |
| 278 | \def\parse@dhd@ad#1#2#3#4#5{% {NEXT}{MOD}{CAT}{{...}...}{NAME [ARGS...]} |
| 279 | \parse@dhd@ae{#1}{#2}{#3}{#4}{#5}#5 \q@} |
| 280 | \def\parse@dhd@ae#1#2#3#4#5#6 #7\q@{% |
| 281 | % {NEXT}{MOD}{CAT}{{...}...}{SYNSOPSIS}NAME [ARGS...]\q@ |
| 282 | #1{#2}{#3}{#4}{#6}{#5}} |
| 283 | |
| 284 | \def\parse@dhd@c#1#2{% {NEXT}{CAT} |
| 285 | \@desc@dispatch{descargs}{#2}{\parse@dhd@cb{#1}{#2}}} |
| 286 | \def\parse@dhd@cb#1#2#3{% {NEXT}{CAT}{{...}...} |
| 287 | \@ifnextchar[{\parse@dhd@cc{#1}{#2}{#3}}{\parse@dhd@cd{#1}{#2}{#3}}} |
| 288 | \def\parse@dhd@cc#1#2#3[#4]#5{% {NEXT}{CAT}{{...}...}[NAME]{SYNOPSIS} |
| 289 | #1{}{#2}{#3}{#4}{#5}} |
| 290 | \def\parse@dhd@cd#1#2#3#4{% {NEXT}{CAT}{{...}...}{SYNOPSIS} |
| 291 | \parse@dhd@ce{#1}{#2}{#3}{#4}#4 \q@} |
| 292 | \def\parse@dhd@ce#1#2#3#4#5 #6\q@{% |
| 293 | % {NEXT}{CAT}{{...}...}{SYNOPSIS}NAME [ARGS...]\q@ |
| 294 | \def\temp@{#5}% |
| 295 | \ifx\@setf\temp@\def\next@{\parse@dhd@csetf{#1}{#2}{#3}{#4}#6 \q@}% |
| 296 | \else\def\next@{#1{}{#2}{#3}{#5}{#4}}\fi% |
| 297 | \next@% |
| 298 | } |
| 299 | \def\parse@dhd@csetf#1#2#3#4(#5 #6\q@{% |
| 300 | % {NEXT}{CAT}{{...}...}{SYNOPSIS}(NAME [ARGS...])\q@ |
| 301 | #1{setf}{#2}{#3}{#5}{#4}} |
| 302 | |
| 303 | \newif\if@dheadfirst |
| 304 | \def\dhead{\parse@dhd\dhead@} |
| 305 | \def\dhead@#1#2#3#4#5{% {MOD}{CAT}{{...}...}{NAME}{SYNOPSIS} |
| 306 | \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi% |
| 307 | {\let\protect\@empty\let\@uscore\relax% |
| 308 | \edef\temp@{\@desc@dispatch{desclabel}{#2}{#2}{#1}{#4}#3}% |
| 309 | \def\@uscore{_\@gobble}\expandafter\message\expandafter{\temp@}% |
| 310 | \def\@uscore{-\@gobble}\expandafter\label\expandafter{\temp@}}% |
| 311 | {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}% |
| 312 | \protected@edef\@tempa##1{% |
| 313 | \noexpand\index{\@desc@dispatch{descindex}{#2}{#2}{#1}{#4}#3##1}}% |
| 314 | \toks@\expandafter{\@tempa{|)}}% |
| 315 | \toks\tw@\expandafter{\after@desc}% |
| 316 | \xdef\after@desc{\the\toks\tw@\the\toks@}% |
| 317 | \@tempa{|(}}% |
| 318 | \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries |
| 319 | [\describecategoryname[#1]{#2}]}}% |
| 320 | #5% |
| 321 | } |
| 322 | |
| 323 | \def\desc@begin#1{% |
| 324 | \let\saved@after@desc\after@desc% |
| 325 | \gdef\after@desc{}% |
| 326 | \normalfont% |
| 327 | \if@nobreak\else\par\goodbreak\fi% |
| 328 | \global\@dheadfirsttrue% |
| 329 | \begingroup% |
| 330 | \let\@endparenv\relax% |
| 331 | \clubpenalty\@M \widowpenalty\@M \interlinepenalty50% |
| 332 | \@prog#1\endtabbing% |
| 333 | \endgroup% |
| 334 | \penalty\@M\@afterheading% |
| 335 | \list{}{\rightmargin\z@\topsep\z@}\item% |
| 336 | } |
| 337 | \def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc} |
| 338 | |
| 339 | \@namedef{describe*}#1{\desc@begin{#1}} |
| 340 | \expandafter\let\csname enddescribe*\endcsname\desc@end |
| 341 | \def\describe{\parse@dhd\desc@} |
| 342 | \def\desc@#1#2#3#4#5{\desc@begin{\dhead@{#1}{#2}{#3}{#4}{#5}}} |
| 343 | \let\enddescribe\desc@end |
| 344 | |
| 345 | \def\descref#1{\@ifnextchar[{\descref@i{#1}}{\descref@ii{#1}{}}} |
| 346 | \def\descref@i#1[#2]{\descref@ii{#1}{ #2}} |
| 347 | \def\descref@ii#1#2#3{% |
| 348 | \code{#1}#2 (page~% |
| 349 | {\let\protect\@empty% |
| 350 | \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\pageref{#3:#1}}\@tempa}% |
| 351 | )% |
| 352 | } |
| 353 | |
| 354 | %%%----- That's all, folks -------------------------------------------------- |
| 355 | \endinput |