def test_latex_mapper():
    from pymbolic import parse
    from pymbolic.mapper.stringifier import LaTeXMapper, StringifyMapper
    tm = LaTeXMapper()
    sm = StringifyMapper()
    equations = []

    def add(expr):
        equations.append('\\[{}\\] % from: {}'.format(tm(expr), sm(expr)))
    add(parse('a * b + c'))
    add(parse('f(a,b,c)'))
    add(parse('a ** b ** c'))
    add(parse('(a | b) ^ ~c'))
    add(parse('a << b'))
    add(parse('a >> b'))
    add(parse('a[i,j,k]'))
    add(parse('a[1:3]'))
    add(parse('a // b'))
    add(parse('not (a or b) and c'))
    add(parse('(a % b) % c'))
    add(parse('(a >= b) or (b <= c)'))
    add((prim.Min((1,)) + prim.Max((1, 2))))
    add(prim.Substitution((prim.Variable('x') ** 2), ('x',), (2,)))
    add(prim.Derivative(parse('x**2'), ('x',)))
    import os
    import tempfile
    import subprocess
    import shutil
    latex_dir = tempfile.mkdtemp('pymbolic')
    try:
        tex_file_path = os.path.join(latex_dir, 'input.tex')
        with open(tex_file_path, 'w') as tex_file:
            contents = (LATEX_TEMPLATE % '\n'.join(equations))
            tex_file.write(contents)
        try:
            subprocess.check_output(['latex', '-interaction=nonstopmode', ('-output-directory=%s' % latex_dir), tex_file_path], universal_newlines=True)
        except OSError:
            pytest.skip('latex command not found')
        except subprocess.CalledProcessError as err:
            raise AssertionError(str(err.output))
    finally:
        shutil.rmtree(latex_dir)
def test_latex_mapper():
    from pymbolic import parse
    from pymbolic.mapper.stringifier import LaTeXMapper, StringifyMapper
    tm = LaTeXMapper()
    sm = StringifyMapper()
    equations = []

    def add(expr):
        equations.append('\\[{}\\] % from: {}'.format(tm(expr), sm(expr)))
    add(parse('a * b + c'))
    add(parse('f(a,b,c)'))
    add(parse('a ** b ** c'))
    add(parse('(a | b) ^ ~c'))
    add(parse('a << b'))
    add(parse('a >> b'))
    add(parse('a[i,j,k]'))
    add(parse('a[1:3]'))
    add(parse('a // b'))
    add(parse('not (a or b) and c'))
    add(parse('(a % b) % c'))
    add(parse('(a >= b) or (b <= c)'))
    add((prim.Min((1,)) + prim.Max((1, 2))))
    add(prim.Substitution((prim.Variable('x') ** 2), ('x',), (2,)))
    add(prim.Derivative(parse('x**2'), ('x',)))
    import os
    import tempfile
    import subprocess
    import shutil
    latex_dir = tempfile.mkdtemp('pymbolic')
    try:
        tex_file_path = os.path.join(latex_dir, 'input.tex')
        with open(tex_file_path, 'w') as tex_file:
            contents = (LATEX_TEMPLATE % '\n'.join(equations))
            tex_file.write(contents)
        try:
            subprocess.check_output(['latex', '-interaction=nonstopmode', ('-output-directory=%s' % latex_dir), tex_file_path], universal_newlines=True)
        except OSError:
            pytest.skip('latex command not found')
        except subprocess.CalledProcessError as err:
            raise AssertionError(str(err.output))
    finally:
        shutil.rmtree(latex_dir)