Some notes before trying any of the following options
Option 0 will increase build time even with --incremental and indeed option 1 should probably be used in most cases, however, this, together with the extra space required, can be costly if you are deploying on the network with clients who may not have access to the CDN.
Both options were tested on a private server with kramdown as the markdown interpreter and mathjax: true set in the _config.yml project _config.yml ; see step 2 Soham Bhattacharya’s answer and his introduction, as well as the first two Karamdir code blocks for instructions on these bits.
Option 0 download and copy the unpacked source to project-name
- Download source
cd ~ mkdir -p git/hub && cd git/hub git clone --depth 1 https://github.com/mathjax/MathJax.git
- Create a directory path in your project and copy files from
MathJax/unpacked along this path
cd ~ mkdir -p git/lan/project-name/assets/JS_3rd_Party/MathJax cp -r git/hub/MathJax/unpacked/* git/lan/project-name/assets/JS_3rd_Party/MathJax/
- Add source to
git tracking
cd git/lan/project-name/ git add assets/JS_3rd_Party/MathJax git commit -m 'Added MathJax.js unpacked source to git tracking'
- Write an include file
tee ./_includes/MathJax.html 1>/dev/null <<EOF {%- if jekyll.environment == 'production' and site.mathjax == true -%} <script type="text/javascript" src="{{'/assets/javascripts/JS_3rd_Party/latest.js?config=TeX-AMS-MML_HTMLorMML' | relative_url}}"></script> {%- elsif jekyll.environment != 'production' and site.mathjax == true -%} <script type="text/javascript" src="{{'/assets/javascripts/JS_3rd_Party/MathJax.js?config=TeX-AMS-MML_HTMLorMML' | relative_url}}"></script> {%- endif -%} EOF
Private server assemblies will use MathJax.js where the MathJax.js will be used as the production environment (GitHub) using the latest.js latest.js Liquid if ... elsif ... endif above.
- Write a post to check it out
tee ./_posts/$(date +'%Y-%d-%m')-math-tests.markdown 1>/dev/null <<EOF --- layout: post title: "Math Tests" date: $(date +'%Y-%d-%m %H:%M:%S %z') categories: math --- {%- include MathJax.html -%} <span> for $x,y,z \in \{1, 2,\dots 9\}$ </span> <span> $$ \sum_{i=1}^n X_n $$ </span> EOF
I have not tried this without a <span> because the cboettig suggestion seems to fully help . Additionally, extra lines within the span are an error , without them where there are still problems with the output being displayed.
- Add these latest
git tracking files
git add _posts/$(date +'%Y-%d-')math-tests.markdown git add _includes/MathJax.html
- Build locally or install and build on a remote server
bundle exec jekyll build --destination /tmp/www/project-name --config _config.yml --incremental
Option 1 copy only latest.js to use CDN (Content Delivery Network)
See Option 0 step 1.
Create a directory path for third-party JavaScripts scripts and copy MathJax/unpacked/latest.js
cd ~ mkdir -p git/lan/project-name/assets/JS_3rd_Party/MathJax cp git/hub/MathJax/unpacked/latest.js git/lan/project-name/assets/JS_3rd_Party/MathJax/
- Write an include file
cd git/lan/project-name tee ./_includes/MathJax.html 1>/dev/null <<EOF <script type="text/javascript" src="{{'/assets/javascripts/JS_3rd_Party/latest.js?config=TeX-AMS-MML_HTMLorMML' | relative_url}}"></script> EOF
See Option 0 Step 5.
Add these three files to track git
git add _includes/MathJax.html git add _posts/$(date +'%Y-%d-')math-tests.markdown git add assets/JS_3rd_Party/MathJax git commit -m 'Added 'MathJax.html', 'latest.js', and a test post to git tracking'
- See
Option 0 Step 7. for local construction
For any of the options
When deploying to a private server, you may also need to define baseurl in your _config.yml project _config.yml , especially if the _config.yml URL scheme is username.tld/project-name , which GitHub uses on your private server.
When deploying both on a private server and on GitHub, it may be better to use a separate configuration file and when building the problem --config _config.yml,_config_baseurl.yml , for example ...
Hope this helps with asset loading through inclusion.