This is a followup to Using soul with indirect formatting applied, where it was determined that using \soulregister allows the soul macros to have font switching macros within the parameters (specifically \ul in this case). However, I am not able to get this to work if the macro has more than one parameter.
Single Parameter: \ApplyStyleA
This seems to work fine if the macro has one mandatory parameter, as per the answer in Using soul with indirect formatting applied.
Two Mandatory Parameters: \ApplyStyleB
However, if the macro has two mandatory parameters, then I get:
Extra }, or forgotten \endgroup
Two Parameters (one optional): \ApplyStyleC
Or, for the case where there is one optional parameter and one mandatory parameter, I get:
TeX capacity exceeded, sorry [input stack size=5000]
Notes:
- The MWE as is below compiles fine as the two problematic lines are commented out. So, one needs to uncomment one of those to reproduce the problem.
Code:
\documentclass{article}
\usepackage{xparse}
\usepackage{xcolor}
\usepackage{soul}
\usepackage{xspace}
%% ----------------------------------------------------------------
%% https://tex.stackexchange.com/questions/36894/
%% underline-omitting-the-descenders
%%
%%
\makeatletter
\ExplSyntaxOn
\cs_new:Npn \white_text:n #1
{
\fp_set:Nn \l_tmpa_fp {.01}
\fp_mul:Nn \l_tmpa_fp {#1}
\llap{\textcolor{white}{\the\SOUL@syllable}\hspace{\fp_to_decimal:N \l_tmpa_fp em}}
\llap{\textcolor{white}{\the\SOUL@syllable}\hspace{-\fp_to_decimal:N \l_tmpa_fp em}}
}
\NewDocumentCommand{\whiten}{ m }
{
\int_step_function:nnnN {1}{1}{#1} \white_text:n
}
\ExplSyntaxOff
\NewDocumentCommand{ \varul }{ D<>{5} O{0.2ex} O{0.1ex} +m } {%
\begingroup
\setul{#2}{#3}%
\def\SOUL@uleverysyllable{%
\setbox0=\hbox{\the\SOUL@syllable}%
\ifdim\dp0>\z@
\SOUL@ulunderline{\phantom{\the\SOUL@syllable}}%
\whiten{#1}%
\llap{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
\else
\SOUL@ulunderline{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
\fi}%
\ul{#4}%
\endgroup
}%
\makeatother
%% ----------------------------------------------------------------
\newcommand{\ApplyStyleA}[1]{\textit{#1}}
\soulregister\ApplyStyleA{1}
\newcommand{\ApplyStyleB}[2]{\textit{#1}}
\soulregister\ApplyStyleB{2}
\newcommand{\ApplyStyleC}[2][]{\textit{#2}}
\soulregister\ApplyStyleC{2}
\begin{document}
This one works just fine:
\varul{\ApplyStyleA{special text}\xspace}%
\medskip
These one leads to ``Extra }, or forgotten \verb|\endgroup|."
%\varul{\ApplyStyleB{special text}{second paramater}\xspace}%
\medskip
This one leads to ``TeX capacity exceeded, sorry [input stack size=5000]"
%\varul{\ApplyStyleC[first optional paramater]{special text}\xspace}%
\end{document}

0and1aremore an identifier and not specifically the number of arguments. The digits7,8and9are reserved for superscripts, footnotes and accents respectively. The number is used in\SOUL@docmdin a few conditionals. I fear that your commands won’t be recognized bysoulout of the box. It is also important to know what the optional argument does. Will the content be typeset? How does the command work? – Qrrbrbirlbel Jul 24 '13 at 22:16