xdanaux / fontawesome-latex

LaTeX mappings for Font Awesome, the icons font
300 stars 36 forks source link

Fix fontspec's font-not-found error on XeLaTeX #16

Open yudai-nkt opened 6 years ago

yudai-nkt commented 6 years ago

TL;DR: XeTeX cannot load fonts in TEXMF tree by their font name whereas LuaTeX can. Therefore we need to specify FontAwesome by file name so that both XeTeX and LuaTeX can load it.


Consider the following MWE:

\documentclass{article}
\usepackage{fontawesome}
\begin{document}
\faAdjust
\end{document}

While this MWE works with LuaLaTeX, it doesn't with XeLaTeX issuing the following error:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "FontAwesome" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.45 \newfontfamily{\FA}{FontAwesome}

The reason for this pretty easy; it's clearly described in the fontspec documentation. Here is an excerpt from section 5.2 of v2.6d:

Fonts in such locations are visible to XeTeX but cannot be loaded by font name, only file name; LuaTeX does not have this restriction.

There are several ways to load fonts by file name, and I specified the extension .otf in the optional argument because this is convenient when we load bold and italic variants of a font (FontAwesome doesn't have variants, though).

Fix #12.

dropsonic commented 5 years ago

Please merge it. I had the same issue with this package and had to create my own "fixed" version of it.

yudai-nkt commented 5 years ago

@dropsonic FYI: You can give a try to fontawesome5 if you don't like putting the fixed fork in your TEXMFHOME or TEXMFLOCAL. I don't really look into the package, but at least

\documentclass{article}
\usepackage{fontawesome}
\begin{document}
\faAdjust
\end{document}

works well with XeLaTeX.