Difference between revisions of "Simplefonts"

From ConTeXt wiki
m (add link to sources)
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
'''ATTENTION!!'''
 +
 +
As of December 2013, the functionality of the Simplefonts module has been included into the ConTeXt core. You do no longer need to load any external module to take advantage of the simplified font commands. However, the commands have slightly changed:
 +
 +
`\setmainfont`
 +
 +
is now
 +
 +
`\definefontfamily  [myfamily] [serif]  [DejaVu]`
 +
 +
(and the same syntax to set the sans, mono and math font).
 +
 +
To use this family:
 +
 +
`\setupbodyfont [myfamily]`
 +
 +
Note that for monospace fonts, undesired ligatures may be used in `\type`.  To avoid this, font features should be disabled:
 +
 +
`\definefontfamily [myfamily] [mono] [TeX Gyre Cursor] [features=none]`
 +
 +
If you want more examples, have a look at the file {{src|font-sel.mkvi}} in the distribution, which contains a good explanation.
 +
 +
-----
 +
 
=== Introduction ===
 
=== Introduction ===
  
Line 8: Line 32:
  
 
* the interface is much easier to use.
 
* the interface is much easier to use.
 +
 +
* Note that some major changes were released in Oct. 2013. Documentation on this page typically describes the earlier version of simplefonts distributed with TeX Live 2013, unless otherwise noted.
  
 
=== Installing <code>simplefonts</code> ===
 
=== Installing <code>simplefonts</code> ===
Line 13: Line 39:
 
