tex4ebook:内容包含表格时,html 解析错误

tex4ebook:内容包含表格时,html 解析错误

我正在使用 tex4ebook 生成 .epub。编译过程中出现两组错误,均与解析包含表格(不平衡或意外标签)的 html 文件有关。如能提供任何有关如何解决这些错误的提示,我将不胜感激。

麦格

\documentclass{book}

\usepackage{tabularx}

\begin{document}

\begin{center}
\begin{tabularx}{\textwidth}{l X}
    A & Apple \\
\end{tabularx}
\end{center}

\part{B}
\noindent
\begin{tabularx}{\textwidth}{l X}
    B & Banana \\
\end{tabularx}
\end{document}

版本.mk4

local domfilter = require "make4ht-domfilter"
local filter = require "make4ht-filter"
local dom    = require "luaxml-domobject"
local log = logging.new "build file"


local function mwe_parsing(s)
      local status, obj = pcall(function()
          return dom.parse(s)
      end)
      if not status then 
        log:warning("HTML parsing failed")
        log:warning(obj)
        return s 
      end
      obj:traverse_elements(function(el)
      end)
      -- serialize the DOM object back to HTML
      return obj:serialize()
end

local process = filter {mwe_parsing}
Make:match("html$", process)
Make:match("html$", "tidy -m -xml -utf8 -q -i ${filename}")

Make:htlatex {}

我在下面包含了编译期间生成的输出。如果我注释掉\begin{center}\end{center},第一组错误就会消失。如果我注释掉\part{B}或,\noindent第二组错误就会消失。

[STATUS]  tex4ebook: Conversion started
[STATUS]  tex4ebook: Input file: mwe.tex
[WARNING] build file: HTML parsing failed
[WARNING] build file: /usr/share/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/div) [char=1303]

line 27 column 1 - Error: unexpected </div> in <p>
line 36 column 1 - Error: unexpected </body> in <p>
line 36 column 8 - Error: unexpected </html> in <p>
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.

[WARNING] domfilter: DOM parsing of mwe.html failed:
[WARNING] domfilter: /usr/share/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/div) [char=1303]

[WARNING] build file: HTML parsing failed
[WARNING] build file: /usr/share/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/body) [char=1525]

line 32 column 1 - Error: unexpected </body> in <p>
line 32 column 8 - Error: unexpected </html> in <p>
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.

[WARNING] domfilter: DOM parsing of mwepa1.html failed:
[WARNING] domfilter: /usr/share/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/body) [char=1525]

HTML Tidy for Linux version 5.7.16
[STATUS]  tex4ebook: Conversion finished

