<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import subprocess <EOL> from subprocess import call , PIPE <EOL> import os <EOL> import tempfile <EOL> from django . template import loader , Context <EOL> def process_latex ( template , context = { } , outtype = '<STR_LIT>' , outfile = None ) : <EOL> """<STR_LIT>""" <EOL> if type ( template ) in ( list , tuple ) : <EOL> t = loader . select_template ( template ) <EOL> else : <EOL> t = loader . get_template ( template ) <EOL> c = Context ( context ) <EOL> r = t . render ( c ) <EOL> r = r . encode ( "<STR_LIT:utf-8>" ) <EOL> fd , base = tempfile . mkstemp ( ) <EOL> tex = os . fdopen ( fd ) <EOL> tex . write ( r ) <EOL> tex . close ( ) <EOL> items = "<STR_LIT>" . split ( ) <EOL> names = dict ( ( x , '<STR_LIT>' % ( base , x ) ) for x in items ) <EOL> output = names [ outtype ] <EOL> if outtype == '<STR_LIT>' or outtype == '<STR_LIT>' : <EOL> pdflatex ( base , outtype ) <EOL> elif outtype == '<STR_LIT>' : <EOL> pdflatex ( base , '<STR_LIT>' ) <EOL> call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> names [ '<STR_LIT>' ] , '<STR_LIT>' , names [ '<STR_LIT>' ] ] , <EOL> cwd = os . path . dirname ( base ) , <EOL> stdout = PIPE , stderr = PIPE ) <EOL> os . remove ( names [ '<STR_LIT>' ] ) <EOL> os . remove ( names [ '<STR_LIT>' ] ) <EOL> os . remove ( base ) <EOL> if not outfile : <EOL> o = file ( output ) . read ( ) <EOL> os . remove ( output ) <EOL> return o <EOL> else : <EOL> os . rename ( output , outfile ) <EOL> def pdflatex ( outfile , outtype = '<STR_LIT>' ) : <EOL> dirname , filename = os . path . split ( outfile ) <EOL> print ( "<STR_LIT>" , dirname ) <EOL> print ( "<STR_LIT>" , filename ) <EOL> subprocess . check_call ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , outtype , <EOL> filename ] , <EOL> cwd = dirname ) </s>
