tex4ht、缺少 TFM 文件以及“make4ht -l”

tex4ht、缺少 TFM 文件以及“make4ht -l”

我在使用 make4ht/tex4ht 识别字体时遇到了问题。

$ make4ht --version
make4ht version v0.3g
$ lualatex --version
This is LuaHBTeX, Version 1.13.0 (TeX Live 2021/Cygwin)
$ kpsewhich awesomebox.4ht
/usr/share/texmf-dist/tex/generic/tex4ht/awesomebox.4ht

梅威瑟:

$ cat mwe.tex
\documentclass[letterpaper, 10pt]{article}
\usepackage{awesomebox}

\begin{document}
Paragraph\notebox{TeX is Awesome!}
\end{document}

结果:

$ make4ht -l mwe
...
--- error --- Can't find/open file `[/usr/share/texmf-dist/fonts/opentype/public/fontawesome5/FontAwesome5Free-Solid-900.otf].tfm'
[FATAL]   make4ht-lib: Fatal error. Command tex4ht returned exit code 1

有人能指点我如何修复这个问题吗?我以为 tex4ht 支持 OTF。

答案1

不幸的是,TeX4ht 不支持 OpenType 字体。它们需要受到保护以防止加载,否则您将收到此致命错误。幸运的是,在这种情况下找到解决方法并不难。我们只需要破解fontawesome5包以防止加载 OpenType 字体并改为加载 Type 1 字体。我们可以使用特殊配置文件来完成此任务。

第一个文件是fontawesome5-utex-helper-hooks.4ht

\:dontusepackage{fontawesome5-utex-helper}
\RequirePackage{fontawesome5-generic-helper}

它禁用 OpenType 字体的加载,而是加载 Type 1 字体。

有一个问题我花了很长时间才搞明白。我array.sty使用此补丁时遇到了编译错误。原来:是角色的 catcode 错误。所以我们需要另一个补丁文件,fontawesome5-hooks.4ht

\:AtEndOfPackage{\catcode`\:=12}

它只是在加载后将catcode 重置:为正常。fontawesome5

然后我们需要告诉 TeX4ht 加载这些文件。需要在 usepackage.4ht文件中进行操作:

% usepackage.4ht (2021-02-07-14:58), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2021 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 2021-02-07-14:58}

   \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}{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}{biblatex.sty}{biblatex-hooks.4ht}
\Configure{PackageHooks}{xeCJK.sty}{xecjk-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}{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}{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}{fontawesome5-utex-helper.sty}{fontawesome5-utex-helper-hooks.4ht}
\Configure{PackageHooks}{fontawesome5.sty}{fontawesome5-hooks.4ht}



\endinput

通过这样的改变,你会得到正确的结果:

在此处输入图片描述

我们不必止步于此。我们可以添加对所有 FontAwesome 图标的支持。我们只需要告诉 TeX4ht 将它们转换为图片。这可以使用以下文件完成fontawesome5.4ht

\NewConfigure{fontawesome}{2}
\ExplSyntaxOn
\cs_new_protected:Nn\temp:nn{%
\a:fontawesome%
\o:fontawesome_use_icon:nn:{#1}{#2}
\b:fontawesome}

\HLet\fontawesome_use_icon:nn\temp:nn
\ExplSyntaxOff
\Configure{fontawesome}{\Picture+{}}{\EndPicture}
\Hinput{fontawesome5}
\endinput

你可以用一个样本来测试它:

\documentclass{article}
\RequirePackage{fontawesome5}
\begin{document}

Hello \faDrum\faDemocrat\faDizzy

\end{document}

在此处输入图片描述

我将更新 TeX4ht 源,因此这些更改很快就会在 TeX Live 中可用。

相关内容