Fontspec 包在 MacOS/MacTeX 上找不到“Latin Modern Mono”

Fontspec 包在 MacOS/MacTeX 上找不到“Latin Modern Mono”

我一直在使用 XeTeX 的 fontspec 包来加载字体。下面是一个不起作用的简单示例:

\documentclass[12pt,a4paper]{book}
\usepackage{fontspec}
\begin{document}
\setmainfont{Latin Modern Mono}
\end{document}

这在 Windows 和 Linux 上都运行良好(在 Linux 上我必须更新我的 FontConfig 设置)。在装有 MacTeX 的 MacOS 上,我收到此错误:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "Latin Modern Mono" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.4 \setmainfont{Latin Modern Mono}

如果我将字体文件复制到 ~/Library/Fonts 如下:

cp /usr/local/texlive/2017/texmf-dist/fonts/opentype/public/lm/lmmono12-regular.otf ~/Library/Fonts/

它解决了问题,但对于我的情况来说并不理想,因为其他用户也使用此设置,我不希望他们担心复制字体,尤其是字体已经存在于 texlive 目录中。我的理解是 XeTeX 会搜索 macOS 字体文件夹和 texlive 安装文件夹(http://mactex-wiki.tug.org/wiki/index.php/Font_Selection#Using_fonts_with_XeTeX)。

fontspec 如何解析 MacOS 上的字体?MacTeX 在 MacOS 上使用 FontConfig 还是其他东西?

我因为其他原因在 Mac 上安装了 FontConfig,这有问题吗?

系统信息:

macOS 10.13.1 - 2011 年 Macbook Air

XeTeX 3.14159265-2.6-0.99998 (TeX Live 2017)

答案1

看来这是 RTFM 的一个案例(http://ctan.mirrors.hoobly.com/macros/latex/contrib/fontspec/fontspec.pdf)。根据最新的 fontspec 文档,不可能使用 XeTeX 而无需将字体复制到 ~/Library/Fonts。

XeTeX 和 LuaTEX 还允许通过文件名而不是字体名来加载字体。当您拥有大量字体时,有时您不希望将它们全部安装在系统的字体目录中。在这种情况下,从磁盘上的其他位置加载它们会更方便。在 XeTeX 中,加载 TEX 发行版中存在的 OpenType 字体(例如 /usr/local/texlive/2013/texmf-dist/fonts/opentype/public)时,此技术也是必需的。这些位置的字体对 XeTeX 来说是可见的,但不能通过字体名称加载,只能通过文件名加载;LuaTEX 没有这个限制。

答案2

我已经在我的 中使用符号链接一段时间了~/Library/Fonts。以下是来自 Emacs 的该目录的视图:

在此处输入图片描述

然后,考虑测试文档

\documentclass[12pt,a4paper]{book}
\usepackage{fontspec}
\XeTeXtracingfonts1
\setmainfont{Latin Modern Mono}
\begin{document}
Hello
\end{document}

它产生了预期的结果,并且日志文件包含以下内容

Requested font "Latin Modern Mono" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
\g__fontspec_family_LatinModernMono_int=\count180
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/BI/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/B/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
.................................................
. fontspec info: "no-font-shape"
. 
. Could not resolve font "Latin Modern Mono/B" (it probably doesn't exist).
.................................................
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/I/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf
Requested font "Latin Modern Mono/I/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
Requested font "Latin Modern Mono/I/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
Requested font "Latin Modern Mono/BI/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
Requested font "Latin Modern Mono/BI/OT" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono10-italic.otf
.................................................
. fontspec info: "defining-font"
. 
. Font family 'LatinModernMono(0)' created for font 'Latin Modern Mono' with
. options [Ligatures=TeX].
.  
.  This font family consists of the following NFSS series/shapes:
.  
. - 'normal' (m/n) with NFSS spec.: <->"Latin Modern
. Mono/OT:script=latn;language=DFLT;mapping=tex-text;"
. - 'small caps'  (m/sc) with NFSS spec.: 
. - 'italic' (m/it) with NFSS spec.: <->"Latin Modern
. Mono/I/OT:script=latn;language=DFLT;mapping=tex-text;"
. - 'italic small caps'  (m/itsc) with NFSS spec.: 
. - 'bold italic' (bx/it) with NFSS spec.: <->"Latin Modern
. Mono/BI/OT:script=latn;language=DFLT;mapping=tex-text;"
. - 'bold italic small caps'  (bx/itsc) with NFSS spec.: 
.................................................
LaTeX Info: Redefining \rmfamily on input line 4.
Requested font "Latin Modern Mono/OT:script=latn;language=DFLT;mapping=tex-text
;" at 12.0pt
 -> /Users/xXx/Library/Fonts/TeXOpenType/public/lm/lmmono12-regular.otf

顺便说一句,这不会影响最近的情况luaotfload:LuaTeX 数据库将不会包含重复条目,就像两年前的情况一样(即 2015 年)。我忘记了细节。

相关内容