3

I am used to using \newenvironment to wrap an environment:

\newenvironment{wrappedequation}
    {Look out for the equation!
    \begin{equation}}
    {\end{equation}
    Phew, it's over.}

This works fine. However, it doesn't seem to work with align or align*:

\documentclass{amsart}
\newenvironment{wrappedalign}
    {Look out for the aligned equation!
    \begin{align}}
    {\undefinedcommand
    \end{align}
    Phew, it's over.}
\begin{document}
\begin{wrappedalign}\end{wrappedalign}
\end{document}

produces

! LaTeX Error: \begin{align} on input line 9 ended by \end{wrappedalign}.

This error must be produced somehow very early in the expansion process (maybe in the argument-grabbing process?), because it doesn't mention the \undefinedcommand that I snuck in there.

EDIT: Darn it, I knew that this looked familiar. Is it the same as some \newcommand instructions not working ? Is there any (good) way to wrap align environments?

LSpice
  • 1,448
  • 1
    I believe the solution at newenvironment: error with \begin{align} and \end{align} (use \align and \endalign instead of \begin{align} and \end{align}, respectively) should work for your case too. – Paul Gessler Jun 06 '15 at 22:09
  • @PaulGessler, you are right! Could you post that as an answer, so that I can accept it? – LSpice Jun 06 '15 at 22:15
  • No, better to mark as a duplicate. Then your question can help point future searchers to the already existing solution. :-) – Paul Gessler Jun 06 '15 at 22:16
  • This is not exactly a duplicate, because it also asks for align* (without numbering). The solution given in the linked question does not apply for align*. Using \align* and \endalign* does not do the intended. After lots of digging, I found out (from here) that I could use \csname align*\endcsname and \csname endalign*\endcsname to achieve what I wanted. Also, it is important to have no space before \endcsname. – frabala Feb 03 '21 at 12:42

0 Answers0