I'm really interested to publish my thesis on a website HTML + CSS (when it's done) augmented with tools to annotate it, like the philoweb initative (see here, and here).

I know the universal converter Pandoc or the latex2html, but i'm interested to know if others tools exists, or if some users already create a batch workflow to make this conversion automaticaly.

Perhaps it can be a community wiki question ?

Updated list (16 april 2015) :

MWE creation :

I propose a first link to collaborate on a complex MWE to test these tools, which contain all complex elements you want :

Link to public MWE on sharelatex

Things to transform and eventually beautify with some js :

  • Math
  • Complex Side Caption
  • Bibliography
  • Public annotation

Example of great conversion :

  • 1
    Perhaps... but meanwhile maybe you need to use something more than HTML and CSS. Have you seen something about MathJax before? I don't know how complex were the mathematical expressions that you used in your thesis. If they are not so, you could even use something less sophisticated such as the Beautiful Maths plugin from the Jetpack bundle used in wordpress.org. – Aradnix Apr 8 '15 at 18:17
  • the question of tex to html convertors must be a duplicate, I'll find an older question. tex4ht and latexml are probably the two most robust convertors that you don't mention. – David Carlisle Apr 8 '15 at 18:47
  • 2
    probably a duplicate of tex.stackexchange.com/questions/43847/… – David Carlisle Apr 8 '15 at 18:49
  • it is easy to add javascript with tex4ht, we just need some sample document to work with – michal.h21 Apr 9 '15 at 8:29
  • 2
    Please edit your question to include an MWE here. Questions should be self-contained so that they remain useful even if the content of external links changes or disappears. – cfr Apr 15 '15 at 12:31

I will show a solution with tex4ht. I used your sample text and added some math samples from the internet. You can see the complete resulting webpage on my Github page. All code is also hosted on Github.

You have four wishes, some of them can be solved using external Javascript tools, for others we must create custom JS scripts.

tex4ht can be configured using .cfg file. This file has special structure:

\Preamble{xhtml,list of options}

we can require some packages before \Preamble command, which we may use for some helper packages. In our example, we may need two packages:

  • one for fixes some issues with Memoir under tex4ht
  • other with some helper macros

you need recently updated TeX Live for latest bug fixes for tex4ht Memoir support, in this case you need only fo fix this issue with double Bibliography entry in the TOC.

This can be fixed with mem4hack.sty:


the other supporting package is tools.sty:

