31

Is there a way to have references in the same latex file (i.e. instead of having the references in a separate .bib file)

2
28

Yes and no.

You can create your own bibliography manually:

\begin{thebibliography}{xx}
  \bibitem{abc}
  \textsc{Author}, \textit{Title}, ...

  ...

\end{thebibliography}

However, this lacks consistency through automation as well as ease-of-maintenance.

A far better alternative to handling a bibliography "within the same file" would be to embed it via the aid of thefilecontents or filecontents* environment (with the overwrite option to accommodate perpetual changes). This way you can manage your bibliography within the main TeX file, while it is actually always written out to file for use in the expected way.

Here is an example:

\documentclass{article}

\usepackage{biblatex}

\begin{filecontents*}[overwrite]{general.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
\end{filecontents*}

\addbibresource{general.bib}

\nocite{*}

\begin{document}

\printbibliography

\end{document}

The file general.bib is overwritten with every compilation, allowing you to add/remove bibliography entries as you please. Every change, however, should still be accompanied with the appropriate BibTeX engine (biber in the above case).

9
  • this code needs a biblatex.sty file, how to do that? – user3741635 Jun 16 '14 at 13:28
  • @user3741635 you need to install biblatex. On miktex and texlive there are package installers to do this for you. – Chris H Jun 16 '14 at 15:24
  • @user3741635: You can follow the direction in How do I update my TeX distribution? to install packages. If you're talking about the general use of a bibliography and how to obtain/display it in your document, then that's a different question. That requires a compilation sequence (pdf)LaTeX > BibTeX/Biber > (pdf)LaTeX (and possibly one more (pdf)LaTeX). – Werner Jun 16 '14 at 15:37
  • 1
    @DiaaAbidou: The filecontents environment adds a specific 4-line commented header to the output file (see page 2 of the filecontents documentation). filecontents* does not add this header. You'd use filecontents* when eventual reading may have comments (via %) interpreted; this is typically the case when you would read in via (say) \lstinputlisting. – Werner Mar 2 '17 at 16:22
  • 1
    @zyy: You need need to compile multiple times with every change in the bibliography. Once there aren't changes, a single compilation should suffice. The same goes for references. – Werner Jan 12 '20 at 17:47
9

In case this is the request of a publisher who wants only one file compiling with standard packages only, the classical way of doing this is:

  1. Use bibtex or biblatex as usual when preparing your manuscript, say manuscript.tex.

  2. Before sending to the publisher, make a copy your manuscript .tex file, say to submitted_version.tex, edit that copy and replace the lines calling Bibtex by the contents of the manuscript.bbl file.

Send that file submitted_version.tex to the publisher.

1
  • Though this is common, all cases I've come across for this require bibtex not biblatex - be warned :) – Chris H Jun 16 '14 at 15:23
3

In addition, you may use the amsrefs-package.

According to the documentation, there are three ways of using the package:

  1. Enter bibliography items directly in your LaTeX-document using the biblist-environment and the \bib-command.
  2. Import items from an external .ltb-file.
  3. Import items from a .bib file using BibTeX and the special bibliography styles distributed with the amsrefs-package

Item 1 is the method you are asking for. The amsrefs-package is included in TeX-distributions.

2
  • An example for the how to use the syntax would be really nice – lucidbrot Aug 5 '20 at 20:59
  • 1
    @lucidbrot The package documentation offers simple examples for each of the three methods at the beginning itself. You may glance through it to gather an idea of what it's like. – The Amplitwist 2 days ago

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.