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?

1 Answer 1

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}

You must log in to answer this question.

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