#!/usr/bin/env python # # mathmltest.py -- test the MathML support in eqn # # This script generates an HTML test page from a list of eqn equations. # The test page will have putatively equivalent MathML in it and can be # checked in a browser. import os, commands, tempfile tests = ( ("x + y", "Demonstrate binary operators and identifiers"), ("a sub 1", "Demonstrate subscripting."), ("b prime", "Demonstrate prime boxes."), ("x={-b +- sqrt{b sup 2 -4ac}} over 2a", "Quadratic formula."), ("lim from {x -> pi /2} ( tan~x) sup{sin~2x}~=~1", "Inline first example from the abstract of the guide to eqn."), (''' G(z)~mark =~ e sup { ln ~ G(z) } ~=~ exp left ( sum from k>=1 {S sub k z sup k} over k right ) ~=~ prod from k>=1 e sup {S sub k z sup k /k} ''', "Second (display) example from the abstract of the guide to eqn."), ("matrix { ccol { x sub i above y sub i } ccol { x sup 2 above y sup 2 }}", "First matrix example from the guide to eqn."), ("x = 2 pi int sin ( omega t ) dt", "Integral example from the guide to eqn."), ("A~=~left [ pile { a above b above c } ~~ pile { x above y above z } right ]", "First pile example from the guide to eqn."), ) def filter_string(str, command): fp = tempfile.NamedTemporaryFile(prefix="mathmltest") fp.write(str + "\n") fp.flush() output = os.popen(command + " <" + fp.name, "r").read() fp.close() return output print ''' Test page demonstrating eqn to MathML translation This is a test page demonstating eqn to MathML parsing with the -TMathML option. ''' for (test, explanation) in tests: print "

%s

" % explanation mathml = filter_string(".EQ\n" + test + "\n.EN\n", "eqn -TMathML") mathml = mathml.replace(".EQ\n", "").replace(".EN\n", "") #mathml = filter_string(mathml, "xmllint --valid --format -") print "EQN markup text:" print "
%s
" % test print "MathML translation:" print mathml print ''' '''