5

How do I define fonts with additional non-standard styles, alternatives and sizes? For example, these fonts:

Cormorant[1][2]

  • Styles: Cormorant, Garamond, Infant, SC, Unicase, Upright
  • Alternatives: Light, Light Italic, Regular, Italic, Medium, Medium Italic, SemiBold, SemiBold Italic, Bold, Bold Italic
  • Sizes: Text

PT[3]

  • Styles: Mono, Sans, Sans Narrow, Serif, Serif Narrow
  • Alternatives: Regular, Italic, Bold Italic
  • Sizes: Text, Caption

Libertinus[4]

  • Styles: Mono, Sans, Serif
  • Alternatives: Regular, Italic, Semibold, Semibold Italic, Bold, Bold Italic
  • Sizes: Text, Display

Following the ConTeXt Reference Manual[5] and the ConTeXt: Font Weights[6] answer on this site, I've tried (read the comments, they're important):

% I don't know if features go with `definetypeface` or `definefontsynonym`. The
% reference manual shows it both ways. Perhaps it is a MkII vs MkIV thing?
\starttypescript [cormorant]
    \definetypeface[cormorant] [rmcm] [serifcormorant]  [cormorant] [default] [features=default]
    \definetypeface[cormorant] [rmgm] [serifgaramond]   [cormorant] [default] [features=default]
    \definetypeface[cormorant] [rmif] [serifinfant]     [cormorant] [default] [features=default]
    \definetypeface[cormorant] [rmur] [serifupright]    [cormorant] [default] [features=default]
    % Right, so these two are both provided as uppercase-only font files. Since the
    % fonts come this way, we don't need to use `features=smallcaps` to switch
    % smallcaps on. Right?
    \definetypeface[cormorant] [rmuc] [serifunicase]    [cormorant] [default] [features=default]
    \definetypeface[cormorant] [rmsc] [serifsc]         [cormorant] [default] [features=default]
\stoptypescript

% Do this for each style:
% ...
\starttypescript [serifcormorant] [cormorant] [name]
    \definefontsynonym [SerifLight]             [name:CormorantLight]
    \definefontsynonym [SerifLightItalic]       [name:CormorantLightItalic]
    \definefontsynonym [Serif]                  [name:CormorantRegular]
    \definefontsynonym [SerifItalic]            [name:CormorantItalic]
    \definefontsynonym [SerifMedium]            [name:CormorantMedium]
    \definefontsynonym [SerifMediumItalic]      [name:CormorantMediumItalic]
    \definefontsynonym [SerifSemiBold]          [name:CormorantSemiBold]
    \definefontsynonym [SerifSemiBoldItalic]    [name:CormorantSemiBoldItalic]
    \definefontsynonym [SerifBold]              [name:CormorantBold]
    \definefontsynonym [SerifBoldItalic]        [name:CormorantBoldItalic]
\stoptypescript

% Do this for each style:
% ...
\starttypescript [serifcormorant] [default] [size]
    \definebodyfont [default] [rmcm]
        % Additional size/alternative combinations are automatically created by
        % ConTeXt.
        %
        % Also according to the manual `definebodyfont` automatically creates macros
        % for each argument, i.e. the `\lt` macro and the `\li` macro and so on are all
        % automatically created by this command.
        [lt=SerifLight sa 1,
         li=SerifLightItalic sa 1,
         tf=Serif sa 1,
         it=SerifItalic sa 1,
         md=SerifMedium sa 1,
         mi=SerifMediumItalic sa 1,
         sb=SerifSemiBold sa 1,
         si=SerifSemiBoldItalic sa 1,
         bf=SerifBold sa 1,
         bi=SerifBoldItalic sa 1,
        ]

% Here we should probably link the standard style macros to the new variants:
%   \rm -> rmcm
%   \sc -> rmsc
% Somehow...

% Right now there are 60 style-alternatives combinations (6 styles * 10
% alternatives). They are duplicated for each `definebodyfont` and
% `definefontsynonym` groups. Alternatively, instead of 6 styles, we can
% keep one style (roman/serif) and define a massive list of 60 alternatives
% in `\definebodyfont` (SerifLight, GaramondSerifLight, InfantSerifLight,
% ..., Serif, GaramondSerif, InfantSerif, ..., SerifBold,
% GaramondSerifBold, InfantSerifBold, ...), which is about half as much
% text. There are enough two-letter combinations (576>60) but they wouldn't
% make sense as abbreviations. Rather, I'd chose alternatives as [aa, ab,
% ac, ad, ..., ba, bb, bc, bd, ...]. I also think it would be confusing to
% mix true *styles* with *alternatives*.

