无法使用 make4ht 解释不平衡的正文或段落标签问题

无法使用 make4ht 解释不平衡的正文或段落标签问题

我不明白为什么 make4ht 转换会导致 DOM 解析失败。

系统:macOS,通过 TeXLive-2022 搭载 TeXShop(所有最新版本均最近更新)

所有配置的 MWE(以防出现包冲突)

%% 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}

该文档通过 LaTeX 编译为 PDF。

我正在通过这个命令行引擎编译为 HTML

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

css 文件中的元素类似于

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

cfg 文件是

\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

编译消息是

[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

HTML 文件缺少结束符 </p>

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

答案1

问题在于您没有在body配置中关闭段落。当您想要插入应关闭当前段落且不应包含在任何段落中的标签(例如)时,</body>您需要使用\ifvmode\IgnorePar\fi\EndP命令。\IgnorePar将阻止插入新<p>标签,\EndP并将插入关闭</p>

因此正确的配置文件可能如下所示:

\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

结果如下:

在此处输入图片描述

相关内容