tags:

views:

79

answers:

5

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?

A: 

Did you know that there was a latex stackoverflow clone? I just can't seem to find the link. :/

Gleno
tex.stackexchange.com
Zack
@Zack, Thanks, that's exactly what I was looking for!
Gleno
Should be a comment.
KennyTM
My answer was "look for answer elsewhere, since ye won't find one here". I was spot on the money. :)
Gleno
A: 

Not sure what you mean with "marker". Do you need a new counter?

ShiDoiSi
@ShiDoiSi I've updated my question, see above please.
Vincenzo
A: 

If you want to have a label, consider the following (from here);

  • \label{marker} You give the object you want to reference a marker, you can see it like a name.

  • \ref{marker} You can reference the object you have marked before. This prints the number that was assigned to the object.

  • \pageref{marker} It will print the number of the page where the object is.

Normally, if you reference to a label, LaTeX prints out the section, subsection, etc. But if you want to specify the exact place in text, you can use pageref. So with pageref you can exactly print out the page number of the "marker".

This is - as far as i know - the most exact possibility to tell the reader where in text a "marker" was, i.e. it is - as far as i know - impossible to tell LaTeX to print the exact line number or so.

phimuemue
@phimuemue I've updated my question, see above please.
Vincenzo
A: 

You can use \label anywhere, including in the body of the text, but the thing labelled will be (roughly) the 'current labellable thing', that is the last \*section, or the current equation or table.

If you want to label something else (what is it you're after?) then you'll have to roll your own (not trivial), and have something which, if I recall correctly, sets \@currentlabel.

Edited, to add:

\begin{document}
\section{Hello}
Here is some text
\label{l1}
More text.
\newpage
Further text, on page 2
\label{l2}

This is section~\ref{l1} on page~\pageref{l1}.
And section~\ref{l2} on page~\pageref{l2}.
\end{document}

In both cases, the \ref refers to section 1, though the \pageref refers to pages 1 and 2 respectively. In both cases, the 'thing being labelled' is the section, and the text that goes in the label, and which appears in the \ref, is the section number.

So if you want to refer to an 'arbitrary place in the text', you have to ask yourself 'what is the text that would be produced by the \ref?'

Norman Gray
@Norman I want to label just a place in text, which is unique in my context.. How can I do it?
Vincenzo
See my edit above. It's still not clear what you're looking for. Can you give an example – what would the cross-reference look like? For example, after you've added a `\label{mylabel}` after a section, the text `see section~\ref{mylabel}` turns into _see section 1.2_ or something like that.
Norman Gray
@Norman I've made changes to my questions, please see above
Vincenzo
A: 

This is the solution:

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

Posted by Will at http://tex.stackexchange.com/questions/4021/how-to-set-a-marker-counter-label-to-an-arbitrary-piece-of-text

Vincenzo
Ah, `\refstepcounter` -- that's it! That's what sets `\@currentlabel`. The only thing you could potentially add would be something like `\newcommand\refitem{\refstepcounter{foo}\thefoo}`
Norman Gray