Difference between revisions of "Installing a TrueType font, step by step - Old Content"

From Wiki
Jump to navigation Jump to search
m (added Category "Fonts")
Line 45: Line 45:
 
If you manage to get to this point and <tt>texfont</tt> does not complain much, the fonts are installed!
 
If you manage to get to this point and <tt>texfont</tt> does not complain much, the fonts are installed!
  
The command above will make the fonts with texnansi encoding. If you don't know what encodings are, then just let it be as it is. If you need another encoding (such as ec, 8r), it can be specified with a switch <tt>--en=ec</tt>. You can install the same font several times with different encodings, the naming scheme allows coexistence.
+
The command above will make the fonts with texnansi encoding. If you don't know what encodings are, then just let it be as it is. If you need another encoding (such as ec, 8r), it can be specified with a switch <tt>--en=ec</tt>. You can install the same font several times with different encodings; the naming scheme allows coexistence.
  
 
With the simple command line you may have problems with ligatures. For example, two hyphens <tt>--</tt> in the source file still print as two hyphens (not as an en dash). This can be cured by giving the switch <tt>--afmpl</tt> which tells <tt>texfont</tt> to use a slightly more intelligent utility (<tt>afm2pl</tt>) with the fonts.
 
With the simple command line you may have problems with ligatures. For example, two hyphens <tt>--</tt> in the source file still print as two hyphens (not as an en dash). This can be cured by giving the switch <tt>--afmpl</tt> which tells <tt>texfont</tt> to use a slightly more intelligent utility (<tt>afm2pl</tt>) with the fonts.

Revision as of 09:06, 30 August 2005

Background

I wanted to install the very fine Gentium font to my computer. The font is a free font with a very wide collection of latin and greek glyphs (cyrillic to come later). It can be downloaded from the SIL home page: http://www.sil.org/ .

While the font system is rather elegant and can be tweaked every possible way, it is difficult to get started with. For a beginner, new fonts may feel extremely difficult to install.

There are several good introductions to the subject. This is not one of those, as I am not going to tell a word about why or what. This is just a description of how I managed to install a new font. The process is surprisingly easy if it goes smoothly. If it doesn't, then I cannot help... If you want to stay out of trouble, please test your ConTeXt installation before installing the fonts. If it doesn't work before, it won't after.

My installation is a rather recent gwTeX (31 Jan 05) on Mac OS X with a ConTeXt installation from the same date. As the distribution is based on TeX Live, I guess the instructions given here should be rather universal. I am sorry, but the instructions give all the commands in the Unix form, so Windows users have to adapt. I try to give some hints to Windows and Linux users, as well, but everything is untested.

Procedure

Before starting, it is important to understand that the ConTeXt font installation is completely independent from the operating system fonts. You may have a font which ConTeXt can use but the operating system does not see, or vice versa. In many cases it is very useful to have the same fonts available, e.g., it is nice to be able to use the same fonts in illustrations drawn with a drawing package and text typeset by ConTeXt. Unfortunately, there is no simple link between the two font systems.

In most cases it is possible to install the operating system fonts for ConTeXt to use. The converse holds true, as well. Especially the OS part of that is certainly beyond the scope of this text, but some ideas for the opposite are given.

Getting the font files

