Utilizing oldstyle figures without resorting to \oldstylenums

Quite a few of the freely available LaTeX fonts include oldstyle figures (numerals that harmonize with lower case letters) in addition to lining figures. (Generally, you have to load the textcomp package to make the additional symbols available.) However, only a few font packages provide an easy switch to oldstyle figures - the ones I know that are freely available are

• \usepackage[osf]{mathpazo} (for the Palatino font),

• \usepackage[osf]{libertine}, and

• \usepackage{cfr-lm} (for the Latin Modern font).

For other fonts, one may use the \oldstylenums macro to access oldstyle figures, typing (e.g.) \oldstylenums{123} in every single instance. This is impractical and tedious.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{textcomp}

\usepackage{tgschola}% or, e.g., tgtermes, cmbright, iwona

\begin{document}

\Large

0123456789

\oldstylenums{0123456789}

\end{document}


I know that XeLaTeX allows for easy access to Open Type Font features (among them oldstyle figures). However, I'm interested in (pdf)LaTeX for the moment. Is it possible to conveniently utilize oldstyle figures for every LaTeX font that includes them?

-
Just to add to your list, kpfonts provides multiple options: \usepackage[oldstylenums]{kpfonts} gives old style numerals in text mode and \usepackage[fulloldstylenums]{kpfonts} gives them in both text and math mode. There are other possibilities too; see its documentation. – frabjous Sep 7 '10 at 20:16
The general answer for this question is "no". Fonts must explicitly support OSF variants. – Will Robertson Sep 8 '10 at 5:02

There isn't generally a single answer for this. It all depends on the fonts and font tables that the font foundry provides and how they're mapped and installed in your TeX system. Let me try to explain.

[To make things less confusing, the answer that follows assumes your question is directed at LaTeX scenarios, rather than XeTeX, LuaTeX etc. which provide different and somewhat simpler ways to approach this.]

Assuming that your fonts are properly installed in your texmf directory stucture, and perhaps assuming outline (non-bitmap) fonts, you'll have several sets of fonts (let's say, "shapes" and/or "series") for each typeface. Depending on the particular typeface, i.e., depending on what the particular font foundry has provided, you will have shapes/series for regular, bold, italic, bold-italic as a minimum (although in some cases there might be less), and then possibly, old style nums, true caps, condensed, alternative weights etc (usually from 'Pro' or 'expert' collections).

Now, TeX can access the oldstyle nums provided in your fonts in several ways, depending on how the font has been created or (more accurately) how its mappings are laid out on your system. In cases where you have dedicated oldstyle font files, all TeX needs to do to switch from oldstyle figures to lining figures is to switch its tables pointing at them in its mappings. And all you need to do is specify what you want by selecting them. Here are some examples:

Font Family       lining figures   old style figures
----------------------------------------------------
Kepler Project        jkpx             jkpxosn
Palatino              pplx              pplj



Alternatively, if you want to use Palatino with oldstyle nums at a particular place in your document, you might write \fontfamily{pplj}\selectfont. If you do that while you're in a group (e.g., inside an inner { and }), you'll revert to the font that was in effect when you leave the group. As above, this is all that mathpazo is doing for you when you write \oldstylenums{12345}. I.e., mathpazo includes the command (notice the group):

