hml-equation-parser
Usage
If you have equation string
from hml
document, you can convert it to latex string by using eq2latex
function.
>>> import hml_equation_parser as hp
>>> hp.eq2latex("LEFT β a+b RIGHT β")
'\\left \\lfloor a+b \\right \\rfloor'
Sample code
Let's assume that you have test.hml
file for converting.
There are some sample code to show how to parse hml documents.
You can refer to this sample codes in hmlParser.py
(parseHmlSample
, convertEquationSample
, extract2HtmlStrSample
).
import hml_equation_parser as hp
doc = hp.parseHmlSample("test.hml") # parse hml document and make ElementTree
doc = hp.convertEquationSample(doc) # find equations from ElementTree and convert them to latex string
string = hp.extract2HtmlStrSample(doc) # convert ElementTree to html document with MathJax.
import codecs
f = codecs.open("test.html", "w", "utf8")
f.write(string)
f.close()
hml-equation-parser νκΈ λ¬Έμ
μ¬μ©λ²
hml
λ¬Έμμμ μμ string
μ λ½μλλ€λ©΄ eq2latex
ν¨μλ₯Ό μ΄μ©νμ¬ latex
μμμΌλ‘ λ³νν μ μμ΅λλ€.
>>> import hml_equation_parser as hp
>>> hp.eq2latex("LEFT β a+b RIGHT β")
'\\left \\lfloor a+b \\right \\rfloor'
μμ μ½λ
hmlλ¬Έμλ₯Ό νμ±νμ¬ μ 체 λ¬Έμμμ μμμ λ°κΎΈκ³ μΆλ€λ©΄ λ€μ μ½λλ₯Ό μ°Έμ‘°νλ©΄ λ©λλ€. μμ μμλ test.hml
μ νμ±νμ¬ htmlλ¬Έμλ‘ λ°κΏλλ€. νμ±μ λν λ μμΈν λ΄μ©μ libraryμ hmlParser.py
μ½λλ₯Ό μ°Έμ‘°νμΈμ(parseHmlSample
, convertEquationSample
, extract2HtmlStrSample
).
import hml_equation_parser as hp
doc = hp.parseHmlSample("test.hml") # parse hml document and make ElementTree
doc = hp.convertEquationSample(doc) # find equations from ElementTree and convert them to latex string
string = hp.extract2HtmlStrSample(doc) # convert ElementTree to html document with MathJax.
import codecs
f = codecs.open("test.html", "w", "utf8")
f.write(string)
f.close()