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.

The idea is to place \LBL{some_label_name} in a paragraph so that I can refer back to the particular point inside that paragraph where the \LBL was placed. I would like to define the macro for \LBL.

Unfortunately the \label must be placed inside an environment with a counter. I tried phantomsection but the label picks up the true section counter. I'm using the hyperref package.

How can I achieve this, what would the \def for \LBL look like?

share|improve this question
add comment

1 Answer 1

up vote 13 down vote accepted

There are many ways. The following is using \refstepcounter that generates implicitly an anchor. Also instead of a section number \theword is redefined to get the word instead, if called by \ref.

\documentclass{article}
\usepackage{hyperref}
\usepackage{lipsum}
\newcounter{word}
\makeatletter
\newcommand*{\LBL}{%
  \@dblarg\@LBL
}
\def\@LBL[#1]#2{%
  \begingroup
    \renewcommand*{\theword}{#2}%
    \refstepcounter{word}%
    \label{#1}%
    #2%
  \endgroup
}
\makeatother

\begin{document}
  The \ref{word} is referenced.

  \lipsum*[1] \LBL{word} \lipsum[2]

\end{document}

If the word is complicate that it cannot be used as label name, then the optional argument helps: \LBL[labelword]{weird word}\ref{labelword}.

share|improve this answer
    
As it turned out, I would need more. Could you please check my new question? –  Ali Oct 1 '12 at 21:57
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.