Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:37:03+00:00 2026-06-12T19:37:03+00:00

I am having trouble with pexpect . I’m trying to grab output from tralics

  • 0

I am having trouble with pexpect. I’m trying to grab output from tralics which reads in latex equations and emits the MathML representation, like this:

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 try to get the formula using 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 the formula, but with the original input at the beginning and some control chars 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 clean the output string, but I must be missing something basic. Is there a cleaner way to get the MathML?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:37:06+00:00Added an answer on June 12, 2026 at 7:37 pm

    From what I understand you are trying to get this from pexpect:

    <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>
    

    You can use a regexp instead of “>” for the matching in order to get the expected result. This is the easiest example:

    c.expect("<formula.*formula>");
    

    After that, you can access the matched string by calling the match attribute of pexpect:

    print c.match
    

    You might also try different regexps, due to the fact that the one I posted is a greedy one and it might hinder your execution time if the formulas are big.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with the db.alter command when changing a date field from null=True and
Having trouble getting the oauth access token and secret exchanged from the request tokens
Having trouble getting my POST arrays to show all checkbox values from my form.
Having trouble using foreach to output the contents of a mysql table. The table
Having trouble with this code, wondering if I'm trying to achieve something impossible. I'm
Having trouble trying to turn an XDocument into an list of objects, in particular
Having trouble getting the javascript alert to display from my code behind. c# -
Having trouble getting this syntax right: SELECT DISTINCT id FROM metadata WHERE (meta_key =
Having trouble converting AM time values from MySQL fetch_array when using the PHP date()
Having trouble when trying to create a class using another class(and 2 inner classes),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.