I am trying to create a custom tblr environment for a schedule which I reuse often. I want to include an optional label for cross-referencing.
I'm using the xparse \NewDocumentEnvironment
command together with tabularray, but I cannot get tabularray to expand the command \IfValueT{#1}{label={#1},}
in the outer specification.
Everything works if I instead use \IfValueTF
and duplicate the \begin{tblr}[
, but that doesn't seem very robust.
Is there a way to make the "testa" option in the below MWE work?
MWE:
\documentclass{scrreprt}
\usepackage{tabularray}
\NewDocumentEnvironment{testa}{o m +b}{
\begin{tblr}[
\IfValueT{#1}{label={#1},}
caption={#2},
long,
]{
colspec = {ll},
}
Column 1 & Column 2 \\
#3
\end{tblr}
}{}
\NewDocumentEnvironment{testb}{o m +b}{
\IfValueTF{#1}{\begin{tblr}[label={#1},}{\begin{tblr}[}
caption={#2},
long,
]{
colspec = {ll},
}
Column 1 & Column 2 \\
#3
\end{tblr}
}{}
\begin{document}
\begin{testa}[labela]{captiona}
a & b
\end{testa}
\begin{testb}[labelb]{captionb}
a & b
\end{testb}
Tables \ref{labela} and \ref{labelb} should be the same, but Table \ref{labela} is an undefined reference.
\end{document}