# How to specify an arbitrary (possibly non-integer) font size in LaTeX

I may be wrong, but it seems to me that I cannot obtain non-integer (or non-preloaded) font sizes (say, 9.876pt) using \fontsize. If this is true, how do I do this in LaTeX? Do I have to resort to the \font ... at ... primitive?

(The reason I need this is that I'd like to implement a more LaTeXy way to do the \diminuendo macro from http://tug.org/texshowcase/.)

-
This is closely related to tex.stackexchange.com/questions/47160/… –  David Carlisle Mar 10 '12 at 12:42
That's true (I didn't find that one), although it might make sense keeping this question in case someone needs it (and then he can find the link you mentioned). –  mbork Mar 10 '12 at 12:45

You can specify arbitrary non-integer font sizes using \fontsizes so you are mistaken ;-). But in order to work two things need to be true as well:

• the font in use needs to be available in the size you request (what that means in a minute)
• LaTeX must know that the font exists in the requested size.

If the first requirement is false you are out of luck and the only way to resolve things is by using scaling as suggested in Getting a larger font (NOT \fontsize)? or a combination of \fontsizeand scaling.

However, if it is simply the problem that LaTeX doesn't know about the available sizes then you can correct this by changing your NFSS (New Font Selection Scheme) setup.

## Example:

We use a large size 39.976pt so that we can easily spot issues:

\documentclass{article}

\begin{document}

\fontsize{39.876}{42}\selectfont      Test CM

\fontfamily{ppl}\selectfont                Test ppl

\showoutput
\end{document}


If we run this through LaTeX we will get

We can see that Computer Modern comes out much smaller than Palatino (the second font selected).

We also get a warning:

LaTeX Font Warning: Size substitutions with differences
(Font)              up to 14.996pt have occurred.


which shows that at least one font was "off" by nearly 15pts (that's the CM font) and if we look at the details provided by the \showoutput command we see lines like

....\OT1/cmr/m/n/24.88 T
....\kern-1.94974
....\OT1/cmr/m/n/24.88 e
....\OT1/cmr/m/n/24.88 s
....\OT1/cmr/m/n/24.88 t
....\glue 7.51096 plus 3.89944 minus 2.59964
....\OT1/cmr/m/n/24.88 C
....\OT1/cmr/m/n/24.88 M
....\penalty 10000
....\glue(\parfillskip) 0.0 plus 1.0fil
....\glue(\rightskip) 0.0
...\glue(\parskip) 0.0 plus 1.0
...\glue(\baselineskip) 12.95067
...\hbox(29.04933+11.24483)x345.0, glue set 190.71533fil
....\hbox(0.0+0.0)x15.0
....\OT1/ppl/m/n/39.876 T
....\kern-3.66829
....\OT1/ppl/m/n/39.876 e
....\OT1/ppl/m/n/39.876 s
....\OT1/ppl/m/n/39.876 t
....\glue 9.969 plus 5.98138 minus 2.39249
....\OT1/ppl/m/n/39.876 p
....\OT1/ppl/m/n/39.876 p
....\OT1/ppl/m/n/39.876 l


which shows that LaTeX has selected a font in 24.88 for Computer Modern Roman (cmr) but also that it used the requested size for Palatino (ppl).

## Explanation

The reason for this difference in behavior is the way the two fonts have been made known to LaTeX. In case of Palatino it is a single Type 1 font and LATeX is requested to scale it to any size as needed. But in case of Computer Modern Roman, LaTeX was told that there are different real fonts for different sizes and that onely a defined set of sizes are available.

The two definitions (from the files ot1ppl.fd and ot1cmr.fd) are

\DeclareFontShape{OT1}{ppl}{m}{n}{<-> pplr7t}{}

\DeclareFontShape{OT1}{cmr}{m}{n}%
{<5><6><7><8><9><10><12>gen*cmr%
<10.95>cmr10%
<14.4>cmr12%
<17.28><20.74><24.88>cmr17}{}


and this difference explains the different behavior.

## Resolution

In case of Computer Modern there are in fact different real fonts available specifically designed for certain font sizes and in the early days that was all you could get. Even a low-level \font wouldn't help in that case. True LaTeX or TeX would then assume they could use the font, but at the time of printing things would then fail.

However, nowadays most TeX installation can generate MetaFont based fonts on the fly and thus would be able to generate any intermediate font if requested.

So why is LaTex by default still using a fixed set of fonts for Metafont based fonts? The reason for LaTeX2e was mainly to avoid getting very many generated fonts just because somebody was using special \fontsize values. And of course backward compatibility!

But if you want to have this possibility: no problem you just need to provide the right kind of font shape definitions. Here is one possibility for CM:

 \DeclareFontShape{OT1}{cmr}{m}{n}%
{<-6>cmr5<6-7>cmr6<7-8>cmr7<8-9>cmr8<9-10>cmr9%
<10-12>cmr10%
<12-17.28>cmr12%
<17.28->cmr17}{}


This is now using intervals, e.g., cmr10is used for all fontsizes between 10pt and 12pt, etc.

In the case of Computer Modern these type of redefinitions are in fact provided by the package fix-cm so simply loading this package will enable all intermediate sizes.

## Documentation

You will find some good information on LaTeX's font setup in the document LaTeX2e font selection and the LaTeX Companion 2ed has a full chapter on all the details and possibilities of it.

-
if using the CM fonts, the fix-cm package fixes these scaling issues. –  ArTourter Mar 10 '12 at 18:22
thanks @ArTourter - I kind of remembered that there is a package like that but didn't remember the name. updated the answer –  Frank Mittelbach Mar 10 '12 at 18:33