4

I really don't see any proper guide on how to load fonts in Context. There are a lot of different functions for fonts, family and typescript without a proper explanations on how to use them or the difference between them.

If I want to use Source Sans Pro as a sans-serif font with charter and mathdesign. How do I do it?

\loadtypescriptfile[mathdesign]
\definefontfamily [mainface] [rm]       [charter]
\definefontfamily [mainface] [ss]       [Source Sans Pro]
\definefontfamily [mainface] [math]     [charter]
% These don't work either
%\definefontfamily [mainface] [mm]      [charter]
%\definefontfamily [mainface] [mm]      [mathdesign]
\setupbodyfont[mainface,10pt]

It is not working in the sense that there is no compile time error. It simply compile the document with the default font.

  • 2
    Source Sans works fine for me that way. Has ConTeXt found the font (look into the log, there won't be an error if it doesn't find the font, just a log warning). – TeXnician Oct 23 '18 at 18:54
  • If you would like a detailed discussion of fonts in ConTeXt, you may want to considering checking out the fonts manual: pragma-ade.nl/general/manuals/fonts-mkiv.pdf – ssokolen Oct 23 '18 at 23:58
4

Typescripts for both Charter and Source Sans Pro are readily available in the ConTeXt system. Therefore it is natural to make use of these. However, the naïve approach does not work:

\definetypeface [mainface] [rm] [serif] [charter] [default]
\definetypeface [mainface] [ss] [sans]  [source]  [default]
\definetypeface [mainface] [tt] [mono]  [source]  [default]
\definetypeface [mainface] [mm] [math]  [charter] [default]
\setupbodyfont [mainface]

\starttext

\samplefile{knuth}

\sans{\samplefile{knuth}}

\stoptext

The resulting file will be typeset in all Charter and the log contains the message:

fonts           > defining > forced type 'ttf' of 'SourceSansPro-Regular' not found
fonts           > defining > font with asked name 'SourceSansPro-Regular' is not found using lookup 'file'
fonts           > defining > unknown font 'SourceSansPro-Regular', loading aborted

That is due to the fact that the type-imp-source.mkiv typescript hardcodes the .ttf extension but the file is distributed with TeX Live using the .otf extension. To fix this, simply copy the typescript to the working directory and remove all the .ttf extensions. On Linux (and probably also Mac OS) you can do that with these two commands.

$ cp `kpsewhich type-imp-source.mkiv` .
$ sed -i 's/\.ttf//g' type-imp-source.mkiv

Afterwards it should typeset normally. To be sure that ConTeXt uses the edited typescript file, check the log for a line like

open source     > level 3, order 5, name 'type-imp-source.mkiv'

enter image description here

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.