

def formulaeToImages(document, dir, _system=os.system):
    macros = ''
    for node in domhelpers.findElementsWithAttribute(document, 'class', 'latexmacros'):
        macros += domhelpers.getNodeText(node)
        node.parentNode.removeChild(node)
    i = 0
    for node in domhelpers.findElementsWithAttribute(document, 'class', 'latexformula'):
        latexText = ('\\documentclass[12pt]{amsart}%s\n                     \\begin{document}\\[%s\\]\n                     \\end{document}' % (macros, domhelpers.getNodeText(node)))
        file = tempfile.mktemp()
        f = open((file + '.tex'), 'w')
        f.write(latexText)
        f.close()
        _system(('latex %s.tex' % file))
        _system(('dvips %s.dvi -o %s.ps' % (os.path.basename(file), file)))
        baseimgname = ('latexformula%d.png' % i)
        imgname = os.path.join(dir, baseimgname)
        i += 1
        _system(('pstoimg -type png -crop a -trans -interlace -out %s %s.ps' % (imgname, file)))
        newNode = dom.parseString(('<span><br /><img src="%s" /><br /></span>' % (baseimgname,))).documentElement
        node.parentNode.replaceChild(newNode, node)

dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/lore/lmath.py formulaeToImages/original