[Tex/LaTex] Labeling a text and referencing it later


Is there a way to attach a label to a string and then refer to that string with a reference?

For example,

\labelText{This is a text that is also a tag}{label:text}

and then refer to this string with \ref{label:text} where the string will serve as a tag itself.

Why I need it? I am writing a pseudo code and using a command go to #line number but the line number might change if I insert extra line in the code.
With referencing this will be avoided.

Best Answer

Something like this? This writes the text explicitly to the .aux file and provides a hyperlink to it. Use \nameref to get the label content, not the label number (which is given by \ref)

With more information a better solution could be given.






In \nameref{label:text} we have
\section{First} \label{firstsection}
\labelText{This \textsc{is} a text that is also a tag}{label:text}


enter image description here

Related Question