How do I convert a BibTex bib file to Word 2010 XML?
Asked Answered
W

7

24

What's the best way to convert a Bibtex .bib file to an XML file that can be imported by MS Word 2010?

Willaims answered 21/2, 2013 at 1:20 Comment(0)
W
10

Here's the solution I found.

Bibutils, available in the Ubuntu repos, provides some tools for converting BibTex to Word XML, but there was some trouble with Word not importing some of the fields properly. Here's some Python Code to do it all in one go. So far i've got it going for @article and @inproceedings entries..

#THIS REQUIRES THAT bibutils IS INSTALLED ON YOUR MACHINE

"""
Usage:
./Bib2Word2010XML.py [Input file name] [Output file name]
"""

import sys
import fileinput
import os

if __name__ == '__main__':
  #input a BibTex .bib file
  fnameIN = sys.argv[1]
  fnameOUT = sys.argv[2]

  #run bibutils functions to convert to Word XML
  os.system("bib2xml " + fnameIN + " > TEMPOUT1.xml")
  os.system("xml2wordbib TEMPOUT1.xml > TEMPOUT2.xml")
  os.system("rm TEMPOUT1.xml")

  #clean up for Word 2010 formatting
  f1 = open('TEMPOUT2.xml', 'r')
  f2 = open(fnameOUT, 'w')
  for line in f1:
    line = line.replace("ArticleInAPeriodical", "JournalArticle")
    line = line.replace("PeriodicalName", "JournalName")
    line = line.replace("Proceedings", "ConferenceProceedings")
    f2.write(line)
  f1.close()
  f2.close()
  os.system("rm TEMPOUT2.xml")
Willaims answered 26/2, 2013 at 20:22 Comment(0)
U
25

The Java application JabRef is a great tool, I have used it successfully to export my BibTex entries to XML and imported them into Word 2013 with no problems at all.

Check it out at: http://www.jabref.org/

Uncanonical answered 3/3, 2013 at 1:20 Comment(2)
Any tool available in Lua Script?Greatniece
This was actually the easiest way for me, too. Just export from Zotero as BibTeX, open in JabRef, export via File -> Export and import as source in MS Word.Roadbed
W
10

Here's the solution I found.

Bibutils, available in the Ubuntu repos, provides some tools for converting BibTex to Word XML, but there was some trouble with Word not importing some of the fields properly. Here's some Python Code to do it all in one go. So far i've got it going for @article and @inproceedings entries..

#THIS REQUIRES THAT bibutils IS INSTALLED ON YOUR MACHINE

"""
Usage:
./Bib2Word2010XML.py [Input file name] [Output file name]
"""

import sys
import fileinput
import os

if __name__ == '__main__':
  #input a BibTex .bib file
  fnameIN = sys.argv[1]
  fnameOUT = sys.argv[2]

  #run bibutils functions to convert to Word XML
  os.system("bib2xml " + fnameIN + " > TEMPOUT1.xml")
  os.system("xml2wordbib TEMPOUT1.xml > TEMPOUT2.xml")
  os.system("rm TEMPOUT1.xml")

  #clean up for Word 2010 formatting
  f1 = open('TEMPOUT2.xml', 'r')
  f2 = open(fnameOUT, 'w')
  for line in f1:
    line = line.replace("ArticleInAPeriodical", "JournalArticle")
    line = line.replace("PeriodicalName", "JournalName")
    line = line.replace("Proceedings", "ConferenceProceedings")
    f2.write(line)
  f1.close()
  f2.close()
  os.system("rm TEMPOUT2.xml")
Willaims answered 26/2, 2013 at 20:22 Comment(0)
K
6

Based on impala79s' answer this one-liner worked for me using MS Word 2007. mybib.bib is the input bib file we want to convert to word format and word.xml is the output name of the file we want to save the wordbib format to. As stated above you need to install the bibutils package.

bib2xml mybib.bib | xml2wordbib | sed -e 's/PeriodicalName/PeriodicalTitle/g' -e 's/>Proceedings/>ConferenceProceedings/g' > word.xml

PS. You need bibutils package installed on your machine similarly with above answer

Kierakieran answered 16/6, 2015 at 6:41 Comment(1)
This answer is simple and elegant.Johnsonjohnsonese
H
3

Using the R port of bibutils (rbibutils) I managed to do it much simpler in Windows.

https://geobosh.github.io/rbibutils/

Install with

install.packages("rbibutils")

Then it's just one easy command:

rbibutils::bibConvert("myfile.bib", "myfile.xml", informat = "bibtex", outformat = "word")

Rember to include the quotes, as this is R.

Hydrotropism answered 19/10, 2020 at 7:26 Comment(1)
Any tool available in Lua Script?Greatniece
K
1

Based on Andreas Grivas script, I wrote and share you a multiple files bib to xml (word compatible) converter. You should run in inside the folder that contains your .bib files:

#this script convert a .bib file to xml file and to word xml file.
#this script use bibutils tools.


echo -e "===================\nscript to convert multiple .bib (bibtex)     files to word xml\n==================="

echo -e "Settings\n==================="

mypwd=$(pwd)
output=$(pwd)/output 
echo -e "Path:\n$mypwd"
echo -e "output folder:\n$output"
mkdir -p "${output}"

echo -e "===================\nProcessing"
counter=0
for file in *.bib; 
do
    counter=$((counter+1));
    name=${file%.*};
    echo -e "=================== \n$file"
    bib2xml $name.bib | xml2wordbib | sed -e "$mypwd" -e "$mypwd" > "$output/$name.xml"
done
echo -e "==================="
echo -e "$counter .bib files were found.\nDone!"enter code here
Kilburn answered 20/6, 2017 at 0:20 Comment(0)
U
1

The free reference manager software Mendeley also offers this option. You can open your .bib file and export to Endnote XML. You can download it at www.mendeley.com/download-desktop-new.

Upper answered 3/4, 2020 at 9:3 Comment(0)
Z
0

For those using Docker, https://github.com/derlin/docker-bib2word has a Dockerfile and a simple script to do the job.

To build the image:

git clone https://github.com/derlin/docker-bib2word
cd docker-bib2word
docker build -t bib2word --rm .

Then, just run:

docker run --rm -v $(pwd):/app bib2word biblio.tex

to convert biblio.tex into biblio.xml (the can be imported into word).

Zimmerman answered 2/5, 2018 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.