2

Recently, @marmot in Need help to create a more flexible \cancel command that works inside an align environment suggested the use of the \tikzmarknode command of the last version (1.6) of the tikzmark package to do the same job as the \cancel command of the cancel package. I tried to figure out a similar way to implement the \cancelto command, but without success.

As I understood, the whole expression being cancelled is turned into a node by the \tikzmarknode command, and a line is drawn from the south west corner of the path picture (node) to its north east corner. I can transform the line into an arrow, but I am unable to show the value to cancel to in the upper right side of the north east corner because it is outside of the bounding box.

I also tried the solutions in https://tex.stackexchange.com/a/218486/95438 and https://tex.stackexchange.com/a/234601/95438, but the former is not typeset correctly, and the last one, despite being exactly what I wanted, looses its equation number.

How could I obtain the same typeset of this last try but using the tikzmark package so as to not loose the equation number?

Thank you for any help!

\documentclass[mainlanguage=english,babel={main=english,french,brazil},sepcorpaffilfrench={,~},sepcorpaffilenglish={,~},version=inprogress]{yathesis}
%\documentclass{book}
%\documentclass{article}
%
% If using XeLaTex or LuaLaTex
%\usepackage{fontspec}
%
% If using LaTex or PdfLaTex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
\usepackage{lmodern} % latin modern font
\usepackage{amsmath}
\usepackage{cancel} % draw diagonal lines  ("cancelling" a term)
%
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{cancel/.style={path picture={
            \draw[#1] (path picture bounding box.south west) -- (path picture bounding box.north east);
}}}
%
%%% My try
\tikzset{cancelto/.style={path picture={
            \draw[#1,->,-latex] (path picture bounding box.south west) -- (path picture bounding box.north east) node[anchor=south west] at (path picture bounding box.north east) {1};
}}}
%
%%% From https://tex.stackexchange.com/a/218486/95438
\tikzset{
    main node/.style={inner sep=0,outer sep=0},
    label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
    strike out/.style={shorten <=.2em,shorten >=.5em,overlay}
}
\newcommand{\cancelt}[3][]{\tikz[baseline=(N.base)]{
        \node[main node](N){$#2$};
        \node[label node,#1, anchor=south west] at (N.north east){$#3$};
        \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
%
%%% From https://tex.stackexchange.com/a/234601/95438
\tikzset{block/.style = {anchor = center, inner sep = 0pt,
        execute at begin node={\begin{varwidth}{1.5\linewidth}},  %% change 0.5 as you wish
            execute at end node={\end{varwidth}}
    }
}
\usepackage{relsize}
\usetikzlibrary{calc}
\newcommand\canceltoSwNe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
    \node[block] (B) {#1};
    \draw[arrows = {}-{latex}]%
    ($(B.south west)+(-1pt, -1pt)$) -- ($(B.north east)+(+4pt, +1pt)$)%
    node [anchor = south west, xshift = +1pt, yshift = -1pt,%
    inner sep = 0pt]%
    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}
%
\begin{document}
    \begin{align}
    \begin{split}
    &= \mp \cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\pm \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\mp \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \mp \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \tikzmarknode[cancelto]{cc}{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \cancelt{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \canceltoSwNe{\[\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    &= \mp \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{align}
\end{document}

Output:

enter image description here

1

Path pictures have the property to just clip away everything that runs outside their bounding boxes, otherwise your approach would have worked. But it is easy to make it work.

\documentclass[mainlanguage=english,babel={main=english,french,brazil},sepcorpaffilfrench={,~},sepcorpaffilenglish={,~},version=inprogress]{yathesis}
%\documentclass{book}
%\documentclass{article}
%
% If using XeLaTex or LuaLaTex
%\usepackage{fontspec}
%
% If using LaTex or PdfLaTex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
%
\usepackage{lmodern} % latin modern font
\usepackage{amsmath}
\usepackage{cancel} % draw diagonal lines  ("cancelling" a term)
%
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{cancel/.style={path picture={
            \draw[#1] (path picture bounding box.south west) -- (path picture bounding box.north east);
}}}
%
%%% My try
\tikzset{cancelto/.style={path picture={
\node[anchor=north east,font=\small] (aux) at (path picture bounding box.north east) {1};
\draw[#1,-latex] (path picture bounding box.south west) -- (aux);
}}}
%
%%% From https://tex.stackexchange.com/a/218486/95438
\tikzset{
    main node/.style={inner sep=0,outer sep=0},
    label node/.style={inner sep=0,outer ysep=.2em,outer xsep=.4em,font=\scriptsize,overlay},
    strike out/.style={shorten <=.2em,shorten >=.5em,overlay}
}
\newcommand{\cancelt}[3][]{\tikz[baseline=(N.base)]{
        \node[main node](N){$#2$};
        \node[label node,#1, anchor=south west] at (N.north east){$#3$};
        \draw[strike out,-latex,#1]  (N.south west) -- (N.north east);
}}
%
%%% From https://tex.stackexchange.com/a/234601/95438
\tikzset{block/.style = {anchor = center, inner sep = 0pt,
        execute at begin node={\begin{varwidth}{1.5\linewidth}},  %% change 0.5 as you wish
            execute at end node={\end{varwidth}}
    }
}
\usepackage{relsize}
\usetikzlibrary{calc}
\newcommand\canceltoSwNe[2]{%
    \begin{tikzpicture}[baseline = (B.base)]
    \node[block] (B) {#1};
    \draw[arrows = {}-{latex}]%
    ($(B.south west)+(-1pt, -1pt)$) -- ($(B.north east)+(+4pt, +1pt)$)%
    node [anchor = south west, xshift = +1pt, yshift = -1pt,%
    inner sep = 0pt]%
    {\smaller\smaller{#2}};
    \end{tikzpicture}%
}
%
\begin{document}
    \begin{align}
    \begin{split}
    &= \mp \cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\pm \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \tikzmarknode[cancel]{cc}{\mp \frac{1}{2} \sin \left[ 4\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \cos \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau} \\
    &\mathrel{\phantom{=}} \mp \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \tikzmarknode[cancelto]{cc}{\cos^{2} \left[ 2\pi\left( 
    \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[
    2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\,~} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \cancelt{\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    \begin{split}
    &= \mp \left\lbrace \canceltoSwNe{\[\cos^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right] + \sin^{2} \left[ 2\pi\left(  \frac{k}{2}t^{2} + f_{1}t + \varphi\right)\right]\]}{1} \right\rbrace \\
    &\mathrel{\phantom{=}} \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{split} \\
    &= \mp \int_{0}^{t} s_{i}\left( \tau\right) \sin \left[ 2\pi\left( kt + f_{1}\right)\tau\right] \, d\tau
    \end{align}
\end{document}

enter image description here

BTW, in your question you are now using the macros/methods of two different answers, so it is very hard for anyone who is not familiar with the previous posts to answer your question. Therefore, I'd like to kindly ask you to cut down future questions to the minimal amount such that more users are encouraged to answer them, and you get quicker and better answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.