# Cross reference in LyX

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

\let\ref\autoref


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.

-

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.

\AtBeginDocument{%
\let\ref\autoref
\renewcommand\equationautorefname{\@gobble}
}


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:

-
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):

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:

\newref{fig}{%
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:

\def\RSThmtxt{Theorem~}


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).

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