1

I would like to have a minor modification of some standard AMS-environment and realize it as a new one. The problem is that not all the environments allow this procedure. Say, even the mere duplication

\newenvironment{myEnv}{\begin{gather}}{\end{gather}}

does not work. TeX-system produces the error like

! LaTeX Error: \begin{gather} on input line 126 ended by \end{myEnv}.

However, replacing above gather -> equation or some other (good) environmens works Ok. I've faced the problem in MiKTeX 2.3 and 2.9. Is this a bug or a feature? Ideally, I would like to construct modifications like

\newenvironment{myGather}{\begin{gather} ... my tuning ...}{\end{gather}}

Investigation inside the amsmath.sty did not help me. Who can? Should I fix a built-in gather-environment in this situation?

JP-Ellis
  • 8,929
  • 2
  • 33
  • 49

1 Answers1

3

In LaTeX, \begin{foo} and \end{foo} actually call the commands \foo and \endfoo, so you can try modify them directly if the \newenviornment method doesn't work.

With the particular case of the gather environment, I believe it changes the way certain characters are handled which I think is the cause of the issue. This can be solved by preventing \gather from being executed with \expandafter as follows:

\def\mygather{
  \expandafter\gather
    some tuning
}
\def\endmygather{\endgather}
% Or, basically equivalently:
\newenvironment{mygather}{
  \expandafter\gather
    some tuning
}{\endgather}

Without knowing what tuning you want to do, I can't really tell you whether that will fix your issue.

JP-Ellis
  • 8,929
  • 2
  • 33
  • 49
  • Did I right understand that I may define new environment \mygather by your way above instead of standard one through \newenvironment ... ? I just checked your version. Seems it works nice. –  Feb 05 '16 at 14:28
  • 1
    Yes, the \newenvironment{foo} command is just a nicer and more user friendly way of defining \foo and \endfoo. – JP-Ellis Feb 05 '16 at 14:33
  • 1
    Glad I could help! (PS: don't forget to mark the question as "answered" with the tick. You should probably do the same with all your other questions too :) ) – JP-Ellis Feb 05 '16 at 14:53
  • Customizations after \gather would only act on the first row. And \expandafter seems pretty useless. – egreg Feb 05 '16 at 15:27
  • @egreg I understand that the customizations after \gather would only act on the first row, but @maximav did not really elaborate on what he is trying to do, and apparently it works for him. Regarding the \expandafter, omitting it causes the it to fail, so I'm not really sure what you mean when you say it is useless. – JP-Ellis Feb 05 '16 at 15:32
  • JP-Ellis. What about environments with the star-version. Actually I wanted not gather but to create a universal alignat* version. Namelly, instead of constant pointing out number of columns in alignat, like –  Feb 06 '16 at 12:15
  • \begin{alignat}{3}... I want to have something universal with excessive column number, say, \begin{myAlign}... written through {alignat}{22}... I could not modify your way above to the -case and {22}. How to do this? –  Feb 06 '16 at 12:25
  • 1
    @maximav, without knowing what you want to achieve exactly, it's hard to tell you how the answer should be modified. As egreg mentioned, my answer would only work for the first row, so I don't even know if that is correct. Also, of the questions you have asked you have only accepted one answer... You should consider accepting more answers (though obviously, not this one since it isn't working now). – JP-Ellis Feb 06 '16 at 13:42
  • Seems I've found a question. Here is a working version \newenvironment{Align}{\csname alignat\endcsname{22}}{\csname endalignat*\endcsname}. But there is the question. Is this bad when I insert some excessive {22}? How much bad for TeX-processor to work out, say, 20 excessive columns if I used explicitly only two ones? –  Feb 06 '16 at 13:51
  • 1
    If you use the \def method, then you can have \def\myalign#1{\alignat*{#1}...}. In this case, you can then use \begin{myalign}{2}. – JP-Ellis Feb 06 '16 at 13:54