chiark / gitweb /
mdwtools.tex, *.dtx: Provide a hack for setting `description' labels.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 7 Sep 2020 16:24:40 +0000 (17:24 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 7 Sep 2020 16:33:19 +0000 (17:33 +0100)
LaTeX has a bug (which I'm sure can't be fixed without unacceptable
compatibility lossage) which starts setting `description' list labels
`\labelsep' too far to the left, so the `\makelabel' implementation
compensates by adding a `\labelsep' of horizontal space before the
actual label text.  The array rule-spec list overrides `\makelabel' to
reduce typing, and therefore must duplicate this countermeasure.

My `strayman' document class, and the `mdwlist' package in this
collection, both correct this bug, so if either of those is loaded then
the list ends up with the labels too far to the right.  (This is, of
course, the very compatibility problem that prevents the bug from being
fixed upstream.)

Provide a command which detects (hackily) either of these two situations
and sets a label with the correct spacing, and use it everywhere.

cmtt.dtx
mdwmath.dtx
mdwtab.dtx
mdwtools.tex
poetry.dtx
syntax.dtx

index 45b4be0566548fb1a5a2bebdcfc28a7bc1f277bb..f09aeeb791495a3b11de8e3bbb9b1671351792d6 100644 (file)
--- a/cmtt.dtx
+++ b/cmtt.dtx
 % Typewriter font, since it doesn't allow hyphenation by default anyway.)
 %
 % There are several files you'll need to create:
-% \begin{description} \def\makelabel#1{\hskip\labelsep\mttfamily#1\hfil}
+% \begin{description} \setdescriptionlabel{\mttfamily#1}
 %
 % \item [cmtt.sty] tells \LaTeX\ that there's a new encoding.  It also
 %       provides some options for customising some aspects of the
 % \end{description}
 %
 % The package accepts some options which may be useful:
-% \begin{description} \def\makelabel#1{\hskip\labelsep\sffamily#1\hfil}
+% \begin{description} \setdescriptionlabel{\sffamily#1}
 %
 % \item [override] overrides the meaning of the \mtt{\\ttfamily} command
 %       (and therefore also the \mtt{\\texttt} command too), making it the
index 92788ff58893f8d99be7ad6cb04f52e4f5638d46..f115aafd8018472860817982c58b1ccc558ddd3a 100644 (file)
 % The types provided (and it's easy-ish to add more) are:
 %
 % \def\ch{\char`}
-% \begin{description} \def\makelabel{\hskip\labelsep\normalfont\ttfamily}
+% \begin{description} \setdescriptionlabel{\normalfont\ttfamily#1}
 % \item [r] Right aligned equation
 % \item [c] Centre-aligned equation
 % \item [l] Left aligned equation
index 5f863b2c0136afe44bd932ef27357e129b36f303..3b090425f0f4c14e41a2755f801f4adf35a0fe7e 100644 (file)
 % |\arrayrulewidth|.  However, there's an optional argument which can contain
 % one of:
 %
-% \begin{description}
-% \renewcommand\makelabel[1]{\kern\labelsep\ttfamily#1}
+% \begin{description} \setdescriptionlabel{\ttfamily#1}
 % \item[thin] Use |\arrayrulewidth| as the line width.  This is the default.
 % \item[thick] Use |\arraythickrulewidth| as the line width.  This is the
 %   same as giving a |*| after the command.
index fbf97216ddbc9a4e3e167989814658fae290a084..7807d44481759f73078ce34decc263ec1bfd2c51 100644 (file)
@@ -36,7 +36,7 @@
 %</mdwtools>
 % \end{meta-comment}
 %
-% \CheckSum{743}
+% \CheckSum{765}
 %% \CharacterTable
 %%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
 %%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
 %    \end{macrocode}
 %
 %
+% \subsection{Custom description lists}
+%
+% For some bizarre reason, the \LaTeX\ \env{description} environment sets
+% |\itemindent| so that the label starts |\labelsep| into the left margin,
+% and the default |\makelabel| must therefore contain a hack to compensate.
+% This is fixed in the \package{strayman} document class, and by the
+% \package{mdwlist} package in this collection.  But this introduces a
+% problem: if I want to set a \env{description} list with custom labels, how
+% can I do this without messing up the spacing?
+%
+% Detection of the relevant packages is done in an awfully hacky way, because
+% \LaTeXe\ seems to go out of its way to forget which packages have been
+% loaded at |\begin{document}| time.
+%
+%    \begin{macrocode}
+\def\setdescriptionlabel#1{%
+  \if1\ifx\sectindent\xxundefined% strayman?
+      \ifx\defaultdesc\xxundefined% mdwlist?
+      1\else0\fi\else0\fi%
+    \def\makelabel##1{\hskip\labelsep\relax#1}%
+  \else%
+    \def\makelabel##1{#1}%
+  \fi%
+}
+%    \end{macrocode}
+%
+%
 % \subsection{A table environment}
 %
 % \begin{environment}{tab}
index e32439aa7e1406a342a5b3755ba81c166d2b6340..4cf859662b6007cef2e654b4a18a9206f7b4f23d 100644 (file)
 % are described below (if you're not interested in this sort of thing, skip
 % to the next section).
 %
-% \begin{description} \def\makelabel#1{\hskip\labelsep\cmd{#1}\hfil}
+% \begin{description} \setdescriptionlabel{\cmd{#1}}
 % \item [stanza] is a \LaTeX\ counter which contains the current stanza
 %       number.
 % \item [\thestanza] typesets the value of the |stanza| counter in normal
index 5b4bd94b90c124be3f5d28acb3b6a0ccfc92db64..b46298fdc3e77ab64c3a5223429067c07788d75e 100644 (file)
 %
 % You can modify the appearance of grammars using three length parameters:
 %
-% \begin{description} \def\makelabel{\hskip\labelsep\cmd}
+% \begin{description} \setdescriptionlabel{\cmd{#1}}
 %
 % \item [\grammarparsep] is the amount of space inserted between production
 %       rules.  It is a rubber length whose default value is 8\,pt, with
 %
 % The following length parameters may be altered:
 %
-% \begin{description} \def\makelabel{\hskip\labelsep\cmd}
+% \begin{description} \setdescriptionlabel{\cmd{#1}}
 %
 % \item [\sdstartspace] The length of the rule between the arrows which
 %       begin each line of the syntax diagram and the first item on the line.