coding utf8 from pylab import import os def getPNGfromTex formula out_

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#-*- coding: utf8 -*-
from pylab import *
import os
def getPNGfromTex(formula, out_path, dpi=300):
rc('font',**{'family':'serif'})
rc('text', usetex=True)
rc('text.latex',unicode=True)
rc('text.latex',preamble='\usepackage[utf8]{inputenc}')
rc('text.latex',preamble='\usepackage[russian]{babel}')
fig = figure()
text = fig.text(0, 0, formula, family = 'verdana')
fig.savefig(out_path, dpi=dpi)
bbox = text.get_window_extent()
width, height = bbox.size / float(dpi) + 0.005
fig.set_size_inches((width, height))
dy = (bbox.ymin / float(dpi)) / height
text.set_position((0, -dy))
fig.savefig(out_path, dpi=dpi)
def main():
f = raw_input()
f = f.encode('utf-8')
f = unicode(f, 'UTF-8')
print f
p = raw_input()
getPNGfromTex(f, p)
#main()
s = unicode('текст', 'utf-8')
getPNGfromTex(s, './oood1.png')