I'm trying to write section numbers to a file with the newfile package.
In details, this MWE basically tries to write to a .ref file with lines like A-B. The A and B are generated by \label and \ref commands: if \ref{A} is written in section 2 and \label{A} is defined in section 1, then we should write 2|1 in the file.
This example actually fails to expand the \ref command, probably due to the insertion of the hyperref package, which makes \ref robust. How can one avoid this?
\documentclass{article}
\usepackage{newfile}
\newoutputstream{refFile}
\openoutputfile{\jobname.ref}{refFile}
\let\oldref\ref
\let\oldAutoref\autoref
\usepackage[linktoc=all,backref=page]{hyperref}
%%
%% Write SRC-DST of \ref to file
%%
\newcommand{\myref}[1]{%
\def\val{\thesection|\ref{#1}}
\addtostream{refFile}{\val}
}
%%
%% Redefine \autoref
%%
\let\oldAutoref\autoref
\renewcommand{\autoref}[1]{%
\oldAutoref{#1}
\myref{#1}
}
\begin{document}
\section{S1}\label{sec:one}
\autoref{sec:three}
\section{S2}\label{sec:two}
\autoref{sec:one}
\section{S3}\label{sec:three}
\autoref{sec:two}
\closeoutputstream{refFile}
\end{document}
The current content of the .ref file is
1|\ref {sec:three}
2|\ref {sec:one}
3|\ref {sec:two}
but I would like the expansion of the \ref to give:
1|3
2|1
3|2
\TheRealRefthat are not expanded in the output file. – wwjoze Mar 22 '13 at 16:13