Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Converting Bibitem into Bibtex Entry with Perl

by monkfan (Curate)
on Jun 08, 2007 at 07:11 UTC ( #619969=perlquestion: print w/ replies, xml ) Need Help??
monkfan has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
Do you guys happen to know if there is existing Perl implementation for converting BIBITEM entry like this:
\bibitem[Ao {\it et~al}., 2004]{AGKM04} Ao, W. {\it et~al.} (2001) Som +e long title 1, {\it Science}, {\bf 305}, 1743-1746. \bibitem[Bailey and Elkan, 1995]{BE95} Bailey, T. Elkan, C. (1995) S +ome long title 2 {\it Machine Learning}, {\bf 21}, 51-80.
Into BIBTEX entry like this:
@article{AGKM04, author = {Ao, W and \ {\it et~al.}}, title = {Some long title 1}, journal = {Science}, year = {2004}, volume= {305}, pages = {1743-1746}, } @article{BE95, author = {Bailey, T and Elkan, C.}, title = {Some long title 2}, journal = {Machine Learning}, year = {1995}, volume= {21}, pages = {51-80}, }

Regards,
Edward

Comment on Converting Bibitem into Bibtex Entry with Perl
Select or Download Code
Re: Converting Bibitem into Bibtex Entry with Perl
by Corion (Pope) on Jun 08, 2007 at 07:21 UTC

    What have you tried so far? I'd simply parse out the information with a regular expression (untested):

    use strict; for my $item (<DATA>) { chomp $item; if ($item !~ /^\\bibitem\[.*?\] # skip the command and optional +argument \{([A-Z\d]+)\] # extract the bibliography item, + all caps letters \s*(.*?) # extract the author list \((\d{4})\) # extract the year (.*?) # extract the publication title \{\\it\s(.*?)\}, # extract the category \s*\{\\bf\s(\d+)\},# extract the volume \s*(\d+-\d+) # extract the page numbers \. # a dot at the end /x) { print "%% Ignoring weird bibliography item: >$item<\n"; next; }; printf <<'TEX',$1,$2,$3,... @article{%s, ... TEX }; __DATA__ \bibitem[Ao {\it et~al}., 2004]{AGKM04} Ao, W. {\it et~al.} (2001) Som +e long title 1, {\it Science}, {\bf 305}, 1743-1746. \bibitem[Bailey and Elkan, 1995]{BE95} Bailey, T. Elkan, C. (1995) Som +e long title 2 {\it Machine Learning}, {\bf 21}, 51-80.
Re: Converting Bibitem into Bibtex Entry with Perl
by andreas1234567 (Vicar) on Jun 08, 2007 at 07:57 UTC
    Perhaps Text::BibTeX could be useful?

    Update:Try the Tex2bib script on this site.

    --
    print map{chr}unpack(q{A3}x24,q{074117115116032097110111116104101114032080101114108032104097099107101114})

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://619969]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2014-07-22 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (106 votes), past polls