Skip to content

Instantly share code, notes, and snippets.

@asmaier
Last active November 11, 2022 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmaier/500269a31a0e45ed87377d9e5b4af235 to your computer and use it in GitHub Desktop.
Save asmaier/500269a31a0e45ed87377d9e5b4af235 to your computer and use it in GitHub Desktop.
Converting latex files into HTML5 with Tufte Css

Latex to Tufte-HTML

To convert LaTeX to HTML5 with tufte-css layout one first needs to copy the file tufte.css and the corresponding font directory et-book from the tufte-css github repo into your working directory.

Then we need to extract the default html5 template from pandoc via

pandoc -D html5 > html5.html

This template must be modified and the tags <article> and <section> should be added around the body of the template like

<body>
<article>     
<section>
....
</section>
</article>
</body>

We stored the new template as tufte_template.html.

Then we need to create a custom lua HTML writer for pandoc which will convert footnotes to sidenotes:

function Writer (doc, opts)
  local filter = {
    Note = function(elem)
      text = pandoc.utils.stringify(elem.content)
      return pandoc.RawInline('html','<span class="sidenote-number"></span><span class="sidenote">' .. text .. '</span>')
    end     
  }
  return pandoc.write(doc:walk(filter), 'html', opts)
end

We save it as tufte_html.lua .

To finally convert our LaTeX file myfile.tex to Tufte HTML myfile.html we use the command

pandoc --wrap=preserve --bibliography=promotion.bib --citeproc -t tufte_html.lua --template tufte_template.html -c tufte.css --mathjax --toc -s myfile.tex -o myfile.html

The following problems are unsolved:

  • equation numbering and reference don't work
  • math equations in sidenotes are not rendered
  • sidenotes loose any formating because we stringify(elem.content)
  • very wide equations of links overlap with sidenotes (especially when zooming)
  • font size of references in bibliography is much too small

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment