1

I'm attempting to convert a LaTeX document of mine as no-style sheet html to be copy-pasted as a (Wordpress) blog post (thus the css-less requirement). So, I've started from michal.h21's instructions at Generation of simple, CSS-less HTML with htlatex. Things work mostly fine, but I still have some problems with enumerate environments, which get a line break between the label and the item text.

My settings are the following:

.make4ht (just to set the .cfg file):

set_settings{tex4ht_sty_par = "filename," .. settings.tex4ht_sty_par}

filename.cfg:

\Preamble{xhtml}

\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<b>}}{\HCode{</b>}}

\Configure{HtmlPar}
    {\EndP\Tg<p>}
    {\EndP\Tg<p>}
    {\HCode{</p>\Hnewline}}
    {\HCode{</p>\Hnewline}}

\begin{document}

\EndPreamble

the build file filename.mk4:

settings_add{ tex4ht_sty_par =  ",xhtml,NoFonts,-css" }
Make:latexmk()

and the file itself filename.tex

\documentclass{article}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=4em, itemsep=0pt}
\setlist[enumerate,1]{wide, labelindent=0pt, label={Part \Roman* --}}
\setlist[enumerate,2]{wide=1em, label={\arabic* --}, resume}

\begin{document}

\begin{enumerate}
\item A first item
  \begin{enumerate}
  \item A first subitem in enumerate
  \item A second one
    \begin{itemize}
    \item Itemize item
    \end{itemize}
  \end{enumerate}
\end{enumerate}

\end{document}

Compiling this with:

make4ht -uf html5+tidy filename.tex

The result is:

enter image description here

How could I get rid of these line breaks between the label and the item text in the enumerate environments?

(Side note: comments on the overall procedure and the used settings for the purpose at hand would also be welcome).

2

With the help of @michal.h21's comments, I was able to reach a solution to this. My initial attempt had been to get the relevant list configuration settings from the tex4ht folder, and adapt them to my purposes in my own config file. But I could then not build my document.

However, as Michal taught me, those files commonly use : in macros names, which cannot be ported without due care. With that information in hand, I could then reach the desired results with the following settings:

A build file filename.mk4:

set_settings{tex4ht_sty_par = "filename," .. settings.tex4ht_sty_par}
settings_add{ tex4ht_sty_par =  ",NoFonts,-css" }
Make:latexmk()

A config file filename.cfg:

\Preamble{html5}

\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<b>}}{\HCode{</b>}}

\Configure{HtmlPar}
    {\EndP\Tg<p>}
    {\EndP\Tg<p>}
    {\HCode{</p>\Hnewline}}
    {\HCode{</p>\Hnewline}}


\catcode`\:=11

    \ConfigureList{enumerate}%
   {\EndP\HCode{<dl \a:LRdir class="enumerate-enumitem">}%
      \PushMacro\end:itm
\global\let\end:itm=\empty}
   {\PopMacro\end:itm \global\let\end:itm \end:itm
\EndP\HCode{</dd></dl>}\ShowPar}
   {\end:itm \global\def\end:itm{\EndP\Tg</dd>}\HCode{<dt
        class="enumerate-enumitem"  style="float:left; clear:left; margin-left:1em; margin-right:1em; padding-top:5px;">}\bgroup \bf}
   {\egroup\EndP\HCode{</dt><dd\Hnewline class="enumerate-enumitem" style="padding-top:5px;">}}

\catcode`\:=12

\begin{document}

\EndPreamble

(Note the definition of \ConfigureList{enumerate} was taken from html4.4ht and only the style settings were added, directly within the tags of interest).

The file itself filename.tex:

\documentclass{article}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=4em, itemsep=0pt}
\setlist[enumerate,1]{wide, labelindent=0pt, label={Part \Roman* --}}
\setlist[enumerate,2]{wide=1em, label={\arabic* --}, resume}

\newlist{biblio}{itemize}{1}
\setlist[biblio]{label=\textbullet}

\begin{document}

\begin{enumerate}
\item A first item
  \begin{enumerate}
  \item A first subitem in enumerate
  \item A second one
    \begin{itemize}
    \item Itemize item
    \end{itemize}
  \end{enumerate}
\end{enumerate}

\end{document}

Built with make4ht -uf html5+tidy filename.tex will result in:

enter image description here

From the following html code:

