changing digits language or font in the rendered output

113 views
Skip to first unread message

a.maha...@gmail.com

unread,
Jul 18, 2015, 1:49:04 PM7/18/15
to mathja...@googlegroups.com
hi to everyone,
we have used mathjax to our website(java- GWT) to render formulas  and it works pretty fine, but the problem is, we need to show the digits in persian/arabic language to our users 
I have searched to find a solutions for days and I could find anything:(. I need a way to replace english digits with persian digits or changing digits' font.  any suggestion ?


Thank you in advance


Davide P. Cervone

unread,
Jul 20, 2015, 12:34:17 PM7/20/15
to mathja...@googlegroups.com
In order to access the Persian digits, you would need to use references to the Unicode positions for those glyphs.  The Persian digits are at U+06F0 to U+06F9 (and the Arabic digits are U+0660 to U+0669).  Therefore you could use  \unicode{0x6F2} to produce the Persian glyph for 2 (۲).  The web fonts available in MathJax do not include glyphs for the Arabic or Persian digits, so there is no guarantee that the reader will be able to view this symbol, however.  You can improve the odds by including suggested fonts that include the symbol.  It looks like Arial and Times New Roman both include the Arabic and Persian characters, so 

\unicode['Times New Roman',Arial]{x6F2}

would likely make it possible for most viewers to see the characters you expect.  Of course, you could create macros like \0, \1, \2, etc. to make it easier to type.

Alternatively, if you want to have "123" display as "۱۲۳" automatically, that can be done by adding the following

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  "HTML-CSS": {
    undefinedFamily: "'Times New Roman',Arial,STIXGeneral,'Arial Unicode MS',serif",
    noReflows: false
  }
});
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready", function () {
  var REMAP = MathJax.OutputJax["HTML-CSS"].FONTDATA.REMAP;
  var ZERO = 0x6F0;     // use 0x660 for Arabic, 0x6F0 for Persian
  for (var i = 0; i < 10; i++) {REMAP[0x30+i] = ZERO+i}
});
</script>

to your page just BEFORE the script that loads MathJax.js itself.  This will remap all the digits 0 through 9 to their Persian (or Arabic if you change ZERO = 0x6F0 to ZERO = 0x660) counterparts.

Note that this only affects the HTML-CSS output.  A similar configuration would work for SVG output if you change the HTML-CSS to SVG throughout.  But this will NOT change the results for NativeMML output (the original \unicode{} approach would work in all three output formats, however).

Hope one of these does what you want.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

a.maha...@gmail.com

unread,
Jul 21, 2015, 4:13:40 AM7/21/15
to mathja...@googlegroups.com, dp...@union.edu
Thank you David
You made my day. it works quite well.
Reply all
Reply to author
Forward
0 new messages