2 # $Id: texml.py,v 1.20 2006-07-20 03:56:49 olpa Exp $
4 VERSION = "2.0.2"; # GREPVERSION # Format of this string is important
5 usage = """Convert TeXML markup to [La]TeX markup. v.%s. Usage:
6 python texml.py [-e encoding] [-w auto_width] [-c|--context] [-a|--ascii] in_file out_file""" % VERSION
9 # Check command line, print help
13 print >>sys.stderr, usage
17 # Parse command line options
26 opts, args = getopt.getopt(sys.argv[1:], 'hcaw:e:', ['help', 'context', 'ascii', 'width=', 'encoding=', ])
27 except getopt.GetoptError as e:
28 print >>sys.stderr, 'texml: Can\'t parse command line: %s' % e
29 print >>sys.stderr, usage
32 if o in ('-h', '--help'):
33 print >>sys.stderr, usage;
35 if o in ('-c', '--context'):
37 if o in ('-a', '--ascii'):
39 if o in ('-w', '--width'):
43 print >>sys.stderr, "texml: Width is not an integer: '%s'" % a
45 if width < 3: # just a random value
46 print >>sys.stderr, "texml: Width should be greater 3 but get '%s'" % a
48 if o in ('-e', '--encoding'):
52 # Get input and output file
55 print >>sys.stderr, 'texml: Expected two command line arguments, but got %d' % len(args)
57 (infile, outfile) = args
60 # Prepare transformation-1: input file, XML parser
63 from xml.sax.handler import feature_namespaces
69 # Prepare transformation-2: output
74 f = open(outfile, 'wb')
85 # import main class and parse
87 import Texml.processor
89 Texml.processor.process(infile, f, encoding, width, always_ascii, use_context)
91 except Exception as msg:
92 msg = 'texml: %s\n' % (str(msg))