![是否可以同时突出显示和下划线?](https://linux22.com/image/444188/%E6%98%AF%E5%90%A6%E5%8F%AF%E4%BB%A5%E5%90%8C%E6%97%B6%E7%AA%81%E5%87%BA%E6%98%BE%E7%A4%BA%E5%92%8C%E4%B8%8B%E5%88%92%E7%BA%BF%EF%BC%9F.png)
在看着使用彩色下划线突出显示文本,链接到边注,我被(对我来说)意想不到的吸引人的文本外观所震撼,这些文本既突出显示和下划线——当然不建议在所有情况下使用,但在这种情况下它似乎很有用。我对这两种方法都比较熟悉,soul
而且可以轻松实现,但不能同时实现。文档soul
说嵌套是不可能的(我可以确认:<( )。的代码soul
令人望而生畏,我不愿意修改。
这可能吗?
答案1
在这方面,适当修改的censor
软件包可能会提供一些有用的东西。确保你[2021-12-23]
加载了最新版本,https://www.ctan.org/pkg/censor。
\documentclass{article}
\usepackage{censor}[2021-12-23]
\usepackage{xcolor,stackengine}
\makeatletter
\renewcommand\censorrule[1]{\textcolor{yellow}{\protect
\rule[\censorruledepth]{#1}{\censorruleheight}}}
\newcommand\censorul[1]{\textcolor{blue}{\protect
\rule[\censorruledepth]{#1}{1pt}}}
\renewcommand\@cenword[1]{\bgroup
\renewcommand\stacktype{L}%
\setstackgap{L}{0pt}%
\stackon{\stackon{\censorrule{\widthofpbox{#1}}}
{\censorul{\widthofpbox{#1}}}}%
{#1}%
\egroup
}
\def\censpace{\rlap{\censorrule{\spacelap}}%
\rlap{\censorul{\spacelap}} \llap{\censorrule{\spacelap}}%
\llap{\censorul{\spacelap}}}
\let\sv@censpace\censpace
\censorruledepth -\dp\strutbox
\censorruleheight \baselineskip
\makeatother
\begin{document}
We now have to test this approach.
\xblackout{Testing of a theory is proceeding at this point.
We must see whether line breaking occurs. I can even include
expandable macros if I use v 4.0. See: \expanded{\today}---however,
hyphenation will not occur with this approach.}
The test is now complete.
\end{document}
补充
OP 指出了一个潜在的问题,它不仅延伸到这个解决方案,还延伸到包censor
本身,我必须修复它。问题涉及宏,如\$
、、等,它们应该是可合并的,但不能(通过)扩展为简单文本。\#
\&
\expanded
提供的解决方法是:\xblackout{...\censor{\$}...}
。
更好的解决方案是重新定义,\xblackout
首先查找此类字符,找到后,无需用户额外干预即可对其进行审查。以下代码块演示了如何做到这一点。但请注意,这样的解决方案最终将被纳入包中censor
。
\xblackout
以下是重新定义并纳入此类字符检查所需的附加代码。其他字符宏可以添加到\testchars
宏中:
\makeatletter
\xtokcycleenvironment\xblackoutenv
{\ifx.##1\@dump\censored@word\addcytoks[1]{\censordot}\else
\@append\censored@word{##1}%
\tcpeek\@next\ifx\@next\@tcEscapeptr\@dump\censored@word\fi\fi}
{\tctestifcon\ifexpandarg{\expandafter\processtoks\expandafter{\expanded{##1}}}%
{\processtoks{##1}}\@dump\censored@word\expandargfalse}
{\@dump\censored@word\tctestifx{~##1}{\@append\censored@word{##1}}%
{\tctestifx{\expanded##1}{\expandargtrue}{%
\testchars{##1}\ifchar\addcytoks{\censor{##1}}\else\addcytoks{##1}\fi}}}
{\@dump\censored@word\addcytoks{\censpace}}
{\def\censored@word{}}
{\@dump\censored@word}
\newif\ifchar
\newcommand\testchars[1]{\charfalse
\ifx\$#1\chartrue\else
\ifx\\chartrue\else
\ifx\##1\chartrue\else
\fi\fi\fi
}
\makeatother