6

Preamble: In a document I want to use EB Garamond for both text and maths and I don't want to install anything that doesn't come with TeX Live (i. e. no Garamond Math and no URW Garamond).

So here's my typescript thing for that (sorry for the long listing, it is the minimal working example i could make):

\definefontfeature
    [eb-garamond-be-normal]
    [default]
    [onum=yes]
\starttypescriptcollection[ebgaramond-be]
    \starttypescript [serif] [ebgaramond-be]
        \loadfontgoodies[ebgaramond]
        \setups[font:fallback:serif]
        \definefontsynonym [Serif] [file:ebgaramond-regular] [features=eb-garamond-be-normal]
        \definefontsynonym [SerifItalic] [file:ebgaramond-italic] [features=eb-garamond-be-normal]
    \stoptypescript
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Regular.otf] [digitsnormal] [force=yes]
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Regular.otf] [lowercasenormal] [force=yes]
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Regular.otf] [uppercasenormal] [force=yes]
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Italic] [lowercasenormal] [offset=lowercaseitalic,force=yes]
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Italic] [0x00068] [offset=0x0210E,force=yes] 
    \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Italic] [uppercasenormal] [offset=uppercaseitalic,force=yes]    
    \starttypescript [math] [ebgaramondandbonum] 
        \definefontsynonym [MathRoman] [texgyrebonummath] [features={math,mathextra},fallbacks=ebgaramondmathtext]
    \stoptypescript 
    \starttypescript [ebgaramond-be]
        \definetypeface[ebgaramond-be] [rm] [serif] [ebgaramond-be] [default] [designsize=auto]
        \definetypeface[ebgaramond-be] [mm] [math] [ebgaramondandbonum] [default]
    \stoptypescript 
\stoptypescriptcollection

It does work:

\setupbodyfont[ebgaramond-be]

\starttext
text: {\it abcde123}

math: $abcde123$
\stoptext

enter image description here

but I want lining figures in math mode, instead of oldstyle ones. I tried to create separate feature set with lnum=yes,onum=no using \definefontfeature and add it alongside with {math,mathextra} to the main math font with no luck. Even worse: when I make lnum=yes for the main text font, it affects only text mode, leaving oldstyle figures in math mode:

enter image description here

Is it possible to set opentype features (like lnum, for example) to fallback fonts? Or, maybe, there are some other solutions?

Upd:

In the comments Metafox posted a solution. First there should be a fontfeature that does not rely on default

\definefontfeature [EBGM] [lnum=yes]

and then this feature can be referenced using * after file name in the fallback definition:

\definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Regular.otf*EBGM] [digitsnormal] [force=yes]
  • 3
    To apply features to the fallback font you have to first create a synonym for the font file (e.g. \definefontsynonym [EBGaramond-Regular] [file:ebgaramond12regular] [features=...]) where you can apply the features and then load the font synonym in your fallback definition (e.g. \definefontfallback [ebgaramondmathtext] [EBGaramond-Regular] [...] [...]). – Wolfgang Schuster Jun 2 '18 at 20:38
  • Thank you, but I tried that either, like this: \definefontfeature [eb-garamond-be-math] [default] [lnum=yes,onum=no] ... \definefontsynonym [EBGM] [file:EBGaramond12-Regular.otf] [features=eb-garamond-be-math] \definefontfallback [ebgaramondmathtext] [EBGM] [digitsnormal] [force=yes] and it doesn't produce digits at all, but '?' instead. For some reason \definefontfallback doesn't seem to understand font synonyms. – Sergey Slyusarev Jun 2 '18 at 20:46
  • 2
    There is a second method where you set the features with the font file, the font and the features in this case are separated with a *. The fallback for the digits in your example should be like this: \definefontfallback [ebgaramondmathtext] [file:ebgaramond12regular*eb-garamond-be-normal] [...] [...]. – Wolfgang Schuster Jun 2 '18 at 21:09
  • I didn't try it before, but it doesn't seem to work. With \definefontfallback [ebgaramondmathtext] [file:ebgaramond12regular*eb-garamond-be-math] [digitsnormal] [force=yes] digits do appear, but they are oldstyle, no matter what features are set in eb-garamond-be-math – Sergey Slyusarev Jun 2 '18 at 21:23
  • 3
    You have to use base mode for the features of your math fallbacks, e.g. \definefontfeature [ebgaramondmath] [lnum=yes] and apply this feature set to your font files. The default features use node mode which doesn’t work in math mode. – Wolfgang Schuster Jun 2 '18 at 21:45
