问题
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