如何有选择地关闭由 \ref 定义的一些交叉引用的 hyperref?

如何有选择地关闭由 \ref 定义的一些交叉引用的 hyperref?

我定义了一个命令 ( \dingbatise),用于将字符串转换为 dingbat 之一。它适用于\ref

\documentclass{article}
% For clickable refs:
% \usepackage{hyperref}
% For converting numbers to dingbats:
\usepackage{xstring,pifont}
\newcommand{\dingbatise}[1]{%
\edef\tualek{#1}%
\noexpandarg%
\expandafter\StrSubstitute\expandafter{\tualek}{1}{\ding{202}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{2}{\ding{203}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{3}{\ding{204}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{4}{\ding{205}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{5}{\ding{206}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{6}{\ding{207}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{7}{\ding{208}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{8}{\ding{209}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{9}{\ding{210}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{0}{\ding{74}}[\tualek]%
\tualek
}
\begin{document}
\section{Etiam At Risus}\label{etiam}
In \dingbatise{120} pellentesque faucibus vestibulum \dingbatise{\ref{etiam}}.
\end{document}

在使用该hyperref软件包时,我再也无法像上面那样dingbatise指定特定内容\ref。如何解决这个问题?(我不介意 dingbatised ref 不再是超链接。)

答案1

您必须使用 的可扩展版本\ref,例如refcount

\documentclass{article}
\usepackage{xstring,pifont,refcount}
\usepackage[colorlinks]{hyperref}

\protected\def\pding#1{\ding{#1}}
\newcommand{\subhelper}[2]{%
  \StrSubstitute{\tualek}{#1}{\pding{#2}}[\tualek]%
}

\newcommand{\dingbatise}[1]{%
  \edef\tualek{#1}%
  \subhelper{1}{202}%
  \subhelper{2}{203}%
  \subhelper{3}{204}%
  \subhelper{4}{205}%
  \subhelper{5}{206}%
  \subhelper{6}{207}%
  \subhelper{7}{208}%
  \subhelper{8}{209}%
  \subhelper{9}{210}%
  \subhelper{0}{74}%
  \tualek
}
\newcommand{\dref}[1]{%
  \hyperref[#1]{\dingbatise{\getrefnumber{#1}}}%
}

\begin{document}

\section{Etiam At Risus}\label{etiam}

In \dingbatise{120} pellentesque faucibus vestibulum \dref{etiam}.

\end{document}

在此处输入图片描述

答案2

您可以使用 zref 来获取可扩展的 \ref。它还可以用于非简单数字的引用:

\documentclass{article}
% For clickable refs:
\usepackage{hyperref,zref-user}
% For converting numbers to dingbats:
\makeatletter
\newcommand\dingref[1]{\zref@extractdefault{#1}{default}{0}}
\makeatother
\usepackage{xstring,pifont}
\newcommand{\dingbatise}[1]{%
\edef\tualek{#1}%
\noexpandarg%
\expandafter\StrSubstitute\expandafter{\tualek}{1}{\ding{202}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{2}{\ding{203}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{3}{\ding{204}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{4}{\ding{205}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{5}{\ding{206}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{6}{\ding{207}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{7}{\ding{208}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{8}{\ding{209}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{9}{\ding{210}}[\tualek]%
\expandafter\StrSubstitute\expandafter{\tualek}{0}{\ding{74}}[\tualek]%
\tualek
}
\begin{document}
\section{Etiam At Risus}\label{etiam}\zlabel{etiam}
\subsection{Blalb}\zlabel{subsec}
In \dingbatise{120} pellentesque faucibus vestibulum \dingbatise{\dingref{etiam}}.
\dingbatise{\dingref{subsec}}

\end{document}

在此处输入图片描述

相关内容