I am trying to create a new document environment to complete the assembly of a table (simplified for MWE) but I am having a problem combining an expandable environment with an optional only argument.
The error I generate is xparse/expandable-ending-optional
Argument specification for expandable command ends with optional argument.
\documentclass{article}
\usepackage{xparse}
\usepackage{environ,longtable,threeparttablex,booktabs,multirow,array,adjustbox,supertabular}% table adjustment packages
% change spacing/padding of long table: http://tex.stackexchange.com/questions/5683/how-to-remove-top-and-bottom-whitespace-of-longtable
\setlength{\LTpre}{0pt}
\setlength{\LTpost}{0pt}
% Wrapping text in multicolumn: http://tex.stackexchange.com/questions/115668/wrapping-text-in-multicolumn
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
%http://tex.stackexchange.com/questions/70919/vertical-aligning-in-longtable-environment
%\adjustbox{valign=t}{}
%\raisebox{\normalbaselineskip-\height}{#6} & \multicolumn{2}{L{11cm}}{#7}
% changed m to p instead
\makeatletter
\newcommand\eatpar{\@ifnextchar\par{\expandafter\eatpar\@gobble}\relax}
\makeatother
%--------------------New Commands for consistent formatting ---------------
\ExplSyntaxOn
% this one can't be a held in a local variable because the table paramaters are external
\DeclareDocumentCommand{\TableAssembly}{ m m }{%
#1 & #2 \\%
}%
\DeclareExpandableDocumentCommand{\BuildTablePortion}{ O{R{2.5cm} | L{12.25cm}}}%
{%
\begin{ThreePartTable}%
\begin{TableNotes}[para,flushleft]%
\end{TableNotes}%
\renewcommand\multirowsetup{\raggedleft}%
\begin{longtable}[l]{#1}%
}%
\DeclareExpandableDocumentCommand{\endBuildTablePortion}{ o }
{%
%\insertTableNotes%
\end{longtable}%
\end{ThreePartTable}%
}%
\ExplSyntaxOff
\begin{document}
\begin{BuildTablePortion}[R{2.5cm} | L{12.25cm}]
\TableAssembly{1}{2}
\TableAssembly{1}{3}
\end{BuildTablePortion}
\end{document}
\DeclareExpandableDocumentCommand
when you eventually do\begin{BuildTablePortion}
? It makes no sense. What should an “expandable environment” be?\ExplSyntaxOn
? You don't seem to use that syntax at all. For an explanation of the error see page 10 ofxparse
's manual: if you have any arguments, the last one must be of typem
orr
. That is, if you did need expandability, you couldn't use this argument specification.