Skip to content

修复 macOS 下 LuaLaTeX 找不到已下载的楷体和仿宋 - #517

Merged
zepinglee merged 2 commits into
ustctug:masterfrom
Camorgx:fix/macos-luatex-font-assets
Nov 26, 2026
Merged

zepinglee merged 2 commits into
ustctug:masterfrom
Camorgx:fix/macos-luatex-font-assets

Conversation

@Camorgx

@Camorgx Camorgx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Closes #516

在本机通过字体册下载楷体和仿宋后,两个字体文件都位于 /System/Library/AssetsV2/com_apple_MobileAsset_Font8/ 下。在 master 的 8f11ebf 上清除 OSFONTDIR 后,同一个示例用 XeLaTeX 可以编译,用 LuaLaTeX 则在加载文档类时报告 The font "Kaiti SC Regular" cannot be found。

修改

使用 macOS 中文字体配置时,LuaLaTeX 先按名称查找楷体和仿宋。某一字族查找失败时,再到 AssetsV2 及其 PreinstalledAssetsV2/InstallWithOs 子目录中的字体资源包查找该字族的文件。目录名中的版本号和各资源包的标识由运行时读取。这个查找方式参考了 CTeX 对 macOS 字体目录的处理。

正文斜体和 \kaishu 共用 Kaiti.ttc 的简体常规和粗体字形,索引分别为 0 和 3。中文等宽字体和 \fangsong 使用 STFANGSO.ttf。用户可以直接用 LuaLaTeX 编译已有文档。

验证

在 macOS 27.2.1(26B131,Apple Silicon)、TeX Live 2026、LuaHBTeX 1.24.0、luaotfload 3.29 上实测。下面的 fontcheck.tex 也可以用于旧版 macOS 复核。

\documentclass[degree=master,fontset=mac]{ustcthesis}
\pagestyle{empty}
\begin{document}
\textit{正文斜体}\quad\textbf{\textit{正文粗斜体}}\par
{\kaishu 楷体\textbf{粗楷}}\quad{\fangsong 仿宋}\quad\texttt{等宽仿宋}
\end{document}
env -u OSFONTDIR lualatex -no-shell-escape -halt-on-error fontcheck.tex
pdffonts fontcheck.pdf
  • 清除 OSFONTDIR 后,示例一次编译通过。pdffonts 显示 PDF 嵌入了 STKaitiSC-Regular、STKaitiSC-Bold 和 STFangsong。另外分别让楷体或仿宋可按名称找到,两种情况下的字体样张都与原版加 OSFONTDIR 的输出一致。
  • 清除 OSFONTDIR 后执行 latexmk -lualatex main.tex,官方示例共 32 页。与同一版 master 手动设置 OSFONTDIR 的输出逐页比较,96 dpi 灰度渲染完全一致。
  • make test 的 51 项回归测试通过。另行执行 l3build check -c build fontset-mac,通过了包含 \kaishu 和 \fangsong 的 XeLaTeX 专项测试,也用 LuaLaTeX 编译了这一用例。常规回归所需的 Fandol 字体和 Biber 拼音排序模块在临时测试目录中补齐。

When fontspec cannot resolve Kaiti SC or STFangsong by name, look for the installed files in macOS font assets. Select the regular and bold SC faces for both body italics and the Kai family.

Extend the macOS font regression sample to exercise the named Kai and Fangsong families.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 09:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@zepinglee zepinglee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢 PR!

@zepinglee
zepinglee merged commit 6e442dc into ustctug:master Nov 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macOS 下 LuaLaTeX 无法发现已通过字体册安装的中文字体(Kaiti SC Regular)

3 participants