# cancel package documentation, shaded blocks to cancel

I would like to use some kind of colored cancel lines to mark simplifications. The cancel package documentation reads:

If you use the color package, then you can declare

\renewcommand{\CancelColor}{<color_command>}

and the cancellation marks will be printed in that color (e.g. \blue). However if you are using color, I recommend lightly shaded blocks rather then diagonal arrows fro cancelling.

I guess the lightly shaded blocks are a good idea, how would I implement this? (What package should I use?)

### MWE

\documentclass[10pt,a4paper]{article}
\usepackage{cancel}
\usepackage{xcolor}

\begin{document}
$\frac{\cancel{a}b}{4\cancel{a}}$

\renewcommand{\CancelColor}{\color{blue}}
$\frac{\cancel{(a+4)}\cdot 3}{\cancel{a+4}}$

\end{document}
• Welcome to TeX.SX! Rather than posting images of code can you please post the code itself as this way people can cut-and-paste it into examples. If it all possible, which it is here, you should also give a minimal working example. This should be an example that compiles and is as small as possible to demonstrate your problem. In addition to clarifying your question this makes it much easier for people to help you and, hence, much more likely that some one will! :) – Andrew Oct 11 '17 at 16:12
• Unrelated, but see Why is $...$ preferable to $$...$$? – Werner Oct 11 '17 at 16:29
• Cool, I was using $...$ untill someone said to me that $$...$$ is more modern approach. Thanks for the link! – dietervdf Oct 11 '17 at 16:33

I assume the author is suggesting to use something like \colorbox. You can either add a background shade, or shade the font using a different colour. Some options to consider:

\documentclass{article}

\usepackage{cancel,xcolor}

\newcommand{\cancelbox}[1]{{\color{black!50}#1}}

\begin{document}

$\frac{\cancel{a}b}{4\cancel{a}}$

\renewcommand{\CancelColor}{\color{blue}}
$\frac{\cancel{(a + 4)}\cdot 3}{\cancel{a + 4}}$
\renewcommand{\CancelColor}{}

$\frac{\shadedbox{(a + 4)}\cdot 3}{\shadedbox{a + 4}}$

$\frac{\shadedbox{\smash{(a + 4)}\vphantom{+}}\cdot 3}{\shadedbox{a + 4}}$

$\frac{\cancelbox{(a + 4)}\cdot 3}{\cancelbox{a + 4}}$

\end{document}
• Is there a way to add a color argument to \shadedbox? Like \shadedbox[blue]{a+4} ? – dietervdf Oct 11 '17 at 16:56
• \newcommand{\shadedbox}[2]{\colorbox{#1!5}{$#2$}} seems to do it. Usage \shadedbox{blue}{(a+2)} Not really a optional argument, but hey, it works ;) – dietervdf Oct 11 '17 at 17:02
• @dietervdf: You can use \newcommand{\shadedbox}[1][black]{\colorbox{#1!5}}, which would allow you to use the colour as an optional argument. – Werner Oct 11 '17 at 17:12