# macos运行LaTeX时字体缺失

**URL:** <https://forum.beginner.center/t/topic/2350>\
**Category:** 🛠工具与编程\
**Tags:** macos, latex\
**Created:** [2025 年11 月 3 日 09:26 UTC](https://forum.beginner.center/t/topic/2350 "2025-11-03T09:26:16Z")\
**Posts on this page:** 1\
**Page:** 1

## AI 生成的摘要

在使用 Pandoc 和 LaTeX 生成 PDF 时遇到字体缺失的问题。用户提供的代码尝试使用 PingFang SC 作为中文主字体，但运行时报错提示该字体无法找到。用户惊讶于 Mac 系统为何缺少苹方字体，并通过终端命令搜索确认系统中确实没有安装该字体。[doggie](/t/mac-os%E8%BF%90%E8%A1%8Clatex%E6%97%B6%E5%AD%97%E4%BD%93%E7%BC%BA%E5%9D%9A/2350/1) 提到了 [参考链接](https://forum.beginner.center/t/topic/2347) 中的代码配置，但该配置未能成功识别所需的字体。

<div class="post-metadata">

作者： ![doggie](https://forum.beginner.center/user_avatar/forum.beginner.center/doggie/32/550_2.png) [@doggie](https://forum.beginner.center/u/doggie)\
发布日期： [2025 年11 月 3 日 09:26 UTC](https://forum.beginner.center/t/topic/2350/1 "2025-11-03T09:26:16Z")

</div>

[参考这里](https://forum.beginner.center/t/topic/2347)写了一段使用pandoc和latex的代码，这样markdown转换出来的pdf格式最佳

```auto
import pypandoc

def md_to_pdf_pandoc(input_md, output_pdf):
    try:
        # 使用自定义 LaTeX 模板或内联样式
        output = pypandoc.convert_file(
            input_md, 'pdf',
            outputfile=output_pdf,
            extra_args=[
                '--pdf-engine=xelatex',
                '-V', 'documentclass=ctexart',
                '-V', 'CJKmainfont=PingFang SC', # 中文主字体
                '-V', 'mainfont=XITS', # 主字体设为 XITS
                '-V', 'mathfont=XITS Math', # 数学字体设为 XITS Math
                '-V', 'monofont=DejaVu Sans Mono', # 等宽字体（代码块）

                # '-V', 'geometry:margin=1in', # 设置页边距
                # '--template=eisvogel', # 使用自定义模板
                # '--listings',
                # '--highlight-style=pygments' # 使用语法高亮风格（带背景色）
            ]
        )
        print(f"PDF 已生成：{output_pdf}")
    except Exception as e:
        print("转换失败:", str(e))

```

但是运行时会报错缺少字体

```auto
转换失败: Pandoc died with exitcode "43" during conversion: Error producing PDF.
! Package fontspec Error: 
(fontspec) The font "PingFang SC" cannot be found; this may
(fontspec) be but usually is not a fontspec bug. Either there
(fontspec) is a typo in the font name/file, the font is not
(fontspec) installed (correctly), or there is a bug in the
(fontspec) underlying font loading engine (XeTeX/luaotfload).

For immediate help type H <return>.
 ...                                              
                                                  
l.28 \setCJKmainfont[]{PingFang SC}

```

那就很奇怪了，我Mac怎么会缺苹方呢？

在终端输入如下命令搜了一下，还真没有苹方

```auto
fc-list | grep -i "PingFang"

```

然后再用这个命令行查看支持中文的字体，还是没有苹方

```auto
fc-list :lang=zh

/System/Library/Fonts/STHeiti Medium.ttc: Heiti SC,黑體\-簡,黒体\-簡,Heiti\-간체,黑体\-简:style=Medium,中黑,Halbfett,Normaali,Moyen,Medio,ミディアム,중간체,Médio,Средний,Normal,中等,Media
/System/Library/Fonts/STHeiti Light.ttc: Heiti TC,黑體\-繁,黒体\-繁,Heiti\-번체,黑体\-繁:style=Light,細體,Mager,Fein,Ohut,Fin,Leggero,ライト,가는체,Licht,Tynn,Leve,Светлый,细体,Fina
/System/Library/Fonts/Supplemental/Songti.ttc: Songti SC,宋體\-簡,宋体\-简:style=Light,細體,细体
/System/Library/Fonts/Supplemental/Songti.ttc: Songti TC,宋體\-繁,宋体\-繁:style=Regular,標準體,常规体
/System/Library/Fonts/Supplemental/Songti.ttc: Songti SC,宋體\-簡,宋体\-简:style=Regular,標準體,常规体
/System/Library/Fonts/Supplemental/Songti.ttc: Songti TC,宋體\-繁,宋体\-繁:style=Light,細體,细体
/System/Library/Fonts/Supplemental/Songti.ttc: Songti SC,宋體\-簡,宋体\-简:style=Black,黑體,黑体
/Library/Fonts/Arial Unicode.ttf: Arial Unicode MS:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/System/Library/Fonts/Hiragino Sans GB.ttc: .Hiragino Sans GB Interface:style=W6
/System/Library/Fonts/Hiragino Sans GB.ttc: .Hiragino Sans GB Interface:style=W3
/System/Library/Fonts/Supplemental/Arial Unicode.ttf: Arial Unicode MS:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/System/Library/Fonts/STHeiti Medium.ttc: Heiti TC,黑體\-繁,黒体\-繁,Heiti\-번체,黑体\-繁:style=Medium,中黑,Halbfett,Normaali,Moyen,Medio,ミディアム,중간체,Médio,Средний,Normal,中等,Media
/System/Library/Fonts/Supplemental/Songti.ttc: Songti SC,宋體\-簡,宋体\-简:style=Bold,粗體,粗体
/System/Library/Fonts/STHeiti Light.ttc: Heiti SC,黑體\-簡,黒体\-簡,Heiti\-간체,黑体\-简:style=Light,細體,Mager,Fein,Ohut,Fin,Leggero,ライト,가는체,Licht,Tynn,Leve,Светлый,细体,Fina
/System/Library/Fonts/Supplemental/Songti.ttc: Songti TC,宋體\-繁,宋体\-繁:style=Bold,粗體,粗体
/System/Library/Fonts/Hiragino Sans GB.ttc: Hiragino Sans GB,冬青黑體簡體中文,冬青黑体简体中文,Hiragino Sans GB W6,冬青黑體簡體中文 W6,冬青黑体简体中文 W6:style=W6,Bold
/System/Library/Fonts/Supplemental/Songti.ttc: STSong:style=Regular,標準體,Ordinær,Normal,Normaali,Regolare,レギュラー,일반체,Regulier,Обычный,常规体
/System/Library/Fonts/Hiragino Sans GB.ttc: Hiragino Sans GB,冬青黑體簡體中文,冬青黑体简体中文,Hiragino Sans GB W3,冬青黑體簡體中文 W3,冬青黑体简体中文 W3:style=W3,Regular
/System/Library/Fonts/LastResort.otf: .LastResort:style=Regular

```

但是通过这个命令可以很明确看到有苹方字体

```auto
system_profiler SPFontsDataType > output.txt

```

这里只节选部分

```auto
PingFangUI.ttc:

      Kind: TrueType
      Valid: Yes
      Enabled: Yes
      Location: /System/Library/PrivateFrameworks/FontServices.framework/Resources/Reserved/PingFangUI.ttc
      Typefaces:
        PingFangSC-Semibold:
          Full Name: PingFang SC Semibold
          Family: PingFang SC
          Style: Semibold
          Version: 21.0d7e1
          Unique Name: 蘋方-簡; 21.0d7e1; 2025-07-22
          Copyright: © 2024-2025 Apple Inc. All rights reserved.
          Outline: Yes
          Valid: Yes
          Enabled: Yes
          Duplicate: No
          Copy Protected: No
          Embeddable: Yes
        PingFangHK-Semibold:
          Full Name: PingFang HK Semibold
          Family: PingFang HK
          Style: Semibold
          Version: 21.0d7e1
          Unique Name: 蘋方-港; 21.0d7e1; 2025-07-22
          Copyright: © 2024-2025 Apple Inc. All rights reserved.
          Outline: Yes
          Valid: Yes
          Enabled: Yes
          Duplicate: No
          Copy Protected: No
          Embeddable: Yes

```

和ai battle以后才知道， \* 苹方在 macOS 系统里确实存在，但位于 **PrivateFrameworks/FontServices** ，属于 **私有系统字体** ，所以 `fc-list` 不会显示，也不在普通 Fontconfig 索引里。

那我想用怎么办？

凉拌，[再下载一份苹方tff字体](https://github.com/refinec/PingFangSC/)，不能用`/System/Library/PrivateFrameworks/FontServices.framework/Resources/Reserved/PingFangUI.ttc`，识别不了

把新的字体复制黏贴到`~/Library/Fonts`，就能用了
