4

I would like to annotate an equation inside a tikzpicture, and am trying to use subnode from the tikzmark library for this purpose. The problem is that wrapping math in subnode does not maintain the intended font size:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{tikzpicture}[remember picture]
\node[align=left] {$A_A$ (no subnode) \\
                   $\subnode{n1}{$A$}_{\subnode{n2}{$A$}}$ (with subnode)};
\draw[<-] (n2) -- ++(0,-5mm);
\end{tikzpicture}

\end{document}

Screenshot of compiled example

This example shows subscript but other math commands such as frac are also affected.

How can I make the annotated equation match the unannotated one, using either subnode or some other command?

  • 1
    In the very latest version of tikzmark, which is on github but not yet on CTAN, I've made \subnode to be math-aware in that it ought to select the correct math level. Since \subnode is the right thing to use here, if you care to test it and let me know if it works then that would be really useful. – Andrew Stacey Dec 8 '18 at 22:57
3

Disclaimer: I have not much experience with subnode. Nor do I know if the following proposal is absolutely safe. I really hope @LoopSpace will tell us what one is really supposed to do here. I guess you want to read this answer carefully.

Meanwhile, this is just to report that the rather new addition to the already very nice tikzmark library \tikzmarknode makes this amazing library even more powerful. And at least in this case it seems to work.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{tikzpicture}[remember picture]
\node[align=left] {$A_A$ (no subnode) \\
                   $\tikzmarknode{n1}{A}_{\tikzmarknode{n2}{A}}$ (with tikzmarknode)};
\draw[<-] (n2) -- ++(0,-5mm);
\end{tikzpicture}

\end{document}

enter image description here

  • That is a great new command, thanks! It looks like it requires tikzmark 1.6 released just a few weeks ago (not good for overleaf and my colleagues' machines), but I providecommand-ed the definition into my document and it works. – Lack Nov 11 '18 at 19:07
  • In the very latest version (on github), I've made subnode math-aware in the same fashion as tikzmarknode. If you get a chance to test it, that would be amazing (and definitely worth the reputation! - I saw your comment on meta and was highly amused). – Andrew Stacey Dec 8 '18 at 22:59
  • 1
    Just to say, that as \tikzmarknode starts its own tikz environment, it shouldn't be used inside a node. The all-new math-aware \subnode command now fixes this. – Andrew Stacey May 11 '19 at 20:32
4

The latest version of tikzmark is now available on ctan and is now in TeXLive. This has the new math-aware version of \subnode in it which will match the surrounding math mode for its contents. Your original code will work except that you shift into math mode inside the \subnode which you shouldn't do as \subnode now takes care of that itself.

\documentclass{standalone}
%\url{https://tex.stackexchange.com/q/459497/86}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\begin{tikzpicture}[remember picture]
\node[align=left] {\(A_A\) (no subnode) \\
                   \(\subnode{n1}{A}_{\subnode{n2}{A}}\) (with subnode)};
\draw[<-] (n2) -- ++(0,-5mm);
\end{tikzpicture}

\end{document}

all new math-aware subnode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.