-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,34 @@ MathJax.Extension.Arabic = { | |
'8': '٨', | ||
'9': '٩' | ||
}, | ||
// numbers with arabic decimal separator ',' | ||
arabicDecimalSeparator: { | ||
'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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SamirElkhatib please use literal values like |
||
}, | ||
|
||
// support for arabic (modern) numerals | ||
arabicNumbersMap: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why this is needed. We can disable the |
||
'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 | ||
',': '،', | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
|
||
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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the section above needs refactoring:
|
||
|
||
|
||
var replaceNumber = function (m) { | ||
return numbersMap[m]; | ||
|
There was a problem hiding this comment.
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.