3

Goal : add a picture and title on top of the table of contents, in the left frame, using make4ht.

Problem : I used htlatex a while ago and at this time, I have found a preamble which was able to do this (Thanks to @Michal.h21 if I recall correctly) but now repeating the process, I get a trouble with the encoding (I ask for utf-8 using french characters but the file remain in ascii) and also I have not separated frames for chapter/section, .... Using make4ht, no trouble with the encoding and the separated frames, but as I do not know how to handle preambles, I was not able to "mix" with the preamble for htlatex and get a) correct encoding b) 2 frames with the frame in the right being different at each chapter/section c) the frame on the left having a picture above a title above the table of content. What I would like is shown on the right hand of the picture below.

Is there a way (which I have not found yet on internet) to add a picture and a title (and anything else) above the tableofcontents in the left frame, using make4ht ?

Thanks

The results

What I've used :

for Test.tex

\documentclass[10pt, twoside, a4paper, openany]{book} \ifdefined\HCode \def\pgfsysdriver{pgfsys-dvisvgm4ht.def} \fi %% ---------------------------------------- \begin{document} \tableofcontents \chapter{Première Année} \section{Exemplarité 1} \subsection{Bancale} \subsection{Modulable} \section{Exemplarité 2} \subsection{Calculable} \subsection{Promulgable} \chapter{Deuxième Année} \section{Test 1} \section{Test 2} \end{document} 

for pream.cfg :

\Preamble{mathml,ext=xhtml,charset=''utf-8'',3,frames} \begin{document} \Css{body{ margin:1em auto; max-width:95\%; padding:0 .62em; }} \Configure{TITLE}{\HCode{<title>}\special{t4ht@[}}{\special{t4ht@]} Année 2025 \HCode{</title>\Hnewline}} \EndPreamble 

for pream_htlatex.cfg

