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
1 2 3 4 5 |
|
Things seems worked, but undesirably slow.
It took about 16 seconds for loading the math. How can they load quicker with a local configuration file, like http://drz.ac?
Cause
I googled “mathjax local config long”, and found a message from this page extremely useful.
You are missing the
loacComplete()
line in your configuration file, so MathJax waits 15 seconds before timing out and going on without it. AddMathjax.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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
-
Using a local configuration file with the CDN in MathJax Documentation. ↩
-
Refer to MathJax in Octopress via HTTPS in Blog 1 for details. ↩