1 % \iffalse meta-comment
4 % The LaTeX3 Project and any individual authors listed elsewhere
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % http://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2005/12/01 or later.
18 % This file has the LPPL maintenance status "maintained".
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
30 %%% From File: ltmiscen.dtx
34 \ProvidesFile{ltmiscen.dtx}
35 [2014/09/29 v1.1l LaTeX Kernel (Misc. Environments)]
37 \documentclass{ltxdoc}
38 \GetFileInfo{ltmiscen.dtx}
51 \MaintainedByLaTeXTeam{latex}
59 % \changes{v1.0c}{1994/03/28}{Improve Documentation}
60 % \changes{v1.0d}{1994/03/29}{Remove counter macros to ltcntlen}
61 % \changes{v1.0g}{1994/05/02}{Changed 91 to 1991 and moved some bits}
62 % \changes{v1.0i}{1994/05/05}{Removed braces from ifnextchar and
64 % \changes{v1.0m}{1994/05/20}{Use new warning commands}
65 % \changes{v1.0n}{1994/05/21}{Use new error commands}
66 % \changes{v1.0s}{1994/10/14}{Move math to other file}
67 % \changes{v1.0v}{1994/11/17}
68 % {\cs{@tempa} to \cs{reserved@a}}
69 % \changes{v1.0x}{1995/04/22}{Removed extra def of \cs{@gobble}}
70 % \changes{v1.0z}{1995/07/13}{Improve Documentation}
71 % \changes{v1.1c}{1996/04/22}{Improve Documentation}
72 % \changes{v1.1d}{1996/06/03}{Move setting of verbatim font and
74 % \changes{v1.1g}{1998/08/17}{(RmS) Minor documentation fixes.}
76 % \section{Miscellaneous Environments}
77 % This section implements the basic environment mechanism, and also
78 % a few specific environments including |document|, The math
79 % environments and related commands, the `flushing' environments,
80 % (|center|, |flushleft|, |flushright|), and |verbatim|.
86 \message{environments,}
89 % \subsection{Environments}
91 % |\begin{foo}| and |\end{foo}| are used to delimit environment |foo|.
93 % |\begin{foo}| starts a group and calls |\foo| if it is defined,
94 % otherwise it does nothing.
96 % |\end{foo}| checks to see that it matches the
97 % corresponding |\begin| and if so, it calls |\endfoo| and does an
98 % |\endgroup|. Otherwise, |\end{foo}| does nothing.
100 % If |\end{foo}| needs to ignore blanks after it, then |\endfoo| should
101 % globally set the |@ignore| switch true with |\@ignoretrue|
102 % (this will automatically be global).
105 % NOTE: |\@@end| is defined to be the |\end| command of \TeX82.
107 % |\enddocument| is the user's command for ending the manuscript file.
109 % |\stop| is a panic button --- to end \TeX\ in the middle.
111 % \begin{oldcomments}
114 % \@checkend{document} %% checks for unmatched \begin
118 % then close file @mainaux
119 % if G@refundefined = true
120 % then LaTeX Warning: 'There are undefined references.' fi
121 % if @multiplelabels = true
122 % then LaTeX Warning:
123 % 'One or more label(s) multiply defined.'
125 % \@setckpt {ARG1}{ARG2} == null
126 % \newlabel{LABEL}{VAL} ==
129 % if def(\reserved@a) = def(\r@LABEL)
130 % else @tempswa := true fi
132 % \bibcite{LABEL}{VAL} == null
135 % if def(\reserved@a) = def(\g@LABEL)
136 % else @tempswa := true fi
140 % \input \jobname.AUX
142 % then LaTeX Warning: 'Label may have changed.
143 % Rerun to get cross-references right.'
149 % \@writefile{EXT}{ENTRY} ==
150 % if tf@EXT undefined
151 % else \write\tf@EXT{ENTRY}
155 % \begin{macro}{\@currenvir}
156 % The name of the current environment. Initialized to
157 % \texttt{document} to so that |\end{document}| works correctly.
159 \def\@currenvir{document}
163 % \begin{macro}{\if@ignore}
164 % \begin{macro}{\@ignoretrue}
165 % \begin{macro}{\@ignorefalse}
166 % \changes{v1.1e}{1996/07/26}{put \cs{global} into definition}
168 \def\@ignorefalse{\global\let\if@ignore\iffalse}
169 \def\@ignoretrue {\global\let\if@ignore\iftrue}
177 % \begin{macro}{\ignorespacesafterend}
178 % \changes{v1.1e}{1996/07/26}{user level macro added}
180 \let\ignorespacesafterend\@ignoretrue
184 % \begin{macro}{\enddocument}
185 % \changes{LaTeX2.09}{1993/08/03}
186 % {Changed redefinition of \cs{global} to redefinition
188 % \changes{LaTeX2.09}{1993/09/08}
189 % {Added warning in case of undefined references.}%
190 % \changes{v0.9e}{1993/12/09}{Hook added}
194 % The |\end{document}| hook is executed first. If necessary it can
195 % contain a |\clearpage| to output dangling floats first. In this
196 % position it can also contain something like |\end{foo}| so that
197 % the whole document effectively starts and ends with some special
198 % environment. However, this must be used with care, eg if two
199 % applications would use this without knowledge of each other the
200 % order of the environments will be wrong after all.
201 % |\AtEndDocument| is redefined
202 % at this point so that and such commands that get into the hook do
203 % not chase their tail\ldots
204 % \changes{v1.0y}{1995/04/27}{\cs{@checkend} moved after hook}
205 % \changes{v1.0z}{1995/07/13}{Set \cs{@setckpt} to \cs{@gobbletwo}
206 % instead of defining it by hand}
207 % \changes{v1.1i}{2000/05/19}
208 % {Reset \cs{AtEndDocument} for latex/3060}
210 \let\AtEndDocument\@firstofone
212 \@checkend{document}%
216 \immediate\closeout\@mainaux
217 \let\@setckpt\@gobbletwo
218 \let\@newl@bel\@testdef
220 % \changes{v1.0z}{1995/07/13}{Shorten redefinition of \cs{bibcite} and
222 % The previous line is equiv to setting
224 % \def\newlabel{\@testdef r}%
225 % \def\bibcite{\@testdef b}%
227 % \changes{v1.1k}{2010/08/17}{Use braces around \cs{input} arg (pr/4124)}
228 % \changes{v1.1l}{2010/08/17}{Change of plan: use \cs{@@input} instead
230 % We use |\@@input| to load the \texttt{.aux} file, so that it doesn't
231 % show up in the list of files produced by |\listfiles|.
234 \makeatletter \@@input\jobname.aux
237 % \changes{v1.0w}{1994/11/30}
238 % {(DPC) Use \cs{@dofilelist}}
242 % First we check for font size substitution bigger than
243 % |\fontsubfuzz|. The |\relax| is necessary because this is a macro
245 % \changes{v1.0w}{1994/11/30}
246 % {(DPC) Do warnings even for \cs{nofiles}}
248 \ifdim \font@submax >\fontsubfuzz\relax
250 % In case you wonder about the |\@gobbletwo| inside the message
251 % below, this is a horrible hack to remove the tokens |\on@line.|
252 % that are added by |\@font@warning| at the end.
253 % \changes{v1.1j}{2000/07/11}{Fix typo in warning}
255 \@font@warning{Size substitutions with differences\MessageBreak
256 up to \font@submax\space have occurred.\@gobbletwo}%
259 % The macro |\@defaultsubs| is initially |\relax| but gets redefined
261 % a warning if there have been some default font substitutions.
262 % \changes{v1.0z}{1995/07/13}{Use \cs{@defaultsubs} instead of switch}
266 % The macro |\@refundefined| is initially |\relax| but gets redefined
267 % to produce a warning if there are undefined refs.
268 % \changes{v1.1b}{1995/10/24}{Use \cs{@refundefined} instead of switch}
272 % If a label is defined more than once, |\@tempswa| will always be
273 % true and thus produce a ``Label(s) may \ldots'' warning. But
274 % since a rerun will not solve that problem (unless one uses a
275 % package like \texttt{varioref} that generates labels on the fly),
276 % we suppress this message.
277 % \changes{v1.0e}{1994/04/20}{Changed logic for producing
279 % \changes{v1.1b}{1995/10/24}{Changed logic for producing
280 % warning messages and removed switch}
283 \ifx \@multiplelabels \relax
285 \@latex@warning@no@line{Label(s) may have changed.
286 Rerun to get cross-references right}%
293 \deadcycles\z@\@@end}
297 % \begin{macro}{\@testdef}
299 \def\@testdef #1#2#3{%
300 \def\reserved@a{#3}\expandafter \ifx \csname #1@#2\endcsname
301 \reserved@a \else \@tempswatrue \fi}
306 % \begin{macro}{\@writefile}
307 % \changes{v1.0l}{1994/05/20}{Added correct setting of \cs{protect}.}
308 % \changes{v1.0t}{1994/11/04}{Removed setting of \cs{protect}. ASAJ.}
309 % \changes{v1.0z}{1995/07/13}{Added missing percent and use \cs{relax}
312 \long\def\@writefile#1#2{%
313 \@ifundefined{tf@#1}\relax
315 \immediate\write\csname tf@#1\endcsname{\the\@temptokena}%
321 % \begin{macro}{\stop}
323 \def\stop{\clearpage\deadcycles\z@\let\par\@@par\@@end}
328 % \begin{oldcomments}
331 \everypar{\@nodocument} %% To get an error if text appears before the
332 \nullfont %% \begin{document}
335 % \begin, \end, and \@checkend changed so \end{document} will catch
336 % an unmatched \begin. Changed 24 May 89 as suggested by
337 % Frank Mittelbach and Rainer Sch\"opf.
341 % IF \NAME undefined THEN \reserved@a == BEGIN report error END
342 % ELSE \reserved@a ==
343 % (\@currenvir :=L NAME) \NAME
345 % @ignore :=G F %% Added 30 Nov 88
348 % \@currenvir :=L NAME
357 % IF @endpe = T %% @endpe set True by \@endparenv
358 % THEN \@doendpe %% \@doendpe redefines \par and \everypar
359 % %% to suppress paragraph indentation in
360 % FI %% immediately following text
367 % \@checkend{NAME} ==
369 % IF \@currenvir = NAME
370 % ELSE \@badend{NAME}
377 % \begin{macro}{\begin}
378 % \changes{LaTeX2.09}{1992/03/18}{Changed \cs{@ignoretrue} to
379 % \cs{@ignorefalse} (as documented)}
380 % \changes{LaTeX2.09}{1992/08/24}{Added code to \cs{begin} to
381 % remember line number. Used by \cs{@badend} to display
382 % position of non-matching \cs{begin}.}
383 % \changes{v1.1e}{1996/07/26}{remove \cs{global} before \cs{@ignore...}}
387 {\def\reserved@a{\@latex@error{Environment #1 undefined}\@eha}}%
388 {\def\reserved@a{\def\@currenvir{#1}%
389 \edef\@currenvline{\on@line}%
390 \csname #1\endcsname}}%
392 \begingroup\@endpefalse\reserved@a}
396 % \begin{macro}{\end}
397 % \changes{v1.1e}{1996/07/26}{remove \cs{global} before \cs{@ignore...}}
400 \csname end#1\endcsname\@checkend{#1}%
401 \expandafter\endgroup\if@endpe\@doendpe\fi
402 \if@ignore\@ignorefalse\ignorespaces\fi}
406 % \begin{macro}{\@checkend}
408 \def\@checkend#1{\def\reserved@a{#1}\ifx
409 \reserved@a\@currenvir \else\@badend{#1}\fi}
413 % \begin{macro}{\@currenvline}
414 % We do need a default value for |\@currenvline| on top-level since
415 % the document environment cancels the brace group. This means that
416 % a mismatch with |\begin|\allowbreak|{document}| will not produce
417 % a line number. Thus the outer default must be |\@empty| or we
418 % will end up with two spaces.
419 % \changes{v1.0q}{1994/05/24}{Use \cs{@empty} as outer default}
421 \let\@currenvline\@empty
426 % \subsection{Center, Flushright, Flushleft}
432 % \begin{oldcomments}
434 % \center, \flushright and \flushleft set
435 % \rightskip = 0pt or \@flushglue (as appropriate)
436 % \leftskip = 0pt or \@flushglue (as appropriate)
438 % \parfillskip = 0pt. (except \flushleft)
439 % \\ == \par \vskip -\parskip
440 % \\[LENGTH] == \\ \vskip LENGTH
441 % \\* == \par \penalty 10000 \vskip -\parskip
442 % \\*[LEN] == \\* \vskip LENGTH
444 % They invoke the trivlist environment to handle vertical spacing before
447 % \centering, \raggedright and \raggedleft are the declaration analogs
450 % \raggedright has a more universal effect, however. It sets
451 % \@rightskip := flushglue. Every environment, like the list
453 % that set \rightskip to its 'normal' value set it to \@rightskip
457 % \begin{macro}{\@centercr}
458 % \changes{v1.0h}{1994/05/03}{\cs{@badcrerr} replaced by \cs{@nolnerr}}
459 % \changes{v1.0z}{1995/07/13}{Use \cs{nobreak}}
461 \def\@centercr{\ifhmode \unskip\else \@nolnerr\fi
462 \par\@ifstar{\nobreak\@xcentercr}\@xcentercr}
466 % \begin{macro}{\@xcentercr}
468 \def\@xcentercr{\addvspace{-\parskip}\@ifnextchar
469 [\@icentercr\ignorespaces}
473 % \begin{macro}{\@icentercr}
475 \def\@icentercr[#1]{\vskip #1\ignorespaces}
480 % \begin{environment}{center}
481 % \changes{v0.9h}{1993/12/13}{Removed optional argument of \cs{item}}
482 % \changes{v1.0u}{1994/11/12}{Changed end macro to \cs{def}: safer and
484 % We use |\relax| to prevent |\item| scanning too far.
486 \def\center{\trivlist \centering\item\relax}
490 \def\endcenter{\endtrivlist}
494 % \begin{macro}{\centering}
498 \rightskip\@flushglue\leftskip\@flushglue
499 \parindent\z@\parfillskip\z@skip}
503 % \begin{macro}{\@rightskip}
505 \newskip\@rightskip \@rightskip \z@skip
509 % \begin{environment}{flushleft}
510 % \changes{v0.9h}{1993/12/13}{Removed optional argument of \cs{item}}
511 % \changes{v1.0u}{1994/11/12}{Changed end macro to \cs{def}: safer and
513 % We use |\relax| to prevent |\item| scanning too far.
515 \def\flushleft{\trivlist \raggedright\item\relax}
519 \def\endflushleft{\endtrivlist}
523 % \begin{macro}{\raggedright}
526 \let\\\@centercr\@rightskip\@flushglue \rightskip\@rightskip
532 % \begin{environment}{flushright}
533 % \changes{v0.9h}{1993/12/13}{Removed optional argument of \cs{item}}
534 % \changes{v1.0u}{1994/11/12}{Changed end macro to \cs{def}: safer and
536 % We use |\relax| to prevent |\item| scanning too far.
538 \def\flushright{\trivlist \raggedleft\item\relax}
542 \def\endflushright{\endtrivlist}
546 % \begin{macro}{\raggedleft}
550 \rightskip\z@skip\leftskip\@flushglue
551 \parindent\z@\parfillskip\z@skip}
559 % \subsection{Verbatim}
562 % The verbatim environment uses the fixed-width |\ttfamily| font, turns
563 % blanks into spaces, starts a new line for each carriage return (or
564 % sequence of consecutive carriage returns), and interprets
565 % \emph{every} character literally.
566 % I.e., all special characters |\, {, $|, etc.
567 % are |\catcode|'d to 'other'.
569 % The command |\verb| produces in-line verbatim text, where the argument
570 % is delimited by any pair of characters. E.g., |\verb #...#| takes
571 % `|...|' as its argument, and sets it verbatim in |\ttfamily| font.
573 % The *-variants of these commands are the same, except that spaces
574 % print as the \TeX{}book's space character instead of as blank spaces.
576 % \begin{macro}{\@vobeyspaces}
578 {\catcode`\ =\active%
579 \gdef\@vobeyspaces{\catcode`\ \active\let \@xobeysp}}
583 % \begin{macro}{\@xobeysp}
584 % \changes{v1.0z}{1995/07/13}{Use \cs{nobreak}}
585 % \changes{v1.1f}{1996/09/28}{Moved to ltspace.dtx}
589 % \begin{macro}{\@xverbatim}
590 % \begin{macro}{\@sxverbatim}
592 \begingroup \catcode `|=0 \catcode `[= 1
593 \catcode`]=2 \catcode `\{=12 \catcode `\}=12
594 \catcode`\\=12 |gdef|@xverbatim#1\end{verbatim}[#1|end[verbatim]]
595 |gdef|@sxverbatim#1\end{verbatim*}[#1|end[verbatim*]]
601 % \begin{macro}{\@verbatim}
602 % \changes{LaTeX2.09}{1991/07/24}{Added \cs{penalty}\cs{interlinepenalty}
603 % to definition of \cs{par} so that \cs{samepage} works}
604 % \changes{v0.9h}{1993/12/13}{Removed optional argument of \cs{item}}
605 % Real start of verbatim environment
606 % We use |\relax| to prevent |\item| scanning too far.
607 % \changes{v0.9p}{1994/01/18}
608 % {Add \cs{global}\cs{@inlabelfalse}}
609 % \changes{v1.0b}{1994/03/16}
610 % {Remove \cs{global}\cs{@inlabelfalse} again.}
612 \def\@verbatim{\trivlist \item\relax
613 \if@minipage\else\vskip\parskip\fi
614 \leftskip\@totalleftmargin\rightskip\z@skip
615 \parindent\z@\parfillskip\@flushglue\parskip\z@skip
617 % \changes{LaTeX2.09}{1991/08/26}{\cs{@@par} added}
618 % Added |\@@par| to clear possible |\parshape| definition
619 % from a surrounding list (the verbatim guru says).
620 % \changes{v0.9p}{1994/01/18}
621 % {Only add \cs{penalty} if in hmode}
628 % A |\leavevmode| added: needed if, for example, a blank verbatim
629 % line is the first thing in a list item (wow!).
630 % \changes{v1.0f}{1994/04/29}{\cs{leavevmode} added}
632 \leavevmode \null \@@par\penalty\interlinepenalty
635 \ifhmode\@@par\penalty\interlinepenalty\fi
638 % To allow customization we hide the font used in a separate macro.
639 % \changes{v0.9a}{1993/11/21}{use \cs{verbatim@font} instead of \cs{tt}}
640 % \changes{v0.9h}{1993/12/13}{Readded \cs{@noligs}}
641 % \changes{v1.1d}{1996/06/03}{Exchanged the following two code lines
642 % so that \cs{dospecials} cannot reset the category code
643 % of characters handled by \cs{@noligs}.}
644 % \changes{v1.1h}{2000/01/07}{Disable hyphenation even if the font allows it.}
646 \let\do\@makeother \dospecials
647 \obeylines \verbatim@font \@noligs
648 \hyphenchar\font\m@ne
650 % To avoid a breakpoint after the labels box, we remove the penalty
651 % put there by the list macros: another use of |\unpenalty|!
652 % \changes{v1.0f}{1994/04/29}{Change to \cs{everypar} added}
654 \everypar \expandafter{\the\everypar \unpenalty}%
659 % \begin{macro}{\verbatim}
660 % \begin{macro}{\endverbatim}
661 % (RmS 93/09/19) Protected against `missing item' error message
662 % triggered by empty verbatim environment.
664 \def\verbatim{\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
665 \def\endverbatim{\if@newlist \leavevmode\fi\endtrivlist}
670 % \begin{macro}{\verbatim@font}
671 % \changes{v0.9a}{1993/11/21}{Macro added}
672 % Macro to select the font used for verbatim typesetting.
673 % It also does other work if necessary for the font used.
674 % \changes{v0.9s}{1994/01/21}{Removed unnecessary category code
677 \def\verbatim@font{\normalfont\ttfamily}
682 % \begin{environment}{verbatim*}
684 \@namedef{verbatim*}{\@verbatim\@sxverbatim}
685 \expandafter\let\csname endverbatim*\endcsname =\endverbatim
689 % \begin{macro}{\@makeother}
691 \def\@makeother#1{\catcode`#112\relax}
695 % \begin{macro}{\verb@balance@group}
696 % \changes{LaTeX2.09}{1993/09/07}
697 % {(RmS) Changed definition of \cs{verb} so that it detects a
698 % missing second delimiter.}
700 \let\verb@balance@group\@empty
704 % \begin{macro}{\verb@egroup}
706 \def\verb@egroup{\global\let\verb@balance@group\@empty\egroup}
710 % \begin{macro}{\verb@eol@error}
714 \gdef\verb@eol@error{\obeylines%
715 \def^^M{\verb@egroup\@latex@error{%
716 \noexpand\verb ended by end of line}\@ehc}}%
721 % \begin{macro}{\verb}
722 % \changes{LaTeX2.09}{1992/08/24}
723 % {Changed \cs{verb} and \cs{@sverb} to work correctly
725 % \changes{v0.9a}{1993/11/21}{Use \cs{verbatim@font} instead of
727 % \changes{v1.1a}{1995/09/19}{Put \cs{@noligs} after
728 % \cs{verbatim@font} where it belongs.}
729 % Typesetting a small piece verbatim.
730 % \changes{v1.1d}{1996/06/03}{Put setting of verbatim font after
732 % so that \cs{dospecials} cannot reset the category code
733 % of characters handled by \cs{@noligs}.}
735 \def\verb{\relax\ifmmode\hbox\else\leavevmode\null\fi
737 \verb@eol@error \let\do\@makeother \dospecials
738 \verbatim@font\@noligs
739 \@ifstar\@sverb\@verb}
744 % \begin{macro}{\@sverb}
745 % \changes{v1.0j}{1994/05/10}{Slight change in error message text.}
746 % Definitions of |\@sverb| and |\@verb| changed so |\verb+ foo+|
747 % does not lose leading blanks when it comes at the beginning of a line.
748 % Change made 24 May 89. Suggested by Frank Mittelbach and Rainer
755 \gdef\verb@balance@group{\verb@egroup
756 \@latex@error{\noexpand\verb illegal in command argument}\@ehc}%
757 \aftergroup\verb@balance@group
758 \lowercase{\let~\verb@egroup}}%
762 % \begin{macro}{\@verb}
764 \def\@verb{\@vobeyspaces \frenchspacing \@sverb}
768 % \begin{macro}{\verbatim@nolig@list}
769 % \changes{LaTeX2.09}{1993/09/03}
770 % {Replaced \cs{@noligs} by extensible list}
772 \def\verbatim@nolig@list{\do\`\do\<\do\>\do\,\do\'\do\-}
776 % \begin{macro}{\do@noligs}
782 \lowercase{\endgroup\def~{\leavevmode\kern\z@\char`#1}}}
786 % \begin{macro}{\@noligs}
787 % To stay compatible with packages that use |\@noligs| we keep it.
788 % \changes{v0.9h}{1993/12/13}{Readded \cs{@noligs}}
790 \def\@noligs{\let\do\do@noligs \verbatim@nolig@list}
794 % \changes{v0.9i}{1993/12/16}{\cs{literal} added}
795 % \changes{v1.0r}{1994/05/26/16}{\cs{literal} removed}