\newcommand\AddFile[1]{\special{t4ht+@File: #1}}%

  \Configure{@HEAD}{\HCode{<link rel="stylesheet" type="text/css" href="#1" />}}

\Configure{@HEAD}{\HCode{\Hnewline<script type="text/javascript" src="#1"></script>}}

This simplifies inclusion of CSS and JS files in your project.

Regarding used libraries, we can use mathjax for math support and hypothes.is for annotating. Unfortunately, this doesn't work with local pages, you have to use a webserver (but you can install it on your local computer, you don't need actual server).

Math example:

enter image description here

annotation examples:

enter image description here enter image description here

For sidebar, you can make a standalone file for each chapter, with local TOC for sections and subsections. So you can make sidebar containing this TOC and links to previous and next chapter.

The code is here js/sidebar.js:

document.addEventListener("DOMContentLoaded", function() {
    // Code
    // select local TOC
    var menu = q(".chapterTOCS")[0];
    var menuopened = "^^^";
    var m = createEl("a","menu",menuopened);
    var toolbar = createEl("div","toolbar");
    var sidebar = createEl("div","sidebar","");
    var crosslinks = q(".crosslinks")[0];
    var setText = function(node,a){
      var text = document.createTextNode(a);
    var switchMenu = function(){
      // switch menu state
      menu.className = hiddenswitch ? "chapterTOCS red" : "chapterTOCS hiddentoc";
      var text = hiddenswitch ? menuopened:"TOC"  ;
      // set menu class to changed state
      setText(m, text);

      hiddenswitch = !hiddenswitch;
    // pass reference to new container and crosslinks
    var transfromCrosslinks = function(newcrosslinks,el){
      // find all crosslinks 
      var links = el.querySelectorAll("a");
      var newcrs = {}
     // make table with link text as name
          var text = links[i].firstChild.nodeValue;
          newcrs[text] = links[i];
      // select next, prev and up nodes and replace text with unicode arrows
      // is a node doesn't exist, create span with blanklink class
      var next = newcrs["next"] || createEl("span","blanklink",">")
      var prev = newcrs["prev"]|| createEl("span","blanklink",">")
      // add crosslinks to a toolbar
      return newcrosslinks;
    // add elements to the sidebar depending on existence of a local TOC and 
    // crosslinks
      // add sidebat only if it doesn't exist already
      if(!menu) sidebar.appendChild(toolbar);
    if(menu) { 
    var hiddenswitch = false

 }, false);

this uses standard Javascript DOM functions, only small library js/fw.js is being used:

// basic DOM functions
// based on http://blog.adtile.me/2014/01/16/a-dive-into-plain-javascript/
var q = document.querySelectorAll.bind(document);
Element.prototype.on = Element.prototype.addEventListener;
var createEl = function(el, cls, text){
  var x = document.createElement(el);
  if(text) {
    var t = document.createTextNode(text);
  return x;

enter image description here

The TOC can be hidden by click on the ^^^ text.

enter image description here

For bibliography, we can load bibliography page using AJAX and show the citations in a window when you point a cursor over a citation. Window can be closed by clicking anywhere in the document.

File js/bib.js:

var bibdoc = null;

var isBibbox = function(){
  return q("#bibbox").length>0;

var makeBibTooltip = function(bib,id,el){
    var xxx = bib.querySelector(id).parentNode.cloneNode(true);
    var parentpos = el.getBoundingClientRect();  
    var tip = document.createElement("div");
    tip.setAttribute("id", "bibbox")
    tip.style.position = "fixed";
    tip.style.top = parentpos.bottom+ 10+"px";
    tip.style.left = parentpos.left+ 10 +"px" ;
var getBibDoc = function(url,id,el){
    var ajax = new XMLHttpRequest();
    console.log("Load ajax"+url)
    bibdoc = ajax.open("GET",url,true);
    ajax.onreadystatechange = function(){
      if(ajax.readyState == 4 && ajax.status==200 && !bibdoc){
        var res = ajax.responseText;
        bibdoc = createEl("div","bib");
        bibdoc.innerHTML = res;

document.addEventListener("DOMContentLoaded", function() {
  var bibs = q("span.cite");
    bibs[i].on("mouseover", function(e){
      var el = e.currentTarget;
      var link = el.querySelector("a");
      var hash = link.hash;
      var href = link.getAttribute("href");
      //var target = bib.querySelector("body");
      //console.log("nazdar "+ target);

    var bibbox = q("#bibbox");

enter image description here

We can also make a better typography, I really like Viljami Salminen's responsive CSS boilerplate. Use the css/scale.css file.

We can put it all together now, make file myconfig.cfg:

 \Configure{@HEAD}{\HCode{\Hnewline<script type="text/javascript"\Hnewline
\Configure{@HEAD}{\HCode{\Hnewline<script async defer src="http://hypothes.is/embed.js"></script>}}

% fix sublist indentation

\Css{li li{margin-left:2em;}}
\Css{dd dl{margin-left:2em;}}

% we can use helper macros to use variables in the CSS
\def\numcalc#1{\the\numexpr #1\relax}
% sidebar is on a fixed position. you should play with this
\Css{.sidebar{position:fixed;width:\sidebarwidth em;top:3em;left:100\%;margin-left:-\numcalc{\sidebarwidth+2}em;}}
% fix local TOC formating 
\Css{.sidebar .sectionToc,.sidebar .subsectionToc{display:block;margin-top:-1em;margin-bottom:0px;}}
\Css{.sidebar .chapterTOCS br{display:none;}}
% we can turn off the local TOC 
% TOC switch formatting
\Css{.menu red{font-size:0,7em;vertical-align:sub;}}
% toolbar displays links to previous and next chapters and TOC switcher
% tooltip which displays bibliographic record when you point 
% a cursor on a citation
\Css{\#bibbox{border:1px solid black;background-color:\#fed;width:25em;}}
% make standalone page for each chapter. make local TOC for contained sections
% and subsections
% we can delete normal TOC, it is created automatically by tex4ht and it 
% would be duplicated

In the \Preamble command, options for tex4ht are specified. xhtml requests xhtml output, 2 breaks document into standalone web page at every \chapter (1 would break it at every part, 3 at every section ...), mathml requests conversion of math to mathml.

Configurations should go after \Preamble command.

Internal js and CSS files are included using \AddJs resp. \AddCss commands. mathjax and hypothes.is are included using links to external pages, which is configured using


this configuration add stuff to the html <head> element.

You can add CSS styles using \Css command. The included styles are pretty basic, you may want to (and really should) modify them for better look, concentrated only on functionality, not aesthetics)

Now you can compile your file using

htlatex thesis myconfig

or better, use make4ht which is alternative build system for tex4ht. This build file will copy all used files to /var/www/html/reyman/ directory, so you can open in your browser this address: localhost/reyman/thesis.html and everything should work. If you have Unix like system, Apache web server and write permissions to that directory. File thesis.mk4:

local mkutils = require "mkutils"
local outdir = "/var/www/html/reyman/"
if mode == "draft" then
  Make:htlatex {}
  Make:add("bibtex", "bibtex ${input}")
  Make:htlatex {}
  Make:bibtex {}
  Make:htlatex {}
  Make:htlatex {}
Make:match(".*$", function(file, par)
  mkutils.copy(file, outdir .. file)
  return false, "Copy html to destination "..outdir

Compile with

make4ht -u -c myconfig thesis

to speedup the compilation, you can use

make4ht -um draft -c myconfig thesis

which will compile the document only once with LaTeX and it will skip the bibtex.

You can see the result on my Github page

  • Wow, this is a great answer :) The comment is lost after earch regen of the file ? Thanks ! – reyman64 Apr 24 '15 at 18:02
  • @reyman64 it's not lost after you register and login to hypotes.is. it works even on localhost – michal.h21 Apr 25 '15 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.