55

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.

sheet_ethics
  • 2,921

5 Answers5

40
 \PackageError{mypackage}{you did it wrong}{help text}
David Carlisle
  • 757,742
33

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

\stop

in LaTeX and

\bye

in plain TeX.

mbork
  • 13,385
26

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).

Ian Thompson
  • 43,767
15

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.

13

you can insert the end{document}

\documentclass{article}
\def\foo{}
%\def\foo{quit}  % uncomment for stopping sourcecode reading
\begin{document}

foo
\if\relax\foo\else\par
  I'll stop reading source code \ldots
  \end{document}
\fi

bar
\end{document}

If the break is in an included file use:

foo
\def\next{}
\if\relax\foo\else\par
  I'll stop reading source code in the included file \ldots
  \def\next{\endinput\end{document}}
\fi
\next

foo in the included file