XenForo MathJax and XF 2.0.x | XenForo Italia | Your guide to the xenForo world
wizard

XenForo MathJax and XF 2.0.x

wizardVerified member

Administrator

Staff member
Vip Member
Reputation: 61%

Include MathJax


I help administrate a math help site now running XF 2.0.10, and I wanted to share with this community how I added support for LaTeX powered by Mathjax to the site using a series of template edits.

The first thing I did was to initialize and define the scripts to be called on every page so that when any page is loaded, any LaTeX to be rendered will be done.

Open the "PAGE_CONTAINER" template and add the following code to the end of the template:

JAVASCRIPT:
You must log in to view
(90 lines)

This includes my custom macros, and definitions. You can find leaner configurations at MathJax's support site if you wish.

docs.mathjax.org

You don't want any LaTeX markup (that may be present if you are working on a post and have come back to it) to be rendered in the quick reply editor, so open the "quick_reply_macros" template and locate the line:

Code:
You must log in to view
(1 lines)

And change it to:

Code:
You must log in to view
(1 lines)

This will tell MathJax to ignore that element when rendering the markup.

Next, we want any LaTeX to be rendered when a new post is posted, and since new posts are added via AJAX, we will need to call for the new posts to be processed. Open the "post_macros" template, and locate the line:

Code:
You must log in to view
(1 lines)

And directly beneath that line add:

JAVASCRIPT:
You must log in to view
(6 lines)

Next, we want to process any markup when a post is being previewed, so open the "bb_code_preview" template, and directly above the last line, which reads:

Code:
You must log in to view
(1 lines)

Add the following:

Code:
You must log in to view
(3 lines)

And finally, we want any markup in thread previews to be rendered, so open the "thread_preview" template, and directly above the last line, which reads:

Code:
You must log in to view
(1 lines)

Add the following:

Code:
You must log in to view
(3 lines)

And that's what I did to add support for MathJax to a XF 2.0.10 site. :)

Maths between dollars is inline: ∑nk=1k=n(n+1)2∑k=1nk=n(n+1)2.

Maths between slash-square-brackets is display:

n∑k=1k=n(n+1)2∑k=1nk=n(n+1)2
 
Back
Top