Show Hugo: Compile time Latex -> SVG


#1

As I was moving my website to hugo, I had this goal of making something that works without JS. Therefore I spent effort to ensure I can have all functionality at compile time to speed up the runtime of my website. Hugo provides syntax highlighting out of box. I wanted to do the same with Latex. Since hugo does not support calling command line, I ended up creating a service to convert Latex to SVG that can be used at compile time. Here is a short-code that I use to call it:

<!-- tex -->
{{ $inline := "" }}
{{- if eq (.Get 0) "inline" -}}
{{ $inline = "&inline=true" }}
{{- end -}}
{{- $json := getJSON $.Site.Params.Tex "?" (querify "q" .Inner) $inline -}}
{{- with $json.svg -}}
{{. | safeHTML}}
{{- end -}}

Currently hosted at https://tex2svg.herokuapp.com/ . If you plan to have a lot of calls, please use the code from https://github.com/atishay/tex2svg and host it separately. I would like to thank the entire hugo team for making such a fast static system.