ff636208d83a880b6c66db3d2a4d5acc85c08a1c
[sod] / doc / sod.sty
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
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 \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}
116 \atdef -#1{\if>#1{\ensuremath\rightarrow}\fi}
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 \savenotes
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%
140 \spewnotes%
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}
148 \definedescribecategory{fun}{function}
149 \definedescribecategory{gf}{generic function}
150 \definedescribecategory{var}{variable}
151 \definedescribecategory{const}{constant}
152 \definedescribecategory{meth}{primary method}
153 \definedescribecategory{ar-meth}{around-method}
154 \definedescribecategory{be-meth}{before-method}
155 \definedescribecategory{af-meth}{after-method}
156 \definedescribecategory{cls}{class}
157 \definedescribecategory{ty}{type}
158 \definedescribecategory{mac}{macro}
159 \def\nlret{\\\hspace{4em}\returns}
160
161 \def\q@{\q@}
162 \newenvironment{describe}[3][\q@]{%
163 \normalfont%
164 \par\goodbreak%
165 \vspace{\bigskipamount}%
166 \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
167 \dimen@\linewidth\advance\dimen@-\wd\z@%
168 \def\@temp##1 ##2\q@{%
169 \message{#2:##1}%
170 {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
171 }%
172 \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
173 \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
174 @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
175 \noindent\csname tabular*\expandafter\endcsname\@temp%
176 \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
177 % \@afterheading%
178 \list{}{\rightmargin\z@}\item%
179 }{%
180 \endlist%
181 }
182
183 %%%----- That's all, folks --------------------------------------------------
184 \endinput