My first question is, when exactly does LaTeX trigger a font warning? I suspect, it is in the moment when I request a font through \sffamily or \selectfont, correct?
This is why
\documentclass{article}
\begin{document}
\fontseries{book}\selectfont \fontseries{m}\selectfont Test
\end{document}
results in
LaTeX Font Warning: Font shape `OT1/cmr/book/n' undefined
(Font) using `OT1/cmr/m/n' instead on input line 4.
even though I need no single glyph of the book series I requested.
So with that knowledge my issue is, that in my document, I get a spurious font warning from the \tableofcontents, because bx series is not available in my loaded \sfdefault font and replaced with m instead. But no text element is typeset in that font, which is why I don't know where to start to look for it, but I suspect a definition I don't even use tries to select bx.
What way can you propose me to trace down where bx is requested and then not used? So this is not about only this problem, but more a question about a debugging technique. Is it e.g. possible to hook to \selectfont and let it print, when it was called and from which file?
Thanks for your help and hints and please let me know, if I need to clarify further.
Addition to clarify
Thank you very much for your comments so far. While I appreciate, that you want to look into my specific issue here, I am really more eager to learn, how to debug myself. So here is a MWE that illustrates the issue a bit better:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{mycommand.tex}
\newcommand{\MyCommand}[1]{{\fontseries{seriesthatdoesnotexist}\selectfont \fontseries{m}\selectfont #1}}
\end{filecontents}
\input{mycommand.tex}
\begin{document}
\MyCommand{Test}
\end{document}
Imagine mycommand.tex is not that obviously laoded, but is in the documentclass, a package or wherever. But when you see the font warning in the log, it reads:
LaTeX Font Warning: Font shape `OT1/cmr/seriesthatdoesnotexist/n' undefined
(Font) using `OT1/cmr/m/n' instead on input line 11.
From other programming or scripting languages I am used to have a debugger that can step through my code, or set breakpoints, as well as the possibility to see a trace of all calls that have been made before.
In this case LaTeX leaves me with an issue in line 11, that I cannot understand, if I don't know where and how \MyCommand has been defined.
Is it actually possible to get a trace to the place of the command that actually caused the issue or the place where a command was defined? So in this case, is there a way to lead me to mycommand.tex?
I hope this addition clarifies, what I am looking for, which is a debugging technique and not a solution for the font substitution problem.
A MWE that illustrates the problem in the real world:
\documentclass[]{scrbook}
\usepackage[scaled]{uarial}
%%%%\setkomafont{disposition}{\normalfont} %solves the issue
\setkomafont{chapter}{\normalfont\Large\selectfont}
\begin{document}
\tableofcontents
\end{document}
It took me some more time, but here is a MWE in the real world. The chapter font is normally \sffamily\bfseries, but even if you overwrite it, it is still selected, because the komafont disposition is used before. Now the line \setkomafont{disposition}{\normalfont} fixes the issue, but how can this be traced and debugged, without this knowledge?
fooordoesnotexist. What I wanted to illustrate is, that loading a font already results in a font warning, even though it is not used. In my specific document I am looking for the location where this warning is thrown, but I can only trace it down to the\tableofcontentscommand, this is why I suspect, that my document class selects a font shape through\selectfontand then loads another one before actually writing something. – TobiBS Jun 22 '20 at 14:25\def\foo{\def\foo{something else}}, the redefinition would happen when\foois first called. – egreg Jun 22 '20 at 16:12