Pages

Friday, October 18, 2013

XeLaTeX/XeTeX常见字体命令溯源

字体知识

  • Serif (衬线字体):用作正文字体。宋体、仿宋
  • Sans serif(非衬线字体): 用于标题。楷体、黑体、幼圆
  • Typewriter(打印机字体,等宽字体):

fontspec宏包

文档地址:fontspec doc fontspec支持配置文件,文档里有详细的讲解,这里忽略。

主要字体选择命令 newfontfamily

\fontspec [<font features>] {<font name>}  # one-time use
\setmainfont [<font features>] {<font name>}
\setsansfont [<font features>] {<font name>}
\setmonofont [<font features>] {<font name>}
\newfontfamily <cmd> [<font features>] {<font name>}

The font features argument accepts comma separated <font feature>=<option> lists;

这些命令也影响像\mathrm这样的数学模式使用的字体。

选择字体的方式(两种) fontspec

  1. 根据字体名称,如Times New Roman。使用这种方式,粗体、斜体立即就可以使用(使用通常的\textbf, \textit命令)。
  2. 根据字体文件名。在XeTeX中,TeX发行版自带的OpenType字体(如/usr/local/texlive/2013/texmf-dist/fonts/opentype/public)只能通过文件名加载。LuaTeX没有这个问题。在默认搜索路径(包括当前目录)上的字体可以只指定文件名,不用指定完整目录。 通过文件名选择的字体必需显式的指定粗体和斜体。如:

    \fontspec [ BoldFont = texgyrepagella-bold.otf , ItalicFont = texgyrepagella-italic.otf , BoldItalicFont = texgyrepagella-bolditalic.otf ] {texgyrepagella-regular.otf}

或者

\fontspec
  [ Extension   = .otf ,
  BoldFont      = texgyrepagella-bold ,
   ... ]
{texgyrepagella-regular}

或者

\fontspec
    [ Extension     = .otf ,
        UprightFont = *-regular ,
        BoldFont    = *-bold ,
        ... ]
    {texgyrepagella}

或者加载不在默认搜索路径的字体,指定path选项:

\fontspec
   [ Path = /Users/will/Fonts/ ,
        UprightFont = *-regular ,
        BoldFont = *-bold ,
       ... ]
{texgyrepagella}

文档默认字体族(font family) setmainfont, setsansfont, setmonofont

以下命令声明全文使用的字体,它们的参数与fontspec命令相同。

\setmainfont [<font features>] {<font name>}
\setsansfont [<font features>] {<font name>}
\setmonofont [<font features>] {<font name>}

New命令选择新字体 newfontfamily,

\newfontfamily \<font-switch> [<font features>] {<font name>}
\newfontface \<font-switch> [<font features>] {<font name>}

字形选择的更控制 BoldFont, ItalicFont, etc.

这允许我们使用字体A + 字体B的粗体 + 字体C的斜体这种组合。

BoldFont = <font name>
ItalicFont = <font name>
BoldItalicFont = <font name>
SlantedFont = <font name>
BoldSlantedFont = <font name>
SmallCapsFont = <font name>

示例:

\fontspec[BoldFont={Helvetica Neue}]
{Helvetica Neue UltraLight}

数学字体

fontspec 宏包必需在其他数学字体宏包(如euler)之后载入。fontspec不改变一般的数学,只影响upright和bold。要改变数学符号的字体,请使用mathspec或者unicode-math宏包

\setmathrm [<font features>] {<font name>}
\setmathsf [<font features>] {<font name>}
\setmathtt [<font features>] {<font name>}
\setboldmathrm [<font features>] {<font name>}

使用以上命令显式设置要在\mathrm这样的命令中使用的字体。

例子:

\usepackage{mathpazo}
\usepackage{fontspec,xunicode}
\setmainfont{Optima}
\setmathrm{Optima}
\setboldmathrm[BoldFont={Optima ExtraBlack}]{Optima Bold}

选择font feature

可以使用配置文件创建全局的或者每个字体的font feature。

关于feature

找到了这样一段话:

