3

Is it possible to generate multiple \cancel stripes? Say for instance I have

$f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - 3x^2 - 2xy + 4xy^3$

and I want to cancel the 3x^2-term once and the 2xy-term twice.

$f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - 3x^2 - 2xy + 4xy^3$

Obviously,

$f(x,y) = \cancel{3x^2} +\cancel{\cancel{2xy}} +4y^2 - 3x^3 - \cancel{3x^2} - \cancel{\cancel{2xy}} + 4xy^3$

does not work...

ebosi
  • 11,692
Werner
  • 179

1 Answers1

1

I used my answer at How to cross-out a number several times? and modified to

REVISED ANSWER

  1. make it in math mode,

  2. auto-stretch the cancel to fit the term size.

Here is the revised MWE.

\documentclass{article}
\usepackage{stackengine,graphicx,amsmath,fp,scalerel}
\newcount\crosswd
\newcount\termwd
\newcommand\rawcrossout[2]{\ensurestackMath{%
  \setbox0=\hbox{$#2$}%
  \crosswd=\wd0\relax%
  \setbox0=\hbox{$#1$}%
  \termwd=\wd0\relax%
  \FPdiv\myscale{\the\termwd}{\the\crosswd}%
  \stackengine{0pt}{#1}{\stretchrel*{\scalebox{\myscale}[1]{#2}}{#1}}{O}{c}{F}{T}{L}}}
\def\XX{\kern-3pt/}
\def\YY{\kern-.5pt}
\newcommand\crossout[1]{\rawcrossout{#1}{\YY/\YY}}
\newcommand\dcrossout[1]{\rawcrossout{#1}{\YY/\XX\YY}}
\newcommand\tcrossout[1]{\rawcrossout{#1}{\YY/\XX\XX\YY}}
\newcommand\qcrossout[1]{\rawcrossout{#1}{\YY/\XX\XX\XX\YY}}
\begin{document}
\[f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - \crossout{3x^2} - \tcrossout{2xy} + 4xy^3\]

\[
f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - \dcrossout{3x^2} - \tcrossout{2\dfrac{\partial \psi^{\ast}}{\partial \theta}\dfrac{\sin\theta \cos\theta}{r^2}} + 
\qcrossout{4xy^3}
\]
\end{document}

enter image description here

ORIGINAL ANSWER

I used my answer at How to cross-out a number several times? and modified to

  1. make it in math mode,

  2. stretch the cancel horizontally by a default amount, and

  3. allow an optional argument to respecify the horizontal stretch value. Thus, for example, \crossout[3]{3x^2} could be used to make the 1-stroke cancel wider.

Here is the MWE.

\documentclass{article}
\usepackage{stackengine,graphicx}
\newcommand\rawcrossout[3]{\ensurestackMath{%
  \stackengine{0pt}{#2}{\scalebox{#1}[1]{#3}}{O}{c}{F}{T}{L}}}
\def\XX{\kern-3pt/}
\newcommand\crossout[2][2.5]{\rawcrossout{#1}{#2}{/}}
\newcommand\dcrossout[2][2.5]{\rawcrossout{#1}{#2}{/\XX}}
\newcommand\tcrossout[2][2.5]{\rawcrossout{#1}{#2}{/\XX\XX}}
\newcommand\qcrossout[2][2.0]{\rawcrossout{#1}{#2}{/\XX\XX\XX}}
\begin{document}
$f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - \crossout{3x^2} - \dcrossout{2xy} + 4xy^3$
\end{document}

enter image description here

  • That's already a step in the right direction, but unfortunately it doesn't work well with 'larger' expressions. The example I gave here was somewhat artificial, I'd be more interested to be able to double cancel terms of this size:
    $f(x,y) = 3x^2 +2xy +4y^2 - 3x^3 - \dcrossout{3x^2} - \dcrossout{{2\dfrac{\partial \psi^{\ast}}{\partial \theta}\dfrac{\sin\theta \cos\theta}{r^2}}} + 4xy^3$
    
    

    Oops, I can't get the code to work. I only have a small edit window at my disposal...

    – Werner Jun 15 '16 at 10:28
  • @Werner I could work to make the crossout autoscale to the object size, but then, the appearance would change with the object width/height. Is that acceptable? – Steven B. Segletes Jun 15 '16 at 10:39
  • Yes, that would be perfectly acceptable. – Werner Jun 15 '16 at 10:42
  • @Werner Please see revision. – Steven B. Segletes Jun 15 '16 at 11:01
  • The lines are thicker than I'm used to, but the solution's acceptable to me. Thank you for your effort! – Werner Jun 15 '16 at 11:11
  • 1
    @Werner You are welcome. The strokes can be made slightly thinner by modifiying \def\XX{\kern-0pt/}. – Steven B. Segletes Jun 15 '16 at 11:43