I have a command \cont
used mainly in the form \cont{X, Y}
and defined using \SplitArgument
, as shown in the source below. How can I redefine (that is, extend the definition of)\cont
so as to allow 4 arguments rather than 2, which get grouped in pairs as shown in the outout equation (2)?
Notice that I want to continue using a comma as separator when there are only 2 arguments, as in \cont{X, Y}
. But I want to change the (main) separator to a semicolon when there are 4 arguments, while retaining commas as subsidiary separators, as in \cont{X, x; Y, y}
.
\documentclass[fleqn]{memoir}
\usepackage{xparse}
\NewDocumentCommand{\cont}{ >{\SplitArgument{1}{,}} m }{\printcont#1}
\NewDocumentCommand{\printcont}{mm}{{\mathcal{C}}({#1}\IfValueT{#2}{, {#2}})}
\begin{document}
\noindent Equation~(\ref{one}) shows use of \verb!\cont! with 2 arguments, as in \verb!\cont{X, Y}!, with comma as separator:
\begin{equation}\label{one}
\cont{X, Y}
\end{equation}
\noindent How can we \emph{extend} the definition of \verb!\cont! so that\dots\\[6pt]
\mbox{}\qquad\verb!\cont{X, x; Y, y}! \\[6pt]
---with commas and a single semicolon as separators----gives the same result as equation~(\ref{two}), below?
\begin{equation}\label{two}
\mathcal{C}[(X, x), (Y, y)]
\end{equation}
\end{document}
Best Answer
I'd issue the
\mathcal{C}
immediately and then pass control to another command that checks for a semicolon and takes the appropriate action.If you want to add
\bigl
and\bigr
to the brackets with\cont*
, then pass the argument throughout.