0

I would like to strikeout a paragraph with some different text colorings in it. As I learned here: Strikeout - when which package ? ( ulem vs soul vs ...) the \st command in soul strikesout whole paragraphs (respecting line breaks), while \sout in ulem just puts everything on one line (highly undesirable). But when I put my color commands inside \st, it tells me Argument of \textcolor has an extra }. and Package xcolor Error: Undefined color {gray}.!

\documentclass{article}
\usepackage[normalem]{ulem}
\usepackage{soul}
\usepackage{xcolor}
\newcommand{\clight}[1]{\textcolor{white!70!black}{#1}}
\definecolor{alert}{RGB}{255, 10, 61} % 1/20/22
\newcommand{\calert}[1]{\textcolor{alert}{#1}}


\begin{document}

\clight{blah blah blah \calert{Warning!} blah blah blah}.

\sout{\clight{blah blah blah}}

\st{blah blah blah}.

%\st{\textcolor{gray}{blah blah}}
%\st{\clight{blah blah}} % gives `Argument of \clight has an extra }.`

\end{document}

There seem to be known issues regarding these packages: Interaction between xcolor, ulem, and no-break spaces, soul: broken highlighting with xcolor when using \selectcolormodel, acro acronym not recognized inside the soul package's strikeout command. very disappointing that no better solutions have been developed.

P.S. using \sout, it looks like the horizontal line is behind the text, not over it... very strange

3
  • Your MWE compiles fine on my machine with pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) or with LuaHBTeX, Version 1.15.0 (TeX Live 2022). Have you an up-to-date installation?
    – NBur
    Oct 21, 2022 at 6:17
  • @NBur even with the commented out portion inserted?
    – D.R
    Oct 21, 2022 at 7:16
  • Sorry, commented too fast… That was really a mWe!
    – NBur
    Oct 21, 2022 at 8:16

1 Answer 1

2

soul is fragile and doesn't like commands in the arguments. See the documentation for some background info. In your case it works if you add additional braces and color word by word:

\documentclass{article}
\usepackage{soul}
\usepackage{xcolor}
\newcommand{\clight}[1]{\textcolor{white!70!black}{#1}}
\definecolor{alert}{RGB}{255, 10, 61} % 1/20/22
\newcommand{\calert}[1]{\textcolor{alert}{#1}}

\begin{document}

\st{blah blah blah}.

\st{{\textcolor{gray}{blah}} {\textcolor{gray}{blah}}}

\st{{\clight{blah}} {\clight{blah}}} 

\end{document}

A much more robust solution is to use lualatex and the lua-ul package:

\documentclass{article}
\usepackage{luacolor}
\usepackage[soul]{lua-ul}
\usepackage{xcolor}
\newcommand{\clight}[1]{\textcolor{white!70!black}{#1}}
\definecolor{alert}{RGB}{255, 10, 61} % 1/20/22
\newcommand{\calert}[1]{\textcolor{alert}{#1}}

\begin{document}

\st{blah blah blah}.

\st{\textcolor{gray}{blah blah}}
\st{\clight{blah blah}} %

\end{document}

enter image description here

5
  • are there truly no "native" LaTeX packages that have more robust underlining/strikethrough capabilities? If so, do you have any idea why? Is it particularly difficult, or just something the community has overlooked?
    – D.R
    Oct 21, 2022 at 7:37
  • it is very difficult if you want also hyphenation and line breaking. The alternative method to the token analysis done by soul would be dedicated fonts with strikethrough characters. The luatex version works with attributes which makes everything much easier. Oct 21, 2022 at 7:44
  • @D.R there is also ulem, that one is more robust than soul but lacks automatic hyphenation (manual hyphenation with \- works though).
    – Skillmon
    Oct 21, 2022 at 8:59
  • @Skillmon I can't get ulem to work with a whole paragraph of text, like I mentioned in my question above.
    – D.R
    Oct 22, 2022 at 20:14
  • @D.R if your lines are equally spaced you can also use TikZ (there are solutions for this on the site).
    – Skillmon
    Oct 22, 2022 at 20:20

You must log in to answer this question.

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