[texhax] latex2html and listings package

Ross Moore ross at ics.mq.edu.au
Wed Mar 9 00:40:20 CET 2005


Hello Ivan,

On 09/03/2005, at 9:22 AM, Ivan Ivanov wrote:

> Dear Colleagues,
>
> I am using listings package in order to input some C/C++ source file
> in my latex documents and I had no problems using listings package.
> But now when I am trying to convert my latex documents to html with
> latex2html I am failing to generate correctly the C/C++ sources in the
> html files. For example, I am inluding my sources in my latex files
> with the command
> \lstinputlisting[language=C, showstringspaces=false,
>     breaklines=true, breakatwhitespace=true]{../src/ch2/errortype.c}
> The above command is treated literally by latex2html and the output in
> the html files is:
> [language=C, showstringspaces=false, breaklines=true,
> breakatwhitespace=true]../src/ch2/errortype.c

No Perl coding has been written to support the commands defined
in the  listings  package.

However, there is code to support  \verbatiminput  from the {verbatim}
package.

So all you need to do is recast the expansion of \lstinputlisting
to use \verbatiminput  when processing your document with LaTeX2HTML.


Do this by adding code to your document's preamble:


\usepackage{html}   %  *always* load this for LaTeX2HTML
\begin{htmlonly}
  \usepackage{verbatim}
  \providecommand{\lstinputlisting}[2][]{\verbatiminput{#2}}
\end{htmlonly}



>
> I am sure I use listings packagew correctly since when my latex files
> are compiled to dvi, the C code from my source are printed correctly
> in the dvi file.
>
> Could you please help me in configuring latex2html?

As above, within your document.

Alternatively ...


  ... it is also possible to write a little bit of Perl to achieve
the same effect. This could be placed in your  .latex2html-init
file, to be available for many documents.

With a bit more effort, you could write a short .perl file
and add it to your LaTeX2HTML installation.
There is one already that could be used as a model:

    $LATEX2HTMLDIR/styles/verbatimfiles.perl

Note that you need to catch the options [....] part,
and discard this.

Even better would be to parse the options and devise
more complicated Perl coding to create "pretty-printed"
markup. However HTML is not good at doing this, while
also respecting spaces/indents in a code listing,
so it's probably not worth the effort.

>
> Reagrds and thank you in advance


Hope this helps,

	Ross Moore


> Ivan Ivanov
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> TeX newsgroup: http://groups.google.com/groups?group=comp.text.tex
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
>
> Automated subscription management: 
> http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org
>
------------------------------------------------------------------------
Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia                                  fax: +61 +2 9850 8114
------------------------------------------------------------------------



More information about the texhax mailing list