Problem/Motivation

The usual way of managing text parsing in Drupal is through text formats, which are collections of input filters. That MathJax adds a 'global' filter – set by path/page rather than the selected text format – may confuse Drupal users (and deviates from best practices). It also risks parsing text as LaTeX, when the user had no intention of writing LaTeX.

Proposed resolution

* Add a filter for MathJax, that can be used when setting up text formats.
* Allow using this filter, as an alternative to the 'global switch'.

Completed tasks

* Added a MathJax text-filter.
* Removed deprecated configuration variables.
* Removed the per-page activation settings.
* Modify the administration forms with a radio button choice for configuration: text format, or custom.
* Retain the current configuration as "custom" when upgrading.
* Load the appropriate configuration based on the user's choice.
* Text format will be the default for new installs.
* Functional testing.
* Web tests.

Remaining tasks

User interface changes

* A new filter at the text formats settings.
* A choice of configuration types: global, text format, or custom.
* Custom will be the default when upgrading.

API changes

Not applicable.

#1526034: Disable Mathjax for an input format

CommentFileSizeAuthor
#7 2084267-7.patch376 bytesjweinstein

Comments

cilefen’s picture

This is a much-needed feature.

cilefen’s picture

Under Remaining Tasks, I also suggest we add: Read up on how to apply MathJax formatting to certain DOM elements (not globally).

cilefen’s picture

Example module that creates an input filter.

cilefen’s picture

Status: Active » Needs work

I pushed a prototype to 7.x-2.x.

To test it, set up an input type with the MathJax filter and also set your MathJax configuration to:

MathJax.Hub.Config({
  extensions: ["tex2jax.js"],
  jax: ["input/TeX","output/HTML-CSS"],
  tex2jax: {
    inlineMath: [ ['$','$'], ['\\(','\\)'] ],
    processEscapes: true
  },
  showProcessingMessages: false,
  messageStyle: "none",
  elements: ['mathjax']
});

Known issues:
* This will work on only one DOM ID. This is because the Typeset() method by default wants a DOM ID, not a class.

cilefen’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

See issue #2084267: Allow using MathJax as a input filter for text formats, rather than a global filter

This is a prototype of the idea. To test it, set up an input type with the MathJax filter and also set your MathJax configuration to:

MathJax.Hub.Config({
  extensions: ["tex2jax.js"],
  jax: ["input/TeX","output/HTML-CSS"],
  tex2jax: {
    inlineMath: [ ['$','$'], ['\\(','\\)'] ],
    processEscapes: true,
    processClass: "tex2jax",
    ignoreClass: "html"
  },
  showProcessingMessages: false,
  messageStyle: "none"
});

Known issues:
* None

cilefen’s picture

This was done with the advice of Peter Krautzberger on the MathJax user group: https://groups.google.com/d/topic/mathjax-users/kGLtdrssYrg/discussion

jweinstein’s picture

StatusFileSize
new376 bytes

The filter works as expected - with the patch attached, save the default MathJax configuration and create a text format using a MathJax filter.

The patch adds a missing comma to the MathJax configuration variable.

cilefen’s picture

Thank you - patched.

itangalo’s picture

Awesome work on this feature!

However, as far as I can tell the patch doesn't make much difference. I still need to enable MathJax globally, and then everything on a page will be processed – regardless of whether the filter is used or not. (This is at least what happens when I try the 2.x branch on a node with plain text filter. Even the title is processed by MathJax.)

I'll dig a bit, and see what I can find.

cilefen’s picture

Did you replace the MathJax configuration on the admin screen with this?:

MathJax.Hub.Config({
  extensions: ["tex2jax.js"],
  jax: ["input/TeX","output/HTML-CSS"],
  tex2jax: {
    inlineMath: [ ['$','$'], ['\\(','\\)'] ],
    processEscapes: true,
    processClass: "tex2jax",
    ignoreClass: "html"
  },
  showProcessingMessages: false,
  messageStyle: "none"
});
itangalo’s picture

That's probably what I did wrong – now things are working as they should. Thanks!

itangalo’s picture

I also realized that the MathJax filter needs to be placed below the 'Limit allowed HTML tags' filter. Not 100% why.

itangalo’s picture

Again – awesome stuff. I was going to sit down and try to write this code tonight, and found that it was already written! (Instead I could spend some time on boring code cleanup, to spare you that work.)

Are you thinking of keeping the 'global' option for MathJax in the 2.x branch? If so, that checkbox on the config page makes sense – but then the conditions for running input filters must be reversed (and only used if the global switch is off).
If the global option will be dropped, then the condition for running input filters can be dropped all together. (If the filter is called, it should always be executed.)

cilefen’s picture

Let me think about that a while.

cilefen’s picture

I think we need to either throw away the global option or offer a choice:

(*) Text filter: MathJax will be available as a text filter.
( ) MathJax runs globally.

By choosing either option, a default MathJax configuration will be placed into the admin form (by JS, I think), then the admin may edit.

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
cilefen’s picture

Issue summary: View changes
cilefen’s picture

Status: Needs work » Needs review
cilefen’s picture

jweinstein’s picture

After testing the 7.x-2.x branch, using mathjax as a text format seems to work. The instructions are clear and work as expected.

cilefen’s picture

Automated tests were failing in 7.x-2.x-beta1, those have been fixed in 7.x-2.x.

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Status: Needs review » Closed (fixed)