Commit af1f8c1f by Peter Baratta

Cleanup; add unicode test

parent b2da162e
......@@ -136,6 +136,9 @@ def render_power(children):
If you have 'a^(b+c)' don't include that last set of parens ('a^{b+c}').
"""
if len(children) == 1:
return children[0]
children_latex = [k.latex for k in children if k.latex != "^"]
children_latex[-1] = children[-1].sans_parens
......@@ -237,13 +240,13 @@ def render_atom(children):
"""
parens = None
if children[0].latex in "([{":
# then len(children) == 3
parens = children[0].latex
children = children[1:-1]
tall = any(k.tall for k in children)
children = [children[1]]
return LatexRendered(
"".join(k.latex for k in children),
children[0].latex,
parens,
tall
children[0].tall
)
......@@ -281,8 +284,8 @@ def latex_preview(math_expr, variables=(), functions=(), case_sensitive=False):
'sum': render_sum
}
bs = "\\"
wrap_escaped_strings = lambda s: LatexRendered(s.replace(bs, bs * 2))
bksh = "\\"
wrap_escaped_strings = lambda s: LatexRendered(s.replace(bksh, bksh * 2))
output = thing.handle_tree(render_actions, wrap_escaped_strings)
return output.latex
......@@ -42,7 +42,12 @@ class LatexRenderedTest(PreviewTestUtility):
Helper method to test the way parens are wrapped.
"""
obj = preview.LatexRendered(math, parens=parens, tall=tall)
self.assert_latex_rendered(obj, tall=tall, latex=with_parens, sans_parens=math)
self.assert_latex_rendered(
obj,
tall=tall,
latex=with_parens,
sans_parens=math
)
def test_parens(self):
""" Test curvy parens. """
......@@ -107,6 +112,18 @@ class RenderMethodsTest(PreviewTestUtility):
out = _call_render_method(render_variable, ['x'])
self.assert_latex_rendered(out, latex='x')
def test_variable_unicode(self):
"""
Simple valid unicode variables should pass through as well.
Note: it isn't supported right now in the rest of the code (esp. the
way we have set up pyparsing), but when it is, this should work.
"""
var = "✖"
render_variable = preview.variable_closure([var], lambda x: x.lower())
out = _call_render_method(render_variable, [var])
self.assert_latex_rendered(out, latex=var)
def test_greek(self):
""" Variable names that are greek should be formatted accordingly. """
render_variable = preview.variable_closure(['pi'], lambda x: x.lower())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment