Why can't I expand \ref*{} as a string?
\ref
can't go in \edef
no matter whether you load hyperref
or not. The code
\documentclass{article}
\begin{document}
\section{Section}\label{first}
\edef\temp{\ref{first}}\noindent Section = \temp
\end{document}
stops with
! Missing control sequence inserted.
<inserted text>
\inaccessible
l.5 ...\temp{\ref{first}}\noindent Section = \temp
Only if the label has already been written to the .aux
file the \edef
works. In any case, no command with a *
-variant or optional argument can go in \edef
(unless it's defined in a special way with xparse
).
Solution:
\documentclass{article}
\usepackage{refcount}
\usepackage{hyperref}
\begin{document}
\section{Section}\label{first}
\edef\temp{\getrefnumber{first}}\noindent Section = \temp
\end{document}
On the first run after the \label
has been added, \temp
will expand to 0
. Upon rerunning LaTeX, you'll get the correct reference.