Using expl3 syntax, I want in my \coolgloss command to use as an optional argument one or several formatting commands such as \small and \itshape.
With a command like \newcommand{\coolgloss}[3][\small\itshape]{text}{gloss} I have no problems, but I specifically want to use expl3 in order to have a split optional which includes the negative raise value for \rule.
It works if I only want to pass one command name (e.g. small) through \csname...\endcsname, but I want support for multiple commands (e.g. \small\itshape), and I want the arguments to be given with the backslash included.
Thus, the command must take a split optional argument, whose the second subargument (argument #2) is dedicated to the formatting:
\coolgloss[5,\small\itshape]{text}{gloss}
But when I input it, the \small command (not the \itshape one) triggers a TeX capacity exceeded error.
This has to be an issue with expansion and variable types, i.e. somewhere I should replace a n with some other type.
MWE
\documentclass{article}
\usepackage{gb4e}
\NewDocumentCommand{\coolglossaux}{mmmm}{%
\renewcommand{\eachwordtwo}{\rule[-#1pt]{0pt}{0pt}#2}% !! #2 is the one !!
\getwords(\lineone,\eachwordone)#3 \%
\getwords(\linetwo,\eachwordtwo)#4 \%
\loop\lastword{\eachwordone}{\lineone}{\wordone}%
\lastword{\eachwordtwo}{\linetwo}{\wordtwo}%
\global\setbox\gline=\hbox{\unhbox\gline
\hskip\glossglue
\vtop{\box\wordone
\nointerlineskip
\box\wordtwo
}%
}%
\testdone
\ifnotdone
\repeat
{\hskip -\glossglue}\unhbox\gline
}
\ExplSyntaxOn
\NewDocumentCommand{\coolgloss}{>{\SplitArgument{1}{,}}omm}
{
\my_xcoolgloss:nnnn #1 {#2} {#3}
}
\cs_new_protected:Nn \my_xcoolgloss:nnnn
{
__my_xcoolgloss:eenn
{ \tl_if_novalue:nTF { #1 } { 10 } { #1 } }
{ \tl_if_novalue:nTF { #2 } {} { #2 } }
{ #3 }
{ #4 }
}
\cs_set_eq:NN __my_xcoolgloss:nnnn \coolglossaux
\cs_generate_variant:Nn __my_xcoolgloss:nnnn {ee}
\ExplSyntaxOff
\begin{document}
\coolgloss[5,\itshape]{I like \LaTeX}{I like \LaTeX}
%\coolgloss[5,\small\itshape]{I like \LaTeX}{I like \LaTeX} => TeX capacity exceeded
\end{document}


\small(you get the same error with just\expanded{\small}). You need to either protect\smallor not try and expand it. – Max Chernoff Jan 18 '23 at 05:03\smallis not expandable because in its definition,\selectfonthas already expanded\fontsize{}{}. – Vincent Krebs Jan 22 '23 at 16:16\itshapeand\smallboth ultimately call\selectfont, which is unexpandable since it calls\def. The difference is that\itshapeis a\protectedmacro while\smallis\protect'ed.\protectedmacros never expand (except with\expandafter) while\protect'ed macros only don't expand if they are used in certain LaTeX constructs (like\protected@edef). It's a fairly confusing topic, not at all helped by the confusing names. – Max Chernoff Jan 23 '23 at 05:54