Pass values in vice versa with Javascript or jQuery

3

Hi, I'm working with Mathquill, what happens is that I have this expression format.

     sqrt[]{}

which can be

     sqrt[3]{4+5-8}

or any number within the brackets and braces, what I did was modify the template of the api of the root that is:

   _.textTemplate = ['sqrt[',']{','}'];

for this

    _.textTemplate = ['(',')^(1/',')'];

so the result is:

    (3)^(1/4+5-8)

The problem is that the values go the other way, and should be shown like this:

    (4+5-8)^(1/3)

I need your help please

    
asked by goku venz 14.03.2017 в 22:43
source

2 answers

0

I solved the problem with the function _.text , modify it to return the template with the values in vice versa

 _.text = function(){ return  '('+this.ends[R].text()+')'+'^(1/'+this.ends[L].text()+')'; };

at the end the code stayed like this:

    var NthRoot =
LatexCmds.nthroot = P(SquareRoot, function(_, super_)
{
  _.htmlTemplate =
      '<sup class="mq-nthroot mq-non-leaf" style="margin-top:1%">&0</sup>'
    + '<span class="mq-scaled">'
    +   '<span class="mq-sqrt-prefix mq-scaled">&radic;</span>'
    +   '<span class="mq-sqrt-stem mq-non-leaf">&1</span>'
    + '</span>'
  ;


 _.text = function(){ return  '('+this.ends[R].text()+')'+'^(1/'+this.ends[L].text()+')'; };

});
    
answered by 16.03.2017 / 20:48
source
0

Suppose then that you took nthroot

var NthRoot =
LatexCmds.nthroot = P(SquareRoot, function(_, super_) {
  _.htmlTemplate =
      '<sup class="mq-nthroot mq-non-leaf">&0</sup>'
    + '<span class="mq-scaled">'
    +   '<span class="mq-sqrt-prefix mq-scaled">&radic;</span>'
    +   '<span class="mq-sqrt-stem mq-non-leaf">&1</span>'
    + '</span>'
  ;
  _.textTemplate = ['sqrt[', '](', ')'];
  _.latex = function() {
    return '\sqrt['+this.ends[L].latex()+']{'+this.ends[R].latex()+'}';
  };
});

And you changed

 _.textTemplate = ['sqrt[', '](', ')'];

By

 _.textTemplate = ['(',')^(1/',')'];

For what you want to do, if you notice the command that reaches Latex:

return '\sqrt['+this.ends[L].latex()+']{'+this.ends[R].latex()+'}';

Keep saying: transform this into \sqrt[param izquierdo]{param derecho}

You had to change that part to be

return '\sqrt['+this.ends[R].latex()+']{'+this.ends[L].latex()+'}';
    
answered by 15.03.2017 в 13:48