Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Persian variable in MathJax?

I want to show a Persian variable, but it is displayed as individual letters س ر م ا ی ه instead of سرمایه. Can someone solve this?

Here's my code:

function createFormula() {
  var value = '`a*b/(5+9)-6+8/9+9+"سرمایه"/895+9+' + '"' + 'c' + '"' + '`';
  document.querySelector('#formula').textContent = value;
  MathJax.Hub.Queue(["Typeset", MathJax.Hub, 'formula']);
}

//show س ر م ا ی ه  insted سرمایه
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<input type="button" id="btn" value="show text" onclick="createFormula()">
<br>
<span id="formula" style></span>

JSFiddle

like image 567
lind rev Avatar asked Sep 03 '18 10:09

lind rev


1 Answers

I was able to get the text to display properly by making two changes:

  • Wrap the Persian text in \text{...}.
  • Set the option mtextFontInherit to true, to prevent MathJax's font from being used.

function createFormula() {
    MathJax.Hub.Config({
        "HTML-CSS": { mtextFontInherit: true }
    });
     
    var value='`a*b/(5+9)-6+8/9+9+\\text{'+
	  'سرمایه'
	  +'}/895+9+'+'"'+'c'+'"'+'`';
    document.querySelector('#formula').textContent =value;
    MathJax.Hub.Queue(["Typeset",MathJax.Hub,'formula']); 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<input type="button" id="btn" value="show text" onclick="createFormula()">
<br>
<span id="formula" style></span>
like image 95
Kobi Avatar answered Nov 17 '22 07:11

Kobi