I'm having problems with pexpect . I am trying to get the output from tralics , which reads in latex equations and emits a MathML representation, for example:
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$ <formula type='inline'><math xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mi>x</mi> <mo>+</mo><mi>y</mi><mo>=</mo><mi>z</mi></mrow></math></formula> >
So I'm trying to get the formula with pexpect:
import pexpect c = pexpect.spawn('tralics --interactivemath') c.expect('>') c.sendline('$x+y=z$') s = c.read_nonblocking(size=2000) print s
The output has a formula, but with the original input at the beginning and some control characters at the end:
"x+y=z$\r\n<formula type='inline'><math xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mi>x</mi><mo>+</mo><mi>y</mi><mo>=</mo><mi>z</mi></mrow></math></formula>\r\n\r> \x1b[K"
I can clear the output line, but I have to miss something basic. Is there a cleaner way to get MathML?
source share