This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Overview

The asciitomathml converts ASCII math to MathML. See http://mathcs.chapman.edu/~jipsen/mathml/asciimath.html for more details. As an example, asciitomathml converts the string x^2 to:

<math xmlns="http://www.w3.org/1998/Math/MathML">
 <mstyle>
  <msup>
   <mi>x</mi>
   <mn>2</mn>
  </msup>
 </mstyle>
</math>

Installation

Install asciitomathml in the normal way:

python setup.py install

Or, for pip:

pip install asciitomathml

Installation for Python 2

Use version .88 if you need asciimathml for Python 2.7::
pip install asciitomathml=.88

Use

The following creates etree from a string:

import asciitomathml.asciitomathml
the_string = 'x^2'
math_obj =  asciitomathml.asciitomathml.AsciiMathML()
math_obj.parse_string(the_string)

In order to get the tree, use the math_tree method:

math_tree = math_obj.get_tree() # math_tree is an etree object

Instead, if you want an XML string, use the to_xml_string method:

xml_string = math_obj.to_xml_string() # xml_string a binary string

The xml_string will have type ‘bytes’. If you will to have a type of ‘str’ pass an encoding of type “unicode”:

xml_string = math_obj.to_xml_string(encoding='unicode')

The string will be encoded as UTF-8.

If you pass an encoding other than utf8 to this method, the string will start with the standard XML encoding, in accordance with XML standards:

<?xml version='1.0' encoding='utf8'?>

If you are incorporating the string into an XML document, and don’t want the encoding string, you should probably use the get_tree method and incorporate the resulting object into your etree document. Likewise, by not passing any encoding to this method, the returned string will be encoded as ASCII and should not include the encoding part of the string. However, if for whatever reason you need a tree without the encoding, pass the no_encoding_string option to the to_xml_string method:

xml_string = math_obj.to_xml_string(encoding="utf8", no_encoding_string = True)

Math style

You can pass any attributes to the <msstyle> that are allowed. Use the mstyle option to pass a dictionary when creating the method:

math_obj =  asciitomathml.asciitomathml.AsciiMathML(mstyle={'displaystyle':'true'})

The most useful attribute is probably displaystyle. In general, set this attribute to true if you will put the equation by itself, in block. Otherwise, don’t set this value at all, or set it to false. The consortium for mathml explains it this way:

For an instance of MathML embedded in a textual data format (such as HTML) in “display” mode, i.e. in place of a paragraph, displaystyle = “true” and scriptlevel = “0” for the outermost expression of the embedded MathML; if the MathML is embedded in “inline” mode, i.e. in place of a character, displaystyle = “false” and scriptlevel = “0” for the outermost expression. See Chapter 7 The MathML Interface for further discussion of the distinction between “display” and “inline” embedding of MathML and how this can be specified in particular instances. In general, a MathML renderer may determine these initial values in whatever manner is appropriate for the location and context of the specific instance of MathML it is rendering, or if it has no way to determine this, based on the way it is most likely to be used; as a last resort it is suggested that it use the most generic values displaystyle = “”true”” and scriptlevel = “”0”“.

http://www.w3.org/TR/MathML2/chapter3.html#presm.mstyle

Scripts

I have included two scripts as examples. These scripts show the capability of the libarary. Since they must read text from a file, form paragraphs, and distinguish between math and non math markup, they are not meant as tools for extensive conversion of text to HTM or FO. For such conversions, see:

http://docutils.sourceforge.net/

Specifically, see the sandbox/docbook directory, which features extensive stylesheets and instructions for converting text to docbook, and then to HTML or FO.

In order to use the scripts, type:

python scripts/asciimath2fo.py <file.txt>

or:

python scripts/asciimath2html.py <file.txt>

The scripts convert anything between “`” and “`” to mathml; otherwise, the scripts just copy the text verbatim. See the examples in the example directory. For a quick start, try:

python scripts/asciimath2html.py examples/linear_regression.txt > linear.xhtml

and then open linear.xhtml in a browser that can handle mathml, such as Firefox.

Test

To test the library, type:

python test/test_all.py
Release History

Release History

1.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.89

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

.89

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

.88

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

.87

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

.86

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

.85

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
asciitomathml-1.0.tar.gz (51.7 kB) Copy SHA256 Checksum SHA256 Source Jul 17, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting