Text FormattingDefine Shortcut Macro for 'align' Environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
linuxophile
Posts: 2
Joined: Thu May 10, 2012 1:23 pm

Define Shortcut Macro for 'align' Environment

Post by linuxophile »

Hello,

I am trying to switch from eqnarray to align environment; since I use everywhere a macro

Code: Select all

\def\bea{\begin{eqnarray}}
\end\eea{\end{eqnarray}}
I thought I would simply re-define them as in the code below

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath}
\def\bea{\begin{align}}
\def\eea{\end{align}}
\begin{document}
\bea
a & =f\\
f & = weeq\\
\eea
\end{document}

But when I compile I get the error:
! LaTeX Error: \begin{align} on input line 6 ended by \end{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.10 \end{document}
I cannot understand why or how to fix it.
Any help is very welcome, Thanks!
Last edited by Stefan Kottwitz on Thu May 10, 2012 1:42 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Define Shortcut Macro for 'align' Environment

Post by Stefan Kottwitz »

Hi,

welcome to the board!

The amsmath technote document explains it. In short: the align environment is too complex to make the redefinition in that simple way. This would work:

Code: Select all

\documentclass[11pt]{article}
\usepackage{amsmath}
\def\bea#1\eea{\begin{align}#1\end{align}}
\begin{document}
\bea
a & =f\\
f & = weeq\\
\eea
\end{document}
I recommend not to redefine standard syntax just for saving some keystrokes, because it would be less readable. Documents may be typed once but read often, such as when troubleshooting. Also, hiding environments behind commands (declaration) doesn't make code clearer. So I would use align without renaming it. If I would need to save keystrokes, I would define a macro in the editor or use a shortcut key program.

Stefan
LaTeX.org admin
linuxophile
Posts: 2
Joined: Thu May 10, 2012 1:23 pm

Re: Define Shortcut Macro for 'align' Environment

Post by linuxophile »

Fantastic!
Thanks
Post Reply