PDCFMT2—Formatting Macros

Version 2.4, last changed pdc 1995–04–06

P. Damian Cugley

1. Introduction

This document describes pdcfmt2.tex, a collection of formatting macros for plain TEX documents. For example, it defines commands for making bulleted lists, verbatim text, and generic headings. For longer documents, a higher-level ‘style file’ like pdccmdoc.tex will define commands to start sections and generate a table of contents and so on.

The definitions file and the printed documentation are both in pdcfmt2.dtx, a ‘documented TEX macros’ file* which, when processed by plain TEX, generates a fresh copy of pdcfmt2.tex in the current directory in addition to the dvi file. This ensures that the printed documentation and the code it describes are identical. The dtx file uses the mac-

ros in pdccode.tex.

The name of the macros file ends in ‘-2’ to prevent confusion with pdcfmt.tex version 1.1.10, with which it is slightly incompatible.

2. File identification

Nowadays, macro files start with some comments identifying the file.

 1 % pdcfmt2.tex 2.4 1995/04/06 -- macros for formatting

2

 3 %%%@TeX-definition-file {
 4 %%% filename       = "$texmf/tex/plain/pdcmac/pdcfmt2.tex",
 5 %%% version        = "2.4",
 6 %%% date           = "1995/04/06",
 7 %%% package        = "pdcmac 1.0",
 8 %%% author         = "P. Damian Cugley",
 9 %%% email          = "damian.cugley@comlab.ox.ac.uk",
10 %%% address        = "Oxford University Computing Laboratory,
11 %%%                   Parks Road, Oxford  OX1 3QD, UK",
12 %%% codetable      = "USASCII",
13 %%% keywords       = "TeX, plain TeX, macros",
14 %%% supported      = "Maybe",
15 %%% abstract       = "Formatting macros for plain TeX documents.
16 %%%                   This file was generated by running
17 %%%                   plain TeX on pdcfmt2.dtx",
18 %%% copyright      = "Copyright (c) 1991-1995 P. Damian Cugley",
19 %%% copying        = "DO NOT DISTRIBUTE THIS FILE.
20 %%%                   Distribute pdcfmt2.dtx only as part of the
21 %%%                   package it came in.",
22 %%% dependencies   = "",
23 %%% }

24

25 \message{2.4 <pdc 1995/04/06>}

26

3. Internal definitions

Most internal control sequence names will start with ‘FMT’. Here are a few miscellaneous definitions used to save a token here or there.

* The LaTEX 2e distribution uses files with the ‘dtx’ suffix for similar purposes.

27–45 PDCFMT2—Formatting Macros 2.4 1995–04–06

I will often use \toksa to create definitions containing characters with unusual catcodes. The idiom is

    \begingroup ⟨assignments⟩ \toksa={\endgroup

⟨definitions⟩

    } \the\toksa

When \toksa is expanded, it closes the group (undoing the ⟨assignments⟩) but then scans the ⟨definition⟩ using the catcodes set by ⟨assignments⟩. (In extreme cases, the definition of \toksa might be enclosed in \uppercase, to get strange characters into a definiton.)

The advantage of this idiom over using \gdef in a group is that the definitions need not be global. Avoiding global assignments makes it more likely that the document will be embeddable in other documents.

Using \toksa instead of \toks0 is more robust when using \uppercase, because digits are be given \uccode values by maamac.tex.

 27 \toksdef\toksa=0
 28 \chardef\other=12

4. Verbatim text

‘Verbatim’ text means text designed to match the ASCII characters in the manuscript file as closely as possible. It kis most often used in computer manuals, where commands typed to a computer or the contents of text files are to be presented. Within verbatim text, most of TEX’s special characters are temporarily disabled.

