20

I'd like to define a shorthand command for \begin{align*} and \end{align*}. When I write

\newcommand{\ba}{\begin{align*}}  

it works fine. But when I write

\newcommand{\ea}{\end{align*}}  

LaTeX complains. It looks like it's interpreting it as part of the environment and is not happy with that. Anyone know how to fix this?

hola
  • 4,026
  • 3
  • 35
  • 72

3 Answers3

18

An alternative solution -- this is the code in the custom document class I use for everything:

\newcommand{\eq}[1]{\begin{align*}#1\end{align*}}

Usage:

\eq{
  x^2 + 9 &= 0
}

(Obviously, change the command name to suit your preference.)

Etaoin
  • 600
6

A little testing shows that this appears to be fairly specific to the "align" environment from amsmath. For example,

\documentclass{article}

\usepackage{amsmath}

\newcommand{\bc}{\begin{center}}
\newcommand{\ec}{\end{center}}

\begin{document}

\bc
hello world
\ec

\end{document}

works fine. I'm not sure why align* doesn't work (it doesn't work without the star either); I suspect that the myriad expansions and aliases surrounding the align environment do something a little more complicated than a "traditional" LaTeX environment. However, I have found something that might just achieve the same objective for you:

\documentclass{article}

\usepackage{amsmath}

\newcommand{\ba}{\[\begin{aligned}}
\newcommand{\ea}{\end{aligned}\]}

\begin{document}

\ba
x^2 &= y^2 \\
z^2 &= t^2
\ea

\end{document}

Hope that helps!

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
1

It seems to me that it's a bug.

\newcommand{\ba}{\begin{align}} 
\newcommand{\ea}{\end{align}}
\ba
x=1
\ea

LaTeX complains about align not being closed.

Hendrik Vogt
  • 37,935