2

In the simple example below, a reference inside varwidth environment fails due to hyperref package loaded with option ocgcolorlinks. Ading ocgx2 (with the same option) makes this even worse.

\documentclass{article}

\usepackage{varwidth}
\usepackage[ocgcolorlinks]{hyperref}
%\usepackage[ocgcolorlinks]{ocgx2}

\begin{document}
    \section{A section} \label{sec}

    A reference outside \texttt{varwidth}: sec.~\ref{sec}.

    \noindent
    \begin{varwidth}{\textwidth}
        A reference \hphantom{outside }\llap{inside} \texttt{varwidth}: sec.~\ref{sec}.
    \end{varwidth}
\end{document}

Output

Can anybody provide a fix which would allow the usage of ref/href/cref/… inside varwidth environment without disabling ocgcolorlinks option of hyperref or ocgx2?

3

You could try to locally restore \pdfliteral to the original definition (varwidth redefines it):

\documentclass{article}
\usepackage{varwidth}
\usepackage{hyperref}
\usepackage[ocgcolorlinks]{ocgx2}

\begin{document}
    \section{A section} \label{sec}

    A reference outside \texttt{varwidth}: sec.~\ref{sec}.

    \makeatletter
    \noindent
    \begin{varwidth}{\textwidth}
        A reference \hphantom{outside }\llap{inside}\texttt{varwidth}: sec.~\mbox{\let\pdfliteral\@@vwid@pdfliteral\ref{sec}}.
    \end{varwidth}
    \makeatother
\end{document}

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.