OpenType fonts (and other ‘smart’ font technologies such as AAT and Graphite) can change the appearance of text in many different ways. These changes are referred to as features. When the user applies a feature — for example, small capitals — to a run of text, the code inside the font makes appropriate adjustments and small capitals appear in place of lowercase letters. However, the use of such features does not affect the underlying text. In our small caps example, the lowercase letters are still stored in the document; only the appearance has been changed by the OpenType feature. This makes it possible to search and copy text without difficulty. If the user selected a different font that does not support small caps, the ‘plain’ lowercase letters would appear instead. Some OpenType features are required to support particular scripts, and these features

small caps, the ‘plain’ lowercase letters would appear instead. Some OpenType features are required to support particular scripts, and these features are often applied automatically. Other features can be applied to support a particular language.

A very large group of OpenType features is designed to support high quality typography in Latin, Greek, Cyrillic and other standard scripts.

详细的feature请参考 fontspec说明文档的第10节。

feature按照逻辑功能分类。所有的分类如下(fontspec doc 第10节)

  • Ligature (两个特定的字母连在一起,为了美观或者功能)
  • Letters (转为大写、小型大写字母等)
  • Numbers (指定显示样式等)
  • Contextuals (根据字母在单词中的位置不同使用不同的笔画)
  • VerticalPosition (把字母或数字设置为上标、下标样式)
  • Fractions (显示成小型的分数的样式,类似LaTeX的行间分数,也可以显示斜的分数线
  • StylisticSet (以另一种字母样式显示)
  • CharacterVariant (与StylisticSet类似)
  • Alternates (选择字体的可选字体样式,如果存在)
  • Style
  • Diacritics
  • Kerning (指定字母与字母之间的距离如何调整)

默认 feature defaultfontfeatures

\defaultfontfeatures{<font features>}
\defaultfontfeatures[<font name>] {<font features>}

重复使用这两个命令新设置会覆盖旧的。 例子:

\defaultfontfeatures[TeX Gyre Adventor]{Color=blue}
\setmainfont{TeX Gyre Adventor}% will be blue

改变当前选择的feature addfontfeatures

\addfontfeatures{<font features>}

例子:

\addfontfeature{Numbers=OldStyle}...
\addfontfeature{Numbers=Lining}...

例子中,两次改变同一个feature,结果如何,要看具体字体。作者说以后会实现新的配置覆盖旧的配置。

不同字体不同 feature

BoldFeatures{<features>}
ItalicFeatures{<features>}
BoldItalicFeatures{<features>}
SlantedFeatures{<features>}
BoldSlantedFeatures{<features>}
SmallCapsFeatures{<features>}

例子:

\fontspec[
    UprightFeatures={Color = 220022,
    SmallCapsFeatures = {Color=115511}},
    ItalicFeatures={Color = 2244FF,
    SmallCapsFeatures = {Color=112299}},
    BoldFeatures={Color = FF4422,
    SmallCapsFeatures = {Color=992211}},
    BoldItalicFeatures={Color = 888844,
    SmallCapsFeatures = {Color=444422}},
]{TeX Gyre Termes}

 Upright {\scshape Small Caps}\\
 \itshape Italic {\scshape Italic Small Caps}\\
 \upshape\bfseries Bold {\scshape Bold Small Caps}\\
 \itshape Bold Italic {\scshape Bold Italic Small Caps}

与字体无关的features

  1. color/colour: 颜色值为6个十六进制数,外加可选的两位十六进制数指定透明度(即RRGGBBAA或RRGGBB),注:透明度只有Mac OS X中的LuaTeX和XeTeX使用xdv2pdf驱动支持,使用xdvipdfmx的XeTeX不支持透明度。如果载入了xcolor宏包,也可以使用它定义的颜色名称。
  2. scale: Scale = / MatchLowercase / MatchUppercase
  3. ...省略了。还包括调整字距、标题符号后面的距离、连字符、

再往下都是些用处不大的东西了。不写了。

other \usefont{OT1}{cmr}{m}{n}

Written with StackEdit.