33

What is the best way (most proper and general solution) to get rid of the warning

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

by explicitly setting which font should be used for particular family+series+shape combination in edited document?


Bold small-caps are not widely available font-wise. E.g. they are available in CM-Super (which the default font for T1 encoding), but not in overall better Latin Modern.

Let's say I use Latin Modern as the default font (\usepackage{lmodern}). What should be done to make LaTeX fallback to CM-Super in case of bold small caps? (And only in the case of bold small caps, medium small caps should remain typed using Latin Modern.)

przemoc
  • 2,142

2 Answers2

31

AFAIK you just need to declare that font shape using \DeclareFontShape. You can just declare the font shape to use the font shape of the standard font. This should lead to the same result as before just without the warning.

Using `lmodern` with `T1` font encoding you get the following warning with `\scshape\bfseries`:
LaTeX Font Warning: Font shape `T1/lmr/bx/sc' undefined
(Font)              using `T1/lmr/bx/n' instead on input line 19.

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

So you need to declare the font shape T1/lmr/bx/sc. As Ulrike pointed out you can substitute another font using the following code:

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{lmodern} \normalfont %to load T1lmr.fd 
\DeclareFontShape{T1}{lmr}{bx}{sc} { <-> ssub * cmr/bx/sc }{}

\begin{document}

{\normalfont normal font}
{\scshape small caps}
{\ttfamily tt family}
{\bfseries bold font}
{\scshape\bfseries bold small caps}% works and uses `cmr` font instead of `lmr`

\end{document}
Martin Scharrer
  • 262,582
  • 1
    Effort appreciated. It is good as it works for my exemplary case, but at the same time I cannot say I like it, because it requires checking and copying some stuff from .fd file, which I believe should be avoidable, as we're ultimately reusing family+series+shape already defined out there. – przemoc Jul 04 '11 at 01:14
  • Mmm, Adobe Acrobat Reader crashes with the above MWE when I try to display Properties->Fonts! pdffonts actually displays the fonts nicely, so does evince. – Martin Scharrer Jul 04 '11 at 01:15
  • Works in okular too, where I see shiny new SFXC1200. :-) – przemoc Jul 04 '11 at 01:22
  • @przemoc: There's nothing else to do in this case; the font you desire is not available in the Latin Modern family. If their developers don't add themselves such a substitution, it's impossible for LaTeX to define it by itself: no default substitution can be allowed to change the family. – egreg Jul 04 '11 at 08:10
  • 6
    You can use the sub (or ssub) function to declare the substituation: \usepackage{lmodern} \normalfont %to load T1lmr.fd \DeclareFontShape{T1}{lmr}{bx}{sc} { <-> ssub * cmr/bx/sc }{} – Ulrike Fischer Jul 04 '11 at 09:06
  • 1
    @Ulrike: Thank you! This is exactly what I was looking for and I believe this is the best solution. Could you "transform" your comment into separate answer? You can make it a bit more elaborate if you want. I will happily accept it after day or two. :-) – przemoc Jul 04 '11 at 09:29
  • 1
    Martin can include it in his answer. – Ulrike Fischer Jul 04 '11 at 09:46
  • @Martin: Please include Ulrike's solution in your answer in some spare time. I wouldn't bother you, but I cannot do it myself yet. Thanks in advance! – przemoc Jul 04 '11 at 18:27
  • @Martin: One more thing -- your disclaimer is rather no longer relevant. – przemoc Jul 06 '11 at 16:33
  • Can we apply this for T1/lmr/n/n? – alper Dec 14 '22 at 15:37
5

I was trying to use the technique from the previous comment, until I realised I was using a sans font and that the CM fonts dont have a 'sans serif' bold small caps...

To solve it, I used the helvet package which has them. There is an additional trick as you have to re-load the declaration for \sfdefault as \usepackage{helvet} overwrites it! Then it defaults to lmodern except for the sans small caps where you use helvet...

Just posting the code here in case it is useful to someone!

\documentclass[a4paper,11pt]{article}

\usepackage[T1]{fontenc}

\usepackage{lmodern}
\sffamily %to load T1lmss.fd 

% Load 'sans small caps' from helvet:
\usepackage{helvet}
\sffamily %to load T1phvss.fd 
% Substitute non-existing lmss/bx/sc with phv/bx/sc
\DeclareFontShape{T1}{lmss}{bx}{sc} { <-> ssub * phv/bx/sc }{}
% Can also pick the sans small caps:
\DeclareFontShape{T1}{lmss}{m}{sc} { <-> ssub * phv/m/sc }{}

% Use lmodern to override helvet:
\renewcommand{\rmdefault}{lmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}

\begin{document}

This is lmodern roman (lmr) -- default

{\sffamily This is lmodern sans (lmss)}

{\scshape This is small caps from lmodern (lmr)}

{\sffamily \scshape This is sans small caps from helvet (phv)}

{\sffamily \bfseries \scshape This is sans bold small caps from helvet (phv)}

\end{document}