5

I have created some new short command using \newcommand in the following example:

\documentclass[12pt,twoside,a4paper]{book}      
\usepackage{enumerate,amsmath}  

\newcommand{\ba}{\begin{array}}     
\newcommand{\ea}{\end{array}}  

\newcommand{\ben}{\begin{enumerate}}      
\newcommand{\een}{\end{enumerate}}  

\newcommand{\bal}{\begin{align}}      
\newcommand{\eal}{\end{align}}  

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

\newcommand{\de}{^\circ}  

\begin{document}     

\bc      
$5\de$      
\ec  

\ben      
\item Text  
\item Text  
\een  


$\ba{cc}    
a & b\\   
c & d    
\ea$  


\bal      
& r\\      
& f      
\eal  


But   

\begin{align}     
& r\\      
& f     
\end{align}  

is working.     
\end{document}

All \newcommands are working well except \bal and \eal. I don't know why it is not working.

  • 2
    Please format your questions. As is documented you can not use the AMS alignments in that way. You have to use the \begin \end form. – David Carlisle May 5 '13 at 10:43
  • 7
    My advice is not to do this. It drastically decreases the readability of your code without saving that many keystrokes. – Matthew Leingang May 5 '13 at 10:46
  • 4
    Section 6 of technote.pdf mirrors.ctan.org/macros/latex/required/amslatex/math/… gives some details regarding this problem. – Ulrike Fischer May 5 '13 at 10:47
  • To the OP: Please accept answers to the previous questions you have asked. It helps the site run smoothly. – kan May 5 '13 at 11:31
  • 1
    It's amazing how this question not only keeps coming up, but comes up in exactly the notation used in the quote in Matthew's answer. – Ryan Reich May 5 '13 at 14:40
17

David and Ulrike have told you why it doesn't work for align. Quoting from the link Ulrike provided, “Technical notes on the amsmath package

6 Why can't I use abbreviations for \begin{align} . . . \end{align}?

... An attempt to define \bal...\eal as shorthand for \begin{align}...\end{align} will fail with a puzzling error message. This has to do with unfortunately nontrivial technical complications: the given environments must read their contents as a delimited macro argument because they do multipass processing of the contents using algorithms inherited from Spivak's amstex.tex. The obvious solution—substitution of different algorithms that do box shuffling instead of token shuffling for the multipass calculations—would require rewriting these display environments from the ground up; while that is a worthy goal, it was beyond the original scope of the AmS-LaTeX project. [Emph. added]

For my own part, here is why I think in general this is a bad idea, puzzling errors notwithstanding. Quickly tell me what this code is supposed to produce.

\bc  

$5\de$  

\ec  

\ben  

\item Text  

\item Text  

\een  

If this took you more then 10 seconds you're wasting time. Now think about posting code looking like that to a forum asking for help troubleshooting it. Others trying to read it will quickly stumble and not bother.

Compare to:

\[
    5^\circ
\]

\begin{enumerate}
   \item Text
   \item Text
\end{enumerate}

Much more readable and conventional.

I think that zero-argument, zero-logic macros, unless they add syntactic sugar, represent optimization of the the wrong thing: keystrokes, at a cost of readability and portability. If you really want to type less, use text-expansion software like TextExpander or AutoHotKey.

  • 1
    To the OP: Or, use a good editor like emacs which works based on key bindings. – kan May 5 '13 at 11:30

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.