1

I cannot figure out why make4ht conversion gives a DOM parsing failure.

System: macOS with TeXShop via TeXLive-2022 (all latest versions recently updated)

MWE with all configurations (in case a package conflict is to blame)

%% course outline
\DocumentMetadata{uncompress,pdfstandard=a-2u}
\documentclass[12pt]{article}
%%% PACKAGES
\usepackage{newtxtext, newtxmath}
\usepackage{ifthen, geometry, hyperref}
\usepackage{lipsum}
%%% COMMANDS
\newboolean{HTML}
\setboolean{HTML}{false}
\newcommand{\SetHTML}[1][true]{
    \setboolean{HTML}{#1}
    }
\newcommand{\WhenHTML}[1]{%
    \ifthenelse{\boolean{HTML}}
        {#1}{}
        }
%%% COURSE INFO
%%%\input{courseinfo} -- separate file when in use
%%% DOCUMENT SETTINGS
%% page
\geometry{
    letterpaper,
    hmargin={1in,1in},
    vmargin={0.75in,1in},
    headsep=6pt,
    headheight=18pt
    }
%% style
\setlength{\parindent}{0pt}
\setlength{\parskip}{4pt}
\setcounter{secnumdepth}{0}
%% hyperref
\hypersetup{
    pdftitle={111 The Course},
    pdfsubject={subject},
    pdfkeywords={keywords},
    pdfauthor={author},
    pdflang={en-US},
    colorlinks=true,
    urlcolor=blue,
    citecolor=blue
    }
%%% DOCUMENT
\begin{document}

%% output ToC in HTML mode
\WhenHTML{\tableofcontents}

\thispagestyle{empty}

\begin{center}{\LARGE{}111: The Course}\end{center}

\section{Course Information}

\subsection{Contact}

\vspace*{-\baselineskip}
\begin{tabular}{lr}
\multicolumn{2}{c}{\rule{0.95\textwidth}{0pt}} \\
\textbf{Instructor}: Instructor
& \textbf{Office}: Office \\
\textbf{Email}: \href{mailto:[email protected]}{[email protected]} &
\textbf{Phone}: 111-222-3333 \\
\multicolumn{2}{l}{\textbf{Office Hours}: by appointment} \\
\end{tabular}

\subsection{Details}

\vspace*{-\baselineskip}
\begin{tabular}{lr}
\multicolumn{2}{c}{\rule{0.95\textwidth}{0pt}} \\
\textbf{Course Name}: The Course
& \textbf{Delivery Mode}: in person \\
\textbf{Credit Hours}: 3 &
\textbf{Semester/Year}: Fall 2022 \\
\multicolumn{2}{l}{\textbf{Meeting}: at some time, somewhere}
\end{tabular}

\textbf{Prerequisites}: some things you must know before you start

\subsection{Overview}

\subsubsection{Catalogue Description}

\subsubsection{Description}

\lipsum[1]

\section{University Information}

Refer to information posted under the Syllabus link for the course.

\end{document}

The document compiles via LaTeX to PDF.

I am compiling to HTML via an engine with this command line

make4ht -u -c syllabus.cfg -d Webpage $1

Elements in the css file are akin to

/* start css.sty */
body{
    font-size:100%;
    }
.likesectionHead{
    font-size:5vw;
    color:blue;
    }
table{
    width:100%;
    }
/* end css.sty */

The cfg file is

\Preamble{xhmtl}
% top
\Configure{VERSION}{} 
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>}} 
\Configure{HTML}{\HCode{\Hnewline<html>}}{\HCode{</html>}}
\Configure{AddCss}{syllabus.css}
% header
\Configure{HEAD}{\HCode{\Hnewline<head>}}{\HCode{\Hnewline</head>}}
\Configure{TITLE+}{Course Outline} 
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{\Hnewline<meta  charset="utf-8"/>}}
\Configure{@HEAD}{\HCode{\Hnewline<meta name="viewport" content="width=device-width,initial-scale=1"/>}}
\Configure{@HEAD}{\HCode{\Hnewline<link rel="stylesheet" type="text/css" href="syllabus.css"/>}}
% body
\Configure{BODY}{\HCode{\Hnewline<body>}}{\HCode{</body>\Hnewline}} 
% paragraphs
\Configure{HtmlPar}
    {\EndP\HCode{\Hnewline<p class="indent">}}{\EndP\HCode{\Hnewline<p class="noindent">}}
    {\HCode{</p>}}{\HCode{</p>}}
