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:
- https://github.com/CatharsisFonts/Cormorant
- https://www.behance.net/gallery/28579883/Cormorant-an-open-source-display-font-family
- https://company.paratype.com/pt-sans-pt-serif
- https://github.com/libertinus-fonts/libertinus
- http://pmrb.free.fr/contextref.pdf
- https://tex.stackexchange.com/a/324318/174577
\em
) don’t work with them.cormorant
andcormorant-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
.type-imp-ghz.mkiv
for an example of what I mean.\definefontfamily
from simplefonts does? If I'm not defining extra style or alternatives, why don't I just use that?