Beispiel #1
0
def parse(filename):
    eqs_all = []
    eqs_count = 0
    fileOriginal = open(filename)
    fileParsed = open(PARSED_PREFIX+filename, 'w+')
    ineqa = False
    for line in fileOriginal:
        if MATH_TOKEN in line:
            # assume all $$$ are paired
            eqs_all = eqs_all + extractEqs(line)
            eqs_new_count = len(eqs_all)
            text = extractText(line)
            line = ''
            for i in range(eqs_new_count - eqs_count):
                line = line + text[i] + getImgMarkdown(eqs_count+i)
            line = line + text[-1]
            fileParsed.writelines(line)
            eqs_count = eqs_new_count
        else:
            fileParsed.writelines(line)

    latexmath2png.math2png(eqs_all, outdir=MATH_IMG_PATH, prefix=MATH_IMG_PREFIX, size = MATH_IMG_SIZE)
    fileOriginal.close()
    fileParsed.close()
Beispiel #2
0
Author: Kamran Riaz Khan <*****@*****.**>
"""
 
import gtk
import os
import latexmath2png
 
pre = 'gtktex_'
eqs = [
	r'$\alpha_i > \beta_i$',
	r'$\sum_{i=0}^\infty x_i$',
	r'$\left(\frac{5 - \frac{1}{x}}{4}\right)$',
	r'$s(t) = \mathcal{A}\sin(2 \omega t)$',
	r'a_d:=6+\frac{7}{(4+5)}\cdot6=6'
	]
latexmath2png.math2png(eqs, os.getcwd(), prefix = pre)
 
def window_destroy(widget):
	for i in range(0, len(eqs)):
		os.unlink(os.path.join(os.getcwd(), '%s%d.png' % (pre, i + 1)))
	gtk.main_quit()
 
window = gtk.Window()
window.set_border_width(10)
window.set_title('LaTeX Equations in GTK')
window.connect('destroy', window_destroy)
vbox = gtk.VBox(spacing = 10)
window.add(vbox)
 
images = [None] * len(eqs)
for i in range(len(eqs)):
Beispiel #3
0
# A quick guide to tex equations
"""def math2png(eqs, outdir, packages = default_packages, prefix = '', size = 1):
    Parameters:
	eqs         - A list of equations
	outdir      - Output directory for PNG images
	packages    - Optional list of packages to include in the LaTeX preamble
	prefix      - Optional prefix for output files
	size        - Scale factor for output"""

pre = 'gtktex_'
eqs = [
    r'$\alpha_i > \beta_i$', r'$\sum_{i=0}^\infty x_i$',
    r'$\left(\frac{5 - \frac{1}{x}}{4}\right)$',
    r'$s(t) = \mathcal{A}\sin(2 \omega t)$',
    r'$\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$'
]
latexmath2png.math2png(eqs, "./equations/", prefix=pre)
latexmath2png.math2png([r'Y = c + \alpha~D + \beta~G(x)~D^2'],
                       "./equations/",
                       prefix="YfuncG",
                       size=1.5)
latexmath2png.math2png([r'Y = c + \alpha~D + \beta~D^2'],
                       "./equations/",
                       prefix="Yfunc",
                       size=1.5)
latexmath2png.math2png(
    [r'$G(x) = \frac{2}{x^2}~\left( x-1+e^{-x} \right),~~~x=\frac{t}{t_0}$'],
    "./equations/",
    prefix="Gfunc",
    size=1.3)
import matplotlib.mathtext as mathtext
import matplotlib.pyplot as plt
import matplotlib
import re
matplotlib.rc('image', origin='upper')
matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
matplotlib.rc('text', usetex=True)

from latexmath2png import math2png

'''
parser = mathtext.MathTextParser("Bitmap")


#latextext = latextext.replace(r'\',r'\\')
print latextext
                  
parser.to_png('test2.png',r'$\alpha$' r'$\\\\$' r'$\beta$'
              , color='k', fontsize=14, dpi=100)

print 1
'''

latextext = r"""\[\left\{ \begin{array}{l}
{y_1}\left( {x = d} \right) = {y_3}\left( {x = d} \right)\\
\frac{{d{y_1}}}{{dx}}(x = d) = \frac{{d{y_3}}}{{dx}}(x = d)\\
\frac{{d{y_1}}}{{dx}}(x = 0) = 0\\
 - EI\frac{{{d^3}{y_1}}}{{d{x^3}}}(x = 0) + \frac{P}{2} = 0
\end{array} \right.\]"""
math2png([latextext],'test')
Beispiel #5
0
	def updateimg(self,g,h):
		if self.edit.get_text():
			latexmath2png.math2png([self.edit.get_text()], os.getcwd(), prefix = "pre")
			self.btn.set_from_file('pre1.png')
		self.btn.show()
		self.edit.hide()