# Is there a simple way to manually change font with font size in XeTeX?

Many typfaces come with different fonts for different font sizes. For example Surveyor Pro has a Book style for main text and a Display style for headings (or in general, large text). Another example is the open source project XITS which if scaled down to smaller text needs kerning pair adjustments (which result in a different font).

In these cases one could redefine the \Huge or \footnotesize environment and use the fontspec package to associate different fonts with those commands. This however is a rather hacky way and could lead to more problems. So hence my question.

Is there a simple way to manually change font with font size in XeTeX?

EDIT: I should point out that fontspec recognises optical scaling and would therefore automatically pick a different font for a different size if available. There are a lot of SizeFeatures too (as described in the fontspec manual) such as changing colour, kerning values et cetera. Is it possible though to change font? For example:

``````\setmainfont{Typeface}[SizeFeatures = {{Size =   -8, <Font_A>},
{Size = 8-12, <Font_B>},
{Size = 12- , <Font_C>}}]
``````

For the argument's sake Font_A should be Garamond and Font_B should be Times New Roman and Font_C can be Surveyor Pro Display.

-
It's an interesting question. I have not explore yet XeTeX so deep for reply properly your question, but below my own experience with different fonts in DPAs, those professional fonts need a better control, the most of times manually. I think that in XeTeX the ease won't be greater, at least not by default. –  Aradnix Jul 10 at 6:28
Are we talking optical sizes here or something else? The part about 'display text' suggests you are thinking of what would normally be regarded as different fonts, not simply different optical design sizes. –  Joseph Wright Jul 10 at 6:39
@ChrisS I can see that this is done automatically with CM, but for other systems you might have to manually specify for which size range which font to use. So I wouldn't say it's a duplicate. –  JaloCapa Jul 10 at 6:40
@JosephWright I would argue that in many cases optical sizes are directly linked to (and therefore mean) different fonts. (Not strictly of course. I'm referring to size regimes, e.g. Size 9 pt to 12 pt Book, 18 pt to 32 pt Display) –  JaloCapa Jul 10 at 6:46
I suspect here the answer is 'no': the `fontspec` mechanism is about optical sizes of what the designer regards as the same font rather than actually changing font. (Semantically, the font size commands are only supposed to change the size, so that's not an unreasonable position.) –  Joseph Wright Jul 10 at 8:48

Ok, so I found the answer to my own question. It turns out I was pretty close:

``````\setmainfont[SizeFeatures = {{Size =   -8, Font = <Font_A>},
{Size = 8-12, Font = <Font_B>},
{Size = 12- , Font = <Font_C>}}]{<Typeface>}
``````

produces exactly what I wanted.

-
Isn't this the same as the example in your question? Not sure where the misunderstanding was originally. –  Will Robertson Jul 10 at 10:26
@WillRobertson Almost, it's missing the `,Font = ' bit. I should have seen that earlier I guess. Still, this might be helpful for others. –  JaloCapa Jul 10 at 10:43
— Ah, I must be blind! Thanks. (BTW, probably best to be consistent with where the optional argument to `\setmainfont` goes.) –  Will Robertson Jul 10 at 14:26