doc/sod.sty: Add macro for table column heads.
[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@]{%
130 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
131 \medskip%
132 \vbox\bgroup\hrule\hbox\bgroup\vrule%
133 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
134 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
135}{%
136 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
137 \vrule\egroup\hrule\egroup%
138 \medskip%
139}
140
141%% Lisp documentation machinery.
142\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
143\def\describecategoryname#1{%
144 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
145 \ifx\@tempa\relax#1\else\@tempa\fi}
146\definedescribecategory{fun}{function}
147\definedescribecategory{gf}{generic function}
148\definedescribecategory{var}{variable}
149\definedescribecategory{const}{constant}
150\definedescribecategory{meth}{primary method}
151\definedescribecategory{ar-meth}{around-method}
152\definedescribecategory{be-meth}{before-method}
153\definedescribecategory{af-meth}{after-method}
154\definedescribecategory{cls}{class}
155\definedescribecategory{ty}{type}
156\definedescribecategory{mac}{macro}
157\def\nlret{\\\hspace{4em}\returns}
158
159\def\q@{\q@}
160\newenvironment{describe}[3][\q@]{%
161 \normalfont%
162 \par\goodbreak%
163 \vspace{\bigskipamount}%
164 \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
165 \dimen@\linewidth\advance\dimen@-\wd\z@%
23e44cba
MW
166 \def\@temp##1 ##2\q@{%
167 \message{#2:##1}%
168 {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
169 }%
1f7d590d
MW
170 \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
171 \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
172 @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
173 \noindent\csname tabular*\expandafter\endcsname\@temp%
174 \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
175% \@afterheading%
176 \list{}{\rightmargin\z@}\item%
177}{%
178 \endlist%
179}
180
181%%% ----- That's all, folks --------------------------------------------------
182\endinput