-
Notifications
You must be signed in to change notification settings - Fork 31
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
MathJax Arabic extension #20
Conversation
👍 awesome to see your work move forward! |
Thanks Peter :) |
9cf59ee
to
ed92b87
Compare
Hi @pkra I've make some progress and modularized my extension. However I'm using functions as modules. Do you think it's wise to use Startup hooks and events to declare modules dependency in extensions or is that incorrect? My goal is to put each module in a separate file and perhaps I'm not a big fan of huge JS files. What do you think? |
cc @dpvc (traveling this week) |
(to clarify: I'm traveling this week.) |
@pkra 👍 |
It is correct to use those signals and hooks. That's what they are there for. I haven't looked closely at your code, but it looks like the right thing to me. |
Thanks @dpvc :) Will do it and update the PR :) |
@pkra Looks like I've completed most of the work, if not all of it. It has been heavily refactored. Now it should be much easier to understand and to extend. It would be great if someone review it, and perhaps merge it ^_^. I will be focusing on bringing this version into edX platform so we can test it and hopefully use it for our students. |
@OmarIthawi awesome -- we'll take a look! |
Thanks @pkra 😄 |
Sorry we dropped the ball on this, @OmarIthawi. @dpvc PTAL? |
No problem Peter :) |
@OmarIthawi, first of all, thanks for all your efforts in working on this, and putting it into shape for the 3rd-party repository. We really appreciate what you have done. I do have some comments on the code, however. I will make some general comments here, and then add in-line comments to the code about specific issues. I know that receiving comments on your code can be traumatic, so please don't take what I say as criticism. We are glad to be working with you on this. First, I should point out that the difference between the unpacked and packed versions of the code in MathJax is that the packed versions use YUIcompressor to remove white-space and comments, and reduce the code size via variable name substitutions (from long names to short ones) and other code-analysis techniques. Since this compressed version becomes nearly unreadable, the uncompressed version is retained for development purposes. So the uncompressed copy usually is a working copy of the code with the same file structure as the compressed version, but with all the white-space and comments in it. You seem to have the uncompressed version as a collection of separate files that are combined into your "compressed" version. While I understand that setup, it is not what we usually do in MathJax, and so it is somewhat unusual in that respect. While you are free to manage your code however you wish, I did want to point out that this is not consistent with the rest of how MathJax works. Second, I'm not sure I understand your use of The usual way to do this in MathJax would be to create an object in the
This makes it a bit harder to break your default configuration into separate pieces in separate files, but it could be done, if you really want to do that. I will make further comments in the code itself. |
Arabic: { | ||
identifiersMap: { | ||
// Sets operations, and other stuff | ||
'A': 'أ', |
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.
You should probably use "\u0623"
rather than 'أ'
, since the latter depends on the page encoding, while the former doesn't. Scripts are loaded using the encoding of the page (last time I checked), so this would require the page to be UTF-8, and we don't know what encoding may be used on the page. So it is best to use explicit unicode code points via \uXXXX
instead.
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.
- ✓ Sure, I can do that. I might do it as a postprocessing step along with the other gulp steps that I have.
It is really handy for me to see the original Arabic text instead of unicode points. In production this is not a requirement, so I can post process this.
OK, I've had the chance to go through your code in detail, and overall, I like the changes you have made. There are still a few items to consider, which I will mark in the code itself. Most of these are minor (often issues of style), and you can ignore them if you wish. But a couple are important. You were correct to be concerned about the replacement for the In the previous round of comments, I had suggested that you replace the raw Unicode characters by |
className += ' mar'; // Keep the leading space | ||
} | ||
|
||
flipElement.className = className; |
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.
The code from lines 96 to 102 could be simplified. There is really no need for a separate variable for this, and the initial space is not needed in line 96 (despite the comment) since there is no previous className
value to worry about. You could just do
flipElement.className = 'mfliph';
if ('ar' === this.arabicFontLang) flipElement.className += ' mar';
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 might take longer than I thought to work on the amendments you've suggested.
I intentionally left the unpacked version without encoding these characters. However the packed version has them encoded correctly. I mainly did this to enable easier debugging (which is what the unpacked versions for, right?). If you still think that both of them needs this. I don't mind adding it to the build script. |
OK, great. I didn't check the minified version. You are right that the un-minified version is mostly for debugging, but ideally it would be the same code as the minified one (modulo the minification), so having one with unicode characters and the other with
so that you get the best of both worlds. But it is your code, so you should do what seems best for you. I am only making suggestions. |
I had to work on a many internal tasks. I have time now to get back to this PR.
I ended up escaping it in both the packed and the unpacked version, while keeping it only in the source code. |
@dpvc Thank you so much for your time and comments. I have addressed all the amendments you've suggested. Please let me know if you have any additional comments. Thanks to you the extension is now much better. I have tested the extension so far on 85 test cases (publically accessible), and it looks good so far. The other good news, we're already using it on Edraak.org for more than 15,000 enrollee in the first course: |
It's looking great, @OmarIthawi! |
|
||
var escapeRegExp = (function () { | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
var reHasRegExpChar = new RegExp(reRegExpChar.source); |
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.
This variable is no longer used, and can be removed.
Thanks for all your work on this. I did note two minor items (an unused variable that can be removed, and a left-over |
@OmarIthawi let me know if you want to update this PR or if I should merge -- finally! 🎆 |
1cfb353
to
0b17823
Compare
Thanks a lot David for your detailed review and feedback. It truly helped me to get the extension done correctly. It is my pleasure to work with you and contribute to such great and highly beneficial project like MathJax. I have fixed the two issues, and finally now we're good to go. |
Woohoo! |
The extension should now be available on the CDN's contrib path (check http://cdn.mathjax.org/mathjax/contrib/arabic/arabic.js) |
Thanks again for this amazing contribution, @OmarIthawi! |
🎉 🎉 🎉 🎉 🎉 Thank for your efforts 😀 🎉 🎉 🎉 🎉 🎉 |
This pull request will be updated to get the Arabic MathJax solution from the original hack.
In this pull request the following will be done:
Contrib
extension\ar
command.Note: Now it is hard-coded in the the lang attribute of the tag.
\lim
(Unlike\sum
and\int
, this requires a completely different drawing)I will not try to make a one-size fits all RTL solution, instead I will try to do the following:
Extra Features:
\transt{Radius}{نق}
for text and\trans{\Pi}{\text{باي}}
for generic TeX.Pending TODOs from @dpvc 1st review:
Test
MML.chars
andMML.entity
instead of overridemi
,mo
andms
Result: Couldn't get it running, and resorted back to overriding
mi
,mo
andms
.Handle AMSmath array/tables
Test with the
\tag{}
for equations.Refactor the
AlignedArray
andthis.stack.env.lang
to avoid the three nested loops.