1

I'm trying to define a shortcut / new command for equations split on multiple lines.

The \beq and \eeq commands below work, for single line equations, but the \bsp and \esp commands don't.

The error message I see is

! Paragraph ended before \split was complete.

and this could mean a blank line somewhere, but I don't know how to fix this.

\documentclass[12pt]{article}

\usepackage{amsfonts,amsfonts,amsmath,amssymb,bm}

\newcommand{\beq}{\begin{equation}} \newcommand{\eeq}{\end{equation}} \newcommand{\bsp}{\begin{split}} \newcommand{\esp}{\end{split}}

\begin{document}

This equation works \beq a^2 + b^2 = c^2 \eeq

And this one \beq \begin{split} \cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b \end{split} \eeq

But this one doesn't \beq\bsp \cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b \esp\eeq

\end{document}

Bernard
  • 271,350
  • As you can find many places on this site: this is not recommended! For one because some macros need special attention, secondly it makes the code much much harder to read. You are much better of learning the ins and out of your editor which can often insert code sniplets via short cuts. – daleif Jun 02 '22 at 14:14

2 Answers2

2

The following is copy-and-pasted from technotes.tex in the amsmath distribution

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

Authors often like to use abbreviations such as \beq \eeq for \begin{equation} \end{equation}. For some environments defined by the amsmath package, such as align, gather, multline, and others of the same general type, this does not work: 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. Work is under way on an auxiliary package called breqn that addresses not only this problem but a number of others; at the time of this writing, however [September 1999] it has only progressed as far as a beta release.

Some workarounds:

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

Given the code you've shown, you may want to investigate the first of the workarounds mentioned.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
0

This way it will work:

\documentclass[12pt]{article}

\usepackage{amsfonts,amsfonts,amsmath,amssymb,bm}

\newcommand{\beq}{\begin{equation}} \newcommand{\eeq}{\end{equation}} \newcommand{\bsp}{\begin{split}} \newcommand{\esp}{\end{split}}

\newcommand\multi[1]{% one command \begin{equation}% \begin{split}% #1% \end{split}% \end{equation}% }

\newcommand\me[1]{% split into the equation part ... \begin{equation}% #1% \end{equation}% } \newcommand\ms[1]{% ... and the split part \begin{split}% #1% \end{split}% }

\begin{document}

This equation works \beq a^2 + b^2 = c^2 \eeq

And this one \beq \begin{split} \cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b \end{split} \eeq

\multi{\cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b}

\me{\ms{ \cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b }}

\me{% same, but in a neater presentation \ms{ \cos(a+b) &= \cos a \cos b - \sin a \sin b \ \sin(a+b) &= \sin a \cos b + \cos a \sin b } }

\end{document}

x

MS-SPO
  • 11,519