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}
A.Ellett
  • 50,533

2 Answers2

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.

Dan
  • 6,899
4

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}
egreg
  • 1,121,712
  • 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