# Experience using silence package with fontspec, luatex?

The following MWE does not work for me:

% !TeX program = LuaLaTeX
% !TeX encoding = UTF-8
\documentclass{minimal}
\RequirePackage{silence}
\ErrorFilter*{fontspec}{The}
\RequirePackage{fontspec}
\setmainfont{DoesNotExist}
\begin{document}
It was a dark and stormy night.
\end{document}


My objective to is to filter out the fontspec error message telling me that The font "DoesNotExist" cannot be found. Above, I used "The" as the only filter word, since I am not sure if fontspec is inerting non-breaking space in its messages. From the silence package documentation, I expect that the starred command will filter the error message during compilation. No joy.

Could it be that fontspec, or luatex, or the expl3 syntax used within fontspec.sty, is incompatible with silence? Or am I doing something wrong?

My ultimate objective is to catch the fontspec error for a particular font, and substitute my own error message that is more helpful (to me).

• That's a pretty heavy error, which I see reported by luaotfload, not fontspec. Aren't you looking for something more like LaTeX Font Warning: Font shape EU2/DoesNotExist... warning? – jon Oct 13 '16 at 2:06
• Hmm.. The error I get says that it is reported by fontspec (I can see it in the fontspec style file). However, it is quite possible that luaotfload is cooperating with fontspec there. Alas, I cannot easily decode what is happening in the style files. In any case: I found a workaround that doesn't answer my question, but minimally does what I need it to do. I can edit one of the macros in fontspec-luatex.sty, so that when it give the cannot find font message, it also says "If the missing font is DoesNotExist, see item 14.3 in the handout." Then attention is directed there. – user103221 Oct 13 '16 at 3:55
• Are you looking in the actual .log or working through the .sty files? I was just looking at the .log that results from your test file. (And, fontspec definitely relies on luaotfload: there'd be no fontspec for LuaTeX without it ... or at least a radically different fontspec.) – jon Oct 13 '16 at 4:19
• Didn't look in the log... Got caught up looking at the .sty files. Sometimes simple things are overlooked. I just went by the message that appeared in the console, which (in TeXworks) mentions fontspec rather than luaotfload. Or, if it does mention luaotfload, that message has disappeared from view by the time it is noticed. Task for tomorrow. – user103221 Oct 13 '16 at 5:21

The silence package does nothing at all with messages generated by fontspec, that uses the expl3 features for them.

The error message is

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


There is a simple redirection mechanism if you want to silence warning or error messages:

\documentclass{article}
\usepackage{fontspec}

\ExplSyntaxOn
\msg_redirect_name:nnn { fontspec } { font-not-found } { none }
\ExplSyntaxOff

\setmainfont{DoesNotExist}

\begin{document}

It was a dark and stormy night.

\end{document}


However, this will end up in a lower level error message:

! Font \EU2/DoesNotExist(0)/m/n/10=DoesNotExist:mode=node;+tlig; at 10pt not lo

• I tried the code above, which performs as described. But apparently \msg_redirect_name can only redirect to a class of results, such as warning or none. Ideally, I would like the redirect to go to a different error message, which I will define in expl3. so instead of none in the above code, the redirect would go to myown-error-message-macro which I can create by imitating the original expl3 code. The ordinary latex analogy is the renewcommand feature. – user103221 Oct 13 '16 at 20:07