\edef\hash{\string#} \Preamble{mathml,ext=html,charset = "UTF-8", 4,frames} \Configure{HTML}{\HCode{<html lang = "fr"> \Hnewline}}{\HCode{\Hnewline</html>}} \Css{ body{ margin:1em auto; max-width:None; padding:0 .62em; } } \Configure{TITLE}{\HCode{<title>}\special{t4ht@[}}{\special{t4ht@]}Année 2025\HCode{</title>\Hnewline}} \Configure{@HEAD}{\HCode{<link rel="profile" href="http://gmpg.org/xfn/11" />\Hnewline}} \Configure{@HEAD}{\HCode{<link rel="shortcut icon" href="logo.png" />\Hnewline}} \makeatletter \let\Title\@empty \let\Author\@empty \let\Date\@empty \def\title#1{\gdef\@title{#1} \immediate\write\@auxout{\string\gdef\string\Title{#1}}} \def\author#1{\gdef\@author{#1} \immediate\write\@auxout{\string\gdef\string\Author{#1}}} \def\date#1{\gdef\@date{#1} \immediate\write\@auxout{\string\gdef\string\Date{#1}}} \Configure{BODY} {\Tg<a id="title"/>% \HorFrames{*,3*}\Frame[ marginwidth="20" name="f1"]{s1}\Frame[ marginwidth="20" name="f2"]{s2} \NoFrames \PushStack\eBody{} \SubConfig \HPage[p1]{hello}\Link{}{s1}\EndLink \bgroup \Tg<img src="logo.png"> \Tg<h1>Année 20525 \Tg</h1> \Configure{Link}{a}{target="f2" href=}{name=}{} \tableofcontents \egroup \EndHPage{p1} \Tg<br /> \HPage[p2]{text2222}\Link{}{s2}\EndLink } { \EndHPage{p2}} \def\SubConfig{% \Configure{BODY} {\PushStack\eBody{x}\Tg<body>} {\PopStack\eBody\temp \ifx \temp\empty \EndFrames \else\Tg</body>\fi} \Configure{DOCTYPE} {\HCode{<!DOCTYPE html> \Hnewline}} } \def\pgfsysdriver{pgfsys-tex4ht.def} \renewcommand{\mathcal}[1]{#1} \begin{document} \EndPreamble 

and the command lines where

htlatex Test.tex "pream_htlatex.cfg, xhtml, html5" 

and

make4ht Second_Test.tex "3,frames" -c pream.cfg 

1 Answer 1

5

There are several issues with your config file. The first is with the \Preamble command. It needs to start with the xhtml option, otherwise invalid HTML file will be produced. charset is not necessary, make4ht produces utf-8 files by default. I also added some \ifvmode\IgnorePar\fi\EndP and \SaveEndP commands to handle paragraphs.

Here is a fixed config file:

\edef\hash{\string#} \Preamble{xhtml,mathml,ext=xhtml,4,frames} \Configure{HTML}{\HCode{<html lang = "fr"> \Hnewline}}{\HCode{\Hnewline</html>}} \Css{ body{ margin:1em auto; max-width:None; padding:0 .62em; } } \Configure{TITLE}{\HCode{<title>}\special{t4ht@[}}{\special{t4ht@]}Année 2025\HCode{</title>\Hnewline}} \Configure{@HEAD}{\HCode{<link rel="profile" href="http://gmpg.org/xfn/11" />\Hnewline}} \Configure{@HEAD}{\HCode{<link rel="shortcut icon" href="logo.png" />\Hnewline}} \makeatletter \let\Title\@empty \let\Author\@empty \let\Date\@empty \def\title#1{\gdef\@title{#1} \immediate\write\@auxout{\string\gdef\string\Title{#1}}} \def\author#1{\gdef\@author{#1} \immediate\write\@auxout{\string\gdef\string\Author{#1}}} \def\date#1{\gdef\@date{#1} \immediate\write\@auxout{\string\gdef\string\Date{#1}}} \Configure{BODY} {\HCode{<a id="title"></a>}% \ifvmode\IgnorePar\fi\EndP \HorFrames{*,3*}\Frame[ marginwidth="20" name="f1"]{s1}\Frame[ marginwidth="20" name="f2"]{s2} \ifvmode\IgnorePar\fi\EndP\NoFrames \PushStack\eBody{} \SubConfig %\ifvmode\IgnorePar\fi\EndP \HPage[p1]{hello}\Link{}{s1}\EndLink \bgroup\ifvmode\IgnorePar\fi\EndP \Tg<img src="logo.png"> \Tg<h1>Année 20525 \Tg</h1> \Configure{Link}{a}{target="f2" href=}{name=}{} \tableofcontents \ifvmode\IgnorePar\fi\EndP \egroup \EndHPage{p1} \Tg<br /> \ifvmode\IgnorePar\fi\EndP \HPage[p2]{text2222}\Link{}{s2}\EndLink } { \ifvmode\IgnorePar\fi\EndP \EndHPage{p2} hello} \def\SubConfig{% \Configure{BODY} {\SaveEndP\PushStack\eBody{x}\Tg<body>} {\PopStack\eBody\temp \ifx \temp\empty \EndFrames \else \EndP\Tg</body>\fi} \Configure{DOCTYPE} {\HCode{<!DOCTYPE html> \Hnewline}} } \def\pgfsysdriver{pgfsys-tex4ht.def} \renewcommand{\mathcal}[1]{#1} \begin{document} \EndPreamble 

This is the result:

enter image description here

5
  • Top ! Thanks a lot ! I have looked at your corrections and learned (even if I am not sure to understand fully) Commented Sep 12 at 12:52
  • 1
    @Tezhom the problem is that make4ht parses the HTML files using XML parser and then does some post-processing. When the XML parser fails, it tries a HTML parser, but sometimes even that fails if the HTML code is well formed. Without the post-processing, MathML code can be incorrect. So it is always good to check for DOM parsing errors in the make4ht run. Usually they are caused by unclosed paragraphs, which can be fixed using the \EndP command usually. The \IgnorePar command will prevent opening of paragraph before block level elements, such as <div>, that would lead to errors too. Commented Sep 12 at 15:53
  • I see, thanks for the explanation, well done as I currently undergoes troubles with package : \usepackage{wrapfig} gives "[WARNING] domfilter: XML DOM parsing of Test.html failed: [WARNING] domfilter: ...ive/2025/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/p) [char=736]" Commented Sep 13 at 7:27
  • So far, so good, thanks again ! Commented Sep 13 at 7:52
  • 1
    @Tezhom can you add a new MWE for the wrapfig issue? maybe as a new question? It should be fixable. Commented Sep 13 at 17:50

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.