I'm trying to write \newcommand
macros that will check the user's inputs to arguments and return an error message if an error (for example, value out of range) is found. Is there a good reference? Thanks
source2e
(section 14 Error handling) describes techniques to write errors and warnings (and information) to the end user. Here are some references:
These commands are intended for use by package and class writers, to give information to authors. The syntax is:
\PackageError{<package>}{<error>}{<help>} \PackageWarning{<package>}{<warning>} \PackageWarningNoLine{<package>}{<warning>} \PackageInfo{<package>}{<info>}
and similarly for classes (use
\Class...
instead of\Package...
). TheError
commands print the<error>
message, and present the interactive prompt; if the author types h, then the<help>
information is displayed. TheWarning
commands produce a warning but do not present the interactive prompt. TheWarningNoLine
commands do the same, but don't print the input line number. TheInfo
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.
The above macros are specialized versions of more generic constructions:
\GenericInfo{<continuation>}{<info>}
\GenericWarning{<continuation>}{<warning>}
\GenericError{<continuation>}{<error>}{<further help>}{<help info>}
Also, a rudimentary way of sending information to the console is to use \typeout{...}
.
texdoc clsguide
) both include details of for example\PackageError
. – Joseph Wright♦ Feb 13 '15 at 7:07