Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In Lyx 2.0, I'm trying to use a formatted reference to a claim, but I cannot get the "formatted" part, i.e. I can't get it to typeset "claim" as well as the claim number.

I'm using modules "Theorems (Numbered by type)" and "Theorems (Numbered by type within sections)". I have a paragraph in the "Claim" environment, with a label "claim:1". (I got the "claim:" part in there by editing ../Resources/layouts/theorems-refprefix.inc, but I had the same behavior before I made this change.) I later put in a formatted reference which generates tex code as "\claimref{1}". This typesets to "... 1.1 ..." in the output, i.e. just section and claim counter number. What I'd like to see is "... claim 1.1 ..."

If I change these claims to theorem environments AND delete and remake the labels (so "thm:1") and update the references, the formatted reference typesets the word "theorem" for the reference, as desired. Lemma does not seem to work (though I may not have remade all the lables.)

I do see Lyx adding this to the preamble:

\AtBeginDocument{\providecommand\claimref[1]{\ref{claim:#1}}}

I also see

\RS@ifundefined{thmref}
  {\def\RSthmtxt{theorem~}\newref{thm}{name = \RSthmtxt}}
  {}

which I can't trace the origin of, but it may explain why theorem works.

Any ideas?

share|improve this question
    
The involved package is refstyle –  egreg Jul 4 '12 at 7:49
add comment

2 Answers 2

up vote 4 down vote accepted

Add to the document preamble (Document --> Settings --> LaTeX preamble)

\newref{claim}{name=claim~}

and it will probably work. As mentioned by egreg in the comments, the refstyle package is used, and you have to tell it what it should insert for labels starting with claim:.

refstyle also provides commands for start-of-sentence references (capital letter) and plural forms, and the words to insert in these cases can also be specified, e.g.

\newref{claim}{name=claim~,Name=Claim~,names=claims~,Names=Claims~}

I don't know, however, how to make LyX use these, other than through using an ERT, with e.g. \Claimref{claim:1}. See the refstyle documentation for details.

Example

Copy the following code to an empty file and save as a .lyx file, e.g. example.lyx. Open in LyX and compile. Screenshots of LyX view and PDF below.

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\begin_preamble
\newref{claim}{name=claim~}
\end_preamble
\use_default_options true
\begin_modules
theorems-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Section
Something
\end_layout

\begin_layout Claim
\begin_inset CommandInset label
LatexCommand label
name "claim:claim1"

\end_inset

I hereby claim that I don't use LyX.
\end_layout

\begin_layout Theorem
\begin_inset CommandInset label
LatexCommand label
name "thm:1"

\end_inset

LyX makes some things harder.
\end_layout

\begin_layout Standard
Inserting references: 
\begin_inset CommandInset ref
LatexCommand formatted
reference "thm:1"

\end_inset

 and 
\begin_inset CommandInset ref
LatexCommand formatted
reference "claim:claim1"

\end_inset

.

\end_layout

\end_body
\end_document

enter image description here enter image description here

share|improve this answer
    
Thanks very much for the suggestions, explicit and implicit! :) I really appreciate your work. –  jspencer Feb 19 '13 at 0:32
add comment

According to the LyX manual, first make sure to check Use refstyle (not prettyref) ... in Document -> Settings -> Document Class, and you can put the following in the preamble:

\newref{claim}{refcmd={claim \ref{#1}}}

Then whenever you refer to a label begin with claim: with Formatted reference option, you will get the desired format.

I took the liberty of modifying the example lyx file:

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\begin_preamble
\newref{claim}{refcmd={claim \ref{#1}}}
\end_preamble
\use_default_options true
\begin_modules
theorems-bytype
theorems-sec-bytype
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Section
Something
\end_layout

\begin_layout Claim
\begin_inset CommandInset label
LatexCommand label
name "claim:1"

\end_inset

I hereby claim that I don't use LyX.
\end_layout

\begin_layout Theorem
\begin_inset CommandInset label
LatexCommand label
name "thm:1"

\end_inset

LyX makes some things harder.
\end_layout

\begin_layout Standard
Inserting references: 
\begin_inset CommandInset ref
LatexCommand formatted
reference "thm:1"

\end_inset

 and 
\begin_inset CommandInset ref
LatexCommand formatted
reference "claim:1"

\end_inset

.
\end_layout

\end_body
\end_document
share|improve this answer
add comment

Your Answer

 
discard

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.