% This file is part of the CTAN package named plain-grid.
%
% plain-grid-doc.tex: instructions for the package
% Version 1.0, 05.05.2026
%
% Copyright (C) 2026 Udo Wermuth (author)
%
% 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
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see .
%
\def\plaingridversion{1.0}\def\plaingriddate{05.05.2026}
% %%%%%
\hsize=36pc
\input plaingridB.tex
\def\gridlog{ 3 }
% %%%
% %%% verbatim macros (from manmac.tex)
% %%%
\newskip\ttglue {\tt\global\ttglue=0.5em plus 0.25em minus 0.15em }
\def\ttverbatim{\begingroup \frenchspacing
\catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\$=12 \catcode`\&=12
\catcode`\#=12 \catcode`\%=12 \catcode`\~=12 \catcode`\_=12 \catcode`\^=12
\obeyspaces \obeylines \tt}
\def\verbatimspace{\ifvmode\indent\fi\space}
{\obeyspaces \gdef\makespaceverbspace{\def {\verbatimspace}}}
\outer\def\verbatim{$$\ifdim\parskip>0pt
\abovedisplayskip=\parskip \abovedisplayshortskip=\parskip
\belowdisplayskip=\parskip \belowdisplayshortskip=\parskip
\else
\abovedisplayskip=3pt \abovedisplayshortskip=3pt
\belowdisplayskip=3pt \belowdisplayshortskip=3pt
\fi
\let\par=\endgraf \ttverbatim \makespaceverbspace \parskip=0pt
\catcode`\§=0 \advance\leftskip by 10pt \ttfinish}
{\catcode`\§=0 §catcode`§\=12 % § is temporary escape character
§obeylines % end of line is active
§gdef§ttfinish#1^^M#2\endverbatim{§vbox{#2}§endgroup$$}}
\catcode`\|=\active
{\obeylines \gdef|{\ttverbatim \spaceskip\ttglue \let^^M=\ \let|=\endgroup}}
% %%%
% %%% own settings
% %%%
\hyphenation{plaingridT plaingridM plaingridI plaingridB plaingridX
end-note end-notes endnotesi endnotesii}
\def\alt{\ $\vert$ } \def\<#1>{$<$\hbox{#1}$>$}
% %%%
% %%% code from The \TeX book, page 257
% %%%
\def\plaingridlnostartpage{99 }% later changed
\newdimen\fullhsize
\fullhsize=1.08\hsize \hsize=.475\fullhsize
\def\fullline{\hbox to\fullhsize}
\catcode`@=11
\def\makeheadline{\vbox to\z@{\vskip-22.5\p@
\fullline{\vbox to8.5\p@{}\the\headline}\vss}\nointerlineskip}
\def\makefootline{\baselineskip24\p@\lineskiplimit\z@\fullline{\the\footline}}
\catcode`@=12
\let\lr=L \newbox\leftcolumn
\output={\if L\lr
\global\setbox\leftcolumn=\columnbox \global\let\lr=R
\else \doubleformat \global\let\lr=L\fi
\ifnum\outputpenalty>-20000 \else\dosupereject\fi}
\def\doubleformat{\shipout\vbox{\makeheadline
\fullline{\box\leftcolumn\hfil\columnbox}
\makefootline}
\advancepageno}
\def\columnbox{\leftline{\pagebody}}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\font\titlefont=cmssdc10 at 36pt
\font\subtitlefont=cmssdc10 at 17pt
%
\gridtopinsert \hsize=\fullhsize \null
\centerline{\titlefont plain-grid}
\gridskiponeline \gridsnaptonextbaseline % fix for the unusal font size
\centerline{\subtitlefont Version \plaingridversion, \plaingriddate}
\gridskiponeline \gridsnaptonextbaseline % ditto
\centerline{Macros for plain \TeX\ by Udo Wermuth}
\gridskiponeline
\gridendinsert
\gridskiponeline
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%% \headline is set on second page; see start of section 3 below
\noindent
This package contains macros to typeset straight text with a fix
distance between the lines, i.e., the text obeys a baseline
grid. Moreover, the package contains macros to handle displayed
equations, formulas with unusual height and depth in inline
mathematics, vertical boxes, topinserts, and footnotes.
However, the baseline grid is only obeyed if the author avoids all
plain \TeX\ commands that destroy this grid. Therefore, an author must
not use vertical skips, i.e., |\vskip| as well as |\smallskip|, etc.,
or |\smallbreak|, etc., and macros that contain such skips like
|\beginsection|.
For additional information and an example see my article in TUGboat
{\bf47}:1 (2026), 119--134.
\gridbeginsection 1. Activation
To activate the plain-grid macros load one of the following four
files after plain \TeX\ via |\input|.
\gridskiponeline
\item{1.}{\tt plaingridT.tex} supports an author to typeset straight
text on a baseline grid. It provides macros for endnotes
too. It also contains a macro to draw horizontal rules.
\item{2.}{\tt plaingridM.tex} helps an author to typeset text and
mathematics, like displayed equations and theorems. Moreover,
texts in vboxes are supported.
\item{3.}{\tt plaingridI.tex} adds to {\tt plaingridM.tex} the treatment
of insertions and footnotes. It includes the feature of a {\sl
ragged bottom\/} if an author decides to violate the grid
structure.
\item{4.}{\tt plaingridB.tex} loads {\tt plaingridI.tex} and contains
macros for vboxes and vtops in horizontal mode, i.e., in
paragraphs.
\gridskiponeline
The above files usually implement new macros; they do not replace
existing commands of \TeX\ or macros of plain. But there are a few
exceptions: |\pagebody|, |\pagecontents|, |\vfootnote|, and the
protected macro |\@foot|. The first is changed by {\tt plaingridT.tex}
and is therefore active in all files. The others are changed in {\tt
plaingridI.tex}.
As mentioned above, an author must use the new macros to stay on the
baseline grid. Plain \TeX's macros must only be used in certain
structures like math displays or vertical boxes created by the new
macros. Then plain's macros are protected and the grid is at most
violated inside the structure.\looseness=-1
Moreover, an author should be aware that page breaks might occur at
typographically bad places. For example, club and widow lines are
possible and must be fixed by the author.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gridtopinsert \null \gridskipmax7 \gridendinsert % lower 2nd column
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gridskiponeline
The new macros do not work correctly if some parameters of the set-up
do not match with each other before they are loaded. This package
requires that (i)~the natural space of\/ |\baselineskip| equals the
sum of height and depth of\/ |\strutbox| and (ii)~|\maxdepth| and
|\boxmaxdepth| are not smaller than the depth of\/ |\strutbox|. Either
check these requirements before any of the above files is loaded or
input the file {\tt plaingridX.tex} after one of the above files was
input. It reports violations of the stated requirements. Nothing is
fixed; do it yourself before the grid macros are loaded. If you
continue although the values do not match, grid-aware typesetting is
not active. When the extra file does not report any mismatch the file
{\tt plaingridX.tex} is no longer needed.
Of course, plain \TeX\ obeys the requirements.
\gridbeginsection 2. Immediate changes
As soon as one of the four files is input, several \TeX\ parameters
receive new values. Only two parameter changes are shown to the user
on the terminal: (a)~A change to the value of\/ |\vsize| and (b)~a
change to the value of\/ |\baselineskip|.
\gridskiponeline
\item{1.}{\tt plaingridT.tex} changes the following parameters and macros:
\itemitem{a)}|\baselineskip| is coerced to a dimension, i.e., any
stretchability and shrinkability of this glue parameter
is removed. If this changes |\baselineskip|'s value the
user is informed via a message.
\itemitem{b)}|\vsize| becomes an integer multiple of the |\baselineskip|. If
this changes |\vsize|'s value the user is informed via a
message.
\itemitem{c)}|\normalbottom| is called.
\itemitem{d)}|\topskip| is set to |\baselineskip|.
\itemitem{e)}|\lineskip| is set to $\rm0\,pt$.
\itemitem{f)}|\lineskiplimit| is set to $\rm0\,pt$.
\itemitem{g)}|\parskip| is set to $\rm0\,pt$.
\itemitem{h)}|\interlinepenalty| is set to 0.
\itemitem{i)}|\clubpenalty| is set to 0.
\itemitem{j)}|\widowpenalty| is set to 0.
\itemitem{k)}|\brokenpenalty| is set to 0.
\itemitem{l)}Plain \TeX's macro |\pagebody| is changed.
\item{2.}{\tt plaingridM.tex} changes the above and the following
parameters:
\itemitem{a)}|\abovedisplayskip| is set to $\rm0\,pt$.
\itemitem{b)}|\belowdisplayskip| is set to $\rm0\,pt$.
\itemitem{c)}|\abovedisplayshortskip| is set to $\rm0\,pt$.
\itemitem{d)}|\belowdisplayshortskip| is set to $\rm0\,pt$.
\itemitem{e)}|\predisplaypenalty| is set to 0.
\itemitem{f)}|\postdisplaypenalty| is set to 0.
\itemitem{g)}|\displaywidowpenalty| is set to 0.
\itemitem{h)}|\everydisplay| is used by the package. The original token list
is stored in a new token register: |\grideverydisplay|.
\item{3.}{\tt plaingridI.tex} changes the above and the following parameters
and macros:
\itemitem{a)}|\skip\topins| is set to $\rm0\,pt$.
\itemitem{b)}|\skip\footins| is set to |\baselineskip|.
\itemitem{c)}Plain's macro |\pagecontents| is changed.
\itemitem{d)}Plain's macro |\vfootnote| is changed.
\itemitem{e)}Plain's macro |\@foot| is changed.
\gridskiponeline
The package declares one output stream and twelve registers. It uses
several scratch registers.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\headline{\tenrm Udo Wermuth\hfil plain-grid (version \plaingridversion)}
\newcount\nmcnt \nmcnt=1
\def\nextmacro{{\bf\number\nmcnt.}\advance\nmcnt by 1\relax}
\def\nmtextindent{\gridskiponeline\expandafter\textindent\nextmacro}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\gridbeginsection 3. Macros and conditionals in {\tt plaingridT.tex}
The first set of macros defines vertical skips.
\nmtextindent|\gridskiponeline| leaves a single blank line.
\nmtextindent|\gridbackoneline| jumps back one line.
\nmtextindent|\gridskipmax{|$n$|}| skips $n$ lines. (Braces are
only needed for $n>9$.) If the current page has only $m$ lines left
with $m
The \ stands for a dimension in the unit {\tt pt}. This message is
shown if the |\baselineskip| has at the beginning a glue value with
stretch- and/or shrinkability. Grid-aware typesetting removes any
stretch and shrink components and keeps only the natural space.
Change the |\baselineskip| to a dimension before the macros are
loaded and no message is shown.
\item{2.}GRID: |\vsize| changed; new value \ (\ lines)
Again, \ is a dimension and \ represents an
integer. Here the |\vsize| was changed as it must be an exact
multiple of\/ |\baselineskip|.
Change the |\vsize| to an integer multiple of\/ |\baselineskip| before
the macros are loaded and no message is shown.
\item{3.}GRID: file with endnotes not yet output: \
|\griduseendnotes| was called twice without printing the existing
endnotes by calling the macro |\gridprintendnotes|. The macro opens a
new file for the next endnotes and the author is informed that the
file \ needs to be manually loaded.
\item{4.}GRID: unexpected page ejection
This message might indicate an error. The user wants to output a
multiline structure as it is created, for example, by
|\gridbeginsection|, but it's too large for the current page. Thus,
empty lines fill the current page and the structure is output on the
next page.
To move the begin of a section might be okay. Then the message can be
suppressed by setting |\gridnewpageOKtrue| in front of the section
command. The message that is output for the movement of a displayed
equation is not affected by the conditional and should not be
tolerated.
\gridskiponeline
Messages in the file {\tt plaingridI.tex}.
\item{5.}GRID: page too short; fix
There is a footnote in the last available line on the current
page. As there is no room for the text of the footnote the last line
is moved to the next page leaving an underfull page. A line with more
than one footnote might generate message no.\ 7.
In the log you find the following text: ``The page is a line too
short because a line with a footnote must be moved.''
\item{6.}GRID: page ends ragged; fix
The user left the grid on the current page, for example, with
|\gridskiphalfaline| or |\gridskip| but does not accept to end a page
within shifted material, i.e., we have |\gridraggedfalse|.
\item{7.}GRID: ugly page; fix
Something went wrong and the page is underfull. It was not
possible to identify the root cause as in the previous two messages.
The message is accompanied in the log by this text: ``The page is not
filled as expected. Maybe a text line with footnotes is moved to the
next page, a skip violates the grid, or a forbidden command was used.
Check the |\vbox| shown in TeX's warning.''
\gridskiponeline
Messages in the file {\tt plaingridB.tex}.
\item{8.}GRID: vtop moved; check
A |\gridvtop| does not fit on the current page and must be moved to
the beginning of the next. The current page is underfull.
\item{9.}GRID: vbox moved; check
A |\gridvbox| does not fit on the current page and must be moved to
the next page. The current page is underfull.
\gridskiponeline
\textindent{c)}There is one log message that is always output.
\item{1.}GRID line \: |\gridsnaptonextbaseline| uses \
Here \ is an integer and \ a
dimension. |\gridsnaptonextbaseline| was used in line \ of
the currently processed file. The skip used by this macro is reported
as \ in the log.
\gridskiponeline \textindent{d)}There are four messages that are
written to the log if\/ |\gridlog|'s replacement text stores a number
larger than~1. Two are written if\/ |\gridlog| contains 2; otherwise
all four are output. Often they do not reflect a user's input;
different macros, sometimes internal, write them. They help to debug
problems.
\item{1.}(level 2) GRID line \: available lines = \
This message is in file {\tt plaingridT.tex}. A macro wants to check
how many lines are available on the page. The value \ represents
the number of unused lines.
\item{2.}(level 2) GRID: page (\) [is bad\alt is okay\alt with
footnote\alt has a ragged bottom\alt has a shift\alt with footnote
has a ragged bottom\alt with footnote has a shift]
This message is in file {\tt plaingridI.tex}. The message outputs the
internal computation of the page's fill level, the dimension \,
and the conclusion from this computation, i.e., one of the texts
between the brackets where \alt\ means ``or''. A page that is labeled
``is bad'' or ``has a shift'' is an ugly page and produces one of the
above described terminal messages. A ``has a ragged bottom''
indicates a page that ends in shifted material but the user set
|\gridraggedtrue|, i.e., the user accepts such pages. The text ``with
footnote'' indicates that the computation determines that there is a
footnote on the page; it does not indicate a problem.
\item{3.}(level 3) GRID line \: box (\+\) [changed by
(\+\)] output as\hfil\break (\+\) in \ lines
A vbox is automatically created; it has height and depth of \
and \. The call specifies that some white space of \
and \ are added to height and depth, respectively. The box is
output with dimensions \ and \ in \ lines to make it fit
into the grid.
\item{4.}(level 3) GRID line \: user's height \ lines or \;
top plus \
The user decided to overrule the automatism in the calculation of a
vbox with a displayed equation and this is reported in the
log. Dimension \ states the amount of white space that the user
added at the top of the display.
The two level~3 messages belong to the file {\tt
plaingridM.tex}.
\gridbye