(filename=None, debug=False, paper=(14, 11))
return
Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
    pdf file.
Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
    pdf file.
Post processes LaTeX output ( see comments below ) adds preamble and postscript generates tex file inputs file to latex displays resulting pdf file .
def xdvi(filename=None, debug=False, paper=(14, 11)):
    """
    Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
    pdf file.
    """
    if GA_LatexPrinter.ipy:
        GA_LatexPrinter.restore(GA_LatexPrinter.ipy)
        return

    sys_cmd = SYS_CMD[sys.platform]

    latex_str = sys.stdout.getvalue()
    GA_LatexPrinter.restore()
    latex_lst = latex_str.split('\n')
    latex_str = ''

    lhs = ''
    code_flg = False

    for latex_line in latex_lst:
        if len(latex_line) > 0 and '##' == latex_line[:2]:
            if code_flg:
                code_flg = False
                latex_line = latex_line[2:]
            else:
                code_flg = True
                latex_line = latex_line[2:]
        elif code_flg:
                    pass
        elif len(latex_line) > 0 and '#' in latex_line:  # Non equation mode output (comment)
            latex_line = latex_line.replace('#', '')
            if '%' in latex_line:  # Equation mode with no variables to print (comment)
                latex_line = latex_line.replace('%', '')
                latex_line = '\\begin{equation*} ' + latex_line + ' \\end{equation*}\n'

        else:
            latex_line = latex_line.replace('.', r' \cdot ')  # For components of metric tensor
            if '=' in latex_line:  # determing lhs of equation/align
                eq_index = latex_line.rindex('=') + 1
                lhs = latex_line[:eq_index]
                latex_line = latex_line.replace(lhs, '')
                if '%' in lhs:  # Do not preprocess lhs of equation/align
                    lhs = lhs.replace('%', '')
                else:  # preprocess lhs of equation/align
                    lhs = lhs.replace('|', r'\cdot ')
                    lhs = lhs.replace('^', r'\W ')
                    lhs = lhs.replace('*', ' ')
                    lhs = lhs.replace('grad', r'\bm{\nabla} ')
                    lhs = lhs.replace('<<', r'\rfloor ')
                    lhs = lhs.replace('<', r'\rfloor ')
                    lhs = lhs.replace('>>', r'\lfloor ')
                    lhs = lhs.replace('>', r'\lfloor ')
                latex_line = lhs + latex_line

            if r'\begin{align*}' in latex_line:  # insert lhs of align environment
                latex_line = latex_line = latex_line.replace(lhs, '')
                latex_line = latex_line.replace(r'\begin{align*}', r'\begin{align*} ' + lhs)
                lhs = ''
            else:  # normal sympy equation
                latex_line = latex_line.strip()
                if len(latex_line) > 0:
                    latex_line = '\\begin{equation*} ' + latex_line + ' \\end{equation*}'

        latex_str += latex_line + '\n'

    latex_str = latex_str.replace('\n\n', '\n')

    if debug:
        print(latex_str)

    if paper == 'letter':
        paper_size = \
"""
\\documentclass[10pt,fleqn]{report}
"""
    else:
        paper_size = \
"""
\\documentclass[10pt,fleqn]{report}
\\usepackage[vcentering]{geometry}
"""
        paper_size += '\\geometry{papersize={' + str(paper[0]) + \
                      'in,' + str(paper[1]) + 'in},total={' + str(paper[0] - 1) + \
                      'in,' + str(paper[1] - 1) + 'in}}\n'

    latex_str = paper_size + GA_LatexPrinter.preamble + latex_str + GA_LatexPrinter.postscript

    if filename is None:
        pyfilename = sys.argv[0]
        rootfilename = pyfilename.replace('.py', '')
        filename = rootfilename + '.tex'

    print('latex file =', filename)

    latex_file = open(filename, 'w')
    latex_file.write(latex_str)
    latex_file.close()

    latex_str = None

    pdflatex = find_executable('pdflatex')

    print('pdflatex path =', pdflatex)

    if pdflatex is not None:
        latex_str = 'pdflatex'
    else:
        return

    if latex_str is not None:
        if debug:  # Display latex excution output for debugging purposes
            os.system(latex_str + ' ' + filename[:-4])
        else:  # Works for Linux don't know about Windows
            os.system(latex_str + ' ' + filename[:-4] + sys_cmd['null'])

        print_cmd = sys_cmd['evince'] + ' ' + filename[:-4] + '.pdf ' + sys_cmd['&']
        print(print_cmd)

        os.system(print_cmd)
        raw_input('!!!!Return to continue!!!!\n')

        if debug:
            os.system(sys_cmd['rm'] + ' ' + filename[:-4] + '.aux ' + filename[:-4] + '.log')
        else:
            os.system(sys_cmd['rm'] + ' ' + filename[:-4] + '.aux ' + filename[:-4] + '.log ' + filename[:-4] + '.tex')
    return