Before anything can be installed, that anything should be obtained. ConTeXt requires the TrueType .ttf files (or type 1, but that's another story). The easiest way to get the .ttf files is to download the Windows font files from the foundry (wherever you get your fonts from). Even if your system is Linux or OS X, the Windows files provide the easiest way to get the font files in the correct format, because they are almost always either pure .ttf or zipped .ttf files.

If you have the font installed in Windows or XWin (Linux, etc.), try to locate the corresponding .ttf file (actual location varies by the OS). The naming scheme may be confusing, finding the right files may take some effort. Usually you need at least two to four files (bold and italic are separate files, etc.)

With OS X the situation is a bit trickier, as the system does not store the .ttf files as such. If you either have only the OS X font file (usually .sit) or the font is only installed in your computer, you need to extract the actual .ttf files. Go and get a small utility called fondu. The utility comes with OpenOffice or can be downloaded from http://fondu.sourceforge.net/ . Using the utility is very simple: just type the path to the font to be converted, e.g.: fondu /Users/username/Library/Fonts/Gentium and you will get a couple of .ttf files in the current working directory.

Installing the fonts

Once you have obtained the .ttf files one way or another, it is wise to make a temporary directory somewhere. If you do not know where, go and make a directory under /tmp, for example /tmp/work. There is no magic in the directory name, anything goes.

Now we have a nice temporary directory somewhere and a few .ttf files in it. Then the actual font installation goes with a magic command (read on, if you want to avoid some pitfalls with file permissions):

texfont --ve=sil --co=gentium --makepath --install

This tells the wonderful texfont script to process all the .ttf files in the directory (you can limit the choice by supplying file names to the end of the command). The vendor of the fonts is sil and the name for the font collection is gentium. Again, there is no magic in these names, they are just used as directory names in the texmf tree. However, using just anything will make administration harder later on, so try to stick to reality.

The last two switches tell the script to make all missing directories and install the actual .ttf files to the right place in the texmf tree. In my case everything was installed into the local tree (/usr/local/teTex/share/texmf.local/...).

Beware, you will need administrative priviledges (power user, administrator, root) to be able to change the texmf tree. On Unix/Linux/OS X systems you can either log in as root which is not a good idea in general or use sudo. In OS X and other sudo-aware operating systems the following will work for all power users:

sudo texfont --ve=sil --co=gentium --makepath --install

Note that the password asked at this point is your password, not the root password.

In Windows, you should log in as a Power User (Administrator, whatever, different names in different versions of Windows). Otherwise you will end up with permission conflicts.

If you manage to get to this point and texfont does not complain much, the fonts are installed!

The command above will make the fonts with texnansi encoding. If you don't know what encodings are, then just let it be as it is. If you need another encoding (such as ec, 8r), it can be specified with a switch --en=ec. You can install the same font several times with different encodings; the naming scheme allows coexistence.

With the simple command line you may have problems with ligatures. For example, two hyphens -- in the source file still print as two hyphens (not as an en dash). This can be cured by giving the switch --afmpl which tells texfont to use a slightly more intelligent utility (afm2pl) with the fonts.

Unfortunately, there seems to be a file missing in gwTeX, so you will need to get default.lig somewhere. The easiest way is to download it from http://www.tug.org/ftp/texlive/Contents/testinstalled/texmf/fonts/lig/afm2pl/default.lig . Placing it in your working directory is enough, but you could also download all the .lig files in that directory and putting them in your own TeX tree at fonts/lig/afm2pl, and then run texhash/mktexlsr.

Testing the fonts

One of the nicest features in texfont is that it produces a test file. In this case the file is called texnansi-sil-gentium.tex. This file can be run by texexec --pdf texnansi-sil-gentium.tex. It will take a while (with my 1.25 GHz G4 it takes around a minute), but the result will be a few pages of glyphs.


Using the fonts in a document

To use the fonts in a document, a few definitions are needed. A simple test document is shown below:

\loadmapfile[ec-sil-gentium.map]
\usetypescriptfile[type-buy]

\starttypescript [serif] [Gentium] [ec]
  \usetypescript[serif][fallback]
  \definefontsynonym [Gentium-Roman]       [ec-GentiumRegular]  [encoding=ec]
  \definefontsynonym [Gentium-Italic]      [ec-GentiumItalic] [encoding=ec]
\stoptypescript

\starttypescript [serif] [Gentium] [name]
  \usetypescript[serif][fallback]
  \definefontsynonym [Serif]           [Gentium-Roman]
  \definefontsynonym [SerifItalic]     [Gentium-Italic]
\stoptypescript

\starttypescript [Gentium] 
  \definetypeface [MyGentium] [rm] [serif] [Gentium] [default] [encoding=ec]
\stoptypescript

\usetypescript[Gentium]
\setupbodyfont[MyGentium,11pt]

\starttext

This is Gentium!

{\it This is Gentium Italic!}

\stoptext

One important thing to note is that there aren't Gentium Bold or Bold Italic flavours available, yet. So, "to regularly go where no man has gone before".

Of course, you can (and probably should) put the typescript definitions into another file so that they can be reused in other documents. For more information on using typescripts, Wiki around! My suggestion is to start with the Bill McClain's ConTeXt beginners page and then check the TypeScripts page. Note that the font names on the latter are slightly different from the ones on this page even though the font is the same.