[Tex/LaTex] ConTeXt: Font weights

contextcontext-mkivdocumentationfonts

Is there a canonical way to access font weights other than regular and bold in ConTeXt? This does not work:

\definefontfamily [myfamily] [serif][Calluna]
\definefontfamily [myfamily] [sans] [Calluna Sans Light]

\setupbodyfont [myfamily]

\starttext
1. Avec Serif\\
{\ss 2. Sans Serif}
\blank
\it 3. Avec Serif\\
\ss\bi 4. Sans Serif
\stoptext

Line 1 and 3 come out OK, serif regular and serif regular italic; the lines containing \ss come out as serif regular. If I leave out the Light in the family definition everything works as expected, i.e. line 2 as sans serif regular and line 4 as sans serif bold italic.

I do have the fonts, Gnome Font Manager knows them and mtxrun --script fonts --list --all --pattern=Calluna* too:

calluna                     callunablack                /home/thomas/.local/share/fonts/exljbris - Calluna-Black.otf
callunablack                callunablack                /home/thomas/.local/share/fonts/exljbris - Calluna-Black.otf
callunabold                 callunabold                 /home/thomas/.local/share/fonts/exljbris - Calluna-Bold.otf
callunaboldit               callunaboldit               /home/thomas/.local/share/fonts/exljbris - Calluna-BoldIt.otf
callunabolditalic           callunaboldit               /home/thomas/.local/share/fonts/exljbris - Calluna-BoldIt.otf
callunait                   callunait                   /home/thomas/.local/share/fonts/exljbris - Calluna-It.otf
callunaitalic               callunait                   /home/thomas/.local/share/fonts/exljbris - Calluna-It.otf
callunalight                callunalight                /home/thomas/.local/share/fonts/exljbris - Calluna-Light.otf
callunanormal               callunait                   /home/thomas/.local/share/fonts/exljbris - Calluna-It.otf
callunaregular              callunaregular              /home/thomas/.local/share/fonts/exljbris - Calluna-Regular.otf
callunasans                 callunasansblack            /home/thomas/.local/share/fonts/CallunaSansBlack.otf
callunasansblack            callunasansblack            /home/thomas/.local/share/fonts/CallunaSansBlack.otf
callunasansblackitalic      callunasansblackitalic      /home/thomas/.local/share/fonts/CallunaSansBlackItalic.otf
callunasansbold             callunasansbold             /home/thomas/.local/share/fonts/CallunaSansBold.otf
callunasansbolditalic       callunasansbolditalic       /home/thomas/.local/share/fonts/CallunaSansBoldItalic.otf
callunasansdemibold         callunasanssemibold         /home/thomas/.local/share/fonts/CallunaSansSemiBold.otf
callunasansitalic           callunasansitalic           /home/thomas/.local/share/fonts/exljbris - CallunaSans-Italic.otf
callunasanslight            callunasanslight            /home/thomas/.local/share/fonts/CallunaSansLight.otf
callunasanslightitalic      callunasanslightitalic      /home/thomas/.local/share/fonts/CallunaSansLightItalic.otf
callunasansnormal           callunasansitalic           /home/thomas/.local/share/fonts/exljbris - CallunaSans-Italic.otf
callunasansregular          callunasansregular          /home/thomas/.local/share/fonts/exljbris - CallunaSans-Regular.otf
callunasanssemibold         callunasanssemibold         /home/thomas/.local/share/fonts/CallunaSansSemiBold.otf
callunasanssemibolditalic   callunasanssemibolditalic   /home/thomas/.local/share/fonts/CallunaSansSemiBoldItalic.otf
callunasemibold             callunasemibold             /home/thomas/.local/share/fonts/exljbris - Calluna-Semibold.otf
callunasemiboldit           callunasemiboldit           /home/thomas/.local/share/fonts/exljbris - Calluna-SemiboldIt.otf

Saying callunasanslight instead of Calluna Sans Light doesn't work either. What I'm trying to do is using Sans Light and Sans Semibold instead of Sans and Sans Bold. But it would also be nice to have font switches for light, semibold and heavy in addition to \bf and \tf.

