예제 #1
0
def test_preview():
    x = Symbol("x")
    obj = BytesIO()
    try:
        preview(x, output="png", viewer="BytesIO", outputbuffer=obj)
    except RuntimeError:
        pass  # latex not installed on CI server
def test_preview():
    x = Symbol('x')
    obj = BytesIO()
    try:
        preview(x, output='png', viewer='BytesIO', outputbuffer=obj)
    except RuntimeError:
        pass  # latex not installed on CI server
예제 #3
0
def _mathml(expression):
	global filei
	filename = 'eq%d.png' % filei
	filei = filei + 1
	preview(expression, output='png', viewer='file', filename=filename)
	latexstr = latex(expression)
	return '<img src="%s" alt="%s" />' % (filename, latexstr)
def test_preview_unicode_symbol():
    # issue 9107
    a = Symbol('α')
    obj = BytesIO()
    try:
        preview(a, output='png', viewer='BytesIO', outputbuffer=obj)
    except RuntimeError:
        pass  # latex not installed on CI server
예제 #5
0
def write_to_file(latex, filename):
    preview(
        "$$%s$$" % (latex, ),
        output="png",
        viewer="file",
        filename=filename,
        preamble=PREAMBLE,
    )
def test_preview_latex_construct_in_expr():
    # see PR 9801
    x = Symbol('x')
    pw = Piecewise((1, Eq(x, 0)), (0, True))
    obj = BytesIO()
    try:
        preview(pw, output='png', viewer='BytesIO', outputbuffer=obj)
    except RuntimeError:
        pass  # latex not installed on CI server
예제 #7
0
 def _preview_wrapper(o):
     exprbuffer = BytesIO()
     try:
         preview(o, output='png', viewer='BytesIO',
                 outputbuffer=exprbuffer, preamble=preamble,
                 dvioptions=dvioptions)
     except Exception as e:
         # IPython swallows exceptions
         debug("png printing:", "_preview_wrapper exception raised:",
               repr(e))
         raise
     return exprbuffer.getvalue()
예제 #8
0
파일: latex_ex.py 프로젝트: vchekan/sympy
def xdvi(filename='tmplatex.tex', debug=False):
    """
    Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
    dvi file with xdvi or yap.
    """
    if not LatexPrinter.LaTeX_flg:
        return
    body = sys.stdout.getvalue()
    LatexPrinter.restore()

    body_lst = body.split('\n')
    body = ''
    array_flg = False
    eqnarray_flg = False
    raw_flg = False
    i = iter(body_lst)
    line = i.next()

    while True:
        if '$' in line:  # Inline math expression(s)
            if len(line) > 0:
                line += '\\newline \n'
            body += line
            try:
                line = i.next()
            except StopIteration:
                break

        elif '%' in line:  # Raw LaTeX input
            """
            If % in line assume line is beginning of raw LaTeX input and stop
            post processing
            """
            line = line.replace('%', '')
            raw_flg = True
            while raw_flg:
                if '%' in line:
                    """
                    If % in line assume line is end of LaTeX input and begin
                    post processing
                    """
                    raw_flg = False
                    line = line.replace('%', '') + '\n'
                else:
                    line += '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        elif '#' in line:  # Array input
            """
            If # in line assume line is beginning of array input and contains
            \begin{array} statement
            """
            line = line.replace('#', '')
            array_flg = True
            line = '\\begin{equation*}\n' + line
            while array_flg:
                if '#' in line:
                    """
                    If # in line assume line is end of array input and contains
                    \end{array} statement
                    """
                    array_flg = False
                    line = line.replace('#', '')
                    line += '\\end{equation*}\n'
                else:
                    line += '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        elif '@' in line:  # Align input
            """
            If @ in line assume line is beginning of align input
            """
            line = line.replace('@', '')
            line = line.replace('=', '& = ')
            eqnarray_flg = True
            line = '\\begin{align*}\n' + line
            line = process_equals(line)
            body += line
            try:
                line = i.next()
            except StopIteration:
                break
            while eqnarray_flg:
                if '@' in line:
                    """
                    If @ in line assume line is end of align input
                    """
                    eqnarray_flg = False
                    line = line.replace('@', '')
                    line += '\\end{align*}\n'
                else:
                    line + '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        else:
            if '=' in line:  # Single line equation
                line = '\\begin{equation*}\n' + line + '\n\\end{equation*}'
            else:  # Text with no math expression(s)unless \ or _ in line
                if '\\' in line or '_' in line or '^' in line:
                    line = '\\begin{equation*}\n' + line + '\n\\end{equation*}'
                else:
                    if len(line) > 0:
                        line += '\\newline \n'
            line = process_equals(line)
            body += line
            try:
                line = i.next()
            except StopIteration:
                break
    preview(body,
            output='dvi',
            outputTexFile=filename,
            preamble=LatexPrinter.preamble)
    LatexPrinter.LaTeX_flg = False
    return
