For various reasons, I’m using the fontspec package.

However, I’d also like to use Palatino as the document’s main font, and I want to use it with small caps and old-style figures.

So I’ve got four requirements:

  1. fontspec,
  2. Palatino,
  3. Small caps,
  4. Old-style figures (everywhere, not only selected via \oldstylenums).

Any three out of these four features work fine together. But I can’t get all four working in the same document.

In fact, using \usepackage[osf]{mathpazo}, I get nice small caps and lowercase figures. But as soon as I \usepackage{fontspec}, old-style figures no longer work, even if I don’t select a font.

Now, I could be tempted to say \usemainfont[Numbers=OldStyle]{Palatino}, but this doesn’t work: figures remain as they are. Furthermore, small caps now cease to work (presumably because I don’t have the expensive, shiny version of Palatino that includes old-style figure glyphs – with mathpazo this only works because the package “cheats” and selects the typeface family pplj instead).

How can I get this to work? Is there a way to explicitly select pplj for the main text (\rmfamily) even when using fontspec for other fonts?





\textsc{This is a test} 0123
  • There are many Palatinos around, which one are you using? – Khaled Hosny Sep 11 '10 at 20:46
  • I'm can't figure out how you got \usepackage[osf]{mathpazo} and \usepackage{fontspec} working without errors. The main problem I see is in clashes between their font encodings, e.g., T1 (or whatever) and EUx. Can you provide a MWE that compiles cleanly in this or some related configuration? – Geoffrey Jones Sep 12 '10 at 2:42
  • @Geoffrey: hmm. Unfortunately, I don’t know anything about font encodings. I’d forgotten to include my MWE but on the other hand … but I don’t think it will help you, since it’s essentially what I’d written before. – Konrad Rudolph Sep 12 '10 at 11:22

You need a Palatino with proper OpenType support, alternatively you can use TeX Gyre Pagella (which is true Palatino by Zapf, and further opentypified by GUST) which is included in TeXlive.


\setmainfont[Numbers=OldStyle]{TeX Gyre Pagella}

Text 12345.
  • You can also use a different font for small caps, RTM. – Khaled Hosny Sep 11 '10 at 21:37
  • I can't use your example; you're sure you can call the fonts by name? I have the TeX Gyre fonts installed, at /usr/share/texmf/fonts/opentype/public/tex-gyre . This is Ubuntu 10.04, with texlive 2009. – Mateus Araújo Sep 11 '10 at 23:28
  • If you are using lualatex and texlive2010, yes, else no. In such case you have to options, added texlive fonts to your system fonts by playing with fontconfig confoguration (explained somewhere in texlive documentation), then you will be able to access fonts by name in xetex, or select fonts by font file but it is a bit complex, again check fontspec manual. – Khaled Hosny Sep 11 '10 at 23:55
  • 1
    Not that hard, you just need a valid ~/.fonts.conf fontconfig file with few <dir>path</dir> lines (it scan recursively, so you need to include only top directories). – Khaled Hosny Sep 12 '10 at 1:21
  • 1
    Incidentally, the "somewhere in the texlive documentation" this is explained is here: tug.org/texlive/doc/texlive-en/texlive-en.html#x1-360003.4.5 -- I'm pretty sure that works even with the Debian/Ubuntu version. (I know I did it on Ubuntu at some point, though I ended up regretting it since the number of fonts it adds is enormous, and sifting through them every time I used a font dialogue was annoying; installing directly from gust.org.pl works just as well.) – frabjous Sep 12 '10 at 2:22

I like Khaled's approach better, but here's an answer to your more general problem. You can mix fonts with TeX-era encodings with unicode fonts if you specifically switch between font encodings:

Text 12345. {\fontencoding{EU1}\foo fontspec font}

