1

In order to strike text in red in math mode, I found this solution quite useful. However, it fails when I want to do it in subscript, since the command does not detect that the size of the text is smaller. Therefore, it overlaps on the content written after, like here:

enter image description here

Any idea how to strike text in red in math mode in a subscript?

MWE:

\documentclass[]{article}

\usepackage{xcolor}
\newcommand\hcancel[2][black]{\setbox0=\hbox{$#2$}%
   \rlap{\raisebox{.25\ht0}{\textcolor{#1}{\rule{\wd0}{1pt}}}}#2}

\begin{document}

$ABC_{\hcancel[red]{DEF}\textcolor{green!50!black}{GHI}}(JKL)$
\end{document}

1 Answer 1

1

You can modify the command to use the current math style with \ThisStyle and \SavedStyle from scalerel.

\documentclass{article}
\usepackage{scalerel}
\usepackage{xcolor}
\newcommand\hcancel[2][black]{%
    \ThisStyle{%
        \setbox0=\hbox{$\SavedStyle #2$}%
        \rlap{\raisebox{.25\ht0}{\textcolor{#1}{\rule{\wd0}{1pt}}}}\SavedStyle #2}%
    }
\begin{document}
$ABC_{\hcancel[red]{DEF}\textcolor{green!50!black}{GHI}}(JKL)$
\end{document}

You must log in to answer this question.

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