I'm working on a LaTeX template for our institute. The guidelines dictate an unusual style when referencing figures, equqations or tables. The frist time, they are mentioned in the text, they have to be underlined. So what can I do to get this working automatically? I already tried some stuff with glossary and acronym but got nothing to work.

I'm happy to hear from you, Bernte

  • Welcome to TeX.SX! Do you need all of “Figure x.y” underlined?
    – egreg
    Nov 13 '15 at 16:42
  • 1
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jan 2 '18 at 11:11
  • @samcarter: The OP seems to have multiple accounts :-(
    – user31729
    Jan 2 '18 at 15:38
  • @ChristianHupfer He/She has been told by the TeXnician how to merge them. So this is no excuse not to accept :) Jan 2 '18 at 15:41
  • @samcarter: I don't excuse that. I excuse only my own errors. And now, excuse me, please ;-)
    – user31729
    Jan 2 '18 at 15:43

Here is a modification of my answer to a previous question asking to add margin notes the first time a reference is made. This uses the cleveref package to allow context-aware citations, which makes underlining the name as well as number easy.

Edit: As pointed out by @egreg below, the previous answer would break if a list of references was passed to \cref. To correct this, the check is now made to see if the passed argument contains a comma. If so, no underlining is performed, regardless of the references. In other words, this approach will underline the first time a reference is made by itself.






%Redefine \cref so that it will make a margin note if the passed label is referenced for the first time.
    %check if the label has already been referenced.
    \ifcsname marginnote@#1\endcsname
        %already exists...therefore not the first citation
        \expandafter\gdef\csname marginnote@#1\endcsname{}%first citation...with this defined, will not underline again

\author{John Doe}
\title{Automatic underlining of the first use of a reference}


  See \cref{fig:figure}. \lipsum[1] 

  A new reference to \cref{fig:figure} is not underlined.

  Let's do the same with an equation.
    \label{eq:1}f(x) = x^2

  Refering to \cref{eq:1} for the first time, there should be a marginal note, as is visible here, but it shoudl begin with  ``Eq.'', not ``Fig.''.
  Here we can test a list of references \cref{eq:1,tab:1,fig:figure} which should bypass the underling no matter the contents.
  Adding another reference to \cref{eq:1} does not result in an underline; however, referring to \cref{tab:1} for the first time does.


% lets put a table and a figure
    \caption{Table title}
      x & y \\ \hline 
      3 & 3 \\
      4 & 4 \\ \hline

    \caption{A figure}\label{fig:figure}


enter image description here

  • I wouldn't overload \cref.
    – egreg
    Nov 13 '15 at 17:00
  • @egreg: I'm interested to know why. Is it bad form? Is there a conflict I should be aware of?
    – Guho
    Nov 13 '15 at 17:12
  • 1
    \cref allows lists of references.
    – egreg
    Nov 13 '15 at 17:12
  • @egreg: Excellent point! A list would certainly break this approach. I'll make a note of that in the answer.
    – Guho
    Nov 13 '15 at 17:19
  • @egreg: Answer updated to pass a list directly to the old \cref without considering the contents. Thanks for the catch!
    – Guho
    Nov 13 '15 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.