Now that I write out this example, it strikes me that \newfontfamily should include the line about switching font encodings. This has been simplified in this commit on Github.

  • 1
    +1 Will. Thanks for raising the issue on Github. I'm sure that having encodings automatically attached to fontspec fonts will considerably widen the package's adoption. For myself, I have quite a few commercial (as you say, ahem) "TeX-era" fonts. Even if equivalents could be sourced, at today's prices the expense of upgrading these to OTF is prohibitive, making fontspec considerably less attractive as a result. At least there's a 2nd-best solution to the font co-habitation problem now, with a 1st-best solution in the wings. – Geoffrey Jones Sep 12 '10 at 6:56
  • Another afterthought, this solution should probably be added to the fontspec doc -- while I could see that Konrad's problem was a font encoding clash, I couldn't on my own work out how to solve the problem so I eventually gave up. (Since I didn't know how fontspec used encodings internally and therefore whether I'd break anything going down that road, I'd essentially been trying the reverse of your solution, explicitly setting \fontencoding{T1} around fontspec font usage, and inside redefined \oldstylenums -- too messy!) – Geoffrey Jones Sep 12 '10 at 7:48
  • Thanks, this is exactly what I’ve been searching for – but Khaled’s answer makes this even easier (minus the issue of xdvipdfmx finding the font). – Konrad Rudolph Sep 12 '10 at 13:43

This answer shouldn't take anything away from Khaled's or Will's insightful answers. Its purpose is just to pull their ideas together, to provide a soultion about \oldstylenums that they'd omitted, to bring up the issue of math (since you had initially pulled in mathpazo), and to introduce some font naming code to help you visualise your problem, especially when it comes to encodings. Here goes...

In fact, using \usepackage[osf]{mathpazo}, I get nice small caps and lowercase figures. But as soon as I \usepackage{fontspec}, old-style figures no longer work, even if I don’t select a font.

Firts, try adding (\fontname\the\font) to your body text. If you do that, you'll quickly see that fontspec has set your body text to Latin Modern (non-OSF) for you. Why, you might ask? Good question, go ask Will. In any event, you'll need to (re)load a compatible Palatino font. Per Khaled's answer, \setmainfont[Numbers=OldStyle]{TeX Gyre Pagella} will do the trick. It's typeface is amazingly similar to ppl. Everything will work now, except unfortunately this breaks \oldstylenums{...} (because of the way mathpazo has redefined \oldstylenums, XeTeX throws a "Font shape `EU1/pplj/m/n' undefined" warning). This is the problem I was wrestling with when I started working on your problem.

You're very clear about the four points in your question. What's less clear is whether you also require that:

  • \oldstylenums{...} must be available (and work)
  • mathpazo is absolutely needed for its nicer maths symbols than those from other Palatino families

The problem about using \oldstylenums in your current configuration is that it reverts to printing Latin Modern (terrible match for Palatino). The second point is probably no big deal - mathpazo math symbols are little different to those fontspec gives you with TeX Gyre Pagella. Still, to my eye, the mathpazo math symbols are definitely (albeit subtly) more refined.

The code below shows you the consequences and trade-offs that you get from various combinations. Try commenting out the \usepackage[sc,osf]{mathpazo} line and, alternatively, my new definition for \oldstylenums to see the effects of these. I've thrown in some font naming code and a \liningstylenums command to help you with your choices.

\usepackage[margin=0.5in]{geometry}  % there are some pretty wide hboxes below

\usepackage{amsmath}                 % needed for the example below
\usepackage[sc,osf]{mathpazo}        % comment this line in and out to see the
                                     % differences in the displayed math

\setmainfont[Numbers=OldStyle]{TeX Gyre Pagella}
\newfontfamily\altfont[Numbers=OldStyle]{TeX Gyre Bonum}

\renewcommand*\oldstylenums[1]{{\fontencoding{T1}\fontfamily{pplj}\selectfont #1 (\fontname\the\font)}}
\newcommand*\liningstylenums[1]{{\fontencoding{T1}\fontfamily{pplx}\selectfont #1 (\fontname\the\font)}}

  Plain text: abcdefghijk ABCDEFGHIJK (\fontname\the\font)\par
  \textsc{Small caps: abcdefghijk ABCDEFGHIJK (\fontname\the\font)}\par
  Plain figures: 0123456789 (\fontname\the\font)\par
  Old style figures: \oldstylenums{0123456789}\par
  Lining figures: \liningstylenums{0123456789}\par

Here's some math:
\[\frac{1}{2\pi i}\int_\gamma f = \sum_{k=1}^m n(\gamma;a_k) \text{Res}(f;a_k).
\qquad (\fontname\the\font)\]\par
{\altfont Alternative font...\par\printstuff}
  • 2
    If mathpazo is needed just for math, then you can use Asana Math font, which is an OpenType math font based on mathpazo fonts. \usepackage{unicode-math} and \setmathfont{Asana Math}, but then you need texlive 2010. – Khaled Hosny Sep 12 '10 at 13:40
  • 2
    Great answer, too. To answer your questions: (1) I don’t care about \oldstylenums, since the mechanisms provided by fontspec are superior. (2) Loading mathpazo was simply my try to get old-style numbers in Palatino (well, that and true small caps). That said, I’ll try to use Asana-Math for math mode. – Konrad Rudolph Sep 12 '10 at 14:09
  • @Khaled: unfortunately, loading Asana Math doesn’t work (Cambria Math, on the other hand, works) because apparently the TFM file cannot be found – do you know a quick fix? (Otherwise => new question.) – Konrad Rudolph Sep 12 '10 at 14:55
  • 1
    @Konrad: the TFMnot found error is misleading, it basically means xetex did not find the system font, so falls back to tfm font which is non-existent in this case. Just make sure you have the font and is accessible to xetex. The situation with math fonts is simpler since it involves one file, so you can say \setmathfont{asana-math.otf} (or whatever file name is) to access the font from texmf tree. – Khaled Hosny Sep 12 '10 at 15:36
  • 1
    Thanks for pointing out the \oldstylenums problem. Can't believe no-one pointed it out until now. I've added it to the issue tracker. – Will Robertson Sep 12 '10 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.