4

Is there a way For ConTeXt to use uninstalled .otf files in an arbitrary folder?

In my current LaTeX files, for example, I have:

\setmainfont{ProximaNova}[
    UprightFont=*-Regular,
    ItalicFont=*-RegularItalic,
    BoldFont=*-Bold,
    BoldItalicFont=*-BoldItalic,
    Path=../../fonts/ProximaNova/,
    Extension=.otf]

It picks up the font files from a specific folder where I store all of my fonts. The naming is sometimes different between fonts so they are spec'ed in setmainfont.

The best I can tell from this question and documentation is that ConTeXt needs to read the fonts from some OSFONTDIR, which can be more can one folder, but must be specified in this variable. I can't use just any .otf files, specified directly in the .tex file. Or am I misreading? I don't think I saw anything indicating that typescript can take paths to files?

1
  • While you may call fonts by file name, the font has to be in the font name database. The easiest approach is to have a script that runs mtxrun wirh appropriate parameters to update the database.
    – TeXnician
    Nov 22, 2018 at 16:27

1 Answer 1

5

I don't have the Proxima Nova font, but I just downloaded the Cormorant font, so I'll use this one. Then I use \definefontfamily to set up the font.

\definefontfamily [mainface] [serif] [Latin Modern Roman]
                  [tf=file:Cormorant-Regular.ttf,
                   it=file:Cormorant-Italic.ttf,
                   bf=file:Cormorant-Bold.ttf,
                   bi=file:Cormorant-BoldItalic.ttf,
                   sc=file:CormorantSC-Regular.ttf]
\definefontfamily [mainface] [sans] [Latin Modern Sans]
\definefontfamily [mainface] [mono] [Latin Modern Mono] [features=none]
\definefontfamily [mainface] [math] [Latin Modern Math]
\setupbodyfont [mainface]

\starttext

\samplefile{knuth}

\stoptext

I could have hardcoded the complete file path but that is too unflexible in my opinion. Instead I pass an appropriate value of OSFONTDIR to ConTeXt, as such

OSFONTDIR="~/Downloads/Cormorant_Install_v3.601/1. TrueType Font Files" context test.mkvi

enter image description here

4
  • @Roxy You can also define a typescript, which is actually my preferred way. \definefontfamily is document in the Garden: wiki.contextgarden.net/Command/definefontfamily Nov 22, 2018 at 22:46
  • Thanks. If you are using new font files, why do the commands have to reference an unrelated font, i.e. Latin Modern Roman in your example?
    – Roxy
    Nov 22, 2018 at 22:46
  • @Roxy Fallback purposes. Nov 22, 2018 at 23:15
  • 1
    Can you please tell me how to hardcode the path to the font file? I tried: \definefontfamily [mainface] [serif] [My Font] [tf=file:./fonts/myfont.otf] but that results in an error.
    – Kresimir
    Nov 15, 2019 at 10:39

You must log in to answer this question.

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