Difference between revisions of "Use the fonts you want"

From Wiki
Jump to navigation Jump to search
Line 25: Line 25:
 
= Practical application #1 - Quick use of a new font =
 
= Practical application #1 - Quick use of a new font =
  
Let's take a example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. If it is already installed on your computer, go directly to '''#2'''.
+
Let's take a example: we want to use [https://fonts.google.com/specimen/Noto+Serif Noto Serif]. If it is already installed on your computer, and you already update the databases like shown previously, go directly to '''#2'''.
  
 
It not, you have to download it first. Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).
 
It not, you have to download it first. Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).

Revision as of 19:47, 2 June 2020

Fonts location on your computer

The first step is to declare the storage locations of the fonts you want ConTeXt to consider.

Either way, ConTeXt will use fonts properly stored in its tree structure (for example, any fonts you would have downloaded from Fonts Squirrel Google Fonts).

  • TeX users create a new folder for each new font in tex/texmf-fonts/fonts/, following TeX Directory Structure.
    • it helps the algorithms to deal with the incredibly wide variety of fonts's variables and parameters.
    • People who handle a lot of fonts can be more structured by using tex/texmf-fonts/fonts/truetype/vendor/fontfamily.

But it it's very likely that you also want to use the fonts already available on your Operating System:

1. Specify where ConTeXt should looked for fonts, by setting the OSFONTDIR environment variable.
  • WINDOWS: set OSFONTDIR=c:/windows/fonts/
  • MAC: export OSFONTDIR=/Library/Fonts/;/System/Library/Fonts;$HOME/Library/Fonts
  • GNU/LINUX: export OSFONTDIR=/Library/Fonts/;/System/Library/Fonts;$HOME/Library/Fonts
  • Add it to your .bashrc or shell equivalent to make the declaration permanent.
2. Run ConTeXt to index the files
  • update of the file database: mtxrun --generate
  • update of the fonts database: mtxrun --script font --reload
3. Check by looking for the specific font you want to use next
  • a very common example mtxrun --script font --list --file -pattern=*helvetica*

Now, let's learn how to use them for typesetting.


Practical application #1 - Quick use of a new font

Let's take a example: we want to use Noto Serif. If it is already installed on your computer, and you already update the databases like shown previously, go directly to #2.

It not, you have to download it first. Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic).

#1. Store them is a dedicated folder indexed by ConTeXt.
  • create a "Noto-serif" in the ConTeXt distribution tex/texmf-fonts/fonts/.
  • unzip and store the .ttf file in tex/texmf-fonts/fonts/Noto-serif/.
  • Regenerate ConTeXt databases
    • the file database: mtxrun --generate
    • the fonts database: mtxrun --script font --reload
#2. Check the fontname used to identify the fonts
run mtxrun --script font --list --file -pattern=*noto*:
familyname   weight   style    width    variant   fontname              filename                   subfont   fontweight

notoserif    bold     normal   normal   normal    notoserifbold         NotoSerif-Bold.ttf
notoserif    bold     italic   normal   normal    notoserifbolditalic   NotoSerif-BoldItalic.ttf
notoserif    normal   italic   normal   normal    notoserifitalic       NotoSerif-Italic.ttf
notoserif    normal   normal   normal   normal    notoserif             NotoSerif-Regular.ttf
#3. Your are done! You can use the font anywhere in your input files with \definedfont
  • and add *default to enable default features, like for example kerning.
\definedfont[name:notoserifbolditalic*default at 12 pt]
The quick brown fox jumps over the lazy dog

result of test with noto-serif one.png

Practical application #2 - Use the different font variations


#1. Define a new typescript in your input file, with \starttypescript.
  • Define the links between filenames and People-readable names with \definefontsynonym.
  • In this example, the typescript is called "mynotoserif".
  • Reminder: you find the filenames for the Noto Serif fonts with mtxrun --script font --list --file -pattern=*noto*:
