35

Is there any way to use BibTex entries in thebibliography environment like following:

\begin{thebibliography}{9}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}

@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}

\end{thebibliography}

For example consider that you want to quickly write a note that refers to three papers those their BibTex entries are available (perhaps via scholar.google.com ), it is easier that you directly insert them to your document instead of creating a .bib file or converting bibtex entries.

7
  • no that is not possible.
    – user2478
    Jun 21, 2012 at 6:31
  • 5
    You can use \begin{filecontents}{\jobname.bib} ... \end{filecontents} to create your bibliography on the fly, from one document. For extended filecontent environments, use the filecontents package.
    – matth
    Jun 21, 2012 at 7:50
  • 2
    @VafaKhalighi it means you only have to keep track of one file. I often don't want to share my entire bib file with collaborators.
    – StrongBad
    Jun 21, 2012 at 9:19
  • 2
    @DanielE.Shub That seems to be one of the reasons why the filecontents package was developed. The normal filecontents environment does not overwrite files, but the filecontents environment provided by the filecontents packge does.
    – matth
    Jun 21, 2012 at 9:44
  • 1
    possible duplicate: tex.stackexchange.com/questions/10201/…
    – matth
    Jun 21, 2012 at 10:01

2 Answers 2

33

Converting my comments into an answer: Maybe the filecontents package can do what you want.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{greenwade93,
    author  = "George D. Greenwade",
    title   = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
    year    = "1993",
    journal = "TUGBoat",
    volume  = "14",
    number  = "3",
    pages   = "342--351"
}
@book{goossens93,
    author    = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
    title     = "The LaTeX Companion",
    year      = "1993",
    publisher = "Addison-Wesley",
    address   = "Reading, Massachusetts"
}
\end{filecontents}

\usepackage{natbib}

\begin{document}
Lorem ipsum~\citep{goossens93}.
Dolor sit amet~\citet{greenwade93}.
\bibliographystyle{plainnat}
\bibliography{\jobname} 
\end{document}

In contrast to the filecontents environment provided by LaTeX2e, the filecontents environment provided by the filecontents packge does overwrite existing files.

3
  • 2
    remember that bibtex still has to be run separately. no getting around that. Jun 21, 2012 at 13:06
  • 2
    @barbarabeeton: put \immediate\write18{bibtex \jobname} after the end of filecontents environment and run pdflatex with shell-escape option. Jun 22, 2012 at 6:27
  • 1
    Thanks a lot! I am not sure why but I had to remove the escape from the file name. Namely I had to change \jobname to jobname.
    – djhurio
    Jul 29, 2021 at 13:51
3

You can do it, to a perhaps limited extent, with amsrefs:

\documentclass{article}
\usepackage{amsrefs}
\newenvironment{rezabib}
  {\bibdiv\biblist\setupbib}
  {\endbiblist\endbibdiv}

\def\setupbib{\catcode`@=\active}
\begingroup\lccode`~=`@
  \lowercase{\endgroup\def~}#1#{\gatherkey{#1}}
\def\gatherkey#1#2{\gatherkeyaux{#1}#2\gatherkeyaux}
\def\gatherkeyaux#1#2,#3\gatherkeyaux{\bib{#2}{#1}{#3}}

\begin{document}

\nocite{*}

\begin{rezabib}
@article{greenwade93,
    author  = {George D. Greenwade},
    title   = {The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})},
    year    = {1993},
    journal = {TUGBoat},
    volume  = {14},
    number  = {3},
    pages   = {342--351}
}

@book{goossens93,
    author    = {Michel Goossens and Frank Mittelbach and Alexander Samarin},
    title     = {The LaTeX Companion},
    year      = {1993},
    publisher = {Addison-Wesley},
    address   = {Reading, Massachusetts}
}
\end{rezabib}

\end{document}

Note that you must use braces for delimiting fields. There should be no additional space in the starting lines for entries

@book{goossens93,

The limitation on spaces might be lifted, but not the one on delimiting braces. You can't use @ in fields (also this may be lifted, if really needed).

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.