日志

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020/Arch Linux) (preloaded format=latex 2021.2.14)  3 MAR 2021 22:17
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCo
de"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.
{\g@addto@macro\@documentclasshook{\RequirePackage[#1,html]{tex4ht}\RequirePack
age{tex4ebook}}\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HC
ode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentst
yle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}}\makeatother\HCode x
html,,charset=utf-8,charset=utf-8,epub,uni-html4.a.b.c.\input "\detokenize{mwe.
tex}"
(./mwe.tex (/usr/share/texmf-dist/tex/latex/base/book.cls
Document Class: book 2020/04/10 v1.4m Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/bk10.clo
File: bk10.clo 2020/04/10 v1.4m Standard LaTeX file (size option)
)
\c@part=\count177
\c@chapter=\count178
\c@section=\count179
\c@subsection=\count180
\c@subsubsection=\count181
\c@paragraph=\count182
\c@subparagraph=\count183
\c@figure=\count184
\c@table=\count185
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
) (/usr/share/texmf-dist/tex/generic/tex4ht/tex4ht.sty
version 2020-10-16-13:47
Package: tex4ht 
\tmp:toks=\toks15
) (/usr/share/texmf-dist/tex/generic/tex4ht/usepackage.4ht
version 2020-10-17-13:53
) (/usr/share/texmf-dist/tex/latex/tex4ebook/tex4ebook.sty
Package: tex4ebook 2016/03/31 version 0.1d
(/usr/share/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
\etb@tempcnta=\count186
) (/usr/share/texmf-dist/tex/latex/kvoptions/kvoptions.sty
Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO)
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks16
) (/usr/share/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty
Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO)
) (/usr/share/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty
Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO)
)) (/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty
Package: graphicx 2020/09/09 v1.2b Enhanced LaTeX Graphics (DPC,SPQR)
(/usr/share/texmf-dist/tex/generic/tex4ht/graphics-hooks.4ht
version 2020-10-17-13:53
) (/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
Package: graphics 2020/08/30 v1.4c Standard LaTeX Graphics (DPC,SPQR)
(/usr/share/texmf-dist/tex/latex/graphics/trig.sty
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
) (/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: dvips.def on input line 105.
(/usr/share/texmf-dist/tex/latex/graphics-def/dvips.def
File: dvips.def 2017/06/20 v3.1d Graphics/color driver for dvips
))
\Gin@req@height=\dimen139
\Gin@req@width=\dimen140
)) (/usr/share/texmf-dist/tex/latex/tools/tabularx.sty
Package: tabularx 2020/01/15 v2.11c `tabularx' package (DPC)
(/usr/share/texmf-dist/tex/latex/tools/array.sty
Package: array 2020/10/01 v2.5c Tabular extension package (FMi)
\col@sep=\dimen141
\ar@mcellbox=\box47
\extrarowheight=\dimen142
\NC@list=\toks17
\extratabsurround=\skip49
\backup@length=\skip50
\ar@cellbox=\box48
)
\TX@col@width=\dimen143
\TX@old@table=\dimen144
\TX@old@col=\dimen145
\TX@target=\dimen146
\TX@delta=\dimen147
\TX@cols=\count187
\TX@ftn=\toks18
) (/usr/share/texmf-dist/tex/generic/tex4ht/tex4ht.4ht
version 2020-03-12-14:03
::::::::::::::::::::::::::::::::::::::::::
 TeX4ht info is available in the log file 
::::::::::::::::::::::::::::::::::::::::::
) (/usr/share/texmf-dist/tex/generic/tex4ht/tex4ht.sty
version 2020-10-16-13:47
--- needs --- tex4ht mwe ---
\tmp:cnt=\count188
(./mwe.tmp)
\tmp:dim=\skip51
l.1460 --- TeX4ht warning --- No file mwe.xref ---
\:refout=\write3
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
TeX4ht package options: xhtml,charset=utf-8,epub,uni-html4,html
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)
\:tokwrite=\toks19
\:tokpage=\toks20
\:tocout=\write4
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht) (/usr/share/texmf-di
st/tex/generic/tex4ht/latex.4ht
version 2020-10-03-14:24
LaTeX Info: Redefining \_ on input line 173.
LaTeX Info: Redefining \, on input line 787.
LaTeX Info: Redefining \; on input line 788.
LaTeX Info: Redefining \! on input line 789.
LaTeX Info: Redefining \: on input line 790.
LaTeX Info: Redefining \> on input line 791.
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht) (/usr/share/texmf-di
st/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/fontmath.4ht
version 2018-11-06-15:55
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/book.4ht (/usr/share/texmf-dist/tex/generic/tex4ht/html4
.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/latex/tex4ebook/tex4ebook.4ht
\opf:htmlid=\count189
\navpoint=\count190
) (/usr/share/texmf-dist/tex/generic/tex4ht/graphicx.4ht
version 2018-10-01-14:24
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/graphics.4ht (/usr/share/texmf-dist/tex/generic/tex4ht/h
tml4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/dvips.4ht
version 2009-05-21-09:32
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/tabularx.4ht
version 2009-05-21-09:32
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/array.4ht
version 2009-05-21-09:32
(/usr/share/texmf-dist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/generic/tex4ht/html4.4ht
version 2020-11-27-15:09
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-math.4ht
version 2020-11-09-14:28
) (/usr/share/texmf-dist/tex/generic/tex4ht/unicode.4ht
version 2020-09-18-15:30
) (/usr/share/texmf-dist/tex/generic/tex4ht/html4-uni.4ht)) (/usr/share/texmf-d
ist/tex/latex/l3backend/l3backend-dvips.def
File: l3backend-dvips.def 2020-09-24 L3 backend support: dvips
\l__pdf_internal_box=\box49
\g__pdf_backend_object_int=\count191
\l__pdf_backend_content_box=\box50
\l__pdf_backend_model_box=\box51
\g__pdf_backend_annotation_int=\count192
\g__pdf_backend_link_int=\count193
\g__pdf_backend_link_sf_int=\count194
)
No file mwe.aux.
LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
--- file mwe.css ---
[1

] [2

] [3] [4]
--- file mwepa1.html ---
No file mwe.4tc
[5] [6

] (./mwe.aux) ) 

答案1

在某些情况下,环境似乎tabularx不会关闭上一段。使用以下配置文件可以很容易地修复此问题:

\Preamble{xhtml}
\ConfigureEnv{tabularx}{\ifvmode\IgnorePar\fi\EndP}{}{}{}
\begin{document}
\EndPreamble

它配置tabularx环境以在输出标签之前关闭前一段<table>

以下是原始输出:

<!--l. 7--><p class="noindent" >
 <table id="TBL-3" class="tabular" 

这是固定输出:

   <p class='noindent'></p>
      <table id='TBL-3' class='tabular'>

相关内容