Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Welcome to TeX.SX! –  Heiko Oberdiek Apr 13 at 9:40
    
Verbatim-like environments cannot be in the argument to another command. You can define, with the help of the fancyvrb package a new environment for writing out a file. –  egreg Apr 13 at 10:12

1 Answer 1

up vote 4 down vote accepted

Verbatim-like environments cannot be in the argument to another command. You can define, with the help of the fancyvrb package a new environment for writing out a file:

\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{fancyvrb}
\newcounter{BibFileCount}
\newenvironment{addbiblioref}
 {\stepcounter{BibFileCount}%
  \VerbatimEnvironment
  \begin{VerbatimOut}{biblio.\theBibFileCount}}
 {\end{VerbatimOut}}

\addbibresource{biblio.bib}

\begin{document}

\begin{addbiblioref}
@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{addbiblioref}

\begin{addbiblioref}
@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{addbiblioref}

    Lorem ipsum dolor sit amet~\supercite{kastenholz}.
    At vero eos et accusam et justo duo dolores et ea rebum~\supercite{sigfridsson}.

    \printbibliography 
\end{document}

Here's the .1 file, for a check:

@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},
}

However, I don't think that having the bibliographic entries scattered among the document is helpful. I'm rather convinced it's very unhelpful.

share|improve this answer
    
Many thanks for your answer It works very well now. Scattering (or not) biblio entries can be debated: I think it's useful in my case, because my references are cited once or twice in my text and because I've a lot of these. So, when reading my LaTeX source, I can easily come back to my reference when I need to fine-tune or to crosscheck. And when printing, all the refs are put at the end of the book. In this specific case, this approach is very convenient to me. –  Eric Detienne May 3 at 8:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.