# Creating a strikeout command

I am trying to create a command that works in mathmode which simulates a strikeout diagonally while leaving the math display intact.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\strikeout}[1]{%
\ifmmode%
\tikz[inner sep=0.5pt,baseline] \node [strike out,draw=OrangeRed,anchor=text]{$#1$};%
\else%
\tikz[inner sep=0.5pt,baseline] \node [strike out,draw=OrangeRed,anchor=text]{#1};%
\fi%
}

\begin{document}
$\dfrac{x^2\times 10^3} {x^2\strikeout{\times 10^3}}$

$\dfrac{x^2\times 10^3} {x^2\tikzmark{matha}\times 10^3\tikzmark{mathb}}$
\tikz[remember picture, overlay,OrangeRed]
{\draw ($(matha)+(0.1em,-0.125em)$) --
($(mathb)+(-0.1em,0.825em)$);}

$\dfrac{x^2\times 10^3} {x^2\tikzmark{matha}\times 10^3\tikzmark{mathb}}$
\tikz[remember picture, overlay,OrangeRed,baseline]
{\draw[anchor=text] (matha.south west) --
(mathb.north east);}
\end{document}


Note the discrepancies in the displays. The first does not maintain the mathmode. Note I want this to work for any scenario thus I was thinking of redefining the strikeout command I have by using remember picture, overlay. But note my problem is to get to the line to be drawn like the original strikeout command. The second code seems to do the trick but it is fixed and am trying to make a user friendly command and well the third, its just out of the question. Thus, I am looking for a suitable way to make a command usable and with the results desired.

• You know about cancel, right? – Werner Mar 18 '13 at 19:31
• @Werner Yes, I am well aware of it. Note the cancel package has the same effect as my strikeout command. – azetina Mar 18 '13 at 19:32
• What do you have against $\dfrac{x^2\times 10^3}{x^2\strikeout{{}\times 10^3}}$ (using your definition)? BTW: I'm missing \usetikzlibrary{shapes.misc} in your code to compile. – cgnieder Mar 18 '13 at 20:06
• Interesting @cgnieder That seems to do the trick. – azetina Mar 18 '13 at 21:18

As noted by cgnieder in comments you can restore the mathbin spacing of \times by inserting {} at the ends of the math mode list inside the node. The code below adds that to \strikeout used in the first example. However this still boxes the subexpression making a mathord out of the term and freezing any white space at its natural width.

If the tikz bits in the second example are doing anything like I think they are doing (which is not guaranteed) then instead the tikz marks are attached to the individual atoms so no subterm involving white space is boxed, and the spacing is re-asserted by making the combination of the first mark and the times a mathbin atom. With a bit more work the code could determine the class of its argument and insert \mathbin (or \mathxx) automatically.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\newcommand{\tikzmarkb}[3]{\tikz[remember picture,baseline,inner sep=0pt] \node[anchor=text](#2)
{$#1#3$};}

\newcommand{\strikeout}[1]{%
\ifmmode%
\tikz[inner sep=0.5pt,baseline] \node [strike out,draw=OrangeRed,anchor=text]{${}#1{}$};%
\else%
\tikz[inner sep=0.5pt,baseline] \node [strike out,draw=OrangeRed,anchor=text]{#1};%
\fi%
}

\begin{document}
$\dfrac{x^2\times 10^3} {x^2\strikeout{\times 10^3}}$

\bigskip

$\dfrac{x^2\times 10^3} {x^2\mathbin{\tikzmarkb{}{matha}\times} 10^{\tikzmarkb\scriptstyle{mathb}3}}$
\tikz[remember picture, overlay,OrangeRed,baseline]
{\draw[anchor=text] (matha.south west) --
(mathb.north east);}
\end{document}

• Thanks this seems to solve the problem. Didn't think the use of { } would solve the issue. – azetina Mar 18 '13 at 21:23
• @azetina oh no, you took the {} in strikeout version! I could have answered that in 2 seconds, I slaved for hours (well minutes:-) on the tikz code for the second example:-) – David Carlisle Mar 18 '13 at 21:25
• Yeah I know right. I definitely am going to use the second example as well since it allows me to be more flexible with shapes etc. Its just that the usage of the {} was like straight forward. Thanks by the way for the second example. It was what I was looking for. – azetina Mar 18 '13 at 21:27
• @azetina nice MWE by the way (I wouldn't have a clue how to draw a line in tikz so having running code to start with is a necessary first step:-) – David Carlisle Mar 18 '13 at 21:29
• Hey imagine me struggling with what I want to achieve and not getting it. I appreciate it a lot and that is because I use tikz for diagrams just that sometimes I tend to get stuck with nodes and anchors. – azetina Mar 18 '13 at 21:32