BTW: The bigger question is really: Where does one find documentation on such stuff in ConTeXt??? ConTeXt is such a difficult word to google!

Edit: I found one way to work this, at least partially:

\definefontfamily [myfamily][sans] [Calluna Sans]
                  [tf=Calluna Sans Light,
                   it=Calluna Sans Light Italic,
                   bf=Calluna Sans SemiBold,
                   bi=Calluna Sans SemiBold Italic,
                   sc=Calluna Sans Light]

It is not in the definition or the description of \definefontfamily on contextgarden. There is no description there at all, just a number of examples.

Anyway, I'm still missing (a) the semibold smallcaps and (b) a way to make all the weights accessible "at the same time".

Best Answer

To access more alternatives with a single typeface you have to create first additional alternatives with the \definefontalternative command. For my example I add new definitions for a light and a medium style, for the name of the alternative itself you’re limited to two letter for each and you should ensure no important commands are overwritten, e.g. below I overwrite the language switch for lithuanian which can be ignored because you can still use \language[lt] in a document.

\definefontalternative[lt] % light
\definefontalternative[li] % lightitalic
\definefontalternative[md] % medium
\definefontalternative[mi] % mediumitalic

Now you can add entries for the light and medium styles in your typescript and map synonyms to the font files, for the names of the synonyms you should stick close the the default names, e.g. I used SerifLight for the light style if the font.

\starttypescript [serif] [antykwa-torunska-extended]
  \definefontsynonym [SerifLight]        [file:antykwatorunskalightregular] [features=default]
  \definefontsynonym [SerifLightItalic]  [file:antykwatorunskalightitalic]  [features=default]
  \definefontsynonym [Serif]             [file:antykwatorunskaRegular]      [features=default]
  \definefontsynonym [SerifItalic]       [file:antykwatorunskaitalic]       [features=default]
  \definefontsynonym [SerifMedium]       [file:antykwatorunskamedregular]    [features=default]
  \definefontsynonym [SerifMediumItalic] [file:antykwatorunskameditalic]   [features=default]
  \definefontsynonym [SerifBold]         [file:antykwatorunskabold]         [features=default]
  \definefontsynonym [SerifBoldItalic]   [file:antykwatorunskabolditalic]   [features=default]
  \definefontsynonym [SerifCaps]         [file:antykwatorunskaregular]      [features=smallcaps]
\stoptypescript

Now comes the important part where I assign the files for the light and medium styles to the additional alternatives which is done with the \definebodyfont command.

\starttypescript [serif] [antykwa-torunska-extended]
  \definebodyfont [default] [rm]
     [lt=SerifLight sa 1,
      li=SerifLightItalic sa 1,
      tf=Serif sa 1,
      it=SerifItalic sa 1,
      md=SerifMedium sa 1,
      mi=SerifMediumItalic sa 1,
      bf=SerifBold sa 1,
      bi=SerifBoldItalic sa 1,
      sc=SerifCaps sa 1]
\stoptypescript

After this is done you I can now create a new typeface which supports alternatives than the one provided by default (\tf, \it etc.).

\definetypeface[antykwa-torunska-extended][rm][serif][antykwa-torunska-extended][default]

\setupbodyfont[antykwa-torunska-extended]

\starttext

\starttabulate[|l|l|]
\NC \tex{lt} \NC \lt Light        \NC\NR
\NC \tex{li} \NC \li LightItalic  \NC\NR
\NC \tex{tf} \NC \tf Regular      \NC\NR
\NC \tex{it} \NC \it Italic       \NC\NR
\NC \tex{md} \NC \md Medium       \NC\NR
\NC \tex{mi} \NC \mi MediumItalic \NC\NR
\NC \tex{bf} \NC \bf Bold         \NC\NR
\NC \tex{bi} \NC \bi BoldItalic   \NC\NR
\NC \tex{sc} \NC \sc SmallCaps    \NC\NR
\stoptabulate

\stoptext

Example with new font alternatives for ConTeXt

Related Question