Skip to content

Commit

Permalink
JMEsimplifysub subs values into a tree, not a JME string
Browse files Browse the repository at this point in the history
This avoids the problem where a decimal value is rendered in JME as `dec(...)`
and then rendered in TeX as `\textrm{...}`.
  • Loading branch information
christianp committed Nov 22, 2022
1 parent 6b7cd40 commit 9b08ae7
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions editor/static/js/editor.js
Expand Up @@ -94,16 +94,31 @@ $(document).ready(function() {
this.Push(mml);
}
function JMEsimplifysub(name) {
var rules = this.GetBrackets(name);
if(rules===undefined) {
rules = 'all';
var ruleset = this.GetBrackets(name);
if(ruleset === undefined) {
ruleset = 'all';
}
var expr = this.GetArgument(name);

var scope = currentScope;
expr = Numbas.jme.subvars(expr,scope,false);

var tex = Numbas.jme.display.exprToLaTeX(expr,rules,scope);
var tree = Numbas.jme.compile(wrap_subvar(expr));

function subvars(tree) {
if(tree.tok.type=='function' && tree.tok.name == 'subvar'){
return {tok: scope.evaluate(tree.args[0])};
}
if(tree.args) {
var args = tree.args.map(subvars);
return {tok: tree.tok, args: args};
}
return tree;
}

var subbed_tree = subvars(tree);

var tex = Numbas.jme.display.treeToLaTeX(subbed_tree, ruleset, scope);

var mml = TEX.Parse(tex,this.stack.env).mml();

this.Push(mml);
Expand Down

0 comments on commit 9b08ae7

Please sign in to comment.