0

I'm having a hard time doing a strikeout of a multi-line text within a newcommand using ulem and soul.

The answers below were not helpful:

https://tex.stackexchange.com/a/74910/265141 % Multi-line word with hyphenation https://tex.stackexchange.com/a/430295/265141 % Adding \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}

Output of MWE showing undesired behaviour.

1 Answers1

1

Unfortunately, the command \st must see the text directly (not hidden behind any macro) for it to work. Any \textcolor must go outside.

So one option is to write

\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?} 

It's not impossible to extend the \st macro to handle a few more special cases, but being completely general is very difficult.

Alternatively use lua-ul package, which uses some special abilities of LuaLaTeX to implement the functionality.

\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}

user202729
  • 7,143