Old style numbers in TeX Gyre Pagella
The TeX Gyre fonts contain four sets of numbers. The names prefixed with / are the PostScript glyph names:
/zero, /one, /two, …
The "normal" digits with equal widths, suitable for tabulars.
/zero.prop, /one.prop, /two.prop, …
The "normal" digits with proportinal widths.
/zero.taboldstyle, /one.taboldstyle, /two.taboldstyle, …
Old style digits with equal widths, suitable for tabulars.
/zero.oldstyle, /one.oldstyle, /two.oldstyle, …
Old style digits with proportional widths.
The manual way
In the font setup for LaTeX only the digits with equal widths are available.
The "default" are the "normal" digits with equal widths except for small caps.
Manually you get old style numbers via package textcomp and \oldstylenums or
via small caps:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{tgpagella}
\begin{document}
0123456789\textdollar\textcent
\oldstylenums{0123456789}\textdollaroldstyle\textcentoldstyle
\textsc{0123456789\textdollar}
\end{document}

Patching the encoding
In the font map file qpl-ec.map, qpl.map or pdftex.map the font ec-qplr is used
in the example above. The map line is:
TeXGyrePagella-Regular "encqec ReEncodeFont" <q-ec.enc <qplr.pfb
The encoding file q-ec.enc defines which glyphs are used for the slots of the
font encoding:
% [some coment lines]
/encqenc [
/grave
/acute
...
/zero
/one
...
/nine
...
] def
There we could replace the glyph names for the digits. Let us copy the file to
q-ec-taboldstyle.enc. There the digits are replaced by the variant with
suffix .taboldstyle.
Now pdfTeX allows to replace the map line using \pdfmapline that should be used
before the font is used. For example, this can be done right at the beginning
of the TeX document:
\pdfmapline{=ec-qplr TeXGyrePagella-Regular "encqec ReEncodeFont" <q-ec-taboldstyle.enc <qplr.pfb}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgpagella}
\begin{document}
0123456789
\end{document}
Then the numbes are set using /<num>.taboldstyle instead of /<num>:

This trick does not change the font for LaTeX/TeX. The glyph metrics (TFM file) are
not changed. Because we have used taboldstyle instead of oldstyle, the widths of
the glyphs remain the same. However, some of the old style digits have a depth, that
is not seen by LaTeX or TeX.
New TFM files
If the correct glyph metrics are needed, then we also need new TFM files.
In our case we have ec-qplr.tfm (the base name is the first entry in the map line above).
This can be converted to a more human readable form using tftopl:
tftopl ec-qplr.tfm ec-qplr.pl
The file ec-qplr.tfm needs the correct directory. The program kpsewhich can be used to look for the file. In Linux the can be combined to:
tftopl `kpsewhich ec-qplr.tfm` ec-qplr.pl
The character metrics for 0, 1, and 7 in ec-qplr.pl:
(CHARACTER C 0
(CHARWD R 0.5)
(CHARHT R 0.6775)
)
(CHARACTER C 1
(CHARWD R 0.5)
(CHARHT R 0.6775)
)
...
(CHARACTER C 7
(CHARWD R 0.5)
(CHARHT R 0.6775)
(CHARIC R 0.025)
)
CHARWD, CHARHT, CHARDP, and CHARIC specify the height, width, depth, and italic correction of the character.
Now these values need to be replaced by the values for our taboldstyle digits.
Happily they are available in the TS1 encoding or file ts1-qplr.tfm. Alternatively
the small caps font ec-qplr-sc.tfm can be used. Again we convert the .tfm file
to the readable .pl format using tftopl. The result for 0, 1, 7:
(CHARACTER C 0
(CHARWD R 0.5)
(CHARHT R 0.464)
(CHARDP R 0.0164995)
(CHARIC R 0.003)
)
(CHARACTER C 1
(CHARWD R 0.5)
(CHARHT R 0.4904995)
(CHARDP R 0.0075)
)
...
(CHARACTER C 7
(CHARWD R 0.5)
(CHARHT R 0.464)
(CHARDP R 0.237999)
(CHARIC R 0.025)
)
This way we create a file ec-qplr-taboldstyle.pl with the changed metrics data for
the old style digits. The .tfm file is generated by pltotf:
pltotf ec-qplr-taboldstyle.pl
Result: ec-qplr-taboldstyle.tfm.
Remark: TFM files are not available for the non-proportinal digits. Thus the metrics need
to be guessed somehow. The AFM files contain the glyph bounding boxes that include
side bearings and similar things that are not taken into account for the TeX metric data.
But at least they can give a hint.
Now this font is added and does not replace the old entry for ec-qplr:
\pdfmapline{+ec-qplr-taboldstyle TeXGyrePagella-Regular "encqec ReEncodeFont" <q-ec-taboldstyle.enc <qplr.pfb}
In the next step we need a new font definition file for LaTeX and a new name for the
font in LaTeX. Let us use qplrtosn. Then we copy the old .fd file to the new one,
e.g. Linux:
cp `kpsewhich t1qplr.fd` t1qplrtosn.fd
The new file needs some changes:
- file name in
\ProvidesFile,
- font name in description text of
\ProvidesFile,
- date in
\ProvidesFile,
- font family name
qplr is replaced by qplrtosn (second argument of \DeclareFont...),
TFM name ec-qplr is replaced by ec-qplr-taboldstyle,
- then internal macro prefix
\qpl@ by \qpltosn@ if we want to use both font families in the same document,
It makes sense to make new TFM files for the other fonts, too.
At last we need a new package file tgpagella-tosn.sty with changes from tgpagella.sty:
\ProvidesPackage,
- internal prefix,
- font family name,