tompollard/phd_thesis_markdown

Equation support with LaTeX - MathJax

Closed this issue · 1 comments

Hi all :-)

I am facing troubles with some mathematic equations that are probably not understood by pandoc and the html doesn't display them (e.g. $$\frac{a}{b}$$ doesn't work and literally stays $$\frac{a}{b}$$)

I found a workaround by leveraging MathJax which is a JS reader for math equations. Indeed just adding that snippet in the <head> of the .html file :

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</script>

And equations are rendered. 👌

I have two issues though :

  1. When trying to add this to the template.html I get an error :
pandoc: "template" (line 16, column 57):
unexpected "'"
expecting letter
CallStack (from HasCallStack):
  error, called at src/Text/Pandoc/Templates.hs:73:35 in pandoc-1.19.2.1-J1nmFBg9ln971v0RrPbKLJ:Text.Pandoc.Templates
make: *** [html] Error 1

so I just add it to the thesis.html which works... but not very clean, I'd rather avoid adding it every time !

  1. I would find more consistent (and aesthetically clean) to only rely on one math formatter. Personally, I even think MathJax renders better. So assuming I could add it to my template.html, is there a way I can deactivate the equation rendering from pandoc ?

Thank you very much for your help !

Ok so I found that thread on pandoc's repo where the MathJax approach is discussed.

They seem to agree that MathJax is maybe the best to use

MathJax is now the best and dominant effort to bring LaTeX math to HTML

And I've realized that --mathjax is just an option supported by pandoc.

So I edited the Makefile for html and appended that --mathjax

html:
	pandoc "$(INPUTDIR)"/*.md \
	-o "$(OUTPUTDIR)/thesis.html" \
	--standalone \
	--template="$(STYLEDIR)/template.html" \
	--bibliography="$(BIBFILE)" \
	--csl="$(STYLEDIR)/ref_format.csl" \
	--include-in-header="$(STYLEDIR)/style.css" \
	--toc \
	--number-sections \
	--mathjax
	rm -rf "$(OUTPUTDIR)/source"
	mkdir "$(OUTPUTDIR)/source"
	cp -r "$(INPUTDIR)/figures" "$(OUTPUTDIR)/source/figures"

That's all. It works perfectly.

Maybe great to put this by default ?