# Latex: Get text of hypertarget

Please take a look at the following LaTeX code. How can I get the text of a \hypertarget?

\newcounter{reqCounter}
\newcommand{\newReq}[1]{\stepcounter{reqCounter}\hypertarget{#1}{(R\arabic{reqCounter})}}


Example:

This is a requirement \newReq{req1}. This is the same requirement as \Req{req1}.


Result:

This is a requirement (R1). This is the same requirement as (R1).

-
Welcome to TeX.SX! Your post was migrated here from another Stack Exchange site. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. –  Marco Daniel Jun 23 '13 at 13:08

## migrated from stackoverflow.comJun 23 '13 at 13:05

This question came from our site for professional and enthusiast programmers.

Use the regular \label-\ref system in the following way:

\documentclass{article}
\newcounter{reqCounter}\renewcommand{\thereqCounter}{R\arabic{reqCounter}}
\newcommand{\newReq}[1]{\refstepcounter{reqCounter}\label{#1}(\thereqCounter)}
\newcommand{\Req}[1]{(\ref{#1})}
\begin{document}
Example: This is a requirement~\newReq{req1}. This is the same requirement as~\Req{req1}.
\end{document}


Depending on the use case, there may be more optimal ways of dealing with this.

-