如何使用 Soul 在连续突出显示的文本内添加下划线(带换行)

如何使用 Soul 在连续突出显示的文本内添加下划线(带换行)

我想\ul使用以下代码中包含的宏在连续突出显示的文本块内使用该命令:

\documentclass[12pt,openany]{book}
\usepackage{soul}
\usepackage[svgnames]{xcolor}
\colorlet{soulred}{red!30}
\sethlcolor{soulred}

\makeatletter
\def\SOUL@hlpreamble{%
\setul{\dimexpr\dp\strutbox+2pt}{\dimexpr\ht\strutbox+\dp\strutbox+2pt\relax}
\let\SOUL@stcolor\SOUL@hlcolor
\SOUL@stpreamble
}
\makeatother

\begin{document}
\thispagestyle{empty}
\setlength{\lineskip}{0pt}

\hl{I would like to underline within this highlighted sentence. Here is another sentences to illustrate that the highlighting is also contiguous.}\\[15pt]
\hl{I would like to \ul{underline} within this highlighted sentence. Here is another sentences to illustrate that the highlighting is also contiguous.}
\end{document} 

产生

在此处输入图片描述

从输出中可以看出,使用命令\ulwithin\hl会产生错误。如果我用 替换\ul\underline仍然会得到错误——黑框和我加下划线的单词都会消失。

我怎样才能使用换行功能来​​加下划线(这就是我尝试使用的原因\ul)并在命令的范围内\hl

答案1

soul 不能嵌套这样的命令,至少如果你想在内部命令中允许换行的话。使用 lualatex 和 lua-ul 包它可以工作:

\documentclass[12pt,openany]{book}
\usepackage{luacolor,xcolor}
\usepackage[soul]{lua-ul}
\colorlet{soulred}{red!30}
\LuaULSetHighLightColor{soulred}
\begin{document}

\hl{I would like to underline within this highlighted sentence. Here is another sentences to illustrate that the highlighting is also contiguous.}\\[15pt]
\hl{I would like to \ul[top=-0.2ex,height=1pt]{underline within this highlighted sentence. Here is another sentences to} illustrate that the highlighting is also contiguous.}
\end{document} 

在此处输入图片描述

相关内容