I would like to implement something akin to the following in LaTeX, perhaps in tikz. I would be very grateful for any help.
5 Answers
Here's a tikz solution:
\documentclass[border=10pt]{standalone}
\usepackage{tikz,amsmath}
\newcommand\tikzmark[2][]{
\tikz[remember picture,inner sep=0,outer sep=0,baseline=(#1.base)]{\node(#1){$#2$};}
}
\newlength{\bubblesize}
\setlength{\bubblesize}{6pt}
\begin{document}
$ \dfrac{\tikzmark[topleft]{3}}{\tikzmark[bottomleft]{4}} =
\dfrac{\tikzmark[topright]{x}}{\tikzmark[bottomright]{10}} $
\begin{tikzpicture} [remember picture,overlay]
\foreach \fracpart in {topleft,topright,bottomleft,bottomright}{
\begin{scope}[shift=(\fracpart)]
\coordinate (a\fracpart) at (60:\bubblesize);
\coordinate (b\fracpart) at (240:\bubblesize);
\coordinate (c\fracpart) at (120:\bubblesize);
\coordinate (d\fracpart) at (300:\bubblesize);
\end{scope}
}
\draw [black!20] (abottomright) arc (60:-120:\bubblesize) -- (btopleft) arc (240:60:\bubblesize) -- cycle;
\draw [black!20] (cbottomleft) arc (120:300:\bubblesize) -- (dtopright) arc (-60:120:\bubblesize) -- cycle;
\end{tikzpicture}
\end{document}
This method uses highlight rather than drawing borders (because I don't know how to get a transparent color for double
:/)
Code
\documentclass{article}
\usepackage{tikz,amsmath}
\newcommand\tikzmark[2][]{
\tikz[remember picture,inner sep=0,outer sep=0,baseline=(#1.base)]{\node(#1){$#2$};}
}
\tikzset{
crossmult/.style={double distance=9pt,line cap=round,opacity=.1,shorten >=3pt,shorten <=3pt,#1}
}
\begin{document}
\[
\frac{\tikzmark[a]{3}}{\tikzmark[b]{4}}
=
\frac{\tikzmark[c]{x}}{\tikzmark[d]{10}}
\]
\tikz[remember picture,overlay]{
\draw[crossmult=red](a.north west)--(d.south east);
\draw[crossmult=green](b.south west)--(c.north east);
}
\end{document}
Output
Update it works better with fewer control points
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}
\begin{document}
\Large
\[
\frac{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (A){$3$};}}
{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (B){$4$};}}
=
\frac{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (C){$x$};}}
{\tikz[remember picture,inner sep=1pt, outer sep=0pt]{\node (D){$10$};}}
\]
\begin{tikzpicture}[remember picture, overlay]
\draw[draw=red](A.north west)
to[closed,curve through={ (A.south west) .. (D.south west) ..
(D.south east) .. (D.north east) .. (A.north east)
}](A.north west);
\draw[draw=green](C.north east)
to[closed,curve through={(C.south east) .. (B.south east) .. (B.south west) ..
(B.north west) .. (C.north west)
}](C.north east);
\end{tikzpicture}
\end{document}
I fear I haven't got the control points quite right (it's what comes of stealing code you don't understand from random answers on this site:-) , but something like
Updated with more symmetric use of code points.
\documentclass{article}
\usepackage{amsmath,cancel}
\usepackage{tikz}
%\usetikzlibrary{fit,shapes.geometric}
%\usetikzlibrary{tikzmark}
\usetikzlibrary{shapes.geometric} % required for the ellipse shape
\usetikzlibrary{arrows, backgrounds, calc, hobby, positioning}
\makeatletter
\begin{document}
\Large
\[
\frac{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (A){$3$};}}
{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (B){$4$};}}
=
\frac{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (C){$x$};}}
{\tikz[remember picture,inner sep=0pt, outer sep=0pt]{\node (D){$10$};}}
\]
\vspace*{-1.32cm}\hspace*{4.75cm}%I guess I shouldn't need this
\begin{tikzpicture}[]
\draw[draw=red](A.north)
to[closed,curve through={(A.north west) .. (A.west) .. (A.south west)
.. (D.south west) ..
(D.south)..(D.south east) ..(D.east) .. (D.north east) .. (A.north east)
}](A.north);
\draw[draw=green](C.north)
to[closed,curve through={(C.north east).. (C.east) .. (C.south east)
.. (B.south east) .. (B.south) .. (B.south west) ..
(B.west)..(B.north west) .. (C.north west)
}](C.north);
\end{tikzpicture}
\end{document}
-
-
was the artistic quality of the result consciously implemented in the code?– user4686Nov 29, 2013 at 16:29
-
1There are now two artistic examples you can submit to the 2014 TUG's Calendar. Great job.– ManuelNov 29, 2013 at 16:48
-
A pstricks
approach (requiring LaTeX or XeLaTeX):
\documentclass{article}
\usepackage{pst-node,xcolor}% http://tug.org/PSTricks/main.cgi/
\begin{document}
\[
\frac{\Rnode{lt}{3}}{\Rnode{lb}{4}} = \frac{\Rnode{rt}{x}}{\Rnode{rb}{10}}
\]
%\ncline{->}{lt}{rb}\ncline{->}{lb}{rt} Arrows
\psset{nodesep=2pt,boxsize=.2,linearc=.2,linewidth=.5pt,linecolor=black!20,linestyle=dashed}% Boxes
\ncbox{lt}{rb}\ncbox{lb}{rt}
\end{document}
Here is another version:
\documentclass{article}
\usepackage{pst-node}% http://tug.org/PSTricks/main.cgi/
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\begin{document}
\psset{boxsize=.2,linewidth=.5pt,linecolor=black!30,fillstyle=solid,fillcolor=black!15}% Boxes
\[
\frac{\Rnode{lt}{\psframebox{3}}}{\Rnode{lb}{\psframebox{4}}} \rnode{eq}{\phantom{=}} \frac{\Rnode{rt}{\psframebox{x}}}{\Rnode{rb}{\psframebox{10}}}
\]
\psset{angleA=0,angleB=180,fillstyle=none}
\nccurve{->}{lt}{rb}\nccurve{->}{lb}{rt}\rput(eq){=}
\end{document}
-
-
1Honestly, to me it looks like two infinite symbols that happen to be there for no clear reason... Nov 30, 2013 at 3:41
The following requires two runs. I know its not what you really asked for but it can help somehow. I think.....
\documentclass[dvipsnames]{article}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[inner xsep=0pt,outer sep=0pt] (#1) {};}
%-------------- Cross Multiply Commands ---------------------------------------------
\newcommand{\crossmultiplynd}[2]{%
\tikz[remember picture, overlay]{
\draw[OrangeRed,thick,<-,shorten <=0pt]
(#1.east) -- (#2.north west);}}
\newcommand{\crossmultiplydn}[2]{%
\tikz[remember picture, overlay]{
\draw[Cerulean,thick,->,shorten >=0pt]
(#1.north east) -- (#2.west);}}
%------------------------------------------------------------------------------------
\begin{document}
\[
\dfrac{a \tikzmark{a}}{b\tikzmark{b}}=\dfrac{\tikzmark{c}c}{\tikzmark{d}d}
\crossmultiplynd{a}{d}
\crossmultiplydn{b}{c}
\]
\end{document}