Font schemes and LaTeX3

There was a question recently on the TeX.sx site about font selection and LaTeX3. At the moment, there is not a LaTeX3 font system set up, and there are issues outstanding, so this is not something with a single answer. What I can do, though, is look at what seems likely and what some of the areas to consider are.

(New) Font Selection Scheme

TeX’s font mechanism is pretty basic. There is no relationship between one text font and another: they are all simply set up using the \font primitive. So with plain TeX

{\bf Some {\it text}}

will have ‘Some’ in bold, but ‘text’ in mid-weight italics. LaTeX2e introduced the ‘New Font Selection Scheme’ (NFSS), which provides a method for managing fonts in a way that is likely to be more logical for the user. Thus

{\bfseries Some {\itshape text}}

will have the inner text both bold and italic. At the same time, the NFSS provides a system for loading font files in an organised way and substituting fonts when a particular shape combination is unavailable.

Over all, the NFSS is one the key successes of LaTeX2e compared with LaTeX2.09. There are also a lot of existing .fd files about for using fonts with LaTeX2e, and supporting those is important. So something like the NFSS is definitely needed: the ‘New’ is rather anachronistic nowadays, so the working title is just FSS.

The NFSS is not perfect, and so LaTeX3’s FSS cannot be simply a clone of NFSS. Perhaps the most common complaint about the NFSS is that \textsc is treated as a shape, which makes it impossible to combine it with \itshape to have italic small caps. Other areas which need addressing are for example flexible sizing and proportional/fixed width numbers for tables. This is all evolutionary, and so the plan is to port the existing NFSS first, tidy it up to fit better with LaTeX3 coding approaches, then add new abilities.

Font face loading

The second area to think about is loading fonts in the first place. The traditional LaTeX2e approach to this to set up a small(ish) package to select a font family, for example lmodern or mathptmx, which will then use the NFSS to load the appropriate TeX font files. For users of XeTeX or LuaTeX, the standard method is to use the fontspec package, which provides an interface between the extended \font primitives in these engines and the NFSS.

There are a few things to think about here. First, while XeTeX and LuaTeX can load system fonts directly, pdfTeX cannot. Secondly, even if you are using XeTeX or LuaTeX access to traditional TeX fonts cannot be ignored. There is a lot of MetaFont material on CTAN which is not available in any other format, so simply dropping support for these is not an option.

What I feel we need is a single font-loading interface at the user level which is capable of dealing with these requirements. Clearly, fontspec is going to provide inspiration on how to proceed, but some mechanism for working with pdfTeX will also be needed. My personal take on this is we’ll need a mapping layer, which will mean that at the user level you choose a font by name (as you would in a GUI application), and which then does the appropriate translation to the engine layer.

There are also math mode fonts to worry about. OpenType maths fonts are very much in development, but that doesn’t help with pdfTeX and again does not cover all cases. So again we need to continue to support TeX’s traditional math mode fonts. That will probably be the last part of this particular jigsaw to be tackled, simply because it’s the one with the least clear path at present.