Well that was pretty depressing and also doesn't work, but lets move on to varying fonts sizes anyway.

\starttypescript [libertinus]
    \definetypeface[libertinus] [rm] [serif] [libertinus] [default]
    \definetypeface[libertinus] [ss] [sans]  [libertinus] [default]
    \definetypeface[libertinus] [tt] [mono]  [libertinus] [default]
\stoptypescript

% Do this for each style:
% ...
% Keep in mind that unlike the cormorant font, each style does not have every
% possible alternative. For example, "Sans" is lacking all SemiBold variations
% as well as BoldItalic.
\starttypescript [serif] [libertinus] [name]
    \definefontsynonym [Serif]                  [name:LibertinusSerifRegular]
    \definefontsynonym [SerifItalic]            [name:LibertinusSerifRegular]
    \definefontsynonym [SerifSemiBold]          [name:LibertinusSerifSemiBold]
    \definefontsynonym [SerifSemiBoldItalic]    [name:LibertinusSerifSemiBoldItalic]
    \definefontsynonym [SerifBold]              [name:LibertinusSerifBold]
    \definefontsynonym [SerifBoldItalic]        [name:LibertinusSerifBoldItalic]
    % And now for the font size variants:
    \definefontsynonym [SerifDisplay]           [name:LibertinusSerifDisplayRegular]
    % ... which happen to be defined only for the regular alternative of the serif style.
\stoptypescript

% Do this for each style. However only the serif style provides the *display*
% sizes, and without any alternatives.
\starttypescript
    % According to the reference manual section 5.8.1, when `\setupbodyfont` and
    % `\switchtobodyfont` are given undefined font sizes, they will extrapolate
    % values from the nearest smaller body font environment. Unfortunately this
    % only applies to relative font environments and not individual fonts. So I
    % have to specify every font size, otherwise the default case is used. Which is
    % impossible.
    %
    % For example, I want:
    %   >=20pt
    % What I have to do:
    %   20pt, 20.001pt, 20.01pt, 20.1pt, 20.101pt, 20.11pt, ..., 20.999pt, ..., 21pt, ..., 22pt, ..., 30pt, ..., 100pt, ..., Infpt
    % What I actually end up doing. Some terminal-foo plus copy-paste:
    %   $ python3 -c 'print("pt, ".join(map(lambda i: str(i/2),range(40,200))) + "pt")'
    \definebodyfont [20.0pt,20.5pt,21.0pt,21.5pt,22.0pt,22.5pt,23.0pt,23.5pt,24.0pt,24.5pt,25.0pt,25.5pt,26.0pt,26.5pt,27.0pt,27.5pt,28.0pt,28.5pt,29.0pt,29.5pt,30.0pt,30.5pt,31.0pt,31.5pt,32.0pt,32.5pt,33.0pt,33.5pt,34.0pt,34.5pt,35.0pt,35.5pt,36.0pt,36.5pt,37.0pt,37.5pt,38.0pt,38.5pt,39.0pt,39.5pt,40.0pt,40.5pt,41.0pt,41.5pt,42.0pt,42.5pt,43.0pt,43.5pt,44.0pt,44.5pt,45.0pt,45.5pt,46.0pt,46.5pt,47.0pt,47.5pt,48.0pt,48.5pt,49.0pt,49.5pt,50.0pt,50.5pt,51.0pt,51.5pt,52.0pt,52.5pt,53.0pt,53.5pt,54.0pt,54.5pt,55.0pt,55.5pt,56.0pt,56.5pt,57.0pt,57.5pt,58.0pt,58.5pt,59.0pt,59.5pt,60.0pt,60.5pt,61.0pt,61.5pt,62.0pt,62.5pt,63.0pt,63.5pt,64.0pt,64.5pt,65.0pt,65.5pt,66.0pt,66.5pt,67.0pt,67.5pt,68.0pt,68.5pt,69.0pt,69.5pt,70.0pt,70.5pt,71.0pt,71.5pt,72.0pt,72.5pt,73.0pt,73.5pt,74.0pt,74.5pt,75.0pt,75.5pt,76.0pt,76.5pt,77.0pt,77.5pt,78.0pt,78.5pt,79.0pt,79.5pt,80.0pt,80.5pt,81.0pt,81.5pt,82.0pt,82.5pt,83.0pt,83.5pt,84.0pt,84.5pt,85.0pt,85.5pt,86.0pt,86.5pt,87.0pt,87.5pt,88.0pt,88.5pt,89.0pt,89.5pt,90.0pt,90.5pt,91.0pt,91.5pt,92.0pt,92.5pt,93.0pt,93.5pt,94.0pt,94.5pt,95.0pt,95.5pt,96.0pt,96.5pt,97.0pt,97.5pt,98.0pt,98.5pt,99.0pt,99.5pt] [rm]
        % Which is sub-par because TeX defaults to oddly specific font-sizes:
        %   12pt, 14.4pt, 17.3pt, 20.7pt, ...
        %
        % I also don't know what concrete sizes to use for suggestions like "caption"
        % or "display". Less than 9pt, 8pt, 5pt? More than 20pt, 30pt, 40pt?
        [tf=SerifDisplay sa 1,
         it=SerifItalic sa 1,
         sb=SerifSemiBold sa 1,
         si=SerifSemiBoldItalic sa 1,
         bf=SerifBold sa 1,
         bi=SerifBoldItalic sa 1,
        ]
    % The catch-all case:
    \definebodyfont [default] [rm]
        [tf=Serif sa 1,
         it=SerifItalic sa 1,
         sb=SerifSemiBold sa 1,
         si=SerifSemiBoldItalic sa 1,
         bf=SerifBold sa 1,
         bi=SerifBoldItalic sa 1,
        ]