% Translate \textbf, \textit and \texttt directives into <strong>, <em> and <code> 
\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}} 
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<strong>}}{\HCode{</strong>}} 
\Configure{textit}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}} 
\Configure{texttt}{\ifvmode\ShowPar\fi\HCode{<code>}}{\HCode{</code>}} 
\Configure{textsc}{\ifvmode\ShowPar\fi\HCode{<span class="sc">}}{\HCode{</span>}} 
\begin{document}
% \Configure{FontFamily}{rmfamily}{Latin Modern}
\SetHTML{}
\EndPreamble

The compilation message is

[37m[STATUS]  [0mmake4ht: Conversion started
[37m[STATUS]  [0mmake4ht: Input file: courseoutline.tex
[33m[WARNING] [0mdomfilter: DOM parsing of courseoutline.html failed:
[33m[WARNING] [0mdomfilter: ...ive/2022/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/body) [char=6707]

[37m[STATUS]  [0mmake4ht: Conversion finished

The HTML file is missing a closing </p>

<p class="indent">Refer to information posted under the Syllabus link for the course.
</body> 
</html>

1 Answer 1

1

The problem is that you don't close paragraphs in your body configuration. When you want to insert tags which should close the current paragraph, and which shouldn't be included in any paragraphs, such as </body>, you need to use the \ifvmode\IgnorePar\fi\EndP commands. The \IgnorePar will prevent insertion of the new <p> tag, and \EndP will insert closing </p>.

So the correct configuration file could look like this:

\Preamble{xthml}
% top
\Configure{VERSION}{} 
\Configure{DOCTYPE}{\HCode{<!DOCTYPE html>}} 
\Configure{HTML}{\HCode{\Hnewline<html>}}{\HCode{</html>}}
\Configure{AddCss}{syllabus.css}
% header
\Configure{HEAD}{\HCode{\Hnewline<head>}}{\HCode{\Hnewline</head>}}
\Configure{TITLE+}{Course Outline} 
\Configure{@HEAD}{}
\Configure{@HEAD}{\HCode{\Hnewline<meta  charset="utf-8"/>}}
\Configure{@HEAD}{\HCode{\Hnewline<meta name="viewport" content="width=device-width,initial-scale=1"/>}}
\Configure{@HEAD}{\HCode{\Hnewline<link rel="stylesheet" type="text/css" href="syllabus.css"/>}}
% body
\Configure{BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{\Hnewline<body>}}{\ifvmode\IgnorePar\fi\EndP\HCode{</body>\Hnewline}} 
% paragraphs
\Configure{HtmlPar}
    {\EndP\HCode{\Hnewline<p class="indent">}}{\EndP\HCode{\Hnewline<p class="noindent">}}
    {\HCode{</p>}}{\HCode{</p>}}
% Translate \textbf, \textit and \texttt directives into <strong>, <em> and <code> 
\Configure{emph}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}} 
\Configure{textbf}{\ifvmode\ShowPar\fi\HCode{<strong>}}{\HCode{</strong>}} 
\Configure{textit}{\ifvmode\ShowPar\fi\HCode{<em>}}{\HCode{</em>}} 
\Configure{texttt}{\ifvmode\ShowPar\fi\HCode{<code>}}{\HCode{</code>}} 
\Configure{textsc}{\ifvmode\ShowPar\fi\HCode{<span class="sc">}}{\HCode{</span>}} 
\begin{document}
% \Configure{FontFamily}{rmfamily}{Latin Modern}
\SetHTML{}
\EndPreamble

This is the result:

enter image description here

2
  • Thank you. My approach to the cfg likely reveals an engineer who hacked together various parts scattered on the Web. I would never have recognized that this addition is needed, and I lack the deeper understanding to have puzzled it out on my own. FWIW, I had hacked a work-around that simply substituted {\HCode{</p>\Hnewline</body>\Hnewline}} as the closing code for \Configure{BODY}. All is good now! Aug 16, 2022 at 13:13
  • @JeffreyJWeimer sure, it is a normal approach, as there is a lot of information scattered around the web. Lately, I've put lot of actual information to the documentation here: kodymirus.cz/tex4ht-doc/Configurations.html
    – michal.h21
    Aug 16, 2022 at 13:24

You must log in to answer this question.

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