From 78cdb9cc6b9784b7777438957a99611a7870b9ab Mon Sep 17 00:00:00 2001
From: Mark Wooding <mdw@distorted.org.uk>
Date: Mon, 7 Sep 2020 17:24:40 +0100
Subject: [PATCH] mdwtools.tex, *.dtx: Provide a hack for setting `description'
 labels.

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     |  4 ++--
 mdwmath.dtx  |  2 +-
 mdwtab.dtx   |  3 +--
 mdwtools.tex | 29 ++++++++++++++++++++++++++++-
 poetry.dtx   |  2 +-
 syntax.dtx   |  4 ++--
 6 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/cmtt.dtx b/cmtt.dtx
index 45b4be0..f09aeeb 100644
--- a/cmtt.dtx
+++ b/cmtt.dtx
@@ -110,7 +110,7 @@
 % 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
@@ -125,7 +125,7 @@
 % \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
diff --git a/mdwmath.dtx b/mdwmath.dtx
index 92788ff..f115aaf 100644
--- a/mdwmath.dtx
+++ b/mdwmath.dtx
@@ -318,7 +318,7 @@
 % 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
diff --git a/mdwtab.dtx b/mdwtab.dtx
index 5f863b2..3b09042 100644
--- a/mdwtab.dtx
+++ b/mdwtab.dtx
@@ -713,8 +713,7 @@
 % |\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.
diff --git a/mdwtools.tex b/mdwtools.tex
index fbf9721..7807d44 100644
--- a/mdwtools.tex
+++ b/mdwtools.tex
@@ -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
@@ -440,6 +440,33 @@
 %    \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}
diff --git a/poetry.dtx b/poetry.dtx
index e32439a..4cf8596 100644
--- a/poetry.dtx
+++ b/poetry.dtx
@@ -164,7 +164,7 @@
 % 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
diff --git a/syntax.dtx b/syntax.dtx
index 5b4bd94..b46298f 100644
--- a/syntax.dtx
+++ b/syntax.dtx
@@ -313,7 +313,7 @@
 %
 % 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
@@ -562,7 +562,7 @@
 %
 % 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.
-- 
2.11.0

