예제 #1
0
def latex2png(latex, filename, fontset='cm'):
    latex = "$%s$" % latex

    m = Mathtex(latex, 'bakoma')

    if not os.path.exists(filename):
        try:
	    m.save(filename)
        except:
            warnings.warn("Could not render math expression %s" % latex,
                          Warning)
    sys.stdout.write("#")
    sys.stdout.flush()
    return m.depth
예제 #2
0
def latex2png(latex, filename, fontset='cm'):
    latex = "$%s$" % latex

    m = Mathtex(latex, 'bakoma')

    if not os.path.exists(filename):
        try:
            m.save(filename)
        except:
            warnings.warn("Could not render math expression %s" % latex,
                          Warning)
    sys.stdout.write("#")
    sys.stdout.flush()
    return m.depth
예제 #3
0
파일: tests.py 프로젝트: richarddzh/mathtex
    for fontsize, dpi, font in actual_presets:
        count += 1
        print "Test %d of %d ['%s' at (%.1f, %d, %s)]" % (count, total, name, fontsize, dpi, font)

        key = (name, fontsize, dpi, font)

        m = Mathtex(tex, fontset=font, fontsize=fontsize, dpi=dpi)

        if options.gen_output:
            # Generate the base file name
            fn = os.path.join(os.path.dirname(__file__), "%s.%s.%dpt.%ddpi" % (name, font, fontsize, dpi))
            # Produce the normal and reference file names
            filenames[key] = (fn + ".png", fn + "-ref.png")

            if options.update:
                m.save(filenames[key][1])
            else:
                m.save(filenames[key][0])

        glyphs[key] = extract_glyphs(m.glyphs)
        rects[key] = m.rects
        bitmap[key] = md5(m.as_rgba_bitmap()).hexdigest()

# Compare hashes against a previous run
if os.path.isfile(options.hashfile) and not options.update:
    # Load the reference results set
    fh = open(options.hashfile, "rb")
    ref_glyphs = pickle.load(fh)
    ref_rects = pickle.load(fh)
    ref_bitmap = pickle.load(fh)
예제 #4
0
파일: gui.py 프로젝트: chentianran/knotted
 def onResult(self):
     m = Mathtex (self.result_tex, self.mathfont, 26)
     m.save('result.png', 'png')
     img = wx.Image('result.png', wx.BITMAP_TYPE_ANY)
     self.img_result.SetBitmap(wx.BitmapFromImage(img))
     self.panel.Refresh()
예제 #5
0
# Import Mathtex and the appropriate font set
from mathtex.mathtex_main import Mathtex
from mathtex.fonts import UnicodeFonts

# Create the font set instance; if \bf and \it are not provided
# they will be the bold and italic versions of \rm
u = UnicodeFonts(rm='Times New Roman', sf='Arial')

# Create the expression object and save it as a PNG
m = Mathtex(r"${\it x} = {\rm x} = {\sf x} = {\bf x}$", u, 20)
m.save('unicode.png')

# Attempt to also save it as a PDF -- requires PyCairo
try:
    m.save('unicode.pdf')
except:
    print 'PDF output requires PyCairo.'
예제 #6
0
파일: test.py 프로젝트: segv11/mathtex
from mathtex.fonts import StixFonts
from mathtex.backends.backend_cairo import MathtexBackendCairo
from mathtex.backends.backend_image import MathtexBackendImage

parser = MathtexParser()
bakoma = BakomaFonts()
stix = StixFonts()

box =  parser.parse(r"$x_{1,2}=\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$", stix, 18, 99.0)

#print box

rects, glyphs, bbox =  ship(0, 0, box)

width = bbox[2] - bbox[0]
height = box.height
depth = box.depth

backend = MathtexBackendImage(99.0)
backend.set_canvas_size(box.width, box.height, box.depth)
backend.render(glyphs, rects)
backend.save('test.png', 'png')
"""
from mathtex.mathtex_main import Mathtex
from mathtex.fonts import UnicodeFonts

u = UnicodeFonts(rm="times new roman",it='times new roman:italic',bf='times new roman:bold')

m = Mathtex(r"$\sqrt{x^2} \times \frac{2}{3}$", u)
m.save('testnew.png', 'png')
예제 #7
0
actual_presets = [presets[int(i)] for i in options.presets.split(",")]

# For progress reports
total = len(actual_tests) * len(actual_presets)
count = 0

for (name, tex) in actual_tests.iteritems():
    for fontsize, dpi, font in actual_presets:
        count += 1
        print "Test %d of %d ['%s' at (%.1f, %d, %s)]" % (count, total, name, fontsize, dpi, font)

        m = Mathtex(tex, fontset=font, fontsize=fontsize, dpi=dpi)

        if options.gen_output:
            m.save(os.path.join(os.path.dirname(__file__), "%s.%s.%dpt.%ddpi.png" % (name, font, fontsize, dpi)))

        key = (name, fontsize, dpi, font)

        glyphs[key] = extract_glyphs(m.glyphs)
        rects[key] = m.rects
        bitmap[key] = md5(m.as_rgba_bitmap()).hexdigest()

# Compare hashes against a previous run
if os.path.isfile(options.hashfile) and not options.update:
    # Load the reference results set
    fh = open(options.hashfile, "rb")
    ref_glyphs = pickle.load(fh)
    ref_rects = pickle.load(fh)
    ref_bitmap = pickle.load(fh)
예제 #8
0
        print "Test %d of %d ['%s' at (%.1f, %d, %s)]" % (count, total, name,
                                                          fontsize, dpi, font)

        key = (name, fontsize, dpi, font)

        m = Mathtex(tex, fontset=font, fontsize=fontsize, dpi=dpi)

        if options.gen_output:
            # Generate the base file name
            fn = os.path.join(os.path.dirname(__file__),
                              "%s.%s.%dpt.%ddpi" % (name, font, fontsize, dpi))
            # Produce the normal and reference file names
            filenames[key] = (fn + '.png', fn + '-ref.png')

            if options.update:
                m.save(filenames[key][1])
            else:
                m.save(filenames[key][0])

        glyphs[key] = extract_glyphs(m.glyphs)
        rects[key] = m.rects
        bitmap[key] = md5(m.as_rgba_bitmap()).hexdigest()

# Compare hashes against a previous run
if os.path.isfile(options.hashfile) and not options.update:
    # Load the reference results set
    fh = open(options.hashfile, 'rb')
    ref_glyphs = pickle.load(fh)
    ref_rects = pickle.load(fh)
    ref_bitmap = pickle.load(fh)