\stoptypescript

Even more depressing: this doesn't work either.

Links:

  1. https://github.com/CatharsisFonts/Cormorant
  2. https://www.behance.net/gallery/28579883/Cormorant-an-open-source-display-font-family
  3. https://company.paratype.com/pt-sans-pt-serif
  4. https://github.com/libertinus-fonts/libertinus
  5. http://pmrb.free.fr/contextref.pdf
  6. https://tex.stackexchange.com/a/324318/174577
11
  • 1
    The easiest solution is to create additional typefaces for the medium/semibold weights and also extra ones for the unicase etc. styles. While you can create an alternative for the medium weight the predefined font switches (e.g. \em) don’t work with them. Nov 20, 2018 at 20:01
  • 1
    Usually you would define different typescripts for each weight, i.e. cormorant and cormorant-light. It is highly unlikely that you want to regularly switch between regular and light weight and this way you can do it using \switchtobodyfont. Nov 20, 2018 at 20:40
  • @HenriMenke For what you recommend, there's no reason not to use simplefonts (as integrated into ConTeXt core), is there?
    – user19087
    Nov 21, 2018 at 3:51
  • 1
    @user19087 See the typescript type-imp-ghz.mkiv for an example of what I mean. Nov 21, 2018 at 4:01
  • 1
    @HenriMenke However isn't the process I outlined above exactly what \definefontfamily from simplefonts does? If I'm not defining extra style or alternatives, why don't I just use that?
    – user19087
    Nov 21, 2018 at 6:32

1 Answer 1

4

Here is how I would design a typescript for Cormorant. This does not map all the different combinations of weight and style because a lot of them don't make too much sense.

