Is there a \return statement in Latex to end the current macro from being processed?

\if some condition
  \PackageError{mypackage}{main text}{help text}

I just think it would be more elegant than putting the main function of the macro within an \else statement. Or what is standard practice among package writers?

  • 1
    Here compilation stops at \PackageError so would never reach \return. Other than that, no. It does not really make any sense in this type of language.
    – daleif
    Apr 3, 2022 at 10:23
  • Compilation doesn't stop at \PackageError. Any code after \fi in the same macro will be processed and (presumably) cause other errors to be thrown. Those may be confusing to the end user, hence I'd like to suppress them. I suppose I'll use \else. Apr 3, 2022 at 10:50
  • 3
    That depends on your compilation settings, a normal straight pdflatex stops at PackageError
    – daleif
    Apr 3, 2022 at 11:02
  • 1
    It is not uncommon for (La)TeX errors to have knock-on effects that cause further errors down the line. So conventional wisdom has it that one should always focus on the very first error message. Users are (or should be) generally aware of this, so a macro that "exits cleanly" might not be that big of a usability improvement and might not be worth the additional hassle if making it exit cleanly makes the implementation more opaque or much less efficient.
    – moewe
    Apr 3, 2022 at 11:52
  • You probably want ifthen. It doesn’t call what you want a return statement, but does let you return different things conditionally.
    – Davislor
    Apr 3, 2022 at 18:41

1 Answer 1


A macro is not a function call, it is textual expansion. So if you have

\def\abc{111  \return I don't want 222}

and used

  aaa \abc\ bbb

then the first thing that happens is that \abc gets expanded into the input buffer so TeX has seen aaa already but then the input is

   111  \return I don't want 222\ bbb

So if you want your \return to skip everything from \return to the end of the replacement text you are responsible for adding some marker at that point.

You must log in to answer this question.

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