The alltt environment^{∗}

Johannes Braams

1997/06/16

Abstract

This package defines the alltt environment, which is like the verbatim environment except that \, {, and } have their usual meanings.

Thus, other commands and environments can appear within an alltt environment.

1 Introduction

alltt Here are some things you may want to do in an alltt environment:

• Change fonts–e.g., by typing {\em emphasized text\/}

• Insert text from a file foo.tex by typing \input{foo}. Beware that each <return> starts a new line, so if foo.tex ends with a <return> you can wind up with an extra blank line if you’re not careful.

• Insert a math formula. Note that $ just produces a dollar sign, so you’ll have to type \(...\) or \[...\]. Also, ^and _just produce their characters; use \sp or \sb for super- and subscripts, as in \(x\sp{2}\).

2 The Implementation

1 ⟨∗package⟩

alltt The alltt environment is similar to the verbatim environment, except that \, { and } have their usual behaviour.

2 \begingroup
3 \lccode`\~=`\'
4 \lowercase{\endgroup
5 \newenvironment{alltt}{%
6 \trivlist
7 \item\relax
8  \if@minipage

∗This file has version number v2.0g, last revised 1997/06/16.

 9  \else
10  \vskip\parskip
11  \fi
12  \leftskip\@totalleftmargin
13  \rightskip\z@skip
14  \parindent\z@
15  \parfillskip\@flushglue
16  \parskip\z@skip
17  \@@par
18  \@tempswafalse
19  \def\par{%
20  \if@tempswa
21  \leavevmode\null\@@par\penalty\interlinepenalty
22  \else
23  \@tempswatrue
24  \ifhmode\@@par\penalty\interlinepenalty\fi
25  \fi}
26  \obeylines
27  \verbatim@font
28  \let\org@prime~%
29  \@noligs
30  \everymath\expandafter{\the\everymath
31  \catcode`\'=12 \let~\org@prime}
32  \everydisplay\expandafter{\the\everydisplay
33  \catcode`\'=12 \let~\org@prime}
34  \let\org@dospecials\dospecials
35  \g@remfrom@specials{\\}
36  \g@remfrom@specials{\{}
37  \g@remfrom@specials{\}}
38  \let\do\@makeother
39  \dospecials
40  \let\dospecials\org@dospecials
41  \frenchspacing\@vobeyspaces
42  \everypar \expandafter{\the\everypar \unpenalty}}
43 {\endtrivlist}}

\g@remfrom@specials In the old implementation of the alltt package a fixed \dospecials was used. However nowadays the \dospecials command might contain more special characters at run-time then as was defined in the format. Therefore we remove the necessary special character from \dospecials at the start of the alltt environment. For this we need a macro. Remember that the list of special characters in \dospecials contains the control sequence \do between the characters. We use that to check whether a character has to be removed.

The macro \g@remfrom@specials takes one argument, the chracter to be removed from the list.

44 \def\g@remfrom@specials#1{%

We build up a new list in \@new@speicals.

45 \def\@new@specials{}

The command \@remove compares its argument with the argument of

\g@remfrom@specials.
46 \def\@remove##1{%
47  \ifx##1#1\else

When they are not the same the argument of \@remove is added (together with \do) to the new list.

48  \g@addto@macro\@new@specials{\do ##1}\fi}
Now we \let \do be equal to \@remove and execute \dospecials.
49 \let\do\@remove\dospecials

All that’s left is to make \dospecials point to the new list.

50 \let\dospecials\@new@specials

51 }

52 ⟨/package⟩

Change History

v2.0b

alltt:  Added  a  missing

\dospecials . . . . . . . . . . . . . . 1

v2.0c

   alltt: Reset \dospecials after its

changed version is executed … 1

v2.0d

General: A few documentation fixes (PR 1517) . . . . . . . . . . . . . . . 1 v2.0e

alltt: brought definition up to date with the verbatim environment 1 Save and restore (in math mode) the definition of the ' character 1

v2.0f

alltt: Added setting of the

\catcode of the ' character … 2 v2.0g

General: A few documentation fixes (PR 2520) . . . . . . . . . . . . . . . 1

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\' . . . . . . . . . . 3, 31, 33 \@@par . . . . . . 17, 21, 24

\@flushglue . . . . . . . 15
\@makeother . . . . . . . 38
\@new@specials 45, 48, 50

\@noligs . . . . . . . . . 29 \@remove . . . . . . . 46, 49

\@tempswafalse . . . . 18

                          \@tempswatrue . . . . . 23
                          \@totalleftmargin . 12
                          \@vobeyspaces . . . . . 41

\\ . . . . . . . . . . . . . . 35

\{ . . . . . . . . . . . . . . 36

\} . . . . . . . . . . . . . . 37

\~ . . . . . . . . . . . . . . . 3

A alltt (environment) 1, \underline{2}

B

                                                   \begingroup . . . . . . . . 2

C \catcode . . . . . . . 31, 33 \def . . . . . . . . 19, 44–46 \do . . . . . . . . 38, 48, 49

\dospecials . . . . . . .

. 34, 39, 40, 49, 50

E

\else . . . . . . . . 9, 22, 47 \endgroup . . . . . . . . . 4

\endtrivlist . . . . . . 43

environments:

alltt . . . . . . . . \underline{1}, 1

\everydisplay . . . . . 32
\everymath . . . . . . . 30

\everypar . . . . . . . . 42

\expandafter . 30, 32, 42

F

\fi . . . . . 11, 24, 25, 48

\frenchspacing . . . . 41

G

\g@addto@macro . . . . 48
\g@remfrom@specials

. . . . . . . 35–37, \underline{44}

I

\if@minipage . . . . . . . 8
\if@tempswa . . . . . . . 20

\ifhmode . . . . . . . . . 24 \ifx . . . . . . . . . . . . . 47

\interlinepenalty 21, 24

\item . . . . . . . . . . . . . 7

L

\lccode . . . . . . . . . . . 3

\leavevmode . . . . . . . 21

\leftskip . . . . . . . . 12 \let . . . . . 28, 31, 33,

34, 38, 40, 49, 50

\lowercase . . . . . . . . 4

N

\newenvironment . . . . 5

\null . . . . . . . . . . . . 21

O

\obeylines . . . . . . . 26
\org@dospecials . 34, 40
\org@prime . . 28, 31, 33

P \par . . . . . . . . . . . . . 19

                          \parfillskip . . . . . . 15
                          \parindent . . . . . . . 14

\parskip . . . . . . . 10, 16 \penalty . . . . . . . 21, 24

R \relax . . . . . . . . . . . . 7

                          \rightskip . . . . . . . 13

T \the . . . . . . . . 30, 32, 42 \trivlist . . . . . . . . . 6

U

                          \unpenalty . . . . . . . 42

V

                          \verbatim@font . . . . 27

\vskip . . . . . . . . . . . 10

Z \z@ . . . . . . . . . . . . . 14 \z@skip . . . . . . . . 13, 16