Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
9  
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
1  
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

1 Answer 1

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

 
discard

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.