我在用包裹soul
到省略下划线. 似乎将以下内容作为参数传递可以正常工作
\textit{special text}
但如果\textit
通过宏间接应用,\ApplyStyle
则会出现错误:
\ApplyStyle 的参数有一个额外的}。
问题:
是否可以通过更改宏来间接应用样式\varul
?如果不行,还有哪些其他选项可用(当然,除了在宏调用中直接应用格式外\varul
——这太简单了 :-))?
代码:
\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{\ApplyStyle}[1]{\textit{#1}}%
\begin{document}
\varul{\textit{special text}\xspace}% Works!!
\varul{\ApplyStyle{special text}\xspace}% Does NOT work
\end{document}