latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.94k stars 267 forks source link

Many warnings about reguler to m series substitution as corollary from loading main font using regular not m in its font definition file #1240

Closed jfbu closed 10 months ago

jfbu commented 10 months ago

Brief outline of the bug

In my real life example I observed this after replacing the Roman family font to be provided by Clara (\usepackage{clara} with pdflatex): (forgot to say line numbers from grep of course)

1391:LaTeX Font Warning: Font shape `T1/txss/regular/n' undefined
1401:LaTeX Font Warning: Font shape `T1/txtt/regular/n' undefined
1418:LaTeX Font Warning: Font shape `T1/txss/regular/sc' undefined
1530:LaTeX Font Warning: Font shape `T1/txss/regular/sl' undefined
1592:LaTeX Font Warning: Font shape `T1/txtt/regular/sl' undefined
1613:LaTeX Font Warning: Font shape `TS1/txss/regular/n' undefined
1683:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1691:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1734:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1805:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1810:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1827:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1832:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
1892:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
2107:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
2159:LaTeX Font Warning: Font shape `T1/txss/regular/it' undefined
2731:LaTeX Font Warning: Some font shapes were not available, defaults substituted.

This is a bit noisy and distracting especially when one cares about Warnings (in some contexts in other programming languages people compile with a flag "treat warning as error" which is not realistic in LaTeX).

The triggering event seems to have been this:

LaTeX Font Info:    Font shape `T1/Clara-TLF/m/n' aliased to
(Font)              `T1/Clara-TLF/regular/n' on input line 1414.

MWE:

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{txfonts}
\usepackage{clara}
\AtBeginDocument{%
    \renewcommand{\familydefault}{\sfdefault}%
    \rmfamily
}
\begin{document}
\section{Hello}

World.
\end{document}
LaTeX Font Warning: Font shape `T1/txss/regular/n' undefined
(Font)              using `T1/txss/m/n' instead on input line 11.

Log file (required) and possibly PDF file

testclara.log

u-fischer commented 10 months ago

Well as latexbug tells you:

! Package latexbug Error: Third-party file(s)
(latexbug)                
(latexbug)                This test file uses third-party file(s)
(latexbug)                
(latexbug)                ==============
(latexbug)                txfonts.sty
(latexbug)                clara.sty
(latexbug)                t1clara-tlf.fd
(latexbug)                ==============
(latexbug)                
(latexbug)                So you should contact the authors
(latexbug)                of these files, not the LaTeX Team!
(latexbug)                (Or remove the packages that load
(latexbug)                them, if they are not necessary to
(latexbug)                exhibit the problem).

The bug is in the clara package which uses non-standard font series names (regular and bold instead of m and b or bx) and redefines \mdseries@rm and \bfseries@rm.

jfbu commented 10 months ago

Thanks, to explain: it was not clear to me upfront that font packages would modify internals. I did check the fd file globally and noticed usage of regular there, and I figured the LaTeX font system sort of automatically had switched from m to regular (as one of possible aliases to try?) and was then after the fact complaining as I reported, from having toggled perhaps to some other "internal state". Yes I was perhaps too quick to be happy to have found a likely culprit. As I thought these fd files are produced semi-automatically by the authors of pdflatex font support files working from an OpenType starting point, confirmed from seeing

%% Generated by autoinst on 2019/12/24
%%

at top of T1Clara-TLF.df I did not imagine a problem existed inside of clara.sty as it would then by force be a probably widespread one.

FrankMittelbach commented 10 months ago

I doubt that Clara is a widespread font, but be it as it may, autoinst got through a lot of revisions and 2019 is rather old in that respect. In any case the way the font is set up is incorrect and if you switch fonts you end up with asking for others fonts using a series "regular" which they don't understand, hence the substitution kicks in and you get all the warnings. In other words the font (and the support package) by itself works but if you then switch to a different font (e.g. txss) then that one doesn't know what to make of the non-standard name "regular" or "bold". So it is not noisy, it shows that something is wrong and while the substituation txss/regular/n ends up with the right font txss/m/n by chance, txss/regular/it ends up withe the wrong font after substitution.

As we do not control or maintain external font support packages, I'm closing this one here.

jfbu commented 10 months ago

I do not understand the reason why clara.sty redefines \bfseries@rm and \mdseries@rm as its T1Clara-TLF.fd does all the \DeclareFontShape aliasing {b,bx}-->bold and m-->regular where bold and regular are used in the primary \DeclareFontShape's. Anyway for people seeing this

\usepackage{clara}
\makeatletter
\def\bfseries@rm{bx}
\def\mdseries@rm{m}
\makeatother

is work-around for this non-LaTeX2e problem.