5

Features in math mode can only be changed when you’re in base mode but in your example you create a new feature based on the default set which uses node mode.

The easiest way to achieve this by creating a new feature without an mode settings because (ligatures etc. aren needed for symbols in math mode):

\definefontfeature [ebgaramond-math] [lnum=yes]

Another problem in your example is that you never apply the feature to your fallback font for the digits, to do this can either apply the feature with the font file in the \definefontfallback command, e.g.

\starttypescript [math] [ebgaramondandbonum]
  \definefontfallback [ebgaramondmathtext] [file:EBGaramond12-Regular*ebgaramond-math] [digitsnormal] [force=yes]
  \definefontsynonym [MathRoman] [texgyrebonummath] [features={math,mathextra},fallbacks=ebgaramondmathtext]
\stoptypescript 

or you use a two-step-method where you create a font synonym where you can use the third argument to set the features and load afterwards the synonym in the font fallback, e.g.

\starttypescript [math] [ebgaramondandbonum]
  \definefontsynonym  [EBGaramondFallback-Regular] [file:EBGaramond12-Regular] [features=ebgaramond-math]
  \definefontfallback [ebgaramondmathtext] [EBGaramondFallback-Regular] [digitsnormal] [force=yes]
  \definefontsynonym  [MathRoman] [texgyrebonummath] [features={math,mathextra},fallbacks=ebgaramondmathtext]
\stoptypescript 

The complete code to replace the digits from the math font with digits from EB Garamond would look like this:

\definefontfeature [ebgaramond-text] [default] [lnum=yes]
\definefontfeature [ebgaramond-math]           [lnum=yes]

\starttypescript [serif] [ebgaramond-be]
  \setups[font:fallback:serif]
  \loadfontgoodies[ebgaramond]
  \definefontsynonym [Serif]       [file:ebgaramond-regular] [features=ebgaramond-text]
  \definefontsynonym [SerifItalic] [file:ebgaramond-italic]  [features=ebgaramond-text]
\stoptypescript

\starttypescript [math] [ebgaramondandbonum]
  \definefontsynonym  [EBGaramondFallback-Regular] [file:EBGaramond12-Regular] [features=ebgaramond-math]
  \definefontfallback [ebgaramondmathtext] [EBGaramondFallback-Regular] [digitsnormal] [force=yes]
  \definefontsynonym [MathRoman] [texgyrebonummath] [features={math,mathextra},fallbacks=ebgaramondmathtext]
\stoptypescript 

\starttypescript [ebgaramond-be]
  \definetypeface[ebgaramond-be] [rm] [serif] [ebgaramond-be] [default] [designsize=auto]
  \definetypeface[ebgaramond-be] [mm] [math] [ebgaramondandbonum] [default]
\stoptypescript 

\setupbodyfont[ebgaramond-be]

\starttext

text: {\it abcde123}

math: $abcde123$

\stoptext

enter image description here

  • Thank you once again. The general idea definitely works, but your example doesn't actually produce text in Garamond EB (looking at the screenshot you provided it seems more like Bonum all over the place and i've tested it, with similar results). – Sergey Slyusarev Jun 4 '18 at 9:22
  • @SergeySlyusarev There was a - missing in the names of the text font which is required for the names in the goodies file. – Wolfgang Schuster Jun 4 '18 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.