[tex4ht] Spaces in listings are non-breaking spaces but should be normal spaces

Denis Bitouzé dbitouze at wanadoo.fr
Wed Oct 3 09:41:39 CEST 2012


Hello,

consider the joined 'spaces-in-listings.tex' MCE (I couldn't copy paste
it here because long lines would have been broken), which is of the
form:

\documentclass{article}
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  numbers=left,
  breaklines=true
}
\begin{document}
\noindent\lstinline|<very long line of words with spaces between them>|

\begin{minipage}{.5\linewidth}
\begin{lstlisting}
<very long line of words with spaces between them>
\end{lstlisting}
\end{minipage}
\end{document}

where :

  <very long line of words with spaces between them>

is a "foo bar " string repeated many times.

The .pdf output is as expected: too long lines are broken. But the .html
output (from 'htlatex spaces-in-listings') doesn't imitate the pdf
one: too long lines are not broken.

This comes from the fact that "normal" spaces in the .tex source file
are converted by TeX4ht in non-breaking spaces (&#x00A0;). IMHO, this
shouldn't be the case because of non expected output and also because
this is already specified by the css setup 'white-space: nowrap;':

\Css{div.lstlisting{font-family: monospace; white-space: nowrap;
                    margin-top:0.5em; margin-bottom:0.5em;}}

\Css{div.lstinputlisting{
   font-family: monospace;
   white-space: nowrap;
}}

to be found in html4.4ht. Furthermore, it is preferable to delegate
formating to css and let the user override the default behaviour with
another css specification.

Meanwhile, I partially managed to change this behaviour myself with the
following 'spaces-in-listings.cfg' file:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Preamble{xhtml,fn-in,charset=utf-8}

\Css{lstinline {white-space:normal;}}
\Css{lstlisting {white-space:normal;}}

\makeatletter
\catcode`\:=11
\def\lst at outputspace{\HCode{ }}
\catcode`\:=12
\makeatother
\begin{document}
\EndPreamble
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

but this is successful only for \lstinline: lstlisting environments
still go "outside" the page.

Any better idea is welcome :)

Thanks in anticipation.
-- 
Denis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: spaces-in-listings.tex
Type: text/x-tex
Size: 1018 bytes
Desc: not available
URL: <http://tug.org/pipermail/tex4ht/attachments/20121003/8bf0cb55/attachment.bin>


More information about the tex4ht mailing list