def latex_highlight(classified_text, title='python', commands=default_latex_commands, document=default_latex_document):
 macros = '\n'.join((('\\newcommand{\\py%s}[1]{%s}' % c) for c in commands.items()))
 result = []
 for (kind, text) in classified_text:
  if kind:
   result.append(('\\py%s{' % kind))
  result.append(alltt_escape(text))
  if kind:
   result.append('}')
 return (default_latex_document % dict(title=title, macros=macros, body=''.join(result)))

def latex_highlight ( classified_text , title = 'python' , commands = default_latex_commands , document = default_latex_document ) : macros = '\n' . join ( ( ( '\\newcommand{\\py%s}[1]{%s}' % c ) for c in commands . items ( ) ) ) result = [ ] for ( kind , text ) in classified_text : if kind : result . append ( ( '\\py%s{' % kind ) ) result . append ( alltt_escape ( text ) ) if kind : result . append ( '}' ) return ( default_latex_document % dict ( title = title , macros = macros , body = '' . join ( result ) ) )
create a complete latex document with colorized source code .