定义 n 个字体 \newfontfamily

定义 n 个字体 \newfontfamily

这个问题取代了我之前不清楚的问题。

我想在 XeLatex 中使用 OTF 字体。具体来说,例如,以下是我的计算机上可用的一些 Linux Libertine 字体/字体系列:

(Serif)
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinBiolinum_R.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinBiolinum_RB.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinBiolinum_RBO.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinBiolinum_RI.otf
.....

(Sans Serif)
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinLibertine_R.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinLibertine_I.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinLibertine_M.otf
/usr/share/texmf-dist/fonts/opentype/public/libertine/LinLibertine_MB.otf
....

假设我想要使用 LinLibertine 的所有字体;罗马字体、斜体字体等,而无需单独定义 \rm、\it。是否有简单的命令可以做到这一点?是否可以同时对 LinLibertine(衬线字体)和 LinBiolinum(无衬线字体)执行此操作。我无法找到一个合适的答案来回答这个肯定是基本的问题。

在这样的命令中使用什么“名称”以及如何知道“名称”是什么。在上面的例子中,它是 libertine 还是 LinLibertine 或缩写(例如“cm”),“名称”是否大写?

答案1

首先,xelatex有一个强制包可以使用其他字体(参见texdoc fontspec文档)

\usepackage{fontspec}

在那之后,将字体系列名称定义为所有样式所共有的文件名的一部分(区分大小写)是有意义的。

就你的情况而言:

  1. 林比奥林
  2. 林放荡者

然后在 fontspec 文档中搜索字体系列后,您可能会考虑像这样创建两个新的字体系列:

定义 n 个字体 \newfontfamily

您定义命令名称,但使用语义相关的名称是有意义的。

\newfontfamily\LinBiolinum[%
  Extension = .otf , 
  UprightFont = *_R , % roman font style (segment of file path)
  ItalicFont = *_RI , % italic font style (segment of file path)
  BoldFont = *_RB , % bold font style (segment of file path)
]{LinBiolinum}

\newfontfamily\LinLibertine[%
  Extension = .otf ,
  UprightFont = *_R ,
  ItalicFont = *_I ,
  BoldFont = *_MB ,
]{LinLibertine}

然后,任何时候你想在文档中“激活”该字体,只需调用\LinBiolinum\LinLibertine。你告诉 fontspec 如何加载不同的样式:粗体、斜体、常规:

\rm = /path/LinLibertine_R.otf \it = /path/LinLibertine_RI.otf 等等。

但是,fontspec使用一些内置的字体系列命令。主字体的命令称为\normalfont\setmainfont,也可以像这样手动设置:

\setmainfont[%
  Extension = .otf ,
  UprightFont = *_R ,
  ItalicFont = *_I ,
  BoldFont = *_MB ,
]{LinLibertine}

这些宏的工作方式是通过将字体路径段分解为组件来加载字体,以便其中一些可以用作变量(UprightFont、ItalicFont、BoldFont、Extension 以及文档中列出的其他变量fontspec)。

/path/段被设置为环境变量。每个 TeX Live 安装都会默认为其内部字体设置一些路径。

cat $(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf

如果你想从其他地方加载字体,你有两个选择

  1. 在字体系列定义中使用 Path 参数
  2. 将其添加到您的路径环境变量中。

相关内容