我在使用 ulem 和 soul 在新命令中删除多行文本时遇到了困难。
以下答案没有帮助:
https://tex.stackexchange.com/a/74910/265141 % 带连字符的多行单词
https://tex.stackexchange.com/a/430295/265141% 添加\expandafter
\documentclass{article}
\usepackage{xcolor}
\usepackage[normalem]{ulem}
\usepackage{soul}
\newcommand{\HW}[1]{\textcolor{green}{(HW) #1} }
\newcommand{\WH}[1]{\textcolor{red}{(WH) #1} }
\begin{document}
MWE
% This is ulem
\HW{\sout{\WH{Hello, World! This is a long paragraph so we get multiple lines. It seems this can be difficult to handle by packages and I'm not sure why.}} Do you know?}
Thanks!
% This is soul. It raises an error of unmatched brackets
\WH{\st{\HW{World, Hello! This is a long paragraph so we get multiple lines. It seems this can be difficult to handle by packages and I'm not sure why.}} Do you know?}
% The below should not print red
Thanks!
\end{document}
答案1
不幸的是,命令\st
必须看到文本直接地(不隐藏在任何宏后面)才能工作。任何都\textcolor
必须在外面。
因此,一个选择是写
\WH{\textcolor{green}{\st{World, Hello! This is a long paragraph so we get multiple lines. It seems this can be difficult to handle by packages and I'm not sure why.}} Do you know?}
\st
扩展宏来处理更多特殊情况并非不可能,但实现完全通用则非常困难。
或者使用lua-ul
包,它使用 LuaLaTeX 的一些特殊能力来实现功能。
\documentclass{article}
\usepackage{xcolor}
\usepackage{lua-ul}
\newcommand{\HW}[1]{\textcolor{green}{(HW) #1} }
\newcommand{\WH}[1]{\textcolor{red}{(WH) #1} }
\begin{document}
MWE
\WH{\strikeThrough{\HW{World, Hello! This is a long paragraph so we get multiple lines. It seems this can be difficult to handle by packages and I'm not sure why.}} Do you know?}
Thanks!
\end{document}