# Tikzmark, Arrows (Exponents and Bases)

I would like to improve this program. For example, make the arrows more like semi-circles and bring down the words base and exponent. Any suggestions how I can do this from this start/minimal example?

 \documentclass{article}
\usepackage{amsmath} % loaded automatically by beamer
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{>=stealth}

\newcommand{\tikzmark}[3][]{\tikz[overlay,remember picture,baseline] \node
[anchor=base,#1](#2) {#3};}

\begin{document}

\begin{equation*}
\tikzmark[blue]{base}{$b^{\,\,\tikzmark[red]{exponent}{a}}$}
\end{equation*}
\begin{tikzpicture}[overlay, remember picture,node distance =.2cm]
\node[blue] (basedescr) [below right=of base]{base};
\draw[,->,thick] (basedescr.west) to [in=315,out=225] (base.south);
\node[red] (exponentdescr) [above right=of exponent] {exponent};
\draw[->,thick] (exponentdescr.west) to [in=65,out=135] (exponent.north);
\end{tikzpicture}
\end{document}


In your example, you were nesting tikzpictures since you were putting a tikzpicture in the node of another tikzpicture. This is usually not a good idea. Then I replaced \tikzmark, which actually is a well-defined command in the tikzmark package, by a slightly modified version of Torbjørn T.'s \tikznode command. As for the arcs, they can be easily drawn with the arc syntax, and personally I like bent arrow heads better.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta,bending}
\newcommand{\tikznode}[3][]{\relax
\ifmmode%
\tikz[remember picture,baseline=(#2.base),inner sep=0pt]{\node[#1] (#2) {$#3$};}
\else
\tikz[remember picture,baseline=(#2.base),inner sep=0pt]{\node[#1] (#2) {#3};}%
\fi}
\begin{document}

\begin{equation*}
\tikznode[blue]{base}{b}^{\tikznode[red]{exponent}{a}}
\end{equation*}
\begin{tikzpicture}[overlay, remember picture,node distance =.2cm,inner sep=0pt]
\node[blue] (basedescr) [below right=of base]{base};
\draw[-{Stealth[bend]},thick] let  \p1=($(basedescr.west)-(base.south)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in
(basedescr.west) arc(\n1-45:\n1-135:\n2) ;
\node[red] (exponentdescr) [above right=of exponent] {exponent};
\draw[-{Stealth[bend]},thick] let  \p1=($(exponentdescr.west)-(exponent.north)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in  (exponentdescr.west) arc(\n1+45:\n1+135:\n2);
\end{tikzpicture}
\end{document}


1. You have \tikzmark[blue]{base}{$b^{\,\,\tikzmark[red]{exponent}{a}}$}. This expands to \tikz[...]{\node[...]{...\tikz[...]{\node[...]{...};}};}, which is a TikZ picture inside a TikZ picture, aka nested tikzpicture.
2. If you use the below right key, say, you can pass to it two distances separated by and, e.g. below right=2pt and 2mm of base will move the thing only 2pt down but 2mm right. If you want it the basedescr node further up, you may either use negative dimensions, or something like right=2mm of base,yshift=-6pt.

Here is the updated code. There are good chances that you will get a much better answers using LoopSpace's great tikzmark library. which has new commands that are superior to the (nevertheless very nice and useful) \tikznode command by Torbjørn T..

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta,bending}
\newcommand{\tikznode}[3][]{\relax
\ifmmode%
\tikz[remember picture,baseline=(#2.base),inner sep=0pt]{\node[#1] (#2) {$#3$};}
\else
\tikz[remember picture,baseline=(#2.base),inner sep=0pt]{\node[#1] (#2) {#3};}%
\fi}
\begin{document}

\begin{equation*}
\tikznode[blue]{base}{b}^{\tikznode[red]{exponent}{a}}
\end{equation*}
\begin{tikzpicture}[overlay, remember picture,inner sep=0pt]
\node[blue] (basedescr) [below right=2pt and 2mm of base]{base};
\draw[-{Stealth[bend]},thick] let  \p1=($(basedescr.west)-(base.south)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in
(basedescr.west) arc(\n1-45:\n1-135:\n2) ;
\node[red] (exponentdescr) [above right=2pt and 2mm of exponent] {exponent};
\draw[-{Stealth[bend]},thick] let  \p1=($(exponentdescr.west)-(exponent.north)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in  (exponentdescr.west) arc(\n1+45:\n1+135:\n2);
\end{tikzpicture}
\end{document}


• Hello, how can I bring the word 'exponent' down and the word 'base' up. If I can achieve that then I can finish the rest. Not sure how I nested a tikzpicture node within a node? – MathScholar Sep 9 '18 at 19:54
• @MathScholar I addressed your questions in an update of the answer. – user121799 Sep 9 '18 at 20:19

I've just added a version of Torbjørn's \tikznode (which is itself a version of the original \tikzmark) to the tikzmark library. It needs some testing before being sent to CTAN so I'm taking this opportunity to test it. In the meantime, it is available from github. With it, marmot's solution becomes:

\documentclass{article}
%\url{https://tex.stackexchange.com/q/450135/86}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,arrows.meta,bending,tikzmark}

\begin{document}

\begin{equation*}
\tikzmarknode[blue]{base}{b}^{\tikzmarknode[red]{exponent}{a}}
\end{equation*}

\begin{tikzpicture}[overlay, remember picture,node distance =.2cm,inner sep=0pt]
\node[blue] (basedescr) [below right=.5cm of base]{base};
\draw[-{Stealth[bend]},thick,shorten >=2pt] let  \p1=($(basedescr.west)-(base.south)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in
(basedescr.west) arc(\n1-45:\n1-135:\n2) ;
\node[red] (exponentdescr) [above right=.5cm of exponent] {exponent};
\draw[-{Stealth[bend]},thick,shorten >=2pt] let  \p1=($(exponentdescr.west)-(exponent.north)$),
\n1={ifthenelse(\x1>0,atan2(\y1,\x1),atan2(\y1,\x1)-180)},
\n2={veclen(\x1,\y1)/sqrt(2)}
in  (exponentdescr.west) arc(\n1+45:\n1+135:\n2);
\end{tikzpicture}

\end{document}


(I added a little bit of space between the items and their explanations and shortened the arrows as well.)

• @marmot Thanks. It could do with a bit of testing before sending to CTAN so if you know of any other tests please send them my way. – Loop Space Sep 9 '18 at 20:26
• @marmot Not overly sure what's being asked for in that one. And re Torbjørn's answer, I did look at the linked questions from his question but he also links many other answers so I need a bit of time to work through to see which ones are from your answers. – Loop Space Sep 9 '18 at 20:48
• Yes, I know that the search tools on this site are not great. I just posted a fun answer here to try out your great library. It works great. I'm gonna use it a lot when it is official. (My most common use is in beamer presentations, where I attach callouts to symbols that I want to explain. So I guess I will test it with beamer and the aobs library in the near future.) – user121799 Sep 9 '18 at 20:54
• @marmot And I just voted for it. – Loop Space Sep 9 '18 at 20:57
• I'm fine with this method of communication, but if you find it easier then "I hereby promise not to share your email address"! Alternatively, you could use the github issue tracker and link back to questions on this site. – Loop Space Sep 18 '18 at 19:31