2

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 Answer 1

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}
1
  • 1
    Link to some related questions 1 (contain lua-ul example) 2 3 4 5
    – user202729
    Commented Jul 29, 2022 at 5:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .