ltmiscen.dtx

Johannes Braams  David Carlisle  Alan Jeffrey
Leslie Lamport  Frank Mittelbach  Chris Rowley

Rainer Schöpf

1995/10/24

1 Miscellaneous Environments

This section implements the basic environment mechanism, and also a few specific environments including document, The math environments and related commands, the ‘flushing’ environments, (center, flushleft, flushright), and verbatim.

1 ⟨∗2ekernel⟩

 2 \message{environments,}

1.1 Environments

\begin{foo} and \end{foo} are used to delimit environment foo.

\begin{foo} starts a group and calls \foo if it is defined, otherwise it does nothing.

\end{foo} checks to see that it matches the corresponding \begin and if so, it calls \endfoo and does an \endgroup. Otherwise, \end{foo} does nothing.

If \end{foo} needs to ignore blanks after it, then \endfoo should globally set

the @ignore switch true with \global\@ignoretrue.

NOTE: \@@end is defined to be the \end command of TEX82.

\enddocument is the user’s command for ending the manuscript file.

\stop is a panic button — to end TEX in the middle.

 \enddocument ==

BEGIN \@checkend{document} %% checks for unmatched \begin

    \clearpage
    \begingroup

if @filesw = true

then close file @mainaux if G@refundefined = true then LaTeX Warning: ’There are undefined references.’ fi if @multiplelabels = true then LaTeX Warning:

’One or more label(s) multiply defined.’ else \@setckpt {ARG1}{ARG2} == null

\newlabel{LABEL}{VAL} ==

BEGIN

      \reserved@a == VAL
      if def(\reserved@a) = def(\r@LABEL)

else @tempswa := true fi END

\bibcite{LABEL}{VAL} == null

BEGIN

      \reserved@a == VAL
      if def(\reserved@a) = def(\g@LABEL)

else @tempswa := true fi END

@tempswa := false make @ a letter

\input \jobname.AUX

if @tempswa = true

then LaTeX Warning: ’Label may have changed.

Rerun to get cross-references right.’

fi  fi  fi

\endgroup

finish up END

\@writefile{EXT}{ENTRY} ==

if tf@EXT undefined

else \write\tf@EXT{ENTRY}

fi

\@currenvir The name of the current environment. Initialized to document to so that \end{document} works correctly.

3 \def\@currenvir{document}
\if@ignore
\@ignoretrue
\@ignorefalse

4 \newif\if@ignore
\enddocument
5 \def\enddocument{%

The \end{document} hook is executed first. If necessary it can contain a \clearpage to output dangling floats first. In this position it can also contain something like \end{foo} so that the whole document effectively starts and ends with some special environment. However, this must be used with care, eg if two applications would use this without knowledge of each other the order of the environments will be wrong after all.

6 \@enddocumenthook

 7 \@checkend{document}%
 8 \clearpage
 9 \begingroup
10  \if@filesw
11  \immediate\closeout\@mainaux
12  \let\@setckpt\@gobbletwo
13  \let\@newl@bel\@testdef

The previous line is equiv to setting

       \def\newlabel{\@testdef r}%
       \def\bibcite{\@testdef b}%
14  \@tempswafalse
15  \makeatletter \input\jobname.aux
16  \fi
17  \@dofilelist

First we check for font size substitution bigger than \fontsubfuzz. The \relax is necessary because this is a macro not a register.

18  \ifdim \font@submax >\fontsubfuzz\relax

In case you wonder about the \@gobbletwo inside the message below, this is a horrible hack to remove the tokens \on@line. that are added by \@font@warning at the end.

19  \@font@warning{Size substitutions with differences\MessageBreak
20  up to \font@submax\space have occured.\@gobbletwo}%
21  \fi

The macro \@defaultsubs is initially \relax but gets redefined to produce a warning if there have been some default font substitutions.

22  \@defaultsubs

The macro \@refundefined is initially \relax but gets redefined to produce a warning if there are undefined refs.

23  \@refundefined

If a label is defined more than once, \@tempswa will always be true and thus produce a “Label(s) may … ” warning. But since a rerun will not solve that problem (unless one uses a package like varioref that generates labels on the fly), we suppress this message.

24  \if@filesw
25  \ifx \@multiplelabels \relax
26  \if@tempswa
27  \@latex@warning@no@line{Label(s) may have changed.
28  Rerun to get cross-references right}%
29  \fi
30  \else
31  \@multiplelabels
32  \fi
33  \fi
34 \endgroup
35 \deadcycles\z@\@@end}

