#!/usr/local/bin/python
# \par Py2tex, % -*-Python-*-
# script to translate Python source to \LaTeX\ code.

import getopt, sys
from py2tex import Interpret

# The \|-m| and \|-n| options affect the typographic treatment of the
# tokens #=#, #==#, #<=#, #>=#, #!=#, #<>#, #<<#, #>>#, #in#,
# #not in#, #is#, and~#is not#. When \|-n| is in effect these tokens
# are printed as they appear in the Python source. When \|-m| (the
# default) is in effect they are translated to mathematical symbols
# that are designed for use in typeset documents.  (Please read
# Chapter {\em Book Printing versus Ordinary Typing\/} from the
# \TeX{}book before you use the \|-n| option.) The \|-o| option causes
# the script to write the \LaTeX\ output to the specified file, rather
# than standard output.
#
# The \|-i| and \|-v| options determine whether the comments will be
# interpreted by (La)\TeX~(\|-i|) or typeset verbatim~(\|-v|).

    # Default values.
interpret = 1
math = 1
output = None

    # Parse options.
optlist, args = getopt.getopt (sys.argv [1:], 'imno:v')
for pair in optlist:
    key = pair [0]
    if pair [0] == '-i':
	interpret = 1
    if pair [0] == '-m':
	math = 1
    if pair [0] == '-n':
	math = 0
    if pair [0] == '-o':
	output = pair [1]
    if pair [0] == '-v':
	interpret = 0

if args == []:
    args = ['-']

    # Open output file.
if output == None:
    outfile = sys.stdout
else:
    outfile = open (output, 'w')

    # Translate source files.
for name in args:
    file = Interpret (name, math, interpret)
    outfile.write (file.translation () [0])
    while file.translate () != None:
	for scrap in file.translation ():
	    outfile.write (scrap)

    # Close output file.
outfile.close ()
