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@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
\documentclass{article}
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  numbers=left,
  breaklines=true
}
\begin{document}
\noindent\lstinline|foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar|

\begin{minipage}{.5\linewidth}
\begin{lstlisting}
foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar
\end{lstlisting}
\end{minipage}
\end{document}

Reply via email to