# How to create arrows which can be hidden/visible and are overlaid on the text?

In the microtype manual on page 17, they have used multiple arrows which become visible when you click on some keywords. These arrows link to a figure and some portions of main text. What packages were used to create this?

After some search I became aware that ocgx has capability of hiding/showing objects based on a clickable switch. Using ocgx could create simple objects which could be hidden and were non-overlapping. The MWE below hides and shows the two triangles and the arrows.

But what I want is for these to be overlapping, like in the microtype manual. The arrows should be in the top layer and are not hidden by the text and that they are able to traverse the text. Any suggestions of how this could be achieved or what other packages might produce similar results?

\documentclass{article}
\usepackage{ocgx}
\usepackage{tikz}

\begin{document}
The Two triangles

\begin{ocg}{OCG 2}{ocg3}{0}
\begin{tikzpicture}
\path[draw,line width=4pt,red] (1,1) -- (2,2)--(3,1)--cycle;
\end{tikzpicture}
\end{ocg}

\begin{ocg}{OCG 2}{ocg2}{0}
\begin{tikzpicture}
\path[draw,line width=4pt] (1,1) -- (2,2)--(3,1)--cycle;
\end{tikzpicture}
\end{ocg}

\begin{ocg}{OCG 2}{ocg4}{0}
\tikz \draw[-latex,red] (0,-1) node {} -- (2,2);
\end{ocg}

\begin{ocg}{OCG 2}{ocg5}{0}
\tikz \draw[-latex] (1,1) node {} -- (2,2);
\end{ocg}

\switchocg{ocg2}{Black Triangle}
\switchocg{ocg3}{Red Triangle}
\switchocg{ocg4}{Red Arrow}
\switchocg{ocg5}{Black Arrow}


\end{document}

Are you by chance looking for the overlay and remember picture keys, and the tikzmark library?

\documentclass{article}
\usepackage[tikz]{ocgx2}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
\tikzmarknode{H}{Hello} \tikzmarknode{w}{world!} \tikzmarknode{A}{And}
\tikzmarknode{f}{fellow} \tikzmarknode{c}{cats}!

\begin{ocg}{OCG 2}{ocg2}{0}
\begin{tikzpicture}[overlay,remember picture]
\draw[red,thick] (H) to[out=45,in=135] (w);
\end{tikzpicture}
\end{ocg}

\begin{ocg}{OCG 2}{ocg3}{0}
\begin{tikzpicture}[overlay,remember picture]
\draw[blue,thick] (H) to[out=-45,in=-135] (w);
\end{tikzpicture}
\end{ocg}

\begin{ocg}{OCG 2}{ocg4}{0}
\begin{tikzpicture}[overlay,remember picture]
\draw[red,thick] (A) to[out=45,in=-135] (c);
\end{tikzpicture}
\end{ocg}

\begin{ocg}{OCG 2}{ocg5}{0}
\begin{tikzpicture}[overlay,remember picture]
\draw[blue,thick] (A) to[out=-45,in=135] (c);
\end{tikzpicture}
\end{ocg}

\switchocg{ocg2}{upper}
\switchocg{ocg3}{lower}
\switchocg{ocg4}{upper 2}
\switchocg{ocg5}{lower 2}
\end{document}


Click on upper to get

Click on lower to get

Click on upper 2 to get

And so on.

You can use this in many ways.

\documentclass{article}
\usepackage[tikz]{ocgx2}
\usepackage{tikz}
\usepackage{tikzlings}
\usetikzlibrary{tikzmark,calc}

\begin{document}
Hello \switchocg{ocg1}{\tikzmarknode{c}{cats}},
\switchocg{ocg2}{\tikzmarknode{k}{koalas}} and
\switchocg{ocg3}{\tikzmarknode{m}{marmots}}!

\begin{ocg}{OCG 2}{ocg1}{0}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}[shift={($(c)+(-1,1)$)},local bounding box=cat]
\cat[eyes=green]
\end{scope}
\draw[thick,-latex] (cat) to[bend right] (c);
\end{tikzpicture}
\end{ocg}
\begin{ocg}{OCG 2}{ocg2}{0}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}[shift={($(c)+(0,-3)$)},local bounding box=koala]
\koala[blush]
\end{scope}
\draw[thick,-latex] (koala) to[bend right] (k);
\end{tikzpicture}
\end{ocg}
\begin{ocg}{OCG 2}{ocg3}{0}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}[shift={($(m)+(1,1)$)},local bounding box=marmot]
\marmot[whiskers,teeth]
\end{scope}
\draw[thick,-latex] (marmot) to[bend right] (m);
\end{tikzpicture}
\end{ocg}
\end{document}


Try out what happens when you click on the names of the beings. (Of course, you need acrobat reader.)