# Scalebox not working properly inside hyperlinks when using ocgx2 package

I am using hyperlink text formatted with graphicx' \scalebox command with independent factors for horizontal and vertical scaling. When formatting is applied inside hyperref's hyperlinks, the text in resulting PDF is still present in the PDF (may be copied), but became invisible (and also cause further problems when other packages are added that would use such solution).

The obvious workaround would be to switch to hyperlink used inside formatting command. Unfortunately, in actual document \hyperlinks are generated by other package that forces internal formatting (as described in this answer to the original question that led to identifying the problem). Then, relsize's \textscale command is an alternative, but it does not allow for independent scaling in both dimensions, so it cannot fully relace \scalebox.

When ocgx2 package is not used (or is used without ocgcolorlinks option) the internal formatting works properly.

MWE:

\documentclass{article}

\usepackage{graphicx}
\newcommand{\myfmt}[1]{\scalebox{.8}[.7]{#1}}

\begin{document}

\hypertarget{t1}{Some text}.

\end{document}

• The link is already invisible if one inserts a \pdfsave/\pdfrestore pair (\newcommand{\myfmt}[1]{{#1\pdfsave\pdfrestore}}). Imho this interrupts the path and ocgx can no longer use the text for clipping. I would drop the idea to use scalebox here and try to implement whatever you want to achieve with proper font commands. – Ulrike Fischer Aug 1 '18 at 15:11
• Further experiments indicate that \hyperlink has a problem with graphics in general, not just \scalebox. Even \fbox{...} has problems. – John Kormylo Aug 1 '18 at 16:22

Command \ocglinkprotect{...} defined by ocgx2 was provided for such special cases:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\hypertarget{t1}{Some text}.

%%%%%%%%%%%
%%%%%%%%%%%

\end{document}


Other use-cases:

\hyperlink{t1}{Unformatted link text \ocglinkprotect{\includegraphics[width=1cm]{example-image}} unformatted link text cont'ed}

\hyperlink{t1}{Unformatted link text \ocglinkprotect{\fbox{f-boxed text}} unformatted link text cont'ed}

Note that the text argument of \ocglinkprotect{...} doesn't wrap around line breaks. But this should not be an issue, as such portions of the link text that need protection (\scalebox..., \fbox{...}, \includegraphics{...} etc.) are not breakable anyway.