[Tex/LaTex] Can a LaTeX file include the BibTeX file

biblatexbibtex

Is there a way to include the BibTeX content in the LaTeX file?

The issue came up during a revision submission to a journal. I could submit a new main file but I did not see a way of submitting a new BibTeX file. So the natural question was if I can combine them into a single file

Best Answer

filecontents

Phelype Oleinik mentions the filecontents environment in the comments and purely from the title of your question I would have said that is what you are looking for (assuming that BibTeX file means .bib file).

filecontents can be used to include an arbitrary file in a .tex file. That file will be written into the working directory (usually the folder where your main .tex file lives), if it does not exist already (if additionally you load the filecontents package, filecontents overwrites existing files) when TeX compiles the .tex file.

So

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{natbib}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@book{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  year    = {1980},
}
\end{filecontents}

\begin{document}
\cite{appleby}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

Will produce a .bib file with the same name as the .tex file and that file can then be used to produce the bibliography.

filecontents is extremely useful if you want to provide self-contained files for other people for testing, it is also very good for MWEs on this site. But it is usually not what publishers want when they ask you to submit the bibliography in your .tex file. This is what the body of your question seems to be about. Publishers then usually talk about the .bbl file.

.bbl files for BibTeX-based bibliographies

When you compile the example from above with LaTeX, BibTeX, LaTeX, LaTeX you get a document with a fully working bibliography. The key to that bibliography is the .bbl file that is produced by the BibTeX run. You can learn more about it at Question mark or bold citation key instead of citation number, but in a nutshell the .bbl file contains the bibliography in a format that is ready to typeset for LaTeX in a thebibliography environment that one could also produce manually.

The .bbl file for the example above contains (amongst others, I shortened it a bit)

\begin{thebibliography}{1}
\bibitem[Appleby(1980)]{appleby}
Humphrey Appleby.
\newblock \emph{On the Importance of the Civil Service}.
\newblock 1980.
\end{thebibliography}

that code can be directly typeset by LaTeX.

Indeed, if you replace the the line

\bibliography{\jobname}

from the example above with the entire contents of the .bbl and throw out the filecontents to obtain

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage{natbib}

\begin{document}
\cite{appleby}
\bibliographystyle{plainnat}
\begin{thebibliography}{1}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\expandafter\ifx\csname urlstyle\endcsname\relax
  \providecommand{\doi}[1]{doi: #1}\else
  \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi

\bibitem[Appleby(1980)]{appleby}
Humphrey Appleby.
\newblock \emph{On the Importance of the Civil Service}.
\newblock 1980.

\end{thebibliography}
\end{document}

you get a document that can be compiled with LaTeX alone to produce the same document with a bibliography and working citations.

This is what many publishers would like you to submit, since that is one document that contains all typesettable material directly and does not require additional runs of auxiliary tools like BibTeX. See also https://www.overleaf.com/help/219.

Some journals may not need you to copy the contents of the .bbl file into the .tex file directly and instead ask you to submit the .tex and .bbl file together, but they rarely want the .bib file.

.bbl files for biblatex

.bbl files for biblatex do not contain ready-to-typeset TeX code, instead they contain the extended and sorted raw data in a format that is easier to digest for LaTeX than the .bib files The formatting still has to be done on the biblatex side. That means that it is not as easy to just copy and paste the .bbl contents.

It is possible to include a biblatex-.bbl into a .tex as explained in Biblatex: submitting to a journal, but that is rarely what journals want or need. For one the .bbl file is intimately tied to a specific version of biblatex (and Biber), which means that your version and your publisher's version of the software must be the same. Secondly, not many publishers can deal with biblatex anyway as it requires a different workflow than BibTeX-based bibliographies, so it is unlikely that they can accept a submission even if you include the .bbl file and you have matching versions.

People submitting to the arXiv, which allows biblatex submissions, often have version problems and need to find old versions of biblatex and Biber to make things work. See Making the arXiv accept a BibTeX BBL (May 2018).