#!/usr/bin/python
# Program mrefh.py converts typical .bbl file into html format
# with MR links by reference to MR database using MREF
# Written by Jim Pitman pitman@stat.berkeley.edu 10/10/03.
# Uses standard input and standard output.
# e.g. on unix system, save program in a file mrefh.py then do
# chmod +x mrefh.py
# then starting from a file refs.bbl to create refs.html usage is
# cat refs.bbl | mrefh.py > refs.html
import urllib,string,sys
flag1 = r'\item'
flag2 = r'\bibitem'
htmltop = '''
TITLE HERE
'''
htmlbot = '
'
tst = '''\bibitem{p72}
C.R. Heathcote and J.~Pitman.
\newblock An inequality for characteristic functions.
\newblock {\em Bull. Aust. Math. Soc.}, 6:1--10, 1972.
'''
def mref(texstring):
front = r'http://www.ams.org/mathscinet-mref?ref='
back = r'&mref-submit=Search&dataType=bibtex'
back = r'&mref-submit=Search&dataType=mathscinet'
address = '%s%s%s' % (front,urllib.quote_plus(texstring),back)
infile = urllib.urlopen(address)
while 1:
line = infile.readline()
if string.find(line,'No Unique Match Found') >=0 :
print '' + texstring + ' |
'
break
if not line : break
if string.find(line,'Matched') >= 0:
break
while 1:
if string.find(line,'No Unique Match Found') >=0 :
break
line = infile.readline()
if not line : break
if string.find(line,'getitem') >= 0:
print line
break
print line,
f = sys.stdin
currentstring = ''
addline = 0
def printout(xstring):
print
print htmltop
while 1:
line = f.readline()
if not line :
mref(currentstring)
break
if string.find(line,flag1) >= 0 or string.find(line,flag2) >= 0:
addline = 1
mref(currentstring)
currentstring = line
elif addline == 1:
currentstring = currentstring + line
print htmlbot