TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use the \autoref function in LyX, so that when I refer to a labeled figure or theorem, it is typeset as "Figure #" or "Theorem #". According to this answer, I can redefine the \ref command as \autoref using


at the beginning of the document. However, this creates a problem: when I refer to an equation, it comes out as "(Equation #)". This is because LyX does not use \eqref{eq_label}, but rather (\ref{eq_label}) to refer to equations.

So my question is: Is there a way to configure LyX so that it uses \eqref to refer to equations, and \autoref to refer to figures, theorems, etc.

I'm using the article document class and MikTeX distribution.

share|improve this question
up vote 5 down vote accepted

Using \autoref is actually simpler and has an nice advantage! The area for clicking on a hyperlink is larger (see example below) since the "type names" are included in the clickable area.

For that, we insert following code in the LyX Preamble.


The command \renewcommand\equationautorefname{\@gobble} is used for equation references to remove the word "Equation~". In the example the styles "Reference" and "(<Reference>)" are used:

lyx document output

share|improve this answer
Excellent answer! Thanks so much! – Herr K. Mar 28 '13 at 4:41

Such cross references can be generated in LyX without \autoref. LyX uses internally the refstyle package. Just change the style for figure, theorem, ... references to "Formatted Reference", and use "(<Reference>)" for equation references. Note that correct label prefixes, e.g., thm: or fig:, are important. Here is an example (with "hyperref" package support switched on):

enter image description here

enter image description here

In this example we also changed the lower case letters at the beginning of type names to upper case one, e.g., figure 1 to Figure 1. This is done by modifying the setup of the reference style in \newref{...}{...}. We add following to the LyX Preamble:

    name      = \RSFigtxt,  
    names     = \RSFigstxt,
    Name      = \RSFigtxt,
    Names     = \RSFigstxt,
    rngtxt    = \RSrngtxt,
    lsttwotxt = \RSlsttwotxt,
    lsttxt    = \RSlsttxt}

If no additional package about reference manipulation are used (e.g., "cleveref") the line \newref{fig}{name = \RSFigtxt} might be enough. -- If the "refstyle" package does not know about an environment we need to define a new command additionally. For example, for theorems LyX already provides \RSthmtxt. But we add to the LyX Preamble:


(See also: Lyx 2.0 Formatted references to theorem/lemma/claim environments)

How to make deeper changes?

If one writes in a language different from English, one wants references in the native language rather than in English. By default, some translations are available in the "refstyle" package and choosen. Otherwise copy the file "refstyle.cfg" from your TeX tree (probably: "tex/latex/refstyle/refstyle.cfg") to the directory of your “.lyx” file and rename it to “refstyle.def”. You can modify this file to your liking. See "refstyle" package documentation (or also How can I get capitalised cross references in LyX with refstyle).

share|improve this answer
I've always wondered what the "formatted reference" option is for... Thanks for the enlightenment :) – Herr K. Mar 28 '13 at 4:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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