【问题标题】:how to set stack to mathjax?如何将堆栈设置为mathjax?
【发布时间】:2019-02-09 03:14:15
【问题描述】:

我想将堆栈的表达式设置为 mathjax(动态)

这是我的堆栈

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: "اندوخته قانونی - سال قبل"
            });      

这段代码从我的堆栈中创建我的公式

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

createFormula 用于创建 mathjax 公式

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


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

但结果是

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

我的代码不起作用,我的问题在哪里? 谢谢

【问题讨论】:

    标签: jquery mathjax


    【解决方案1】:

    您只需要更改此代码

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

    并添加此代码

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 2019-12-14
      相关资源
      最近更新 更多