5

I am trying to define a style to help my pupils understand the resolution of equations. Nevertheless, I have two problems :

1 : I cannot make arrows of grey color between the steps of the resolution. 2 : How can I use this style intelligently to add steps to the resolution ?

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes}
\begin{document}

\tikzset{
    eq/.style={minimum width=3cm,rectangle},
    bubble/.style={draw,help lines,ellipse},
}

%%%%%%%%%%%%%%%%%%%% What I would like to automate %%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
    \node[eq]   (first) {$e=mc^2$};
    \node[bubble]   (left)  [below left=of first] {$\times 2$};
    \node[bubble]   (right) [below right=of first] {$\times 2$};
    \node[eq] (second) [below right=of left] {$2e=2mc^2$};
    \draw[help lines] (first.west) to [out=180,in=90] (left.north);
    \draw[help lines] (first.east) to [out=0,in=95] (right.north);
    \draw[->,help lines] (left.south) to [out=-90,in=180] (second.west);
    \draw[->,help lines] (right.south) to [out=-90,in=0] (second.east);

    \node[bubble]   (lleft) [below left=of second] {$-1$};
    \node[bubble]   (rright) [below right=of second] {$-1$};
    \node[eq] (third) [below right=of lleft] {$2e-1=2mc^2-1$};
    \draw[help lines] (second.west) to [out=180,in=90] (lleft.north);
    \draw[help lines] (second.east) to [out=0,in=95] (rright.north);
    \draw[->,help lines] (lleft.south) to [out=-90,in=180] (third.west);
    \draw[->,help lines] (rright.south) to [out=-90,in=0] (third.east);

\end{tikzpicture}

\vspace{1cm}

%%%%%%%%%%%%%%%%%%%% Intent of automation %%%%%%%%%%%%%%%%%%%%
\tikzset{%
    nexteq/.style n args={2}{%
        append after command={
            \pgfextra{\let\mainnode=\tikzlastnode}
            node[bubble]    (left) [below left=of \mainnode] {#1}
            node[bubble]    (right) [below right=of \mainnode] {#1}
            node[eq] (second) [below right=of left] {#2}
            (\mainnode.west) to [out=180,in=90] (left)
            (\mainnode.east) to [out=0,in=95] (right.north)
            (left.south) to [out=-90,in=180] (second.west)
            (right.south) to [out=-90,in=0] (second.east)
        },
    }
}

\begin{tikzpicture}
\draw node(first) [eq,nexteq={$\times 2$}{$2e=2mc^2$}] {$e=mc2$};
\end{tikzpicture}

\end{document}
2
  • Please do not use minimal for examples - it is not intended for the purpose and causes seemingly mysterious problems.
    – cfr
    Aug 28, 2015 at 16:13
  • You can use edge[help lines,out=180,in=90] instead of to paths
    – percusse
    Aug 29, 2015 at 7:12

2 Answers 2

2

I found tikz-cd surprisingly suited in this case.

\documentclass[tikz,border=9]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric}
\begin{document}

%%%%%%%%%%%%%%%%%%%% What YOU would like to automate %%%%%%%%%%%%%%%%%%%%
\begin{tikzcd}[row sep=30]
    ax^2+bx+c=0
                                                             \dar[bend left=80][description,ellipse,draw]{\div a} \\
    x^2+\frac bax+\frac ca=0
                                                             \dar[bend left=80][description,ellipse,draw]{+\frac{b^2}{4a^2}-\frac ca} \\
    x^2+\frac bax+\frac{b^2}{4a^2}=\frac{b^2}{4a^2}-\frac ca
                                                             \dar[bend left=80][description,ellipse,draw]{=} \\
    \left(x+\frac b{2a}\right)^2=\frac{b^2}{4a^2}-\frac ca
                                                             \dar[bend left=80][description,ellipse,draw]{\sqrt{~}} \\
    x+\frac b{2a}=\sqrt{\frac{b^2}{4a^2}-\frac ca}
                                                             \dar[bend left=80][description,ellipse,draw]{-\frac b{2a}} \\
    x=-\frac b{2a}+\sqrt{\frac{b^2}{4a^2}-\frac ca}
                                                             \dar[bend left=80][description,ellipse,draw]{=} \\
    x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{tikzcd}

%%%%%%%%%%%%%%%%%%%% Intent of automation %%%%%%%%%%%%%%%%%%%%
\def\dear#1{\dar[bend left=80][description,ellipse,draw]{#1}}
\begin{tikzcd}[row sep=30]
    ax^2+bx+c=0
                                                             \dear{\div a}\\
    x^2+\frac bax+\frac ca=0 
                                                             \dear{+\frac{b^2}{4a^2}-\frac ca} \\
    x^2+\frac bax+\frac{b^2}{4a^2}=\frac{b^2}{4a^2}-\frac ca
                                                             \dear{=} \\
    \left(x+\frac b{2a}\right)^2=\frac{b^2}{4a^2}-\frac ca 
                                                             \dear{\sqrt{~}} \\
    x+\frac b{2a}=\pm\sqrt{\frac{b^2}{4a^2}-\frac ca}
                                                             \dear{-\frac b{2a}} \\
    x=-\frac b{2a}\pm\sqrt{\frac{b^2}{4a^2}-\frac ca}
                                                             \dear{=} \\
    x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{tikzcd}

\end{document}

2

Another approach, here nodes are named 0,1,...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes}

\newcounter{i}
\setcounter{i}{0}

\tikzset{
    eq/.style={minimum width=3cm,rectangle,name=\thei},
    bubble/.style={draw,help lines,ellipse}}
\begin{document}

\def\step#1#2{%
    \node[bubble]   (left)  [below left=of \thei] {#1};
    \node[bubble]   (right) [below right=of \thei] {#1};
    \draw[help lines] (\thei .west) to [out=180,in=90] (left.north);
    \draw[help lines] (\thei .east) to [out=0,in=95] (right.north);
    \stepcounter{i}
    \node[eq] [below right=of left] {#2};
    \draw[->,help lines] (left.south) to [out=-90,in=180] (\thei .west);
    \draw[->,help lines] (right.south) to [out=-90,in=0] (\thei .east);
    }


\begin{tikzpicture}
\node[eq]{$ax+b=c$};
\step{$-b$}{$ax=c-b$}
\step{$\div a$}{$x=\frac{c-b}{a}$}
\end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .