1

I used a customized command \myref (From a previous question here) that allows me to include in the hyperref link the word, say, Equation, before the reference. Unfortunatly, it does not seems to happy when used with \usepackage{showkeys}, especially when labels contain math symboles like underscores.

Is there a possible fix for the code that would allow then to work nicely together ?

The MWE:

\documentclass[10pt,a4paper]{report}
\usepackage{fontspec}
\usepackage{hyperref}
\usepackage{twoopt}
\hypersetup{colorlinks=true,linkcolor=blue} 

\newcommandtwoopt*{\myref}[3][][]{%
  \hyperref[{#3}]{%
    \ifx\\#1\\%
    \else
      #1~%
    \fi
    \ref*{#3}%
    \ifx\\#2\\%
    \else
      \,#2%
    \fi
  }%
}

\usepackage{showkeys} 
\begin{document}

\begin{equation}
x - 3 = 7
\label{eq:too_complicated}
\end{equation}

\myref[Equation]{eq:too_complicated} is so complicated that it does not admit any analytical solution.

\end{document}
HcN
  • 1,274
  • 9
  • 25

1 Answers1

3

Just change the order of the calls (hyperrefshould be the last package to be called!)

MWE:

\documentclass[10pt,a4paper]{report}
\usepackage{fontspec}
\usepackage{showkeys} % <========================================
\usepackage{twoopt}   % <========================================
\usepackage{hyperref}
%\usepackage{twoopt}  % <========================================
\hypersetup{colorlinks=true,linkcolor=blue} 

\newcommandtwoopt*{\myref}[3][][]{%
  \hyperref[{#3}]{%
    \ifx\\#1\\%
    \else
      #1~%
    \fi
    \ref*{#3}%
    \ifx\\#2\\%
    \else
      \,#2%
    \fi
  }%
}


\begin{document}

\begin{equation}
x - 3 = 7
\label{eq:too_complicated}
\end{equation}

\myref[Equation]{eq:too_complicated} is so complicated that it does not admit any analytical solution.

\end{document}

Result:

enter image description here

Mensch
  • 65,388