Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.