Difference between revisions of "Use the fonts you want"

From Wiki
Jump to navigation Jump to search
Line 28: Line 28:
 
= Use of the different variations =
 
= Use of the different variations =
  
; #1. Define them as a new typescript (ConTeXt vocabulary) in your input file, with {{cmd|starttypescript}} and {{cmd|definefontsynonym}}.
+
; #1. Define them as a new typescript (ConTeXt vocabulary) in your input file, with {{cmd|starttypescript}} and define the link between ''filenames'' and ''Human readable names'' with {{cmd|definefontsynonym}}.
  
 
<texcode>
 
<texcode>
% 1. From filenames to Human readable names
 
 
\starttypescript [mynotoserif]
 
\starttypescript [mynotoserif]
 
% \definefontsynonym[Human readable]      [file:filename without extension]
 
% \definefontsynonym[Human readable]      [file:filename without extension]
Line 41: Line 40:
 
</texcode>
 
</texcode>
  
; #2. Define them as part of your font family, here as a roman
+
; #2. The boring step: define the link between ''ConTeXt basics names'' and the ''Human readable names''. It's good to define a fallback.
 +
 
 
<texcode>
 
<texcode>
\definefontfamily [MyFontIdentifier] [rm] [notoserif]
+
\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
 
</texcode>
 
</texcode>
  

Revision as of 17:07, 1 June 2020

Quick use of a new font

Let's take a example, we want to use Noto Serif. The google website enable us to download 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
  • create a "Noto-serif" in the ConTeXt distribution tex/texmf-fonts.
  • unzip and store the .ttf file in tex/texmf-fonts/Noto-serif/.
#2. Regenerate ConTeXt databases
  • the file database: mtxrun --generate
  • the fonts database: mtxrun --script font --reload
  • and check the situation 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
\definedfont[file:NotoSerif-BoldItalic at 12pt]
The quick brown fox jumps over the lazy dog

result of test with noto-serif one.png

Use of the different variations

#1. Define them as a new typescript (ConTeXt vocabulary) in your input file, with \starttypescript and define the link between filenames and Human readable names with \definefontsynonym.
\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 link between ConTeXt basics names and the Human readable names. It's good to define 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. You are done! Finally, we have the following input file
\starttypescript [serif] [notoserif]
  \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

\definefontfamily [MyFontIdentifier] [rm] [notoserif]

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

And it gives:

result of test with noto-serif.png