23

I'd like to write a command that checks the given arguments and throws an error if they are not in a range.

I'm imagining this would look something like this:

\usepackage{xifthen}

\newcommand{\wb}[2][]{\ifthenelse{{#2} > 0 \AND {#2} < 7}
    {\includegraphics[{#1}]{wong-baker/{#2}.eps}}}
    {%throw error here}
}

How can I check parameters in newcommand?

1 Answer 1

29
\PackageError{mypackage}{dont do that}{extra help}

see section 4.9 of texdoc clsguide

3
  • 5
    Does this also work for a quick command which is not inside any package?
    – ipavlic
    Commented Jun 9, 2014 at 12:19
  • 5
    @ipavlic yes you can put anything you like in the mypackage argument it doesn't have to be really the name of a package. Commented Jun 9, 2014 at 12:20
  • 1
    @ipavlic there is also the \GenericError macro, which is used by \PackageError internally.
    – Skillmon
    Commented Jun 23, 2019 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .