Exporting TeX to HTML+MathJax
As I mentioned in my previous post about integrating Emacs into my workflow, I used to draft TeX-heavy posts for this blog in an eatsleepmath.org org-mode file and then export to TeX and HTML by either using org-mode’s native exporting (though recent versions of Emacs have significantly altered how its LaTeX export works) or by using pandoc to convert .org -> .tex -> .html.
However, I was using an extremely outdated version of pandoc, and when I reinstalled it earlier today I found out pandoc’s creator jgm pushed a bewildering change to pandoc’s LaTeX macro expansions: it wraps any expanded macro in an extra set of curly braces, apparently because users are expected to not enclose arguments passed to macros in braces.
To get around this, I found out about the helpful python script de-macro, which is included in texlive. (Instructions in this tex.se answer: here.)
Pandoc still works fine as long as it doesn’t have to expand macros, so now I just expand macros separately and then export to html.
In a simple bash script, which I used to make the next post:
#!/bin/bash
clear
echo "Enter the path of the TeX source file you need converted to HTML."
read fullpath
filename=$(basename $fullpath)
noextfilename="${filename%.*}"
cp $fullpath ~/.pandoc/
cd ~/.pandoc/
de-macro $filename
sudo pandoc $noextfilename"-clean.tex" -s --mathjax -o $noextfilename".html"
sudo chmod 644 $noextfilename".html" & sudo chown $USER $noextfilename".html"
xdg-open $noextfilename".html" & exit