Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter
Support for Vanilla Forums Cloud product

In this Discussion

Follow Us

LaTeX editor

cdavidcdavid New
edited August 2010 in Questions
Dear all,

I am interested in developing a Math Forum version of Vanilla that would contain some sort of LaTeX editor in which you can put LaTeX code and then have the post result as XHTML (+MathML).

We have a tool (a daemon running here ) that is able to take LaTeX code as input and output XHTML (+MathML for the math) via a version of LaTeXML ( ), but I am not sure how to go about modifying VanillaForums.

The first idea that I have would be to have in the MySQL Discussion table two columns, Body and BodySrc and when you are done editing a webpage, what you wrote should be kept in BodySrc and a hook should be launched to send the LaTeX content that you wrote to the daemon running and the result will be put in the Body column and displayed.

In my mind, that would require changes in only three places:

1. In the MySQL table structure (which I am familiar with)
2. In the PHP files where the adding to the database is done where I should:
a. save to BodySrc instead of Body
b. call the daemon with BodySrc
c. get the result from the daemon and put it in Body.
3. In the PHP files, when the content of the Body should be edited, it should load BodySrc instead of Body

Unfortunately, I am not very familiar with how VanillaForums works and would need guidance to see where things happen and to modify in the appropriate place.

If anyone is willing to give me a file name and the line of code where the magic happens, I would be eternally grateful.


P.S.: MathML only works in Firefox, or other Gecko based browsers. Don't expect anything for Webkit based browsers or any other.


  • TimTim Lord of Servers Vanilla Staff
    Hi Catalin,

    This sounds like a good use case for a custom Input Formatter.

    Our current MySQL table structure has a Body column, as well as a Format column. When the HTML formatter is enabled, posts go into the Comment and Discussion tables with the Format 'Html'. Something similar could be done with a LaTeX plugin and corresponding Format value. The plugin can hook the comment/discussion save and load events and do any formatting it needs to before sending the comment to the browser / database.

    Check out the bundled HtmLawed plugin for a fully functional example of this.


    Vanilla Forums Senior Developer [GitHub, Twitter,]

  • Hello, @Tim !

    Oki, so first of all thanks for the input.

    I started reading the documentation of htmLawed and tried to find a way to display MathML inside a post, but failed to find some configuration and also bumped into this:

    " * It cannot handle input that has non-HTML code like SVG and MathML. One way around is to break the input into pieces and passing only those without non-HTML code to htmLawed. "

    So, for now, my first priority is to be able to display MathML code into a post; e.g.: if I put this code in a post, it should render nicely as x^2 in Firefox:


    Once I can configure VanillaForums to display the exact XHTML fragment from the database, we can go on to the next step (which would be transforming the LaTeX source from the post to XHTML and storing this somehow in the database).

    So, what happens now is that if I enable htmLawed, only the stuff inside the XML gets kept, while if I disable it, I guess HTMLPurifier kicks in and replaces the <> with < > at rendering. I saw that the HTMLPurifier add-on should allow HTML, but is not namespace aware, therefore, not that useful for MathML. So, in the end, is there any way in which I can tell VanillaForums to display directly the content from the database, without any modifications? I imagine that, afterwards, I should restrict only to the MathML namespace ( xmlns:m="" ).

    I will try to understand even further what happens behind the scenes and will come back with questions/answers.

    Thanks a lot for your help. Highly appreciated.

  • Progress update: I was trying all day long to add the m:math element to HTMLPurifier so that it is properly displayed, but I have failed miserably. I have tracked down the problem to this, if I have this plugin enabled.

    If all plugins are disabled, I still see that < , > , & , ' and " are replaced by their HTML counterparts, resulting in posts that contain the HTML code, only with <, > etc. Unfortunately, I can't see where these replacements are made in the PHP, because in the database, the content is preserved as HTML. I've narrowed it down to lines 386 + 20 of library/core/class.format.php ... Working on this.

    Thanks again,

  • Well, I went through some steps, but finally did it. Will hack around a bit more, but will release my LaTeX editor plugin pretty soon.

    Among the hacks:

    I have made some adjustments to the core in order to be able to serve application/xhtml+xml in order to be able to display MathML.
    Did some jQuery hack to enable XHTML in jQuery (usually breaks in the each function).
    Adjusted jquery.autogrow to support XHTML markup (the bundled one breaks due to the bad design).
    Adjust HtmLawed to accept MathML tags in the m namespace (consider having xmlns:m="" ).

    The deployment of this forum will be a redesigned PlanetMath ( ).

    Hoping to release soon,

  • Catalin - I'm interested in this functionality as well. Did your project progress any further?
  • @leSunnyRa -- yes, I have a version of this plugin. We use for much more complicated stuff -- we basically extended Vanilla into a CMS, but it works also only for the forum part. It makes use of LaTeXML ( ) -- actually an extension of LaTeXML that is able to transform LaTeX to XHTML on the fly. Please contact me in a message so that I can know more about what you want to do -- since the plugin is not "Vanilla material" yet, it's not stable enough.

Sign In or Register to comment.