3

When using the package breqn I got some compile errors. Without the package this works just fine. (I am using xelatex.)

\documentclass[a4paper,12pt]{scrbook}

\usepackage{breqn}
\newcommand{\cat}[1]{\mathbf{#1}}

\begin{document}
This does not work: $A_\cat{C} = 0$.
\end{document}

Gives the (not so useful) error:

! Argument of \cat has an extra }.
<inserted text> 
                \par 
l.7 This does not work: $A_\cat
                               {C} = 0$.

Now it is easily fixed by putting extra curly brackets around \cat{C}.

Since I have a solution, my actual question is: is it wrong (or bad habit) to leave out the curly braces in plain LaTeX in this situation?

And: how can breqn break this?

3
  • 2
    If you want more than one token in a subscript, use braces A_{\cat{C}}. Sometimes it works without braces, but you shouldn't expect that.
    – Manuel
    Nov 26 '14 at 14:08
  • 2
    "And: how can breqn break this?" breqn can break more or less anything, it completely redefines more or less every command related to math typesetting. the fact that it takes input that superficially looks like normal tex math input should not lull you into a false sense of security:-) Nov 26 '14 at 14:21
  • I now see that this is also mentioned in the breqn documentation: texdoc.net/texmf-dist/doc/latex/mh/breqn.pdf section 6.4
    – Jaxan
    Nov 26 '14 at 14:31
5

It is a bad habit to get in to. The offical (Latex book) syntax always has braces even for x_{2} although everyone sort of knows that x_2 works.

The fact that x_\mathbf{x} works is related to the details of the tex primitive parsing of _ and the fact that it is completely unlike macro argument parsing. If you have a macro \x with one argument then the argument in

\x\mathbf{x}

is just \mathbf without \mathbf's argument {x} and things will go wrong.

It is often convenient to make _ an active character then define it to by

\def_#1{\sb{#1}}

and perhaps include additional processing.

If you do that and omit the braces you end up with

 x_\mathbf{x}

being

 x\sb{\mathbf}  {x}

and things go wrong.

tex4ht needs (last time I checked, at least) this to generate html markup, breqn apparanetly needs it to do what it needs to do, many editors will similarly not know where the subscript ends if you do not brace it.

3
  • Thanks for the nice example of \x\mathbf{x}!
    – Jaxan
    Nov 26 '14 at 14:31
  • With breqn, _ receives math code "8000 and its definition as active character is _=macro: #1->\mathsub {\protect \subsupstyle #1}. so the reference to \def_#1{\sb{#1}} is a good approximation of what actually happens.
    – egreg
    Nov 26 '14 at 15:43
  • @egreg I know:-) Nov 26 '14 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.