[tex4ht] [Patch submitted] Spurious line break (<br />) with \lstinputlisting

Denis Bitouzé dbitouze at wanadoo.fr
Sun Sep 9 16:06:49 CEST 2012

Le dimanche 09/09/12 à 11h25,
Denis Bitouzé <dbitouze at wanadoo.fr> a écrit :

> I had a look at listings.4ht but I'm not not sure what to change in it
> without side effects.

If I'm right, the following patch is a clean solution to the trouble I

In the original html4.4ht, replace lines 36834 to 36848 by:

   {\ifvmode \IgnorePar\fi \EndP
    \gHAdvance\listingN by 1
    \HCode{<!--l. \the\inputlineno-->}%
    \HCode{<div class="lstinputlisting" id="listing-\listingN">}%
       \gdef\start:LstLn{\leavevmode\special{t4ht at +\string&{35}x00A0{59}}x%
\HCode{<br />}}}
    \bgroup %\special{t4ht@(}%
         {\start:LstLn \HCode{<span class="label">}}
    \ifvmode \IgnorePar\fi \EndP  \HCode{</div>}\par}

If the original code and this patch are isolated in individual files,
the differences between them are:

>     \gHAdvance\listingN by 1
<     \HCode{<div class="lstinputlisting">}%
<     \bgroup \tt %\special{t4ht@(}%
>     \gdef\start:LstLn{%
>     \HCode{<div class="lstinputlisting" id="listing-\listingN">}%
>        \gdef\start:LstLn{\leavevmode\special{t4ht at +\string&{35}x00A0{59}}x%
> \HCode{<br />}}}
>     \bgroup %\special{t4ht@(}%
<          {\leavevmode\special{t4ht at +\string&{35}x00A0{59}}x%
<              \HCode{<br /><span class="label">}}
>          {\start:LstLn \HCode{<span class="label">}}

The first difference is intended to identify the "lstinputed listings"
exactly as "lstlistings environment listings" are, and make them share
the same counter.

The next ones simply apply the code of the original
\ConfigureEnv{lstlisting} to the \Configure{lstinputlisting} in order
to obtain the same behaviour.

It must be noticed the "\tt" removed from the original line:

\bgroup \tt %\special{t4ht@(}%

of \Configure{lstinputlisting}. This follows lstlisting TeX4ht
configuration and should not be a problem because of the
"font-family: monospace;" in the lines

   font-family: monospace;
   white-space: nowrap;

of the original html4.4ht.

I hope this patch won't have any side effect and will be useful to you.


More information about the tex4ht mailing list