* If you’re using LuaTeX along with [https://www.tug.org/texlive/ TeX Live], <code>simplefonts</code> is already installed.
 
* If you’re using LuaTeX along with [https://www.tug.org/texlive/ TeX Live], <code>simplefonts</code> is already installed.
  
* If you’re running [[ConTeXt Standalone]] (which is a better option), <code>simplefonts</code> can be installed like [[ConTeXt_Standalone#Installing_third_party_modules|any third-party module]]:
+
* If you’re running [[ConTeXt Standalone]] (which is updated more often, allowing use of newer features but with less stability testing), <code>simplefonts</code> can be installed like [[ConTeXt_Standalone#Installing_third_party_modules|any third-party module]]:
 
   first-setup.sh --modules="t-simplefonts"
 
   first-setup.sh --modules="t-simplefonts"
  
Line 42: Line 68:
 
Here is the most basic sample:
 
Here is the most basic sample:
  
<texcode>
+
<context mode="mkiv" source="yes">
 
\setupbodyfontenvironment[default][em=italic]
 
\setupbodyfontenvironment[default][em=italic]
 
\usemodule[simplefonts][size=10pt]
 
\usemodule[simplefonts][size=10pt]
\setmainfont[FreeSerif]
+
\setmainfont[TeX Gyre Termes]
\setmonofont[FreeMono]
+
\setsansfont[TeX Gyre Heros]
\setsansfont[FreeSans]
+
\setmonofont[TeX Gyre Cursor]
 
 
\starttext
 
Serif typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.
 
 
 
{\ss Sans--serif typeface: regular {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.}
 
 
 
{\tt Monospace typeface: regular {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.}
 
\stoptext
 
</texcode>
 
 
 
It isn’t required to define size for 12pt, since it is the default value.
 
 
 
<!-- when MkIV is enabled in the wiki
 
This is the output:
 
 
 
<context>
 
\setupbodyfontenvironment[default][em=italic]
 
\usemodule[simplefonts][size=10pt]
 
\setmainfont[FreeSerif]
 
\setmonofont[FreeMono]
 
\setsansfont[FreeSans]
 
  
 
\starttext
 
\starttext
Line 78: Line 83:
 
\stoptext
 
\stoptext
 
</context>
 
</context>
-->
+
 
 +
It isn’t required to define size for 12pt, since it is the default value.
  
 
=== Mixing fonts ===
 
=== Mixing fonts ===
Line 84: Line 90:
 
In some cases, you might want to mix fonts (it is up to you whether they really match or not).
 
In some cases, you might want to mix fonts (it is up to you whether they really match or not).
  
Here is the way to do it:
+
Here is the way to do it (I know that fonts don’t match):
  
<texcode>
+
<context mode="mkiv" source="yes">
 
\setupbodyfontenvironment[default][em=italic]
 
\setupbodyfontenvironment[default][em=italic]
 
\usemodule[simplefonts]
 
\usemodule[simplefonts]
\setmainfont[TheanoDidot][italicfont=Old Standard-Italic, boldfont=Old Standard-Bold,
+
\setmainfont[TeX Gyre Termes][italicfont=TeX Gyre Bonum-Italic,
bolditalicfont=TeX Gyre Pagella-Bold Italic] % yes, bold italics don’t match
+
boldfont=TeX Gyre Adventor-Bold, bolditalicfont=TeX Gyre Pagella-Bold Italic]
  
 
\starttext
 
\starttext
Serif typeface: regular {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.
+
Serif typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.
 
\stoptext
 
\stoptext
</texcode>
+
</context>
  
 
=== Font fallback mechanism ===
 
=== Font fallback mechanism ===
Line 101: Line 107:
 
We can have documents in which we use typefaces that lack some characters or a whole character range. In that case, font fallbacks can be defined.
 
We can have documents in which we use typefaces that lack some characters or a whole character range. In that case, font fallbacks can be defined.
  
The example shows how to get Greek characters for TeX Gyre Pagella:
+
The example shows how to get Greek characters for TeX Gyre Pagella (I know they don’t fit well together, but I rely on system fonts):
  
<texcode>
+
<context mode="mkiv" source="yes">
 
\setupbodyfontenvironment[default][em=italic]
 
\setupbodyfontenvironment[default][em=italic]
 
\usemodule[simplefonts]
 
\usemodule[simplefonts]
\setmainfontfallback[GFS Didot][range={greekandcoptic, greekextended},
+
\setmainfontfallback[DejaVu Serif][range={greekandcoptic, greekextended},
     force=yes]
+
     force=yes, rscale=auto]
 
\setmainfont[TeX Gyre Pagella]
 
\setmainfont[TeX Gyre Pagella]
  
Line 119: Line 125:
 
{\bf\em English text. δύσκολα τὰ καλά.}
 
{\bf\em English text. δύσκολα τὰ καλά.}
 
\stoptext
 
\stoptext
</texcode>
+
</context>
  
 
Two things to be considered:
 
Two things to be considered:
Line 135: Line 141:
 
*`\definesimplefonttypeface`, defines a single typeface.
 
*`\definesimplefonttypeface`, defines a single typeface.
 
*`\simplefonttypeface`, can define a typeface set (such as serif, sans–serif, monospaced, caligraphy and others).
 
*`\simplefonttypeface`, can define a typeface set (such as serif, sans–serif, monospaced, caligraphy and others).
 +
 +
The \definesimplefont command can be used when you want a certain font
 +
for the heading of a chapter, section etc. E.g.
 +
 +
<texcode>
 +
\definesimplefont[ChapterFont][Gentium Basic][size=24pt]
 +
\setuphead[chapter][style=ChapterFont]
 +
</texcode>
 +
 +
but Wolfgang doesn’t recommend this command anymore (and removed it from the new, Oct. 2013 version) because you can get the same result with a custom typeface, e.g.
 +
 +
<texcode>
 +
\definesimplefonttypeface[chapterfont][TeX Gyre Termes]
 +
\definefont[ChapterFont][\classfont{chapterfont}{Serif} at 24pt]
 +
\setuphead[chapter][style=ChapterFont]
 +
</texcode>
 +
 +
When you want to change only the global font for your document you
 +
need the <code>\definesimplefonttypeface</code> command, e.g.
 +
 +
<texcode>
 +
\definesimplefonttypeface[documentfont][TeX Gyre Termes]
 +
\setupbodyfont[documentfont]
 +
</texcode>
  
 
=== Handling special cases ===
 
=== Handling special cases ===
Line 146: Line 176:
 
Again, it would be the exception, rather than the rule, where this suggested method outputs a reasonable result. If you use ConTeXt for its high–quality typographical performance, using faked fonts can ruin that performance.
 
Again, it would be the exception, rather than the rule, where this suggested method outputs a reasonable result. If you use ConTeXt for its high–quality typographical performance, using faked fonts can ruin that performance.
  
Wolfgang Schuster proposed the following code to get slanted and fake bold fonts (not working right now, I guess it’s a bug):
+
Wolfgang Schuster proposed the following code to get slanted and fake bold fonts:
  
<texcode>
+
<context mode="mkiv" source="yes">
 
\setupbodyfontenvironment[default][em=italic]
 
\setupbodyfontenvironment[default][em=italic]
 
\usemodule[simplefonts]
 
\usemodule[simplefonts]
Line 155: Line 185:
 
\definefontfeature[fakebold][default][extend=2]
 
\definefontfeature[fakebold][default][extend=2]
 
\definefontfeature[fakebolditalic][default][slant=.25, extend=2]
 
\definefontfeature[fakebolditalic][default][slant=.25, extend=2]
\setmainfont[Larabiefont][italicfont={* Regular}, boldfont={*
+
\setmainfont[TeX Gyre Pagella]
Regular}, bolditalicfont={* Regular}, italicfeatures=fakeitalic,
+
 
 +
\definesimplefonttypeface[fakingall][TeX Gyre Pagella][italicfont={* Regular}, boldfont={* Regular}, bolditalicfont={* Regular}, italicfeatures=fakeitalic,
 
boldfeatures=fakebold, bolditalicfeatures=fakebolditalic]
 
boldfeatures=fakebold, bolditalicfeatures=fakebolditalic]
</texcode>
+
 
 +
\starttext
 +
Compare:
 +
 
 +
Four fonts, real typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.
 +
 
 +
{\fakingall One font, faked typeface: regular, {\em italic  (actually slanted)} , {\bf bold (actually stretched)} and {\bf\em bold italic (actually slanted and stretched)} fonts.}
 +
\stoptext
 +
</context>

Latest revision as of 14:05, 6 February 2017

ATTENTION!!

As of December 2013, the functionality of the Simplefonts module has been included into the ConTeXt core. You do no longer need to load any external module to take advantage of the simplified font commands. However, the commands have slightly changed:

\setmainfont

is now

\definefontfamily [myfamily] [serif] [DejaVu]

(and the same syntax to set the sans, mono and math font).

To use this family:

\setupbodyfont [myfamily]

Note that for monospace fonts, undesired ligatures may be used in \type. To avoid this, font features should be disabled:

\definefontfamily [myfamily] [mono] [TeX Gyre Cursor] [features=none]

If you want more examples, have a look at the file font-sel.mkvi in the distribution, which contains a good explanation.


Introduction

simplefonts is a third–party module written by Wolfgang Schuster.

It has two main advantages over the standard font handling in ConTeXt:

  • the interface is much easier to use.
  • Note that some major changes were released in Oct. 2013. Documentation on this page typically describes the earlier version of simplefonts distributed with TeX Live 2013, unless otherwise noted.

Installing simplefonts

  • If you’re using LuaTeX along with TeX Live, simplefonts is already installed.
 first-setup.sh --modules="t-simplefonts"

Setting the system font directory

If you want to use system font within ConTeXt, the path to these fonts must be known to ConTeXt.

You have to set the OSFONTDIR variable to the path where your system font are located. If you use ConTeXt Standalone, please follow these instructions.

In Linux, the standard value is:

   OSFONTDIR= /usr/share/fonts//;$HOME/.fonts

In Windows, the following line is to be added (slashes are fine, no need for backslashes):

   OSFONTDIR= c:/{windows,winnt,winnt35}/fonts//

On Mac, here is a value:

   OSFONTDIR = /Library/Fonts//;/System/Library/Fonts;$HOME/Library/Fonts

(If you have font in non–standard locations or use another operating system, all you have to do is to add the path to the OSFONTDIR variable.)

In TeX Live, you have to add this variable (or update it) in texmf.cnf (find it with kpsewhich texmf.cnf).

Basic usage

Here is the most basic sample:

\setupbodyfontenvironment[default][em=italic]
\usemodule[simplefonts][size=10pt]
\setmainfont[TeX Gyre Termes]
\setsansfont[TeX Gyre Heros]
\setmonofont[TeX Gyre Cursor]

\starttext
Serif typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.

{\ss Sans--serif typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.}

{\tt Monospace typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.}
\stoptext

It isn’t required to define size for 12pt, since it is the default value.

Mixing fonts

In some cases, you might want to mix fonts (it is up to you whether they really match or not).

Here is the way to do it (I know that fonts don’t match):

\setupbodyfontenvironment[default][em=italic]
\usemodule[simplefonts]
\setmainfont[TeX Gyre Termes][italicfont=TeX Gyre Bonum-Italic,
boldfont=TeX Gyre Adventor-Bold, bolditalicfont=TeX Gyre Pagella-Bold Italic]

\starttext
Serif typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.
\stoptext

Font fallback mechanism

We can have documents in which we use typefaces that lack some characters or a whole character range. In that case, font fallbacks can be defined.

The example shows how to get Greek characters for TeX Gyre Pagella (I know they don’t fit well together, but I rely on system fonts):

\setupbodyfontenvironment[default][em=italic]
\usemodule[simplefonts]
\setmainfontfallback[DejaVu Serif][range={greekandcoptic, greekextended},
    force=yes, rscale=auto]
\setmainfont[TeX Gyre Pagella]

\starttext
English text. δύσκολα τὰ καλά.

{\em English text. δύσκολα τὰ καλά.}

{\bf English text. δύσκολα τὰ καλά.}

{\bf\em English text. δύσκολα τὰ καλά.}
\stoptext

Two things to be considered:

  • range can assume the following values: any of the block names in char-ini.lua, or a manual range such as 0x003B1-0x003B6.
  • force=yes should be enabled, unless you want the characters to have their glyphs from the original font replaced with the ones from the fallback font.

Defining other typefaces and fonts

simplefonts has two commands to define fonts and two commands to define typefaces (Times Regular, Times Italics, Times Bold and Times Bold Italic are four different fonts, but a single typeface):

  • \definesimplefont, defines a font for the use in headers or other style elements.
  • \simplefont, defines a font for inline use.
  • \definesimplefonttypeface, defines a single typeface.
  • \simplefonttypeface, can define a typeface set (such as serif, sans–serif, monospaced, caligraphy and others).

The \definesimplefont command can be used when you want a certain font for the heading of a chapter, section etc. E.g.

\definesimplefont[ChapterFont][Gentium Basic][size=24pt]
\setuphead[chapter][style=ChapterFont]

but Wolfgang doesn’t recommend this command anymore (and removed it from the new, Oct. 2013 version) because you can get the same result with a custom typeface, e.g.

\definesimplefonttypeface[chapterfont][TeX Gyre Termes]
\definefont[ChapterFont][\classfont{chapterfont}{Serif} at 24pt]
\setuphead[chapter][style=ChapterFont]

When you want to change only the global font for your document you need the \definesimplefonttypeface command, e.g.

\definesimplefonttypeface[documentfont][TeX Gyre Termes]
\setupbodyfont[documentfont]

Handling special cases

If the font in question has an unusual naming scheme (or wrong names) and/or it is missing some features, it may be necessary to specify the names to look for and the font features to implement.

Faking italics and bold fonts

As a general rule, it is not a good idea to use faked italics and bold fonts. A slanted font is by no means an italic one (at least, in the vast majority of typefaces). And faked bold fonts don’t look the same as real bold fonts (a similar consideration could be made about small caps).

Again, it would be the exception, rather than the rule, where this suggested method outputs a reasonable result. If you use ConTeXt for its high–quality typographical performance, using faked fonts can ruin that performance.

Wolfgang Schuster proposed the following code to get slanted and fake bold fonts:

\setupbodyfontenvironment[default][em=italic]
\usemodule[simplefonts]

\definefontfeature[fakeitalic][default][slant=.25]
\definefontfeature[fakebold][default][extend=2]
\definefontfeature[fakebolditalic][default][slant=.25, extend=2]
\setmainfont[TeX Gyre Pagella]

\definesimplefonttypeface[fakingall][TeX Gyre Pagella][italicfont={* Regular}, boldfont={* Regular}, bolditalicfont={* Regular}, italicfeatures=fakeitalic,
boldfeatures=fakebold, bolditalicfeatures=fakebolditalic]

\starttext
Compare:

Four fonts, real typeface: regular, {\em italic}, {\bf bold} and {\bf\em bold italic} fonts.

{\fakingall One font, faked typeface: regular, {\em italic  (actually slanted)} , {\bf bold (actually stretched)} and {\bf\em bold italic (actually slanted and stretched)} fonts.}
\stoptext