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'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?

share|improve this question

migrated from stackoverflow.com Mar 9 '11 at 12:47

This question came from our site for professional and enthusiast programmers.

2  
This seems the sort of thing you should have a shortcut for in your editor, rather than in LaTeX itself. –  ShreevatsaR Apr 21 '10 at 14:27

3 Answers 3

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.)

share|improve this answer
    
Thanks for the help! I defined the \eq command, and it's working well. –  Dmitry Vaintrob Apr 30 '10 at 6:01
    
This is a great idea, thank you. What does the [1] signify? –  Eric Auld Sep 26 '13 at 15:52
    
It's the number of arguments your new \eq command will require. See en.wikibooks.org/wiki/LaTeX/Macros for more information. –  Etaoin Sep 28 '13 at 0:03

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!

share|improve this answer

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.

share|improve this answer
4  
This is not a bug, but indeed unexpected behaviour of align. It's explained over at tex.stackexchange.com –  Hendrik Vogt Nov 18 '10 at 16:21

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.