<s> """<STR_LIT>""" <EOL> from cStringIO import StringIO <EOL> import docutils . core <EOL> from pyth import document <EOL> from pyth . format import PythWriter <EOL> from pyth . plugins . rst . writer import RSTWriter <EOL> class LatexWriter ( PythWriter ) : <EOL> @ classmethod <EOL> def write ( klass , document , target = None , stylesheet = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> writer = LatexWriter ( document , target , stylesheet ) <EOL> return writer . go ( ) <EOL> def __init__ ( self , doc , target = None , stylesheet = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> self . document = doc <EOL> self . stylesheet = stylesheet <EOL> self . target = target if target is not None else StringIO ( ) <EOL> @ property <EOL> def full_stylesheet ( self ) : <EOL> """<STR_LIT>""" <EOL> latex_fragment = r"""<STR_LIT>""" % ( self . document . properties . get ( "<STR_LIT:title>" ) , <EOL> self . document . properties . get ( "<STR_LIT>" ) , <EOL> self . document . properties . get ( "<STR_LIT>" ) ) <EOL> return latex_fragment + self . stylesheet <EOL> def go ( self ) : <EOL> rst = RSTWriter . write ( self . document ) . getvalue ( ) <EOL> settings = dict ( input_encoding = "<STR_LIT>" , <EOL> output_encoding = "<STR_LIT>" , <EOL> stylesheet = "<STR_LIT>" ) <EOL> latex = docutils . core . publish_string ( rst , <EOL> writer_name = "<STR_LIT>" , <EOL> settings_overrides = settings ) <EOL> latex = latex . replace ( r"<STR_LIT>" , <EOL> self . full_stylesheet ) <EOL> self . target . write ( latex ) <EOL> return self . target </s>
