addmathjax (1252B)
1 #!/bin/bash 2 3 TEMP=$(mktemp) 4 5 CACHEDIR="$HOME/temp/addmathjax.cache" 6 mkdir -p "$CACHEDIR" 7 8 # a3nm-mathjax-testing follows a base debian image and included config 9 # and a container must have been created with 10 # sudo docker run -di --name=a3nm-mathjax-testing \ 11 # a3nm-mathjax-testing bash 12 #if ! sudo docker ps | grep '\sa3nm-mathjax-testing$' > /dev/null 13 #then 14 # sudo docker start a3nm-mathjax-testing >/dev/null || { 15 # echo "cannot start the mathjax container" >&2; exit 3; 16 # } 17 #fi 18 19 cat > $TEMP 20 if grep -E "class=\"math\"|class=\"tex\"|class=\"MathJax_Preview\"" $TEMP > /dev/null 21 then 22 # expensive processing 23 SHA=$(sha1sum < $TEMP | cut -d ' ' -f1) 24 if [ -f "$CACHEDIR/$SHA" ] 25 then 26 # already cached 27 cat "$CACHEDIR/$SHA" 28 else 29 TEMP2=$(mktemp) 30 #sudo docker exec -i a3nm-mathjax-testing node_modules/mathjax-node/bin/page2html \ 31 ~/apps/MathJax-node/bin/page2html \ 32 --fontURL "https://a3nm.net/mathjax/fonts/HTML-CSS" <$TEMP >$TEMP2 || \ 33 { echo "cannot run mathjax" >&2; exit 2;} 34 sed 's,<style id="MathJax_CHTML_styles">undefined</style>,,g' "$TEMP2" | 35 sed 's,<span class="mjx-char"></span>,,g' >$CACHEDIR/$SHA 36 cat "$CACHEDIR/$SHA" 37 rm -f "$TEMP2" 38 fi 39 else 40 cat "$TEMP" 41 fi 42 43 rm -f "$TEMP" 44