For questions like this tikzmark is your friend: you can create a mark at the end of the equation and then draw your arrow from inside a \tag
command. For example, one way to automate this is with:
\newcommand\Tag[1]{%
\tikzmark{mytag}%
\tag{\tikz[remember picture]{%
\draw[overlay, ->](-0.5,0)--(pic cs:mytag)}\Large$#1$}%
}
This command is used as \Tag{\star}
.
In fact, this command is not quite enough as the tag name is not dynamic. My initial thought was to use the equation
counter but this does not work because \tag
does not increment the equation. Instead, let's define a new counter, say Tag
, and then use this for the labels inside \tikzmark
.
This is enough to define the basic command but let's go a little further and add an optional argument for styling the TikZ arrow. It would also be nice to be able to draw these arrows from an equation number, which should be the default. As we already have an optional argument for styling the arrow we can use the \NewDocumentCommand
command from xparse to require a second optional argument that is enclosed by parentheses to replace the equation number with a symbol, such as \star
. That is, \Tag
will draw an arrow from the equation number, \Tag(\star)
will draw from a \star
and then \Tag[red]
and \Tag[red](\star)
, respectively, will colour these arrows red.
With this in place the MWE below produces:
Here is the full code.
\documentclass{article}
\usepackage{amsmath,tikz,xparse}
\usetikzlibrary{tikzmark, arrows.meta}
\usetikzlibrary{decorations.pathmorphing} % for the coil
\newcounter{Tag}
\tikzset{
Tag/.style = {% default styling for the \Tag arrow
arrows=-{LaTeX},
blue
}
}
\NewDocumentCommand\Tag{ O{} d() }{%
\refstepcounter{Tag} % increment Tag counter for unique tags
\tikzmark{tagging \theTag} % create the tikzmark
\tag{\tikz[remember picture,overlay]{% tag equation and point to mark
\draw[Tag, #1](-0.2,0.1)--([shift={(0.2,0.1)}]pic cs:tagging \theTag);}{%
\IfNoValueTF{#2}{\refstepcounter{equation}\theequation}{$#2$}
}%
}%
}
\begin{document}
\begin{align}
A &= x + y - z \Tag \\
&= 5 + (-2) - (-0.3)\Tag[red](\star) \\
&= 3.3 \Tag[orange,decorate,decoration={coil,aspect=0}](\ast)
\end{align}
\end{document}
Note that I have created a Tag
style using \tikzset
to make styling of the arrow easier. By default, LaTeX
arrow tips are used and the arrow is blue. Also, as is always the case when you use tikzmark, you need to compile the document twice before the marks start working.