# LaTeX report wrong error line when enclosing thing within a macro

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?

\documentclass{article}

\usepackage{amsmath}

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

\begin{document}

\mydisplay
{
\boomUndefinedMacro \\
x + 1 = 2
}

\end{document}

-
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

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.