# Microtype's \textls{}' and '\lsstyle' seem to break the icons from Fontawesome5

Sometimes I use the fontawesome5 icons in a block of text set in all uppercase. When I do this I'll letterspace that text with microtype's \textls{} or \lsstyle (depending on the macro) to increase readability. This breaks the icons, in that they are not displayed in the final output. A minimal working (broken) example is given below.

As you can see, the icons aren't affected by bold or italic conversions. The sizing commands (\small, \large etc.) also make no difference — I didn't included them in the MWE to keep it small.

This problem doesn't exist if I use the fontawesome package, which loads the fontawesome 4.x set of icons.

With fontawesome5 i get the following error:

...standalone.cls:18: Missing number, treated as zero. [\textls{Hello \faGlobe}]


I get the following warning when compiling with both fontawesome and fontawesome5:

...standalone.cls: Package microtype Warning: Unknown slot number of character(microtype)                \A'(microtype)                in font encoding TU' in inheritance list(microtype)


Any idea what is happening or where am I going wrong here?

MWE

%!TEX program = lualatex
\documentclass[varwidth]{standalone}
\usepackage{fontawesome5}
\usepackage{microtype}

\begin{document}

Hello \faGlobe

\textbf{Hello \faGlobe}

{\bfseries Hello \faGlobe}

\textit{Hello \faGlobe}

{\itshape Hello \faGlobe}

\textls{Hello \faGlobe}

{\lsstyle Hello \faGlobe}

\end{document}


Output

## 1 Answer

microtype has to use a different technique to letterspace OpenType fonts than to letterspace legacy fonts. Therefore, it has to know for every font if it is a legacy font, but this detection currently assumes that all OpenType fonts are loaded though fontspec. Now fontawesome5 does not use fontspec, even when using the OpenType fonts in LuaTeX, so this detection fails and the attempt to add legacy letterspacing breaks the font.

This has to be fixed in microtype, but for the time being you can replace the detection code as a workaround:

%!TEX program = lualatex
\documentclass[varwidth]{standalone}
\usepackage{fontawesome5}
\usepackage{iftex}
\usepackage{microtype}
% Fixup microtype's OpenType font detection
\makeatletter
\ifxetex
\def\MT@if@fontspec@font{%
\ifnum\XeTeXfonttype\font=0
\expandafter\@secondoftwo
\else
\expandafter\@firstoftwo
\fi
}
\fi
\ifluatex
\def\MT@if@fontspec@font{%
\directlua{tex.sprint(token.create(function()
local f = font.getfont(font.current())
if not f then return false end
if f.encodingbytes then return f.encodingbytes == 2 end
return f.format and f.format:sub(5) == 'type'
end and '@firstoftwo' or '@secondoftwo'))
}%
}
\fi
\makeatother
\begin{document}

Hello \faGlobe

\textbf{Hello \faGlobe}

{\bfseries Hello \faGlobe}

\textit{Hello \faGlobe}

{\itshape Hello \faGlobe}

\textls{Hello \faGlobe}

{\lsstyle Hello \faGlobe}

\end{document}


• Why tex.sprint instead of token.put? – Henri Menke Jun 2 '20 at 10:22
• @HenriMenke It didn't matter and I thought that tex.sprint is better known than token.put_next, so it might make the code slightly easier to understand for some people. – Marcel Krüger Jun 2 '20 at 10:28
• Perfection, @MarcelKrüger. Thanks – tmgriffiths Jun 2 '20 at 23:11
• does the microtype author know about it? – Ulrike Fischer Jun 7 '20 at 15:36
• @UlrikeFischer Yes. He currently uses a slightly different fix, so the next microtype version will include one of the two solutions. – Marcel Krüger Jun 7 '20 at 16:04