Changes

Jump to navigation Jump to search
8,276 bytes added ,  17:17, 26 September 2023
m
Corrected a mistake in the mtxrun command (it was fot it should be fonts)
= Fonts location on your computer =
= Using a newly downloaded font =The first step is to declare the storage locations of the fonts you want ConTeXt to consider.
== Quickly Either way, ConTeXt will use one of the styles fonts properly stored in its tree structure (3 stepsfor example, 1 minany fonts you would have downloaded from [https://www.fontsquirrel.com Fonts Squirrel] [https://fonts.google.com Google Fonts], or see [[Available Free Fonts]]) ==.* '''TeX users create a new folder for each new font in <code>tex/texmf-fonts/fonts/</code>''', following [http://tug.org/tds/ 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*: <code>tex/texmf-fonts/fonts/truetype/vendor/fontfamily</code>.
LetBut it it's take a examplevery likely that you also want to use the '''fonts already available on your Operating System''':;1. Specify where ConTeXt should looked for fonts, we by setting the '''OSFONTDIR''' environment variable.:* WINDOWS: <code>set OSFONTDIR=c:/windows/fonts/</code>:* MAC: <code>export OSFONTDIR=/Library/Fonts/:/System/Library/Fonts:$HOME/Library/Fonts</code>:* GNU/LINUX: <code>export OSFONTDIR=$HOME/.fonts:/usr/share/fonts</code>:* Add it to your .bashrc or shell equivalent to make the declaration permanent.;2. Run ConTeXt to index the files and the fonts :<texcode>mtxrun --generatemtxrun --script fonts --reload</texcode>;3. Check by looking for the specific font you want to use [httpsnext. A common example:<texcode>mtxrun --script fonts --list --all --pattern='*helvetica*'</texcode> '''NOTE''' : In recent versions of ConTeXt (2023), the use of wildcards is no longer necessary to check for the presence of a particular font.  In addition, it is no longer necessary to tell ConTeXt where the fonts are located (on Windows or Apple Mac), as a routine has been implemented in <texcode>mtxrun.lua</fontstexcode> that automates the font search. If no value for OSFONTDIR is set, then mtxrun.lua looks to the directory.googleHere is the code of mtxrun.comlua (given here as information) : <texcode>do local osfontdir=osgetenv("OSFONTDIR") if osfontdir and osfontdir~="" then elseif osname=="windows" then ossetenv("OSFONTDIR","c:/specimenwindows/Noto+Serif Noto Serif]fonts//") elseif osname=="macosx" thenossetenv("OSFONTDIR","$HOME/Library/Fonts//;/Library/Fonts//;/System/Library/Fonts//") endend </texcode> On the other hand, if the routine seeks to locate fonts on Windows and Mac, insofar as we are seeking to install new fonts for the Linux system, we must ask ConTeXt — as indicated above — for the path that leads to the directory where the new fonts are deposited; in this case <texcode>tex/texmf-fonts/fonts/</texcode>. The google website enable us Then you'll need to download empty the font cache and regenerate it, so that the <texcode>mtxrun --script fonts --list --all --pattern=didot</texcode> command can return something (if you've installed a zip file with GFS Didot, or Theano Didot font, for example). To empty the cache and regenerate it, enter the 4 alternative stylesfollowing command (in the directory : /home/johndoe/context/tex/texmf-linux64/bin):* Regular 400<texcode>mtxrun --script cache --erase && mtxrun --generate</texcode> Now you can search for the font you've just installed.      * Regular 400 italicNow, let's learn how to use them for typesetting.* Bold 700* Bold 700 italic= Practical application #1 - Quick use of a new font =
; #1. Store them is a dedicated folderLet's take an example: we want to use [https:* create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-/fonts</code>.:* unzip and store the google.ttf file in <code>texcom/texmf-fontsspecimen/Noto-serif/</code>+Serif Noto Serif].
; If it is already installed on your computer, and you already updated the ConTeXt databases like shown previously, go directly to '''#2'''. Regenerate ConTeXt databases:* the file database: <code>mtxrun --generate</code>:* the fonts database: <code>mtxrun --script font --reload</code>:* and check the situation <code>mtxrun --script font --list --file -pattern=*noto*</code>:<texcode>familyname weight style width variant fontname filename subfont fontweight
It not, you have to download and store it first. The Google website provides a zip file with the 4 alternative variations (Regular 400, Regular 400 italic, Bold 700, Bold 700 italic). ; #1. Store them in a dedicated folder [[#Fonts location on your computer|indexed by ConTeXt]].:* for example, create a "Noto-serif" in the ConTeXt distribution <code>tex/texmf-fonts/fonts/</code>.:* unzip and store the .ttf file in <code>tex/texmf-fonts/fonts/Noto-serif/</code>.:* Regenerate ConTeXt databases:** the file database: <code>mtxrun --generate</code>:** the fonts database: <code>mtxrun --script font --reload</code> ; #2. Now you can check the ''fontname'' used to identify the fonts, :*run <code>mtxrun --script font --list --file -pattern=*noto*</code>. You should obtain something like<texcode>familyname weight style width variant fontname filename subfont fontweight notoserif bold bold normal normal normal normal notoserifbold NotoSerif-Bold.ttfnotoserif bold bold italic normal normal normal notoserifbolditalic NotoSerif-BoldItalic.ttfnotoserif normal italic normal normal normal notoserifitalic NotoSerif-Italic.ttfnotoserif normal normal normal normal normal notoserif NotoSerif-Regular.ttf
</texcode>
; #3. Your You are done! You can use the font anywhere on in your input files.:* Use the commands with {{cmd|definedfont}}:* it's good to add <code>*default</code> to benefit from default features, like for example [http://www.pragma-ade.nl/general/manuals/fonts-mkiv.pdf#&#91;169,{%22name%22:%22Fit%22}&#93; kerning].
<texcode>
\definedfont[filename:NotoSerif-BoldItalic notoserifbolditalic*default at 12pt12 pt]
The quick brown fox jumps over the lazy dog
</texcode>
[[File:result_of_test_with_noto-serif_one.png]]
== Practical application #2 - Use all the styles (3 steps, 1 min.) =different font variations =
* It's not nice to have to write \definedfont[name:yoursuperfont-weightstyle*default at xxpt] each time you want to use a particular font. * That why it's worth defining a '''typescript'''. It's just 3 steps, and less than 5 minutes. Then, you will be able to easily switch between fonts with {{cmd|tf}}, {{cmd|it}}, {{cmd|bf}}, {{cmd|bi}} (see [[Font_Switching#Font_styles_and_alternatives|Font styles and alternatives]]), and all the typesetting of your document will use a consistent set of fonts.* [[Typescripts_examples| Many typescripts are ready]] for use on usual free and commercial fonts, and obviously for the [[ConTeXt_distribution's_Fonts|ConTeXt distribution's Fonts]].   ; #1. Define them as a new typescript (ConTeXt vocabulary) in your input file.:* Use the commands , with {{cmd|starttypescript}} .:* Define the links between ''filenames'' and ''People-readable names'' with {{cmd|definefontsynonym}} to declare.:* In this example, the typescript is called "mynotoserif".:* Reminder: you find the filenames for the Noto Serif fonts with <code>mtxrun --script font --list --file -pattern=*noto*</code>:
<texcode>
\starttypescript [serifmynotoserif] % \definefontsynonym[notoserifHuman 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
</texcode>
; #2. Define them as part of your The boring step, define the links between ''[https://github.com/contextgarden/context-mirror/blob/a0270f13065d116355a953c6f246cbba26289fc2/tex/context/base/mkiv/font family, here as -sel.lua#L514 ConTeXt basics names]'' and the ''People-readable names''.:* It's good to add a romanfallback.
<texcode>
\definefontfamily starttypescript [MyFontIdentifiermynotoserif] \setups[rmfont:fallback:serif] % security: if not found==> back to defaults% \definefontsynonym[notoserifConTeXt basics 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>
; #3. Define the pack of the 4 variations as the roman typeface of the typescript "mynotoserif" :<texcode>\starttypescript [mynotoserif] \definetypeface [mynotoserif] [rm] [serif] [mynotoserif] [default]\stoptypescript</texcode> ; #4. You are done! Finally, we have the following input file:
<texcode>
\starttypescript [serif] [notoserifmynotoserif] \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
\definefontfamily starttypescript [MyFontIdentifiermynotoserif] \definetypeface [mynotoserif] [rm] [notoserifserif] [mynotoserif] [default]\stoptypescript
\setupbodyfont[MyFontIdentifiermynotoserif]
\setupbodyfont[12pt]
{\rm The quick brown fox jumps over the lazy dog}\\{\rmit The quick brown fox jumps over the lazy dog}\\{\bf The quick brown fox jumps over the lazy dog}\\{\rm\it bi The quick brown fox jumps over the lazy dog}\\
</texcode>
[[File: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, we remind the definition:
 
<texcode>
\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
</texcode>
 
 
# Save your file as <code>type-(some-name-you-like).tex</code>, for example here <code>type-mynotoserif.tex</code>
# Copy the typescript files into <code>tex/texmf-fonts/tex/context/user/</code>
# Run <code>context --generate</code> to update ConTeXt file database
# It's done! Now, two lines at the beginning of any input will declare to typeset with the new fonts:
<texcode>
\usetypescriptfile[mynotoserif] % this is the 'some-name-you-like' part of the saved filename
\setupbodyfont[mynotoserif] % this is the first argument to \definetypeface
</texcode>
 
====Note:====
 
The naming convention for typescript files has changed in LMTX
 
<blockquote>
There has been a change in the naming of typescript file, a simple <code>"type-"</code> prefix isn't anough anymore, you have to change it to <code>"type-imp-" </code>(e.g. type-imp-sourceserif.tex) to be found by ConTeXt.
 
Valid file extensions for a typescript file in LMTX (and MkIV) are "tex", "mkiv" and "mkxl".
 
Wolfgang [20 Dec 2020]
</blockquote>
 
 
[[Category:Fonts]]
18

edits

Navigation menu