2

I'm writing a book and I create a new environement dialog in my .cls as following :

\RequirePackage{enumitem}
\newlist{dialog}{itemize}{1}
\setlist[dialog]{label=---,left = 0pt}

When I try to generate an ebook with tex4ebook, there is no new line at the end of dialog lines (all the dialog lines are the same one). There is no message error.

If I try to make a simple list in my document within itemize environment everything is ok, so I think there is a problem with my dialog environment but I can't figure out what is it. I precise that the pdf created with xetex is ok.

1
  • could you please make a full MWE, that show the intended usage of your custom environment, and that could be directly compiled?
    – michal.h21
    Commented Sep 22, 2021 at 9:54

1 Answer 1

2

You haven't provided a MWE, so here is some small sample:

\documentclass{article}
\RequirePackage{enumitem}
\newlist{dialog}{itemize}{1}
\setlist[dialog]{label=---,left = 0pt}
\begin{document}
\begin{dialog}
\item Hello World
\item Hello, hello
\end{dialog}
\end{document}

When you compile this example, this is the resulting HTML code you get:

<body>
— Hello World
— Hello, hello
    
</body> 

As you can see, there are no HTML tags around your list, so it is rendered on one line in the browser. You need to provide a configuration for all custom lists, in order to insert suitable HTML elements.

As you use custom text for the label, you can use the <dl> element.

All lists are configured using \ConfigureList command. From the documentation:

\ConfigureList.....................5

   #1   type of list (e.g., itemize, description, enumerate,
                            list, trivlist)
   #2   before list
   #3   after  list
   #4   before label
   #5   after label

The configuration file can look like this:

\Preamble{xhtml}
\ConfigureList{dialog}
{\ifvmode\IgnorePar\fi\EndP\HCode{<dl class="dialog">}\par\ShowPar
\def\enddialoglabel{}
}
{\ifvmode\IgnorePar\fi\EndP\enddialoglabel\HCode{</dl>}}
{\enddialoglabel\HCode{<dt>}\def\enddialoglabel{\EndP\HCode{</dd>}}}
{\HCode{</dt><dd>}\par\ShowPar\AnchorLabel}
\Css{.dialog{display:grid;grid-template-columns: 1em 1fr;}}

\begin{document}
\EndPreamble

It creates <dl class="dialog"> element. There is a lot of commands used. \ifvmode\IgnorePar\fi\EndP closes paragraphs before the list. We define the \enddialoglabel command to insert closing tags for the previous item. It is used at the beginning of each item, so it is empty at first, and then redefined to insert the closing tag. \AnchorLabel inserts link destinations for \label commands.

We use the CSS grid to display label and text on the same line, because they are on separate lines by default.

Compile using:

make4ht -c mycfg.cfg filename.tex

This is the resulting HTML:

<body>
   <dl class='dialog'> <dt>
— </dt><dd>
<a id='x1-2x'></a>
   <!-- l. 7 --><p class='noindent'>Hello World
   </p></dd><dt>
— </dt><dd>
<a id='x1-3x'></a>
   <!-- l. 8 --><p class='noindent'>Hello, hello</p></dd></dl>

In the browser:

enter image description here

1
  • Thank you very much for the whole explanation. It works :)
    – Marianne
    Commented Sep 22, 2021 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .