Je rencontre des problèmes avec pexpect
. Je suis en train de saisir la sortie de tralics
qui se lit dans les équations de latex et émet la représentation MathML, comme ceci:Capture de sortie de pexpect
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>
>
J'essaie donc d'obtenir la formule à l'aide pexpect:
import pexpect
c = pexpect.spawn('tralics --interactivemath')
c.expect('>')
c.sendline('$x+y=z$')
s = c.read_nonblocking(size=2000)
print s
La sortie a la formule, mais avec l'entrée d'origine au début et à certains caractères de contrôle à la fin:
"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"
je peux nettoyer la chaîne de sortie, mais je dois manquer ba quelque chose sic. Y a-t-il une manière plus simple d'obtenir le MathML?
merci! Pour être complet, je fais 'c.expect (" ")' et ensuite j'obtiens le résultat avec 'print c.match.group()'. Pour me préparer à la prochaine formule, je fais 'c.expect ('>') et répète. –
Tim
Je suis content que ça ait aidé :) –