4

I am using the fontspec package with LuaLaTeX. I'm curious if there is a way to automatically set numbers in small caps by default similar to how you can set numbers in OldStyle/Lowercase by default via the fontspec package options Numbers=OldStyle or Numbers=Lowercase

Note: Not all fonts support numbers in small caps. I use a free font in my MWE that supports small caps numbers.

My motivation for asking this question is that I am currently testing if typesetting numbers in small caps is easier or nicer to read than the usual uppercased, monospaced numbers. Having an easier way to output numbers in small caps would be wonderful.

\documentclass{article}
\newcommand{\alphabet}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\digits}{0123456789}
\usepackage{fontspec}
\setmainfont{Source Serif Pro}%Available for free on Google Fonts.
    [
    %Numbers=OldStyle%
    %Numbers=Lowercase%
    ]
\begin{document}
\textbf{Regular letters and digits:}
\par
\alphabet\quad\digits
\par
\textbf{Small caps letters and digits:}
\par
\textsc{\alphabet\quad\digits}
\par
\textbf{Regular letters and Oldstyle digits:}
\par
\alphabet\quad\oldstylenums{\digits}
\end{document}

EDIT 1: I added a photo displaying numbers with small caps. enter image description here

EDIT 2: I am looking for a solution, if possible, that makes numbers display as small caps by default without having to use \textsc or any other in-text macro. Thus, \textsc{1234} and 1234 should look identical. If this isn't possible, of course, I can always fall back on making an in-text macro.

7
  • 1
    I am not sure what you mean with "small caps numbers". I only know small caps for letters and old style numbers. Maybe you can post a picture of what you're after? If the font you use indeed supports something like numbers that fit the size of small caps (smaller numbers, so to say, which I assume is about what you mean), then you need to look up the font feature that selects this style in this font. You can then select this style, for example, using the option RawFeature=+xxxx where xxxx stands for the relevant feature abbreviation. Mar 10 at 17:35
  • 1
    I've added a photo that displays how numbers with small caps look like. I hope this clears up some confusion. Mar 10 at 17:47
  • 1
    Okay, so ... You want to get these "small caps numbers" by default, without small caps letters surrounding them? Is this what you're after? Mar 10 at 20:13
  • 1
    Yes! That is what I want! Mar 10 at 20:14
  • 2
    There are "small caps numbers" in some fonts. One familiar to me, simply has the numerals at small caps size, without the ascenders or descenders found in oldstyle. But in that case (it is a custom font, not public) there is a specific OpenType feature for it. If you look in the fontspec documentation, you will see that you can define your own custom feature, where you select specific characters in a font, and give them a new feature name.
    – rallg
    Mar 11 at 4:55

1 Answer 1

5

So, what you're after are digits that match small caps in size (which have not really a name to my knowledge, since the term "small caps" is usually only used for letters), but you want them printed in this style regardless of the sourrounding style of the text.

You can select specific OpenType features using fontspec via the option RawFeature=+xxxx where xxxx is the abbreviation of the relevant OpenType feature. So, you could select RawFeature=+smcp to enable small caps in general. Sadly, Source Sans Pro does not contain a feature that lets you select only these small numbers without affecting other letters, and on the other hand it seems that it is not directly possible to only select such features only for numbers using fontspec.

However, you can use fonts.handlers.otf.addfeature and enhance the font with your own custom OpenType feature which you can then use with fontspec. In the following example, I created the feature xnum which replaces the digit glyphs with the small-caps variants (you'd need to look up the relevant glyph names in the font, though):

\documentclass{article}
\usepackage{fontspec}

\directlua{
    fonts.handlers.otf.addfeature {
        name = "xnum",
        type = "substitution",
        data = {
            ["zero"] = "zero.sc",
            ["one"] = "one.sc",
            ["two"] = "two.sc",
            ["three"] = "three.sc",
            ["four"] = "four.sc",
            ["five"] = "five.sc",
            ["six"] = "six.sc",
            ["seven"] = "seven.sc",
            ["eight"] = "eight.sc",
            ["nine"] = "nine.sc",
        },
    }
}

\setmainfont[RawFeature=+xnum]{Source Serif Pro}

\newcommand{\alphabet}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\digits}{0123456789}

\begin{document}

\textbf{Regular letters and digits:}
\par
\alphabet\quad\digits

\end{document}

enter image description here


Another way would be to create a combofont using the package with the same name (which is based on the mechanisms provided by the luaotfload package). It is important to note that adding features such as smcp to the second font only works with setting mode=base.

\documentclass{article}
\usepackage{combofont}
\setupcombofont{sourceserifpro-regular}{
    {name:Source Serif Pro-Regular:mode=base;language=DFLT;+tlig} at #1pt,
    {name:Source Serif Pro-Regular:mode=base;language=DFLT;+tlig;+smcp} at #1pt
}{
    {} ,
    0x30-0x39
}
\setupcombofont{sourceserifpro-bold}{
    {name:Source Serif Pro-Bold:mode=base;language=DFLT;+tlig} at #1pt,
    {name:Source Serif Pro-Bold:mode=base;language=DFLT;+tlig;+smcp} at #1pt
}{
    {} ,
    0x30-0x39
}

\DeclareFontFamily{TU}{sourceserifpro-combo}{}
\DeclareFontShape {TU}{sourceserifpro-combo}{m}{n} {<->combo*sourceserifpro-regular}{}
\DeclareFontShape {TU}{sourceserifpro-combo}{bx}{n}{<->combo*sourceserifpro-bold}{}

\newcommand{\alphabet}{abcdefghijklmnopqrstuvwxyz}
\newcommand{\digits}{0123456789}

\begin{document}

\fontfamily{sourceserifpro-combo}\selectfont

\textbf{Regular letters and digits:}
\par
\alphabet\quad\digits

\end{document}

The output is the same as above.

4
  • 2
    "lowercase" is not a traditional printer's term for digits. (Some people call oldstyle digits lowercase, but this is mistaken.) In the traditional context, I'm familiar with two pairs of terms: lining/oldstyle and tabular/proportional. Together they provide four styles. Either lining or oldstyle can be used in tables, but tabular is essential, as columnar consistency is essential. Any of the four styles can be used in text. I doubt that "small caps oldstyle" would be wanted, but the tabular/proportional requirement probably holds. Mar 10 at 20:11
  • 1
    @barbarabeeton Maybe not traditional, but certainly it is possible to design digits at the height of small caps, without ascenders or descenders. I have done it. But there is no standard OpenType feature code. It would need to be assigned to a style set (ssNN) which is not the same in every font. Purpose of such digits: Might look better than either lining or oldstyle, when mingled in an extended string of small caps text.
    – rallg
    Mar 12 at 14:31
  • 1
    @rallg Indeed, I also thought that the proper OpenType feature code should maybe something like ssNN. Source Serif Pro assigns ss01 (Bulgarian variants of certain Cyrillic letters) and ss02 (Serbian/Macedonian variant of Cyrillc letter be) as far as I can see, so you could also use ss03 for the custom feature actually, since xnum is not really standardized. Mar 12 at 14:41
  • 1
    @rallg -- Of course proper-sized digits will look better, while oldstyle might look rather odd. But the point about not traditional just meant that it's not surprising there's no standard procedure for OpenType. Maybe this will catch on. Mar 12 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .