# MathJax Local Configuration File

## Motivation

Before I changed the HTML syntax for embedding MathJax with a local configuration file, I often encountered error while viewing the math rendered by MathJax.1 The custom commands defined in the local configuration file sometimes wouldn’t be converted to mathematical expressions in a post while browsing the page for the first time. Though refreshing the page can get the math shown, it’s quite troublesome. Therefore, I searched for a better way in the official manual.

## Problem

I tried following the instructions in MathJax’s official Wiki for using a local configuration file.2

Things seems worked, but undesirably slow.

## Cause

You are missing the loacComplete() line in your configuration file, so MathJax waits 15 seconds before timing out and going on without it. Add

Mathjax.Ajax.loadComplete("[Mathjax]/config/local/font.js");

at the bottom of your font configuration file and that should take care of it for you.

## Failed attempts

I tried using relative paths in source/_includes/custom/head.html , {{ root_url }} in the <script> tag that calls MathJax with a local configuration file and in the local configuration file source/javascripts/MathJaxLocal.js. Since this blog has more than 200 pages, it took about a minute for regeneration of contents after each slight modification in the code.

## Conclusion

I typed full paths manually for the above <script> tag in the custom head of a page and the local configuration file. To avoid loading “insecure contents”, I used full URLs instead of {{ site.url }} since the URL of this site doesn’t start with “https” in _config.yml.34 Then the equations should load quickly.

## Lessons learnt

If I could do the same job again, I’d first change the local configuration file and upload it to GitHub, so that I could test it in a local HTML file file:///path/to/test-mathjax.html

1. Refer to commit 12d38c1

2. Using a local configuration file with the CDN in MathJax Documentation

3. Refer to MathJax in Octopress via HTTPS in Blog 1 for details.

4. _config.yml at commit 71ff4fb