# Nesting custom xparse environments

I've defined two simple environments with xparse. Problem is when I try to nest todominute environment inside minutes environment:

\documentclass[a4paper, 10pt]{article}

\usepackage{polski}
\usepackage{xltxtra}
\usepackage{xparse}
\usepackage{booktabs}

\NewDocumentEnvironment {minutes} {} {%
\begin{table*}[h!]
\begin{tabular*}{\textwidth}{@{} p{0.25\textwidth} l p{0.4\textwidth} l @{}}
\textbf{Zadanie} & \textbf{Typ} & \textbf{Opis} & \textbf{Przydział} \\
\midrule
}{%
\end{tabular*}
\end{table*}
}

\NewDocumentEnvironment {todominute} {m O{}} {%
{#1} & \textsc{TODO} &
}{%
& {#2} \\
}

\begin{document}

\begin{minutes}
\begin{todominute}{Poprawki opisu produktu}[TC]
Zgodnie z opisem z paragrafu \ref{sec:opis_produktu}.
\end{todominute}
\begin{todominute}{Poprawki mapy pamięci}[MM]
Zgodnie z opisem z paragrafu \ref{sec:mapa_pamieci}.
\end{todominute}
\end{minutes}

\end{document}

All I get is somewhat unhelpful message:

! Extra }, or forgotten \endgroup.
\@endpbox ...finalstrut \@arstrutbox \par \egroup
\hfil
l.27 ...n{todominute}{Poprawki opisu produktu}[TC]

EDIT: After the reading the comments I understand the problem. Is there a simple way to achieve the desired behaviour? Can I declare a new command that could be used like that and as a result print whole rows for the table declared in minutes environment?

\begin{minutes}
\todominute{Poprawki opisu produktu}[TC]
Zgodnie z opisem z paragrafu \ref{sec:opis_produktu}.
\todominute{Poprawki mapy pamięci}[MM]
Zgodnie z opisem z paragrafu \ref{sec:mapa_pamieci}.
\end{minutes}
-
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that should compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. It's hard having to guess at all the necessary packages. –  egreg Nov 19 '12 at 23:25
Actually the problem seems to be in the fact that you open the environment in a table cell and close it in another: this is not allowed, because environments form a group. –  egreg Nov 19 '12 at 23:30
you would get a similar error without all the packages if you went \begin{tabular}{cc} \begingroup a & b \endgroup \\ –  David Carlisle Nov 19 '12 at 23:34

The problem goes away if you use a command rather than an environment for the table row.

\documentclass{article}

\usepackage{booktabs}
\usepackage{xparse}

\NewDocumentEnvironment {minutes} {} {%
\begin{table*}[htp!]
\begin{tabular*}{\textwidth}{@{} p{0.25\textwidth} l p{0.5\textwidth} l @{}}
\textbf{Zadanie} & \textbf{Typ} & \textbf{Opis} & \textbf{Przydział} \\
\midrule
}{%
\end{tabular*}
\end{table*}
}

\NewDocumentCommand {\todominute} {m o m} {
#1 & \textsc{TODO} & #3
& #2 \tabularnewline
}

\begin{document}

\begin{minutes}
\todominute{Poprawki opisu produktu}[TC]
{Zgodnie z opisem z paragrafu \ref{sec:opis_produktu}.}
\todominute{Poprawki mapy pamięci}[MM]
{Zgodnie z opisem z paragrafu \ref{sec:mapa_pamieci}.
\begin{enumerate}
\item asd
\item qwe
\item zxc
\end{enumerate}
}
\end{minutes}

\end{document}
-
After going through xparse documentation I've got little question. Shouldn't in this case the command declaration use the + token for the last argument, as in \NewDocumentCommand {\todominute} {m o +m} { ... }? –  Tomasz Nov 19 '12 at 23:56
@tomasz er yes to make it long (allow blank lines) that would probably be better –  David Carlisle Nov 20 '12 at 0:15

I've modified a bit the solution presented by David.

I wanted to avoid wrapping the usually long text that goes in the Details column in curly brackets.

My method isn't really flexible, when it comes to the order of arguments, as only the last column can be filled without putting its content in an {}-wrapped argument.

Anyway, using it this way feels way more natural, as it resembles the default itemize environment. As a bonus it doesn't mess up the syntax colouring in your text editor.

\documentclass[10pt]{article}

\usepackage{booktabs}
\usepackage{xparse}

\NewDocumentEnvironment {minutes} { } {%
\begin{table}[htp]
\begin{tabular}{@{} p{0.2\textwidth} p{0.2\textwidth} p{0.5\textwidth} @{}}
\toprule
\textbf{Minute} & \textbf{Owner} & \textbf{Details} \tabularnewline
\midrule
}{%
\end{minipage} \tabularnewline
\bottomrule
\end{tabular}
\end{table}
}

\NewDocumentCommand {\minute} { s m O{} } {%
\IfBooleanTF #1 {%
}{%
\end{minipage} \tabularnewline
\midrule
}%
{#2} & {#3} &
\begin{minipage}[t]{0.5\textwidth}
}

\begin{document}

\begin{minutes}
\minute*{Subject 1}%
The first item \textbf{has to be} starred:\newline
\verb=\minute*{The first...}=
\minute{Info 2}
The rest \textbf{musn't} be starred.