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

