doc/sod.sty: Overhaul `describe' environment.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 30 Aug 2015 09:58:38 +0000 (10:58 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 20 Sep 2015 09:43:26 +0000 (10:43 +0100)
  * Split out the machinery which parses and sets the heading to make a
    new environment `describe*' which can have multiple headings.

  * Remove the `tabular' layer in the headings, by using `\rlap'
    instead.

  * Fix spacing around the header lines.

  * Insert penalties and drive the `\if@nobreak' and `\@afterheading'
    machinery correctly so that we mostly don't get bad page breaks.

doc/sod.sty

index ff63620..71b72fe 100644 (file)
 \def\nlret{\\\hspace{4em}\returns}
 
 \def\q@{\q@}
-\newenvironment{describe}[3][\q@]{%
+\def\parse@dhd#1{\@ifnextchar[{\parse@dhd@a{#1}}{\parse@dhd@c{#1}}}
+\def\parse@dhd@a#1[#2]{#1{#2}}
+\def\parse@dhd@c#1#2#3{\parse@dhd@cc{#1}{#2}{#3}#3 \q@}
+\def\parse@dhd@cc#1#2#3#4 #5\q@{#1{#4}{#2}{#3}}
+
+\newif\if@dheadfirst
+\def\dhead{\parse@dhd\dhead@}
+\def\dhead@#1#2#3{%
+  \if@dheadfirst\global\@dheadfirstfalse\else\relax\\[\smallskipamount]\fi%
+  {\let\protect\@empty\def\@uscore{_\@gobble}\message{#2:#1}%
+   \def\@uscore{-\@gobble}\edef\@tempa{\noexpand\label{#2:#1}}\@tempa}%
+  \rlap{\rightline{\normalfont\bfseries[\describecategoryname{#2}]}}%
+  #3%
+}
+
+\def\desc@begin#1{%
   \normalfont%
-  \par\goodbreak%
-  \vspace{\bigskipamount}%
-  \setbox\z@\hbox{\bfseries[\describecategoryname{#2}]}%
-  \dimen@\linewidth\advance\dimen@-\wd\z@%
-  \def\@temp##1 ##2\q@{%
-    \message{#2:##1}%
-    {\def\@uscore####1{-}\edef\@tempb{\noexpand\label{#2:##1}}\@tempb}%
-  }%
-  \def\@tempa{#1}\ifx\@tempa\q@\@temp#3 \q@\else\@temp{#1} \q@\fi%
-  \edef\@temp{{\the\linewidth}{@{}p{\the\dimen@}%
-      @{\extracolsep{\fill}}l@{\extracolsep{0pt}}}}%
-  \noindent\csname tabular*\expandafter\endcsname\@temp%
-  \tabbing\codeface#3\endtabbing&\unhbox\z@\\\endtabular%
-%  \@afterheading%
-  \list{}{\rightmargin\z@}\item%
-}{%
-  \endlist%
+  \if@nobreak\else\par\goodbreak\fi%
+  \global\@dheadfirsttrue%
+  \begingroup%
+    \codeface%
+    \let\@endparenv\relax%
+    \clubpenalty\@M \widowpenalty\@M \interlinepenalty50%
+    \tabbing#1\endtabbing%
+  \endgroup%
+  \penalty\@M\@afterheading%
+  \list{}{\rightmargin\z@\topsep\z@}\item%
 }
+\let\desc@end\endlist
+
+\@namedef{describe*}#1{\desc@begin{#1}}
+\expandafter\let\csname enddescribe*\endcsname\desc@end
+\def\describe{\parse@dhd\desc@}
+\def\desc@#1#2#3{\desc@begin{\dhead@{#1}{#2}{#3}}}
+\let\enddescribe\desc@end
 
 %%%----- That's all, folks --------------------------------------------------
 \endinput