我遇到了pexpect问题.我试图从tralics中获取输出,这些tralics读取乳胶方程并发出MathML表示,如下所示:
1 ~/ % tralics --interactivemath
This is tralics 2.14.5, a LaTeX to XML translator, running on tlocal
Copyright INRIA/MIAOU/APICS/MARELLE 2002-2012, Jos\'e Grimm
Licensed under the CeCILL Free Software Licensing Agreement
Starting translation of file texput.tex.
No configuration file.
> $x+y=z$
x+y=z
>
所以我尝试使用pexpect获取公式:
import pexpect
c = pexpect.spawn('tralics --interactivemath')
c.expect('>')
c.sendline('$x+y=z$')
s = c.read_nonblocking(size=2000)
print s
输出具有公式,但开头的原始输入和结尾的一些控制字符:
"x+y=z$\r\nx+y=z\r\n\r> \x1b[K"
我可以清理输出字符串,但我必须遗漏一些基本的东西.有没有更简洁的方法来获得MathML?