\starttypescriptcollection[cormorant]

  \starttypescript [cormorant,cormorant-light,cormorant-garamond,cormorant-infant,cormorant-unicase]
    \definetypeface [\typescriptone] [rm] [serif] [\typescriptone] [default]
    \definetypeface [\typescriptone] [ss] [sans]  [modern]         [default]
    \definetypeface [\typescriptone] [tt] [mono]  [modern]         [default]
    \definetypeface [\typescriptone] [mm] [math]  [modern]         [default]
    \quittypescriptscanning
  \stoptypescript

  \starttypescript [serif] [cormorant,cormorant-light,cormorant-garamond,cormorant-infant,cormorant-unicase]

    \definefontsynonym [Cormorant-BoldItalic]             [file:Cormorant-BoldItalic]             [features=default]
    \definefontsynonym [Cormorant-Bold]                   [file:Cormorant-Bold]                   [features=default]
    \definefontsynonym [CormorantGaramond-BoldItalic]     [file:CormorantGaramond-BoldItalic]     [features=default]
    \definefontsynonym [CormorantGaramond-Bold]           [file:CormorantGaramond-Bold]           [features=default]
    \definefontsynonym [CormorantGaramond-Italic]         [file:CormorantGaramond-Italic]         [features=default]
    \definefontsynonym [CormorantGaramond-LightItalic]    [file:CormorantGaramond-LightItalic]    [features=default]
    \definefontsynonym [CormorantGaramond-Light]          [file:CormorantGaramond-Light]          [features=default]
    \definefontsynonym [CormorantGaramond-MediumItalic]   [file:CormorantGaramond-MediumItalic]   [features=default]
    \definefontsynonym [CormorantGaramond-Medium]         [file:CormorantGaramond-Medium]         [features=default]
    \definefontsynonym [CormorantGaramond-Regular]        [file:CormorantGaramond-Regular]        [features=default]
    \definefontsynonym [CormorantGaramond-SemiBoldItalic] [file:CormorantGaramond-SemiBoldItalic] [features=default]
    \definefontsynonym [CormorantGaramond-SemiBold]       [file:CormorantGaramond-SemiBold]       [features=default]
    \definefontsynonym [CormorantInfant-BoldItalic]       [file:CormorantInfant-BoldItalic]       [features=default]
    \definefontsynonym [CormorantInfant-Bold]             [file:CormorantInfant-Bold]             [features=default]
    \definefontsynonym [CormorantInfant-Italic]           [file:CormorantInfant-Italic]           [features=default]
    \definefontsynonym [CormorantInfant-LightItalic]      [file:CormorantInfant-LightItalic]      [features=default]
    \definefontsynonym [CormorantInfant-Light]            [file:CormorantInfant-Light]            [features=default]
    \definefontsynonym [CormorantInfant-MediumItalic]     [file:CormorantInfant-MediumItalic]     [features=default]
    \definefontsynonym [CormorantInfant-Medium]           [file:CormorantInfant-Medium]           [features=default]
    \definefontsynonym [CormorantInfant-Regular]          [file:CormorantInfant-Regular]          [features=default]
    \definefontsynonym [CormorantInfant-SemiBoldItalic]   [file:CormorantInfant-SemiBoldItalic]   [features=default]
    \definefontsynonym [CormorantInfant-SemiBold]         [file:CormorantInfant-SemiBold]         [features=default]
    \definefontsynonym [Cormorant-Italic]                 [file:Cormorant-Italic]                 [features=default]
    \definefontsynonym [Cormorant-LightItalic]            [file:Cormorant-LightItalic]            [features=default]
    \definefontsynonym [Cormorant-Light]                  [file:Cormorant-Light]                  [features=default]
    \definefontsynonym [Cormorant-MediumItalic]           [file:Cormorant-MediumItalic]           [features=default]
    \definefontsynonym [Cormorant-Medium]                 [file:Cormorant-Medium]                 [features=default]
    \definefontsynonym [Cormorant-Regular]                [file:Cormorant-Regular]                [features=default]
    \definefontsynonym [CormorantSC-Bold]                 [file:CormorantSC-Bold]                 [features=smallcaps]
    \definefontsynonym [CormorantSC-Light]                [file:CormorantSC-Light]                [features=smallcaps]
    \definefontsynonym [CormorantSC-Medium]               [file:CormorantSC-Medium]               [features=smallcaps]
    \definefontsynonym [CormorantSC-Regular]              [file:CormorantSC-Regular]              [features=smallcaps]
    \definefontsynonym [CormorantSC-SemiBold]             [file:CormorantSC-SemiBold]             [features=smallcaps]
    \definefontsynonym [Cormorant-SemiBoldItalic]         [file:Cormorant-SemiBoldItalic]         [features=default]
    \definefontsynonym [Cormorant-SemiBold]               [file:Cormorant-SemiBold]               [features=default]
    \definefontsynonym [CormorantUnicase-Bold]            [file:CormorantUnicase-Bold]            [features=default]
    \definefontsynonym [CormorantUnicase-Light]           [file:CormorantUnicase-Light]           [features=default]
    \definefontsynonym [CormorantUnicase-Medium]          [file:CormorantUnicase-Medium]          [features=default]
    \definefontsynonym [CormorantUnicase-Regular]         [file:CormorantUnicase-Regular]         [features=default]
    \definefontsynonym [CormorantUnicase-SemiBold]        [file:CormorantUnicase-SemiBold]        [features=default]
    \definefontsynonym [CormorantUpright-Bold]            [file:CormorantUpright-Bold]            [features=default]
    \definefontsynonym [CormorantUpright-Light]           [file:CormorantUpright-Light]           [features=default]
    \definefontsynonym [CormorantUpright-Medium]          [file:CormorantUpright-Medium]          [features=default]
    \definefontsynonym [CormorantUpright-Regular]         [file:CormorantUpright-Regular]         [features=default]
    \definefontsynonym [CormorantUpright-SemiBold]        [file:CormorantUpright-SemiBold]        [features=default]

  \stoptypescript

  \starttypescript [serif] [cormorant] [name]

    \definefontsynonym [Serif]            [Cormorant-Regular]
    \definefontsynonym [SerifItalic]      [Cormorant-Italic]
    \definefontsynonym [SerifBold]        [Cormorant-Bold]
    \definefontsynonym [SerifBoldItalic]  [Cormorant-BoldItalic]
    \definefontsynonym [SerifSlanted]     [SerifItalic]
    \definefontsynonym [SerifBoldSlanted] [SerifBoldItalic]
    \definefontsynonym [SerifCaps]        [CormorantSC-Regular]

  \stoptypescript

  \starttypescript [serif] [cormorant-light] [name]

    \definefontsynonym [Serif]            [Cormorant-Light]
    \definefontsynonym [SerifItalic]      [Cormorant-LightItalic]
    \definefontsynonym [SerifBold]        [Cormorant-SemiBold]
    \definefontsynonym [SerifBoldItalic]  [Cormorant-SemiBoldItalic]
    \definefontsynonym [SerifSlanted]     [SerifItalic]
    \definefontsynonym [SerifBoldSlanted] [SerifBoldItalic]
    \definefontsynonym [SerifCaps]        [CormorantSC-Light]

  \stoptypescript

  \starttypescript [serif] [cormorant-garamond] [name]

    \definefontsynonym [Serif]            [CormorantGaramond-Regular]
    \definefontsynonym [SerifItalic]      [CormorantGaramond-LightItalic]
    \definefontsynonym [SerifBold]        [CormorantGaramond-Bold]
    \definefontsynonym [SerifBoldItalic]  [CormorantGaramond-BoldItalic]
    \definefontsynonym [SerifSlanted]     [SerifItalic]
    \definefontsynonym [SerifBoldSlanted] [SerifBoldItalic]

  \stoptypescript

  \starttypescript [serif] [cormorant-infant] [name]

    \definefontsynonym [Serif]            [CormorantInfant-Regular]
    \definefontsynonym [SerifItalic]      [CormorantInfant-LightItalic]
    \definefontsynonym [SerifBold]        [CormorantInfant-Bold]
    \definefontsynonym [SerifBoldItalic]  [CormorantInfant-BoldItalic]
    \definefontsynonym [SerifSlanted]     [SerifItalic]
    \definefontsynonym [SerifBoldSlanted] [SerifBoldItalic]

  \stoptypescript

  \starttypescript [serif] [cormorant-unicase] [name]

    \definefontsynonym [Serif]            [CormorantUnicase-Regular]
    \definefontsynonym [SerifItalic]      [CormorantUnicase-LightItalic]
    \definefontsynonym [SerifBold]        [CormorantUnicase-Bold]
    \definefontsynonym [SerifBoldItalic]  [CormorantUnicase-BoldItalic]
    \definefontsynonym [SerifSlanted]     [SerifItalic]
    \definefontsynonym [SerifBoldSlanted] [SerifBoldItalic]

  \stoptypescript

