I tried using \marginpar using tex4ht and pdflatex.

Here is the PDF output:

\marginpar PDF

Here is the HTML output:

\marginpar HTML

Is it possible to configure tex4ht to produce HTML output with good looking marginal notes?

  • How is the HTML output supposed to look like? – krlmlr Oct 18 '12 at 23:00
  • Like the PDF output in the first image? – M-V Oct 19 '12 at 3:03
  • @M-V, what is the status of this question? Are you still looking for solutions or have you found something suitable? – Paul Gessler Aug 19 '14 at 2:15
  • Actually I gave up and moved on. I am no longer using tex4ht. Thanks. – M-V Aug 19 '14 at 3:59

This is really just a css issue. Stylesheets produced by tex4ht are pretty plain and basic, which is a good thing, because you can easily modify the appearance of things to your needs.

By default, content generated by tex4ht is sized to fill whole page width. This is on the one hand wrong from typographical and usability points of view, as long lines are hard to read. Second problem in this particular problem is that there is no space in the right column where margin par could float.

So we need to set text width to some size, to ease the read and to take some space in the margins. To make things little bit harder, we have to take account the fact, that these days, many people browse web with their smartphones or tablets, so we have to deal with situation that these devices have width smaller than ideal page width and there is no space left for the margins.

This is possible to solve using css technique called media queries and responsive web. I like the article about web typography, which provides basic template for responsive typography.

I made small package for ease working with css in tex4ht. It is not released yet, but it is useful for including external css files. This package is called cssframework.sty:


% open css file

% close css file

      {\HCode{<link rel="stylesheet" type="text/css" href="#1" />}}%
% #1 template name
% #2 css output file

  \special{t4ht+@File: #1}

    \edef\css@selectrpath{\css@selectrpath{} #1}

% support for media queries 
% default medium is all, #2 is rule, #3 is 
    @media #1 and (#2)\{\hnl

% Various helper functions
% default font size
% convert pt to rem
% support for browsers without rem 
      #1:\the\dimexpr #2\relax;#1:\CalcRem{#2}rem;

and I modified the code provided by Viljamis little bit, incorporating some adjustments for tex4ht, you can download it from gist: scale.css.

Now you need to combine these pieces in custom config file:

\Css{.marginpar {width:5em; float:right; text-align:left; margin-left:auto; font-size:85\%; text-decoration:none;color:\#aaa;}

\Css{@media screen and (min-width: 46.3em){

we loaded cssframework package, included file scale.css and provided basic styling for marginpar. Notice that we used \% and \# to escape special characters. Interesting part is

\Css{@media screen and (min-width: 46.3em){

from inspection of scale.css, I found that text width, when there is enough space is set to 34.3em. Marginpar has width of 5em, plus 1em is left as space between text and the note. Because the text is centered, we need to show marginpar in margin when there is enough space on both sides, so we need to calculate text width + 2 * (margin par width + space) = 34.3em + 2 * (5em + 1em) = 46.3em. So enough space for showing the margin par is 46.3em.

The result when there is enough room:

enter image description here

And when the width is too small:

enter image description here

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.