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

  • Home
  • SEARCH
  • 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 4052924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:22:52+00:00 2026-05-20T14:22:52+00:00

I am trying to render algebra as an SVG using sympy and svgmath. I

  • 0

I am trying to render algebra as an SVG using sympy and svgmath. I have the file ‘svgmath.xml’ in the root directory. Unfortunately I get: ‘ImportError: No module named libxml2’. I’m not sure of the best way to sort this out. I would much appreciate any help/advice. My code is:

from xml import sax
from xml.sax.saxutils import XMLGenerator

from svgmath.tools.saxtools import XMLGenerator, ContentFilter
from svgmath.mathhandler import MathHandler, MathNS
from svgmath.tools.saxtools import XMLGenerator

from sympy.printing.mathml import mathml
from sympy.abc import x

from sympy.utilities.mathml import c2p

# Open all files
output = open("test.svg", "w") 
config = open("svgmath.xml", "r")    

# Create the converter as a content handler. 
saxoutput = XMLGenerator(output, 'utf-8')
handler = MathHandler(saxoutput, config)

# Parse input file with a namespace-aware SAX parser
parser = sax.make_parser()
parser.setFeature(sax.handler.feature_namespaces, 1)
parser.setContentHandler(handler)
parser.parse(c2p(mathml(3*x), simple=False))

The Stack trace is now:

Traceback (most recent call last):
  File "D:\Geddes\my python\SVGmath\test1.py", line 29, in <module>
    parser.parse(c2p(mathml(3*x), simple=True))
  File "C:\Python27\lib\xml\sax\expatreader.py", line 102, in parse
    source = saxutils.prepare_input_source(source)
  File "C:\Python27\lib\xml\sax\saxutils.py", line 298, in prepare_input_source
    f = urllib.urlopen(source.getSystemId())
  File "C:\Python27\lib\urllib.py", line 84, in urlopen
    return opener.open(url)
  File "C:\Python27\lib\urllib.py", line 202, in open
    return self.open_unknown(fullurl, data)
  File "C:\Python27\lib\urllib.py", line 214, in open_unknown
    raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: '?xml%20version=%221.0%22?%3e%0a%3cmath%20xmlns=%22http'

My modified code:

from xml import sax
from xml.sax.saxutils import XMLGenerator

from svgmath.tools.saxtools import XMLGenerator, ContentFilter
from svgmath.mathhandler import MathHandler, MathNS
from svgmath.tools.saxtools import XMLGenerator

from sympy.printing.mathml import mathml
from sympy.abc import x

from sympy.utilities.mathml import c2p

import libxml2

import StringIO

# Open all files
output = open("test.svg", "w") 
config = open("svgmath.xml", "r")    

# Create the converter as a content handler. 
saxoutput = XMLGenerator(output, 'utf-8')
handler = MathHandler(saxoutput, config)

# Parse input file with a namespace-aware SAX parser
parser = sax.make_parser()
parser.setFeature(sax.handler.feature_namespaces, 1)
parser.setContentHandler(handler)
parser.parse(StringIO.StringIO(mathml(3*x)))

This fails to produce a valid SVG file and gives:

[WARNING] line 1, column 0: Root element in MathML document must be 'math'
[WARNING] line 1, column 7: MathML element 'times' is unsupported
[WARNING] line 1, column 15: MathML element 'cn' is unsupported
[WARNING] line 1, column 25: MathML element 'ci' is unsupported
[WARNING] line 1, column 0: MathML element 'apply' is unsupported
  • 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-05-20T14:22:53+00:00Added an answer on May 20, 2026 at 2:22 pm

    Install the libxml2 library. For example, on ubuntu this is the python-libxml2 package. I too tried the sympy -> mathml -> svg route once, I also had to install the package (iirc it’s needed for c2p(), which applies a XSLT to convert content to presentation MathML).

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

Sidebar

Related Questions

I am trying to render a complex XML document as webpage(FF only) using a
I have been trying to render JSON data in a JQGrid. I get the
I am trying to render a very complex model using json file. The size
I'm trying render the results of surveys from Surveryor gem as a CSV file,
I am trying to render a ViewModel using Razor and MVC3. For some reason
I'm trying to render a font using the css property @font-face , in Firefox,
I am trying to render the dictionary content using Django template like this for
Trying to render a list, each of which has an ajax form to get
When trying to render a Django template file in Google App Engine from google.appengine.ext.webapp
I'm trying to render a cube using an array of 8 vertices and an

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.