I am using htlatex to generate the HTML version of book and I am having problems with vertical spacing. I have configured an environment like this:

{\begin{samepage}\IgnorePar\EndP\HCode{<pre><code class="tawny">}\EndNoFonts}
{\NoFonts \HCode{</code></pre>}\end{samepage}}

I am then using Javascript to syntax highlight this.

The problem is that, although I am using \ScriptEnv, htlatex still inserts large vertical spaces at times. So, for instance, in this HTML,


This code:

 :disjoint :cover
 (defclass PizzaBase)
 (defclass PizzaTopping))

is coming out like this:

<pre><code class="tawny">(as-subclasses
 :disjoint :cover

 (defclass PizzaBase)
 (defclass PizzaTopping))

Obviously, as I am in a pre environment, this gap turns up in the final presentation on screen.

I do not get this gap in all environments, and it is inconsistent. It does not occur with small code snippets. I believe that the source of the error is coming from the pagination that tex is applying. Looking at the DVI file that is produced by htlatex, these gaps always occur at page breaks in the DVI, even though the page break is meaningless in the HTML.

I have tried adding samepage (you can see this in my configuration above) which does seem to reduce the problem, but not remove it entirely.

Is there any way I can stop this?

  • yes, linebreaks in depends on linebreaks in the dvi file. you may try to set higher value to \paperheight
    – michal.h21
    Oct 7, 2014 at 11:09

2 Answers 2


With inspiration from Egreg's answer to a prevent pagebreak question, I created macro which prevents page break modified .cfg file form your previous question:

{\IgnorePar\EndP\StartSuppressPage\HCode{<pre><code class="clojure">\Hnewline}\HtmlParOff\NoFonts}

I also made some other minor edits - I swaped usage of \NoFonts and \EndNoFonts and added \HtmlParOff and \HtmlParOn to suppress paragraphs inside <pre> element.

I created really long code sample (200 lines) and no empty lines were added inside (just at the end, I don't know why).


In the end, I have gone for the simple solution of fiddling with textheight and stuffing a \newpage line on the beginning of every code block which doesn't make it in to the end document!

{\newpage\IgnorePar\EndP\HCode{<pre><code class="tawny">}\HtmlParOff\NoFonts}
{\EndNoFonts\HtmlParOn \HCode{</code></pre>}}

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.