Based on this question: How to draw arrows between parts of an equation to show the Math Distributive Property (Multiplication)? I got some nice tools for illustrating to my students how to find the product of a number or a variable and a parenthesis.
However, the solution fails when I should have two sources in one line, for instance when expanding (a+3)(b+4)
. I would also be able to place a small number next to or above the arrowhead to indicate the first calculation, the second, etc. The second set of arrows could just as well go below the expression, not above it, to simplify things.
I could of course define myself a new set of macros similar to the existing ones, for instance \sourceTwo
and \targetTwo
, but it feels like this could be done more elegant.
MWE:
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand\source[1]{%
\tikz[remember picture,baseline,inner sep=0pt] {%
\node [name=source,anchor=base]{$#1$};
}%
\setcounter{target}{0}
}
\newcounter{target}
\newcommand\target[1]{%
\tikz[remember picture,baseline,inner sep=0pt] {%
\node [name=target-\thetarget,anchor=base]{$#1$};
}%
\stepcounter{target}%
}
\newcommand\drawarrows{
\tikz[remember picture, overlay, bend left=45, -latex] {
\foreach \i [evaluate=\i as \n using int(\i-1)] in {1,...,\thetarget} {
\draw (source.north) to (target-\n.north);
}
}
}
\begin{document}
\begin{equation}
(\source{a}+4)(\target{b}+\target{3}) = \drawarrows
\end{equation}
\end{document}
Best Answer
The following code maybe a starting point for you:
Output:
Update: Labeling each arrow:
and the output: