3

I want to get htlatex to put some text into my HTML file verbatim. The problem is that it keeps redo-ing my spacing. So, for example, I use a cf.cfg like this.

\Preamble{html}
\ConfigureEnv{tawny}
{\IgnorePar\EndP\HCode{<pre><code class="clojure">}\EndNoFonts}
{\NoFonts \HCode{</code></pre>}}{}{}
\begin{document}
\EndPreamble

And a document like this...

\documentclass{article}
\newenvironment{tawny}%
{}%
{}%

\begin{document}
\begin{tawny}
(defclass Pizza
  :super Thing)
\end{tawny}
\end{document}

which produces this piece of html (and the rest!)

<pre><code class="clojure"> (defclass Pizza :super Thing)
</code></pre>

while what I want is:

<pre><code class="clojure"> 
(defclass Pizza 
   :super Thing)
</code></pre>

with indentation and spacing preserved

So, the pre tag has been defeated because htlatex has re-ordered things. I tried using alltt -- so redefinign tawny in the example above.

\newenvironment{tawny}%
{\begin{alltt}}%
{\end{alltt}}%

And htlatex puts in nbsp and br tags which don't really make sense in a pre tag.

<pre><code class="clojure"><div class="alltt">
<!--l. 11--><p class="noindent" ><div class="obeylines-v">
(defclass&#x00A0;Pizza
<br />&#x00A0;&#x00A0;:super&#x00A0;Thing)
</div>
</div>
</code></pre>

I've tried the documentation, and looking through the source, but cannot see where this behaviour comes from nor if it is configurable!

1 Answer 1

3

You can use \ScriptEnv command to define verbatim environment:

\Preamble{html}
\ScriptEnv{tawny}
{\IgnorePar\EndP\HCode{<pre><code class="clojure">\Hnewline}\EndNoFonts}
{\NoFonts \HCode{</code></pre>}}
\begin{document}
\EndPreamble

resulting html:

<pre><code class="clojure"> 
(defclass Pizza
  :super Thing)
</code></pre>
1
  • Superb. This is just what I needed. Many thanks!
    – Phil Lord
    Oct 2, 2014 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .