42

After a lot of struggle, I was successful with using a .bib file for the references in my .tex file using the following 2 lines of code:

\bibliographystyle{abbrv}
\bibliography{parallel-stochastic-hmm} 

Unfortunately, I just found out that I need to produce a single .tex file instead of using separate files. How do I insert the citations of my .bib file into my .tex file? Is there a special command for that?

3
  • You mean that you want to combine the formatted bibliography code directly into the .tex file?
    – Joseph Wright
    Apr 18 '12 at 7:18
  • 7
    Related question for biblatex: tex.stackexchange.com/q/20317/5701
    – N.N.
    Apr 18 '12 at 7:19
  • As mentioned here, you can simply use \input{my_file_name.bbl}.
    – Watson
    Feb 10 '21 at 14:03
34

After you run bibtex, you can copy the contents of the .bbl file into your document.

3
  • 2
    Should I remove the line \bibliography{parallel-stochastic-hmm} ?
    – Paul
    Apr 18 '12 at 7:25
  • 4
    Yes, the file contents replaces that line.
    – Ben
    Apr 18 '12 at 7:34
  • Fine. Would be fine some more details how exactly it can be integrated: at the end, any more commands, etc.
    – leon
    Feb 22 '21 at 2:45
40

You can use the filecontents package to insert the contents of your bib file into your tex file.

Here is an MWE of how it would look using biblatex and bibtex.

\documentclass{article}
\usepackage{filecontents}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
date = {2005},
}
\end{filecontents}

\usepackage[style=authoryear,backend=bibtex]{biblatex} %backend tells biblatex what you will be using to process the bibliography file
\addbibresource{jobname.bib}

\begin{document}
\nocite{*}
\printbibliography
\end{document}

Here is a MWE without using biblatex:

\documentclass{article}
\usepackage{filecontents}

\begin{filecontents}{jobname.bib}
@book{author_book,
title = {Book's title},
author = {Author, Some},
location = {The City},
publisher = {Publisher},
year = {2005},
}
\end{filecontents}

\begin{document}
\nocite{*}

\bibliographystyle{abbrv}
\bibliography{jobname}

\end{document}

When you compile this the first time, a bib file is created just like several other files are created (aux, toc, log, etc) so it shouldn't be a problem for whoever is requesting to have everything in a single file. After the first compile, you need to run bibtex as you normally would. Everything is pretty much the same.

Edit: I see now that using filecontents is the solution in the post to which @N.N. pointed in his comment.

3
  • jobname should probably be \jobname to replace it with the name of the current file. Oct 4 '18 at 7:43
  • Thank you very much for posting both options
    – leon
    Feb 22 '21 at 2:46
  • According to ctan.org/pkg/filecontents , the filecontents functionality is available in recent latex kernels
    – Gus
    Apr 8 '21 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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