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.

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})}}
\newcommand{\Req}[1]{(\hyperlink{#1}{%text of hypertarget%})}

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

share|improve this question
    
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
add comment

migrated from stackoverflow.com Jun 23 '13 at 13:05

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

1 Answer

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

enter image description here

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.