16

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?

MWE:

\documentclass{article}

\usepackage[osf]{mathpazo}
\usepackage{fontspec}

%\setmainfont[Numbers=OldStyle]{Palatino}

\begin{document}
\textsc{This is a test} 0123
\end{document}
Konrad Rudolph
  • 39,394
  • 22
  • 107
  • 160
  • There are many Palatinos around, which one are you using? – خالد حسني 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 02: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

3 Answers3

15

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.

\documentclass{article}
\usepackage{fontspec}

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

\begin{document}
Text 12345.
\end{document}
  • You can also use a different font for small caps, RTM. – خالد حسني 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. – خالد حسني Sep 11 '10 at 23:55
  • The first option is highly non-trivial with ubuntu/debian. What I did wast to go here: http://www.gust.org.pl/projects/e-foundry/tex-gyre/pagella/index_html download the fonts and install them manually. – Mateus Araújo Sep 12 '10 at 00:22
  • 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). – خالد حسني Sep 12 '10 at 01:21
  • 1
    Incidentally, the "somewhere in the texlive documentation" this is explained is here: http://www.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 02:22
  • No it does not: the file texlive-fontconfig.conf does not exist in the debian packaging of texlive. Perhaps it was in an earlier version of Ubuntu? – Mateus Araújo Sep 12 '10 at 06:58
  • Thanks Khaled, it is indeed easy. The best way is to use /etc/fonts/font.conf as a model, and save the resulting file as /etc/fonts/conf.d/09-texlive.conf. Then run sudo fc-cache -fsv. I just had to add the line /usr/share/texmf/fonts/opentype/public I take back the highly, but is still nontrivial. – Mateus Araújo Sep 12 '10 at 07:19
  • I know it is non-trivial, that is why lualatex (luaotfload) can access fonts in texmf tree by name without any extra configuration. – خالد حسني Sep 12 '10 at 10:45
  • Wow, this is great. Unfortunately, using this font (either from TEXMF or when installed in the system directory, which is very easy on OS X) results in this problem. The fix mentioned in the question works, but I’m still interested in a solution (hence the bounty). – Konrad Rudolph Sep 12 '10 at 13:41
10

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:

\documentclass{article}
\usepackage{fontspec}
\newfontfamily\foo{Helvetica}
\usepackage[sc,osf]{mathpazo}
\usepackage[T1]{fontenc}
\begin{document}
Text 12345. {\fontencoding{EU1}\foo fontspec font}
\end{document}

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 06: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 07: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
8

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.

\documentclass{article}
\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

\usepackage{fontspec}
\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)}}

\newcommand\printstuff{
  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
  \vspace{\baselineskip}
}

\begin{document}
Palatino...\par\printstuff
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}
Palatino...\par\printstuff
\end{document}
  • 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. – خالد حسني 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
  • @Konrad, @Khaled -- all's well that ends well then :) – Geoffrey Jones Sep 12 '10 at 14:56
  • 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. – خالد حسني Sep 12 '10 at 15:36
  • @Khaled: setting the font directly works indeed (had tried that myself in the meantime), I’m just not sure why it’s necessary, since even installing the font in the system directly didn’t work. But well, so long as it works now. – Konrad Rudolph Sep 12 '10 at 16:08
  • 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
  • @Will: the reason nobody pointed this out is probably very simple: who uses it when they use fontspec anyway? The latter provides much superior mechanisms … – Konrad Rudolph Sep 13 '10 at 11:43
  • @Konrad, anyone who must continue to access Type1 fonts (which using myself as a sample set of n=1 means everyone) is stuck in this predicament. It isn't the case that everyone can in one big bang divest themselves of Type1, investing in OTF to cover all the fonts that are lost (even were fontiers to offer the option in each case). The cost and effort of doing so would be prohibitive for me and, I assume, more or less the same with everyone who has taken their font collections seriously to this point. The real issue is not oldstylenums but fontspecs weak font type cohabitation approach. – Geoffrey Jones Sep 13 '10 at 12:07
  • @Geoffrey: forget my comment. You’re of course right. – Konrad Rudolph Sep 13 '10 at 12:50
  • @Konrad, forget what comment ;) @Will, please don't forget my comment, being able (or not as the case may be) to continue to use my many Type1 fonts as first-class font entities (not some derogated rejects) makes all the difference in the world to whether I want to, let alone whether I can, adopt fontspec except for creating toy documents. (That and microtype in XeTeX, although that particular issue seems to be resolving itself rapidly apace.) – Geoffrey Jones Sep 13 '10 at 13:14