lterror.dtx

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

Rainer Schöpf

1995/11/28

1 Error handling

This section defines L^{A}TEX’s error commands.

The ‘2ekernel’ code ensures that a \usepackage{autoerr} is essentially ignored if a ‘full’ format is being used that has picture mode already in the format.

 1 ⟨2ekernel⟩\expandafter\let\csname ver@autoerr.sty\endcsname\fmtversion

2 ⟨∗2ekernel | autoload⟩

1.1 General commands

\MessageBreak This command prints a new-line inside a messaage, followed by a continuation line begun with \@msg@continuation. Normally it is defined to be \relax, but inside messages, it is let to \@message@break.

 3 \let\MessageBreak\relax

\GenericInfo This takes two arguments: a continuation and a message, and sends the result to the log file.

 4 \DeclareRobustCommand{\GenericInfo}[2]{%
 5 \begingroup
 6  \def\MessageBreak{^^J#1}%
 7  \set@display@protect
 8  \immediate\write\m@ne{#2\on@line.}%
 9 \endgroup

10 }

\GenericWarning This takes two arguments: a continuation and a message, and sends the result to the screen.

11 \DeclareRobustCommand{\GenericWarning}[2]{%
12 \begingroup
13  \def\MessageBreak{^^J#1}%
14  \set@display@protect
15  \immediate\write\@unused{^^J#2\on@line.^^J}%
16 \endgroup

18 ⟨/2ekernel | autoload⟩

\GenericError This macro takes four arguments: a continuation, an error message, where to go for further information, and the help information. It displays the error message, and sets the error help (the result of typing h to the prompt), and does a horrible hack to turn the last context line (which by default is the only context line) into just three dots. This could be made more efficient.

19 ⟨autoload⟩\def\GenericError{\@autoerr\GenericError}

20 ⟨∗2ekernel | def⟩

21 \bgroup
22 \lccode`\@=`\ %
23 \lccode`\~=`\ %
24 \lccode`\}=`\ %
25 \lccode`\{=`\ %
26 \lccode`\T=`\T%
27 \lccode`\H=`\H%
28 \catcode`\ =11\relax%
29 \lowercase{%
30 \egroup%

Unfortunately TEX versions older than 3.141 have a bug which means that ^^J does not force a linebreak in \message and \errmessage commands. So for these old TEX’s we use \typeout to produce the message, and then have an empty \errmessage command. This causes an extra line of the form

! .

To appear on the terminal, but if you do not like it, you can always upgrade your TEX! In order for your format to use this version, you must define the macro \@TeXversion to be the version number, e.g., 3.14 of the underlying TEX. See the

comments in ltdircheck.dtx.
31 \dimen@\ifx\@TeXversion\@undefined4\else\@TeXversion\fi\p@%
32 \ifdim\dimen@>3.14\p@%

First the ‘standard case’.

33 \DeclareRobustCommand{\GenericError}[4]{%
34 \begingroup%
35 \immediate\write\@unused{}%
36 \def\MessageBreak{^^J}%
37 \set@display@protect%
38 \edef%
39 %    %<-------------------do not delete this space!------------------->%
40 \@err@                                                                 %
41 {{#4}}%
42 \errhelp
43 %    %<-------------------do not delete this space!------------------->%
44 \@err@                                                                 %
45 \let
46 %    %<-------------------do not delete this space!------------------->%

47 \@err@                                                                 %
48 \@empty
49 \def\MessageBreak{^^J#1}%
50 \def~{\errmessage{%
51 #2.^^J^^J%
52 #3^^J%
53 Type  H <return>  for immediate help%
54 %    %<-------------------do not delete this space!------------------->%
55 \@err@                                                                 %
56 }}%
57 ~%
58 \endgroup}%
59 \else%

Secondly the version for old TEX’s.

60 \DeclareRobustCommand{\GenericError}[4]{%
61 \begingroup%
62 \immediate\write\@unused{}%
63 \def\MessageBreak{^^J}%
64 \set@display@protect%
65 \edef%
66 %    %<-------------------do not delete this space!------------------->%
67 \@err@                                                                 %
68 {{#4}}%
69 \errhelp
70 %    %<-------------------do not delete this space!------------------->%
71 \@err@                                                                 %
72 \let
73 %    %<-------------------do not delete this space!------------------->%
74 \@err@                                                                 %
75 \errmessage
76 \def\MessageBreak{^^J#1}%
77 \def~{\typeout{! %
78 #2.^^J^^J%
79 #3^^J%
80 Type  H <return>  for immediate help.}%
81 %    %<-------------------do not delete this space!------------------->%
82 \@err@                                                                 %
83 {}}%
84 ~%
85 \endgroup}%
86 \fi}%

87 ⟨/2ekernel | def⟩

\PackageError \PackageWarning \PackageWarningNoLine \PackageInfo \ClassError \ClassWarning \ClassWarningNoLine \ClassInfo These commands are intended for use by package and class writers, to give infor-

mation to authors. The syntax is:

\PackageError{⟨package⟩}{⟨error⟩}{⟨help⟩}

     \PackageWarning{⟨package⟩}{⟨warning⟩}

      \PackageWarningNoLine{⟨package⟩}{⟨warning⟩}
      \PackageInfo{⟨package⟩}{⟨info⟩}

and similarly for classes. The Error commands print the ⟨error⟩ message, and present the interactive prompt; if the author types h, then the ⟨help⟩ information is displayed. The Warning commands produce a warning but do not present the interactive prompt. The WarningNoLine commands do the same, but don’t print the input line number. The Info commands write the message to the log file. Within the messages, the command \MessageBreak can be used to break a line, \protect can be used to protect command names, and \space is a space, for example:

     \newcommand{\foo}{FOO}
     \PackageWarning{ethel}{%
        Your hovercraft is full of eels,\MessageBreak
        and \protect\foo\space is \foo}

produces:

     Package ethel warning: Your hovercraft is full of eels,
     (ethel)                and \foo is FOO on input line 54.

 88 ⟨autoload⟩\def\PackageError{\@autoerr\PackageError}

89 ⟨∗2ekernel | def⟩

 90 \gdef\PackageError#1#2#3{%
 91 \GenericError{%
 92  (#1)\@spaces\@spaces\@spaces\@spaces
 93 }{%
 94  Package #1 Error: #2%
 95 }{%
 96  See the #1 package documentation for explanation.%
 97 }{#3}%

98 } 99 ⟨/2ekernel | def⟩

100 ⟨∗2ekernel | autoload⟩

101 \def\PackageWarning#1#2{%
102 \GenericWarning{%
103  (#1)\@spaces\@spaces\@spaces\@spaces
104 }{%
105  Package #1 Warning: #2%

106 }% 107 }

108 \def\PackageWarningNoLine#1#2{%
109 \PackageWarning{#1}{#2\@gobble}%

110 }

111 \def\PackageInfo#1#2{%
112 \GenericInfo{%
113  (#1) \@spaces\@spaces\@spaces

114 }{%
115  Package #1 Info: #2%

116 }% 117 } 118 ⟨/2ekernel | autoload⟩

119 ⟨autoload⟩\def\ClassError{\@autoerr\ClassError}

120 ⟨∗2ekernel | def⟩

121 \gdef\ClassError#1#2#3{%
122 \GenericError{%
123  (#1) \space\@spaces\@spaces\@spaces
124 }{%
125  Class #1 Error: #2%
126 }{%
127  See the #1 class documentation for explanation.%
128 }{#3}%

129 } 130 ⟨/2ekernel | def⟩

131 ⟨∗2ekernel | autoload⟩

132 \def\ClassWarning#1#2{%
133 \GenericWarning{%
134  (#1) \space\@spaces\@spaces\@spaces
135 }{%
136  Class #1 Warning: #2%

137 }% 138 }

139 \def\ClassWarningNoLine#1#2{%
140 \ClassWarning{#1}{#2\@gobble}%

141 }

142 \def\ClassInfo#1#2{%
143 \GenericInfo{%
144  (#1) \space\space\@spaces\@spaces
145 }{%
146  Class #1 Info: #2%

147 }% 148 } 149 ⟨/2ekernel | autoload⟩

\@latex@error \@latex@warning \@latex@warning@no@line \@latex@info \@latex@info@no@line Errors and other info, for use in the L^{A}TEX core.
150 ⟨autoload⟩\def\@latex@error{\@autoerr\@latex@error}

151 ⟨∗2ekernel | def⟩

152 \gdef\@latex@error#1#2{%
153 \GenericError{%
154  \space\space\space\@spaces\@spaces\@spaces
155 }{%
156  LaTeX Error: #1%
157 }{%
158  See the LaTeX manual or LaTeX Companion for explanation.%
159 }{#2}%

160 } 161 ⟨/2ekernel | def⟩

162 ⟨∗2ekernel | autoload⟩

163 \def\@latex@warning#1{%
164 \GenericWarning{%
165  \space\space\space\@spaces\@spaces\@spaces
166 }{%
167  LaTeX Warning: #1%

168 }% 169 }

170 \def\@latex@warning@no@line#1{%
171 \@latex@warning{#1\@gobble}}
172 \def\@latex@info#1{%
173 \GenericInfo{%
174  \@spaces\@spaces\@spaces
175 }{%
176  LaTeX Info: #1%

177 }% 178 }

179 \def\@latex@info@no@line#1{%
180 \@latex@info{#1\@gobble}}

\@font@warning and \@font@info are defined later since they have to be redefined by the tracefnt package.

 \def\@font@warning#1{%
    \GenericWarning{%
       {(font)\@spaces\@spaces}%
       {Font Warning: #1}%
  }
 \def\@font@info#1{%
    \GenericInfo{%
       (font)\space\@spaces
    }{%
       Font Info: #1%
    }%
  }

\c@errorcontextlines \errorcontextlines as a L^{A}TEX counter, so that it may be be manipulated with \setcounter (once it is defined :-)

181 \let\c@errorcontextlines\errorcontextlines
182 \c@errorcontextlines=-1

\on@line The message ‘ on input line n’, if possible.

183 \ifnum\inputlineno=\m@ne
184 \let\on@line\@empty
185 \else
186 \def\on@line{ on input line \the\inputlineno}
187 \fi

\@warning \@@warning \@latexerr Older L^{A}TEX messages. For the moment, these \let to the new message commands. They may be changed later, once only obsolete packages and classes contain them.

188 \let\@warning\@latex@warning
189 \let\@@warning\@latex@warning@no@line

190 ⟨/2ekernel | autoload⟩

191 \global\let\@latexerr\@latex@error

\@spaces Four spaces.

192 ⟨∗2ekernel | autoload⟩

193 \def\@spaces{\space\space\space\space}

194 ⟨/2ekernel | autoload⟩

1.2 Specific errors

\@eha \@ehb \@ehc \@ehd The more common error help messages.

195 ⟨∗2ekernel | def⟩

196 \gdef\@eha{%
197 Your command was ignored.\MessageBreak
198 Type \space I <command> <return> \space to replace it %
199 with another command,\MessageBreak
200 or \space <return> \space to continue without it.}
201 \gdef\@ehb{%
202 You've lost some text. \space \@ehc}
203 \gdef\@ehc{%
204 Try typing \space <return> %
205 \space to proceed.\MessageBreak
206 If that doesn't work, type \space X <return> \space to quit.}
207 \gdef\@ehd{%
208 You're in trouble here.  \space\@ehc}

209 ⟨/2ekernel | def⟩

As \latex@error triggers the autoload, these definitions should not be needed in the autoload format, but just to be safe…

210 ⟨∗autoload⟩

211 \let\@eha\@empty\let\@ehb\@empty\let\@ehc\@empty\let\@ehd\@empty

212 ⟨/autoload⟩

Here are most of the error message-generating commands of L^{A}TEX.

\@autoerr Make this autoload command robust, as it may be read in at unpredicatble times.

213 ⟨autoload⟩\def\@autoerr{\protect\@autoload{err}\protect}

\@notdefinable Error message generated in \@ifdefinable from calls to one of the commands \newcommand, \newlength or \newtheorem specifying an already-defined command name.

214 \gdef\@notdefinable{%
215 ⟨!autoload⟩ \@latex@error{%
216 ⟨!autoload⟩ Command \@backslashchar\reserved@a\space already defined%

217 ⟨!autoload⟩}\@eha}

218 ⟨autoload⟩ \@autoerr\@notdefinable}

\@nolnerr Generated by \newline and \\ when called in vertical mode.

219 \gdef\@nolnerr{%
220 ⟨!autoload⟩ \@latex@error{There's no line here to end}\@eha}
221 ⟨autoload⟩ \@autoerr\@nolnerr}
\@nocounterr Generated by \setcounter, \addtocounter or \newcounter if applied to an un-

defined counter ⟨cnt⟩.

\@nocnterr Obsolete error message generated in L^{A}TEX2.09 by \setcounter, \addtocounter or \newcounter for undefined counter. DO NOT use for L^{A}TEX 2ε it MIGHT vanish! Use \@nocounterr{⟨cnt⟩} instead.

222 \gdef\@nocounterr#1{%
223 ⟨!autoload⟩ \@latex@error{No counter '#1' defined}\@eha}
224 ⟨autoload⟩ \@autoerr\@nocounterr}
225 \gdef\@nocnterr{\@nocounterr?}

\@ctrerr Called when trying to print the value of a counter numbered by letters that’s greater than 26.

226 \gdef\@ctrerr{%
227 ⟨!autoload⟩ \@latex@error{Counter too large}\@ehb}
228 ⟨autoload⟩ \@autoerr\@ctrerr}

\@nodocument Error produced if paragraphs are typeset in the preamble.

229 \gdef\@nodocument{%
230 ⟨!autoload⟩ \@latex@error{Missing \protect\begin{document}}\@ehd}
231 ⟨autoload⟩ \@autoerr\@nodocument}

\@badend Called by \end that doesn’t match its \begin. RmS 1992/08/24: added code to \@badend to display position of non-matching \begin. FMi 1993/01/14: missing space added.

232 \gdef\@badend#1{%
233 ⟨!autoload⟩ \@latex@error{\protect\begin{\@currenvir}\@currenvline
234 ⟨!autoload⟩  \space ended by \protect\end{#1}}\@eha}
235 ⟨autoload⟩ \@autoerr\@badend}

\@badmath Called by \[, \], \( or \) when used in wrong mode.

236 \gdef\@badmath{%
237 ⟨!autoload⟩ \@latex@error{Bad math environment delimiter}\@eha}
238 ⟨autoload⟩ \@autoerr\@badmath}

\@toodeep Called by a list environment nested more than six levels deep, or an enumerate or itemize nested more than four levels.

239 \gdef\@toodeep{%
240 ⟨!autoload⟩ \@latex@error{Too deeply nested}\@ehd}
241 ⟨autoload⟩ \@autoerr\@toodeep}

\@badpoptabs Called by \endtabbing when not enough \poptabs have occurred, or by \poptabs

when too many have occurred.

242 \gdef\@badpoptabs{%
243 ⟨!autoload⟩ \@latex@error{\protect\pushtabs\space and \protect\poptabs
244 ⟨!autoload⟩  \space don't match}\@ehd}
245 ⟨autoload⟩ \@autoerr\@badpoptabs}

\@badtab Called by \>, \+ , \- or \< when stepping to an undefined tab.

246 \gdef\@badtab{%
247 ⟨!autoload⟩ \@latex@error{Undefined tab position}\@ehd}
248 ⟨autoload⟩ \@autoerr\@badtab}

\@preamerr This error is special: it appear in places where we normally have to \protect expansions. However, to prevent a protection of the error message itself (which would result in the message getting printed not issued on the terminal) we need to locally reset \protect to \relax.

249 \gdef\@preamerr#1{%
250 \begingroup
251  \let\protect\relax

252 ⟨∗!autoload⟩

253  \@latex@error{\ifcase #1 Illegal character\or
254  Missing @-exp\or Missing p-arg\fi\space
255  in array arg}\@ehd

256 ⟨/!autoload⟩

257 ⟨autoload⟩ \@autoerr\@preamerr{#1}%
258 \endgroup}

\@badlinearg Occurs in \line and \vector command when a bad slope argument is encountered.

259 \gdef\@badlinearg{%
260 ⟨!autoload⟩ \@latex@error{%
261 ⟨!autoload⟩  Bad \protect\line\space or \protect\vector
262 ⟨!autoload⟩  \space argument}\@ehb}
263 ⟨autoload⟩ \@autoerr\@badlinearg}

\@parmoderr Occurs in a float environment or a \marginpar when encountered in inner vertical mode.

264 \gdef\@parmoderr{%
265 ⟨!autoload⟩ \@latex@error{Not in outer par mode}\@ehb}
266 ⟨autoload⟩ \@autoerr\@parmoderr}

\@fltovf Occurs in float environment or \marginpar when there are no more free boxes for storing floats.

267 \gdef\@fltovf{%
268 ⟨!autoload⟩ \@latex@error{Too many unprocessed floats}\@ehb}
269 ⟨autoload⟩ \@autoerr\@fltovf}

\@latexbug Occurs in output routine. This is bad news.

270 \gdef\@latexbug{%
271 ⟨!autoload⟩ \@latex@error{This may be a LaTeX bug}{Call for help}}
272 ⟨autoload⟩ \@autoerr\@latexbug}

\@badcrerr This error was removed and replaced by \@nolnerr.

273 %\def\@badcrerr {\@latex@error{Bad use of \protect\\}\@ehc}

\@noitemerr \addvspace or \addpenalty was called when not in vmode. Probably caused by a missing \item.

274 \gdef\@noitemerr{%
275 ⟨!autoload⟩ \@latex@error{Something's wrong--perhaps a missing %
276 ⟨!autoload⟩  \protect\item}\@ehc}
277 ⟨autoload⟩ \@autoerr\@noitemerr}

\@notprerr A command that can be used only in the preamble appears after the command

\begin{document}.
278 \gdef\@notprerr{%
279 ⟨!autoload⟩ \@latex@error{Can be used only in preamble}\@eha}
280 ⟨autoload⟩ \@autoerr\@notprerr}

\@inmatherr Issued by commands that don’t work correctly within math (like \item). There is no real error recovery happening, e.g., the user might get additional errors afterwards.

281 \gdef\@inmatherr#1{%
282 \relax
283 \ifmmode
284 ⟨!autoload⟩ \@latex@error{Command \protect#1 invalid in math mode}\@ehc
285 ⟨autoload⟩ \@autoerr\@inmatherr#1%
286 \fi}

\@invalidchar An error for use with invalid characters. This is commented out, since we decided to use chatcode 15 instead.

287 %\def\@invalidchar{\@latex@error{Invalid character in input}\@ehc}

As well as the above error commands some error messages are directly coded to save space. The Messages alrerady present in L^{A}TEX2.09 included:

   Environment --- undefined

Issued by \begin for undefined environment.

   tab overflow

Occurs in \= when maximum number of tabs exceeded.

   \< in mid line

Occurs in \< when it appears in middle of line.

   Float(s) lost

In output routine, caused by a float environment or \marginpar occurring in inner vertical mode.