\starttypescript [mynotoserif]
% \definefontsynonym[Human readable]       [file:filename without extension]
  \definefontsynonym[NotoSerif-Regular]    [file:NotoSerif-Regular]
  \definefontsynonym[NotoSerif-Italic]     [file:NotoSerif-Italic]
  \definefontsynonym[NotoSerif-Bold]       [file:NotoSerif-Bold]
  \definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]
\stoptypescript
#2. The boring step, define the links between ConTeXt basics names and the People-readable names.
  • It's good to add a fallback.
\starttypescript [mynotoserif]
  \setups[font:fallback:serif]          % security: if not found==> bask to defaults
% \definefontsynonym[ConTeXt bascics name] [Human readable]       [features=default]
  \definefontsynonym[Serif]                [NotoSerif-Regular]    [features=default]
  \definefontsynonym[SerifItalic]          [NotoSerif-Italic]     [features=default]
  \definefontsynonym[SerifBold]            [NotoSerif-Bold]       [features=default]
  \definefontsynonym[SerifBoldItalic]      [NotoSerif-BoldItalic] [features=default]
\stoptypescript
#3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" 
\starttypescript [mynotoserif]
  \definetypeface [mynotoserif]    [rm] [serif] [mynotoserif]    [default]
\stoptypescript
#4. You are done! Finally, we have the following input file
\starttypescript [mynotoserif]
  \definefontsynonym[NotoSerif-Regular]    [file:NotoSerif-Regular]
  \definefontsynonym[NotoSerif-Italic]     [file:NotoSerif-Italic]
  \definefontsynonym[NotoSerif-Bold]       [file:NotoSerif-Bold]
  \definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]
\stoptypescript

\starttypescript [mynotoserif]
  \setups[font:fallback:serif]
  \definefontsynonym[Serif]                [NotoSerif-Regular]    [features=default]
  \definefontsynonym[SerifItalic]          [NotoSerif-Italic]     [features=default]
  \definefontsynonym[SerifBold]            [NotoSerif-Bold]       [features=default]
  \definefontsynonym[SerifBoldItalic]      [NotoSerif-BoldItalic] [features=default]
\stoptypescript

\starttypescript [mynotoserif]
  \definetypeface [mynotoserif]    [rm] [serif] [mynotoserif]    [default]
\stoptypescript

\setupbodyfont[mynotoserif]
\setupbodyfont[12pt]
{    The quick brown fox jumps over the lazy dog}\\
{\it The quick brown fox jumps over the lazy dog}\\
{\bf The quick brown fox jumps over the lazy dog}\\
{\bi The quick brown fox jumps over the lazy dog}\\

And it gives:

result of test with noto-serif.png


Install your new typescript to use it anywhere

You will probably want to use your new customized typescript definition across different documents, so you have to install them in the distribution. Here is the definition.

\starttypescript [mynotoserif]
  \definefontsynonym[NotoSerif-Regular]    [file:NotoSerif-Regular]
  \definefontsynonym[NotoSerif-Italic]     [file:NotoSerif-Italic]
  \definefontsynonym[NotoSerif-Bold]       [file:NotoSerif-Bold]
  \definefontsynonym[NotoSerif-BoldItalic] [file:NotoSerif-BoldItalic]
\stoptypescript

\starttypescript [mynotoserif]
  \setups[font:fallback:serif]
  \definefontsynonym[Serif]                [NotoSerif-Regular]    [features=default]
  \definefontsynonym[SerifItalic]          [NotoSerif-Italic]     [features=default]
  \definefontsynonym[SerifBold]            [NotoSerif-Bold]       [features=default]
  \definefontsynonym[SerifBoldItalic]      [NotoSerif-BoldItalic] [features=default]
\stoptypescript

\starttypescript [mynotoserif]
  \definetypeface [mynotoserif]    [rm] [serif] [mynotoserif]    [default]
\stoptypescript


  1. Save your file as type-(fontname|foundry).tex, for example here type-mynotoserif.tex
  2. Copy the typescript files into tex/texmf-fonts/tex/context/user/
  3. Run context --generate to update ConTeXt file database
  4. You are done!
    • you can add \usetypescriptfile[mynotoserif] at the beginning of any input file
    • and \setupbodyfont[mynotoserif] will declare to typeset with your new font.