I'm trying to define two commands \bal and \eal instead of inserting \begin{align} and \end{align} in my document, but in the code below, I'll get some errors. What is wrong with it?

  • 10
    You cannot, align literally looks for \end{align}. In general it is a bad idea to write using shortcuts like these as it makes the code much harder to read. – daleif Feb 27 '13 at 10:55
  • 8
    It has no sense to use align for a one line display; use equation, instead. Those shorthands may seem useful, but they aren't: they make the LaTeX document less readable and searchable. Good editors provide keyboard shortcuts that make easy inputting those environments. – egreg Feb 27 '13 at 11:33
  • 1
    Related questions (possible duplicates?): tex.stackexchange.com/q/3169/86, tex.stackexchange.com/q/65581/86 – Andrew Stacey Feb 27 '13 at 12:48
  • @egreg my code above is just a MWE. My problem is that why this definition works for, say, equation environment, but doesn't work for align environment. – Vahid Damanafshan Feb 27 '13 at 13:33
  • They are different beasts – daleif Feb 27 '13 at 13:58

The ‘problem’ is known and documented. I don't believe it's a problem at all, actually, for I can't see how


is clearer input than


To the contrary, I firmly believe that the latter syntax is much better than the former, because it clearly marks the document. Good editors provide fast shortcuts for inputting the latter syntax with as few keystrokes as possible.

Let's see why your definition doesn't work. The align environment must absorb all of its contents before starting to typeset it, since it needs to do two passes over the material: the first pass is for measuring it, the second one for doing the real typesetting. This is the key for proper placement of the material and of the equation numbers.

With \newcommand{\bal}{\begingroup\align\@ifstar{\nonumber}{}} you start align, but LaTeX will never see the end of it, because it doesn't expand tokens while absorbing the material, so \eal will be absorbed and not recognized as the end of align.

You could define


so that the required tokens are found, but it's clumsy and, as I said, it doesn't provide no benefit whatsoever, while obfuscating the code.

The issue doesn't show with equation, because this environment doesn't do complex tasks for measuring its contents. But the same arguments apply: there's no gain in inputting


instead of


and nobody will ever be able to convince me of the contrary.

Similarly, one can't define a new environment based on align by


where <something> is any code one wants to be executed for modifying align's behavior. The problem is exactly the same; but this will work:


because \align captures the current environment's name and will use \end{myalign} as the end mark for the material to be gathered.A

| improve this answer | |
  • I would say: you give too much opinion; just answer the question. However, one should not say such things to rep 700k, should one? I will say this: I think OP's question more reasonable than you do. – thb Sep 7 '19 at 22:04
  • @thb I gave the reason why it doesn't work and provided a workaround, didn't I? – egreg Sep 7 '19 at 22:07
  • True. You gave the reason and provided a workaround. Moreover, the workaround displays a level of skill I wish I possessed. – thb Sep 8 '19 at 1:18

This issue is dicussed in section 6 of the file technote.pdf among the files distributed with amsmath.sty. (on my system texdoc technote.pdf will open this file in a pdf viewer.)

I copy here the end of this section, but you should read it in full.

Some workarounds:

  1. \def\bal#1\eal{\begin{align}#1\end{align}}

  2. Define \newcommand{\env}[2]{\begin{#1}#2\end{#1}} and then use \env{align}{...}

| improve this answer | |

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.