9

I am collaborating with another author using email to exchange latest version of the document. Is it possible to include the bibliography in the LaTeX file, so that we don't have to keep two files in synch? (however I would still like it to be in BibTeX format, I know you can have manual \bibitems in LaTeX files)

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
Grzenio
  • 9,465
  • Since 2019, the filecontents package is not needed anymore. Here's how a bibliography could be included directly into the .tex file: https://tex.stackexchange.com/a/698139/ – finnan Oct 10 '23 at 14:19

2 Answers2

12

You can include it using the filecontents environment:

\usepackage{filecontents}
\begin{filecontents}{example.bib}
% File contents here
\end{filecontents}
\documentclass{article}
...

This will extract the file only if it does not already exist locally. (You'll see this approach used a lot for examples on sites such as this one. It's handy for small snippets but is more awkward when things get very long.)

Cyrille
  • 150
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • 3
    @Joseph: it makes more sense to load the package filecontents first and then writing the file. Then one can also edit the exported file and it will be updated, otherwise not. –  Feb 03 '11 at 21:27
  • @Herbert. I only ever use filecontents for a 'one-shot' unpack, so I will take your word for this. – Joseph Wright Feb 03 '11 at 21:30
  • 1
    @Joseph: and you never had typos in your "one shots" ;-) you are a lucky man –  Feb 03 '11 at 21:31
  • @Herbert. No, but I just delete the file (eventually, when I remember). I use filecontents for examples, so am usually attempting to keep additional packages down to a minimum. – Joseph Wright Feb 03 '11 at 21:32
  • @Joseph, is it possible to add this content at the end of the file (an not at the beginning)? That's where bibliography usually goes anyway... – Grzenio Feb 04 '11 at 11:35
  • BibTex doesn't seem to understand filecontents, it reports I couldn't open database file ir.bib – Grzenio Feb 04 '11 at 11:47
5

You should use a revision control system for multiple author documents. There are a lot of programs like subversion or git or ... That makes the email exchange superflous and you get a backup system, too.

  • 1
    You are assuming that the co-authors are comfortable with this. That's fine if they are programmers, but if they are not then LaTeX alone may well be 'quite enough computer stuff'. – Joseph Wright Feb 03 '11 at 21:26
  • No, I didn't assume that. I said, that it is really comfortable for multiple authors. –  Feb 03 '11 at 21:29
  • 1
    Again, I'll take your word for it: my co-authors get annoyed at me if I mention using anything other than Word (and I mean Word only: OpenOffice is already considered dangerous.) – Joseph Wright Feb 03 '11 at 21:35
  • Most VCSes have some GUIs nowadays (or so I'm told), so it really shouldn't be that difficult if they are already comfortable with handling TeX. Otherwise, on can always at least use this technique to keep files in sync at one side. – Caramdir Feb 03 '11 at 21:51
  • 1
    I was thinking about this (I am using mercurial just for myself), but it seems a bit too complicated to set up just to write 20 page long paper with this person. I agree its the best solution if we decide to work together on more projects. – Grzenio Feb 04 '11 at 11:34