4

I looked at the solution to How do I embed a gather environment within a custom environment? But things are still not working for me:

MWE:

\documentclass[border=6pt]{standalone}
\usepackage{amsmath}

\newenvironment{mygather}
  {%%
     \begin{minipage}{2in}
       \csname gather*\endcsname
  }{%%
       \csname endgather*\endcsname
     \end{minipage}%%
  }

\begin{document}

  \begin{mygather}
      y = x^{2} - 3x + 5
  \end{mygather}

\end{document}
  • You're using amsmath, the other answer used mathtools. There was a question here about using align within a custom environment with amsmath, but I can't find it right now. I think that the solution was to use the environ package. – Loop Space May 28 '14 at 16:57
  • @AndrewStacey: You might be referring to Making a new environment combining equation and split. – Werner May 28 '14 at 17:43
  • @Werner That looks like the one I was thinking of. – Loop Space May 28 '14 at 18:07
  • you might want to take a look at the gathered environment defined in the mathtools package. that's meant as a subsidiary environment, which gather is not. – barbara beeton May 28 '14 at 18:20
  • @AndrewStacey I hadn't noticed I wasn't using mathtools. Ultimately I've chosen to go with the environ package. – A.Ellett May 28 '14 at 19:10
5

The \gather* command sees that it is inside the minipage environment, and so looks ahead for \end{minipage}. But that doesn't exist until \end{mygather} is executed, and so \gather* keeps looking. The following might work:

\newenvironment{mygather}
  {%%
     \minipage{2in}
       \csname gather*\endcsname
  }{%%
       \csname endgather*\endcsname
     \endminipage%%
  }

In this rewrite, the \minipage is not an environment. The enclosing environment is mygather and so \gather* looks ahead for \end{mygather}, and finds it. I say it "might work" because, although it compiles fine without errors in your MWE, I don't really know what it is you are trying to achieve.

  • Thank you for the explanation. That helps a great deal to understand why the code is failing. – A.Ellett May 28 '14 at 19:06
3

When you use \csname gather*\endcsname, amsmath is smart enough to know what environment's name it has been called in, so as to absorb all text until the corresponding \end command appears. With your code it determines to have been called in minipage, but it's not able to see \end{minipage}, that's buried inside the end code.

So, just like Dan proposes, you can use \minipage and \endminipage. But this will not give a good output (I added \fbox around it just to clearly show the problem):

enter image description here

Why's that? Because you're starting a paragraph with a display, which shouldn't be done.

A workaround is to back up by \baselineskip

\documentclass[border=6pt]{standalone}
\usepackage{amsmath}

\newenvironment{mygather}
  {%%
   \minipage{2in}
   \vspace{-\baselineskip}
   \csname gather*\endcsname
  }{%%
    \csname endgather*\endcsname
    \endminipage
  }

\begin{document}

\fbox{\begin{mygather}
      y = x^{2} - 3x + 5
  \end{mygather}}

\end{document}

enter image description here

A simpler way is

\documentclass[border=6pt]{standalone}
\usepackage{amsmath}

\newenvironment{mygather}
  {%%
   \minipage{2in}
   \centering$\!\gathered
  }{%%
    \endgathered$
    \endminipage
  }

\begin{document}

\fbox{\begin{mygather}
      y = x^{2} - 3x + 5
  \end{mygather}}

\end{document}
  • You've suggested a work around, but is there a better approach that can avoid starting with a display? The whole point of the my table is to create a nice visual structure that seems rather difficult to achieve with an align* or other such math environments. – A.Ellett May 28 '14 at 19:06
  • @A.Ellett \centering$\gathered...\endgathered$? – egreg May 28 '14 at 20:01

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.