\@testdef
36 \def\@testdef #1#2#3{%
37 \def\reserved@a{#3}\expandafter \ifx \csname #1@#2\endcsname
38 \reserved@a  \else \@tempswatrue \fi}
\@writefile
39 \long\def\@writefile#1#2{%
40 \@ifundefined{tf@#1}\relax
41  {\@temptokena{#2}%
42  \immediate\write\csname tf@#1\endcsname{\the\@temptokena}%
43  }%

44 }

\stop
45 \def\stop{\clearpage\deadcycles\z@\let\par\@@par\@@end}

46 \everypar{\@nodocument} %% To get an error if text appears before the
47 \nullfont               %% \begin{document}

\begin, \end, and \@checkend changed so \end{document} will catch an unmatched \begin. Changed 24 May 89 as suggested by Frank Mittelbach and Rainer Sch\"opf.

\begin{NAME} ==

BEGIN

IF \NAME undefined THEN \reserved@a == BEGIN report error END

                    ELSE \reserved@a ==
                               (\@currenvir :=L NAME) \NAME

FI @ignore :=G F %% Added 30 Nov 88

\begingroup
\@endpe := F
\@currenvir :=L NAME
\NAME

END

\end{NAME} ==

BEGIN

\endNAME
\@checkend{NAME}
\endgroup

IF @endpe = T %% @endpe set True by \@endparenv

 THEN \@doendpe           %% \@doendpe redefines \par and
\everypar

%% to suppress paragraph indentation in FI %% immediately following text IF @ignore = T

THEN @ignore :=G F

          \ignorespaces

FI

END

 \@checkend{NAME} ==

BEGIN

   IF \@currenvir = NAME
     ELSE \@badend{NAME}

FI

END

\begin
48 \def\begin#1{%
49 \@ifundefined{#1}%
50  {\def\reserved@a{\@latex@error{Environment #1 undefined}\@eha}}%
51  {\def\reserved@a{\def\@currenvir{#1}%
52  \edef\@currenvline{\on@line}%
53  \csname #1\endcsname}}%
54 \global\@ignorefalse %% \global...added 2 May 90
55 \begingroup\@endpefalse\reserved@a}
\end
56 \def\end#1{%
57 \csname end#1\endcsname\@checkend{#1}%
58 \expandafter\endgroup\if@endpe\@doendpe\fi
59 \if@ignore\global\@ignorefalse\ignorespaces\fi}
\@checkend
60 \def\@checkend#1{\def\reserved@a{#1}\ifx
61  \reserved@a\@currenvir \else\@badend{#1}\fi}

\@currenvline We do need a default value for \@currenvline on top-level since the document environment cancels the brace group. This means that a missmatch with \begin {document} will not produce a line number. Thus the outer default must be \@empty or we will end up with two spaces.

62 \let\@currenvline\@empty

1.2 Center, Flushright, Flushleft

63 \message{center,}
 \center, \flushright and \flushleft set
   \rightskip = 0pt or \@flushglue (as appropriate)

\leftskip = 0pt or \@flushglue (as appropriate)

   \parindent = 0pt
   \parfillskip = 0pt. (except \flushleft)
   \\  == \par \vskip -\parskip

\\[LENGTH] == \\ \vskip LENGTH

   \\*  == \par \penalty 10000 \vskip -\parskip

\\*[LEN] == \\* \vskip LENGTH

They invoke the trivlist environment to handle vertical spacing before and after them.

 \centering, \raggedright and \raggedleft are the declaration analogs

of the above.

\raggedright has a more universal effect, however. It sets \@rightskip := flushglue. Every environment, like the list environments, that set \rightskip to its ’normal’ value set it to \@rightskip

\@centercr
64 \def\@centercr{\ifhmode \unskip\else \@nolnerr\fi
65  \par\@ifstar{\nobreak\@xcentercr}\@xcentercr}
\@xcentercr
66 \def\@xcentercr{\addvspace{-\parskip}\@ifnextchar
67  [\@icentercr\ignorespaces}
\@icentercr
68 \def\@icentercr[#1]{\vskip #1\ignorespaces}

center We use \relax to prevent \item scanning too far.

69 \def\center{\trivlist \centering\item\relax}
70 \def\centering{\let\\\@centercr\rightskip\@flushglue\leftskip\@flushglue
71 \parindent\z@\parfillskip\z@skip}
72 \def\endcenter{\endtrivlist}
73 \newskip\@rightskip \@rightskip \z@skip

flushleft We use \relax to prevent \item scanning too far.

74 \def\flushleft{\trivlist \raggedright\item\relax}
75 \def\raggedright{%
76 \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip
77 \leftskip\z@skip
78 \parindent\z@}
79 \def\endflushleft{\endtrivlist}

flushright We use \relax to prevent \item scanning too far.

80 \def\flushright{\trivlist \raggedleft\item\relax}
81 \def\raggedleft{\let\\\@centercr\rightskip\z@skip\leftskip\@flushglue
82 \parindent\z@\parfillskip\z@skip}
83 \def\endflushright{\endtrivlist}
84 \message{verbatim,}

1.3 Verbatim

The verbatim environment uses the fixed-width \ttfamily font, turns blanks into spaces, starts a new line for each carrige return (or sequence of consecutive carriage returns), and interprets EVERY character literally. I.e., all special characters \, {, $, etc. are \catcode'd to ’other’.

The command \verb produces in-line verbatim text, where the argument is delimited by any pair of characters. E.g., \verb #...# takes ’...’ as its argument, and sets it verbatim in \ttfamily font.

The *-variants of these commands is the same, except that spaces print as the TeXbook’s space character instead of as blank spaces.

\@vobeyspaces
85 {\catcode`\ =\active%
86 \gdef\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}
\@xobeysp
87 \def\@xobeysp{\leavevmode\nobreak\ }
\@xverbatim
\@sxverbatim
88 \begingroup \catcode `|=0 \catcode `[= 1
89 \catcode`]=2 \catcode `\{=12 \catcode `\}=12
90 \catcode`\\=12 |gdef|@xverbatim#1\end{verbatim}[#1|end[verbatim]]
91 |gdef|@sxverbatim#1\end{verbatim*}[#1|end[verbatim*]]
92 |endgroup

\@verbatim Real start of verbatim environment We use \relax to prevent \item scanning too far.

93 \def\@verbatim{\trivlist \item\relax
94 \if@minipage\else\vskip\parskip\fi
95 \leftskip\@totalleftmargin\rightskip\z@skip
96 \parindent\z@\parfillskip\@flushglue\parskip\z@skip

Added \@@par to clear possible \parshape definition from a surrounding list (the verbatim guru says).

97 \@@par

 98 \@tempswafalse
 99 \def\par{%
100  \if@tempswa

A \leavevmode added: needed if, for example, a blank verbatim line is the first thing in a list item (wow!).

101  \leavevmode \null \@@par\penalty\interlinepenalty
102  \else
103  \@tempswatrue
104  \ifhmode\@@par\penalty\interlinepenalty\fi
105  \fi}%

To allow customization we hide the font used in a separate macro.

106 \obeylines \verbatim@font \@noligs
107 \let\do\@makeother \dospecials

To avoid a breakpoint after the labels box, we remove the penalty put there by the list macros: another use of \unpenalty!

108 \everypar \expandafter{\the\everypar \unpenalty}%

109 }

\begin{matrix}\verbatim \\ \endverbatim \end{matrix} (RmS 93/09/19) Protected against ‘missing item’ error message triggered by empty verbatim environment.

110 \def\verbatim{\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
111 \def\endverbatim{\if@newlist \leavevmode\fi\endtrivlist}

\verbatim@font Macro to select the font used for verbatim typesetting. It also does other work if necessary for the font used.

112 \def\verbatim@font{\normalfont\ttfamily}
verbatim*
113 \@namedef{verbatim*}{\@verbatim\@sxverbatim}
114 \expandafter\let\csname endverbatim*\endcsname =\endverbatim
\@makeother
115 \def\@makeother#1{\catcode`#112\relax}
116 \let\verb@balance@group\@empty

117

118 \def\verb@egroup{\global\let\verb@balance@group\@empty\egroup}

119

120 \begingroup
121 \obeylines%
122 \gdef\verb@eol@error{\obeylines%
123  \def^^M{\verb@egroup\@latex@error{%
124  \noexpand\verb ended by end of line}\@ehc}}%
125 \endgroup

\verb Typesetting a small piece verbatim.

126 \def\verb{\relax\ifmmode\hbox\else\leavevmode\null\fi

127 \bgroup \verbatim@font\@noligs
128  \verb@eol@error \let\do\@makeother \dospecials
129  \@ifstar\@sverb\@verb}

Definitions of \@sverb and \@verb changed so \verb+ foo+ does not lose leading blanks when it comes at the beginning of a line. Change made 24 May 89. Suggested by Frank Mittelbach and Rainer Sch\"opf.

130 \def\@sverb#1{%
131 \catcode`#1\active
132 \lccode`\~`#1%
133 \gdef\verb@balance@group{\verb@egroup
134  \@latex@error{\noexpand\verb illegal in command argument}\@ehc}%
135 \aftergroup\verb@balance@group
136 \lowercase{\let~\verb@egroup}}%
137 \def\@verb{\@vobeyspaces \frenchspacing \@sverb}
\verbatim@nolig@list
138 \def\verbatim@nolig@list{\do\`\do\<\do\>\do\,\do\'\do\-}
\do@noligs
139 \def\do@noligs#1{%
140 \catcode`#1\active
141 \begingroup
142  \lccode`\~`#1\relax
143  \lowercase{\endgroup\def~{\leavevmode\kern\z@\char`#1}}}

\@noligs To stay compatible with packages that use \@noligs we keep it.

144 \def\@noligs{\let\do\do@noligs \verbatim@nolig@list}

145 ⟨/2ekernel⟩