def xdvi ( filename = None , debug = False , paper = ( 14 , 11 ) ) : if GA_LatexPrinter . ipy : GA_LatexPrinter . restore ( GA_LatexPrinter . ipy ) return sys_cmd = SYS_CMD [ sys . platform ] latex_str = sys . stdout . getvalue ( ) GA_LatexPrinter . restore ( ) latex_lst = latex_str . split ( '\n' ) latex_str = '' lhs = '' code_flg = False for latex_line in latex_lst : if len ( latex_line ) > 0 and '##' == latex_line [ : 2 ] : if code_flg : code_flg = False latex_line = latex_line [ 2 : ] else : code_flg = True latex_line = latex_line [ 2 : ] elif code_flg : pass elif len ( latex_line ) > 0 and '#' in latex_line : # Non equation mode output (comment) latex_line = latex_line . replace ( '#' , '' ) if '%' in latex_line : # Equation mode with no variables to print (comment) latex_line = latex_line . replace ( '%' , '' ) latex_line = '\\begin{equation*} ' + latex_line + ' \\end{equation*}\n' else : latex_line = latex_line . replace ( '.' , r' \cdot ' ) # For components of metric tensor if '=' in latex_line : # determing lhs of equation/align eq_index = latex_line . rindex ( '=' ) + 1 lhs = latex_line [ : eq_index ] latex_line = latex_line . replace ( lhs , '' ) if '%' in lhs : # Do not preprocess lhs of equation/align lhs = lhs . replace ( '%' , '' ) else : # preprocess lhs of equation/align lhs = lhs . replace ( '|' , r'\cdot ' ) lhs = lhs . replace ( '^' , r'\W ' ) lhs = lhs . replace ( '*' , ' ' ) lhs = lhs . replace ( 'grad' , r'\bm{\nabla} ' ) lhs = lhs . replace ( '<<' , r'\rfloor ' ) lhs = lhs . replace ( '<' , r'\rfloor ' ) lhs = lhs . replace ( '>>' , r'\lfloor ' ) lhs = lhs . replace ( '>' , r'\lfloor ' ) latex_line = lhs + latex_line if r'\begin{align*}' in latex_line : # insert lhs of align environment latex_line = latex_line = latex_line . replace ( lhs , '' ) latex_line = latex_line . replace ( r'\begin{align*}' , r'\begin{align*} ' + lhs ) lhs = '' else : # normal sympy equation latex_line = latex_line . strip ( ) if len ( latex_line ) > 0 : latex_line = '\\begin{equation*} ' + latex_line + ' \\end{equation*}' latex_str += latex_line + '\n' latex_str = latex_str . replace ( '\n\n' , '\n' ) if debug : print ( latex_str ) if paper == 'letter' : paper_size = """
\\documentclass[10pt,fleqn]{report}
""" else : paper_size = """
\\documentclass[10pt,fleqn]{report}
\\usepackage[vcentering]{geometry}
""" paper_size += '\\geometry{papersize={' + str ( paper [ 0 ] ) + 'in,' + str ( paper [ 1 ] ) + 'in},total={' + str ( paper [ 0 ] - 1 ) + 'in,' + str ( paper [ 1 ] - 1 ) + 'in}}\n' latex_str = paper_size + GA_LatexPrinter . preamble + latex_str + GA_LatexPrinter . postscript if filename is None : pyfilename = sys . argv [ 0 ] rootfilename = pyfilename . replace ( '.py' , '' ) filename = rootfilename + '.tex' print ( 'latex file =' , filename ) latex_file = open ( filename , 'w' ) latex_file . write ( latex_str ) latex_file . close ( ) latex_str = None pdflatex = find_executable ( 'pdflatex' ) print ( 'pdflatex path =' , pdflatex ) if pdflatex is not None : latex_str = 'pdflatex' else : return if latex_str is not None : if debug : # Display latex excution output for debugging purposes os . system ( latex_str + ' ' + filename [ : - 4 ] ) else : # Works for Linux don't know about Windows os . system ( latex_str + ' ' + filename [ : - 4 ] + sys_cmd [ 'null' ] ) print_cmd = sys_cmd [ 'evince' ] + ' ' + filename [ : - 4 ] + '.pdf ' + sys_cmd [ '&' ] print ( print_cmd ) os . system ( print_cmd ) raw_input ( '!!!!Return to continue!!!!\n' ) if debug : os . system ( sys_cmd [ 'rm' ] + ' ' + filename [ : - 4 ] + '.aux ' + filename [ : - 4 ] + '.log' ) else : os . system ( sys_cmd [ 'rm' ] + ' ' + filename [ : - 4 ] + '.aux ' + filename [ : - 4 ] + '.log ' + filename [ : - 4 ] + '.tex' ) return