# Vertical spaces in htlatex \ScriptEnv

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:

\ScriptEnv{tawny}
{\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,

http://homepages.cs.ncl.ac.uk/phillip.lord/take-wing/take_wing.html

This code:

\begin{tawny}
(as-subclasses
PizzaComponent
:disjoint :cover
(defclass PizzaBase)
(defclass PizzaTopping))
\end{tawny}


is coming out like this:

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

(defclass PizzaBase)
(defclass PizzaTopping))
</code></pre>


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 Oct 7, 2014 at 11:09

## 2 Answers

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:

\Preamble{html}
\def\StartSuppressPage{\nobreak\vfil\penalty0\vfilneg\vtop\bgroup}
\def\EndSuppressPage{\egroup}
\ScriptEnv{tawny}
{\IgnorePar\EndP\StartSuppressPage\HCode{<pre><code class="clojure">\Hnewline}\HtmlParOff\NoFonts}
{\EndSuppressPage\HCode{</code></pre>}\EndNoFonts\HtmlParOn}
\begin{document}
\EndPreamble


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!

\setlength{\paperheight}{100cm}
\setlength{\textheight}{99cm}
\ScriptEnv{tawny}
{\newpage\IgnorePar\EndP\HCode{<pre><code class="tawny">}\HtmlParOff\NoFonts}
{\EndNoFonts\HtmlParOn \HCode{</code></pre>}}