TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to stop the compile process through the use of a command? Something like:

 \exception{This is a user-set exception.  Compile halted.}

So when performing the compile process, the specified text string is displayed to the console, and the compile process aborts?

The reason I want to do something like this is I want to have a conditional statement that checks a user-defined parameter. If the parameter is outside a desired range, I want the user to be informed that they made a bad choice and should change it.

Thanks in advance.

share|improve this question
The solutions below are better, but I just use \typeout{<text>}\QUIT, where \QUIT is not defined. – Peter Grill Jun 19 '12 at 21:41
 \PackageError{mypackage}{you did it wrong}{help text}
share|improve this answer

There are a number of error and warning commands for use in different situations. See section 4.9 of LaTeX2e for class and package authors for details of \ClassError and \PackageError (also \ClassWarning and PackageWarning), and have a look at macros2e.pdf for \GenericError (and \GenericWarning).

share|improve this answer

Maybe not the best solution, but for the sake of completeness:


in LaTeX and


in plain TeX.

share|improve this answer
Note: those will produce the output (which might be what you want). – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Nov 27 '14 at 19:43
@ mbork This is awesome to do. thanks – kaka Nov 29 '15 at 20:14

you can insert the end{document}

%\def\foo{quit}  % uncomment for stopping sourcecode reading

  I'll stop reading source code \ldots


If the break is in an included file use:

  I'll stop reading source code in the included file \ldots

foo in the included file
share|improve this answer
But don't do this in tex files that are \included, otherwise you may hit a "Runaway Argument?" with "! File ended while scanning use of \@writefile/\@newl@bel", as in size-limit for aux, problem w/ hyperref, natbib, include • General • LaTeX Community; \stop in those cases seems to work better. – sdaau Feb 15 '14 at 13:34
with a modification it also possible to quit the run in an included file! – Herbert Feb 15 '14 at 13:54

i like @PeterGrill's \typeout{<text>}\QUIT approach because after reading the message, the user can choose to hit the enter key and continue. yes, it might cause more problems later, but it also might allow more problems to be brought to light in the same run so that they can all be corrected at once, instead of one at a time.

and actually, \PackageError will do the same thing with a more informative message.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.