\renewcommand{\oldstylenums}[1]{{\fontfamily{pplj}\selectfont #1}}


Not too many font foundries give you this ease of access to old style figures (mostly because these extra sets make up their 'Pro' collections for which they charge more, or because it's extra work, or because oldstyle nums don't look so fantastic in that particular typeface).

However, as with GUST e-foundry, some font makers provide oldstyle figure glyphs outside the usual slots for these. In other words, you get the usual set of lining figures as well as oldstyle figures through symbol glyphs mappings (TS1 vs T1 encodings). If your mappings have been set up properly (e.g., by fontinst or if someone has done this work for you), you can access lining figures in the usual way ('1', '2',...) and oldstyle figures through commands like \textzerooldstyle, \textoneoldstyle, etc. The trouble is, you can't easily switch in and out of lining and oldstyle figures just by selecting them as we saw in the Palatino example above. This is reason the fontaxes approach (per Lev's and lockstep's suggestion) won't work - for Gyre Schola, it's looking for font definition qcsj or qcs-OsF and can't find either (qcs is the base fontfamily name for Gyre Schola). However, without the fontaxes package loaded, \oldstylenums (defined in the textcomp package) can access them. You can see how it does this by fooling around a little like this:

\documentclass{article}
\usepackage{tgschola}                % or whatever
\usepackage{textcomp}                % no real need to explicitly load textcomp in this case
\usepackage{fontenc}                 % to control your font encoding

\begin{document}
T1 font encoding:\par
\fontencoding{T1}\selectfont
01234567890\par                      % lining figures under T1 encoding, osf under TS1
\oldstylenums{01234567890}\par       % forces TS1 encoding, so typeset osf regardless
abcdefghijABCDEFGHIJ\par             % normal chars under T1 encoding, gobbledygook under TS1
\oldstylenums{abcdefghijABCDEFGHIJ}  % forces TS1 encoding, so typeset symbols regardless
\vspace{\baselineskip}

TS1 font encoding:\par
\fontencoding{TS1}\selectfont
01234567890\par                      % lining figures under T1 encoding, osf under TS1
\oldstylenums{01234567890}\par       % forces TS1 encoding, so typeset osf regardless
abcdefghijABCDEFGHIJ\par             % normal chars under T1 encoding, gobbledygook under TS1
\oldstylenums{abcdefghijABCDEFGHIJ}  % forces TS1 encoding, so typeset symbols regardless
\end{document}


If you do this, you'll quickly see that all that \oldstylenums is doing is switching in and out of TS1 encoding. However, you can see by the nonsense that is printed when you try to typeset normal characters in TS1 font encoding that you mustn't select that encoding when wanting to typeset normal text! Thus, you have to somehow tell LaTeX before entering and after leaving every block of oldstyle nums that this is what you want to do. I.e., you're back to using \oldstylenums, although perhaps by some other name.

There is a third way, which is to set up a set of virtual fonts that assemble the oldstyle figures the font provides into the slots where the normal figures usually reside. This takes some expertise and probably shouldn't be entered lightly but is completely do-able if you have the patience and time to spare.

-
Great answer! Just to add to your list of fonts providing dedicated osf support files: You can access oldstyle figures for Lucida by switching from hlh to hlhj. – lockstep Sep 8 '10 at 5:56
Although it's been a long time since this post, I've thought of suggesting the package lucimatx, which allows -- besides other interesting features -- for text figures (old style numerals, if you so wish) to be set as the default for text. It is not available at CTAN but can be downloaded from pctex.com/fonts.html#Lucida_Fonts. You need the outline (.pfb) files, but the LaTeX package itself is available for free. – Marcos Aug 6 '12 at 12:12
Note: cfr-lm and several of the ADF packages use nfssext-cfr which makes it easy to switch. (Like fontaxes but for fonts named according to the Karl Berry scheme.) Also, venturis is working via virtual fonts, just like cfr-lm. It isn't that they are in the appropriate slots in the fonts, if that means the type1 fonts. It's the method you mention at the end but the virtual fonts are pre-cooked. – cfr Feb 10 '14 at 3:59

You might be able to use the fontaxes package (distributed as part of MinionPro). It gives commands for choosing different axes of fonts: regular/smallcaps/spacedsmallcaps; upright/italic/slanted/swash; oldstylefigs/liningfigs; proportionalTextFigs/tabularTextFigs; proportionalMathFigs/tabularMathFigs.

It is mainly designed for MinionPro, but I believe it also works with other fonts.

-
I installed and loaded fontaxes.sty and issued the command \figureversion{osf}, but it doesn't seem to work. – lockstep Sep 7 '10 at 19:09
Other fonts must be explicitly set up to support it, I think. – Will Robertson Sep 8 '10 at 5:02
In particular, they have to be named appropriately. – cfr Feb 10 '14 at 4:00

Version 5.1.3 of libertine, released on December 11th, 2011, does not work with pdfLaTeX anymore. Quoting Ulrike Fischer at comp.text.tex:

As a warning: this means that support for (pdf)latex and type1 fonts has been dropped. The package no longer works with this engines. And as far as I can see the type1-fonts have disappeared from CTAN.

Herbert Voß gives some advice at de.comp.text.tex how to save libertine's type1 font files to a local texmf tree before upgrading .

UPDATE: On December 20th, 2011 the new libertine-legacy package was released. From the CTAN announcement:

From December 11, 2011, the libertine package supports only xetex and luatex users (opentype-format fonts). This package provides the last version that still supported tex and pdftex users (type 1 fonts). Except for a small number of directory and file re-namings to avoid conflicting with more recent distributions, the files in this package are identical to those of the libertine package version 5.1.2 distributed at CTAN before December 2011.

It is believed that this package can be installed and used as before, without conflicting with newer libertine packages, except that the latter have a "dummy" libertine.sty that should be deleted or avoided. Xetex and luatex users should use libertineotf.sty in the more recent libertine packages.

-