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