how to set stack to mathjax?

泄露秘密 提交于 2019-12-11 07:22:37

问题


i want set expresion of stack to mathjax (dynamically)

this is my stack

var showStack=[];
showStack.push({
                Key: 'topic',
                Value:"سرمایه"
            });
showStack.push({
                Key: 'operator',
                Value: "+"
            });            
showStack.push({
                Key: 'topic',
                Value: "مالیات"
            });          
showStack.push({
                Key: 'opeator',
                Value: "/"
            });
showStack.push({
                Key: 'number',
                Value: "8569"
            });            
showStack.push({
                Key: 'opeator',
                Value: "-"
            });      
showStack.push({
                Key: 'topic',
                Value: "اندوخته قانونی - سال قبل"
            });      

and this code create my fomula from my stack

  jQuery.each( showStack, function( i, val ) {
  if(val.Key=='topic'){
    text+='`\\text{'+ val.Value+'}`';
  }
  else
    text+=val.Value;
});

createFormula for create mathjax formula

 function createFormula() {
  var text="";
  MathJax.Hub.Config({
    "HTML-CSS": { mtextFontInherit: true }
});


  document.querySelector('#formula').textContent =text;
  MathJax.Hub.Queue(["Typeset",MathJax.Hub,'formula']);      
 }

but result is

سرمایه+مالیات/8569-اندوخته قانونی - سال قبل

my code not work,Where is my problem? thanks


回答1:


You just have to change this code

 var text="";
jQuery.each( showStack, function( i, val ) {
  if(val.Key=='topic'){
    text+='\\text{'+ val.Value+'}'; // remove `
  }
  else
    text+=val.Value;
});

And add this code

var value='`'+text+'`';

 document.querySelector('#formula').textContent =value;
 MathJax.Hub.Queue(["Typeset",MathJax.Hub,'formula']);


来源:https://stackoverflow.com/questions/52160323/how-to-set-stack-to-mathjax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!