我想\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}
产生
从输出中可以看出,使用命令\ul
within\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}