How to write the result of a citation to a file?
You can't use \cite
because this has several instruction for printing the citation key.
You need to use \b@<key>
, for instance like this:
\documentclass{article}
\newwrite\tempfile
\AtBeginDocument{\immediate\openout\tempfile=\jobname.txt}
\makeatletter
\newcommand{\writecite}[1]{%
\@for\next:=#1\do{%
\immediate\write\tempfile{%
\@ifundefined{b@\next}{[<\next>]}{[\csname b@\next\endcsname]}%
}%
}%
}
\makeatother
\begin{document}
\cite{Ab,Cd}
\writecite{Ab,Cd}
\begin{thebibliography}{1}
\bibitem{Ab} Author, title, 2016.
\bibitem{Cd} Common, Second, 2015.
\end{thebibliography}
\end{document}
Contents after the first run
[<Ab>]
[<Cd>]
Contents after the second run
[1]
[2]