29

I have equations with a lot of terms and I would like to be able to specify the reason of the cancelation of those terms using a color code (for example : red if the term is null, blue if it cancels out with another term, green if it can be considered as very small...).

How to define new commands to be able to cancel these terms with different colors using the cancel package?

2 Answers 2

39

The color of the line used by cancel can be changed with

\renewcommand\CancelColor{<color command>}

You could include this in a new cancel-command where an optional argument defines the color.

output of below code

\documentclass{article}
\usepackage{cancel}
\usepackage{xcolor}
\newcommand\Ccancel[2][black]{\renewcommand\CancelColor{\color{#1}}\cancel{#2}}

\begin{document}
\[
\Ccancel{x+1} \qquad \Ccancel[blue]{x-1}
\]
\end{document}
13

A less fragile variant of the other answer, which allows \cancel to continue to use the old color:

\newcommand\Ccancel[2][black]{
    \let\OldcancelColor\CancelColor
    \renewcommand\CancelColor{\color{#1}}
    \cancel{#2}
    \renewcommand\CancelColor{\OldcancelColor}
}

You must log in to answer this question.

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