10 thoughts on “Font schemes and LaTeX3

  1. Did you (I mean, the LaTeX team) consider looking at the ConTeXt mechanism for fonts? Granted it’s complicated (I never understood it well), but it seems that it answers many issues: among others, it works (I mean the MkII one) for different engines, and from what I hear it is *very* flexible. I do not suggest copying it verbatim, but it might serve as a good source of inspiration.

    (Well, I am pretty sure you *did* think about it, so I’m just asking about your opinion this way;).)

  2. I guess I am ‘member of the team most likely to look at ConTeXt for ideas’. I have looked at some of the font stuff, but as far as I know they stick to a more plain TeX approach. For example, try

    starttext
    {bf Hello {it World}}
    stoptext
    
  3. Well, that’s true, but substitute tt for bf;). In ConTeXt, “normal”/italic/bold/bolditalic are on one axis (called “alternative”), and serif/sans/typewriter are on another one (“style”). (And there are in fact more options on either axis.) Moreover, if you change it to em, you get what you’d expect.

    Note also that putting bold and italic on the same axis might have been done on purpose, since bold italic (bi in ConTeXt) is usually evil (unless you know what you’re doing, that is).

    On the other hand, ConTeXt has a lot of thought invested in font-related stuff: otf fonts, substituting filenames for logical names, using design sizes, (sub|super)scripts, precise setting of leading, emphasize settings…

  4. access to fonts by filename, instead of system lookup, is much more important than just metafont fonts. accessing by system name makes your document inherently unportable; only looking up by filename (a filename that’s in the tex tree, that is) has any real hope of working. this is true regardless of format.

    for example, no journal (including tugboat) can print anything that relies on system fonts.

    i find it extremely unfortunate that xetex and fontspec tend to encourage one to use system fonts, to the point of some features not working with filename lookup. Will agreed in principle to fix, but as always, time is evidently short.

  5. I would like to see the same flexibility in math fonts that you get with text fonts. That is, in text you can easily write {ttfamily {bfseries xxx}} and get bold typewriter. Try doing that in math – there really isn’t a user-accessible way. I had to look at how LaTeX implemented tt in math mode to figure it out.

  6. (Popular topic: sorry that my replies are out-of-order as a result.)

    @mbork I don’t claim to be a ConTeXt expert: sorry for missing this. The reason I picked bf and it is that most commercial fonts include this combination. I’d also point out that font axes need to be based as far as possible on some logical structure rather than what is subjectively ‘pleasing’. (Yes, you do discourage certain behaviours but can’t prevent them).

    I’m certainly aware of ConTeXt concepts such as ‘real’ text-mode sub/superscripts, and will be looking over their interfaces in more detail once we get the NFSS conversion done and are therefore looking to extend/improve rather than just tidy up.

  7. @karl There are different user groups for LaTeX with different needs. mbork is talking I guess very much from the ‘writing a thesis’ view. There, what you want is ease of use, with portability not really an issue. You are looking at things from the ‘publisher using author source directly’ end, where life looks very different. Even there, I’d imagine that publishers alter the source, though, for example to use commercial fonts in place of open ones. (In my area there is a move away from things like Times to fonts such as Arno Pro, which unless you have a license you simply can’t use as an author.)

    I see the need for both easy access to system fonts by name (for the first group) and a clear method to guarantee loading of a font file by name (for the second). A few minutes thought suggests some approaches, but we’re not quite at the stage yet of trying to implement this. I’ll certainly bear it in mind.

  8. @Justin There are both technical and conceptual limitations here. TeX’s math mode works very differently from text in terms of how it treats fonts. So NFSS-in-math mode is technically challenging at least. There is also then the whole business of the appearance of math mode material conveying meaning in maths. I’ve mentioned before that Unicode math makes this even more ‘interesting’.

  9. @Justin: In ConTeXt MkIV, ${tt {bf x}}$ gives you bold typewriter x.

    @Karl: In ConTeXt, using filename to load the font is the most reliable way. AFAIK, it is not possible (at the user level) to differentiate between fonts in the tex tree (in appropriate TDS location) and fonts in OSFONTDIR. I assume that one can configure texmf.cnf (rather its luatex equivalent) to specify which of the two should take preference.

  10. I’ll play the devil’s advocate here. Should a FSS scheme provide font switches (denoted by font(A|B|..) here) so that the following words are typeset in the style that they refer to:

    {fontA bold {fontB italic} {fontC bolditalic} bold}
    

    and

    {fontD sans {fontA bold {fontB italic} {fontC bolditalic} bold} {fontE sans bold {fontF sans italic} {fontG sansbolditalic} sans bold}
    

    Should a FSS provide commands for all such combinations? I think that a better interface might be something like addff and subff (to add and remove font feature in ConTeXt), so that each font “feature” (like bold, italic, sans) can be added and removed independently.

Leave a Reply