<body>
<dl class="enumerate-enumitem">
<dt class="enumerate-enumitem" style="float:left; clear:left; margin-left:1em; margin-right:1em; padding-top:5px;">Part I –</dt>
<dd class="enumerate-enumitem" style="padding-top:5px;">A first item
<dl class="enumerate-enumitem">
<dt class="enumerate-enumitem" style="float:left; clear:left; margin-left:1em; margin-right:1em; padding-top:5px;">1 –</dt>
<dd class="enumerate-enumitem" style="padding-top:5px;">A first subitem in enumerate</dd>
<dt class="enumerate-enumitem" style="float:left; clear:left; margin-left:1em; margin-right:1em; padding-top:5px;">2 –</dt>
<dd class="enumerate-enumitem" style="padding-top:5px;">A second one
<ul class="itemize1">
<li class="itemize">Itemize item</li>
</ul>
</dd>
</dl>
</dd>
</dl>
</body>

Which can now be properly copy-pasted in a blog post in Wordpress (for it is both css-less and headless).

Previous answer

This works to produce a no-css html, but is not yet good enough, because the style settings are set in the html file head, so when copying to a wordpress blog post these settings were lost. But I keep it here for this might be useful for other purposes (and, strictly speaking, it does answer the OP).

I think I managed a reasonable solution to this (though in not a very useful form for my intended purpose). In no way I could tweak the html tags to get a description list to work without some styling (it doesn't mean it can't be done...). I also could not get the tex4ht option css-in to actually embed the style sheet in my html file. So I had somehow to bring the style manually to my file. I built the document with defaults letting it thus give me a css style sheet, where I found:

dt.enumerate-enumitem{float:left; clear:left; margin-left:1em; margin-right:1em;}

So, I added to my config file:

\Configure{@HEAD}{\HCode{<style>
dt.enumerate-enumitem{float:left; clear:left; margin-left:1em; margin-right:1em;}
</style>}}

And then ran things with option -css. The result is satisfactory:

enter image description here

In detail, my settings for this are:

A build file filename.mk4

set_settings{tex4ht_sty_par = "filename," .. settings.tex4ht_sty_par}
settings_add{ tex4ht_sty_par =  ",NoFonts,-css" }
Make:latexmk()

A config file filename.cfg:

\Preamble{html5}

\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}}
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<b>}}{\HCode{</b>}}

\Configure{HtmlPar}
    {\EndP\Tg<p>}
    {\EndP\Tg<p>}
    {\HCode{</p>\Hnewline}}
    {\HCode{</p>\Hnewline}}

\Configure{@HEAD}{\HCode{<style>
dt.enumerate-enumitem{float:left; clear:left; margin-left:1em; margin-right:1em;}
</style>}}

\begin{document}

\EndPreamble

The file itself filename.tex:

\documentclass{article}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=4em, itemsep=0pt}
\setlist[enumerate,1]{wide, labelindent=0pt, label={Part \Roman* --}}
\setlist[enumerate,2]{wide=1em, label={\arabic* --}, resume}

\begin{document}

\begin{enumerate}
\item A first item
  \begin{enumerate}
  \item A first subitem in enumerate
  \item A second one
    \begin{itemize}
    \item Itemize item
    \end{itemize}
  \end{enumerate}
\end{enumerate}

\end{document}

Built with:

make4ht -uf html5+tidy filename.tex
  • I still welcome comments though. ;-) – gusbrs Feb 20 at 14:58
  • Alas, while this works for a standalone html, it doesn't for copy-pasted html in Wordpress, because the <head> is trimmed in the process... – gusbrs Feb 20 at 15:02
  • isn't it possible to include the CSS file generated by tex4ht in the Wordpress template? – michal.h21 Feb 20 at 17:14
  • @michal.h21 Thank you for your comment. There are ways (which I haven't yet looked into) to define styles in Wordpress (I'm with wordpress.com not on a self hosted wordpress.org, though. Which means I don't really know how flexible things will really be). But I'm really looking for a "self sufficient" alternative. It would be enough to add a "style" directive inside the <dt> tag (I've tested a manual change). But I can't seem to convince tex4ht to do so. – gusbrs Feb 20 at 17:22
  • @michal.h21 On a general note. I looked into the corresponding \ConfigureList definitions inside the tex4ht directory. I tried to copy some of them to my config file to adjust them. But usually, when I do so, the build process fails. What's the catch? – gusbrs Feb 20 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.