我使用了自定义命令\myref
(来自上一个问题这里) 允许我在超链接的引用前添加单词,例如 Equation。不幸的是,与 一起使用时似乎不太好用\usepackage{showkeys}
,尤其是当标签包含数学符号(比如下划线)时。
是否有可能修复代码,使它们能够很好地协同工作?
妇女权利委员会:
\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}
答案1
只需改变调用的顺序(hyperref
应该是最后一个被调用的包!)
梅威瑟:
\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}
结果: