TikZ/PGF – Creating a Working Slider in LaTeX with TikZ and ocgx2

ocgx2tikz-pgf

Is there a way of creating an interactive slider by using TikZ and ocgx2 like this?

  1. Multiple instances of \actionsocg[onmouseall]{}{convenient code}{convenient code}{convenient space} are put side by side on top of a TikZ slider, for instance, one of those found here.
  2. As the user moves the mouse across those links, ocgx2 moves slider's button and moves a point along a parabola built in TikZ.

Edit: I realize that the explanation was not sufficiently clear so I decided to modify this example to better show what I have in mind with a working example.

\documentclass{article}
\usepackage{mwe}
\usepackage{ocgx2}

\begin{document}

\begin{figure}\centering \makebox[0pt][l]{% \begin{ocg}{A}{A}{1}% \includegraphics[width=0.3\paperwidth]{example-image-a}% \end{ocg}% }% \makebox[0pt][l]{% \begin{ocg}{B}{B}{0}% \includegraphics[width=0.3\paperwidth]{example-image-b}% \end{ocg}% }% \begin{ocg}{C}{C}{0}% \includegraphics[width=0.3\paperwidth]{example-image-c}% \end{ocg}

\actionsocg[onmouseall]{}{A,,,}{B C}{\fbox{A}} \actionsocg[onmouseall]{}{B,,,}{A C}{\fbox{B}} \actionsocg[onmouseall]{}{C,,,}{A B}{\fbox{C}} \caption{``Slider'' with three sections} \end{figure}

\end{document}

Imagine the boxes A B C as being sections of a slider. Moving the mouse over the boxes A B C it works like a slider. Now imagine the boxes A B C as being transparent and behind them, we also see convenient images of a slider.

Best Answer

Adding all OCGs (PDF layers) to a common radio button group simplifies the code, esp. when using a lot of slider increments which result in a lot of OCGs.

With a radio button group, simple \showocg can be applied on a single OCG, as hiding of the previously visible OCG is automatic.

The onmouseenter trigger used in both, OP and this answer, only works in Acrobat Reader.

\documentclass[a5paper]{article}

\usepackage{graphicx}
\usepackage{ocgx2}
\usepackage{pgffor}

\begin{document}

\begin{figure}
\centering  
\makebox[0pt][l]{%
  \begin{ocg}[radiobtngrp=sliderEx]{X}{X}{1}%
\includegraphics[width=0.6\linewidth]{example-image}%
\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=sliderEx]{A}{A}{0}%
\includegraphics[width=0.6\linewidth]{example-image-a}%
\end{ocg}%
}%
\makebox[0pt][l]{%
\begin{ocg}[radiobtngrp=sliderEx]{B}{B}{0}%
\includegraphics[width=0.6\linewidth]{example-image-b}%
\end{ocg}%
}%
\begin{ocg}[radiobtngrp=sliderEx]{C}{C}{0}%
\includegraphics[width=0.6\linewidth]{example-image-c}%
\end{ocg}

\foreach \i in {X,A,B,C,X,A,B,C,X,A,B,C} {%
  \showocg[onmouseenter]{\i}{\framebox[0.05\linewidth]{\i}}%
}  
\end{figure}

\end{document}
Related Question