OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



LatexRender vs mathjax?

The Plugin Gallery is a venue for users of PKP software to share their plugins.

Moderators: jmacgreg, michael, John

Forum rules
If you post a plugin here, please include information on which versions of which applications it is compatible with. Attach a tarball of the plugin (e.g. tar cvzf myPlugin-0.1.tar.gz plugins/generic/myPlugin). Thanks for contributing!

LatexRender vs mathjax?

Postby jqj » Fri Nov 26, 2010 10:53 am

I'm interested in providing modern support for both latex and mathml in titles and abstracts. My sense is that the state of the art at the moment is mathjax (http://www.mathjax.org). So, several questions:

1/ has anyone integrated mathjax into OJS? Looks fairly straightforward.

2/ can anyone provide a comparison of the existing latexrender plugin with mathjax? Functionality, ease of integration into OJS, reliability, browser resource demand (mathjax moves rendering to the client using javascript whereas latexrender creates images on the server), etc.

Long term, presumably the brave new world of HTML5 and cross-browser MathML support will make tools like mathjax unnecessary.
jqj
 
Posts: 15
Joined: Wed Dec 23, 2009 2:05 pm

Re: LatexRender vs mathjax?

Postby jmacgreg » Mon Nov 29, 2010 9:07 pm

Hi JQ,

Whoah, I haven't seen mathjax before, but the output looks really, really good. I don't believe anyone has implemented this in OJS as of yet. Is this something you might have the development resources to do? If so, we can certainly provide troubleshooting assistance, tips, etc. wherever you need them. If not, I can submit this as a feature request, but I'm not sure how long it would take to implement.

I may be able to provide a rough comparison between the mathjax and the existing LatexRender plugin in the near future. I'd be very interested to hear of anyone else's opinion on the plugin, and also on mathjax itself; of course, if a lot of folks are interested in it, it would definitely raise the development priority for us.

Cheers,
James
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am

Re: LatexRender vs mathjax?

Postby jmacgreg » Mon Nov 29, 2010 9:20 pm

Hi JQ,

Actually, I just took a look at their integration tutorial. Adding mathjax support would be very easy as a hack, and probably only moderately more difficult as a plugin. As a hack, all you would need to do is upload the library to your webserver, and point to it in the article header template file (templates/article/header.tpl). Should work just fine that way. It'd be nice to do this more "correctly" as a plugin, though. That's a little bit beyond my skillset, but if you might be interested in this, let me know and I can ask a developer to give you some pointers.

Cheers,
James
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am

Re: LatexRender vs mathjax?

Postby mcrider » Tue Nov 30, 2010 4:22 pm

Hi guys,

