7

I'm writing a scientific report and it's required that the first reference to any figure or table (not to equations or sections) in the text is set bold like this:

example

Is there a package for this kind of task?

The acronym package does something similar giving the full description of an acronym when it's used for the first time, so I guess it's not a too special problem.

1 Answer 1

3

The following works:

enter image description here

\documentclass{article}
\makeatletter
\def\@setref#1#2#3{%
  \ifx#1\relax
    \protect\G@refundefinedtrue
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#3' on page \thepage \space
      undefined}%
  \else
    \expandafter\ifx\csname used@#1\endcsname\relax
      \expandafter\global\expandafter\def\csname used@#1\endcsname{used}%
      {\bfseries\expandafter#2#1\null}% Formatting of first reference
    \else
      \expandafter#2#1\null%
    \fi
  \fi%
}
\makeatother
\begin{document}
\begin{figure}
  \centering\rule{150pt}{20pt}
  \caption{A figure}\label{fig:figure}
\end{figure}
See Figure~\ref{fig:figure}. The same reference to Figure~\ref{fig:figure}.
\end{document}

It modifies the macro \@setref which is called from \ref to decide whether a reference exists or not. The formatting is based on a condition to check whether a newly defined macro used@<label> exists or not.

Formatting of the first reference is set using \bfseries and can be modified to suit.

2
  • Thanks for your prompt and detailed answer. Could you modify the example so that the ref{} command prints Fig. x instead of only the number and is still bold for the first time? Sorry for not having been specific enough in my question.
    – Deve
    Commented Mar 15, 2012 at 10:20
  • 1
    @Deve: this would require some package (like, AFAIR, cleveref), since in "vanilla" LaTeX you always have to supply the "Ref.~" part yourself. Don't have time to implement it now, if nobody answers (which is unlikely), I'll try to do it tomorrow.
    – mbork
    Commented Mar 15, 2012 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .