| 1 |
%%^^A%% fontspec-doc-featset.tex -- part of FONTSPEC <latex3.github.io/fontspec> |
| 2 |
|
| 3 |
\documentclass[a4paper]{l3doc} |
| 4 |
\usepackage{fontspec-doc-style} |
| 5 |
\showexamplesfalse |
| 6 |
\begin{document} |
| 7 |
|
| 8 |
\part{Selecting font features} |
| 9 |
\label{sec:selectingfeature} |
| 10 |
|
| 11 |
The commands discussed so far such as \cs{fontspec} each take an optional argument for |
| 12 |
accessing the font features of the requested font. |
| 13 |
Commands are provided to set default features to be applied for all fonts, and even to change the features that a font is presently loaded with. |
| 14 |
Different font shapes can be loaded with separate features, and different features can even be selected for different sizes that the font appears in. |
| 15 |
This part discusses these options. |
| 16 |
|
| 17 |
\section{Default settings} |
| 18 |
\label{sec:defaults} |
| 19 |
|
| 20 |
\cmdbox{\cmd\defaultfontfeatures\marg{font features}} |
| 21 |
|
| 22 |
It is sometimes useful to define |
| 23 |
font features that are applied to every subsequent font selection command. |
| 24 |
This may be defined with the |
| 25 |
\cmd{\defaultfontfeatures} command, shown in \exref{dff}. |
| 26 |
New calls of \cs{defaultfontfeatures} overwrite previous ones, and defaults can be reset by calling the command with an empty argument. |
| 27 |
|
| 28 |
\begin{Xexample}{dff}{A demonstration of the \cs{defaultfontfeatures} command.} |
| 29 |
\fontspec{texgyreadventor-regular.otf} |
| 30 |
Some default text 0123456789 \\ |
| 31 |
\defaultfontfeatures{ |
| 32 |
Numbers=OldStyle, Color=888888 |
| 33 |
} |
| 34 |
\fontspec{texgyreadventor-regular.otf} |
| 35 |
Now grey, with old-style figures: |
| 36 |
0123456789 |
| 37 |
\end{Xexample} |
| 38 |
|
| 39 |
\cmdbox{\cmd\defaultfontfeatures\oarg{font name}\marg{font features}} |
| 40 |
|
| 41 |
Default font features can be specified on a per-font and per-face basis |
| 42 |
by using the optional argument to \cs{defaultfontfeatures} as shown. |
| 43 |
\begin{Verbatim} |
| 44 |
\defaultfontfeatures[texgyreadventor-regular.otf]{Color=blue} |
| 45 |
\setmainfont{texgyreadventor-regular.otf}% will be blue |
| 46 |
\end{Verbatim} |
| 47 |
Multiple fonts may be affected by using a comma separated list of font names. |
| 48 |
|
| 49 |
\cmdbox{\cmd\defaultfontfeatures\oarg{\cs{font-switch}}\marg{font features}} |
| 50 |
|
| 51 |
\textbf{New in v2.4}. |
| 52 |
Defaults can also be applied to symbolic families such as those created with the |\newfontfamily| command and for |\rmfamily|, |\sffamily|, and |\ttfamily|: |
| 53 |
\begin{Verbatim} |
| 54 |
\defaultfontfeatures[\rmfamily,\sffamily]{Ligatures=TeX} |
| 55 |
\setmainfont{texgyreadventor-regular.otf}% will use standard TeX ligatures |
| 56 |
\end{Verbatim} |
| 57 |
The line above to set \TeX-like ligatures is now activated by \emph{default} in \texttt{fontspec.cfg}. |
| 58 |
To reset default font features, simply call the command with an empty argument: |
| 59 |
\begin{Verbatim} |
| 60 |
\defaultfontfeatures[\rmfamily,\sffamily]{} |
| 61 |
\setmainfont{texgyreadventor-regular.otf}% will no longer use standard TeX ligatures |
| 62 |
\end{Verbatim} |
| 63 |
|
| 64 |
\cmdbox{\cmd\defaultfontfeatures\texttt{+}\marg{font features}\\ |
| 65 |
\cmd\defaultfontfeatures\texttt{+}\oarg{font name}\marg{font features}} |
| 66 |
|
| 67 |
\textbf{New in v2.4}. |
| 68 |
Using the |+| form of the command appends the \meta{font features} to any already-selected defaults. |
| 69 |
|
| 70 |
|
| 71 |
\section{Working with the currently selected features} |
| 72 |
\label{sec:addfontfeatures} |
| 73 |
|
| 74 |
|
| 75 |
\cmdbox{\cmd\IfFontFeatureActiveTF\marg{font feature}\marg{true code}\marg{false code}} |
| 76 |
|
| 77 |
This command queries the currently selected font face and executes the appropriate branch based on whether the \meta{font feature} as specified by \pkg{fontspec} is currently active. |
| 78 |
|
| 79 |
For example, the following will print `True': |
| 80 |
\begin{Verbatim} |
| 81 |
\setmainfont{texgyrepagella-regular.otf}[Numbers=OldStyle] |
| 82 |
\IfFontFeatureActiveTF{Numbers=OldStyle}{True}{False} |
| 83 |
\end{Verbatim} |
| 84 |
|
| 85 |
Note that there is no way for \pkg{fontspec} to know what the default features of a font will be. For example, by default the |texgyrepagella| fonts use lining numbers. But in the following example, querying for lining numbers returns false since they have not been explicitly requested: |
| 86 |
\begin{Verbatim} |
| 87 |
\setmainfont{texgyrepagella-regular.otf} |
| 88 |
\IfFontFeatureActiveTF{Numbers=Lining}{True}{False} |
| 89 |
\end{Verbatim} |
| 90 |
|
| 91 |
Please note: At time of writing this function only supports OpenType fonts; AAT/Graphite fonts under the \XeTeX\ engine are not supported. |
| 92 |
|
| 93 |
|
| 94 |
\cmdbox{\cmd\addfontfeatures\marg{font features}} |
| 95 |
|
| 96 |
This command allows font features in an entire font family to |
| 97 |
be changed without knowing what features are currently selected or even what |
| 98 |
font family is being used. A good example of this could be to add a hook to all |
| 99 |
tabular material to use monospaced numbers, as shown in \exref{aff}. |
| 100 |
If you attempt to \emph{change} an already-selected feature, \pkg{fontspec} will try to de-activate any features that clash with the new ones. |
| 101 |
\Eg, the following two invocations are mutually exclusive: |
| 102 |
\begin{Verbatim} |
| 103 |
\addfontfeatures{Numbers=OldStyle}... |
| 104 |
\addfontfeatures{Numbers=Lining}... |
| 105 |
123 |
| 106 |
\end{Verbatim} |
| 107 |
Since |Numbers=Lining| comes last, it takes precedence and deactivates the call |Numbers=OldStyle|. |
| 108 |
|
| 109 |
If you wish to apply the change to only one of the fonts of a family (say, italics only) |
| 110 |
you can write |
| 111 |
\begin{Verbatim} |
| 112 |
\addfontfeatures{ItalicFeatures={Numbers=Lowercase}} |
| 113 |
\end{Verbatim} |
| 114 |
|
| 115 |
|
| 116 |
\begin{Lexample}{aff}{A demonstration of the \cs{addfontfeatures} command.} |
| 117 |
\fontspec{texgyreadventor-regular.otf}% |
| 118 |
[Numbers={Proportional,OldStyle}] |
| 119 |
`In 1842, 999 people sailed 97 miles in |
| 120 |
13 boats. In 1923, 111 people sailed 54 |
| 121 |
miles in 56 boats.' \bigskip |
| 122 |
|
| 123 |
{\addfontfeatures{Numbers={Monospaced,Lining}} |
| 124 |
\begin{tabular}{@{} cccc @{}} |
| 125 |
Year & People & Miles & Boats \\ |
| 126 |
\hline 1842 & 999 & 75 & 13 \\ |
| 127 |
1923 & 111 & 54 & 56 |
| 128 |
\end{tabular}} |
| 129 |
\end{Lexample} |
| 130 |
|
| 131 |
\DescribeMacro{\addfontfeature} |
| 132 |
This command may also be executed under the alias \cmd{\addfontfeature}. |
| 133 |
|
| 134 |
|
| 135 |
\subsection{Priority of feature selection} |
| 136 |
Features defined with \cs{addfontfeatures} override features |
| 137 |
specified by \cs{fontspec}, which in turn override features |
| 138 |
specified by \cs{defaultfontfeatures}. If in doubt, whenever a |
| 139 |
new font is chosen for the first time, an entry is made in the |
| 140 |
transcript (\texttt{.log}) file displaying the font name and the |
| 141 |
features requested. |
| 142 |
|
| 143 |
|
| 144 |
\section{Different features for different font shapes} |
| 145 |
\label{sec:bfit-feat} |
| 146 |
|
| 147 |
\cmdbox{ |
| 148 |
\feat{BoldFeatures}\texttt=\marg{features} \\ |
| 149 |
\feat{ItalicFeatures}\texttt=\marg{features} \\ |
| 150 |
\feat{BoldItalicFeatures}\texttt=\marg{features} \\ |
| 151 |
\feat{SlantedFeatures}\texttt=\marg{features} \\ |
| 152 |
\feat{BoldSlantedFeatures}\texttt=\marg{features} \\ |
| 153 |
\feat{SwashFeatures}\texttt=\marg{features} \\ |
| 154 |
\feat{BoldSwashFeatures}\texttt=\marg{features} \\ |
| 155 |
\feat{SmallCapsFeatures}\texttt=\marg{features} \\ |
| 156 |
\feat{UprightFeatures}\texttt=\marg{features} |
| 157 |
} |
| 158 |
|
| 159 |
It is entirely possible that separate fonts in a family will require |
| 160 |
separate options; \eg, certain italic fonts contains various swash |
| 161 |
feature options that are usually unavailable in the upright (`roman') shapes. |
| 162 |
|
| 163 |
The font features defined at the top level of the optional \cmd\fontspec\ |
| 164 |
argument are applied to \emph{all} shapes of the family. |
| 165 |
Using the \feat{xxFeatures} options shown above, |
| 166 |
separate font features may be defined to their respective shapes |
| 167 |
\emph{in addition} to, and with precedence over, the `global' font features. |
| 168 |
See \exref{itfeat}. |
| 169 |
|
| 170 |
\begin{Xexample}{itfeat}{Features for, say, just italics.} |
| 171 |
\fontspec{EBGaramond-Regular.otf}% |
| 172 |
[ItalicFont=EBGaramond-Italic.otf] |
| 173 |
\itshape Don’t Ask Victoria! \\ |
| 174 |
\addfontfeature{ItalicFeatures={Style=Swash}} |
| 175 |
Don’t Ask Victoria! \\ |
| 176 |
\end{Xexample} |
| 177 |
|
| 178 |
Note that because most fonts include their small caps glyphs |
| 179 |
within the main font, features specified with \feat{SmallCapsFeatures} are applied \emph{in addition} to |
| 180 |
any other shape-specific features as defined above, and hence \feat{SmallCapsFeatures} |
| 181 |
can be nested within \feat{ItalicFeatures} and friends. Every combination |
| 182 |
of upright, italic, bold, (etc.), and small caps can thus be assigned individual |
| 183 |
features, as shown in the somewhat ludicrous \exref{scfeat}. |
| 184 |
|
| 185 |
\begin{Xexample}{scfeat}{An example of setting the \feat{SmallCapsFeatures} |
| 186 |
separately for each font shape.} |
| 187 |
\fontspec{texgyretermes}[ |
| 188 |
Extension = {.otf}, |
| 189 |
UprightFont = {*-regular}, ItalicFont = {*-italic}, |
| 190 |
BoldFont = {*-bold}, BoldItalicFont = {*-bolditalic}, |
| 191 |
UprightFeatures={Color = 220022, |
| 192 |
SmallCapsFeatures = {Color=115511}}, |
| 193 |
ItalicFeatures={Color = 2244FF, |
| 194 |
SmallCapsFeatures = {Color=112299}}, |
| 195 |
BoldFeatures={Color = FF4422, |
| 196 |
SmallCapsFeatures = {Color=992211}}, |
| 197 |
BoldItalicFeatures={Color = 888844, |
| 198 |
SmallCapsFeatures = {Color=444422}}, |
| 199 |
] |
| 200 |
Upright {\scshape Small Caps}\\ |
| 201 |
\itshape Italic {\scshape Italic Small Caps}\\ |
| 202 |
\upshape\bfseries Bold {\scshape Bold Small Caps}\\ |
| 203 |
\itshape Bold Italic {\scshape Bold Italic Small Caps} |
| 204 |
\end{Xexample} |
| 205 |
|
| 206 |
|
| 207 |
\section{Selecting fonts from TrueType Collections (TTC files)} |
| 208 |
TrueType Collections are multiple fonts contained within a single file. |
| 209 |
Each font within a collection must be explicitly chosen using the \feat{FontIndex} command. |
| 210 |
Since TrueType Collections are often used to contain the italic/bold shapes in a family, \pkg{fontspec} automatically selects the italic, bold, and bold italic fontfaces from the same file. |
| 211 |
For example, to load the macOS system font Optima: |
| 212 |
\begin{Verbatim} |
| 213 |
\setmainfont{Optima.ttc}[ |
| 214 |
Path = /System/Library/Fonts/ , |
| 215 |
UprightFeatures = {FontIndex=0} , |
| 216 |
BoldFeatures = {FontIndex=1} , |
| 217 |
ItalicFeatures = {FontIndex=2} , |
| 218 |
BoldItalicFeatures = {FontIndex=3} , |
| 219 |
] |
| 220 |
\end{Verbatim} |
| 221 |
Support for TrueType Collections has only been tested in \XeTeX, but should also work with an up-to-date version of \LuaTeX\ and the \pkg{luaotfload} package. |
| 222 |
|
| 223 |
|
| 224 |
\section{Different features for different font sizes} |
| 225 |
\label{sec:sizefeature} |
| 226 |
|
| 227 |
\cmdbox{ |
| 228 |
\ttfamily SizeFeatures = \char`\{\\ |
| 229 |
\null\quad...\\ |
| 230 |
\null\quad\char`\{~Size = |
| 231 |
\rmfamily\meta{size range}\ttfamily |
| 232 |
, |
| 233 |
\rmfamily \meta{font features}\ttfamily |
| 234 |
~\char`\} , \\ |
| 235 |
\null\quad\char`\{~Size = |
| 236 |
\rmfamily\meta{size range}\ttfamily |
| 237 |
, Font = |
| 238 |
\rmfamily\meta{font name}\texttt, \meta{font features}\ttfamily |
| 239 |
~\char`\} , \\ |
| 240 |
\null\quad... \\ |
| 241 |
\char`\}} |
| 242 |
|
| 243 |
The \feat{SizeFeatures} feature is a little more complicated |
| 244 |
than the previous features discussed. It allows different fonts |
| 245 |
and different font features to be selected for a given font |
| 246 |
family as the point size varies. |
| 247 |
|
| 248 |
It takes a comma separated list of braced, comma separated lists of features for each size range. |
| 249 |
Each sub-list must contain the \opt{Size} option |
| 250 |
to declare the size range, and optionally \opt{Font} to change the |
| 251 |
font based on size. Other (regular) fontspec features that are added |
| 252 |
are used on top of the font features that would be used anyway. |
| 253 |
A demonstration to clarify these details is shown in \exref{sizefeat}. |
| 254 |
A less trivial example is shown in the context of optical font sizes |
| 255 |
in \vref{sec:opticalsize}. |
| 256 |
|
| 257 |
\begin{Xexample}{sizefeat}{An example of specifying different font features for different sizes of font with \feat{SizeFeatures}.} |
| 258 |
\fontspec{texgyrechorus-mediumitalic.otf}[ |
| 259 |
SizeFeatures={ |
| 260 |
{Size={-8}, Font=texgyrebonum-italic.otf, Color=AA0000}, |
| 261 |
{Size={8-14}, Color=00AA00}, |
| 262 |
{Size={14-}, Color=0000AA}} ] |
| 263 |
|
| 264 |
{\scriptsize Small\par} Normal size\par {\Large Large\par} |
| 265 |
\end{Xexample} |
| 266 |
|
| 267 |
To be precise, the \opt{Size} sub-feature accepts arguments in the form shown in \vref{tab:sizing}. |
| 268 |
Braces around the size range are optional. For an exact font size (|Size=X|) |
| 269 |
font sizes chosen near that size will `snap'. For example, for size definitions |
| 270 |
at exactly 11pt and 14pt, if a 12pt font is requested \emph{actually} the |
| 271 |
11pt font will be selected. This is a remnant of the past when fonts were designed |
| 272 |
in metal (at obviously rigid sizes) and later when bitmap fonts were similarly |
| 273 |
designed for fixed sizes. |
| 274 |
|
| 275 |
If additional features are only required for a single size, the other sizes |
| 276 |
must still be specified. As in: |
| 277 |
\begin{Verbatim} |
| 278 |
SizeFeatures={ |
| 279 |
{Size=-10,Numbers=Uppercase}, |
| 280 |
{Size=10-}} |
| 281 |
\end{Verbatim} |
| 282 |
Otherwise, the font sizes greater than 10 won't be defined at all! |
| 283 |
|
| 284 |
\begin{table} |
| 285 |
\caption{Syntax for specifying the size to apply custom font features.}\label{tab:sizing} |
| 286 |
\centering |
| 287 |
\begin{tabular}{@{}ll@{}} |
| 288 |
\toprule |
| 289 |
Input & Font size, $s$ \\ |
| 290 |
\midrule |
| 291 |
|Size = X-| & $s \geq \texttt{X}$ \\ |
| 292 |
|Size = -Y| & $s < \texttt{Y}$ \\ |
| 293 |
|Size = X-Y| & $\texttt{X} \leq s < \texttt{Y}$ \\ |
| 294 |
|Size = X| & $s = \texttt{X}$ \\ |
| 295 |
\bottomrule |
| 296 |
\end{tabular} |
| 297 |
\end{table} |
| 298 |
|
| 299 |
\paragraph{Interaction with other features} |
| 300 |
For \feat{SizeFeatures} to work with \feat{ItalicFeatures}, \feat{BoldFeatures}, etc., and \feat{SmallCapsFeatures}, a strict hierarchy is required: |
| 301 |
\begin{Verbatim} |
| 302 |
UprightFeatures = |
| 303 |
{ |
| 304 |
SizeFeatures = |
| 305 |
{ |
| 306 |
{ |
| 307 |
Size = -10, |
| 308 |
Font = ..., % if necessary |
| 309 |
SmallCapsFeatures = {...}, |
| 310 |
... % other features for this size range |
| 311 |
}, |
| 312 |
... % other size ranges |
| 313 |
} |
| 314 |
} |
| 315 |
\end{Verbatim} |
| 316 |
Suggestions on simplifying this interface welcome. |
| 317 |
|
| 318 |
|
| 319 |
\section{Font independent options} |
| 320 |
\label{sec:font-ind-features} |
| 321 |
|
| 322 |
Features introduced in this section may be used with any font. |
| 323 |
|
| 324 |
\subsection{Colour} |
| 325 |
|
| 326 |
\feat{Color} (or \feat{Colour}) uses font specifications to set the colour of |
| 327 |
the text. |
| 328 |
You should think of this as the literal glyphs of the font being coloured in a certain way. |
| 329 |
Notably, this mechanism is different to that of the \pkg{color}/\pkg{xcolor}/\pkg{hyperref}/etc.\ packages, and in fact using \pkg{fontspec} commands to set colour will prevent your text from changing colour using those packages at all! |
| 330 |
(For example, if you set the colour in a \verb|\setmainfont| command, \verb|\color{...}| and related commands, including hyperlink colouring, will no longer have any effect on text in this font.) |
| 331 |
Therefore, \pkg{fontspec}'s colour commands are best used to set explicit colours in specific situations, and the \pkg{xcolor} package is recommended for more general colour functionality. |
| 332 |
|
| 333 |
The colour can be defined as a triplet of two-digit Hex RGB |
| 334 |
values, with optionally another value for the transparency (where |
| 335 |
|00| is completely transparent and |FF| is opaque.) |
| 336 |
\begin{Lexample}{color}{Selecting colour with transparency.} |
| 337 |
\fontsize{48}{48} |
| 338 |
\fontspec{texgyrebonum-bold.otf} |
| 339 |
{\addfontfeature{Color=FF000099}W}\kern-0.4ex |
| 340 |
{\addfontfeature{Color=0000FF99}S}\kern-0.4ex |
| 341 |
{\addfontfeature{Color=DDBB2299}P}\kern-0.5ex |
| 342 |
{\addfontfeature{Color=00BB3399}R} |
| 343 |
\end{Lexample} |
| 344 |
|
| 345 |
If you load the \pkg{xcolor} package, you may use any named colour instead |
| 346 |
of writing the colours in hexadecimal. |
| 347 |
\begin{Verbatim} |
| 348 |
\usepackage{xcolor} |
| 349 |
... |
| 350 |
\fontspec[Color=red]{Montserrat-Medium.otf} ... |
| 351 |
\definecolor{Foo}{rgb}{0.3,0.4,0.5} |
| 352 |
\fontspec[Color=Foo]{Montserrat-Medium.otf} ... |
| 353 |
\end{Verbatim} |
| 354 |
|
| 355 |
You may also use named colours defined with the color commands of the L3 |
| 356 |
programming layer: |
| 357 |
\begin{Verbatim} |
| 358 |
\ExplSyntaxOn |
| 359 |
\color_set:nnn{Foo}{rgb}{0.3,0.4,0.5} |
| 360 |
\ExplSyntaxOff |
| 361 |
... |
| 362 |
\fontspec[Color=Foo]{Montserrat-Medium.otf} ... |
| 363 |
\end{Verbatim} |
| 364 |
|
| 365 |
Color expressions (like \verb+red!50!blue+) are not supported. The \pkg{color} |
| 366 |
package is \emph{not} supported neither. |
| 367 |
|
| 368 |
The code will at first test for color names of the L3 layer, then for xcolor |
| 369 |
names, and at last try to use the argument as a hexadecimal value. |
| 370 |
|
| 371 |
You may specify the transparency with a named colour using the \feat{Opacity} |
| 372 |
feature, which takes an decimal from zero to one corresponding to transparent |
| 373 |
to opaque respectively: |
| 374 |
\begin{Verbatim} |
| 375 |
\fontspec[Color=red,Opacity=0.7]{Montserrat-Medium.otf} ... |
| 376 |
\end{Verbatim} |
| 377 |
It is still possible to specify a colour in six-char hexadecimal form |
| 378 |
while defining opacity in this way, if you like. |
| 379 |
|
| 380 |
\subsubsection{Color models} |
| 381 |
|
| 382 |
With \XeTeX\ color are always written in the rgb color model into the PDF. |
| 383 |
When using \LuaTeX, colors with the commands of the L3 layer can be written |
| 384 |
as rgb or cmyk or as spot color depending on their definition and of the |
| 385 |
value of the variable \verb+\l_color_fixed_model_tl+. |
| 386 |
|
| 387 |
\subsubsection{Spot colors} |
| 388 |
With \LuaTeX\ it is possible to use spot colors. This requires the use of the |
| 389 |
PDF management: |
| 390 |
\begin{Verbatim} |
| 391 |
\DocumentMetadata{} |
| 392 |
\documentclass{article} |
| 393 |
\usepackage{fontspec} |
| 394 |
\ExplSyntaxOn |
| 395 |
\color_model_new:nnn { sepblue } { Separation } |
| 396 |
{ |
| 397 |
name = PANTONE~3005~U , |
| 398 |
alternative-model = cmyk , |
| 399 |
alternative-values = {1, 0.56, 0,0}, |
| 400 |
} |
| 401 |
\color_set:nnn{spotblue}{sepblue}{1} |
| 402 |
\ExplSyntaxOff |
| 403 |
... |
| 404 |
\fontspec[Color=spotblue]{texgyreheros} |
| 405 |
\end{Verbatim} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
\subsection{Scale} |
| 410 |
|
| 411 |
\cmdbox{ |
| 412 |
\feat{Scale} = \meta{number} \\ |
| 413 |
\feat{Scale} = \opt{MatchLowercase} \\ |
| 414 |
\feat{Scale} = \opt{MatchUppercase} \\ |
| 415 |
\feat{Scale} = \opt{MatchAveragecase} |
| 416 |
} |
| 417 |
|
| 418 |
In its explicit form, \feat{Scale} takes a single |
| 419 |
numeric argument for linearly scaling the font, as demonstrated |
| 420 |
in \exref{fontload}. |
| 421 |
|
| 422 |
As well as a numerical argument, the \feat{Scale} feature |
| 423 |
also accepts options \opt{MatchLowercase}, \opt{MatchUppercase}, |
| 424 |
and \opt{MatchAveragecase}, which will scale the font being selected to match |
| 425 |
the current default roman font to either the height of the lowercase, |
| 426 |
the height of the uppercase letters, or the average of the two, |
| 427 |
respectively; these features are shown in \exref{scale}. |
| 428 |
The amount of scaling used in each instance is reported in the \texttt{.log} file. |
| 429 |
|
| 430 |
\begin{Xexample}{scale}{Automatically calculated scale values.} |
| 431 |
\setmainfont{texgyrepagella-regular.otf} |
| 432 |
\newfontfamily\lc[Scale=MatchLowercase]{texgyreadventor-regular.otf} |
| 433 |
The perfect match {\lc is hard to find.}\\ |
| 434 |
\newfontfamily\uc[Scale=MatchUppercase]{texgyreheros-regular.otf} |
| 435 |
L O G O {\uc F O N T}\\ |
| 436 |
\newfontfamily\ac[Scale=MatchAveragecase]{FiraMath-Regular.otf} |
| 437 |
Lower {\ac and UPPER} CASE |
| 438 |
\end{Xexample} |
| 439 |
|
| 440 |
Additional calls to the \feat{Scale} feature overwrite the settings of the former. |
| 441 |
If you want to accumulate scale factors (useful perhaps to fine-tune the settings of |
| 442 |
\opt{MatchLowercase}), the \feat{ScaleAgain} feature can be used as many times as |
| 443 |
necessary. For example: |
| 444 |
\begin{Verbatim} |
| 445 |
[ Scale = 1.1 , Scale = 1.2 ] % -> scale of 1.2 |
| 446 |
[ Scale = 1.1 , ScaleAgain = 1.2 ] % -> scale of 1.32 |
| 447 |
\end{Verbatim} |
| 448 |
|
| 449 |
Note that when |Scale=MatchLowercase|, |Scale=MatchUppercase|, or |Scale=MatchAverageCase| |
| 450 |
is used with |\setmainfont|, the new `main' |
| 451 |
font of the document will be scaled to match the old default. |
| 452 |
If you wish to automatically scale all fonts except have the main font use `natural' |
| 453 |
scaling, you may write |
| 454 |
\begin{Verbatim} |
| 455 |
\defaultfontfeatures{ Scale = MatchLowercase } |
| 456 |
\defaultfontfeatures[\rmfamily]{ Scale = 1} |
| 457 |
\end{Verbatim} |
| 458 |
One or both of these lines may be placed into a local |fontspec.cfg| file |
| 459 |
(see \vref{sec:config}) for this behaviour to be effected in your own documents |
| 460 |
automatically. |
| 461 |
(Also see \vref{sec:defaults} for more information on setting font defaults.) |
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
\subsection{Interword space} |
| 467 |
|
| 468 |
While the space between words can be varied with the \TeX\ primitive |
| 469 |
\cmd\spaceskip\ command, \pkg{fontspec} also supports changing the |
| 470 |
interword spacing when a given font is loaded. |
| 471 |
|
| 472 |
The space in between words in a paragraph will be chosen automatically, |
| 473 |
and generally will not need to be adjusted. For those |
| 474 |
times when the precise details are important, the \feat{WordSpace} |
| 475 |
feature is |
| 476 |
provided, which takes either a single scaling factor to scale the |
| 477 |
default value, or a triplet of comma-separated |
| 478 |
values to scale the nominal value, the stretch, and the shrink of the |
| 479 |
interword space by, respectively. (|WordSpace={|$x$|}| is the same as |
| 480 |
|WordSpace={|$x$|,|$x$|,|$x$|}|.) |
| 481 |
|
| 482 |
\begingroup |
| 483 |
\let\centering\relax |
| 484 |
\begin{Xexample}{wordspace}{Scaling the default interword space. An exaggerated value has been chosen to emphasise the effects here.} |
| 485 |
\fontspec{texgyretermes-regular.otf} |
| 486 |
Some text for our example to take |
| 487 |
up some space, and to demonstrate |
| 488 |
the default interword space. |
| 489 |
\bigskip |
| 490 |
|
| 491 |
\fontspec{texgyretermes-regular.otf}% |
| 492 |
[WordSpace = 0.3] |
| 493 |
Some text for our example to take |
| 494 |
up some space, and to demonstrate |
| 495 |
the default interword space. |
| 496 |
\end{Xexample} |
| 497 |
\endgroup |
| 498 |
|
| 499 |
Note that \TeX's optimisations in how it loads fonts means that you cannot |
| 500 |
use this feature in \cs{addfontfeatures}. |
| 501 |
|
| 502 |
\subsection{Post-punctuation space} |
| 503 |
|
| 504 |
If \cmd\frenchspacing\ is \emph{not} in effect (which is the default), \TeX\ will allow extra space after some punctuation in its goal of justifying the lines of text. |
| 505 |
|
| 506 |
The \feat{PunctuationSpace} feature takes a scaling factor by which to |
| 507 |
adjust the nominal value chosen for the font; this is demonstrated in |
| 508 |
\exref{punctspace}. |
| 509 |
Note that |PunctuationSpace=0| |
| 510 |
is \emph{not} equivalent to \cmd\frenchspacing, although the difference |
| 511 |
will only be apparent when a line of text is under-full. |
| 512 |
|
| 513 |
\begin{Lexample}{punctspace}{Scaling the default post-punctuation space.} |
| 514 |
\nonfrenchspacing |
| 515 |
\fontspec{texgyreschola-regular.otf} |
| 516 |
Letters, Words. Sentences. \par |
| 517 |
\fontspec{texgyreschola-regular.otf}[PunctuationSpace=2] |
| 518 |
Letters, Words. Sentences. \par |
| 519 |
\fontspec{texgyreschola-regular.otf}[PunctuationSpace=0] |
| 520 |
Letters, Words. Sentences. |
| 521 |
\end{Lexample} |
| 522 |
|
| 523 |
Note that \TeX's optimisations in how it loads fonts means that you cannot |
| 524 |
use this feature in \cs{addfontfeatures}. |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
\subsection{The hyphenation character} |
| 529 |
|
| 530 |
The letter used for hyphenation may be chosen with the \feat{HyphenChar} |
| 531 |
feature. |
| 532 |
With one exception (\feat{HyphenChar} \texttt{=} \opt{None}), |
| 533 |
this is a \XeTeX-only feature since \LuaTeX\ cannot set the hyphenation character on a per-font basis; |
| 534 |
see its \cs{prehyphenchar} primitive for further details. |
| 535 |
|
| 536 |
\feat{HyphenChar} takes three types of input, which are chosen according to some |
| 537 |
simple rules. If the input is the string \opt{None}, then hyphenation is |
| 538 |
suppressed for this font. |
| 539 |
|
| 540 |
As part of \texttt{fontspec.cfg}, the default monospaced family (e.g., \verb|\ttfamily|) |
| 541 |
is set up to automatically set \feat{HyphenChar} \texttt{=} \opt{None}. |
| 542 |
|
| 543 |
If the input is a single character, then this character is used. |
| 544 |
Finally, if the input is longer than a single character |
| 545 |
it must be the UTF-8 slot number of the hyphen character you desire. |
| 546 |
|
| 547 |
\begin{Xexample}{hyphchar}{Explicitly choosing the hyphenation character.} |
| 548 |
\def\text{\fbox{\parbox{1.55cm}{% |
| 549 |
EXAMPLE HYPHENATION% |
| 550 |
}}\qquad\qquad\null\par\bigskip} |
| 551 |
|
| 552 |
\fontspec{LinLibertine_R.otf}[HyphenChar=None] |
| 553 |
\text |
| 554 |
\fontspec{LinLibertine_R.otf}[HyphenChar={+}] |
| 555 |
\text |
| 556 |
\end{Xexample} |
| 557 |
|
| 558 |
Note that \TeX's optimisations in how it loads fonts means that you cannot |
| 559 |
use this feature in \cs{addfontfeatures}. |
| 560 |
|
| 561 |
\subsection{Optical font sizes} \label{sec:opticalsize} |
| 562 |
|
| 563 |
Optically scaled fonts thicken out as the font size decreases |
| 564 |
in order to make the glyph shapes more robust (less prone to losing |
| 565 |
detail), which improves legibility. Conversely, at large optical |
| 566 |
sizes the serifs and other small details may be more delicately |
| 567 |
rendered. |
| 568 |
|
| 569 |
OpenType fonts with optical scaling can exist in |
| 570 |
several discrete sizes (in separate font files). |
| 571 |
When loading fonts by name, \XeTeX\ and Lua\TeX\ engines will attempt to |
| 572 |
\emph{automatically} load the appropriate font as determined by the current font size. |
| 573 |
An example of this behaviour is shown in \exref{optsize}, in which some larger text is |
| 574 |
mechanically scaled down to compare the difference for equivalent font sizes. |
| 575 |
|
| 576 |
The \feat{OpticalSize} feature may be used to specify a different optical size. |
| 577 |
With \feat{OpticalSize} set (\exref{optsize0}) |
| 578 |
to zero, no optical size font substitution is performed. |
| 579 |
|
| 580 |
\begin{Lexample}{optsize}{A demonstration of automatic optical size selection.} |
| 581 |
\fontspec{Latin Modern Roman} |
| 582 |
Automatic optical size \\ |
| 583 |
\scalebox{0.4}{\Huge |
| 584 |
Automatic optical size} |
| 585 |
\end{Lexample} |
| 586 |
|
| 587 |
\begin{Lexample}{optsize0}{Explicit optical size substitution for the Latin Modern Roman family.} |
| 588 |
\fontspec{Latin Modern Roman}[OpticalSize=5] |
| 589 |
Latin Modern optical sizes \\ |
| 590 |
\fontspec{Latin Modern Roman}[OpticalSize=8] |
| 591 |
Latin Modern optical sizes \\ |
| 592 |
\fontspec{Latin Modern Roman}[OpticalSize=12] |
| 593 |
Latin Modern optical sizes \\ |
| 594 |
\fontspec{Latin Modern Roman}[OpticalSize=17] |
| 595 |
Latin Modern optical sizes |
| 596 |
\end{Lexample} |
| 597 |
|
| 598 |
The \feat{SizeFeatures} feature (\vref{sec:sizefeature}) can be |
| 599 |
used to specify exactly which optical sizes will be used for ranges |
| 600 |
of font size. For example, something like: |
| 601 |
\begin{Verbatim} |
| 602 |
\fontspec{Latin Modern Roman}[ |
| 603 |
UprightFeatures = { SizeFeatures = { |
| 604 |
{Size=-10, OpticalSize=8 }, |
| 605 |
{Size= 10-14, OpticalSize=10}, |
| 606 |
{Size= 14-18, OpticalSize=14}, |
| 607 |
{Size= 18-, OpticalSize=18}}} |
| 608 |
] |
| 609 |
\end{Verbatim} |
| 610 |
|
| 611 |
\subsection{Font transformations} |
| 612 |
|
| 613 |
In rare situations users may want to mechanically distort the shapes of the glyphs in the current font such as shown in \exref{fake}. Please don't overuse these features; they are \emph{not} a good alternative to having the real shapes. |
| 614 |
|
| 615 |
\begin{Xexample}{fake}{Artificial font transformations.} |
| 616 |
\fontspec{Quattrocento-Regular.ttf} \emph{ABCxyz} \quad |
| 617 |
\fontspec{Quattrocento-Regular.ttf}[FakeSlant=0.2] ABCxyz |
| 618 |
|
| 619 |
\fontspec{Quattrocento-Regular.ttf} ABCxyz \quad |
| 620 |
\fontspec{Quattrocento-Regular.ttf}[FakeStretch=1.2] ABCxyz |
| 621 |
|
| 622 |
\fontspec{Quattrocento-Regular.ttf} \textbf{ABCxyz} \quad |
| 623 |
\fontspec{Quattrocento-Regular.ttf}[FakeBold=1.5] ABCxyz |
| 624 |
\end{Xexample} |
| 625 |
|
| 626 |
If values are omitted, their defaults are as shown above. |
| 627 |
|
| 628 |
If you want the bold shape to be faked automatically, or the italic shape |
| 629 |
to be slanted automatically, use the \feat{AutoFakeBold} and |
| 630 |
\feat{AutoFakeSlant} features. For example, the following two invocations |
| 631 |
are equivalent: |
| 632 |
\begin{Verbatim} |
| 633 |
\fontspec[AutoFakeBold=1.5]{Charis SIL} |
| 634 |
\fontspec[BoldFeatures={FakeBold=1.5}]{Charis SIL} |
| 635 |
\end{Verbatim} |
| 636 |
If both of the \feat{AutoFake...} features are used, then the bold italic |
| 637 |
font will also be faked. |
| 638 |
|
| 639 |
|
| 640 |
\subsection{Letter spacing} |
| 641 |
Letter spacing, or tracking, is the term given to adding (or subtracting) a small amount of horizontal space in between adjacent characters. It is specified with the \feat{LetterSpace}, which takes a numeric argument, |
| 642 |
shown in \exref{tracking}. |
| 643 |
|
| 644 |
The letter spacing parameter is a normalised additive factor (not a scaling factor); it is defined as a percentage of the font size. That is, for a 10\,pt font, a letter spacing parameter of `|1.0|' will add 0.1\,pt between each letter. |
| 645 |
|
| 646 |
\begin{Xexample}{tracking}{The \feat{LetterSpace} feature.} |
| 647 |
\setmainfont{Ysabeau-Light.otf} |
| 648 |
\addfontfeature{LetterSpace=0.0} |
| 649 |
USE TRACKING FOR DISPLAY CAPS TEXT \\ |
| 650 |
\addfontfeature{LetterSpace=3.0} |
| 651 |
USE TRACKING FOR DISPLAY CAPS TEXT |
| 652 |
\end{Xexample} |
| 653 |
|
| 654 |
This functionality is not generally used for lowercase text in modern typesetting but does have historic precedent in a variety of situations. |
| 655 |
In particular, small amounts of letter spacing can be very useful, when setting small caps or all caps titles. |
| 656 |
Also see the OpenType \opt{Uppercase} option of the \feat{Letters} feature (\vref{sec:letters}). |
| 657 |
|
| 658 |
|
| 659 |
\section{Variable fonts} \label{sec:variable} |
| 660 |
|
| 661 |
OpenType variable fonts and Multiple Master fonts are parameterised over |
| 662 |
orthogonal font axes, allowing continuous selection along such features |
| 663 |
as weight, width, and optical size. |
| 664 |
|
| 665 |
Currently OpenType variable fonts are only supported in \LuaTeX, while |
| 666 |
Multiple Master fonts only work with \XeTeX. |
| 667 |
|
| 668 |
\subsection{Optical font sizes} \label{sec:aat-opticalsize} |
| 669 |
Whereas traditional OpenType fonts will have only a few separate |
| 670 |
optical sizes, a Variable or Multiple Master font's optical size can be |
| 671 |
specified over a continuous range. Unfortunately, this flexibility makes |
| 672 |
it harder to create an automatic interface through \LaTeX, and the |
| 673 |
optical size for a Variable or Multiple Master font must always be specified |
| 674 |
explicitly. |
| 675 |
\begin{Verbatim} |
| 676 |
\fontspec{Minion MM Roman}[OpticalSize=11] |
| 677 |
MM optical size test \\ |
| 678 |
\fontspec{Minion MM Roman}[OpticalSize=47] |
| 679 |
MM optical size test \\ |
| 680 |
\fontspec{Minion MM Roman}[OpticalSize=71] |
| 681 |
MM optical size test \\ |
| 682 |
\end{Verbatim} |
| 683 |
|
| 684 |
|
| 685 |
\subsection{Weight} \label{sec:variable-weight} |
| 686 |
For fonts with a variable weight axis, the weight can be specified through the |
| 687 |
\feat{Weight} feature. The value should be between 0 and 1000, where typically |
| 688 |
400 corresponds to regular weight and 700 is a bold font. |
| 689 |
\begin{Verbatim} |
| 690 |
\fontspec{Source Serif Variable}[Weight=700] |
| 691 |
Bold \\ |
| 692 |
\fontspec{Source Serif Variable}[Weight=200] |
| 693 |
Extra Light \\ |
| 694 |
\end{Verbatim} |
| 695 |
|
| 696 |
|
| 697 |
\subsection{Width} \label{sec:variable-width} |
| 698 |
Similarly, the \feat{Width} feature allows specifying the value of the width axis, |
| 699 |
where the value is a percentage of normal width. |
| 700 |
\begin{Verbatim} |
| 701 |
\fontspec{Noto Serif}[Width=100] |
| 702 |
Normal Width \\ |
| 703 |
\fontspec{Noto Serif}[Width=75] |
| 704 |
Condensed \\ |
| 705 |
\end{Verbatim} |
| 706 |
|
| 707 |
\subsection{Slant} \label{sec:variable-slant} |
| 708 |
Also fonts with a slant axis can be controlled with the \feat{Slant} feature. |
| 709 |
In a standard compliant font the value should specify the clockwise angle in degree |
| 710 |
the glyphs are slanted. Therefore for a typical forward leaning slanted font, a |
| 711 |
negative value should be passed. |
| 712 |
|
| 713 |
Many fonts use this feature in non-standard ways, so you might have to experiment |
| 714 |
a bit with the value. |
| 715 |
\begin{Verbatim} |
| 716 |
\fontspec{Roboto Flex}[Slant=0] |
| 717 |
Upright \\ |
| 718 |
\fontspec{Roboto Flex}[Slant=-5] |
| 719 |
Slanted \\ |
| 720 |
\end{Verbatim} |
| 721 |
|
| 722 |
\subsection{Other axes} \label{sec:variable-raw} |
| 723 |
For OpenType variable fonts, additional axis values can be specified |
| 724 |
if the four letter tag of these axes is known. |
| 725 |
Than their value can be set with the \feat{RawAxis} feature: |
| 726 |
\begin{Verbatim} |
| 727 |
\fontspec{Noto Serif}[RawAxis={CTGR=100}] |
| 728 |
Maximal contrast \\ |
| 729 |
\fontspec{Noto Serif}[RawAxis={CTGR=0}] |
| 730 |
Regular contrast \\ |
| 731 |
\end{Verbatim} |
| 732 |
|
| 733 |
\subsection{Instances} \label{sec:variable-instances} |
| 734 |
Instead of manually setting axis values, many fonts contain named instances which are predefined settings of all axes. |
| 735 |
|
| 736 |
To select such an instance, the \feat{Instance} feature can be used: |
| 737 |
\begin{Verbatim} |
| 738 |
\fontspec{Noto Serif}[Instance=ExtraCondensed Bold] |
| 739 |
This is in extra condensed bold. |
| 740 |
\end{Verbatim} |
| 741 |
|
| 742 |
\end{document} |
| 743 |
|
| 744 |
% /© |
| 745 |
% ------------------------------------------------ |
| 746 |
% The FONTSPEC package <latex3.github.io/fontspec> |
| 747 |
% ------------------------------------------------ |
| 748 |
% Copyright 2022-2025 The LaTeX project, LPPL "maintainer" |
| 749 |
% Copyright 2004-2022 Will Robertson |
| 750 |
% Copyright 2009-2015 Khaled Hosny |
| 751 |
% Copyright 2013 Philipp Gesang |
| 752 |
% Copyright 2013-2016 Joseph Wright |
| 753 |
% ------------------------------------------------ |
| 754 |
% This package is free software and may be redistributed and/or modified under |
| 755 |
% the conditions of the LaTeX Project Public License, version 1.3c or higher |
| 756 |
% (your choice): <http://www.latex-project.org/lppl/>. |
| 757 |
% ------------------------------------------------ |
| 758 |
% ©/ |