我是一家中型公司的员工,目前正在尝试使用 Latex 编写技术文档(请参阅在我们公司实施 Latex)。
我们的大多数文件都需要翻译成多种语言,这项工作由翻译机构完成。为了完成这项任务,他们通常使用 Trados Studio。但是,该程序不支持 .tex 格式的文档。
但是,它支持 .html 格式。由于我使用的是 TexStudio(与 Tex Live 一起使用),所以我能够将 .tex 文档转换为 .html 格式(使用“工具”->“将源转换为 Html”)。这会创建一个文档,在记事本中打开时可以显示 Html 代码,但如果在 Web 浏览器中打开它,则会显示 .tex 代码。
但是,创建的文档与 Trados Studio 不兼容。
我的问题是:
我该如何解决这个问题?问题在于创建的 .HTML 文档没有“正确”转换(当使用 Html 验证器检查创建的 Html 文档时,会弹出一些错误)。
如果这种转换为 .html 文档的方法不是使用 Trados Studio 进行翻译的最佳方法,您建议采用哪种替代方法?
请注意,我们的典型文档大约有 100 页,而且数量庞大,因此我们优先选择不耗时的解决方案。
编辑:我使用了 make4ht -l filename.tex,而最小化的示例(可能是我遗漏了一些东西)是:
% !TeX program = lualatex
% !TeX encoding = UTF-8 Unicode
% !TeX spellcheck = de_DE
\documentclass[10pt,a4paper,twoside]{report}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,251.5mm}, %default je 150mm,237mm
outer=15mm,
inner=20mm,
top=25mm}
\usepackage{fontspec}
\setmainfont{Arial}
\usepackage{titlesec}
\usepackage[most]{tcolorbox}
\newtcolorbox{warning}[1][width=171.375mm, center]{%
enhanced jigsaw, %engine za risanje zahtevnejsih okvirjev
enlarge top initially by=3mm, %presledek pred okvirjem
enlarge bottom finally by=3mm, %presledek za okvirjem
borderline={3.5pt}{-5pt}{black}, %to je dodaten okvir
sharp corners, %kaksni so vogali
fonttitle=\bfseries, %NASLOV v krepkem
title=WARNUNG!, %ime naslova
coltitle=black, %font naslova crne barve
colbacktitle={white!80!gray}, %ozadje naslova sivo
halign title=center, %naslov centriran--------------------
fontupper=\bfseries, %besedilo warninga je v krepkem
halign=flush center, %upper (sredinski) part centriran, ALTERNATIVA: UKAZ CENTER
halign lower=right, %lower (spodnji) part poravnan desno
colframe=black, %barva okvirja
colback={white!80!gray}, %barva ozadja upper in lower part----
lower separated=false, %crta ki locuje
fontlower=\tiny, %font rms in številke
middle=0mm, %minimalen razmik med upper in lower part
bottom=0mm, %minimalen razmik med lower part in okvirjem
%breakable, %ce bi hoteli da se prelomijo cez strani.
#1
}
\newtcolorbox{caution}[1][]{%
enhanced jigsaw, %engine za risanje zahtevnejsih okvirjev
enlarge top initially by=1.5mm, %presledek pred okvirjem
enlarge bottom finally by=1.5mm, %presledek za okvirjem
% borderline={0pt}{0pt}{black}, %to je dodaten okvir
sharp corners, %kaksni so vogali
fonttitle=\bfseries, %NASLOV v krepkem
title=ACHTUNG!, %ime naslova
coltitle=black, %font naslova crne barve
colbacktitle={white!80!gray}, %ozadje naslova sivo
halign title=center, %naslov centriran--------------------
fontupper=\bfseries, %besedilo warninga je v krepkem
halign=flush center, %upper (sredinski) part centriran
halign lower=right, %lower (spodnji) part poravnan desno
colframe=black, %barva okvirja
colback={white!80!gray}, %barva ozadja upper in lower part----
lower separated=false, %crta ki locuje
fontlower=\tiny, %font rms in številke
middle=0mm, %minimalen razmik med upper in lower part
bottom=0mm, %minimalen razmik med lower part in okvirjem
%fontupper={\setlength{\parindent}{20pt}},
#1
}
\newtcolorbox{note}[1][]{%
enhanced jigsaw, %engine za risanje zahtevnejsih okvirjev
enlarge top initially by=1.5mm, %presledek pred okvirjem
enlarge bottom finally by=1.5mm, %presledek za okvirjem
% borderline={0pt}{0pt}{black}, %to je dodaten okvir
sharp corners, %kaksni so vogali
% fonttitle=\bfseries, %NASLOV v krepkem
title=HINWEIS, %ime naslova
coltitle=black, %font naslova crne barve
colbacktitle=white, %ozadje naslova sivo
halign title=center, %naslov centriran--------------------
% fontupper=\bfseries, %besedilo warninga je v krepkem
halign=flush center, %upper (sredinski) part centriran
halign lower=right, %lower (spodnji) part poravnan desno
colframe=black, %barva okvirja
colback=white, %barva ozadja upper in lower part----
lower separated=false, %crta ki locuje
fontlower=\tiny, %font rms in ?tevilke
middle=0mm, %minimalen razmik med upper in lower part
bottom=0mm, %minimalen razmik med lower part in okvirjem
%fontupper={\setlength{\parindent}{20pt}},
#1
}
\usepackage[a-2b]{pdfx}
\usepackage{hyperref}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\newcommand{\fullref}[1]{\hyperref[#1]{\ref*{#1}\ \nameref*{#1}}}
\renewcommand{\figureautorefname}{Abbildung}
\usepackage{lastpage}
\usepackage{fancyhdr}
\def\cnvjobname{\expandafter\cnvjobnameA\jobname\relax}
\def\cnvjobnameA#1{\ifx\relax#1\else
\ifx?#1: \else \expandafter\ifx\string_#1 \else #1\fi\fi
\expandafter\cnvjobnameA\fi
}
\newcommand*{\setmyjobname}{%
\edef\myjobname{\cnvjobname}%
\expandafter\expandafter\expandafter\setmyjobnameaux
\expandafter\myjobname\expandafter"\myjobname"\relax
}
\newcommand*{\setmyjobnameaux}{}
\def\setmyjobnameaux#1"#2"#3\relax{\def\myjobname{#2}}
\setmyjobname
\pagestyle{fancy}
\fancyhf{}
\fancyhead[LE,RO]{\includegraphics*[height=0.6cm]{example-image-b}}
\renewcommand{\figurename}{Abbildung}
\renewcommand{\tablename}{Tabelle}
\newcommand{\cell}{\parbox[t]{20cm}\seqsplit}
\begin{document}
something
\end{document}
答案1
如果您使用的是最新的 TeX Live,则 MWE 存在两个问题。第一个是 PDFX 包导致的致命错误,第二个是 Hyperref 导致的致命错误。
一般情况下,当您使用 TeX4ht 转换文档时,应避免使用仅在 PDF 模式下有效的包,因为它在 DVI 模式下运行。这可能会导致仅通过加载包就出现致命错误。
有两种方法可以禁用该软件包。第一种方法是编辑文档并有条件地包含软件包。例如,可以使用以下命令完成此操作:
\ifdefined\HCode\else
\usepackage[a-2b]{pdfx}
\fi
第二种方法是更改包的 TeX4ht 配置文件。我们有特殊的文件,它们在包之前加载,因此可以禁用包加载。首先,我们必须在 中声明这样的文件usepackage.4ht
:
\def\:temp{tex4ht}\ifx \:temp\@currname
\:warning{\string\usepackage{tex4ht} again?}
\def\:temp#1htex4ht.def,tex4ht.sty#2!*?: {\def\:temp{#2}}
\expandafter\:temp \@filelist htex4ht.def,tex4ht.sty!*?: %
\ifx \:temp\empty \else
\:warning{if
\string\RequirePackage[tex4ht]{hyperref} or
\string\usepackage[tex4ht]{hyperref} was
used try instead, repectively,
\string\RequirePackage{hyperref} or
\string\usepackage{hyperref}}
\fi
\fi
\gdef\a:usepackage{\use:package ,!*?: }
\gdef\use:package#1,{%
\if :#1:\def\:temp##1!*?: {}\else
\def\:temp{#1}\ifx \@currname\:temp
\def\:temp##1!*?: {\input usepackage.4ht }%
\else \let\:temp=\use:package \fi
\fi \:temp}
\Configure{PackageHooks}{biblatex-chicago.sty}{biblatex-chicago-hooks.4ht}
\Configure{PackageHooks}{cleveref.sty}{cleveref-hooks.4ht}
\Configure{PackageHooks}{xr.sty}{xr-hooks.4ht}
\Configure{PackageHooks}{xr-hyper.sty}{xrhyper-hooks.4ht}
\Configure{PackageHooks}{eso-pic.sty}{esopic-hooks.4ht}
\Configure{PackageHooks}{showframe.sty}{showframe-hooks.4ht}
\Configure{PackageHooks}{expl3.sty}{expl3-hooks.4ht}
\Configure{PackageHooks}{savetrees.sty}{savetrees-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{newcomputermodern.sty}{newcomputermodern-hooks.4ht}
\Configure{PackageHooks}{fontawesome5-utex-helper.sty}%
{fontawesome5-utex-helper-hooks.4ht}
\Configure{PackageHooks}{fontawesome5.sty}{fontawesome5-hooks.4ht}
\Configure{PackageHooks}{biblatex.sty}{biblatex-hooks.4ht}
\Configure{PackageHooks}{xeCJK.sty}{xecjk-hooks.4ht}
\Configure{PackageHooks}{unicode-math.sty}{unicode-math-hooks.4ht}
\Configure{PackageHooks}{ctex.sty}{ctex-hooks.4ht}
\Configure{PackageHooks}{polyglossia.sty}{polyglossia-hooks.4ht}
\Configure{PackageHooks}{fontspec.sty}{fontspec-hooks.4ht}
\Configure{PackageHooks}{tikz.sty}{tikz-hooks.4ht}
\Configure{PackageHooks}{pdfbase.sty}{pdfbase-hooks.4ht}
\Configure{PackageHooks}{pdfx.sty}{pdfx-hooks.4ht}
\Configure{PackageHooks}{breakurl.sty}{breakurl-hooks.4ht}
\Configure{PackageHooks}{hyperref.sty}{hyperref-hooks.4ht}
\Configure{PackageHooks}{caption.sty}{caption-hooks.4ht}
\Configure{PackageHooks}{minted.sty}{minted-sty-hooks.4ht}
\Configure{PackageHooks}{graphics.sty}{graphics-hooks.4ht}
\Configure{PackageHooks}{graphbox.sty}{graphbox-hooks.4ht}
\Configure{PackageHooks}{xcolor.sty}{xcolor-hooks.4ht}
\Configure{PackageHooks}{imakeidx.sty}{imakeidx-hooks.4ht}
\Configure{PackageHooks}{fancyhdr.sty}{fancyhdr-hooks.4ht}
\Configure{PackageHooks}{exerquiz.sty}{exerquiz-hooks.4ht}
\Configure{PackageHooks}{hyperxmp.sty}{hyperxmp-hooks.4ht}
\Configure{PackageHooks}{datetime2.sty}{datetime2-hooks.4ht}
\endinput
重要的一行是:
\Configure{PackageHooks}{pdfx.sty}{pdfx-hooks.4ht}
这声明了该pdfx-hooks.4h
文件:
\:dontusepackage{pdfx}
\endinput
阻止\:dontusepackage
包加载,防止 PDFX 出现致命错误。
然后出现 Hyperref 错误,由以下行引起:
\renewcommand{\figureautorefname}{Abbildung}
问题在于\figureautorefname
在 的末尾定义hyperref.sty
,但 Hyperref 检测到 TeX4ht,并提前停止加载,因此此命令未定义。我们可以通过将 autoref 标题从 复制到hyperref.sty
来修复它hyperref-hooks.4ht
:
\:AtEndOfPackage{%
\@ifpackageloaded{nameref}{}
{%
\RequirePackage{ifthen}%
\let\sv:label\label
\RequirePackage{nameref}%
\let\label\sv:label
%\input nameref.4ht
}
\providecommand*\AMSautorefname{\equationautorefname}
\providecommand*\Hfootnoteautorefname{\footnoteautorefname}
\providecommand*\Itemautorefname{\itemautorefname}
\providecommand*\itemautorefname{item}
\providecommand*\equationautorefname{Equation}
\providecommand*\footnoteautorefname{footnote}
\providecommand*\itemautorefname{item}
\providecommand*\figureautorefname{Figure}
\providecommand*\tableautorefname{Table}
\providecommand*\partautorefname{Part}
\providecommand*\appendixautorefname{Appendix}
\providecommand*\chapterautorefname{chapter}
\providecommand*\sectionautorefname{section}
\providecommand*\subsectionautorefname{subsection}
\providecommand*\subsubsectionautorefname{subsubsection}
\providecommand*\paragraphautorefname{paragraph}
\providecommand*\subparagraphautorefname{subparagraph}
\providecommand*\FancyVerbLineautorefname{line}
\providecommand*\theoremautorefname{Theorem}
\providecommand*\pageautorefname{page}
}
完成这些更改后,您的文档应该可以顺利编译。您可以更新 TeX Live 发行版,因为这些更改已在此处更新。