Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Arabic numerals and decimal separator #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/tex.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,34 @@ MathJax.Extension.Arabic = {
'8': '٨',
'9': '٩'
},
// numbers with arabic decimal separator ','
arabicDecimalSeparator: {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this map, we can use RegExp instead without the need to repeat what's in numbersMap. I can add more details if you'd like.

'0.': '\u0660\u066b',
'1.': '\u0661\u066b',
'2.': '\u0662\u066b',
'3.': '\u0663\u066b',
'4.': '\u0664\u066b',
'5.': '\u0665\u066b',
'6.': '\u0666\u066b',
'7.': '\u0667\u066b',
'8.': '\u0668\u066b',
'9.': '\u0669\u066b',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamirElkhatib please use literal values like ٩ instead of \u0669. There's a build step to do that conversion. Let's keep the work human friendly.

},

// support for arabic (modern) numerals
arabicNumbersMap: {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this is needed. We can disable the numbersMap instead of doing this. Right?

'0': '0',
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
},

operatorsMap: {
// English to Arabic punctuations
',': '،',
Expand Down Expand Up @@ -203,8 +231,26 @@ MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () {
return token;
},
arabicNumber: (function () {
var englishNumbersRegExp = /[0-9]/g;
var numbersMap = MathJax.Hub.config.Arabic.numbersMap;
// check for MathJax options
useHindiNumeral = MathJax.Hub.config.useHindiNumeral
useArabicDecimalSeparator = MathJax.Hub.config.useArabicDecimalSeparator

// Default options
if (useHindiNumeral == null) useHindiNumeral = true
if (useArabicDecimalSeparator == null) useArabicDecimalSeparator = true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we identify a better pattern than this e.g. use falsey variables like: disableArabicDecimalSeparator and disableHinduArabicNumbers


arConfig = MathJax.Hub.config.Arabic
if(useArabicDecimalSeparator){
var englishNumbersRegExp = /[0-9]\.?/g;
var numbersMap = {};
for (var nma in arConfig.numbersMap) { numbersMap[nma] = arConfig.numbersMap[nma]; }
for (var nma in arConfig.arabicDecimalSeparator) { numbersMap[nma] = arConfig.arabicDecimalSeparator[nma]; }
} else{
var englishNumbersRegExp = /[0-9]/g;
if(useHindiNumeral) var numbersMap = arConfig.numbersMap;
else var numbersMap = arConfig.arabicNumbersMap
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the section above needs refactoring:

  • The for looop isn't protected with hasOwnProperty
  • Avoid for-loops and use RegExp replace functions like var mapped = text.replace(englishNumbersRegExp, replaceNumber);



var replaceNumber = function (m) {
return numbersMap[m];
Expand Down