0

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.

4
  • 1
    Welcome to TeX.SE! Your question is unclear for me, can you please explain better, for example with a scetch of what you want?
    – Mensch
    Commented Aug 10, 2023 at 22:14
  • Short answer: no (not with OCGs). Commented Aug 11, 2023 at 5:28
  • Dear @paul-gaborit, I have updated my question with a working example to better show what I have in mind.
    – Nemo
    Commented Aug 11, 2023 at 7:42
  • Dear @mensch, I have updated my question with a working example to better show what I have in mind.
    – Nemo
    Commented Aug 11, 2023 at 7:56

1 Answer 1

1

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}
4
  • Hi @alexg, as a proof of concept, I like the \foreach loop because it makes your code easear to write/mantain/understand. Although your code is better then mine because it does not select text when the mouse is down, like mine it does not work when the mouse is over and down simultaneously. As users are likely to use mouse over and down simultaneously, is that problem fixable?
    – Nemo
    Commented Aug 11, 2023 at 13:54
  • I think this does not work, as no mouseenter nor any other of the possible events is fired by AR while the mouse button is down.
    – AlexG
    Commented Aug 11, 2023 at 14:18
  • Hi @alexg, is there a way of putting the result of the command \foreach \i in {X,A,B,C,X,A,B,C,X,A,B,C} {\showocg[onmouseenter]{\i}{\framebox[0.05\linewidth]{\i}}} on top of the images but at the bottom?
    – Nemo
    Commented Aug 11, 2023 at 17:29
  • Just move the code above the image block. Should work.
    – AlexG
    Commented Aug 11, 2023 at 19:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .