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
a4190bfd
Commit
a4190bfd
authored
Sep 09, 2012
by
kimth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Need to escape keywords such as 'in' from MathJax
parent
0e02fc09
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
common/lib/xmodule/xmodule/js/src/capa/display.coffee
+24
-8
No files found.
common/lib/xmodule/xmodule/js/src/capa/display.coffee
View file @
a4190bfd
...
...
@@ -299,24 +299,40 @@ class @Problem
target
=
"display_
#{
element
.
id
.
replace
(
/^input_/
,
''
)
}
"
if
jax
=
MathJax
.
Hub
.
getAllJax
(
target
)[
0
]
eqn
=
@
latexify
(
$
(
element
).
val
())
eqn
=
@
mathjax_preprocessor
(
$
(
element
).
val
())
#eqn = $(element).val()
MathJax
.
Hub
.
Queue
[
'Text'
,
jax
,
eqn
],
[
@
updateMathML
,
jax
,
element
]
latexify
:
(
eqn
)
->
mathjax_preprocessor
:
(
eqn
)
->
###
Translate 6.002x conventions for subscripts to standard Latex, e.g.
'R3' --> 'R_{3}'
'vGS' --> 'v_{GS}'
'K/2*(vIN-VT)^2' --> 'K/2*(v_{IN}-V_{T})^2'
###
subscript_replace
=
(
match
)
->
# Default keywords are taken from capa/calc.py
default_keywords
=
[
'sin'
,
'cos'
,
'tan'
,
'sqrt'
,
'log10'
,
'log2'
,
'ln'
,
'arccos'
,
'arcsin'
,
'arctan'
,
'abs'
,
'pi'
]
if
match
in
default_keywords
# Default keywords are taken from capa/calc.py
default_keywords
=
[
'sin'
,
'cos'
,
'tan'
,
'sqrt'
,
'log10'
,
'log2'
,
'ln'
,
'arccos'
,
'arcsin'
,
'arctan'
,
'abs'
,
'pi'
]
# Escape keywords are strings that have special meaning in 6.002x that should not be processed by Jax
escape_keywords
=
[
'in'
]
# First, perform subscript insertion
replace_subscript
=
(
match
)
->
if
match
in
default_keywords
or
match
in
escape_keywords
return
match
return
match
[
0
]
+
'_{'
+
match
.
substr
(
1
)
+
'}'
return
eqn
.
replace
(
/[A-Za-z]\w+/g
,
subscript_replace
)
else
return
match
[
0
]
+
'_{'
+
match
.
substr
(
1
)
+
'}'
eqn
=
eqn
.
replace
(
/[A-Za-z]\w+/g
,
replace_subscript
)
# Second, escape 6.002x-specific keywords from MathJax
replace_escape_keyword
=
(
match
)
->
return
'"'
+
match
+
'"'
# Force MathJax plain text
for
escape_keyword
in
escape_keywords
eqn
=
eqn
.
replace
(
escape_keyword
,
replace_escape_keyword
)
return
eqn
updateMathML
:
(
jax
,
element
)
=>
try
...
...
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