Motivation
I'm working on a custom \Colour command/environment. I'd like to have two mandatory arguments, one taking comma-separated parameters and the second taking the body. My approach for the comma-separated part uses xparse's \SplitArgument. Is it possible to get the parent function to pass an argument to its auxiliary/child function?
Current version
\documentclass{article}
\usepackage{
xparse,
amsmath,
xcolor
}
\ExplSyntaxOn
\NewDocumentCommand{\ColourAux}{m m m m}{
\newcommand{\Coloured}{\color{#1}#4}
\tl_if_empty:nTF { #2 } { \newcommand{\Body}{\begin{aligned}\Coloured\end{aligned}} }{
\str_case:nnF { #2 } {
{ t }{ \newcommand{\Body}{\text{\Coloured}} }
{ i }{ \newcommand{\Body}{\textit{\Coloured}} }
{ b }{ \newcommand{\Body}{\textbf{\Coloured}} }
{ ib }{ \newcommand{\Body}{\textit{\textbf{\Coloured}}} }
{ bi }{ \newcommand{\Body}{\textit{\textbf{\Coloured}}} }
} { }
}
\tl_if_empty:nTF { #3 } { \Body } { \parbox{#3}{\Body} }
}
\ExplSyntaxOff
\NewDocumentCommand{\Colour}{>{\SplitArgument{3}{,}}m}{\ColourAux#1}
\begin{document}
\begin{align}
& \Colour{red,ib,4cm,the quick brown fox jumps over the lazy dog} \ % works as desired
% & \Colour{red,ib,4cm}{the quick brown fox jumps over the lazy dog} \ % desired syntax
& \Colour{red,,,\frac{1}{\sqrt{a^2+b^2}}} \ % works as desired
% & \Colour{red}{\frac{1}{\sqrt{a^2+b^2}}} % desired syntax
\end{align}
\end{document}
Edit 1: with thanks to Steven B. Segletes, is it possible to do this with expl3/xparse?
Edit 2: in response to egreg's comment, I've found and implemented a suggestion from an answer by Joseph Wright to use \newcommand to store variables.

\defat *all* costs. – egreg Apr 28 '21 at 21:47