Converting to bibitem in LaTeX
I agree whith the general process explained in the comments, but i think that they don't fully address the final task that you must do you for the conference, which very likely want a single self contained .tex
file.
Let's assume that you have mypaper.tex
which is your text with some \cite{<key>}
and a refs.bib
file. Then :
Firstly, put in
mypaper.tex
the two lines :\bibliography{refs} \bibliographystyle{plain}
Secondly run (instead of using the
\nocite
which has two drawbacks: (1) ordering as inrefs.bib
and (2) cites refs. that are not\cite
-d in your paper) :(pdf)latex mypaper bibtex mypaper
If this step is successful you will get
mypaper.bbl
containing thebibitem
-s and amypaper.blg
which is BiBTeX's log file. (Nota :latex
reads themypaper.tex
-- and when present themypaper.bbl
file -- butbibtex
reads themypaper.aux
created bylatex
).Thirdly, (optional but recommended) make sure that all the reference are correctly inserted and displayed in the file with :
(pdf)latex mypaper
Fourthly, open
mypaper.tex
, comment out or discard the two\biblio...
lines and paste the whole content ofmypaper.bbl
at the place where you want to get the bibliography. You then have the final self-contained file.You can run
(pdf)latex mypaper
at least two times to get the final.dvi
or.pdf
.
Edit: This copy-paste holds if he .bbl
file content start with the regular \begin{thebibliography}
. If it starts by loading packages with \usepackage{<name>}
or even by \input{<name>.sty}
(where <name>
= csquote, url, etc.) you must move them in your preamble. If it starts by defining commands, your can keep them at this place or move them to the preamble.
Note for the OP: you use plain
as the format, which looks strange for me. Actually each conference/organization generally has its own .bst
style file which produces \bibitem
formated accordingly to their editorial rules. More specifically, make sure that you need an alphabetical-ordered or a citation-ordered bibliography. In the later case, you must use the unsrt.bst
(or a variant) in place of plain.bst
.
The Python code to convert refs.bib file to bibitem file
python2 bibtex2item.py < refs.bib > bibitem.txt
# filename: bibtex2item.py
import sys
bibtex = sys.stdin.read()
r = bibtex.split('\n')
i = 0
while i < len(r):
line = r[i].strip()
if not line: i += 1
if '@' == line[0]:
code = line.split('{')[-1][:-1]
title = venue = volume = number = pages = year = publisher = authors = None
output_authors = []
i += 1
while i < len(r) and '@' not in r[i]:
line = r[i].strip()
#print(line)
if line.startswith("title"):
title = line.split('{')[-1][:-2]
elif line.startswith("journal"):
venue = line.split('{')[-1][:-2]
elif line.startswith("volume"):
volume = line.split('{')[-1][:-2]
elif line.startswith("number"):
number = line.split('{')[-1][:-2]
elif line.startswith("pages"):
pages = line.split('{')[-1][:-2]
elif line.startswith("year"):
year = line.split('{')[-1][:-2]
elif line.startswith("publisher"):
publisher = line.split('{')[-1][:-2]
elif line.startswith("author"):
authors = line[line.find("{")+1:line.rfind("}")]
for LastFirst in authors.split('and'):
lf = LastFirst.replace(' ', '').split(',')
if len(lf) != 2: continue
last, first = lf[0], lf[1]
output_authors.append("{}, {}.".format(last.capitalize(), first.capitalize()[0]))
i += 1
print "\\bibitem{%s}" % code
if len(output_authors) == 1:
print output_authors[0] + " {}. ".format(title),
else:
print ", ".join(_ for _ in output_authors[:-1]) + " & " + output_authors[-1] + " {}. ".format(title),
if venue:
print "{{\\em {}}}.".format(" ".join([_.capitalize() for _ in venue.split(' ')])),
if volume:
sys.stdout.write(" \\textbf{{{}}}".format(volume))
if pages:
sys.stdout.write(", {}".format(pages) if number else " pp. {}".format(pages))
if year:
sys.stdout.write(" ({})".format(year))
if publisher and not venue:
print "({},{})".format(publisher, year)
print
print
sample input
@article{karrer2011stochastic,
title={Stochastic blockmodels and community structure in networks},
author={Karrer, Brian and Newman, Mark EJ},
journal={Physical Review E},
volume={83},
number={1},
pages={016107},
year={2011},
publisher={APS}
}
sample output
\bibitem{karrer2011stochastic}
Karrer, B. & Newman, M. Stochastic blockmodels and community structure in networks. {\em Physical Review E}. \textbf{83}, 016107 (2011)