[tex4ht] Typesetting source code and pseudo-code

Hans Georg Schaathun georg+tex at schaathun.net
Tue Jan 5 07:11:33 CET 2016

On Tue, Jan 05, 2016 at 10:19:17AM +0530, Jagath AR wrote:
> Hi Hans,
> Could you please send a minimal working example with the problem and the
> command line used to generate the html file.

Sure.  I attach a TeX file and the resulting XML file compiled using
  htlatex test.tex "xhtml,2,mozilla,charset=utf-8" " -cmozhtf -utf8" \

As you can see, tex4ht uses a <div> tag where obviously a <code>
tag should be used, and the XML is not syntactically correct,
firefox reports that
  XML Parsing Error: mismatched tag. Expected: </div>.
  Location: file:///home/georg/tmp/test.xml
  Line Number 37, Column 34:

(I should also have liked to make a verbatim-like environment which
uses a <code> tag as the main (outermost) tag, but I do not have a
minimal example since I do not know where to start defining it.)

:-- George

> Jagath
> On 4 January 2016 at 22:08, Hans Georg Schaathun <georg+tex at schaathun.net>
> wrote:
> > Hi,
> >
> > I am struggling to find a good way to typeset source code
> > with tex4ht.  In my opinion the <code> tag should be used
> > in HTML, for the benefit of screen readers and search engines
> > which might need the semantics.
> >
> > I am used to using both lstlisting (listings package), verbatim,
> > and code (texpower package).  Texpower does not seem to be supported
> > by tex4ht at all.  verbatim is ok, except that I should like to
> > reconfigure it to use the <code> tag.  lstlisting is brilliant for
> > source code, except for the <code> tag.  For pseudo-code I also
> > have the problem that tex4ht does not grok maths within lstlisting.
> > It causes an unclosed tags.
> >
> > Has anyone found a way cleanly to produce <code> elements with tex4ht?
> > All my attempts either produce an excess of tags which mess up
> > the spacing, or they make tex strip linebreaks before it gets
> > to tex4ht.  I do not understand all the low-level TeX code in the
> > listings.4ht style, and I would really hope I don't have to ...
> >
> > Preferably, I should like to specify a custom class name for the
> > purpose of CSS configuration, but it is obviously possible to tailor
> > the CSS style to a non-custom class name if I have to.
> >
> > Secondly, is there a good fix to make tex4ht accept maths within
> > lstlisting?
> >
> > Thanks a lot for any pointers,
> > --
> > :-- Hans Georg
> >

:-- Hans Georg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tex
Type: text/x-tex
Size: 261 bytes
Desc: not available
URL: <http://tug.org/pipermail/tex4ht/attachments/20160105/1e8231d3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.xml
Type: application/xml
Size: 2403 bytes
Desc: not available
URL: <http://tug.org/pipermail/tex4ht/attachments/20160105/1e8231d3/attachment.wsdl>

More information about the tex4ht mailing list