The module Texml.process converts a TeXML file to a TeX file.
Basic use requires the following:
If the input file doesn't conform to the TeXML specification, then the exception TeXML.handler.InvalidXmlException is raised. If the input parameters are invalid, then the exception ValueError is raised. Expect that the underlying libraries might also raise exceptions, such as xml.sax.SAXException.
#!/usr/bin/python
# Import the needed libraries
import sys
import Texml.processor
# Use the standard input and output
in_stream = sys.stdin
out_stream = sys.stdout
# Convert
Texml.processor.process(in_stream, out_stream)
#!/usr/bin/python
# Import the needed libraries
import sys
import Texml.processor
# Input can be given by a path, output should be a file object
infile = 'document.xml'
out = file('out.tex', 'w')
# Older versions of python need the following code:
# out = open('out.tex', 'w')
# Parameters
width = 75
encoding = 'UTF-8'
always_ascii = 1
use_context = 1
# Convert TeXML inside a try-except block
try:
Texml.processor.process(
in_stream = infile,
out_stream = out,
autonl_width = width,
encoding = encoding,
always_ascii = always_ascii,
use_context = use_context)
except Exception, msg:
print sys.stderr, 'texml: %s' % str(msg)
# Clean up resources
out.close()