What I wish to do is create a (hidden) label in which some text is stored, and retrieve the text by referencing to it, without getting an actual link. For example:
\customlabel{refname}{some text} \getcaption{refname}
should give
some text
but some text should not be clickable, it simply has to be text. In fact I need it in something like \ifstrequals{\getcaption{refname}}{foo}{\dothis}{\dothat} (provided etoolbox) so \getcaption should really return pure text.
In Defining custom labels it is shown how to define a hidden label with a custom link caption provided hyperref is not loaded: (see Ian Thompson's answer)
\documentclass{article}
\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{}}}}
\makeatother
\begin{document}
\customlabel{refname}{some text} \ref{refname}
\end{document}
which outputs some text, as desired.
But with hyperref loaded this doesn't work. Henrik Bøgelund Lavstsen suggests
\documentclass{article}
\usepackage{hyperref}
\makeatletter
\newcommand{\customlabel}[2]{%
\protected@write \@auxout {}{\string \newlabel {#1}{{#2}{\thepage}{#2}{#1}{}} }%
\hypertarget{#1}{#2}}
\makeatother
\begin{document}
\customlabel{refname}{some text} \ref{refname}
\end{document}
but this gives some text some text, i.e. the label is not 'hidden'. And of course \ref (playing the role of \getcaption) does not simply return some text, meaning that \ifstrequal{\ref{refname}}{some text}{yes}{no} gives no.
If the caption is just a number one can use \getrefnumber (from refcount) as \getcaption-command, but I am not aware of an alternative of \getrefnumber where the stored text is an arbitrary string.
Note: The reason why I want to use labels (or more generally, store the text in an external file) is that the stored text has to be accessible in the document before the position where it is stored. I.e. the text has to be stored in an external file and retrieved in a next LaTeX run. I do not want to create one file for each \customlabel call, since I have to use this a 1000 times and do not want 1000 auxiliary files. That's why I think using labels is the best option.


minimalfor examples. – cfr Feb 04 '15 at 22:39\gdef\refname{some text}instead of\customlabeland then\refnameinstead of\getcaption? – David Carlisle Feb 04 '15 at 23:02