Product Dev Back to Ghost

Adding MathJax to your Ghost blog

To display mathematics within your blog posts you can easily add MathJax to Ghost. MathJax uses javascript to process LaTeX, MathML, or AsciiMath notation as HTML, SVG or MathML equations within your blog.

There are two possible ways to include MathJax with your blog, the easiest being through Code Injection.

Adding MathJax using Code Injection

To get started, log into your Ghost blog by navigating to yourblog.com/ghost.

Next, access your Code Injection settings.

The code injection settings screen should include both a Blog Header section and a Blog Footer section.

Copy and paste the MathJax CDN script into the Blog Header section. This will load the latest version of MathJax with your blog.

<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">  
</script>  

Next, click Save in the top right hand corner. When you've finished, you should be able to use the notation to create equations.

Adding MathJax to your theme files

If you prefer not to add MathJax via code injection, you can always add it directly to your theme files.

To add MathJax to your theme, first download the latest version of the project.

Once downloaded, you will need to include the MathJax.js file inside your theme. Place it directly into the asset directory of your theme, ideally in the same location as your other javascript files.

Next, open the default.hbs file. In the <head> section of the code, add in a reference to the MathJax file using the {{asset}} helper, stored within your asset directory, like this:

<script type="text/javascript" src="{{asset "js/MathJax.js"}}">  
</script>  

Once the script has been added, save the file and upload the revised file to your blog. You will need to restart Ghost for the changes to display.

If added successfully, your blog should now be capable of displaying equations.

Author image

Sarah Frantz

Sarah is the Head of User Happiness at Ghost. She spends her time helping out users on Ghost(Pro) and crafting our support documentation.

Subscribe to Weekly Posts