如何在 macOS 上为 fontspec 设置 TeXLive 系统字体路径?

如何在 macOS 上为 fontspec 设置 TeXLive 系统字体路径?

macOS 10.15.7 上的 MacTeX / TeXlive 2021

我尝试通过 fontspec 包使用 Times New Roman,但没有成功。

我读过:

fc-list : family | sort

将生成一个系统字体列表,我应该能够通过 XeLaTeX 和 fontspec 使用这些字体。此列表包括 Times New Roman。

此最小测试文档失败


\documentclass{article}

\usepackage{fontspec}

\setmainfont{Times New Roman}

\begin{document}

Hello world.

\end{document}

有以下日志:


This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2021) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./fontspecTest.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2021/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-xetex.def
(|extractbb --version)))
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3packages/xparse/xparse-2020-10-
01.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/l3packages/xparse/xparse-generic.
tex)))
(/usr/local/texlive/2021/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/local/texlive/2021/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
No file fontspecTest.aux.
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/ts1cmr.fd) [1]
(./fontspecTest.aux)
xdvipdfmx:fatal: Cannot proceed without the font: /Users/<user>/Library/Fonts/Times New Roman

No output PDF file written.
 )
Error 256 (driver return code) generating output;
file fontspecTest.pdf may not be valid.
SyncTeX written on fontspecTest.synctex.gz.
Transcript written on fontspecTest.log.

我在网上搜索后发现,我应该编辑 .../texlive/YYYY/texmf.cnf 以包含字体搜索路径。我这样做了,创建了一个包含此内容的文件,保存为 /usr/local/texlive/2021/texmf.cnf:


% (Public domain.)
% This texmf.cnf file should contain only your personal changes from the
% original texmf.cnf (for example, as chosen in the installer).
%
% That is, if you need to make changes to texmf.cnf, put your custom
% settings in this file, which is .../texlive/YYYY/texmf.cnf, rather than
% the distributed file (which is .../texlive/YYYY/texmf-dist/web2c/texmf.cnf).
% And include *only* your changed values, not a copy of the whole thing!
%
TEXMFHOME = ~/Library/texmf
TEXMFVAR = ~/Library/texlive/2021/texmf-var
TEXMFCONFIG = ~/Library/texlive/2021/texmf-config

OSFONTDIR = System/Library/Fonts:System/Library/Fonts/Supplemental:~/Library/Fonts

然而,即使跑完步texhash

kpsewhich --expand-path '$OSFONTDIR'

结果是:

/Users/<user>/Library/Fonts

命令:

fc-list : family

显然搜索了 OSFONTDIR 指定目录之外的地方,同样显然我对 texmf.cnf 的更改没有效果。

我很感激关于如何设置适当搜索路径的建议。

相关内容