I'm not sure why the following code causes problems.
\documentclass{article}
\usepackage{array}
\newcommand{\startStatBlock}[1]
{#1 \arraybackslash}
\newcommand{\stopStatBlock}
{\arraybackslash}
\newenvironment{statBlock}[1]
{\startStatBlock{#1}}
{\stopStatBlock}
\begin{document}
% This works just fine.
\begin{tabular}{ll}
\startStatBlock{thing}
stat one & 2 \\
stat two & 2 \\
\stopStatBlock
\end{tabular}
% The following fails with the following message:
% ! Extra }, or forgotten \endgroup.
% <recently read> \egroup
% l.22 \end{tabular}
\begin{tabular}{ll}
\begin{statBlock}{Some Stats}
stat one & 2 \\
stat two & 2 \\
\end{statBlock}
\end{tabular}
\end{document}
I apologize if this has been covered before, but I wasn't able to find directly related questions. I'm not sure what the difference between the two are.
The reason I'd like to use the environment is to make the semantic structure of my document more clear, so I'd really prefer to use environments over commands to start and stop an environment. Also, this is just a simplified example to isolate an error; ideally, in the final product, there'd be a lot of presentation logic inside of the statBlock
environment and similar environments, and the content inside of the environments would mainly be information, without too much stuff for specifying appearance.
{\begin{statBlock} SomeStats} stat one}
this isn't going to work without a lot of internal definitions to fake an environment\begin{environment}
and\end{environment}
commands were just like macros.{\bfseries xxxx} yyy
the bold font is discarded at the}
you will similarly see if you use\bfseries
in a table cell it stops being bold at the&
so if you use{\begin{foo} ..}
inside a group then you will get an error at the}
because\begin{foo}
starts a group that has to end by\end{foo}
and}
is the wrong kind of group end.&
so not in scope for the rest of the enviornment, so making it look like an environment might be confusing