[tex4ht] Typesetting source code and pseudo-code

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


Hi,

On Tue, Jan 05, 2016 at 01:01:11PM +0530, Jagath AR wrote:
> If you remove the option "mozilla" from the command line then the XML
> syntax problem will be fixed and you can render it without any problem in
> Firefox. There is some problem associated with the conversion to MathML
> which need to be fixed when the "mozilla" option is used.

Right.  That seems to be satisfactory.  Thanks.
I had the impression from the doc's that the mozilla option would
produce better looking output, but nothing I can spot.

> If you need to change the element "div" to "code", then use the following
> tex4ht configuration in a separate cfg file or use the attached TeX file.

Brilliant.  Thanks a lot.

Putting this inside an \AtBeginDocument{...} macro, I can put it
inside my custom style files (.4ht) and keep everything in one
place.  Apparently, one should also unset the white-space: pre property
on the code element, lest there be extra blank lines in the html rendering.

:-- George

> Change the command line to:
> htlatex test.tex "xhtml,2,charset=utf-8" " -cmozhtf -utf8"  "-ccvalidate"
> 
> Regards
> Jagath
> 
> On 5 January 2016 at 11:41, Hans Georg Schaathun <georg+tex at schaathun.net>
> wrote:
> 
> > 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" \
> >       "-cvalidate"
> >
> > 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:
> >
> >   class="cmmi-10x-x-109">A</span></mrow><mrow
> >   ---------------------------------^
> >
> > (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
> >



-- 
:-- Hans Georg


More information about the tex4ht mailing list