\stoptypescriptcollection

Here is how to use it:

\setupbodyfont[cormorant]
\setupbodyfont[cormorant-light]
\setupbodyfont[cormorant-garamond]
\setupbodyfont[cormorant-infant]
\setupbodyfont[cormorant-unicase]

\setupwhitespace[medium]

\starttext

\switchtobodyfont[cormorant]
\samplefile{ward}

\bold{\samplefile{ward}}

\italic{\samplefile{ward}}

\smallcaps{\samplefile{ward}}

\page

\switchtobodyfont[cormorant-light]
\samplefile{ward}

\bold{\samplefile{ward}}

\italic{\samplefile{ward}}

\smallcaps{\samplefile{ward}}

\page

\switchtobodyfont[cormorant-garamond]
\samplefile{ward}

\bold{\samplefile{ward}}

\italic{\samplefile{ward}}

\smallcaps{\samplefile{ward}}

\page

\switchtobodyfont[cormorant-infant]
\samplefile{ward}

\bold{\samplefile{ward}}

\italic{\samplefile{ward}}

\smallcaps{\samplefile{ward}}

\page

\switchtobodyfont[cormorant-unicase]
\samplefile{ward}

\bold{\samplefile{ward}}

\italic{\samplefile{ward}}

\smallcaps{\samplefile{ward}}

\stoptext

Click to enlarge image:

enter image description here

2
  • Why is features=smallcaps required for a font that is already smallcaps-specialized?
    – user19087
    Nov 29, 2018 at 4:07
  • @user19087 If it works without, set it to features=default if you like, Nov 29, 2018 at 4:14

You must log in to answer this question.

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