How to selectively turn off hyperref for some cross-references defined by \ref?

You have to use an expandable version of \ref, for instance with 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}

enter image description here


You could use zref to get an expandable \ref. It will also work with references which are not simple numbers:

\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}

enter image description here

Tags:

Hyperref