CVS edit link for julou

I have written a module to add mathjax support to drupal. This is the modern alternative to jsMath and in my opinion deserve to be available to other drupal users. So I want to make this module public.

More details on http://www.mathjax.org/

CommentFileSizeAuthor
#18 mathjax.zip7.16 KBjulou
#11 mathjax.zip7.15 KBjulou
#5 mathjax.zip4.79 KBjulou
#1 mathjax.zip5.31 KBjulou

Comments

julou’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new5.31 KB

First version of the module as requested… Still very preliminary (no settings), but already functional.

Compared with other latex rendering solutions in Drupal, MathJax has several advantages:

  • drutex module is very powerful but requires a running latex environment (on the server or remote) and outputs images instead of text.
  • math filter is easier to install but also outputs images.
  • As jsMath, MathJax renders math on the client side; in addition to jsMath, it uses Web Font and provides contextual menu (among other advantages...).

As stated by MathJax authors (http://www.mathjax.org/about/):
MathJax grew out of the popular jsMath project, an earlier Ajax-based math rendering system developed by Davide Cervone in 2004. In the intervening time, there have been many significant developments relevant for web publication of mathematics: consolidation of browser support for CSS 2.1, Web Font technology, adoption of math accessibility standards, and increasing usage of XML workflows for scientific publication. Consequently, Cervone and others are designing and developing MathJax from the ground up as a “next-generation” platform, while still benefitting from the extensive real-world experience gained from jsMath.

Thanks for reviewing.

aidanlis’s picture

Hi julou,

Thanks for your initial work, there are a few problems with your module:

a) Please don't use $(document).ready, use Drupal.behaviours for adding javascript functionality.
b) I'm not sure why you're using hook_preprocess ... I think hook_init is probably a better choice, then all you'd need is the two drupal_add_js lines.
c) Please use the Libraries API for installing and downloading the MathJAX library, http://drupal.org/project/libraries

If you could make the above changes, the module is great and I'm looking forward to your next version.

avpaderno’s picture

Component: Miscellaneous » new project application
Status: Needs review » Needs work
Issue tags: +Module review

Hello, and thank you for applying for a CVS account.

As per requirements, the motivation needs to include more than two sentences (possibly a paragraph) that describe the module features (the description should make clear what the module features are without to look at the code), and a comparison with the existing solutions.

I will report here a little checklist:

  • The code needs to follow the coding standards; check in particular the format used for the control structures, and the name given to PHP variables, Drupal persistent variables, functions defined from the module.
  • Files available from third-party sites should not be included within the module/theme. This is particularly true for files that are not licensed under GPL License v2, but it is also true for files that are licensed under the same license used by Drupal.
  • The license file should not be included as well; the packaging script already include that file. In any cases, the code for modules/themes committed in drupal.org repository needs to be released under the same license used by Drupal; any compatible license is not allowed.
  • Check the code passes the Coder validation.
julou’s picture

Thanks for the feedback, I'll do my best to fix your points.
Regards, T.

julou’s picture

StatusFileSize
new4.79 KB

Here is the revised version:

- rely on libraries API to locate the MathJax folder.
- use Drupal.behaviours instead of $(document).ready
- keep using hook_preprocess, in order to activate it only on node and profile pages. hook_init was active on the admin pages as well
- removed license file
- passed coder validation.

Thank you for your feedback.

aidanlis’s picture

Hi julou,

Getting better, but you've still got some things to do!
- Try hook_init with if (arg(0) === 'node'), it really doesn't make sense to be using preprocess there
- Add a hook_requirements check for the mathjax library (I think the library name should be lowercase)
- Extra points: add a drush command to download the mathjax library (like the ckeditor module)

Thanks and keep up the good work.

julou’s picture

I'll do it…
As far as choosing between init and preprocess is concerned, I was using preprocess also because I was in mind to allow for specific node-type activation.
Is it possible to retrieve the node type with hook_init?

Thanks for your help. I must say that this "tutoring" process is really a good thing! :)

aidanlis’s picture

Yes, you can check what node type is being used with if (node_load(arg(1))->type === 'page') { ...

julou’s picture

Great!

Where can I find the list of arguments?
By the way, how can I detect a profile page using this hook_init?

requirements and drush are working now, I'll post them with the revised version of hook_init…

aidanlis’s picture

The arguments come from the url, so yoursite.com/node/1/edit would have arg(0) = node, arg(1) = 1, arg(2) = edit. This is true even the page is aliased.

A user profile page is /user/1 so you can check for this with arg(0) = user, numeric(arg(1)) and !arg(2).

If you're doing these checks you might want to add an administration page where you can control the choices, it will help meat out your module too.

julou’s picture

StatusFileSize
new7.15 KB

Here is modified version with your requests…
I'll definitely add the admin page to enable mathjax by node type (and possibly to set mathjax option with a form), but later. I really don't have time for this now.

aidanlis’s picture

Looks great, I'm happy. kiamlaluno has the final say here :)

avpaderno’s picture

Status: Needs work » Fixed

There are just two things that should be changed:

  • t() is not used inside the installation file; get_t() should be used in hook_requirements(), and the strings should not be translated in the hook_update_N() implementations.
  • There should be a jQuery function to create HTML tags in the DOM.
julou’s picture

Could you explain me:

  • the strings should not be translated in the hook_update_N() implementations (I don't use this hook).
  • There should be a jQuery function to create HTML tags in the DOM (there is already a MathJax object in the DOM and it can be used to create HTML tags in the DOM). Do you have an example of what you are looking for?

Thanks in advance.

avpaderno’s picture

  • The correct sentence is t() is not used in an installation file; I specified what should be done in hook_requirements(), and outside hook_requirements() to avoid the misunderstanding that get_t() should be used in all the code contained in the installation file.
  • The JavaScript code contains a document.createElement(); the jQuery library has its own manipulation functions.
aidanlis’s picture

I think the hook_requirements check should be a runtime check (move it into the .module file) which also moots the get_t problem :)

Also, I think, the document.createElement is fine - it's for asynchronous loading rather than standard manipulation, and it's a straight copy of the JS recommended by MathJax - I think it makes sense to keep that standard instead of maintaining our own.

Thanks for running the gauntlet julou, looking forward to good things :)

avpaderno’s picture

hook_requirements() is in the installation file as it should; see what is done from Drupal core modules.

julou’s picture

StatusFileSize
new7.16 KB

So I propose to keep hook_requirements() in the install file, replacing t() by get_t().
And to leave document.createElement() as is…

Is it fine with you?

P.S.: As far as jQ is concerned, would you like me to use getScript and a callback function?
http://api.jquery.com/jQuery.getScript
Apparently most people rely on document.createElement() and jQ append()
http://stackoverflow.com/questions/1199676/can-i-create-script-tag-by-jq...

Status: Fixed » Closed (fixed)
Issue tags: -Module review

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Assigned: Unassigned » avpaderno
Issue summary: View changes
Status: Closed (fixed) » Fixed

I am giving credits to the users who participated in this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.