LuaTeX在macOS Sonoma字体找不到的解

最近用到 LaTeX,在Mac上编译实在别搞疯了,楷体字体路径成谜,差点被逼去overleaf。

摘自:老问题重新看:字体找不到(2022/11/29)

macOS一升级,TeX Live就吃瘪。

上一篇(最近的一些进展(2022/10/30))提到的LuaTeX配置脚本,以前我写过这个。但是实话说,我有时候也不知道放在哪,也靠搜索。

大致的用法,就是下面的。

增加环境变量:

tlmgr conf texmf OSFONTDIR /System/Library/Assets/com_apple_MobileAsset_Font4/

删除环境变量:

tlmgr conf texmf --delete OSFONTDIR

不过,每次升级,com_apple_MobileAsset_Font后面的那个数都不一样,最近的13.0.1,就是7。

但是,如果用脚本解析一下:

from Foundation import *
from CoreText import *
import urllib.parse


if __name__ == "__main__":
    collection = CTFontCollectionCreateFromAvailableFonts(None)
    fds = CTFontCollectionCreateMatchingFontDescriptors(collection)
    font_all = []

    for i in fds:
        font_family = CTFontDescriptorCopyAttribute(i, kCTFontFamilyNameAttribute)
        font_url = CTFontDescriptorCopyAttribute(i, kCTFontURLAttribute)
        font_all.append(urllib.parse.unquote(urllib.parse.urlparse("%s" % font_url)[2]))

    font_set = sorted(list(set(font_all)))

    for e in font_set:
        print(e)

跑出来的结果,基本就是:

$HOME/Library/Fonts
/Library/Fonts
/System/Library/Fonts
/System/Library/AssetsV2/com_apple_MobileAsset_Font7

所以,实际上要执行的命令是:

tlmgr conf texmf OSFONTDIR $HOME/Library/Fonts:/System/Library/Fonts:/Library/Fonts:/System/Library/AssetsV2/com_apple_MobileAsset_Font7

确实也是麻烦呢。

LuaTeX一套,XeTeX的fontconfig一套。虽然我做的xetex分支的字体库支持是跨平台的,但是它们到时候能不能用,就不知道了。

看以后的机会吧。