## Inserting .bib into .tex for a single source file

• Post category:Tips

If you’re familiar with LaTeX, you might be thinking

Why the heck would you want to insert .bib into .tex?
Well, lots of journals ask authors to submit a single .tex file, merged with .bib, for LaTeX manuscript submissions. As of 2021, this nonsense is still happening with many publishers, even the Nature Publishing Group that you might expect to have modernized their process.

I have a lot to say about the atrocious, outdated systems that make you wonder where all those publishing fees are going (like RSC journals still not supporting vector graphics), but that is another long story. At the end of the day, academics usually have no choice but to suck it up and provide what the journals/publishers want.

Here is the simplest solution for inserting .bib contents into a .tex file. Insert the following code in the preamble (safest to put it before \documentclass):

\begin{filecontents*}{yourfilename.bib}
%paste your .bib file content here
\end{filecontents*}

That is all you need to do. You will have the same code line loading your .bib file, such as \addbibresource{yourfilename.bib} for BibLaTeX (with Biber backend) users or \bibliography{yourfilename} for BibTeX users.

If you’re curious why this works, let me explain. This code at the beginning will generate a file “yourfilename.bib” in the path where you are running your .tex file. Then, by the time your code looks for the .bib file, it will be there and ready to be loaded. Note that if there is already an existing .bib file with the same filename, then this \begin{filecontents*} ... \end{filecontents*} code will simply do nothing. So, if you want to test if your file is working, put your .tex in an empty directory before compiling it. Some journals instruct you with other routes, like copying contents of .bbl into your .tex code. But I noticed that this doesn’t work when using the biber backend.

Hope this helps! I originally found this solution posted on stack exchange if you want to learn more details about it!