3

It seems that \st{} for crossing out a text (strike through) doesn't work on the section title. For example, this

\documentclass{article}
\usepackage{soul,color}
\begin{document}
\section{\st{Motivation}}\label{sec:theproblem}
In this section, we are going to explain the detail and you will see...
\end{document}

fails while it works fine with the body text

\documentclass{article}
\usepackage{soul,color}
\begin{document}
\section{Motivation}\label{sec:theproblem}
In this section, we are going to \st{explain the detail} and you will see...
\end{document}

BTW, yes the soul package is included :)

UPDATE

UPDATE

Using \protect\st works fine but the bug is, if you add \usepackage{hyperref}, you will get this error

! Argument of \let has an extra }.
<inserted text>
                \par
l.5 \section{\protect\st{Motivation}}
                                     \label{sec:theproblem}
?

The problem has been addressed by Christian Hupfer in his answer.

10
  • 2
    you haven't provided a usable test file but \protect\st probably works Apr 24, 2015 at 18:50
  • 1
    Same here. Perhaps it's time to update your packages. Apr 24, 2015 at 19:01
  • 1
    Let start with this example and add your packages one by one to find the problem (may be)
    – touhami
    Apr 24, 2015 at 19:02
  • 1
    the screenshot is not useful as it does not relate to the code you hav eposted Apr 24, 2015 at 19:10
  • 1
    If you had made a test file using hyperref you would have saved people a lot of trouble. It is not a bug see \texorpdfstring{TEXstring }{PDFstring } in the hyperref documentation. Apr 24, 2015 at 19:39

2 Answers 2

6

Early version of this solution

The specific behaviour of the sectioning commands require special treatment for the content to be designed as title of chapters etc, in this case for the \st command from the soul package. It must be protected, i.e. preceeded by a \protect.

Edit

I just tested: The \st macro is already robust. \protect is not really needed.

\documentclass{book}
\usepackage{soul}
\begin{document}
\tableofcontents
\chapter{\protect\st{This is crossed-out}}
\end{document}

enter image description here

Edit Number Two

If hyperref is used, this runs into the typical problem with the bookmarks and hyperlinks. Use \texorpdfstring to get around for such a woe ;-)

\documentclass{book}
\usepackage{soul}
\usepackage[bookmarksopen=true]{hyperref}
\begin{document}
\tableofcontents
\chapter{\texorpdfstring{\st{This is crossed-out}}{This is not crossed out}}
\end{document}
5
  • @mahmood: Your example document works for me without problems (the one with \section{\protect\st....}
    – user31729
    Apr 24, 2015 at 18:57
  • Can you add \usepackage{hyperref} and see if your examples is still working?
    – mahmood
    Apr 24, 2015 at 19:18
  • @mahmood: See my updated answer
    – user31729
    Apr 24, 2015 at 19:24
  • If you want to add command like \setstcolor, you have to use \protect\setstcolor{red}\texorpdfstring{\st{tex}}{pdf}}
    – Syvshc
    Dec 7, 2021 at 13:31
  • This solution in Edit #2 works for highlighting too!!! That is the only thing works to highlight the subsubsection for me. I used \subsubsection{\texorpdfstring{\hl{This is highlighted}}{This is not highlighted}}
    – Huyen
    May 26 at 22:21
1

In user31729's solution the uncrossed text ("This is not crossed out") does not appear in the title or the ToC. If both soul and plain text are required, such as to show a correction, the following code works:

\documentclass{article}
\usepackage{lipsum}
\usepackage{soul}
\usepackage{hyperref}
\begin{document}
  \tableofcontents
  \section{\texorpdfstring{\st{Old}{New}}{}}
  \lipsum[1]
\end{document}

Sample output

Image showing crossed and uncrossed text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.