4.1. Lists of active chararcters The verbatim text macros need to know if any characters have been made special apart from the usual ones. This command tells the verbatim macros that #1 is an active char; in addition to setting its catcode, this makes sure that the character will be re-catcoded appropriately when in verbatim mode. #1 should be a something that will work after ‘` ’; usually this means a one-character control sequence.

 29 \def\declareactivechar#1{%
 30  \toksa\expandafter{\verbatimplains\do#1}%
 31  \edef\verbatimplains{\the\toksa }%
 32  \catcode` #1\active

33 }

Two list macros in the style of \dospecials are defined. The first is for characters that must be set to catcode 12, such as ‘\’, ‘{’, ‘}’, ‘_’, ‘$’, ‘#’, ‘&’, and ‘%’. The other is for a few characters that are given catcode 13, such as ‘` ’, ‘´ ’, ‘~’, ‘^’ and SP.

 34 \def\verbatimplains{\do\\\do\{\do\}\do\_\do\$\do\#\do\&\do\%}
 35 \def\verbatimactives{\do\-\do\` \do\´ \do\~\do\^\do\ }
 36 \chardef\other=12

4.2. Setting up verbatim mode This is a macro common to various verbatim text modes. The default spacing of whatever font is used, without any adjustments of spacefactor for punctuation. The characters ‘` ’, ‘´ ’, ‘~’, and ‘^’ are produce slightly lowered glyphs.

 37 \newtoks\everyverbatim
 38 \bgroup \catcode` \-=13\catcode` \^=13 \catcode` \´ =13 \catcode` \` =13
\toksa={\egroup
 39  \def\setupverbatim{%
 40  \frenchspacing
 41  \spaceskip0pt \xspaceskip0pt % use spacing of font
 42  \def\do##1{\catcode\lq##112 }\verbatimplains
 43  \def\do##1{\catcode\lq##1\active }\verbatimactives
 44  \let` \ttlq \let´ \ttrq
 45  \let~\tttilde \let^\ttcircum \let-\ttminus

46  \the\everyverbatim

47 }

48 }\the\toksa

Here are the definitions for the munged glyphs. These are only necessary in CM Typewriter; when using a PostScript font, different definitions would be necessary.

The names ‘rq’ and ‘lq’ are based on the use of \lq and \rq in plain TEX. An alternative definition for \ttrq would be \chardef\ttrq="0D, producing ‘'’.

49 \def\ttlq{\lower0.125ex \hbox{\char18 }}
50 \def\ttrq{\lower0.125ex \hbox{\char19 }}
51 \def\tttilde{\lower0.5ex \hbox{\char` \~ }}
52 \def\ttcircum{\lower0.5ex \hbox{\char` \^}}
53 \def\ttminus{-}

This makes the difference between ` ´ ^~ and `'^~.

The macro \ttminus is included because it is needed for PostScript font support.

4.3. Defining a self-matching character for verbatim text A macro for defining a self-matching verbatim character (I got the idea of a macro for declaring verbatim characters from the LaTEX 2e documentation macros). #1 must be a one-character control sequence. If it isn’t active already, then \declareactivechar is applied to it first.

54 \def\defverbatim#1{%
55  \ifcat\noexpand#1\noexpand~\else \declareactivechar#1 \fi
56  \begingroup \uccode` \~=` #1 \uppercase{\toksa={\endgroup
57  \def~{%
58  \leavevmode
59  \begingroup \tt \setupverbatim
60  \catcode` #1\active \let~\endgroup
61  }%
62  }}\the\toksa

63 }

Note that there must be a font called \tt for it to switch to. (The catcode of #1 is set to 13 after calling \setupverbatim because #1 will be included in \verbatimplains.)

Finally, we define vertical bar as the conventional self-matching verbatim-mode character.

64 \defverbatim\|
  Both \defverbatim and \defineactivechar have local scope.

4.4. List a file verbatim This does something similar to the lines environment (see below), except here an external file is read in verbatim (see TEXbook Appendix D, Section 3). The \startlinenumbering macro may be put in the \everylisting token register to create a listing with numbered lines.

65 \newtoks\everylisting
66 \def\listfile#1{
67  \medskip
68  \begingroup
69  \parindent=0pt \parskip=0pt
70  \def\par{\null\endgraf}\obeylines
71  \setupverbatim \maketabstab
72  \tt \the\everylisting
73  \input#1
74  \endgroup
75  \medskip\noindent\ignorespaces

76 }

This macro redefines character ^^I (horizontal tab) to produce the equivalent of eight spaces. This isn’t quite the same as what HTs are used for with UNIX files, but it works adequately if all your tabs are at the start of the line (i.e., if tabs are used only for indentation, not to make tables).

77 {\catcode` \^^I=\active
78 \gdef\maketabstab{\catcode` \^^I\active \def^^I{\hskip 4em}}

79 }

5. Everypar hacks

5.1. Parameters The following may be set by higher-level macros to change the apearance of the next paragraph.

If the flag \ifnoindent is set, then the indentation of the next paragraph will be removed (by deleting the box added by TEX’s \indent primitive). Thus \noindenttrue works like \noindent, except that there may be blank lines between \noindenttrue and the paragraph it affects.

80 \newif\ifnoindent

This flag is reset globally once it has had its effect.

If the box \parbox is non-void, then its value is typeset in the left margin of the next paragraph. (At present this does an implicit \noindenttrue but later versions may allow the next paragraph to be indented.) The righthand edge of the parbox will be distance \parboxsep from the left edge of the text area.

81 \newbox\parbox
82 \newdimen\parboxsep \parboxsep=1pc

5.2. Setting \everypar

83 \everypar={%
84  \ifvoid\parbox
85  \ifnoindent {\setbox0=\lastbox}\global\noindentfalse \fi
86  \else
87  {\setbox0=\lastbox}\global\noindentfalse
88  \dp\parbox=0pt
89  \hbox to 0pt{\hss \box\parbox \hskip\parboxsep}%
90  \fi

91 }

6. Environment infrastructure

An environment is a structure used to typeset textual elements consisting of several TEX paragraphs (usually embedded within one conceptual paragraph). It is a concept like LaTEX environments, but with the syntax changed to be more plain-TEX-like.

Since environments have one argument that may span many lines in the file we use more verbose brackets than {–} to make it easier to spot where they begin and end. This is a structure in a document looking like this:

\⟨name⟩⟨args⟩

… \end⟨name⟩

A new environment is defined by defining macros called \⟨name⟩ and \end⟨name⟩. Within the \⟨name⟩ and \end⟨name⟩ macros, calls to \beginthe and \endthe are used to check that environments are nested properly.

92 \def\beginthe#1{%
93  \begingroup\def\PDCFMTblockname{#1}%

94 }

95 \def\endthe#1{%
96  \def\tmp{#1}%
97  \ifx\tmp\PDCFMTblockname
98  \endgroup
99  \else
100  \errmessage{You should have said \string\endthe{\blockname}}%
101  \fi

102 } 6.1. A generic end-of-environment macro

This macro does a \smallskip (if there is not already a larger skip on the current list), and sets the ‘noindent’ flag so that the following TEX paragraph is not indented.

103 \def\PDCFMTendenv#1{
104  \smallskip
105  \endthe{#1}
106  \global\noindenttrue

107 }

Where an environment describes text that should be indented, usually \parindent should be used (for consistency). If \parindent is zero we still want to indent the text, and we use \envindent to describe how much to indent it by.

108 \newdimen\envindent \envindent=1pc
109 \def\PDCFMTindent{%
110  \ifdim\parindent>0pt
111  \parindent
112  \else
113  \envindent
114  \fi

115 }

7. Quotations

This is a simple environment, with the left margin indented and the first paragraph in the quotetd text not indented.

   It is ...  who said
\quotation
   Shookum hip rallo dyne.
\endquotation
Indeed, it burgle gurgler.

It is interesting to remember the words of Spencone Tipeth, who said Shookum hip rallo dyne.

Indeed, it burgle gurgler.

The token register \everyquotation might be used to arrange for all quotations to be in smaller type with

                       \everyquotation={\smallfonts}

116 \newtoks\everyquotation
117 \def\quotation{
118  \smallskip
119  \beginthe{quotation}
120  \advance\leftskip\PDCFMTindent
121  \noindenttrue
122  \the\everyquotation

123 }

124 \def\endquotation{\PDCFMTendenv{quotation}}

The differences from using {\narrower… \par} (apart from how it looks in the source file) include (a) the right margin isn’t indented; (b) it indents by \envindent if there is no \parindent and (c) it is preceeded and followed by a smallskip.

8. Textlists—bulleted or numbered lists

Here’s a generic list-of-items environment, used to implemented bulleted and numbered lists. Each item is started with the convenient \\ macro (and so may contain more than one paragraph). It is called a ‘textlist’ to distinguish it from other meanings of the word ‘list’. Usually textlists will be generated with higher-level macros like \bullets and

\numbered.

8.1. A generic textlist environment The token register \everytextlist is expanded at the start of every textlist. The level of nesting is recorded in \textlistdepth (a to-level list is depth 0, a list inside that is depth 1, and so on). The flag \ifnumbered controls whether items are numbered (using

\numberfordepth) or bulleted (using \bulletfordepth).
125 \newtoks\everytextlist
126 \newif\ifnumbered
127 \newcount\textlistdepth  \textlistdepth=-1
128 \newcount\textlistcount
129 \def\textlist{%
130  \par
131  \beginthe{textlist}
132  \advance\textlistdepth 1
133  \textlistcount0
134  \def\\{
135  \smallskip\noindent
136  \advance\textlistcount1
137  \llap{%
138  \ifnumbered
139  \numberfordepth\textlistdepth\textlistcount
140  \else
141  \bulletfordepth\textlistdepth
142  \fi\enspace}%
143  \ignorespaces

144 }

145  \advance\leftskip\PDCFMTindent
146  \the\everytextlist

147 }

148 \def\endtextlist{\PDCFMTendenv{textlist}}

8.2. Bulleted lists This describes a bulleted list, where each paragraph is indented and preceeded by a mark in the margin.

   I would like to make...
\bullets
\\ this point; and
\\ that point
\endbullets
And so on and so forth.

I would like to make the following very important and relevant itemized points:

• this point; and

• that point And so on and so forth.

Bullets environments may be nested, in which case different marks are used. The sign

is chosen with \bulletfordepth.
149 \newtoks\everybullets
150 \def\bullets{\textlist \numberedfalse \the\everybullets}
151 \let\endbullets=\endtextlist
152 \def\bulletfordepth#1{%
153  \ifcase#1 $\bullet$\or --\or $\circ$\else $\cdot$\fi

154 }

8.3. Numbered lists The numbered list is similar. The style of numbering changes with the listing depth; you can change this by redefining \numberfordepth.

Depth 0  1. 2. 3….
Depth 1  (1) (2) (3) …
Depth 2  (a) (b) (c) …
Depth 3+  (i) (ii) (iii) …

There is also a token regieter \everynumbered for any extra customization. This is read

after \everytextlist.
155 \newtoks\everynumbered

156 \def\numbered{\textlist \numberedtrue \the\everynumbered}
157 \let\endnumbered=\endtextlist
158 \def\numberfordepth#1#2{%
159  \ifcase#1 \n{\number#2}.\or (\n{\number#2})\or
160  ({\it\alphabetletter#2\/})\else (\romannumeral#2)\fi

161 }

It turns out that sometimes it is useful to be able to impose a format on numbers generated by formatting macros. For example, I occasionally find it useful to force all numbers to be generated in maths mode. To do this, all numbers generated by macros are enclosed in \n{–}. By default, \n is equivalent to \relax.

162 \let\n\relax

8.4. Picking a letter of the alphabet

This macro behaves as much like the primitives \number and \romannumeral as it can: it expands entirely within TEX’s mouth, and so may be used in \edefs and the like. It produces ??? or !!! if its argument is not in the range 1–26. The macro is defined so as to reduce the number of tokesn to be skipped when #1 is less than 6.

163 \def\alphabetletter#1{%
164  \ifcase#1 ??? \or a\or b\or c\or d\or e\else
165  \xxxalphabetletter#1\fi

166 }

167 \def\xxxalphabetletter#1{%
168  \ifcase#1 \or\or\or\or\or\or f\or g\or h\or i\or j\or
169  k\or l\or m\or n\or o\or p\or q\or r\or s\or t\or u\or
170  v\or w\or x\or y\or z\else !!!\fi

171 }

9. Tagged lists

In other words, description lists. Each paragraph starts with the ‘tag’ set either in the left margin or sticking in to the current line if it is too long to fit. The tag for each paragraph is introduced with ‘\\{⟨text⟩}’.

The maximum width of tag labels (including the 1 en space that goes between label and text) in is stored in \tagmaxwidth. If there is not room, then the label is run on in to the paragraph and separated from the text by a quad space.

172 \newdimen\tagmaxwidth

As well as giving a new definition to the \\ macro, the \tagged command mast choose a value for \tagmaxwidth. If there is a large left margin (signalled by giving \leftmargin a positive value) then tags will go in there; otherwise the text will be indented and the amount of indentation used as the maximum label width.

173 \newtoks\everytagged
174 \def\tagged{%
175  \par
176  \beginthe{tagged}
177  \let\\\TAG
178  \ifdim\leftmargin=0pt
179  \tagmaxwidth\PDCFMTindent
180  \else
181  \tagmaxwidth\leftmargin
182  \fi
183  \the\everytagged
184  \ifdim\tagmaxwidth>\leftmargin
185  \leftskip\tagmaxwidth \advance\leftskip-\leftmargin
186  \fi

187 }

188 \def\endtagged{\PDCFMTendenv{tagged}}

The adjustment to \leftmargin comes after scanning \everytagged so that it is pos-

sible to adjust \tagmaxwidth inside \everytagged.

Trickery with \futurelet and \aftergroup (like that used in plain TEX’s \footnote command) is used to allow catcode changes in ⟨text⟩ to work. This allows macros that generate ‘verbatim’ text to work.

189 \newtoks\everytag
190 \def\TAG{%
191  \smallskip\noindent
192  \setbox0=\hbox\bgroup        % matched by \TAGfinish
193  \the\everytag\ignorespaces
194  \futurelet\next\TAGtest

195 }

196 \def\TAGtest{%
197  \ifcat\bgroup\noexpand\next
198  \let\next\TAGgotbrace
199  \else
200  \let\next\TAGnobrace
201  \fi \next

202 }

203 \def\TAGgotbrace{%
204  \bgroup\aftergroup\TAGfinish
205  \let\next

206 }

207 \def\TAGnobrace#1{%
208  #1\TAGfinish

209 }

210 \def\TAGfinish{%
211  \unskip\hskip0.5em\egroup       % matches \TAG
212  \ifdim \wd0 < \tagmaxwidth
213  \wd0=\tagmaxwidth
214  \llap{\box0}%
215  \else
216  \hskip-\tagmaxwidth
217  \unhbox0 \unskip\quad
218  \fi
219  \ignorespaces

220 }

It might be interesting to generalize these macros so that new macros with an argument scanned this way may be created more easily.

10. Lines environment (for program listings etc)

In the lines environment, each line in the manuscript file becomes a new paragraph (i.e., a separate line on the printed page). A % at the end of a line may be used to split a file line in to several logical lines. In addition, the lines environment is bracketed by horizontal rules. The effect is similar to that produced by the \beginlines–\endlines macros in TEXbook Appendix E.

221 \newtoks\everylines
222 \def\lines{
223  \par
224  \beginthe{lines}
225  \nobreak\smallskip\hrule\nobreak\smallskip
226  \obeylines
227  \parindent=0pt \parskip=0pt
228  \parfillskip=0pt plus 1fil
229  \the\everylines
230  \nobreak

231 }

232 \def\endlines{
233  \nobreak\smallskip
234  \endthe{lines}
235  \hrule\smallskip
236  \global\noindenttrue

237 }

For longer listings it may be nice to have the lines numbered for later reference. The following two macros may be put in \everylines to enable line numbering—the first starts from 1 in each listing environment, the other continues the numbering from where it left off.

The line number is kept in \linenumber (which may be adjusted by the user). Only every 5th line is numbered. The number of lines until the next printed one is held in \PDCFMTcount. Both these are always set globally (which means lines environments cannot be nested!).

238 \newcount\linenumber
239 \newcount\PDCFMTcount
240 \def\startlinenumbering{%
241  \global\linenumber=0 \global\PDCFMTcount=5
242  \everypar{\numberthisline}%

243 }

244 \def\continuelinenumbering{%
245  \everypar{\numberthisline}%

246 }

The \numberthisline macro is invoked at the beginning of every paragraph. It increments \linenumber, and writes the line number of every fifth line in the right margin. By default it uses the same font as used in subscripts; this can be changed by changing the token register \everylinenum.

247 \newtoks\everylinenum \everylinenum{\the\scriptfont0 }
248 \def\numberthisline{%
249  \strut
250  \global\advance\linenumber1 \global\advance\PDCFMTcount-1
251  \ifnum\PDCFMTcount>0 \else
252 \global\advance\PDCFMTcount 5
253 \rlap{\the\everylinenum \kern\hsize\kern1em \the\linenumber}%
254  \fi

255 }%

Within the lines environment it can be useful to indicate where lines have been skipped. This macro also adjusts the \linenumber macro.

256 \def\linesskipped#1{%
257  \strut \hskip20pt $\vdots$ \hskip20pt
258  {\rm(\it #1 lines omitted\rm)}\par
259  \advance\linenumber#1\relax

260 }

11. Displays, Tables – wrapper about \halign

The display environment does a generic (meaning not necessarily mathematical) display, in a manner similar to the \begindisplay–\enddisplay macros in TEXbook Appendix E. As with Knuth’s macro, assignments may follow on the same line as \display, and \cr and & may be used to split the display into rows and columns.

261 \outer\def\display{\obeylines\startdisplay}
262 \bgroup\obeylines \toksa={\egroup %
263  \def\startdisplay#1^^M{%
264  \catcode` \^^M=5 $$ #1 % matched by \enddisplay
265  \displayindent\PDCFMTindent %
266  \halign\bgroup##\hfil&&\quad##\hfil\cr %

267 } %

268 }\the\toksa %

269 \def\enddisplay{\crcr\egroup$$}

The table environment is similar, ecept that what follows \table is an arbitrary \halign specification.

270 \def\table{%
271  $$                  % matching $$ is in \endtable
272  \displayindent\PDCFMTindent
273  \halign \bgroup

274 }

275 \let\endtable=\enddisplay

Note Both the table and display environments must go within paragraphs. That is, there should not be blank lines before \table, or after \endtable unless the table ends the paragraph.

12. (E)BNF

BNF is Bakus-Naur Formalism; EBNF is Extended BNF. The same environment does either format. The style I happen to like, has non-terminal sumbols written like ⟨this⟩, and terminal symbols enclosed in ‘–’. Optional text is enclosed in brackets (I like to put spaces between the brackets and the enclosed text for clarity) and repeatable text in braces.

In the manuscript file, each production is a separate paragraph. The macro \> goes between the left hand side and right hand side of a production; by default, it expands to ‘::=’. Alternatives are separated by \\; by default this expands to a bar ‘|’. If the terminal symbols happen to be keyboard characters, use the verbatim text character | which adds quotation marks around the text it produces. For example, the following expression

⟨foo⟩ ::= ‘f’ ‘o’ ‘o’ | ⟨bar⟩ [ ⟨mumble⟩ ‘munge’ ].

may be produced with

       \<foo> \> |f| |o| |o| \\ \<bar> [ \<mumble> ` {\bf munge}´ ].

Braces are produced with \{ and \}.

276 \newtoks\everybnf
277 \def\bnf{
278  \nobreak\smallskip
279  \beginthe{bnf}
280  \advance\leftskip2\parindent \parindent=-\parindent
281  \parskip0pt plus 1pt
282  \rightskip=1\rightskip plus 3em
283  \def\\{$\mid$}
284  \def\>{\unskip\enspace$::=$\enspace\ignorespaces}
285  \def|{` \begingroup\tt\setupverbatim\catcode` \|=13
286  \def|{\endgroup´ }}
287  \def\{{$\lbrace$} \def\}{$\rbrace$}
288  \the\everybnf

289 }

290 \def\endbnf{
291  \smallskip
292  \endthe{bnf}
293  \global\noindenttrue

294 }

The macro \< is based on the one in Appendix E of the TEXbook. For example, \<foo> produces ‘⟨foo⟩’.

295 \def\<#1>{\leavevmode\hbox{$\langle${\it#1\/}$\rangle$}}

The difference is that the name is in italics: ⟨name⟩ not ⟨name⟩.

Note This macro is not intened for be used to generate character names like Return and Tab; I suggest just saying ‘Return’ and ‘Tab’ for these.

There is a style of RFC-822 email addresses written in the form ‘Damian Cugley <pdc@alleged.co.uk>’. I suggest that when presenting email addresses in printed documents this be rendered as something like ‘Damian Cugley

       (pdc@alleged.co.uk)’.

13. Headings

Here are some macros for making headings for sections of a document. There are two styles of layout supported by these heading macros: the usual style N, with headings above the first paragraph of the section, and the ‘tab-indexed’ style T, with headings in the left margin, aligned with the first line of the paragraph.

13.1. The left margin parameter

For style T headings, this is the size of the extra margin at the left side of the page (so (hoffset + 1 in) − leftmargin is the margin between the left edge of headings and the edge of the paper). Set this parameter to 0 pt for style N.

296 \newdimen\leftmargin

13.2. Headings that don’t start a new page

This macro is intended to be used by higher-level macro with names like \section, which take care of numbering section headings and so on.

\doheading{⟨skip⟩}{⟨style⟩}{⟨coda⟩}{⟨text⟩}

Where ⟨skip⟩ is the skip to put before the heading (for example, a ⟨dimendef token⟩ like like \medskipamount or \bigskipamount, or a ⟨dimen⟩ enclosed in braces); ⟨style⟩ is tokens to insert before the ⟨text⟩ (such as assignments that select the font); ⟨coda⟩ is tokens that follow the ⟨text⟩ (which might produce a rule under the heading, for example; usually this is empty); and ⟨text⟩ is the text of the heading supplied by the user.

297 \newskip\headingtemp
298 \def\doheading#1#2#3#4{
299  \ifdim\lastskip<#1\relax \removelastskip \vskip#1\relax \fi
300  \ifdim \leftmargin>0pt

If the left margin is greater than zero then we generaten a style T heading. This is done by putting the text in \parbox, which will be used by the \everypar.

301  \global\setbox\parbox=\vtop{%
302  \hsize=\leftmargin \advance\hsize-\parboxsep
303  \parindent=0pt
304  \leftskip=0pt \rightskip=0pt plus 3em
305  \hyphenpenalty=10000 \exhyphenpenalty=5000
306  \strut#2#4#3

307 }

308  \else

Otherwise we typeset the heading as a separate paragraph.

309  \begingroup
310  \parindent=0pt \parfillskip=0pt plus 1fil
311  \leftskip=0pt \rightskip=0pt plus0.25\hsize
312  \hyphenpenalty=10000 \exhyphenpenalty=5000
313  \strut#2#4#3
314  \global\headingtemp=\baselineskip
315  \par
316  \endgroup

The vertical space between the heading and the following text is calculated from the difference in baselineskips between the fonts used in the heading and those used in body text, plus smallskipamount.

317  \advance\headingtemp-\baselineskip
318  \ifdim\headingtemp>0pt \nobreak \vskip 1.0\headingtemp \fi
319  \smallskip
320  \noindenttrue
321  \fi

322 }

13.3. Headings that start a new page Major divisions of a book start on a nw page. The parameters to the macro are similar to

those for \doheading:

\newpageheading{⟨skip⟩}{⟨style⟩}{⟨coda⟩}{⟨text⟩}

Where here the ⟨skip⟩ is the extra space at the top of the page.

323 \def\newpageheading#1#2#3#4{
324  \vfill\supereject % ensure no insertions still floating
325  \null\vskip#1\relax
326  \moveleft\leftmargin\vbox{
327  \advance\hsize\leftmargin
328  \parindent=0pt \parfillskip=0pt plus 1fil
329  \leftskip=0pt \rightskip=0pt plus0.25\hsize
330  \hyphenpenalty=10000 \exhyphenpenalty=5000
331  #2\strut#4#3
332  \global\headingtemp=\baselineskip
333  \par

334 }

335  \advance\headingtemp-\baselineskip
336  \advance\headingtemp\smallskipamount
337  \vskip \headingtemp
338  \noindenttrue
339  \def\tmp{#4}
340  \message{*\expandafter\TOCtrim\meaning\tmp.  }

341 }

14. Footnotes

We define a new command \note that replaces use of the \footnote command. This takes one parameter—the text of the footnote—and supplies automatically-numbered footnote markers.

The \newcount command implicitly sets the counter to 0.

342 \newcount\notecount
343 \def\note{%
344  \global\advance\notecount+1
345  \footnote{\number\notecount}%

346 } We add a parameter for the indentation of footnote paragraphs.

347 \newdimen\footnoteparindent
348 \footnoteparindent=\parindent

Now we modify the definition of \footnote in plain TEX (see TeXbook p. 363). It has the same function as plain TEX’s \footnote, but uses extra parameters (\everyfootnote, \footnotetextmark), and handles the case parindent = 0 pt.

349 \newtoks\everyfootnote
350 \catcode` \@=11
351 \def\footnote#1{\let\@sf\empty
352 \ifhmode\edef\@sf{\spacefactor\the\spacefactor}\/\fi
353 \footnotetextmark{#1}\@sf\vfootnote{#1}}

354 \def\vfootnote#1{\insert\footins\bgroup % matched by \@foot
355  \interlinepenalty=\interfootnotelinepenalty
356  \parindent=\footnoteparindent
357  \leftskip=0pt
358  \the\everyfootnote
359  \splittopskip=\ht\strutbox \splitmaxdepth=\dp\strutbox
360  \floatingpenalty=20000
361  \indent\footstrut
362  \ifdim\parindent>1em
363  \llap{\footnotenotemark{#1}\enspace}%
364  \else
365  \footnotenotemark{#1}\enspace
366  \fi
367  \futurelet\next\fo@t

368 }

369 \def\@foot{\smallskip\egroup}
370 \catcode` \@=12

These two parameters control the formatting of the footnote marker in the text and in the note itself. They take one parameter, a ⟨number⟩. The default definitions simply use a superscript in maths mode.

371 \def\footnotetextmark#1{$^{#1}$}
372 \def\footnotenotemark#1{$^{#1}$}

15. Miscellaneous in-paragraph commands

15.1. Writing the current date

We define a macro \today that prints today’s date. I used to have the option of the abbreviated date but decided this was an unnecessary complication. The format ‘29 April 1996’ is usual in non-American countries, and is recommended by Hart’s Rules* and Strunk & White.†

373 \def\today{\n{\number\day} \monthname\month\ \n{\number\year}}
374 \def\monthname#1{%
375  \ifcase#1\or
376  January\or February\or March\or April\or
377  May\or June\or July\or August\or
378  September\or October\or November\or December%
379  \fi

380 }

Redefine the \monthname macro if you want different names for the months.

Here’s a definition for the date in ISO 8601/BS 4795 format,‡ which puts the year first, giving ‘1996–04–29’:

381 \def\isodate{\n{\number\year}--\twodigits\month--\twodigits\day}
382 \def\twodigits#1{%
383  \ifnum#1<10 0\fi \number#1%

384 }

* Horace Hart, Hart’s Rules for Compositors and Readers at the University Press, Oxford, 39th ed., completely revised (Oxford University Press, 1990), p. 19.

† William Strunk jun., and E. B. White, The Elements of Style, 3rd ed. (Macmillan, 1979), p. 3. The American format is given first but followed by the observation that the day–month–year format is ‘an excellent way to write that date; the figures are separated by a word, and are, for that reason, quickly grasped’.

‡ The Oxford Writers’ Dictionary (Oxford University Press, 1990), under ‘date’. I have not read the relevant standards.

15.2. Raising things The \flushtop macro prints its argument in a box raised so that the its top is aligned with the top of a letter X in the current font.

385 \def\flushtop#1{%
386  \leavevmode
387  \begingroup
388  \setbox0\hbox{#1}\setbox2\hbox{X}%
389  \dimen0\ht2 \advance\dimen0-\ht0
390  \raise\dimen0\box0
391  \endgroup

392 } This allows us to define a fairly generic version of the LaTEX logo:

393 \def\La{L\negthinspace\flushtop{a}}
394 \def\LaTeX{\La\TeX}

I have not given a definition for the LaTEX 2e logo, since I think that ‘\LaTeX~2e’ (or ‘\LaTeX2e’ if you prefer) is adequate, whereas Addison–Wesley think it should be ‘\LaTeX

\kern0.05em 2$ _{\textstyle \varepsilon} $’ in regular text and something involving

bold maths in boldface. SImilarly, I do not include macros for BibTEX, SliTEX, AMS-TEX, and so on; the texlogos.sty file from the Eplain package has definitions for these.

Here’s a variation which raises a scriptstyle letter so that its x-height matches the cap-height of the body text, thus making ‘Mc̄Donald’ and ‘1ā’, ‘1ō’, ‘1^{er}’, ‘2^{ème}’, ‘1^{st}’, ‘2^{nd}’, ‘3^{rd}’ and ‘659^{th}’ (which I prefer to 659^{th}).

395 \def\superiorletter#1{%
396  \flushtop{\the\scriptfont\fam \vphantom{x}\smash{#1}}%

397 }

398 \def\Mc{M\flushtop{\the\scriptfont\fam \b{c}}}