Commit 2b17fb62 by kimth

Translate between 6.002x subscript convention and standard Latex

parent b85fefe6
...@@ -299,8 +299,24 @@ class @Problem ...@@ -299,8 +299,24 @@ class @Problem
target = "display_#{element.id.replace(/^input_/, '')}" target = "display_#{element.id.replace(/^input_/, '')}"
if jax = MathJax.Hub.getAllJax(target)[0] if jax = MathJax.Hub.getAllJax(target)[0]
MathJax.Hub.Queue ['Text', jax, $(element).val()], eqn = @latexify($(element).val())
MathJax.Hub.Queue ['Text', jax, eqn],
[@updateMathML, jax, element] [@updateMathML, jax, element]
latexify: (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
return match
return match[0] + '_{' + match.substr(1) + '}'
return eqn.replace(/[A-Za-z]\w+/g, subscript_replace)
updateMathML: (jax, element) => updateMathML: (jax, element) =>
try try
......
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