21

I'm trying to use Cambria for text and Calibri for headings in a ConTeXt document, but I don't understand what is happening at all, nothing seems to have any effect and in the end it falls back to LMRoman/LMSans.

As a minimal starting point, I'm trying to recreate this document. I can just compile it with lualatex and it finds my fonts, they are installed system-wide through fontconfig. pdffonts shows that two TrueType faces from each family are embedded, nothing else.

\documentclass{minimal}
\usepackage{fontspec}
\setmainfont{Cambria}
\setsansfont{Calibri}
\begin{document}
Cambria \textsf{Calibri}
\emph{Cambria \textsf{Calibri}}
\end{document}

output1

How do I create this document using ConTeXt? I tried this:

\setupbodyfont[Cambria]
%no idea how to set sans
\starttext
Cambria \sans{Calibri}
\em{Cambria \sans{Calibri}}
\stoptext

output2

But only got LM, the log contained an error about loc, which isn't mentioned in my file, is this a bug in the typefile? It seems to try to do something with the argument but fails before loading...

fonts           > typescripts > unknown library 'loc'
(/usr/local/texlive/2013/texmf-dist/tex/context/base/type-imp-cambria.mkiv)

As far as I understand, both fontspec and ConTeXt use luatex' facilities to locate and load the fonts, so I don't have to install them manually, is that true? In my installation, type-otf.mkiv is empty except for a comment claiming that it's unnecessary since OTF fonts can be found by name.


With

\setupbodyfont[libertine]
\starttext ...

output3

I get Biolinum as the roman font and Libertine as sans, but only for the first \sans, everything in \em is roman.

1
  • OT: Note that \em is a font switch, so you have to use {\em .... }.
    – Aditya
    Oct 28, 2013 at 4:35

2 Answers 2

20

There are three ways to use system fonts.

  1. Write your own typescript. ConTeXt comes with the typescripts for most system fonts. See type-imp-*.mkiv for details. For example, the typescript for calibra is defined in type-imp-calibra.mkiv and the typescript for calibiri is defined in type-imp-cleartype.mkiv. To use them, you need to define your own typescript that sets the serif and sans serif fonts. For example (not that \em is font switch, not a font command):

    \usetypescriptfile[cleartype]
    
    \starttypescript[mainface]
      \definetypeface  [mainface] [rm] [serif] [cambria] [default]
      \definetypeface  [mainface] [ss] [sans]  [calibri] [default]
      \definetypeface  [mainface] [tt] [mono]  [consolas][default]
      \definetypeface  [mainface] [mm] [math]  [cambria] [default]
    \stoptypescript
    
    \setupbodyfont[mainface]
    
    \starttext
    Cambria \sans{Calibri}
    {\em Cambria \sans{Calibri}}
    \stoptext
    

    which gives

    enter image description here

  2. The other option is to use the simplefonts module, which will automatically create appropriate typescript fonts. For example:

    \usemodule[simplefonts]
    
    \setmainfont[Cambria]
    \setsansfont[Calibri]
    

    which gives the same result as before.

  3. In recent versions of ConTeXt MKIV the simplefonts module has been superseded by \definefontfamily which is part of the core.

    \definefontfamily [mainface] [rm] [Cambria]
    \definefontfamily [mainface] [ss] [Calibri]
    \definefontfamily [mainface] [tt] [Consolas]
    \definefontfamily [mainface] [mm] [Asana Math]
    
    \setupbodyfont[mainface]
    

    This has the same effect as the above. Keep in mind though that you have to set all typefaces, i.e. rm, ss, tt, mm. Otherwise strange things might happen.

6
  • Simplefonts looks great, however using your example, everything is set in LMMonoPropLt10-Regular for me and the log complains simplefonts > font ''cambria'' not found and simplefonts > font ''calibri'' not found
    – pascal
    Oct 28, 2013 at 14:18
  • The typescript example produces empty output, not even using the LM fallback, and I get font with asked name 'cambria' is not found using lookup 'name' and font with asked name 'calibri' is not found using lookup 'file'
    – pascal
    Oct 28, 2013 at 14:21
  • running with OSFONTDIR=~/.fonts doesn't change anything, but giving the exact subfolder which contains cambria.ttc etc as OSFONTDIR=~/.fonts/fonts/microsoft/ it works fully for typescript, italics missing for simplefonts.
    – pascal
    Oct 28, 2013 at 14:26
  • OK, I think I got it. After running OSFONTDIR=~/.fonts/fonts/microsoft/ mtxrun --script fonts --reload I can just run context without setting OSFONTDIR and simplefonts even finds the italics. Just running mtxrun --script fonts --reload again deletes the cache and only finds fonts in /usr/local/texlive/2013/. I expected that script to use my system's fontconfig paths, as lualatex appears to do.
    – pascal
    Oct 28, 2013 at 14:35
  • 1
    I think the order of examples should be different. Simplefonts solution should be given in the first place. There is hardly any need for typescripts anymore unless you need a very unusual setup.
    – helcim
    May 11, 2015 at 7:30
4

As easy as executing the following command...

If your OSFONTDIR environment variable is set correctly, then installing (new) system fonts in modern versions of ConTeXt should be as easy as executing the following command:

$ mtxrun --script fonts --reload
1
  • this is exactly what i needed
    – Ibn Saeed
    Jan 1, 2016 at 13:32

You must log in to answer this question.

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