doc/sod.sty: Make `@->' typeset a dereferencing arrow.
[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
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}
780dfb99 106\atdef -#1{\if>#1{\ensuremath\rightarrow}\fi}
1f7d590d
MW
107
108%% Comment setting.
109\atdef ;#1\\{\normalfont\itshape;#1\\}
110
111%% Environment for setting programs. Newlines are explicit, because
112%% otherwise I need comments in weird places to make the vertical spacing
113%% come out properly. You can write `\obeylines' if you really want to.
114\def\prog{\codeface\quote\tabbing}
115\def\endprog{\endtabbing\endquote}
116\def\ind{\quad\=\+\kill}
117
118%% Put a chunk of text in a box.
119\newenvironment{boxy}[1][\q@]{%
120 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
121 \medskip%
122 \vbox\bgroup\hrule\hbox\bgroup\vrule%
123 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
124 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
125}{%
126 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
127 \vrule\egroup\hrule\egroup%
128 \medskip%
129}
130
131%% Lisp documentation machinery.
132\def\definedescribecategory#1#2{\@namedef{cat!#1}{#2}}
133\def\describecategoryname#1{%
134 \expandafter\let\expandafter\@tempa\csname cat!#1\endcsname%
135 \ifx\@tempa\relax#1\else\@tempa\fi}
136\definedescribecategory{fun}{function}
137\definedescribecategory{gf}{generic function}
138\definedescribecategory{var}{variable}
139\definedescribecategory{const}{constant}
140\definedescribecategory{meth}{primary method}
141\definedescribecategory{ar-meth}{around-method}
142\definedescribecategory{be-meth}{before-method}
143\definedescribecategory{af-meth}{after-method}
144\definedescribecategory{cls}{class}
145\definedescribecategory{ty}{type}
146\definedescribecategory{mac}{macro}
147\def\nlret{\\\hspace{4em}\returns}
148
149\def\q@{\q@}
150\newenvironment{describe}[3][\q@]{%
151 \normalfont%
152 \par\goodbreak%
153 \vspace{\bigskipamount}%
154 \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
155 \dimen@\linewidth\advance\dimen@-\wd\z@%
23e44cba
MW
156 \def\@temp##1 ##2\q@{%
157 \message{#2:##1}%
158 {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
159 }%
1f7d590d
MW
160 \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
161 \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
162 @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
163 \noindent\csname tabular*\expandafter\endcsname\@temp%
164 \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
165% \@afterheading%
166 \list{}{\rightmargin\z@}\item%
167}{%
168 \endlist%
169}
170
171%%% ----- That's all, folks --------------------------------------------------
172\endinput