cleveref 和自定义 refname

cleveref 和自定义 refname

是否可以cleveref动态自定义可点击链接中的名称?如果您考虑下面的基本示例,那么想法就是让“条件 (1)”处于活动状态(而不是当前的“等式 (1)”。

\documentclass{article}
\usepackage[colorlinks=true,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}
\begin{document}
It is true that
\begin{equation}\label{eq:cos}
\cos\pi=-1
\end{equation}
However, Condition~\Cref{eq:cos} should be considered with care.
\end{document}

部分答案[在 Mico 的答案之后发布,包括 Circumscribe 的评论]:可以使用以下命令手动实现\hyperref

\begin{equation} \label{eq:cos} 
\cos\pi=-1
\end{equation}
However, \hyperref[eq:cos]{Condition~\ref*{eq:cos}} should be considered with care.

答案1

你问,

是否可以cleveref动态自定义可点击链接中的名称?

简短回答:是的。详细回答:您可以使用 的别名功能实现您的排版目标cleveref。有关更多信息,请参阅软件包用户指南的第 6 节,标题为“覆盖交叉引用类型”。

在此处输入图片描述

\documentclass{article}
\usepackage[colorlinks=true,allcolors=red]{hyperref}
\usepackage[nameinlink,noabbrev]{cleveref}

% introduce an alias for 'equation'
\crefalias{condition}{equation}
\crefname{condition}{condition}{conditions}
\Crefname{condition}{Condition}{Conditions}
\creflabelformat{condition}{#2\textup{(#1)}#3} % same as 'equation'

\begin{document}
It is true that
\begin{equation} \label[condition]{eq:cos} % note the optional argument of '\label'
\cos\pi=-1
\end{equation}
However, \Cref{eq:cos} should be considered with care.
\end{document}

答案2

Mico 的回答当然很有趣,但看起来需要新的发展。相反,手动解决方案是可能的:

However, \hyperref[eq:cos]{Condition~\eqref*{eq:cos}} should be considered with care.

因此,可以定义一个新命令(这里用于方程式),该命令有两个参数(学期以及标签)

\newcommand*{\myrefeq}[2]{\hyperref[#2]{#1~(\ref*{#2})}}

然后,我们可以根据需要将其与适当的术语一起使用:In \myrefeq{Equation}{eq:label}...In \myrefeq{Condition}{eq:label}...超链接位于完整Equation (1)或的位置Condition (1)

相关内容