5 The module Texml.process converts a TeXML file to a TeX file.
7 Basic use requires the following:
9 1. Import the needed libraries
10 2. Set up the input and output streams
11 3. Call on the function process
12 4. Use a try-except block around the call to process
15 Parameters for the function process
16 -----------------------------------
19 An input TeXML document as a file object or the path to a file.
23 An output TeX document as a file object. Mandatory.
26 Recommended width to split long lines on smaller ones.
27 Optional, default is 62.
30 Output encoding. Should be known to the Python codecs.
31 Optional, default is ascii.
34 Use only ASCII symbols for output. Non-ASCII bytes are escaped
35 using the ^^XX form, where XX is a hexadecimal code of the
36 character. Optional, default is 0 (False, do not encode as
40 ConTeXt is an alternative to LaTeX. In ConTeXt mode, TeXML
41 translation is slightly different. Set to 1 (True) to activate
42 this mode. Optional, default is 0 (False, LaTeX mode).
44 If the input file doesn't conform to the TeXML specification, then the
45 exception TeXML.handler.InvalidXmlException is raised. If the input
46 parameters are invalid, then the exception ValueError is raised.
47 Expect that the underlying libraries might also raise exceptions, such
48 as xml.sax.SAXException.
55 # Import the needed libraries
57 import Texml.processor
59 # Use the standard input and output
61 out_stream = sys.stdout
64 Texml.processor.process(in_stream, out_stream)
71 # Import the needed libraries
73 import Texml.processor
75 # Input can be given by a path, output should be a file object
76 infile = 'document.xml'
77 out = file('out.tex', 'w')
78 # Older versions of python need the following code:
79 # out = open('out.tex', 'w')
87 # Convert TeXML inside a try-except block
89 Texml.processor.process(
94 always_ascii = always_ascii,
95 use_context = use_context)
96 except Exception as msg:
97 print sys.stderr, 'texml: %s' % str(msg)
102 # $Id: processor.py,v 1.2 2006-06-06 03:37:18 olpa Exp $
107 def process(in_stream, out_stream, encoding='ascii', autonl_width=62, always_ascii=0, use_context=0):
108 transform_obj = Texml.handler.ParseFile()
109 texml_writer = Texml.texmlwr.texmlwr(
112 autonl_width = autonl_width,
113 use_context = use_context,
114 always_ascii = always_ascii,
116 transform_obj.parse_file(
117 read_obj = in_stream,
118 texml_writer = texml_writer,
119 use_context = use_context,