2

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?

TobiBS
  • 5,240
  • Warnings tel you that font series "book" doesn't exist. See https://tex.stackexchange.com/questions/68745/possible-values-for-fontseries-and-fontshape – Zarko Jun 22 '20 at 14:21
  • @Zarko this was on purpose, I could write foo or doesnotexist. 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 \tableofcontents command, this is why I suspect, that my document class selects a font shape through \selectfont and then loads another one before actually writing something. – TobiBS Jun 22 '20 at 14:25
  • 2
    You are requesting a font combination that doesn't exist; the warning is issued at font selection time: it's not possible to wait until a character is typeset.. Possibly the warning might say “selecting” instead of “using”, but usually people uses the font they tried to select. Can you please show a short example of code that triggers the warning you're receiving? – egreg Jun 22 '20 at 14:40
  • Have you seen the site guidelines for preparing a MWE (minimal working example): https://tex.meta.stackexchange.com/questions/228/ive-just-been-asked-to-write-a-minimal-working-example-mwe-what-is-that ? These guidelines are also good for a debugging technique. In summary: gradually remove document content, then packages, or alternatively start from an empty document and gradually add things back in; and in either case, note at what stage the error disappears/reappears, and try to cut things down to a minimal example document triggering the error. – Peter LeFanu Lumsdaine Jun 22 '20 at 15:10
  • @egreg thanks for this information, this confirms my analysis from above. If it would be that simple in this case, I would have brought up the actual problem in a MWE. But I am still looking for a way to achieve this and I am in general more interested in a general debugging approach for LaTeX similar to other languages. – TobiBS Jun 22 '20 at 15:38
  • @PeterLeFanuLumsdaine my first MWE triggers the warning already, but is of course easy to debug. However I added two more MWEs, including solutions (because I know the issue behind the scenes), but again I would like to learn the debugging technique, this is why I opened this question. – TobiBS Jun 22 '20 at 16:11
  • @TobiBS You can't ask TeX where a command was defined: the information is not stored anyway, for the simple reason that a command can be redefined everywhere, including the command itself: with \def\foo{\def\foo{something else}}, the redefinition would happen when \foo is first called. – egreg Jun 22 '20 at 16:12

0 Answers0