12

basic question here. I'm trying to figure out a simple and effective way of writing LaTeX-style formulas on a Github web page.

The top answer here suggests that MathJax is a possible solution.

This thread seems to imply MathJax isn't supported.

Personally, I've followed the directions Herem but the math equations aren't appearing.

Thoughts?

Community
  • 1
  • 1
Alex Zorn
  • 237
  • 2
  • 3
  • It works with Jekyll so it can work with raw html on Github pages. See https://stackoverflow.com/questions/34227995/mathjax-being-parsed-with-jekyll/34231579#34231579 – David Jacquel Dec 18 '15 at 09:12

2 Answers2

6

2022 Answer

MathJax is now natively supported when viewing .md files on GitHub. However, it is not automatically supported in GitHub Pages. To enable MathJax in GitHub Pages, the easiest option is to include the script from a CDN.

TAKE NOTE: the CDN has changed! The updated script tag to include is below. Add this script tag inside the <head/> of your _layouts/default.html file.

<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
</script>

For more information, read the MathJax Docs page about using a CDN.

Additional Help

If you want to use dollar signs (i.e. $1 + 2$) to escape math sequences, add the following as well:

<script>
  MathJax = {
    tex: {
      inlineMath: [['$', '$']]
    }
  };
</script>

see the docs for more information.

nullromo
  • 2,165
  • 2
  • 18
  • 39
  • 1
    Following [these instructions](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll) did not produce a `_layouts/default.html` file. Assuming a new project from those instructions, what am I supposed to code? – Galen Feb 16 '23 at 04:02
  • 1
    You can look [here](https://jekyllrb.com/docs/step-by-step/04-layouts/) for information on how the layouts work with Jekyll. [Here](https://github.com/nullromo/kylekovacs/blob/main/_layouts/default.html) is a small example, and [the corresponding deployment](https://nullromo.github.io/kylekovacs/). – nullromo Feb 16 '23 at 18:05
3

you can use Mathjax on Github Page by adding next code in tag in your html code.

<script type="text/javascript" charset="utf-8" 
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML,
https://vincenttam.github.io/javascripts/MathJaxLocal.js"></script>

I refered this page. https://vincenttam.github.io/blog/2014/11/09/mathjax-local-configuration-file/

lrn
  • 64,680
  • 7
  • 105
  • 121
  • 1
    sorry, adding code is "https://vincenttam.github.io/javascripts/MathJaxLocal.js" after https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML – Takeshi Ikeda Aug 19 '16 at 10:41
  • The CDN has changed. Please see my answer for a more recent update. – nullromo Jul 10 '22 at 18:48