I'm having troubles using the cross referencing system with LyX (version 2.1.1). I place labels on the side of the environment i want to be able to make reference in the future, using the label function from gui. When i want to add a reference i use the reference function from gui. I choose the lable i want and, since i don't want just the numbers but also the environment name (e.g. : Section, Theorem, ecc..), i also select "Formatted reference".

I'm using ams classes since i need to input math. In particular, from Document > Settings > Modules i choose "Theorems (AMS, Numbered by Type), Theorems (AMS Extended, Numbered by Type), Theorems (Numbered by Type Within Sections)", plus others which have nothing to do with math (e.g. fixcm). I'm also editing a document in Italian language, so i want references to be labled in Italian. Keep in mind that in the Lyx editor and in pdf i see correctly translated names for all the environments. The problems comes up only in cross referencing.

The problem is that if i make reference to a Theorem i get the label automatically placed, but in english (Theorem unstead of teorema). If i reference a Definition, i get nothing apart the numbers.

Seems that the problem with the appearance of only some kinds of evironment lables is common but trying some of the solutions proposed seems not to work for me. For instance, adding the following:

\newcommand{\figref}[1]{Figure~\ref{#1}}
\newcommand{\tabref}[1]{Table~\ref{#1}}
\newcommand{\eqnref}[1]{Eq.~\ref{#1}}
\newcommand{\secref}[1]{Section~\ref{#1}}
\newcommand{\defref}[1]{Definition~\ref{#1}}

will give error, since LyX seems to add some kind of definition to be able to manage the only working lables (Theorems, Lemma, Section), by adding hte following:

\AtBeginDocument{\providecommand\thmref[1]{\ref{thm:#1}}}

\RS@ifundefined{subref}
  {\def\RSsubtxt{section~}\newref{sub}{name = \RSsubtxt}}
  {}
\RS@ifundefined{thmref}
  {\def\RSthmtxt{theorem~}\newref{thm}{name = \RSthmtxt}}
  {}
\RS@ifundefined{lemref}
  {\def\RSlemtxt{lemma~}\newref{lem}{name = \RSlemtxt}}
  {}

Any suggestions? Am i using LyX the wrong way? Any help will be appreciated.

  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – mvkorpel Aug 21 '14 at 14:06
  • Is this LyX or LaTeX? Is LyX placing the strings in the file or are you seeing the English strings in the pdf output? – Andrew Swann Aug 21 '14 at 17:20
  • LyX. In the edited file as well as in the pdf i see the correct environment name, correctly translated into the document language i selected in the document settings tabs. The problem arises when i cross reference something: in the pdf output only the english label of the corresponding referenced object is visualized, and not for every kind of the available ones (only theorem, Lemma and some other, but not Definition). – Calculonne Aug 21 '14 at 17:29
  • So for exemple, if i choose Italian, in the pdf i will get "Teorema 1.2, Teorema 1.3, Definizione 1.1" for the different parts of the text, but when i want to show something like "using Theorem 1.2", i will only get this result in english and for the theorem environment, not for the definition one, where i will get "as said in 1.1". I may send a test file, if possible, to show. It's the same i've sent to the LyX development team as bugtracking warning. – Calculonne Aug 21 '14 at 17:32
  • @Calculonne please always link to any relevant ongoing posts for archival purposes: lyx.org/trac/ticket/9248 – scottkosty Aug 22 '14 at 0:23

The way LyX decides what to put in front of a formatted reference is by what label the thing has e.g. if you make a formatted reference to "thm:clever-result" then it will be formatted with "Theorem" at the front (even if the label's in a lemma!). So you need to make sure that the appropriate prefix is in each of your labels. With theorems, LyX puts "thm:" at the start of each label by default, but for historical reasons it doesn't put anything at the start of definitions, so you need to do that yourself. I believe that the correct prefix is "defn:" but you'll need to try it and see.

I think the language of the prefixes is decided by the language of the document: in the document settings, choose the language page and you can change it there. This ought to the same as the language used for the text used when you create the theorems.

  • Thanks for the answer. I checked the labels and all report an automatically placed "def:". I tried changing it do "defn:", but nothing changed... still get only numbers. For the language issue, i had set it already to Italian, so the problem may lay somewhere else. – Calculonne Aug 21 '14 at 14:37

I just found a way to personalise the way LyX presents formatted references, I'm on version 2.2.2 so you millage may vary, it involves 3 steps, I did it for figures,

  1. First make sure to check Use refstyle (not prettyref) ... in Document -> Settings -> Document Class.
  2. Reference a figure with formatted reference, lets say the caption is fig:my-figure, then LyX will create a \figref{my-figure} without the fig:.
  3. Add \renewcommand{\figref}[1]{Fig.~\ref{fig:#1}} to the document's LaTeX preamble, notice that we consider the fig: lost in the last step. And also, notice that you can change the Fig.~ for watever meets your needs for instance \renewcommand{\figref}[1]{Figura~\ref{fig:#1}} if you're working in Spanish.

If you delete all figure formatted references from the document, you should delete the \renewcommand from the document's LATeX preamble, otherwise it won't compile.

Note:

In order to prevent the LyX commands for formatting to run after your own commands you can wrap them with \AtBeginDocument{...}, for example:

\AtBeginDocument{\renewcommand{\eqref}[1]{Eq.~(\ref{eq:#1})}}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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