I'm working on a (very) large document and I'd prefer to define my biblio entries as close as possible to the text I'm working on. Therefore, I'm using the "filecontents" package, to define separate files, and a counter as a suffix. After a first pass using Latex, I only have to merge the entries into a single file - using MSDOS copy /b %WORKDIR%\biblio.* .\biblio.bib - before calling biber and executing LaTeX again. The following code is working.
\documentclass[]{article}
\usepackage[autostyle]{csquotes}
\usepackage{lipsum}
\usepackage[backend=biber,doi=false,url=true,eprint=true,style=ieee]{biblatex}
\usepackage[]{hyperref}
\hypersetup{colorlinks=true}
\usepackage{filecontents}
\newcounter{BibFileCount}
\addbibresource{biblio.bib}
\begin{document}
\stepcounter{BibFileCount}\begin{filecontents}{biblio.\arabic{BibFileCount}}
@article{kastenholz,
author = {Kastenholz, M. A. and H{\"u}nenberger, Philippe H.},
title = {Computation of methodology\hyphen independent ionic solvation
free energies from molecular simulations},
journaltitle = jchph,
date = 2006,
subtitle = {I. The electrostatic potential in molecular liquids},
volume = 124,
eid = 124106,
doi = {10.1063/1.2172593},
langid = {english},
langidopts = {variant=american},
indextitle = {Computation of ionic solvation free energies},
annotation = {An \texttt{article} entry with an \texttt{eid} and a
\texttt{doi} field. Note that the \textsc{doi} is transformed
into a clickable link if \texttt{hyperref} support has been
enabled},
}
\end{filecontents}
\stepcounter{BibFileCount}\begin{filecontents}{biblio.\arabic{BibFileCount}}
@article{sigfridsson,
author = {Sigfridsson, Emma and Ryde, Ulf},
title = {Comparison of methods for deriving atomic charges from the
electrostatic potential and moments},
journaltitle = {Journal of Computational Chemistry},
date = 1998,
volume = 19,
number = 4,
pages = {377-395},
doi = {10.1002/(SICI)1096-987X(199803)19:4<377::AID-JCC1>3.0.CO;2-P},
langid = {english},
langidopts = {variant=american},
indextitle = {Methods for deriving atomic charges},
annotation = {An \texttt{article} entry with \texttt{volume},
\texttt{number}, and \texttt{doi} fields. Note that the
\textsc{doi} is transformed into a clickable link if
\texttt{hyperref} support has been enabled},
}
\end{filecontents}
Lorem ipsum dolor sit amet~\supercite{kastenholz}.
At vero eos et accusam et justo duo dolores et ea rebum~\supercite{sigfridsson}.
\printbibliography
\end{document}
However, when trying to create a macro, the creation of my entries fails (the created file is empty). I suspect that the biblio entries are interpreted by LaTeX before being passed as a macro argument, and I don't know how to prevent that. So, this code is wrong:
\newcounter{BibFileCount}
\newcommand{\addbiblioref}[1]{
\stepcounter{BibFileCount}
\begin{filecontents}{biblio.\arabic{BibFileCount}}
#1
\end{filecontents}
}
\addbiblioref{
@book{massa,
author = {Werner Massa},
title = {Crystal structure determination},
date = 2004,
edition = 2,
publisher = {Spinger},
location = {Berlin},
langid = {english},
langidopts = {variant=british},
annotation = {A \texttt{book} entry with an \texttt{edition} field},
}
}
Any idea to help me? Thanks in advance.
fancyvrbpackage a new environment for writing out a file. – egreg Apr 13 '14 at 10:12