doc/sod.sty: Adjust the default dash pattern.
[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 Sensible 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 %%%--------------------------------------------------------------------------
29 %%% Basic style things.
30
31 %% More reference types.
32 \defxref{p}{part}
33
34 %% A gadget to include in `\xref': call as
35 %%
36 %% \xref[\instead{THING}]{LABEL}
37 %%
38 %% to replace the usual `section' or whatever with THING.
39 \def\instead#1#2{#1}
40
41 %% Other languages with special typesetting.
42 \def\Cplusplus{C\kern-\p@++}
43 \def\Csharp{C\#}
44
45 %% Special maths notation.
46 \def\chain#1#2{\mathsf{ch}_{#1}(#2)}
47 \def\chainhead#1#2{\mathsf{hd}_{#1}(#2)}
48 \def\chaintail#1#2{\mathsf{tl}_{#1}(#2)}
49
50 %% Other mathematical tweaks.
51 \let\implies\Rightarrow
52 \let\epsilon\varepsilon
53
54 %% A table heading cell. Clone and hack \multicolumn.
55 \def\thd{\omit\@ifnextchar[\thd@{\thd@[l]}}
56 \def\thd@[#1]#2{%
57 \begingroup
58 \tab@multicol \tab@initread \let\tab@looped\tab@err@multi
59 \tab@preamble{}\def\tab@midtext{\bfseries#2}\tab@readpreamble{#1}%
60 \the\tab@preamble
61 \endgroup \ignorespaces
62 }
63
64 %% Unix manpage references.
65 \def\man#1#2{\textbf{#1}(#2)}
66
67 %% Listings don't need to be small.
68 \let\listingsize\relax
69
70 %% Notes for later.
71 \def\fixme#1{\leavevmode\marginpar{FIXME}\index{FIXME}[FIXME: #1]}
72
73 %% Diagram settings.
74 \tikzset{
75 every picture/.style={>=stealth, thick},
76 lit/.style={font=\sffamily},
77 dashed/.style={dash pattern=on 2.19pt off 2.19pt}
78 }
79
80 %% Metavariables are italics without decoration.
81 \def\syntleft{\normalfont\itshape}
82 \let\syntright\empty
83
84 %% Literal code is in sans face.
85 \def\codeface{\upshape\sffamily}
86 \DeclareRobustCommand\code[1]{%
87 \ifmmode\hbox\else\leavevmode\fi%
88 {\normalfont\codeface\/#1\/}%
89 }
90 \def\ulitleft{\normalfont\codeface}
91 \let\ulitright\empty
92 \def\lit@i#1#2#3{\ifmmode\leavevmode\hbox\fi{#1{#3\/}#2}}
93
94 %% Conditionally enter maths mode. Can't use \ensuremath here because we
95 %% aren't necessarily sure where the maths will actually end.
96 \let\m@maybe@end\relax
97 \def\m@maybe{\ifmmode\else$\let\m@maybe@end$\fi}
98
99 %% Standard syntax shortcuts.
100 \atdef <#1>{\synt{#1}\@scripts}
101 \atdef "#1"{\lit*{#1}\@scripts}
102 \atdef `#1'{\lit{#1}\@scripts}
103 \atdef |#1|{\lit*{#1}\@scripts}
104
105 %% A handy abbreviation; `\\' itself is too good to steal.
106 \atdef \\{\textbackslash}
107
108 %% Intercept grammar typesetting and replace the vertical bar with the
109 %% maths-font version.
110 \let\@@syn@shorts\syn@shorts
111 \def\syn@shorts{\def\textbar{\hbox{$|$}}\@@syn@shorts}
112
113 %% Collect super- and subscripts. (Note that underscores are active for the
114 %% most part.) When we're done, end maths mode if we entered it
115 %% conditionally.
116 \def\@scripts{\futurelet\@ch\@scripts@i}
117 \begingroup\lccode`\~=`\_\lowercase{\endgroup
118 \def\@scripts@i{\if1\ifx\@ch~1\else\ifx\@ch_1\else\ifx\@ch^1\else0\fi\fi\fi%
119 \expandafter\@scripts@ii\else\expandafter\m@maybe@end\fi}}
120 \def\@scripts@ii#1#2{\m@maybe#1{#2}\@scripts}
121
122 %% Doubling characters, maybe. Either way, chain onto \@scripts.
123 \def\dbl@maybe#1{\let\@tempa#1\futurelet\@ch\dbl@maybe@i}
124 \def\dbl@maybe@i{\m@maybe\ifx\@ch\@tempa\@tempa\!\@tempa%
125 \expandafter\@firstoftwo\expandafter\@scripts%
126 \else\@tempa\expandafter\@scripts\fi}
127
128 %% Lookahead without eating spaces.
129 \def\@ifnextchar@preserve#1#2#3{%
130 \let\want@= #1\def\@tempa{#2}\def\@tempb{#3}%
131 \futurelet\nch@\@ifnch@p%
132 }
133 \def\@ifnch@p{%
134 \ifx\want@\nch@\expandafter\@tempa\else\expandafter\@tempb\fi}
135
136 %% Extra syntax for Lisp templates. These produce the maths-font versions of
137 %% characters, which should contrast well against the sans face used for
138 %% literals.
139 \atdef [{\dbl@maybe[}
140 \atdef ]{\dbl@maybe]}
141 \atdef {{\m@maybe\{\@scripts}
142 \atdef }{\m@maybe\}\@scripts}
143 \atdef ({\m@maybe(\@scripts}
144 \atdef ){\m@maybe)\@scripts}
145 \atdef !{\m@maybe|\@scripts}
146
147 \def\returns{\m@maybe\longrightarrow\m@maybe@end\hspace{0.5em}\ignorespaces}
148 \def\nlret{\\\hspace{4em}\returns}
149 \atdef >{\leavevmode\unskip\hspace{0.5em}\returns}
150
151 %% Extra syntax for common tokens.
152 \atdef ~{\textasciitilde}
153 \atdef -{\leavevmode\hbox\bgroup\futurelet\ch@\@dash}
154 \def\@dash{%
155 \ifx\ch@>%
156 --\raisebox{.4pt}{>}%
157 \def\next@{\@firstoftwo{\egroup\penalty200\relax}}%
158 \else\ifx\ch@-%
159 --\,%
160 \def\next@{\@firstoftwo{\futurelet\ch@\@dash}}%
161 \else%
162 --%
163 \let\next@\egroup%
164 \fi\fi
165 \next@%
166 }
167
168 %% Comment setting.
169 \def\comment#1{\mbox{\normalfont\itshape\/#1\/}}
170 \atdef /*#1*/{/*\comment{#1}*/}
171 \def\@semis;{\@ifnextchar@preserve;{;\@semis}\@semicomment}
172 \def\@semicomment#1\\{\comment{#1}\\}
173 \atdef ;{;\@semis;}
174
175 %% Put a chunk of text in a box.
176 \newenvironment{boxy}[1][\q@]{%
177 \savenotes%
178 \dimen@\linewidth\advance\dimen@-1.2pt\advance\dimen@-2ex%
179 \medskip%
180 \vbox\bgroup\hrule\hbox\bgroup\vrule%
181 \vbox\bgroup\vskip1ex\hbox\bgroup\hskip1ex\minipage\dimen@%
182 \def\@temp{#1}\ifx\@temp\q@\else\leavevmode{\headfam\bfseries#1\quad}\fi%
183 }{%
184 \endminipage\hskip1ex\egroup\vskip1ex\egroup%
185 \vrule\egroup\hrule\egroup%
186 \medskip%
187 \spewnotes%
188 }
189
190 %%%--------------------------------------------------------------------------
191 %%% Environment for setting programs.
192
193 %% Save `\kill' so that `longtable' won't clobber it.
194 \let\prog@@kill\kill
195
196 %% Main guts of `prog' and `nprog'.
197 \def\@prog{%
198 \let\prog@@cr\@tabcr%
199 \let\@tabcr\@progcr%
200 \let\kill\prog@@kill%
201 \codeface%
202 \tabbing%
203 }
204
205 %% Newlines: called by `\\' within a `prog'.
206 %%
207 %% \\ newline without following break
208 %% \\[SKIP] newline /with/ break and vertical glue
209 %% \\*[SKIP] newline without break, with optional glue
210 %% \\+ newline with break and a vertical gap
211 %% \\- newline without break, with a tiny gap
212 \def\@progcr{\futurelet\@tempa\@progcr@i}
213 \def\@progcr@i{%
214 \ifx\@tempa\@sptoken\let\next@\@progcr@sp\else
215 \if1\ifx\@tempa[1\else
216 \ifx\@tempa*1\else
217 0\fi\fi
218 \let\next@\prog@@cr\else
219 \if1\ifx\@tempa+1\else
220 \ifx\@tempa-1\else
221 0\fi\fi
222 \let\next@\@progcr@ii\else
223 \let\next@\@progcr@a\fi\fi\fi
224 \next@}
225 \def\@progcr@a{\prog@@cr*{}\ignorespaces}
226 \def\@progcr@ii#1{\csname @progcr@#1\endcsname\ignorespaces}
227 \@namedef{@progcr@+}{\prog@@cr[\medskipamount]}
228 \@namedef{@progcr@-}{\prog@@cr*[\jot]}
229 {\def\:{\gdef\@progcr@sp}\: {\@progcr}} % \@progcr@sp eats space and recurses
230
231 %% Set a program in `codeface', with implicit tabbing and other toys.
232 %% Newlines are explicit, because otherwise I need comments in weird places
233 %% to make the vertical spacing come out properly. You can write
234 %% `\obeylines' if you really want to.
235 \def\prog{\quote\@prog}
236 \def\endprog{\endtabbing\endquote}
237
238 %% Like `prog', but without indenting the code. Use this within environments
239 %% which already set their contents out from the body text in some
240 %% distinctive way.
241 \let\nprog\@prog
242 \let\endnprog\endtabbing
243
244 %% Indent the following material. Cancel using `\-'.
245 \def\ind{\quad\=\+\kill}
246
247 %% Show a backslash by the right-hand margin; for multiline macros etc.
248 \def\macsl{\`\textbackslash\hskip\leftmargin}
249
250 %% \maplist{THING}{{ITEM}...}: Invoke THING{ITEM} for each ITEM in turn.
251 \def\maplist#1#2{\map@i{#1}#2\q@}
252 \def\map@i#1{\def\next@{\map@ii{#1}}\futurelet\ch@\next@}
253 \def\map@ii#1{\ifx\ch@\q@\expandafter\@gobble%
254 \else\def\next@{\map@iii{#1}}\expandafter\next@\fi}
255 \def\map@iii#1#2{#1{#2}\map@i{#1}}
256
257 %% \crossproduct{THING}{{LIST}...} where each LIST is {ITEM}...
258 %% For each possible way of selecting one ITEM from each LIST, in order,
259 %% invoke THING{{ITEM}...}
260 \toksdef\cprod@new=0
261 \toksdef\cprod@old=2
262 \toksdef\cprod@head=4
263 \toksdef\cprod@tail=6
264 \def\crossproduct#1#2{%
265 \cprod@new{{}}%
266 \maplist{\cprod@f{#1}}{#2}%
267 \cprod@head{#1}%
268 \edef\next@{\noexpand\maplist{\the\cprod@head}{\the\cprod@new}}
269 \next@%
270 }
271 \def\cprod@f#1#2{%
272 \cprod@old\cprod@new\cprod@new{}%
273 \maplist\cprod@g{#2}%
274 }
275 \def\cprod@g#1{%
276 \cprod@head{#1}%
277 \expandafter\maplist\expandafter\cprod@h\expandafter{\the\cprod@old}%
278 }
279 \def\cprod@h#1{%
280 \cprod@tail{#1}%
281 \cprod@new\expandafter{\the\expandafter\cprod@new\expandafter{%
282 \the\expandafter\cprod@tail\the\cprod@head}}%
283 }
284
285 %%%--------------------------------------------------------------------------
286 %%% Machinery for describing functions, etc.
287
288 %% \definedescribecategory{CAT}[KIND]{NAME}
289 %%
290 %% Define a category of things to document. CAT is a short label identifying
291 %% the category to `\describe', `\descref', and friends. The NAME is the
292 %% text to show in the description headline; it is a macro body which is
293 %% passed an argument `#1' that applies a modifier to some portion of the
294 %% text.
295 %%
296 %% The KIND allows additional arguments to be collected, included in label
297 %% strings, and mentioned in the index. The default is `plain'.
298 \def\definedescribecategory#1{%
299 \@ifnextchar[{\def@desc{#1}}{\def@desc{#1}[plain]}}
300 \def\def@desc#1[#2]#3{\@namedef{cat!#1}##1{#3}\@namedef{catsw!#1}{#2}}
301
302 %% \describecategoryname[MOD]{CAT}
303 %%
304 %% Typeset the category name for CAT, modified by MOD.
305 \def\describecategoryname{\@ifnextchar[\@descname@i{\@descname@i[]}}
306 \def\@descname@i[#1]#2{%
307 \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname%
308 \expandafter\let\expandafter\@tempb\csname modcat/#1\endcsname%
309 \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi}
310
311 %% Call a modifier method.
312 \def\@mod@dispatch#1#2{\csname #1/#2\endcsname}
313
314 %% Call a description method given the category.
315 \def\@desc@dispatch#1#2{%
316 \csname #1/%
317 \expandafter\ifx\csname catsw!#2\endcsname\relax plain%
318 \else \csname catsw!#2\endcsname \fi%
319 \endcsname%
320 }
321
322 %% Modifier methods for the default `plain' modifier.
323 \@namedef{modcat/plain}#1{#1}
324 \@namedef{modlabel/plain}#1{#1}
325 \@namedef{modindex/plain}#1{#1@\noexpand\code{#1}}
326
327 %% Modifier methods for `setf'. The name text prefixes the relevant word
328 %% with `setf-'.
329 \@namedef{modcat/setf}#1{\code{setf}-#1}
330 \@namedef{modlabel/setf}#1{setf/#1}
331 \@namedef{modindex/setf}#1{#1@\noexpand\code{#1}}
332
333 %% Modifier methods for words with *earmuffs*. Sort into the index without
334 %% the earmuffs.
335 \@namedef{modcat/muffs}#1{#1}
336 \@namedef{modlabel/muffs}#1{#1}
337 \@namedef{modindex/muffs}#1{\@unmuff#1@\noexpand\code{#1}}
338 \def\@unmuff*#1*{#1}
339
340 %% Modifier methods for :keywords. Sort into the index without the `:'.
341 \@namedef{modcat/kwd}#1{#1}
342 \@namedef{modlabel/kwd}#1{#1}
343 \@namedef{modindex/kwd}#1{\@gobble#1@\noexpand\code{#1}}
344
345 %% Category-kind methods for plain categories.
346 \@namedef{descargs/plain}#1{#1{}}
347 \@namedef{desclabel/plain}#1#2#3{#2:\@mod@dispatch{modlabel}{#1}{#3}}
348 \@namedef{descindex/plain}#1#2#3{%
349 \@mod@dispatch{modindex}{#1}{#3}!%
350 \protect\describecategoryname[#1]{#2}%
351 }
352
353 %% Category-kind methods for `method' categories. Collect an extra argument
354 %% listing the specializers: include them in the label, and typeset them in
355 %% the index.
356 \def\fmtspecs#1#2{%
357 \if!#2!\else\count@\z@\toks@{}#1\fmtspecs@i#2,\q@,\fi}
358 \def\fmtspecs@i#1,{%
359 \def\@tempa{#1}%
360 \ifx\@tempa\q@%
361 \ifcase\count@(no args?!)%
362 \or% nothin' doin
363 \or \space and %
364 \else, and %
365 \fi%
366 \the\toks@%
367 \else%
368 \ifnum\count@>\@ne, \fi%
369 \the\toks@%
370 \toks@{\code{#1}}\advance\count@\@ne%
371 \expandafter\fmtspecs@i%
372 \fi%
373 }
374 \@namedef{descargs/method}#1#2{#1{{#2}}}
375 \@namedef{desclabel/method}#1#2#3#4%
376 {#2:\@mod@dispatch{modlabel}{#1}{#4}(#3)}
377 \@namedef{descindex/method}#1#2#3#4{%
378 \@mod@dispatch{modindex}{#1}{#4}!%
379 \protect\describecategoryname[#1]{#2}%
380 \protect\fmtspecs{ specialized at }{#3}%
381 }
382
383 %% Some magic strings.
384 \def\q@{\q@}
385 \def\@setf{setf}
386 \def\@starstar{**}
387
388 %% \parse@dhd{NEXT}[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
389 %%
390 %% Parse the arguments for a description header, and call
391 %%
392 %% NEXT{MOD}{CAT}{{...}...}{NAME}{SYNOPSIS}
393 %%
394 %% Here, {...}... represents the additional category-kind arguments. See
395 %% `describe' for what all of this means.
396 \def\parse@dhd#1{% {NEXT}
397 \@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
398 \def\parse@dhd@a#1[#2]#3{% {NEXT}[MOD]{CAT}
399 \@desc@dispatch{descargs}{#3}{\parse@dhd@ab{#1}{#2}{#3}}}
400 \def\parse@dhd@ab#1#2#3#4{% {NEXT}{MOD}{CAT}{{...}...}
401 \@ifnextchar[{\parse@dhd@ac{#1}{#2}{#3}{#4}}{\parse@dhd@ad{#1}{#2}{#3}{#4}}}
402 \def\parse@dhd@ac#1#2#3#4[#5]#6{% {NEXT}{MOD}{CAT}{{...}...}[NAME]{SYNOPSIS}
403 #1{#2}{#3}{#4}{#5}{#6}}
404 \def\parse@dhd@ad#1#2#3#4#5{% {NEXT}{MOD}{CAT}{{...}...}{NAME [ARGS...]}
405 \parse@dhd@ae{#1}{#2}{#3}{#4}{#5}#5 \q@}
406 \def\parse@dhd@ae#1#2#3#4#5#6 #7\q@{%
407 % {NEXT}{MOD}{CAT}{{...}...}{SYNSOPSIS}NAME [ARGS...]\q@
408 #1{#2}{#3}{#4}{#6}{#5}}
409
410 \def\parse@dhd@c#1#2{% {NEXT}{CAT}
411 \@desc@dispatch{descargs}{#2}{\parse@dhd@cb{#1}{#2}}}
412 \def\parse@dhd@cb#1#2#3{% {NEXT}{CAT}{{...}...}
413 \@ifnextchar[{\parse@dhd@cc{#1}{#2}{#3}}{\parse@dhd@cd{#1}{#2}{#3}}}
414 \def\parse@dhd@cc#1#2#3[#4]#5{% {NEXT}{CAT}{{...}...}[NAME]{SYNOPSIS}
415 #1{plain}{#2}{#3}{#4}{#5}}
416 \def\parse@dhd@cd#1#2#3#4{% {NEXT}{CAT}{{...}...}{SYNOPSIS}
417 \parse@dhd@ce{#1}{#2}{#3}{#4}#4 \q@}
418 \def\parse@dhd@ce#1#2#3#4#5 #6\q@{%
419 % {NEXT}{CAT}{{...}...}{SYNOPSIS}NAME [ARGS...]\q@
420 \def\temp@{#5}%
421 \ifx\@setf\temp@\def\next@{\parse@dhd@csetf{#1}{#2}{#3}{#4}#6 \q@}%
422 \else\def\temp@##1##2*##3\q@{\def\temp@{##1##3}}\temp@#5*\q@%
423 \ifx\temp@\@starstar\def\next@{#1{muffs}{#2}{#3}{#5}{#4}}%
424 \else\def\temp@##1##2\q@{\def\temp@{##1}}\temp@#5\q@%
425 \if:\temp@\def\next@{#1{kwd}{#2}{#3}{#5}{#4}}%
426 \else\def\next@{#1{plain}{#2}{#3}{#5}{#4}}\fi\fi\fi%
427 \next@%
428 }
429 \def\parse@dhd@csetf#1#2#3#4(#5 #6\q@{%
430 % {NEXT}{CAT}{{...}...}{SYNOPSIS}(NAME [ARGS...])\q@
431 #1{setf}{#2}{#3}{#5}{#4}}
432
433 %% \dhead[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
434 %% \dhead*[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
435 %%
436 %% Typeset a description head. Use this within the first argument of
437 %% `describe*'; see `describe' for the details.
438 %%
439 %% With `*', don't set labels or add items to the index.
440 \newif\if@dheadfirst
441 \newif\if@dheadindex
442 \def\dhead{\@ifstar%
443 {\parse@dhd{\global\@dheadindexfalse\dhead@}}%
444 {\parse@dhd{\global\@dheadindextrue\dhead@}}}
445 \def\dhead@#1#2#3#4#5{% {MOD}{CAT}{{...}...}{NAME}{SYNOPSIS}
446 \if@dheadfirst\global\@dheadfirstfalse\else\relax\\*[\smallskipamount]\fi%
447 \if@dheadindex%
448 \phantomsection%
449 {\let\protect\@empty\let\@uscore\relax%
450 \edef\temp@{\@desc@dispatch{desclabel}{#2}{#1}{#2}#3{#4}}%
451 \def\@uscore{_\@gobble}\expandafter\message\expandafter{\temp@}%
452 \def\@uscore{-\@gobble}\expandafter\label\expandafter{\temp@}}%
453 {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
454 \protected@edef\@tempa##1{%
455 \noexpand\index{\@desc@dispatch{descindex}{#2}{#1}{#2}#3{#4}##1}}%
456 \toks@\expandafter{\@tempa{|)}}%
457 \toks\tw@\expandafter{\after@desc}%
458 \xdef\after@desc{\the\toks\tw@\the\toks@}%
459 \@tempa{|(}}%
460 \fi%
461 \rlap{\hb@xt@\linewidth{\hfil\normalfont\bfseries
462 [\describecategoryname[#1]{#2}]}}%
463 #5%
464 }
465
466 %% Main guts of a description environment. The argument here typesets the
467 %% header line(s).
468 \def\desc@begin#1{%
469 \let\saved@after@desc\after@desc%
470 \gdef\after@desc{}%
471 \normalfont%
472 \if@nobreak\else\par\goodbreak\fi%
473 \global\@dheadfirsttrue%
474 \begingroup%
475 \let\@endparenv\relax%
476 \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
477 \@prog#1\endtabbing%
478 \endgroup%
479 \penalty\@M\@afterheading%
480 \list{}{\rightmargin\z@\topsep\z@}\item%
481 }
482 \def\desc@end{\endlist\after@desc\global\let\after@desc\saved@after@desc}
483
484 %% \begin{describe}[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
485 %% ...
486 %% \end{describe}
487 %%
488 %% Describe some kind of program object. The CAT names the category of thing
489 %% being described -- this will be shown in the header, and index. The
490 %% SYNOPSIS is an implicit `prog' environment in which invoking the thing can
491 %% be summarized.
492 %%
493 %% The {...}... are any additional arguments required by the category's kind
494 %% (e.g., method specializers).
495 %%
496 %% The NAME is the name of the thing, which ends up in the index and
497 %% cross-reference label. If omitted, it defaults to the first word of the
498 %% SYNOPSIS, except that there are some special cases.
499 %%
500 %% The MOD is the modifier to apply. If omitted, it will usually default to
501 %% `plain', but in the absence of a NAME, some kinds of synopses are
502 %% recognized specially:
503 %%
504 %% * `setf (NAME ...) ...': selects NAME, and defaults MOD to `setf'.
505 %%
506 %% * `*NAME*': defaults MOD to `muffs'.
507 %%
508 %% * `:NAME': defaults MOD to `kwd'.
509 \def\describe{\parse@dhd\desc@}
510 \def\desc@#1#2#3#4#5{%
511 \global\@dheadindextrue%
512 \desc@begin{\dhead@{#1}{#2}{#3}{#4}{#5}}%
513 }
514 \let\enddescribe\desc@end
515
516 %% \begin{describe*}
517 %% {\dhead[MOD]{CAT}{...}...[NAME]{SYNOPSIS}
518 %% ...}
519 %% ...
520 %% \end{describe*}
521 %%
522 %% This is the fancy form of `describe' for describing several different
523 %% things at once.
524 \@namedef{describe*}#1{\desc@begin{#1}}
525 \expandafter\let\csname enddescribe*\endcsname\desc@end
526
527 %% \parse@dlbl{NEXT}[MOD]{CAT}{...}...{LABEL}
528 %%
529 %% Parse a description label, and call
530 %%
531 %% NEXT{MOD}{CAT}{{...}...}{LABEL}
532 %%
533 %% This handles defaulting the MOD correctly, based on the LABEL text. See
534 %% `\descref' for the details.
535 \def\parse@dlbl#1{\@ifnextchar[{\parse@dlbl@a{#1}}{\parse@dlbl@c{#1}}}
536 \def\parse@dlbl@a#1[#2]#3{\@desc@dispatch{descargs}{#3}{#1{#2}{#3}}}
537 \def\parse@dlbl@c#1#2%
538 {\@desc@dispatch{descargs}{#2}{\parse@dlbl@cb{#1}{#2}}}
539 \def\parse@dlbl@cb#1#2#3#4{%
540 \def\temp@##1##2*##3\q@{\def\temp@{##1##3}}\temp@#4*\q@%
541 \ifx\temp@\@starstar\def\next@{#1{muffs}{#2}{#3}{#4}}%
542 \else\def\temp@##1##2\q@{\def\temp@{##1}}\temp@#4\q@%
543 \if:\temp@\def\next@{#1{kwd}{#2}{#3}{#4}}
544 \else\def\next@{#1{plain}{#2}{#3}{#4}}\fi\fi%
545 \next@%
546 }
547
548 %% \descref[MOD]{CAT}{...}...{LABEL}[TEXT]
549 %% \descref*[MOD]{CAT}{...}...{LABEL}
550 %%
551 %% Typesets a cross-reference to a described thing. The CAT names the
552 %% category of thing being described, and the LABEL names the specific thing.
553 %%
554 %% The {...}... are any additional arguments required by the category's kind
555 %% (e.g., method specializers).
556 %%
557 %% The MOD is the modifier to apply, similar (but subtly different from) to
558 %% the `describe' environment. If omitted, it will usually default to
559 %% `plain', but in the absence of a NAME, some kinds of synopses are
560 %% recognized specially:
561 %%
562 %% * `*NAME*': defaults MOD to `muffs'.
563 %%
564 %% * `:NAME': defaults MOD to `kwd'.
565 %%
566 %% (`setf' is /not/ specially detected here. Write an explicit `setf'
567 %% modifier if necessary, because it's no more typing.)
568 %%
569 %% Usually a page-number cross-reference is included, so as to help readers
570 %% of a dead-tree copy; this is suppressed by the `*' version.
571 \def\descref{\@ifstar%
572 {\parse@dlbl{\descref@i\relax\@gobble\relax}}%
573 {\parse@dlbl{\descref@i{ (}\autopageref)}}}
574 \def\descref@i#1#2#3#4#5#6#7{\@ifnextchar@preserve[%
575 % {PGA}{PGB}{PGC}{MOD}{CAT}{{...}...}{LABEL}
576 {\descref@ii{#1}{#2}{#3}{#4}{#5}{#6}{#7}}%
577 {\descref@iii{#1}{#2}{#3}{#4}{#5}{#6}{#7}{}}}
578 \def\descref@ii#1#2#3#4#5#6#7[#8]%
579 % {PGA}{PGB}{PGC}{MOD}{CAT}{{...}...}{LABEL}[AFTER]
580 {\descref@iii{#1}{#2}{#3}{#4}{#5}{#6}{#7}{ #8}}
581 \def\descref@iii#1#2#3#4#5#6#7#8{%
582 % {PGA}{PGB}{PGC}{MOD}{CAT}{{...}...}{LABEL}{AFTER}
583 \begingroup%
584 \let\protect\@empty\def\@uscore{-\@gobble}%
585 \edef\temp@{\@desc@dispatch{desclabel}{#5}{#4}{#5}#6{#7}}%
586 \edef\next@##1##2##3{\endgroup%
587 \noexpand\hyperref[\temp@]{##1}##2{\temp@}##3}%
588 \next@{\code{#7}}{#8#1#2}{#3}%
589 }
590
591 %% \descindex[MOD]{CAT}{...}...{LABEL}[SUFFIX]
592 %%
593 %% Set a label and index entry here, as if for a description. The CAT names
594 %% the category of thing being described, and the LABEL names the specific
595 %% thing, as for `\descref'. The {...}... are any additional arguments
596 %% required by the category's kind (e.g., method specializers). The MOD is
597 %% the modifier to apply; see `\descref' for the details.
598 %%
599 %% The SUFFIX is appended to the index-entry text; by default it is empty.
600 %% Useful values are `|(' and `|)' to set ranges.
601 \def\descindex{\parse@dlbl\descindex@i}
602 \def\descindex@i#1#2#3#4{\@ifnextchar[%
603 {\descindex@ii{#1}{#2}{#3}{#4}}%
604 {\descindex@ii{#1}{#2}{#3}{#4}[]}}
605 \def\descindex@ii#1#2#3#4[#5]{%
606 {\begingroup\lccode`\~=`\_\lowercase{\endgroup\def~{_}}%
607 \protected@edef\@tempa{%
608 \noexpand\index{\@desc@dispatch{descindex}{#2}{#1}{#2}#3{#4}#5}}%
609 \@tempa}%
610 }
611
612 %% \desclabel[MOD]{CAT}{...}...{LABEL}[INDEX-SUFFIX]
613 %%
614 %% Set a label and index entry here, as if for a description. The CAT names
615 %% the category of thing being described, and the LABEL names the specific
616 %% thing, as for `\descref'. The {...}... are any additional arguments
617 %% required by the category's kind (e.g., method specializers). The MOD is
618 %% the modifier to apply; see `\descref' for the details.
619 %%
620 %% This will also add an index entry, as for `\descindex'; the INDEX-SUFFIX
621 %% argument has the same effect as its SUFFIX argument.
622 \def\desclabel{\parse@dlbl\desclabel@i}
623 \def\desclabel@i#1#2#3#4{%
624 \begingroup%
625 \let\protect\@empty\def\@uscore{-\@gobble}%
626 \edef\@tempa{\@desc@dispatch{desclabel}{#2}{#1}{#2}#3{#4}}%
627 \phantomsection\label{\@tempa}%
628 \endgroup%
629 \descindex@i{#1}{#2}{#3}{#4}%
630 }
631
632 %% Description categories.
633 \definedescribecategory{sym}{symbol}
634 \definedescribecategory{fun}{#1{function}}
635 \definedescribecategory{gf}{generic #1{function}}
636 \definedescribecategory{msg}{message}
637 \definedescribecategory{var}{variable}
638 \definedescribecategory{modvar}{module variable}
639 \definedescribecategory{const}{constant}
640 \definedescribecategory{meth}[method]{primary #1{method}}
641 \definedescribecategory{ar-meth}[method]{\code{:around} #1{method}}
642 \definedescribecategory{be-meth}[method]{\code{:before} #1{method}}
643 \definedescribecategory{af-meth}[method]{\code{:after} #1{method}}
644 \definedescribecategory{cls}{class}
645 \definedescribecategory{rst}{restart}
646 \definedescribecategory{ty}{type}
647 \definedescribecategory{mac}{#1{macro}}
648 \definedescribecategory{feat}{feature macro}
649 \definedescribecategory{lmac}{local #1{macro}}
650 \definedescribecategory{parse}{parser spec}
651 \definedescribecategory{parseform}{parser form}
652 \definedescribecategory{opt}{option handler}
653 \definedescribecategory{optmac}{option macro}
654 \definedescribecategory{plug}{pluggable parser}
655
656 %%%----- That's all, folks --------------------------------------------------
657 \endinput