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 tried using two Environ's in a nested fashion, but I get the

! Argument of \marray has an extra }

error. Any idea why this happens?

\documentclass{minimal}
\usepackage{amsmath,environ}

\NewEnviron{meqmultinum}[1]{
\begin{equation}\begin{split}
\BODY
\end{split}\label{eq:#1}\end{equation}
}

\NewEnviron{marray}[2]{
\renewcommand*{\arraystretch}{#2}
\begin{array}{#1}
\BODY
\end{array}
}

\begin{document}

\begin{meqmultinum}{test}
a&=\begin{marray}{l l}{1.2}
\alpha & \beta\\
\gamma & \kappa
\end{marray}\\
b&=\begin{array}{l l}
\alpha & \beta\\
\gamma & \kappa
\end{array}
\end{meqmultinum}

\end{document}
share|improve this question
    
You would avoid the problem (and the code would be a lot more efficient if you use \newenvironment{marray}[2]{\renewcommand*{\arraystretch}{#2}\begin{array}{#1}}{‌​\end{array} you only need the \BODY construct in cases where you need to pass the enviornment body as a comamnd argument. –  David Carlisle Nov 19 '12 at 15:35
    
Excellent, thanks! –  Wox Nov 19 '12 at 15:42
    
This question may also be helpful. –  Andrew Uzzell Nov 19 '12 at 15:47
add comment

2 Answers

up vote 7 down vote accepted

Environment split inside meqmultinum provides an alignment. That means that the contents of the environment is processed cell by cell:

Cell 1: a
Cell 2: =\begin{marray}{l l}{1.2} \alpha

The rest & \beta \\ \gamma & \kappa \end{marray} does not belong to cell 2. Thus the code of \begin{marray} complains, because it cannot find \end of \end{marray}.

This can be fixed by adding curly braces around \begin{marray}...\end{marray}:

\begin{meqmultinum}{test}
  a&={\begin{marray}{l l}{1.2}
    \alpha & \beta\\
    \gamma & \kappa
  \end{marray}}\\
  ...
\end{meqmultinum}

Why does it work with array instead of marray? Environment array does not need to see at the beginning \end{array}, instead it sets up a tabular and the contents of array with its & is processed in this inner tabular.

Other definition of marray

Another way to fix this issue is given by David Carlisle in his comment. There is no need for the special environment processing of package environ for array:

\newenvironment*{marray}[2]{%
  \renewcommand*{\arraystretch}{#2}%
  \begin{array}{#1}%
}{‌%
  ​\end{array}%
}
share|improve this answer
    
Thanks for the clear and elaborate answer Heiko. –  Wox Nov 19 '12 at 16:31
add comment

There is no need to use \NewEnviron for these environments; in this case split can give problems, but aligned can be used instead.

\documentclass{article}
\usepackage{amsmath}

\newenvironment{meqmultinum}[1]
  {\equation\label{eq:#1}\aligned}
  {\endaligned\endequation}

\newenvironment{marray}[2]
  {\renewcommand*{\arraystretch}{#2}\array{#1}}
  {\endarray}

\begin{document}

\begin{meqmultinum}{test}
a&=\begin{marray}{l l}{1.2}
\alpha & \beta\\
\gamma & \kappa
\end{marray}\\
b&=\begin{array}{l l}
\alpha & \beta\\
\gamma & \kappa
\end{array}
\end{meqmultinum}

\end{document}
share|improve this answer
    
I wasn't aware of the \something...\endsomething notation instead of \begin{something}...\end{something}. Do you have a reference that explains this? –  Wox Nov 20 '12 at 8:32
    
@Wox The usage of \foo and \endfoo instead of \begin{foo} and \end{foo} is sometimes handier; it has pros and cons: it doesn't form a group and doesn't set the environment's name (so error messages may be more helpful), but for some environments, notably lrbox it mustn't be used. –  egreg Nov 20 '12 at 8:42
add comment

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.