X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/a6ec8b3f5bd19ad4a2a6fc950639cdff196eea2c..db960992be5d9f269f140ac594de77301c54d7c6:/doc/sod.sty

diff --git a/doc/sod.sty b/doc/sod.sty
index 4d2f407..592ff5c 100644
--- a/doc/sod.sty
+++ b/doc/sod.sty
@@ -73,7 +73,8 @@
 %% Diagram settings.
 \tikzset{
   every picture/.style={>=stealth, thick},
-  lit/.style={font=\sffamily}
+  lit/.style={font=\sffamily},
+  dashed/.style={dash pattern=on 2.19pt off 2.19pt}
 }
 
 %% Metavariables are italics without decoration.
@@ -106,8 +107,8 @@
 
 %% Intercept grammar typesetting and replace the vertical bar with the
 %% maths-font version.
-\let\@@grammar\grammar
-\def\grammar{\def\textbar{\hbox{$|$}}\@@grammar}
+\let\@@syn@shorts\syn@shorts
+\def\syn@shorts{\def\textbar{\hbox{$|$}}\@@syn@shorts}
 
 %% Collect super- and subscripts.  (Note that underscores are active for the
 %% most part.)  When we're done, end maths mode if we entered it
@@ -189,8 +190,17 @@
 %%%--------------------------------------------------------------------------
 %%% Environment for setting programs.
 
+%% Save `\kill' so that `longtable' won't clobber it.
+\let\prog@@kill\kill
+
 %% Main guts of `prog' and `nprog'.
-\def\@prog{\let\prog@@cr\@tabcr\let\@tabcr\@progcr\codeface\tabbing}
+\def\@prog{%
+  \let\prog@@cr\@tabcr%
+  \let\@tabcr\@progcr%
+  \let\kill\prog@@kill%
+  \codeface%
+  \tabbing%
+}
 
 %% Newlines: called by `\\' within a `prog'.
 %%
@@ -237,6 +247,41 @@
 %% Show a backslash by the right-hand margin; for multiline macros etc.
 \def\macsl{\`\textbackslash\hskip\leftmargin}
 
+%% \maplist{THING}{{ITEM}...}: Invoke THING{ITEM} for each ITEM in turn.
+\def\maplist#1#2{\map@i{#1}#2\q@}
+\def\map@i#1{\def\next@{\map@ii{#1}}\futurelet\ch@\next@}
+\def\map@ii#1{\ifx\ch@\q@\expandafter\@gobble%
+  \else\def\next@{\map@iii{#1}}\expandafter\next@\fi}
+\def\map@iii#1#2{#1{#2}\map@i{#1}}
+
+%% \crossproduct{THING}{{LIST}...} where each LIST is {ITEM}...
+%% For each possible way of selecting one ITEM from each LIST, in order,
+%% invoke THING{{ITEM}...}
+\toksdef\cprod@new=0
+\toksdef\cprod@old=2
+\toksdef\cprod@head=4
+\toksdef\cprod@tail=6
+\def\crossproduct#1#2{%
+  \cprod@new{{}}%
+  \maplist{\cprod@f{#1}}{#2}%
+  \cprod@head{#1}%
+  \edef\next@{\noexpand\maplist{\the\cprod@head}{\the\cprod@new}}
+  \next@%
+}
+\def\cprod@f#1#2{%
+  \cprod@old\cprod@new\cprod@new{}%
+  \maplist\cprod@g{#2}%
+}
+\def\cprod@g#1{%
+  \cprod@head{#1}%
+  \expandafter\maplist\expandafter\cprod@h\expandafter{\the\cprod@old}%
+}
+\def\cprod@h#1{%
+  \cprod@tail{#1}%
+  \cprod@new\expandafter{\the\expandafter\cprod@new\expandafter{%
+      \the\expandafter\cprod@tail\the\cprod@head}}%
+}
+
 %%%--------------------------------------------------------------------------
 %%% Machinery for describing functions, etc.
 
@@ -261,7 +306,14 @@
 \def\@descname@i[#1]#2{%
   \expandafter\let\expandafter\@tempa\csname cat!#2\endcsname%
   \expandafter\let\expandafter\@tempb\csname modcat/#1\endcsname%
-  \ifx\@tempa\relax\@tempb{#2}\else\@tempa\@tempb\fi}
+  \ifx\@tempa\relax\PackageError{sod}{unknown description category `#2'}%
+    {I don't know what `#2' means as a thing you might try to\MessageBreak
+     document.  Maybe you mistyped it, or forgot to say\MessageBreak
+     `\protect\definedescribecategory' for it.  For now I'm going\MessageBreak
+     just use the literal string `#2' and hope that doesn't look\MessageBreak
+     too terrible.}%
+    \@tempb{#2}%
+  \else\@tempa\@tempb\fi}
 
 %% Call a modifier method.
 \def\@mod@dispatch#1#2{\csname #1/#2\endcsname}
@@ -538,9 +590,9 @@
   \begingroup%
     \let\protect\@empty\def\@uscore{-\@gobble}%
     \edef\temp@{\@desc@dispatch{desclabel}{#5}{#4}{#5}#6{#7}}%
-    \hyperref[\temp@]{\code{#7}}#8%
-    #1#2{\temp@}#3%
-  \endgroup%
+    \edef\next@##1##2##3{\endgroup%
+      \noexpand\hyperref[\temp@]{##1}##2{\temp@}##3}%
+  \next@{\code{#7}}{#8#1#2}{#3}%
 }
 
 %% \descindex[MOD]{CAT}{...}...{LABEL}[SUFFIX]
