A small 'overload' of \autoref
(not fully finished), adding the label to an expl3
\seq
list and checking whether it was added already.
\documentclass{article}
\usepackage{hyperref}
\usepackage{letltxmacro}
\usepackage{xparse}
\newcommand{\autorefformat}[1]{%
{\bfseries#1}%
}
\ExplSyntaxOn
\seq_new:N \g_ref_alreadyused_seq% Define a sequence list
\makeatletter
\AtBeginDocument{
\LetLtxMacro\autoref@@orig\autoref% Get the old definition of \autoref
\RenewDocumentCommand{\autoref}{sm}{%
\seq_if_in:NnTF \g_ref_alreadyused_seq {#2} {
\IfBooleanTF{#1}{% Yes, starred version
\autoref@@orig*{#2}
}{
\autoref@@orig{#2}
}
}{% No, it's not yet used, apply \autorefformat
\seq_gput_right:Nn \g_ref_alreadyused_seq {#2}
\autorefformat{%
\IfBooleanTF{#1}{% Starred version
\autoref@@orig*{#2}
}{
\autoref@@orig{#2}
}
}
}% End of \seq_if_in:F
}
}
\makeatother
\ExplSyntaxOff
\begin{document}
The first reference to~\textbf{\autoref{tab:a}} should be bold.
\begin{table}
\caption{A table}\label{tab:a}
\end{table}
Further references to~\autoref{tab:a} should be normal.
\end{document}
Alternate version: Using a wrapper macro named,say, \autorefext
, that checks similarly for the label being used already. The third, optional argument defaults to \bfseries
.
\documentclass{article}
\usepackage{hyperref}
\usepackage{xparse}
\newcommand{\autorefformat}[1]{%
{\bfseries#1}%
}
\ExplSyntaxOn
\seq_new:N \g_ref_alreadyused_seq
\NewDocumentCommand{\autorefext}{smO{\bfseries}}{%
\seq_if_in:NnTF \g_ref_alreadyused_seq {#2} {
\IfBooleanTF{#1}{
\autoref*{#2}
}{
\autoref{#2}
}
}{%
\seq_gput_right:Nn \g_ref_alreadyused_seq {#2}
{#3%
\IfBooleanTF{#1}{
\autoref*{#2}
}{
\autoref{#2}
}
}
}
}
\ExplSyntaxOff
\begin{document}
The first reference to~\autorefext{tab:a} should be bold.
\begin{table}
\caption{A table}\label{tab:a}
\end{table}
Further references to~\autorefext{tab:a} should be normal.
\end{document}
