TransWikia.com

htlatex ignores value in brackets in item statement when using itemize

TeX - LaTeX Asked by itart on February 9, 2021

In Latex I have the following statements:

begin{itemize}
item[P)] Lorem ipsum dolor sit amet
item[E)] Pellentesque interdum eros in erat
item[Q)] Vestibulum ante ipsum primis
end{itemize}

pdflatex produces the following correct output:

enter image description here

htlatex (HTML output) generates bullets instead of the defined values in the brackets of the item statement:

enter image description here

Does anyone have an idea how I can get the same output in html as in shown in PDF?

One Answer

TeX4ht removes item labels for enumerate and itemize by default because HTML doesn't support custom labels in elements that are used to display lists by default.

This is the default configuration for the itemize environment:

ConfigureList{itemize}%
   {EndPHCode{<ul a:LRdir
          class="getClass{itemize}itemizeexpandafterthe
          csname @itemdepthendcsname">}%
       afterGetClass{itemize}%
       PushMacroend:itm
globalletend:itm=empty}
   {PopMacroend:itm globalletend:itm end:itm
ifvmode IgnoreParfi
    EndPHCode{</li></ul>}ShowPar}
   {end:itm globaldefend:itm{EndPTg</li>}DeleteMark}
   {HCode{<li class="getClass{li}itemize">}afterGetClass{li}}

It is a bit dense, but the important part is this:

   {end:itm globaldefend:itm{EndPTg</li>}DeleteMark}

The DeleteMark command removes the label, so we can remove it if we want to keep the label. We also need to produce different elements than <ul> and <li>, as they don't support custom labels. Instead, we can use just plain <div> elements and some CSS for correct rendering.

This configuration file, mycfg.cfg contains a modified version of this command with different HTML tags and corresponding CSS:

Preamble{xhtml}
catcode`:=11
ConfigureList{itemize}%
   {EndPHCode{<div a:LRdir
          class="custom-itemize"><div class="item-head">}%
       PushMacroend:itm globalletend:itm=empty}
   {PopMacroend:itm globalletend:itm end:itm
ifvmode IgnoreParfi
    EndPHCode{</div></div>}ShowPar}
   {end:itm globaldefend:itm{EndPTg</div>Tg<div class="item-head">}}
   {HCode{</div><div class="item-content">}}
Css{.item-head{float:left;width:2em;clear:left;}}
Css{.item-content{margin-left:2em;}}
catcode`:=12
begin{document}
EndPreamble

Compile using

make4ht -c myconfig.cfg filename.tex

This is the rendered HTML document:

enter image description here

Answered by michal.h21 on February 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP