2

I've tried defining the following custom environment, but I get errors:

\begin{gather} ended by \end{solution} etc...

Here's a MWE showing my problem:

\documentclass{article}

\usepackage[fleqn]{mathtools}

\newenvironment{solution}{%  <-Solution
  \par\addvspace{1em}
  \itshape{Solution:}\par\begin{gather}}
  {\end{gather}\par\normalfont\hfill\qed\par\addvspace{\medskipamount}}%

\begin{document}
  \begin{gather}
    testing
  \end{gather}

  %% This does not work:
  \begin{solution}
    testing
  \end{solution}
\end{document}
4

Use the command-form of the gather environment. That is, \gather...\endgather instead of \begin{gather}...\end{gather}.

enter image description here

\documentclass{article}
\usepackage[fleqn]{mathtools}% http://ctan.org/pkg/mathtools
\newenvironment{solution}{%  <-Solution
  \par\addvspace{1em}
  \textit{Solution:}\par\gather}
  {\endgather\par\normalfont\hfill\qed\par\addvspace{\medskipamount}}%

\begin{document}
Some text
\begin{gather}
  f(x)=ax^2+bx+c
\end{gather}
Some text
\begin{solution}
  f(x)=ax^2+bx+c
\end{solution}
Some text
\end{document}

Addition by OP:

Ultimately I ended up using gather instead, but it works just the same... using \gather and \endgather. But I also wanted to find a way to get rid of the equation numbers. A bit of searching allowed me to find out that \align* and \endalign* do not work as expected, so instead you have to use \csname align*\endcsname and \csname endalign*\endcsname

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.