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
36b44253
Commit
36b44253
authored
Sep 10, 2012
by
kimth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MathJax preprocessor comes from external plugin
parent
5a9a53d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
46 deletions
+10
-46
common/lib/capa/capa/capa_problem.py
+1
-1
common/lib/capa/capa/templates/textinput_dynamath.html
+3
-3
common/lib/xmodule/xmodule/js/src/capa/display.coffee
+6
-42
No files found.
common/lib/capa/capa/capa_problem.py
View file @
36b44253
...
@@ -382,10 +382,10 @@ class LoncapaProblem(object):
...
@@ -382,10 +382,10 @@ class LoncapaProblem(object):
original_path
=
sys
.
path
original_path
=
sys
.
path
for
script
in
scripts
:
for
script
in
scripts
:
sys
.
path
=
original_path
+
self
.
_extract_system_path
(
script
)
sys
.
path
=
original_path
+
self
.
_extract_system_path
(
script
)
stype
=
script
.
get
(
'type'
)
stype
=
script
.
get
(
'type'
)
if
stype
:
if
stype
:
if
'javascript'
in
stype
:
if
'javascript'
in
stype
:
continue
# skip javascript
continue
# skip javascript
...
...
common/lib/capa/capa/templates/textinput_dynamath.html
View file @
36b44253
###
###
### version of textline.html which does dynam
m
ic math
### version of textline.html which does dynamic math
###
###
<section
class=
"text-input-dynamath"
>
<section
class=
"text-input-dynamath
textinputdynamath capa_inputtype"
id=
"inputtype_${id}
"
>
% if state == 'unsubmitted':
% if state == 'unsubmitted':
<div
class=
"unanswered"
id=
"status_${id}"
>
<div
class=
"unanswered"
id=
"status_${id}"
>
% elif state == 'correct':
% elif state == 'correct':
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
style=
"display:none;"
style=
"display:none;"
%
endif
%
endif
/>
/>
<div
class=
"script_placeholder"
data-src=
"/static/js/mathjax_preprocessor_for_6002x.js"
/>
<p
class=
"status"
>
<p
class=
"status"
>
% if state == 'unsubmitted':
% if state == 'unsubmitted':
unanswered
unanswered
...
...
common/lib/xmodule/xmodule/js/src/capa/display.coffee
View file @
36b44253
...
@@ -7,11 +7,6 @@ class @Problem
...
@@ -7,11 +7,6 @@ class @Problem
@
url
=
@
el
.
data
(
'url'
)
@
url
=
@
el
.
data
(
'url'
)
@
render
()
@
render
()
# TODO: Each course should be able to customize the MathJax preprocessor
# through a generic plug-in
if
(
@
id
).
search
(
'6.002x'
)
>=
0
@
mathjax_preprocessor
=
@
mathjax_preprocessor_for_6002x
$
:
(
selector
)
->
$
:
(
selector
)
->
$
(
selector
,
@
el
)
$
(
selector
,
@
el
)
...
@@ -305,47 +300,12 @@ class @Problem
...
@@ -305,47 +300,12 @@ class @Problem
if
jax
=
MathJax
.
Hub
.
getAllJax
(
target
)[
0
]
if
jax
=
MathJax
.
Hub
.
getAllJax
(
target
)[
0
]
eqn
=
$
(
element
).
val
()
eqn
=
$
(
element
).
val
()
if
@
mathjax_preprocessor
if
window
.
mathjax_preprocessor
eqn
=
@
mathjax_preprocessor
(
eqn
)
eqn
=
window
.
mathjax_preprocessor
(
eqn
)
MathJax
.
Hub
.
Queue
[
'Text'
,
jax
,
eqn
],
MathJax
.
Hub
.
Queue
[
'Text'
,
jax
,
eqn
],
[
@
updateMathML
,
jax
,
element
]
[
@
updateMathML
,
jax
,
element
]
# TODO: The 6.002x preprocessor should not be baked into capa/display.coffee, but should be a plug-in
mathjax_preprocessor_for_6002x
:
(
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'
... and also escape specific 6.002x-related keywords from MathJax,
such as 'in' (parsed by MathJax as the set symbol)
###
# 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, but watch out for keywords
replace_subscript
=
(
match
)
->
if
match
in
default_keywords
or
match
in
escape_keywords
return
match
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
escape_keyword_patt
=
RegExp
(
'
\\
b'
+
escape_keyword
+
'
\\
b'
)
eqn
=
eqn
.
replace
(
escape_keyword_patt
,
replace_escape_keyword
)
return
eqn
updateMathML
:
(
jax
,
element
)
=>
updateMathML
:
(
jax
,
element
)
=>
try
try
$
(
"#
#{
element
.
id
}
_dynamath"
).
val
(
jax
.
root
.
toMathML
''
)
$
(
"#
#{
element
.
id
}
_dynamath"
).
val
(
jax
.
root
.
toMathML
''
)
...
@@ -361,6 +321,10 @@ class @Problem
...
@@ -361,6 +321,10 @@ class @Problem
@
answers
=
@
inputs
.
serialize
()
@
answers
=
@
inputs
.
serialize
()
inputtypeSetupMethods
:
inputtypeSetupMethods
:
textinputdynamath
:
(
element
)
=>
@
mathjax_preprocessor
=
window
.
mathjax_preprocessor
javascriptinput
:
(
element
)
=>
javascriptinput
:
(
element
)
=>
data
=
$
(
element
).
find
(
".javascriptinput_data"
)
data
=
$
(
element
).
find
(
".javascriptinput_data"
)
...
...
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