Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Why would anybody want to do that? –  Vafa Khalighi Jun 21 '12 at 6:31
2  
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 '12 at 7:50
1  
@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 '12 at 9:19
1  
@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 '12 at 9:44
1  
possible duplicate: tex.stackexchange.com/questions/10201/… –  matth Jun 21 '12 at 10:01

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
2  
remember that bibtex still has to be run separately. no getting around that. –  barbara beeton Jun 21 '12 at 13:06
2  
@barbarabeeton: put \immediate\write18{bibtex \jobname} after the end of filecontents environment and run pdflatex with shell-escape option. –  Vafa Khalighi Jun 22 '12 at 6:27

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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