1 from pyP2B
.pyP2Bclass
import pyP2B
3 from accents
import latexAccents
6 def utf_to_latex(text
):
10 for search
, replace
in latexAccents
:
11 text
= text
.replace(search
, replace
)
21 parser
= optparse
.OptionParser(usage
='%prog [options] inputfile[.tex] <outputfile[.bib]>', version
='%prog version 0.1')
22 parser
.add_option('-m', '--makepdf', action
="store_true", default
=False, dest
='makepdf', help="Execute commands to create an output pdf")
23 parser
.add_option('-q', '--quiet', action
="store_true", default
=False, dest
='quiet', help="Do not use verbose output")
24 (args
, opts
) = parser
.parse_args()
27 (options
, args
) = parser
.parse_args()
28 verbose
= not options
.quiet
33 bibname
= '%s.bib' % os
.path
.splitext(args
[1])[0]
35 bibname
= '%s.bib' % os
.path
.splitext(args
[0])[0]
39 basefile
= os
.path
.splitext(args
[0])[0]
40 texname
= '%s.tex' % basefile
41 tex
= open(texname
).read()
44 print >>os
.sys
.stderr
, 'Cannot open file %s!' % args
[0]
47 bib
= open(bibname
, "w")
49 if verbose
: print >>os
.sys
.stdout
, 'Generating bibliography file %s...' % bibname
51 for m
in re
.findall("cite\{pmid(\d+)\}", tex
):
54 utf_text
= myref
.getPubmedReference(m
)
55 print >>bib
, utf_to_latex(utf_text
)
63 if bibSuccess
and options
.makepdf
:
65 output
= commands
.getoutput('rm %s.aux' % basefile
)
66 output
+= commands
.getoutput('pdflatex %s' % basefile
)
67 output
+= commands
.getoutput('bibtex %s' %basefile
)
68 output
+= commands
.getoutput('pdflatex %s' % basefile
)
69 output
+= commands
.getoutput('pdflatex %s' % basefile
)
72 print >>os
.sys
.stdout
, 'Generating pdf file %s.pdf...' % basefile
77 if __name__
== "__main__":