Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
af1f8c1f
Commit
af1f8c1f
authored
Jul 23, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup; add unicode test
parent
b2da162e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
7 deletions
+27
-7
common/lib/calc/preview.py
+9
-6
common/lib/calc/tests/test_preview.py
+18
-1
No files found.
common/lib/calc/preview.py
View file @
af1f8c1f
...
@@ -136,6 +136,9 @@ def render_power(children):
...
@@ -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 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
=
[
k
.
latex
for
k
in
children
if
k
.
latex
!=
"^"
]
children_latex
[
-
1
]
=
children
[
-
1
]
.
sans_parens
children_latex
[
-
1
]
=
children
[
-
1
]
.
sans_parens
...
@@ -237,13 +240,13 @@ def render_atom(children):
...
@@ -237,13 +240,13 @@ def render_atom(children):
"""
"""
parens
=
None
parens
=
None
if
children
[
0
]
.
latex
in
"([{"
:
if
children
[
0
]
.
latex
in
"([{"
:
# then len(children) == 3
parens
=
children
[
0
]
.
latex
parens
=
children
[
0
]
.
latex
children
=
children
[
1
:
-
1
]
children
=
[
children
[
1
]]
tall
=
any
(
k
.
tall
for
k
in
children
)
return
LatexRendered
(
return
LatexRendered
(
""
.
join
(
k
.
latex
for
k
in
children
)
,
children
[
0
]
.
latex
,
parens
,
parens
,
tall
children
[
0
]
.
tall
)
)
...
@@ -281,8 +284,8 @@ def latex_preview(math_expr, variables=(), functions=(), case_sensitive=False):
...
@@ -281,8 +284,8 @@ def latex_preview(math_expr, variables=(), functions=(), case_sensitive=False):
'sum'
:
render_sum
'sum'
:
render_sum
}
}
b
s
=
"
\\
"
b
ksh
=
"
\\
"
wrap_escaped_strings
=
lambda
s
:
LatexRendered
(
s
.
replace
(
b
s
,
bs
*
2
))
wrap_escaped_strings
=
lambda
s
:
LatexRendered
(
s
.
replace
(
b
ksh
,
bksh
*
2
))
output
=
thing
.
handle_tree
(
render_actions
,
wrap_escaped_strings
)
output
=
thing
.
handle_tree
(
render_actions
,
wrap_escaped_strings
)
return
output
.
latex
return
output
.
latex
common/lib/calc/tests/test_preview.py
View file @
af1f8c1f
...
@@ -42,7 +42,12 @@ class LatexRenderedTest(PreviewTestUtility):
...
@@ -42,7 +42,12 @@ class LatexRenderedTest(PreviewTestUtility):
Helper method to test the way parens are wrapped.
Helper method to test the way parens are wrapped.
"""
"""
obj
=
preview
.
LatexRendered
(
math
,
parens
=
parens
,
tall
=
tall
)
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
):
def
test_parens
(
self
):
""" Test curvy parens. """
""" Test curvy parens. """
...
@@ -107,6 +112,18 @@ class RenderMethodsTest(PreviewTestUtility):
...
@@ -107,6 +112,18 @@ class RenderMethodsTest(PreviewTestUtility):
out
=
_call_render_method
(
render_variable
,
[
'x'
])
out
=
_call_render_method
(
render_variable
,
[
'x'
])
self
.
assert_latex_rendered
(
out
,
latex
=
'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
):
def
test_greek
(
self
):
""" Variable names that are greek should be formatted accordingly. """
""" Variable names that are greek should be formatted accordingly. """
render_variable
=
preview
.
variable_closure
([
'pi'
],
lambda
x
:
x
.
lower
())
render_variable
=
preview
.
variable_closure
([
'pi'
],
lambda
x
:
x
.
lower
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment