# Integration of Mathjax and JadeJS

## Problem

I have a problem integrating Mathjax and Jade in Express. I need to show formulas inside a 'pre', so I am trying to configure Mathjax through a script. This is my code:

script(type="text/x-mathjax-config")
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\$$','\$$']],
skipTags: ["script","noscript","style","textarea","code"]
}

});


My problem is that when I try to see the page it throws this error:

SyntaxError: Unexpected token {

at Object.Function (unknown source)
at Promise.EventEmitter.emit (events.js:88:17)


Does anyone know what might be happening?

Thank you.

Problem courtesy of: andresmechali

## Solution

The issue appears to be with the type='text/x-mathjax-config'. If I remove that, the view renders fine. If I leave it as it is, jade interprets the script contents as jade tags. I don't think this is a bug in jade, since text templates should be able to be able to be written in jade as well.

In any case, it looks like mathjax requires the type in order to execute the configuration properly, so we need to work around that issue. The easiest solution is simply to keep everything as it is but add a . at the end of the script tag. This will make everything under it a text literal.

script(type="text/x-mathjax-config").
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\$$','\$$']],
skipTags: ["script","noscript","style","textarea","code"]
}
});


Alternatively, maybe you could configure mathjax after the page is loaded, as seen here. Note that I know nothing about mathjax, I just glanced at the documentation.

Solution courtesy of: David Weldon

## Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.