TransWikia.com

tex4ht, missing TFM files, and "make4ht -l"

TeX - LaTeX Asked on May 16, 2021

I’m having a problem with make4ht/tex4ht identifying fonts.

$ 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

MWE:

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

begin{document}
Paragraphnotebox{TeX is Awesome!}
end{document}

Results:

$ 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

Can someone please point me in the right direction to fix this? I thought tex4ht supported OTF.

One Answer

TeX4ht unfortunately doesn't support OpenType fonts. They need to be protected from loading, otherwise you'll get this fatal error. Fortunately, it is not hard to get a work-around in this case. We just need to hack fontawesome5 package from loading OpenType fonts and to load Type 1 fonts instead. We can use special configuration files for this task.

The first file is fontawesome5-utex-helper-hooks.4ht:

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

It disables loading of the OpenType fonts and loads Type 1 fonts instead.

There is one issue that took me quite some time to understand. I've got compilation error from array.sty with this patch. It turned out that the : character had wrong catcode. So we need another patch file, fontawesome5-hooks.4ht:

:AtEndOfPackage{catcode`:=12}

It just resets catcode of : back to normal after fontawesome5 had been loaded.

Then we need to tell TeX4ht to load these files. It needs to be done in the usepackage.4ht file:

% 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.
immediatewrite-1{version 2021-02-07-14:58}

   def:temp{tex4ht}ifx :temp@currname
   :warning{stringusepackage{tex4ht} again?}
   def:temp#1htex4ht.def,tex4ht.sty#2!*?: {def:temp{#2}}
expandafter:temp @filelist htex4ht.def,tex4ht.sty!*?: %
ifx :tempempty  else
   :warning{if
    stringRequirePackage[tex4ht]{hyperref} or
    stringusepackage[tex4ht]{hyperref} was
    used try instead, repectively,
    stringRequirePackage{hyperref} or
    stringusepackage{hyperref}}
fi

fi
gdefa:usepackage{use:package ,!*?: }
gdefuse: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

With this change, you will get the correct result:

enter image description here

We don't need to stop here. We can add support for all FontAwesome icons. We just need to tell TeX4ht to turn them to pictures. This can be done using following file, fontawesome5.4ht:

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

HLetfontawesome_use_icon:nntemp:nn
ExplSyntaxOff
Configure{fontawesome}{Picture+{}}{EndPicture}
Hinput{fontawesome5}
endinput

You can test it with a sample:

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

Hello faDrumfaDemocratfaDizzy

end{document}

enter image description here

I will update TeX4ht sources, so these changes should be available in TeX Live soon.

Correct answer by michal.h21 on May 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP