3

I have the following:

\newenvironment{examplebox}[1]{
    \begin{flalign*}
}
{
    \end{flalign*}
}

\begin{examplebox}{Test}
    & \lim_{x \to 2} f(x)
\end{examplebox}

This results in the following two errors:

LaTeX Error: \begin{examplebox} on input line 47 ended by \end{document}.
LaTeX Error: \begin{flalign*} on input line 47 ended by \end{examplebox}

The environment works fine if I put the flalign in the environment everytime I \begin it. However, I want this to be in a \newenvironemnt because I want to add styling around it and have it be easily reproducable every time I need it. Additionally, I have not decided a style for it because I am focuing more on the content of my document, so I want to be able to change it once and have it change all instances of it.

Is there any particular reason for this error, or is this just a restriction of flalign. If it is a restriction, then are there are alternatives for it?

4

1 Answer 1

3

It's a common problem with amsmath alignments. You might do

\makeatletter
\newenvironment{examplebox}[1]{%
  % do something with #1
  \start@align\tw@\st@rredtrue\m@ne
}
{\endalign}
\makeatother

but it's simpler to use ltcmd (formerly xparse):

\NewDocumentEnvironment{examplebox}{mb}{%
  % do something with #1
  \begin{flalign*}#2\end{flalign*}%
}{}
3
  • This works perfectly, thank you! May I ask what the "mb" means and how I might go about a third (with the second being optional) argument?
    – Eshy
    Apr 3 at 10:39
  • @Eshy m means a mandatory argument, b means the environment's content. See texdoc usrguide.
    – egreg
    Apr 3 at 10:41
  • I understand, thank you for your help!
    – Eshy
    Apr 3 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .