5

I have an old document written in LaTeX which I need to edit/re-write. The document has hundreds of citations without using BibTex but just old style thebibliography environment and \bibitem's. Now I would like to re-use the old bibliographic references and add new ones but using BibTex. Is there a way I can re-use my old references? The thing that comes to mind is a script or something which translates \bibitem's entry and put them into BibTex format, but any solution is welcome. By the way, a (admittedly superficial) search on google and stack exchange did not provide any solution.

  • 2
    I can feel your pain but believe me you are going to save much more time if you convert everything into a .bib file. Many sites offer BibTeX export option and Jabref can search too. So my recommendation is bite the bullet and convert everything at once. You'll waste some hours but save a lot in the long run. – percusse Oct 1 '14 at 21:04
  • 1
    You can script something together that adds fields to a database-field/entry. But if books and articles have a different format, it will be error prone. – Johannes_B Oct 1 '14 at 21:07
  • 1
    I could imagine this being an interesting regular expression programming problem (i.e., everything in the \bibitem braces is a variable called $key, everything in the \emph braces is a variable called $title, ...), but if the number of entries is only on the scale of hundreds, you're about as well off to copy and paste from the \bibitem entries. – Mike Renfro Oct 1 '14 at 21:08
  • @percusse I appreciate your sympathy. Are you suggesting I should convert my \bibitem's entry manually? – lcv Oct 1 '14 at 21:09
  • 1
    One other note: if you decided to script the conversion, you'll probably have to edit lots of your entries if you ever go to a different bibliography style. My default recommendations are to treat your bibtex entries as data, not as formatted output. Treat them like data (cleaning up the entries manually), and changing styles will be easy. Treat them like formatted output, and changing styles will result in a mix of old style and new, and a lot of edit requests from the journal. – Mike Renfro Oct 1 '14 at 21:25
2

Based on a quick google search, there are a couple of scripts that might work:

tex2bib: http://mirror.ctan.org/biblio/bibtex/utils/tex2bib

convertbiblio http://www.mi.infm.it/manini/scripts/convertbiblio.py

Usual caveats of course apply to running scripts from the internet! As others have indicated, you will likely have to clean your entries up manually. Scraping bibliographic data from formatted entries is not trivial, especially if you use a heavily customized style.

Credit to the TeX FAQ for linking to tex2bib.

  • Thanks I had overlooked those scripts! I'll wait a sec if there are better options, if not I'm going to accept your answer. – lcv Oct 2 '14 at 0:22
2

I came up with a simple solution to this problem.

Unfortunately this solution works only for those who have references registered in the https://inspirehep.net/ website.

Here it goes:

First, I wrote a file with all my references (which I called bib.txt). Here is an example of what it contains:

%\cite{White:2012zza}
\bibitem{White:2012zza} 
  R.~M.~White [BaBar Collaboration],
  %``Recent charm physics results from BaBar,''
  J.\ Phys.\ Conf.\ Ser.\  {\bf 347}, 012026 (2012).
  %%CITATION = 00462,347,012026;%%


 %\cite{Zupanc:2013byn}
  \bibitem{Zupanc:2013byn} 
    A.~Zupanc {\it et al.}  [Belle Collaboration],
    %``Measurements of branching fractions of leptonic and hadronic $D_{s}^{+}$ meson decays and extraction of the $D_{s}^{+}$ meson decay constant,''
  JHEP {\bf 1309}, 139 (2013)
 [arXiv:1307.6240 [hep-ex]].
%%CITATION = ARXIV:1307.6240;%%
 %13 citations counted in INSPIRE as of 04 Nov 2014kda

Thus, I wrote a script (attached at the end of the answer) on mathematica that read the file and output it into a file "bibform.tex" in a specific format so that when you submit it to this website (https://inspirehep.net/submit?doctype=bibtex&act=SBI) it gives you the desired format for you reference style.

SetDirectory[NotebookDirectory[]];
file = OpenRead["bib.txt"];
x = ReadList[file, String];
Close[file];

file = OpenWrite["bibform.tex"];
WriteString[file, "\\documentclass[a4paper,12pt]{article}"];
WriteString[file, "\\begin{document}"];
j = 0;

Do[
If[StringMatchQ[x[[i]], "*" <> "\cite{" <> "*"],
WriteString[file, 
"a~\\cite{" <> 
 StringSplit[StringSplit[x[[i]], "}"][[1]], "{"][[2]] <> "}" <> 
 "\n\n"];
j = j + 1;
  ];
, {i, 1, Length[x]}]

WriteString[file, "\\end{document}"];
Print["Found " <> ToString[j] <> "  References.\n"]
Print["File Writen:"]
Close[file]
Print["Upload the file to: \

https://inspirehep.net/submit?doctype=bibtex&act=SBI\n to get the \
output format."]
  • Nice solution, I will look into that. It would be nice if it could crawl into other databases to find the bibitem entry (my references are not listed on INSPIRE). But I'm sure it may help others. – lcv Dec 2 '16 at 0:26

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.