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

I like to write my LaTeX C++ style

1 \mydisplay
2 {
3     \BoomUndefinedMacro \\
4     x + 1 = 2
5 }

But then LaTeX, LaTeX say that the error is in line 5, instead of line 3.
This is not useful, because in more involved use case, there are a hundred line in the display.

Is there a work around in writing enclosing macro so that LaTeX gives the right line number?



\newcommand{\mydisplay}[1]{\begin{align} #1 \end{align}}


    \boomUndefinedMacro \\
    x + 1 = 2

share|improve this question
When TeX reads an argument, it doesn't look whether the tokens are defined, so when it discovers the error it's already at the line where the closing brace is. – egreg Mar 15 '13 at 13:10
It depends on what your macro is supposed to do. In rare cases, it is possible (e.g., making something bold can be done with \def\mybold#{\bgroup\bf\let\bgroup=}), but in general, egreg is right. This is actually a good thing, bcause you wouldn't want TeX to complain when seeing \boom in \newcommand{\boom}{...}. – Bruno Le Floch Apr 28 '13 at 10:33
up vote 7 down vote accepted

There is nothing you can really do. When TeX is absorbing an argument it doesn't expand macros or look whether they're defined. So when \boomUndefinedMacro is discovered, which happens at a later stage than absorbing the argument, TeX's reading apparatus is already at the line with the closing brace and that's the line it will show for the error.

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.