7a5260578032c41b744bab6d105b822e65eba14e
[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 %% Unix manpage references.
45 \def\man#1#2{\textbf{#1}(#2)}
46
47 %% Listings don't need to be small.
48 \let\listingsize\relax
49
50 %% Metavariables are italics without decoration.
51 \def\syntleft{\normalfont\itshape}
52 \let\syntright\empty
53
54 %% Literal code is in sans face.
55 \let\codeface\sffamily
56 \def\code#1{\ifmmode\hbox\fi{\normalfont\codeface\/#1\/}}
57 \def\ulitleft{\normalfont\codeface}
58 \let\ulitright\empty
59
60 %% Conditionally enter maths mode. Can't use \ensuremath here because we
61 %% aren't necessarily sure where the maths will actually end.
62 \let\m@maybe@end\relax
63 \def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
64
65 %% Standard syntax shortcuts.
66 \atdef <#1>{\synt{#1}\@scripts}
67 \atdef "#1"{\lit*{#1}\@scripts}
68 \atdef `#1'{\lit{#1}\@scripts}
69 \atdef |#1|{\textsf{#1}\@scripts}
70
71 %% A handy abbreviation; `\\' itself is too good to steal.
72 \atdef \\{\textbackslash}
73
74 %% Intercept grammar typesetting and replace the vertical bar with the
75 %% maths-font version.
76 \let\@@grammar\grammar
77 \def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
78
79 %% Collect super- and subscripts. (Note that underscores are active for the
80 %% most part.) When we're done, end maths mode if we entered it
81 %% conditionally.
82 \def\@scripts{\futurelet\@ch\@scripts@i}
83 \begingroup\lccode`\~=`\_\lowercase{\endgroup
84 \def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch^1\else0\fi\fi%
85 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
86 \def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
87
88 %% Doubling characters, maybe. Either way, chain onto \@scripts.
89 \def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
90 \def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
91 \expandafter\@firstoftwo\expandafter\@scripts%
92 \else\@tempa\expandafter\@scripts\fi}
93
94 %% Extra syntax for Lisp templates. These produce the maths-font versions of
95 %% characters, which should contrast well against the sans face used for
96 %% literals.
97 \atdef [{\dbl@maybe[}
98 \atdef ]{\dbl@maybe]}
99 \atdef {{\m@maybe\{\@scripts}
100 \atdef }{\m@maybe\}\@scripts}
101 \atdef ({\m@maybe(\@scripts}
102 \atdef ){\m@maybe)\@scripts}
103 \atdef !{\m@maybe|\@scripts}
104 \def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
105 \atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
106
107 %% Comment setting.
108 \atdef ;#1\\{\normalfont\itshape;#1\\}
109
110 %% Environment for setting programs. Newlines are explicit, because
111 %% otherwise I need comments in weird places to make the vertical spacing
112 %% come out properly. You can write `\obeylines' if you really want to.
113 \def\prog{\codeface\quote\tabbing}
114 \def\endprog{\endtabbing\endquote}
115 \def\ind{\quad\=\+\kill}
116
117 %% Put a chunk of text in a box.
118 \newenvironment{boxy}[1][\q@]{%
119 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
120 \medskip%
121 \vbox\bgroup\hrule\hbox\bgroup\vrule%
122 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
123 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
124 }{%
125 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
126 \vrule\egroup\hrule\egroup%
127 \medskip%
128 }
129
130 %% Lisp documentation machinery.
131 \def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
132 \def\describecategoryname#1{%
133 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
134 \ifx\@tempa\relax#1\else\@tempa\fi}
135 \definedescribecategory{fun}{function}
136 \definedescribecategory{gf}{generic function}
137 \definedescribecategory{var}{variable}
138 \definedescribecategory{const}{constant}
139 \definedescribecategory{meth}{primary method}
140 \definedescribecategory{ar-meth}{around-method}
141 \definedescribecategory{be-meth}{before-method}
142 \definedescribecategory{af-meth}{after-method}
143 \definedescribecategory{cls}{class}
144 \definedescribecategory{ty}{type}
145 \definedescribecategory{mac}{macro}
146 \def\nlret{\\\hspace{4em}\returns}
147
148 \def\q@{\q@}
149 \newenvironment{describe}[3][\q@]{%
150 \normalfont%
151 \par\goodbreak%
152 \vspace{\bigskipamount}%
153 \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
154 \dimen@\linewidth\advance\dimen@-\wd\z@%
155 \def\@temp##1 ##2\q@{%
156 \message{#2:##1}%
157 {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
158 }%
159 \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
160 \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
161 @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
162 \noindent\csname tabular*\expandafter\endcsname\@temp%
163 \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
164 % \@afterheading%
165 \list{}{\rightmargin\z@}\item%
166 }{%
167 \endlist%
168 }
169
170 %%% ----- That's all, folks --------------------------------------------------
171 \endinput