1

I am referencing a label like this texttext \ref{p:1}, \ref{p:2} text and after compiling my document I always get an output like this "texttext 8, 9 text".

Is there a way I can force an output like "texttext 1, 2 text"?

7
  • 4
    What exactly do you mean? I get the idea that you use \label where you want to use \ref.
    – jmc
    Mar 27, 2012 at 15:20
  • Oh sorry i fixed that.
    – 71GA
    Mar 27, 2012 at 15:48
  • 1
    The numbers that come out are the numbers used in whatever you have labeled, do you want the section number to be "8" but the reference to that section to be "1" ? Mar 27, 2012 at 15:55
  • 2
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. In this case it would go a long way towards clarifying the question and also serve as a test case to ensure that the solutions provided actually work for your particular case. Mar 27, 2012 at 16:07
  • 2
    How were we to guess that:-) That is why we always ask people to supply a full example. If you use enumerate rather than description, the numbering is automatic and \ref will pick up the numbering, If that doesn't do what you want, edit your question with a complete example see the link in Peter's comment. Mar 27, 2012 at 18:32

2 Answers 2

1

You can use the hyperref package to refer to some label and choose your own text for the reference, for example:

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\begin{description}
\item[42] \phantomsection\label{p:1}Some text.

\item[2010] \phantomsection\label{p:2}Some more text.
\end{description}

Arbitrary numbers for the items.

\newpage

texttext \hyperref[p:1]{p:1}, \hyperref[p:2]{p:2} text

\end{document}

where \hyperref's [...] contains the label's name and {...} the text to be displayed for the reference. The \phantomsections are necessary, else the hyperlinks will aim at the beginning of the description. When the hyperref package is used, at least two compier runs are necessary.

0
1

Is this what you want?

\makeatletter
\newcommand\deflabel[1]{\def\@currentlabel{#1}}
\newcommand\mylabel[1]{#1\deflabel{#1}}
\makeatother
\begin{document}

\begin{description}
\item[\mylabel{foo}\label{l:1}]  bar
\item[\mylabel{baz}\label{l:2}]  quux
\end{description}

See \ref{l:1} and \ref{l:2},

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .