Difference between revisions of "Use the fonts you want"

From Wiki
Jump to navigation Jump to search
Line 102: Line 102:
  
 
[[File:result_of_test_with_noto-serif.png]]
 
[[File:result_of_test_with_noto-serif.png]]
 +
 +
= Install the new typescript definition =
 +
 +
I you wan to use the same customized typescrip across different documents, it make sense to install them in the distribution
 +
 +
1. Copy the typescript files into either
 +
 +
 +
Installing typescripts consists in the following:
 +
 +
1. Copy the typescript files into either <texcode>tex/texmf-fonts/tex/context/user/</texcode>
 +
 +
2. Run <code>context --generate</code>
 +
 +
 +
  <texcode>$TEXMF/tex/texmf-fonts/tex/context/user
 +
$TEXMF/tex/texmf-project/tex/context/user</texcode>
 +
2. Run <code>context --generate</code>
 +
 +
By convention, typescript files are named like <code>type-(fontname|foundry).tex</code>.
 +
 +
It may happen that some <code>type-xx.tex</code> typescript file depends on mkiv-specific code located in a matching <code>type-xx.mkiv</code> file. In this case, both files need to be installed.
 +
 +
=== Loading typescripts ===
 +
 +
A typescript file named <code>type-xx.tex</code> should be loaded using
 +
  \usetypescriptfile[type-xx]
 +
 +
An alternative way is
 +
  \usetypefile[xx]
 +
where ConTeXt prepends <code>type-</code> when it loads the file; but 
 +
<cmd>usetypescriptfile</cmd> is the preferred command because it takes care of the
 +
<cmd>starttypescriptcollection</cmd>/<cmd>stoptypescriptcollection</cmd> environments.

Revision as of 18:45, 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 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".
\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
#3. 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 the new typescript definition

I you wan to use the same customized typescrip across different documents, it make sense to install them in the distribution

1. Copy the typescript files into either


Installing typescripts consists in the following:

1. Copy the typescript files into either

tex/texmf-fonts/tex/context/user/

2. Run context --generate


$TEXMF/tex/texmf-fonts/tex/context/user
$TEXMF/tex/texmf-project/tex/context/user

2. Run context --generate

By convention, typescript files are named like type-(fontname|foundry).tex.

It may happen that some type-xx.tex typescript file depends on mkiv-specific code located in a matching type-xx.mkiv file. In this case, both files need to be installed.

Loading typescripts

A typescript file named type-xx.tex should be loaded using

 \usetypescriptfile[type-xx]

An alternative way is

 \usetypefile[xx]

where ConTeXt prepends type- when it loads the file; but \usetypescriptfile is the preferred command because it takes care of the \starttypescriptcollection/\stoptypescriptcollection environments.