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.

Is it possible to attach a marker to just a place in text, not to section, sub-section, etc.?

This is what I'm trying to achieve:

\begin{document}
Alex (see~\ref{alex}) is a boy, 
Jessica (see~\ref{jessica}) is a girl.
[...]
\label{alex}\ref{alex}: Alex Johnson: 4 y.o.
\label{jessica}\ref{jessica}: Jessica D.: 5 y.o.
\end{document}

I want to get something like this:

Alex (see 1) is a boy, 
Jessica (see 2) is a girl.
[...]
1: Alex Johnson: 4 y.o.
2: Jessica D.: 5 y.o.

Makes sense?

share|improve this question
    
The specific example could be done with an enumerated list, is there a reason why you don't want to do that? –  Loop Space Oct 12 '10 at 11:28
    
@Andrew This is just an example. Correct solution is proposed by Will Robertson below. –  yegor256 Oct 12 '10 at 11:30

2 Answers 2

up vote 11 down vote accepted

You can only \ref-er to a \label that has been attached to a counter using \refstepcounter. For example:

\newcounter{foo}
...
Alex (see~\ref{alex}) is a boy, 
Jessica (see~\ref{jessica}) is a girl.
[...]
\refstepcounter{foo}\thefoo\label{alex}: Alex Johnson: 4 y.o.
\refstepcounter{foo}\thefoo\label{jessica}: Jessica D.: 5 y.o.

Internally, this is the way that all labelling and referencing is done with sections, figures, and so on.

share|improve this answer

For who ever might be interested, adapted from Will Robertson's solution:

Problem: You wish to have an enumeration (e.g. an enumeration of 'hypotheses' in a research proposal) throughout the text, and reference that enumeration in the text.

Solution: Define

\newcounter{hypothesiscounter}
\newcommand*{\hyplabel}[1]{H\refstepcounter{hypothesiscounter}\thehypothesiscounter\label{#1}}
\newcommand*{\hypref}[1]{H\ref{#1}}

and use as:

This shall be hypothesis \hyplabel{HYP:CRAZY_HYPOTH}. I shall explain hypothesis \hypref{HYP:CRAZY_HYPOTH} below.
share|improve this answer

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.