我正在尝试使用 tex4ht 程序转换 Latex 文档,但转换过程中出现各种错误。为了执行转换,我在 TeX Live 命令行中插入了 make4ht -l something.tex(something 是文档的名称),而最小示例是:
% !TeX program = lualatex
% !TeX encoding = UTF-8 Unicode
\documentclass[10pt,a4paper,twoside]{report}
\usepackage{fontspec}
\setmainfont{Arial}
%\usepackage{kotex}
\usepackage{float}
\usepackage{graphicx,graphbox}
\usepackage{enumitem}
\setlist[itemize,2]{label={$\circ$}}
\usepackage{longtable}
\usepackage{arydshln}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\textbox}[1]{node[black,fill=white, draw=black,line width=0.03cm,font=\small,text width = {#1}]}
\newcommand{\numbox}[1]{node[black,line width=0.028cm,fill=white,font=\small, draw={#1}]}
\newenvironment{tiks}[1]{%
\begin{tikzpicture}
\node [above right,inner sep=0] (image) at (0,0){#1};
\begin{scope}[x={($0.1*(image.south east)$)},y={($0.1*(image.north west)$)}]
}
{
\end{scope}
\path ($(image.center)!-1!(current bounding box.west)$)% expand east border
($(image.center)!-1!(current bounding box.east)$);% expand west border
\end{tikzpicture}}
\begin{document}
\begin{titlepage}
\vspace*{5cm}
\begin{tabular}{l l l}
& & \bfseries H:\\
\end{tabular}
\end{titlepage}
\begin{itemize}
\item Zufriedenheit
\begin{itemize}
\item something 1
\end{itemize}
\end{itemize}
\noindent\begin{minipage}[t]{0.3\textwidth}
\vspace{-3.75ex}
\begin{figure}[H]
\begin{tiks}{\includegraphics[width=\linewidth,height=7.6cm,trim={0cm 0cm 0cm 0cm},clip]{example-image}}
\draw (1.7,7.15)
\numbox{black}{1};
\draw[latex-, line width = 0.03cm,red,align=center,left]
(8,8) -- (5,8)
\textbox{2cm} {taste};
\end{tiks}
\end{figure}
\end{minipage}
\begin{tikzpicture}[remember picture,overlay,shift={(current page.north east)}]
\node[anchor=north east,xshift=-7.9cm,yshift=-6.4cm]{\includegraphics[width=0.7cm,height=1cm]{example-image}};
\end{tikzpicture}
% \begin{longtable}{|p{2.8cm}|p{0.6cm}|}
% \hline
% Name & Year \\
% \hline
% \end{longtable}
\end{document}
我尝试执行转换时获得的结果是:
C:\Users\Me>make4ht -l something.tex
[STATUS] make4ht: Conversion started
[STATUS] make4ht: Input file: something.tex
This is LuaTeX, Version 1.13.2 (TeX Live 2021/W32TeX)
restricted system commands enabled.
Unsupported font cmsy10
[ERROR] htlatex: Compilation errors in the htlatex run
[ERROR] htlatex: Filename Line Message
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 61 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: ? 855 Undefined control sequence.
This is LuaTeX, Version 1.13.2 (TeX Live 2021/W32TeX)
restricted system commands enabled.
Unsupported font cmsy10
[ERROR] htlatex: Compilation errors in the htlatex run
[ERROR] htlatex: Filename Line Message
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 61 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: ? 855 Undefined control sequence.
This is LuaTeX, Version 1.13.2 (TeX Live 2021/W32TeX)
restricted system commands enabled.
Unsupported font cmsy10
[ERROR] htlatex: Compilation errors in the htlatex run
[ERROR] htlatex: Filename Line Message
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsL /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 Undefined control sequence.
[ERROR] htlatex: \adl@colsR /\number \adl@... 37 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: \adl@colsR /\number \adl@... 50 LaTeX Error: File `"example-image.xbb"' not found.
[ERROR] htlatex: \adl@colsR /\number \adl@... 61 LaTeX Error: Cannot determine size of graphic in "example-image.xbb" (no Boun
[ERROR] htlatex: ? 855 Undefined control sequence.
pre-processing DVI file (format version 2)
processing page 2
graphic size: 133.83823pt x 44.064459pt (47.038758mm x 15.486886mm)
output written to /
1 of 4 pages converted in 0.803 seconds
pre-processing DVI file (format version 2)
processing page 3
page is empty
graphic size: 0pt x 0pt (0mm x 0mm)
output written to /
1 of 4 pages converted in 0.732 seconds
[STATUS] make4ht: Conversion finished
C:\texlive\2021\bin\win32\runscript.tlu:915: command failed with exit code 1:
texlua c:\texlive\2021\texmf-dist\scripts\make4ht\make4ht -l something.tex
我对所得的一些错误作出了如下评估:
不支持的字体 cmsy 10 警告:此警告是由于 \setlist[itemize,2]{label={$\circ$}} 行导致的嵌套 itemize 环境的结果。
htlatex:\adl@colsL /\number\adl@... 82 未定义控制序列:与 titlepage 环境相关或内部的内容。但是,当我注释掉 arydshln 包时,此错误消失。
htlatex:\adl@colsR /\number\adl@... 82 LaTeX 错误:未找到文件“example-image.xbb”:此错误(以及其后的错误)是 Tikz 图片的后果。虽然我可以通过创建 xbb 文件(在 TeX Live 命令行中插入 ebb -x example-image.png)来消除错误,但请参阅https://www.kodymirus.cz/tex4ht-doc/Howto.html#graphics,将 example-image.png 移动到 C:\Users\Me) 后,创建的 HTML 仍然没有 example-image。
除了主要问题之外,我还有两个问题(不太相关,在接受假设答案时不会被考虑):
- 取消注释 longtable 示例后,转换不会完成,除非我注释掉 arydshln 包。如何修复此问题?
- 当我取消注释 kotex 包时,会出现各种错误。同样,如何修复这个问题?
答案1
还有很多不相关的问题,但我发现大多数问题都得到了修复:
- 表格问题。似乎
arydshln
修补了许多用于处理表格的内部 LaTeX 宏。您可以尝试以下版本arydshln.4ht
:
\def\:new:array{\adl@everyvbox\everyvbox
\everyvbox{\adl@arrayinit \the\adl@everyvbox \everyvbox\adl@everyvbox}%
\ifadl@inactive \adl@inactivate \else \adl@activate \fi
\let\adl@noalign\noalign}
\ifcsname n:@array:\endcsname% if \@array was already patched
\let\orig:n@array\n:@array:
\def\n:@array:{\:new:array\orig:n@array}
\else
\pend:def\@array{\:new:array}
\fi
\Hinput{arydshln}
\endinput
它尝试插入将arydshln
宏初始化为 TeX4ht 版本的 的代码\@array
。这应该可以防止编译错误。但这还不够longtable
。由于 TeX4ht 无论如何都不支持此包提供的功能,您可能只想有条件地包含它。将以下条件放入您的序言中:
\usepackage{longtable}
\ifdefined\HCode\else
\usepackage{arydshln}
\fi
\usepackage{multirow}
- 图形问题。这个比较复杂。问题是您
\includegraphics
在 TikZ 环境中。TikZ 使用命令内部转换为图片\Picture
。然后它取决于 DVI 转换器是否支持图像包含。由于 TikZ 使用 DVISGM 转换为 SVG,因此我们需要使用dvisvgm
Graphics 包的驱动程序才能获得正确的支持。
所有这些都非常复杂,并且还需要对您的 TeX 文档进行一些更改。
首先,要摆脱 XBB 错误,请尝试此版本graphics.4ht
:
% graphics.4ht (2022-03-21-12:05), generated from tex4ht-4ht.tex
% Copyright 1997-2009 Eitan M. Gurari
% Copyright 2009-2022 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2022-03-21-12:05}
\expandafter\let\csname includegraphics \endcsname\includegraphics
\def\includegraphics{\expandafter\protect\csname includegraphics \endcsname}
\def\grf:removequote"#1"{#1}
\def\grf:thrashname#1\relax{}
\def\grf:fixquotes{%
\@ifnextchar"{\edef\Gin@base{\expandafter\grf:removequote\Gin@base}\grf:thrashname}{\grf:thrashname}}
\def\grp:warning#1{\no:bound#1(no BoundingBox)//\:warning{#1}}
\def\no:bound#1(no BoundingBox)#2//{\gdef\noBoundingBox{#2}\ifx
\noBoundingBox\empty \global\let\noBoundingBox\:UnDef\fi}
\let\:tempc\Gin@setfile
\pend:defIII\:tempc{\a:graphics
\global\let\noBoundingBox\:UnDef
\let\@latex@error\grp:warning \let\@ehc\empty}
\append:defIII\:tempc{\b:graphics\grf:gobble\leavevmode grf:gobble}
\HLet\Gin@setfile\:tempc
\NewConfigure{graphics*}[2]{%
\expandafter\ifx \csname :.#1\endcsname\relax
\pend:defIII\n:Gin@setfile:{\csname :.#1\endcsname}%
\fi
\def\:temp{#2}\ifx \:temp\empty
\expandafter\let\csname :.#1\endcsname\:UnDef
\else
\expandafter\def\csname :.#1\endcsname{\edef\:temp{\detokenize{.#1}}%
\ifx \:temp\Gin@ext \let\a:graphics\relax
\def\G:cnfg{#2}\expandafter\grf:gobble \fi}%
\fi }
\NewConfigure{graphics}{2}
\def\grf:gobble#1\leavevmode#2grf:gobble{%
\PictureOff\expandafter\grf:fixquotes\Gin@base\relax#1\PictureOn \G:cnfg \let\G:cnfg\relax}
\let\G:cnfg\relax
\let\old:GreadEps\Gread@eps
\def\Gread@eps#1{\old:GreadEps{"#1"}}
\def\if:boundingbox#1#2{\ifdim\Gin@req@width=\Gin@nat@width\ifx\noBoundingBox\UnDefined#1\else#2\fi\else#1\fi}
\def\Gin:defaultdriver{dvips.def}
\ifx\Gin@driver\Gin:defaultdriver%
\DeclareGraphicsRule{.png}{bmp}{.xbb}{}
\DeclareGraphicsRule{.jpg}{bmp}{.xbb}{}
\DeclareGraphicsRule{.gif}{bmp}{.xbb}{}
\DeclareGraphicsRule{.pdf}{bmp}{.xbb}{}
\DeclareGraphicsRule{.svg}{bmp}{.xbb}{}
\fi
\Hinput{graphics}
\endinput
变化是它\DeclareGraphicsRule
仅在dvips
驱动程序处于活动状态时运行。我们不希望它与dvisvgm
驱动程序一起运行。您仍然需要.xbb
使用创建文件
ebb -x *.png
然后,将调用改为graphicx
:
\ifdefined\HCode
\usepackage[dvisvgm]{graphicx}
\else
\usepackage{graphicx}
\fi
它将使用dvisvgm
带有 TeX4ht 的驱动程序,但默认使用普通 LaTeX,因为dvisvgm
在这种情况下不起作用。
由于某种原因,TikZ 将驱动程序改回dvips
。因此,您需要在加载 TikZ 后再次声明正确的驱动程序。您可以使用此配置文件执行此操作:
\makeatletter
\def\Gin@driver{dvisvgm.def}
\makeatother
\Preamble{xhtml}
\begin{document}
\EndPreamble
经过这些更改后,SVG 文件将包含您的 PNG 文件。但似乎出于某些安全原因,浏览器不会显示它。似乎有必要将<img>
标签更改为<embed>
。我们可以使用以下构建文件来做到这一点:
local domfilter = require "make4ht-domfilter"
local process = domfilter {
function(dom)
for _,img in ipairs(dom:query_selector("img")) do
-- change <img> tags to <embed> for SVG images
if img:get_attribute("src"):match("svg$") then
img._name = "embed"
end
end
return dom
end
}
Make:match("html$", process)
完成所有这些更改后,您可以使用以下命令编译文件:
make4ht -l -c config.cfg -e build.lua filename.tex
结果如下:
图片仍然不正确。在这种情况下,调整大小似乎无法正常工作。最后,我会将图片创建为单独的 PDF 文件,并将其包含在内,而不是进行这种复杂的设置。