The Fontspec Package Font Selection for XƎLATEX and Lualatex
Total Page:16
File Type:pdf, Size:1020Kb
The fontspec package Font selection for XƎLATEX and LuaLATEX Will Robertson and Khaled Hosny [email protected] 2013/05/12 v2.3b Contents 7.5 Different features for dif- ferent font sizes . 14 1 History 3 8 Font independent options 15 2 Introduction 3 8.1 Colour . 15 2.1 About this manual . 3 8.2 Scale . 16 2.2 Acknowledgements . 3 8.3 Interword space . 17 8.4 Post-punctuation space . 17 3 Package loading and options 4 8.5 The hyphenation character 18 3.1 Maths fonts adjustments . 4 8.6 Optical font sizes . 18 3.2 Configuration . 5 3.3 Warnings .......... 5 II OpenType 19 I General font selection 5 9 Introduction 19 9.1 How to select font features 19 4 Font selection 5 4.1 By font name . 5 10 Complete listing of OpenType 4.2 By file name . 6 font features 20 10.1 Ligatures . 20 5 Default font families 7 10.2 Letters . 20 6 New commands to select font 10.3 Numbers . 21 families 7 10.4 Contextuals . 22 6.1 More control over font 10.5 Vertical Position . 22 shape selection . 8 10.6 Fractions . 24 6.2 Math(s) fonts . 10 10.7 Stylistic Set variations . 25 6.3 Miscellaneous font select- 10.8 Character Variants . 25 ing details . 11 10.9 Alternates . 25 10.10 Style . 27 7 Selecting font features 11 10.11 Diacritics . 29 7.1 Default settings . 11 10.12 Kerning . 29 7.2 Changing the currently se- 10.13 Font transformations . 30 lected features . 12 10.14 Annotation . 30 7.3 Priority of feature selection 13 10.15 CJK shape . 31 7.4 Different features for dif- 10.16 Character width . 31 ferent font shapes . 13 10.17 Vertical typesetting . 32 1 10.18 OpenType scripts and lan- VI The patching/improve- guages . 32 ment of LATEX 2" and other packages 46 III LuaTEX-only font fea- 19 Inner emphasis 46 tures 33 20 Unicode footnote symbols 46 11 OpenType font feature files 34 21 Verbatim 46 22 Discretionary hyphenation: \- 46 IV Fonts and features with XƎTEX 36 23 Commands for old-style and lin- ing numbers 47 12 XƎTEX-only font features 36 12.1 Mapping . 36 VII fontspec.sty and 12.2 Letter spacing . 37 12.3 Different font technolo- friends 48 gies: aat and icu . 37 24 ‘Header’ code 48 12.4 Optical font sizes . 37 24.1 expl3 tools . 48 24.2 Bits and pieces . 48 13 Mac OS X’s aat fonts 38 24.3 Error/warning/info mes- 13.1 Ligatures . 38 sages . 49 13.2 Letters . 38 24.4 Option processing . 53 13.3 Numbers . 38 24.5 Packages . 53 13.4 Contextuals . 38 13.5 Vertical position . 39 25 The main package code 54 13.6 Fractions . 39 25.1 Encodings . 54 13.7 Variants . 40 25.2 User commands . 54 13.8 Alternates . 40 25.3 Programmer’s interface . 60 25.4 expl3 interface for font 13.9 Style . 41 loading . 65 13.10 CJK shape . 41 25.5 Internal macros . 66 13.11 Character width . 41 25.6 keyval definitions . 84 13.12 Vertical typesetting . 41 25.7 Italic small caps . 107 13.13 Diacritics . 42 25.8 Selecting maths fonts . 108 13.14 Annotation . 42 25.9 Finishing up . 112 25.10 Compatibility . 113 14 aat & Multiple Master font axes 42 VIII fontspec.lua 114 V Programming interface 43 15 Defining new features 43 IX fontspec-patches.sty 119 25.11 Unicode footnote symbols 119 16 Going behind fontspec’s back 44 25.12 Emph . 119 25.13 \- . 119 25.14 Verbatims . 119 17 Renaming existing features & op- 25.15 \oldstylenums . 121 tions 44 18 Programming details 45 X fontspec.cfg 123 2 1 History This package began life as a LATEX interface to select system-installed Mac OS X fonts in Jonathan Kew’s XƎTEX, the first widely-used Unicode extension to TEX. Over time, XƎTEX was extended to support OpenType fonts and then was ported into a cross-platform program to run also on Windows and Linux. More recently, LuaTEX is fast becoming the TEX engine of the day; it supports Unicode encodings and OpenType fonts and opens up the internals of TEX via the Lua programming language. Hans Hagen’s ConTEXt Mk. IV is a re-write of his powerful typesetting system, taking full advantage of LuaTEX’s features including font support; a kernel of his work in this area has been extracted to be useful for other TEX macro systems as well, and this has enabled fontspec to be adapted for LATEX when run with the LuaTEX engine. 2 Introduction The fontspec package allows users of either XƎTEX or LuaTEX to load OpenType fonts in a LATEX document. No font installation is necessary, and font features can be selected and used as desired throughout the document. Without fontspec, it is necessary to write cumbersome font definition files for LATEX, since LATEX’s font selection scheme (known as the ‘nfss’) has a lot going on behind the scenes to allow easy commands like \emph or \bfseries. With an uncountable number of fonts now available for use, however, it becomes less desirable to have to write these font definition (.fd) files for every font one wishes to use. Because fontspec is designed to work in a variety of modes, this user documentation is split into separate sections that are designed to be relatively independent. Nonetheless, the basic functionality all behaves in the same way, so previous users of fontspec under XƎTEX should have little or no difficulty switching over to LuaTEX. This manual can get rather in-depth, as there are a lot of details to cover. See the example documents fontspec-xetex.tex and fontspec-luatex.tex for a complete minimal example with each engine. 2.1 About this manual This document is typeset with pdfLATEX using pre-compiled examples that have been gen- erated by either XƎTEX or LuaTEX. You may regenerate the examples by removing the doc-files/ subdirectory and typesetting the manual with the following invocation: pdflatex -shell-escape fontspec.dtx Note that many of the examples use fonts that are not included in TEX Live or MiKTeX, and some of them are non-free fonts that must be purchased. I’d like to reduce the number of non-free fonts used in this manual. If you know any freely available fonts that could be used as alternative to any of the fonts in this document, please suggest them to me. Finally, if any aspect of the documentation is unclear or you would like to suggest more examples that could be made, get in touch. (Contributions especially welcome.) 2.2 Acknowledgements This package couldn’t be possible without the early and continued support the author of XƎTEX, Jonathan Kew. When I started this package, he steered me many times in the right direction. 3 I’ve had great feedback over the years on feature requests, documentation queries, bug reports, font suggestions, and so on from lots of people all around the world. Many thanks to you all. Thanks to David Perry and Markus Böhning for numerous documentation improve- ments and David Perry again for contributing the text for one of the sections of this manual. Special thanks to Khaled Hosny, who had been the driving force behind the support for LuaLATEX, ultimately leading to version 2.0 of the package. 3 Package loading and options For basic use, no package options are required: \usepackage{fontspec} Package options will be introduced below; some preliminary details are discussed first: xunicode Ross Moore’s xunicode package is now automatically loaded for users of both XƎLATEX and LuaLATEX. This package provides backwards compatibility with LATEX’s methods for accessing extra characters and accents (for example, \%, \$, \textbullet, \"u, and so on), plus many more Unicode characters. XƎTEX users only The xltxtra package adds some minor extra features to XƎLATEX, in- cluding, via the metalogo package, the \XeTeX macro to typeset the XƎTEX logo. While this package was previously recommended, it serves a much smaller rôle nowadays and gener- ally will not be required. Please consult its documentation to assess whether its features are warranted before loading it. LuaTEX users only In order to load fonts by their name rather than by their filename (e.g., ‘Latin Modern Roman’ instead of ‘ec-lmr10’), you may need to run the script luaotfload- tool, which is distributed with the luaotfload package. Note that if you do not execute this script beforehand, the first time you attempt to typeset the process will pause for (up to) several minutes. (But only the first time.) Please see the luaotfload documentation for more information. babel The babel package is not really supported! Especially Vietnamese, Greek, and Hebrew at least might not work correctly, as far as I can tell. There’s a better chance with Cyrillic and Latin-based languages, however—fontspec ensures at least that fonts should load correctly. The polyglossia package is recommended instead as a modern replacement for babel. 3.1 Maths fonts adjustments By default, fontspec adjusts LATEX’s default maths setup in order to maintain the correct Computer Modern symbols when the roman font changes. However, it will attempt to avoid doing this if another maths font package is loaded (such as mathpazo or the unicode-math package). If you find that fontspec is incorrectly changing the maths font when it should be leaving well enough alone, apply the [no-math] package option to manually suppress its maths font. 4 3.2 Configuration If you wish to customise any part of the fontspec interface (see later in this manual, Section 15 on page 43 and Section 17), this should be done by creating your own fontspec.cfg file, which will be automatically loaded if it is found by XƎTEX or LuaTEX.