예제 #9
0
def xdvi(filename='tmplatex.tex', debug=False):
    """
    Post processes LaTeX output (see comments below), adds preamble and
    postscript, generates tex file, inputs file to latex, displays resulting
    dvi file with xdvi or yap.
    """
    if not LatexPrinter.LaTeX_flg:
        return
    body = sys.stdout.getvalue()
    LatexPrinter.restore()

    body_lst = body.split('\n')
    body = ''
    array_flg = False
    eqnarray_flg = False
    raw_flg = False
    i = iter(body_lst)
    line = i.next()

    while True:
        if '$' in line:  # Inline math expression(s)
            if len(line) > 0:
                line += '\\newline \n'
            body += line
            try:
                line = i.next()
            except StopIteration:
                break

        elif '%' in line:  # Raw LaTeX input
            """
            If % in line assume line is beginning of raw LaTeX input and stop
            post processing
            """
            line = line.replace('%', '')
            raw_flg = True
            while raw_flg:
                if '%' in line:
                    """
                    If % in line assume line is end of LaTeX input and begin
                    post processing
                    """
                    raw_flg = False
                    line = line.replace('%', '') + '\n'
                else:
                    line += '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        elif '#' in line:  # Array input
            """
            If # in line assume line is beginning of array input and contains
            \begin{array} statement
            """
            line = line.replace('#', '')
            array_flg = True
            line = '\\begin{equation*}\n' + line
            while array_flg:
                if '#' in line:
                    """
                    If # in line assume line is end of array input and contains
                    \end{array} statement
                    """
                    array_flg = False
                    line = line.replace('#', '')
                    line += '\\end{equation*}\n'
                else:
                    line += '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        elif '@' in line:  # Align input
            """
            If @ in line assume line is beginning of align input
            """
            line = line.replace('@', '')
            line = line.replace('=', '& = ')
            eqnarray_flg = True
            line = '\\begin{align*}\n' + line
            line = process_equals(line)
            body += line
            try:
                line = i.next()
            except StopIteration:
                break
            while eqnarray_flg:
                if '@' in line:
                    """
                    If @ in line assume line is end of align input
                    """
                    eqnarray_flg = False
                    line = line.replace('@', '')
                    line += '\\end{align*}\n'
                else:
                    line + '\n'
                line = process_equals(line)
                body += line
                try:
                    line = i.next()
                except StopIteration:
                    break

        else:
            if '=' in line:  # Single line equation
                line = '\\begin{equation*}\n' + line + '\n\\end{equation*}'
            else:  # Text with no math expression(s)unless \ or _ in line
                if '\\' in line or '_' in line or '^' in line:
                    line = '\\begin{equation*}\n' + line + '\n\\end{equation*}'
                else:
                    if len(line) > 0:
                        line += '\\newline \n'
            line = process_equals(line)
            body += line
            try:
                line = i.next()
            except StopIteration:
                break
    preview(body, output='dvi', outputTexFile=filename,
            preamble=LatexPrinter.preamble)
    LatexPrinter.LaTeX_flg = False
    return