8

Is it possible to assign multiple colors to the command "cancelto" of the package cancel? This answer change color cancelto is almost there, but it changed the color for all the environments, at least it's my guess.

I was imagining something customizable, for example:

\renewcommand{\CancelColor}{\color{color of choice}} %%%%%%color as an input%%%%%%%

\cancelto[color of choice number 1]{0}{x}
\cancelto[color of choice number 2]{0}{x^2}

Regards,

unmark1
  • 469

1 Answers1

7

This uses a different command with an optional argument that is meant for colour specification. If the argument isn't used the usual \CancelColor is applied.

\documentclass{article}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{cancel}
\usepackage{etoolbox}

\let\cancelorigcolor\CancelColor% Just for conveniency...

\newcommand{\CancelTo}[3][]{%
  \ifblank{#1}{}{%
    \renewcommand{\CancelColor}{#1}%
  }
  \cancelto{#2}{#3}% 
}

\begin{document}


$\cancelto{0}{x}$ versus $\CancelTo[\color{red}]{0}{x}$

Now again

$\CancelTo{0}{x}$ versus $\CancelTo[\color{blue}]{0}{x^2}$

and again

$\CancelTo[\color{brown}]{0}{x^3}$ versus $\CancelTo[\color{green}]{0}{x^2}$

and again and again 

$\CancelTo{0}{x^3}$

\end{document}

enter image description here

  • \renewcommand{\CancelColor}{foocolor} within an equation or align etc environment would of course not change the \CancelColor outside of that environment due to grouping –  Aug 24 '16 at 19:48
  • Perfect, great solution!Thx! – unmark1 Aug 24 '16 at 20:24