-% \begin{meta-comment}
-%
-% $Id: mdwtools.tex,v 1.2 2003/09/05 16:15:33 mdw Exp $
-%
-% Common declarations for mdwtools.dtx files
-%
-% (c) 1996 Mark Wooding
-%
-%----- Revision history -----------------------------------------------------
-%
-% $Log: mdwtools.tex,v $
-% Revision 1.2 2003/09/05 16:15:33 mdw
-% Fix title typesetting: use Oxford comma.
-%
-% Revision 1.1 2002/02/03 20:49:03 mdw
-% Checkin for new build system.
-%
-% Revision 1.4 1996/11/19 20:55:55 mdw
-% Entered into RCS
-%
-%
-% \end{meta-comment}
-%
% \begin{meta-comment} <general public licence>
%%
%% mdwtools common declarations
-%% Copyright (c) 1996 Mark Wooding
+%% Copyright (c) 1996, 2002, 2003, 2020 Mark Wooding
%%
%% This program is free software; you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%</mdwtools>
% \end{meta-comment}
%
-% \CheckSum{672}
+% \CheckSum{804}
%% \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
% everything works. It will automatically read in the licence text (from
% |gpl.tex|, and wraps some other things up.
%
-%
+%
% \subsection{Other commands}
%
% The |mdwtools.tex| file includes the \package{syntax} and \package{sverb}
% loaded is by seeing if the |\documentclass| command has been redefined
% to raise an error. This isn't too hard, really.
%
+% If my \package{strayman} document class is available, then I'd prefer to
+% use that.
+%
% \begin{macrocode}
\ifx\documentclass\@twoclasseserror\else
- \documentclass[a4paper]{ltxdoc}
+ \IfFileExists{strayman.cls}
+ {\documentclass[a4paper]{strayman}}
+ {\documentclass[a4paper]{ltxdoc}}
\ifx\doneclasses\mdw@undefined\else\doneclasses\fi
\fi
% \end{macrocode}
%
+% If I can use better fonts, then that would be nice.
+%
+% \begin{macrocode}
+\usepackage[T1]{fontenc}
+\IfFileExists{mdwfonts.sty}
+ {\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}}{}
+% \end{macrocode}
+%
% As part of my standard environment, I'll load some of my more useful
% packages. If they're already loaded (possibly with different options),
% I'll not try to load them again.
\@ifpackageloaded{sverb}{}{\usepackage{sverb}}
% \end{macrocode}
%
+% If I'm not using the \package{ltxdoc} document class then I'll need some of
+% its definitions. I've no idea why these aren't part of \package{doc}\ldots
%
+% \begin{macro}{\cmd}
+% \begin{macro}{\cs}
+% \begin{macrocode}
+\def\cmd#1{\expandafter\cmd@i\string#1\x}
+\def\cmd@i#1#2\x{\cs{#2}}
+\DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\marg}
+% \begin{macro}{\oarg}
+% \begin{macro}{\parg}
+% \begin{macrocode}
+\def\@arg#1#2#3{\texttt{#1}\meta{#2}\texttt{#3}}
+\def\marg#1{\@arg{\char`\{}{#1}{\char`\}}}
+\def\oarg#1{\@arg{[}{#1}{]}}
+\def\parg#1{\@arg{(}{#1}{)}}
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+
% \subsection{Some macros for interaction}
%
% I like the \LaTeX\ star-boxes, although it's a pain having to cope with
% names and environment names (both in the sans serif font, for now).
%
% \begin{macrocode}
-\tlet\package\textsf
-\tlet\env\textsf
+\tdef\package{\textsf}
+\tdef\env{\textsf}
% \end{macrocode}
%
% I'll define the |\<|\dots|>| shortcut for syntax items suggested in the
% \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}
\def\do##1##2{\addtocontents{##1}{\protect\end{multicols}}}%
\docontents%
\fi%
+ \ifx\backmatter\@@undefined\else\backmatter\fi%
\PrintIndex%
}
% \end{macrocode}
%
% Now to get to work. I need to keep one `lookahead' list item, and a count
% of the number of items read so far. I'll keep the lookahead item in
-% |\@nextitem| and the counter in |\count@|.
+% |\@nextitem| and the counter in |\count@|. Things are even worse because
+% the footnote symbols should appear \emph{after} the separating punctuation,
+% so we need to delay those by another cycle, hence we have |\@nextnote| and
+% |\@prevnote|.
%
% \begin{macrocode}
\count@\z@%
% The first job is to add the previous item to the title string. If this
% is the first item, though, I'll just add the appropriate \lit{The } or
% \lit{ and the } string to the title (this is stored in the |\@prefix|
-% macro).
+% macro). Also maintain a parallel version which doesn't have the footnotes
+% in: this will be suitable for a running header.
%
% \begin{macrocode}
\edef\mdw@title{%
\mdw@title%
\ifcase\count@\@prefix%
\or\@nextitem%
+ \else,\@prevnote\ \@nextitem%
+ \fi%
+ }%
+ \edef\mdw@runningtitle{%
+ \mdw@runningtitle%
+ \ifcase\count@\@prefix%
+ \or\@nextitem%
\else, \@nextitem%
\fi%
}%
% \end{macrocode}
%
-% That was rather easy. Now I'll set up the |\@nextitem| macro for the
-% next time around the loop.
+% That was rather easy. Now I'll set up the |\@previtem| and |\@nextitem|
+% macros for the next time around the loop.
%
% \begin{macrocode}
- \edef\@nextitem{%
- \protect#2{##1}%
+ \edef\@nextitem{\protect#2{##1}}%
+ \let\@prevnote\@nextnote
+ \edef\@nextnote{%
\protect\footnote{%
The \protect#2{##1} #3 is currently at version %
\mdwfileinfo{##1}{version}, dated \mdwfileinfo{##1}{date}.%
- }\space%
+ }%
}%
% \end{macrocode}
%
\edef\mdw@title{%
\mdw@title%
\ifcase\count@%
+ \or\@nextitem\@nextnote\space#3%
+ \or\@prevnote\ and \@nextitem\@nextnote\space#4%
+ \else,\@prevnote\ and \@nextitem\@nextnote\space#4%
+ \fi%
+ }%
+ \edef\mdw@runningtitle{%
+ \mdw@runningtitle%
+ \ifcase\count@%
\or\@nextitem\space#3%
\or\ and \@nextitem\space#4%
\else,\ and \@nextitem\space#4%
%
% \begin{macrocode}
\def\mdw@title{}%
+ \def\mdw@runningtitle{}%
\def\@prefix{The }%
% \end{macrocode}
%
% following hacking will do this.
%
% \begin{macrocode}
- \edef\next{\endgroup\noexpand\title{\mdw@title}}%
+ \edef\next{%
+ \endgroup%
+ \noexpand\title{\noexpand\mdw@titlehack\mdw@title}%
+ \def\noexpand\@headertitle{\mdw@runningtitle}%
+ }%
\next%
}
% \end{macrocode}
%
% \end{macro}
%
+% \begin{macro}{\mdw@titlehack}
+%
+% Wait! Did you notice that |\mdw@titlehack|? What's that about?
+%
+% It turns out that the default document classes hack the footnote insertion
+% commands to make footnote symbols take up no horizontal space in the title.
+% Apparently this makes author names look as if they're centred properly when
+% there are affiliation footnotes. Anyway, \package{doc} perpetuates this
+% silliness, but it makes a mess of the version markers I insert, so I must
+% deploy countermeasures.
+%
+% \begin{macrocode}
+\def\mdw@titlehack{\def\@makefnmark{$\m@th^{\@thefnmark}$}}
+% \end{macrocode}
+%
+% \end{macro}
%
% \subsection{Starting the main document}
%
%
% \begin{macrocode}
\begin{document}
+ \ifx\frontmatter\@@undefined\else\frontmatter\fi%
\maketitle%
% \end{macrocode}
%
%
% \begin{macrocode}
\def\do##1##2{%
- ##2%
\ifhave@multicol\addtocontents{##1}{%
\protect\begin{multicols}{2}%
\hbadness\@M%
}\fi%
+ ##2%
}%
\docontents%
% \end{macrocode}
% Input the main file now.
%
% \begin{macrocode}
+ \ifx\mainmatter\@@undefined\else\mainmatter\fi%
\DocInput{\@basefile}%
% \end{macrocode}
%