doc/sod.sty: Fiddle with the `describe' categories.
[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%%%
10%%% This file is part of the Sensble 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
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.
65\let\codeface\sffamily
66\def\code#1{\ifmmode\hbox\fi{\normalfont\codeface\/#1\/}}
67\def\ulitleft{\normalfont\codeface}
68\let\ulitright\empty
69
70%% Conditionally enter maths mode. Can't use \ensuremath here because we
71%% aren't necessarily sure where the maths will actually end.
72\let\m@maybe@end\relax
73\def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
74
75%% Standard syntax shortcuts.
76\atdef <#1>{\synt{#1}\@scripts}
77\atdef "#1"{\lit*{#1}\@scripts}
78\atdef `#1'{\lit{#1}\@scripts}
79\atdef |#1|{\textsf{#1}\@scripts}
80
81%% A handy abbreviation; `\\' itself is too good to steal.
82\atdef \\{\textbackslash}
83
84%% Intercept grammar typesetting and replace the vertical bar with the
85%% maths-font version.
86\let\@@grammar\grammar
87\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
88
89%% Collect super- and subscripts. (Note that underscores are active for the
90%% most part.) When we're done, end maths mode if we entered it
91%% conditionally.
92\def\@scripts{\futurelet\@ch\@scripts@i}
93\begingroup\lccode`\~=`\_\lowercase{\endgroup
94\def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
95 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
96\def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
97
98%% Doubling characters, maybe. Either way, chain onto \@scripts.
99\def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
100\def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
101 \expandafter\@firstoftwo\expandafter\@scripts%
102 \else\@tempa\expandafter\@scripts\fi}
103
104%% Extra syntax for Lisp templates. These produce the maths-font versions of
105%% characters, which should contrast well against the sans face used for
106%% literals.
107\atdef [{\dbl@maybe[}
108\atdef ]{\dbl@maybe]}
109\atdef {{\m@maybe\{\@scripts}
110\atdef }{\m@maybe\}\@scripts}
111\atdef ({\m@maybe(\@scripts}
112\atdef ){\m@maybe)\@scripts}
113\atdef !{\m@maybe|\@scripts}
114\def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
115\atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
780dfb99 116\atdef -#1{\if>#1{\ensuremath\rightarrow}\fi}
1f7d590d
MW
117
118%% Comment setting.
119\atdef ;#1\\{\normalfont\itshape;#1\\}
120
121%% Environment for setting programs. Newlines are explicit, because
122%% otherwise I need comments in weird places to make the vertical spacing
123%% come out properly. You can write `\obeylines' if you really want to.
124\def\prog{\codeface\quote\tabbing}
125\def\endprog{\endtabbing\endquote}
126\def\ind{\quad\=\+\kill}
127
128%% Put a chunk of text in a box.
129\newenvironment{boxy}[1][\q@]{%
9eb66c6e 130 \savenotes
1f7d590d
MW
131 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
132 \medskip%
133 \vbox\bgroup\hrule\hbox\bgroup\vrule%
134 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
135 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
136}{%
137 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
138 \vrule\egroup\hrule\egroup%
139 \medskip%
9eb66c6e 140 \spewnotes%
1f7d590d
MW
141}
142
143%% Lisp documentation machinery.
144\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
145\def\describecategoryname#1{%
146 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
147 \ifx\@tempa\relax#1\else\@tempa\fi}
95346c38 148\definedescribecategory{sym}{symbol}
1f7d590d
MW
149\definedescribecategory{fun}{function}
150\definedescribecategory{gf}{generic function}
151\definedescribecategory{var}{variable}
152\definedescribecategory{const}{constant}
153\definedescribecategory{meth}{primary method}
95346c38
MW
154\definedescribecategory{ar-meth}{around method}
155\definedescribecategory{be-meth}{before method}
156\definedescribecategory{af-meth}{after method}
1f7d590d
MW
157\definedescribecategory{cls}{class}
158\definedescribecategory{ty}{type}
159\definedescribecategory{mac}{macro}
95346c38
MW
160\definedescribecategory{lmac}{local macro}
161\definedescribecategory{parse}{parser spec}
162\definedescribecategory{parseform}{parser form}
163\definedescribecategory{opt}{option handler}
164\definedescribecategory{optmac}{option macro}
1f7d590d
MW
165\def\nlret{\\\hspace{4em}\returns}
166
167\def\q@{\q@}
7e94c5fe
MW
168\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
169\def\parse@dhd@a#1[#2]{#1{#2}}
170\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@}
171\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}}
172
173\newif\if@dheadfirst
174\def\dhead{\parse@dhd\dhead@}
175\def\dhead@#1#2#3{%
176 \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
177 {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}%
178 \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}%
179 \rlap{\rightline{\normalfont\bfseries[\describecategoryname{#2}]}}%
180 #3%
181}
182
183\def\desc@begin#1{%
1f7d590d 184 \normalfont%
7e94c5fe
MW
185 \if@nobreak\else\par\goodbreak\fi%
186 \global\@dheadfirsttrue%
187 \begingroup%
188 \codeface%
189 \let\@endparenv\relax%
190 \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
191 \tabbing#1\endtabbing%
192 \endgroup%
193 \penalty\@M\@afterheading%
194 \list{}{\rightmargin\z@\topsep\z@}\item%
1f7d590d 195}
7e94c5fe
MW
196\let\desc@end\endlist
197
198\@namedef{describe*}#1{\desc@begin{#1}}
199\expandafter\let\csname enddescribe*\endcsname\desc@end
200\def\describe{\parse@dhd\desc@}
201\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}}
202\let\enddescribe\desc@end
1f7d590d 203
f1f17867
MW
204%%%----- That's all, folks --------------------------------------------------
205\endinput