Cool script, and yeah--This would be pretty easy to integrate into OJS as a plugin. You could start from, for example, the TinyMCE plugin (plugins/generic/tinymce/TinyMCEPlugin.inc.php), strip out the getEnableFields method, do everything thats needed to make it a unique plugin (described for block plugins at http://pkp.sfu.ca/wiki/index.php/Writing_a_Block_Plugin), and replace the callback function with something like
Code: Select all
function callback($hookName, $args) {
         $jaxScript = '<script type="text/javascript" src="path-to-MathJax/MathJax.js">
               MathJax.Hub.Config({
               extensions: ["tex2jax.js", "mml2jax.js"],
               jax: ["input/TeX", "input/MathML", "output/HTML-CSS"],
            });
            </script>'

         $templateManager->assign('additionalHeadData', $additionalHeadData."\n".$jaxScript);
   }
Make sure the path to the javascript file refers to the MatJax JS (which you can place in the plugin directory, along with the fonts and any other required code), and you should be good to go..

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: LatexRender vs mathjax?

Postby jmacgreg » Thu Dec 02, 2010 11:27 pm

Hey Matt,

(Well, I never thought I'd personally be writing a support question on the forum, but here I am. :D)

Thanks for your advice. I've tried creating a generic mathjax plugin following it (specifically, by using the TinyMCE and AnnouncementFeed plugins as starting points). At this point, I have the plugin appearing in the list of generic plugins, and I can en/disable it successfully. The javascript appears in the page header successfully ... but only on the Generic Plugins page itself! It doesn't appear to be appearing on any other page. I've tried a number of different approaches (even took a look at the Google Analytics plugin), and the closest I can figure is that I'm not correctly defining the pages that this thing should appear on. Could you take a look at my MathJaxPlugin.inc.php file (embedded), and let me know if/what I'm doing wrong?

Thanks,
James

Code: Select all
<?php

/**
 * @file plugins/generic/mathjax/MathJaxPlugin.inc.php
 *
 * Copyright (c) 2003-2010 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @class MathJaxPlugin
 * @ingroup plugins_generic_mathjax
 *
 * @brief MathJax plugin for rendering LaTeX and MathML
 */


import('lib.pkp.classes.plugins.GenericPlugin');

class MathJaxPlugin extends GenericPlugin {
   /**
    * Register the plugin, if enabled
    * @param $category string
    * @param $path string
    * @return boolean
    */
   function register($category, $path) {
      if (parent::register($category, $path)) {
         if ($this->getEnabled()) {
            HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
         }
         return true;
      }
      return false;
   }

   /**
    * Hook callback function for TemplateManager::display
    * @param $hookName string
    * @param $args array
    * @return boolean
    */
   function callback($hookName, $args) {
      // Only pages requests interest us here
      if ($this->getEnabled()) {

         $templateManager =& $args[0];
         $baseUrl = $templateManager->get_template_vars('baseUrl');
         $additionalHeadData = $templateManager->get_template_vars('additionalHeadData');
         $mathjaxScript = '   <!-- MathJax plugin -->
      <script type="text/javascript" src="'.$baseUrl.'/plugins/generic/mathjax/MathJax/MathJax.js">
         MathJax.Hub.Config({
            extensions: ["tex2jax.js", "mml2jax.js"],
            jax: ["input/TeX", "input/MathML", "output/HTML-CSS"],
         });
      </script>
   <!-- / MathJax plugin -->';

         $templateManager->assign('additionalHeadData', $additionalHeadData."\n".$mathjaxScript);

      }
      
      return false;
   }

   /**
    * Get the display name of this plugin
    * @return string
    */
   function getDisplayName() {
      return Locale::translate('plugins.generic.mathjax.name');
   }

   /**
    * Get the description of this plugin
    * @return string
    */
   function getDescription() {
      return Locale::translate('plugins.generic.mathjax.description');
   }

   /**
    * Get a list of available management verbs for this plugin
    * @return array
    */
   function getManagementVerbs() {
      $verbs = array();
      $verbs = parent::getManagementVerbs();
      return $verbs;
   }
}
?>
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am

Re: LatexRender vs mathjax?

Postby mcrider » Fri Dec 03, 2010 6:02 pm

Hi James,

Yeah, this is.. weird.... Especially considering what I'm about to say: Have you cleared your caches?

Otherwise your plugin class looks pretty good. Wanna send it over my way via email and I'll take it for a spin?

Cheers,
Matt
mcrider
 
Posts: 952
Joined: Mon May 05, 2008 10:29 am
Location: Vancouver, BC

Re: LatexRender vs mathjax?

Postby jmacgreg » Mon Dec 13, 2010 4:01 pm

Hi all,

I've posted my MathJax plugin here: viewtopic.php?f=28&t=6954. It should work with OJS versions 2.3+, and probably also with OCS 2.3+ (not yet tested). Feedback appreciated!

Cheers,
James
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am

Re: LatexRender vs mathjax?

Postby jqj » Sat Dec 18, 2010 7:45 pm

[this thread should probably move to a different part of the forum, e.g. OJS Development]

I'm looking forward to trying the mathjax plugin, but had difficulty with installation.

I unpacked the .zip file into plugins/generic, enabled, and cleared the template cache and my browser cache. The mathjax code shows up on a couple of pages, notably the Plugin Management and Generic Plugins pages, but not on other pages in the journal. This sounds identical to the problem jmacgreg reported when debugging 2 weeks ago. Did you and mcrider come up with a solution?

OJS 2.3.3.3 (though for some reason the DB is still reporting 2.3.3.2 even though I ran the upgrade script after installing 2.3.3.3). mathjax 1.0.0 plugin.
jqj
 
Posts: 15
Joined: Wed Dec 23, 2009 2:05 pm

Re: LatexRender vs mathjax?

Postby jmacgreg » Sun Dec 19, 2010 1:51 pm

Hi JQ,

The bug I ran into that prevented the MathJax code from being displayed on various other pages was http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=6282 -- try following the instructions in Jerico's last comment there, and let me know if you still run into problems.

Cheers,
James
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am

Re: LatexRender vs mathjax?

Postby jqj » Mon Dec 20, 2010 8:42 pm

Before I saw your message I did a complete reinstall of the ojs code (keeping same files, public, and database, which I had previously updated to 2.3.3.3 by first applying the version patch followed by the update script). After that reinstall (and reinstall of the plugin code) your mathjax plugin worked fine on all pages as expected. So I'm not completely sure what I did to fix things, but it's possible that jerico's advice was a correct analysis of my problem.

Right at the moment I'm a happy camper with working mathjax on my test server. Next I need is a math journal that wants to take advantage of it...
jqj
 
Posts: 15
Joined: Wed Dec 23, 2009 2:05 pm

Re: LatexRender vs mathjax?

Postby jmacgreg » Tue Dec 21, 2010 3:47 pm

Hi JQ,

Thanks for keeping us up to date on your progress with this. I'm not personally familiar with the needs of math journals, so if you do find one that takes advantage of the plugin, I'd really appreciate hearing how it works out! Thanks again, as well, for bringing our attention to MathJax.

Cheers,
James
jmacgreg
 
Posts: 4183
Joined: Tue Feb 14, 2006 10:50 am


Return to Plugin Gallery

Who is online

Users browsing this forum: No registered users and 0 guests