CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
985 stars 124 forks source link

Package fontspec Error: The font "KaiTi" cannot be found. } #698

Open fangquinlan opened 8 months ago

fangquinlan commented 8 months ago

win11系统更新后(26040之后),系统中的KaiTi名称似乎发生了变化,似乎统一成了simkai。我改了改def文件但是好像还是不行。。:

  {
    \setCJKmainfont   { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
    \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKmonofont   { FangSong }
    \setCJKfamilyfont { zhsong  } { simsun          }
    \setCJKfamilyfont { zhhei   } { simhei          }
    \setCJKfamilyfont { zhfs    } { simfang         }
    \setCJKfamilyfont { zhkai   } { simkai          }
    \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
    \setCJKfamilyfont { zhli    } { LiSu            }
    \setCJKfamilyfont { zhyou   } { YouYuan         }
  }
\NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
\NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
\NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
\NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
\NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
\NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
\NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }

1

在C:\WINDOWS\WinSxS\amd64_microsoft-windows-font-truetype-simkai_31bf3856ad364e35_10.0.26040.1000_none_421350759fb8a09d路径下有一个simkai.ttf的字体文件,修改时间是2024/1/21日。

这个bug似乎是在26040到26058更新失败后产生的。我觉得应该与此有关。。。

muzimuzhi commented 8 months ago

请编辑评论,把代码以 markdown 的 fenced code block 进行标记。现在的样子看不出来你是怎么改的。

muzimuzhi commented 8 months ago

我(现在)接触不到 Windows 系统,更别提 Windows 11 Insider Preview Build 26040 (Canary Channel) 版本的系统,于是只能隔空瞎猜。

只看微软提供的字体列表,Win 11 里有 Kaiti,但是在 Chinese (Simplified) Supplemental Fonts 里。你能否检查,系统的语言和区域(可能叫其他的名字)设置里,已经安装了简体中文的语言包?

Related: #695

sikouhjw commented 8 months ago
  1. 先测试是否是代码问题

    \documentclass{article}
    \usepackage{fontspec}
    \begin{document}
    \IfFontExistsTF{simkai.ttf}{T}{F}
    
    \IfFontExistsTF{KaiTi}{T}{F}
    \end{document}
  2. 如果上述代码输出均为 T,则应检查你的代码是否有问题;如果输出为一 TF,那么考虑将 simkai.ttf 上传到 https://fontdrop.info/ 检查字体名是否发生变化。
fangquinlan commented 8 months ago

输出均为T。我重新恢复了ctex-fontset-windows.def默认设置了。 不过还是会报错 Package fontspec Error: The font "KaiTi" cannot be found. } C:\WINDOWS目录下确实有楷体 常规的字体

sikouhjw commented 8 months ago

输出均为T。我重新恢复了ctex-fontset-windows.def默认设置了。 不过还是会报错 Package fontspec Error: The font "KaiTi" cannot be found. } C:\WINDOWS目录下确实有楷体 常规的字体

所以是你的代码有问题。你是不是用了 newtx 宏包?

fangquinlan commented 8 months ago
\documentclass[12pt]{article}
\usepackage{ctex}

我只用了这两个做测试,依旧会报错

muzimuzhi commented 8 months ago

以下回复 https://github.com/CTeX-org/ctex-kit/issues/698#issue-2160534752

win11系统更新后(26040之后),系统中的KaiTi名称似乎发生了变化,似乎统一成了simkai。我改了改def文件但是好像还是不行。。: <代码片段>

你漏改了一处 Kaiti,在你展示的代码片段的第 2 行(第 1 行是 {)。

顺便,建议用更好的方式展示修改后的代码片段,或者「修改前:……,修改后:……,我把xx改成了xx」(不要只提供修改后的片段且不加说明),或者借用 diff 的格式,fenced code block 里写高亮语言是 diff:```diff

   {
     \setCJKmainfont   { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
     \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
     \setCJKmonofont   { FangSong }
-    \setCJKfamilyfont { zhsong  } { SimSun          }
-    \setCJKfamilyfont { zhhei   } { SimHei          }
-    \setCJKfamilyfont { zhfs    } { FangSong        }
-    \setCJKfamilyfont { zhkai   } { KaiTi           }
+    \setCJKfamilyfont { zhsong  } { simsun          }
+    \setCJKfamilyfont { zhhei   } { simhei          }
+    \setCJKfamilyfont { zhfs    } { simfang         }
+    \setCJKfamilyfont { zhkai   } { simkai          }
     \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
     \setCJKfamilyfont { zhli    } { LiSu            }
     \setCJKfamilyfont { zhyou   } { YouYuan         }
   }
 \NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
 \NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
 \NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
 \NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
 \NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
 \NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
 \NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }
fangquinlan commented 8 months ago

以下回复 #698 (comment)

win11系统更新后(26040之后),系统中的KaiTi名称似乎发生了变化,似乎统一成了simkai。我改了改def文件但是好像还是不行。。: <代码片段>

你漏改了一处 Kaiti,在你展示的代码片段的第 2 行(第 1 行是 {)。

顺便,建议用更好的方式展示修改后的代码片段,或者「修改前:……,修改后:……,我把xx改成了xx」(不要只提供修改后的片段且不加说明),或者借用 diff 的格式,fenced code block 里写高亮语言是 diff:```diff

   {
     \setCJKmainfont   { SimSun } [ BoldFont = SimHei , ItalicFont = KaiTi ]
     \setCJKsansfont   { Microsoft~YaHei } [ BoldFont = *~Bold ]
     \setCJKmonofont   { FangSong }
-    \setCJKfamilyfont { zhsong  } { SimSun          }
-    \setCJKfamilyfont { zhhei   } { SimHei          }
-    \setCJKfamilyfont { zhfs    } { FangSong        }
-    \setCJKfamilyfont { zhkai   } { KaiTi           }
+    \setCJKfamilyfont { zhsong  } { simsun          }
+    \setCJKfamilyfont { zhhei   } { simhei          }
+    \setCJKfamilyfont { zhfs    } { simfang         }
+    \setCJKfamilyfont { zhkai   } { simkai          }
     \setCJKfamilyfont { zhyahei } { Microsoft~YaHei } [ BoldFont = *~Bold ]
     \setCJKfamilyfont { zhli    } { LiSu            }
     \setCJKfamilyfont { zhyou   } { YouYuan         }
   }
 \NewDocumentCommand \songti   { } { \CJKfamily { zhsong  } }
 \NewDocumentCommand \heiti    { } { \CJKfamily { zhhei   } }
 \NewDocumentCommand \fangsong { } { \CJKfamily { zhfs    } }
 \NewDocumentCommand \kaishu   { } { \CJKfamily { zhkai   } }
 \NewDocumentCommand \lishu    { } { \CJKfamily { zhli    } }
 \NewDocumentCommand \youyuan  { } { \CJKfamily { zhyou   } }
 \NewDocumentCommand \yahei    { } { \CJKfamily { zhyahei } }

😂我漏了...问题已解决,将KaiTi改为SimKai即可。感谢。

muzimuzhi commented 8 months ago
\documentclass{article}
\usepackage{fontspec}
\begin{document}
  \IfFontExistsTF{simkai.ttf}{T}{F}

  \IfFontExistsTF{KaiTi}{T}{F}
\end{document}

输出均为T。…… 不过还是会报错 Package fontspec Error: The font "KaiTi" cannot be found. }

Why 的部分还没解决

fangquinlan commented 8 months ago
\documentclass{article}
\usepackage{fontspec}
\begin{document}
  \IfFontExistsTF{simkai.ttf}{T}{F}

  \IfFontExistsTF{KaiTi}{T}{F}
\end{document}

输出均为T。…… 不过还是会报错 Package fontspec Error: The font "KaiTi" cannot be found. }

Why 的部分还没解决

很奇怪 \setCJKfamilyfont { zhfs } { SimFang } \setCJKfamilyfont { zhfs } { FangSong } 两种就都可以

muzimuzhi commented 8 months ago

你是用什么引擎编译的?在原生 Win 下还是 WSL 里?

fangquinlan commented 8 months ago

你是用什么引擎编译的?在原生 Win 下还是 WSL 里?

lualatex,原生win11

muzimuzhi commented 8 months ago

换用 xelatex,能编通吗?

加上 \listfiles,然后用 lualatex 编译,把完整例子和 log 末尾的各包版本信息贴上来。

fangquinlan commented 8 months ago

使用xelatex会报错Package fontspec Error: The font "SimKai" cannot be found. }使用lualatex可以。

\documentclass[12pt]{article}
\usepackage{ctex}
\usepackage{fontspec}
\listfiles

\begin{document}

    \section*{第十七章\ 政治文化与精神意识形态空间}

    \kaishu{在其历史中,俄罗斯一直是一个宏大项目的国家。}

\end{document}
 *File List*
 article.cls    2023/05/17 v1.4n Standard LaTeX document class
  size12.clo    2023/05/17 v1.4n Standard LaTeX file (size option)
    ctex.sty    2022/07/14 v2.5.10 Chinese adapter in LaTeX (CTEX)
   expl3.sty    2024-02-20 L3 programming layer (loader) 
l3backend-luatex.def    2024-02-20 L3 backend support: PDF output (LuaTeX)
ctexhook.sty    2022/07/14 v2.5.10 Document and package hooks (CTEX)
ctexpatch.sty    2022/07/14 v2.5.10 Patching commands (CTEX)
  fix-cm.sty    2020/11/24 v1.1t fixes to LaTeX
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
ctexopts.cfg    2022/07/14 v2.5.10 Option configuration file (CTEX)
ctex-engine-luatex.def    2022/07/14 v2.5.10 LuaLaTeX adapter (CTEX)
luatexja.sty    2024-02-19 Japanese Typesetting with Lua(La)TeX
luatexja-core.sty    2023-04-06 Core of LuaTeX-ja
infwarerr.sty    2019/12/03 v1.5 Providing info/warning/error messages (HO)
luatexbase.sty    2015/10/04 v1.3 luatexbase interface to LuaTeX 
ctablestack.sty    2015/10/01 v1.0 Catcode table stable support
 ltxcmds.sty    2023-12-04 v1.26 LaTeX kernel commands for general use (HO)
pdftexcmds.sty    2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO)
   iftex.sty    2022/02/03 v1.0f TeX engine tests
 xkeyval.sty    2022/06/16 v2.9 package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
etoolbox.sty    2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
everyhook.sty    2014/11/26 v1.2 (SVN Rev: 12)\ Hooks for low level TeX everyX 
primitives.
svn-prov.sty    2010/04/24 v3.1862 Package Date/Version from SVN Keywords
ltj-base.sty    2021-03-16
luatexja-compat.sty    2020-08-08 Compatibility with pTeX
fontspec.sty    2024/02/13 v2.9a Font selection for XeLaTeX and LuaLaTeX
  xparse.sty    2024-02-18 L3 Experimental document command parser
fontspec-luatex.sty    2024/02/13 v2.9a Font selection for XeLaTeX and LuaLaTeX

 fontenc.sty    2021/04/29 v2.0v Standard LaTeX package
fontspec.cfg
   tuenc.def    2021/04/29 v2.0v Standard LaTeX file
zhnumber.sty    2022/07/14 v3.0 Typesetting numbers with Chinese glyphs
zhnumber-utf8.cfg    2022/07/14 v3.0 Chinese numerals with UTF8 encoding
ctex-scheme-chinese.def    2022/07/14 v2.5.10 Chinese scheme for generic (CTEX)

ctex-name-utf8.cfg    2022/07/14 v2.5.10 Caption with encoding UTF-8 (CTEX)
indentfirst.sty    2023/07/02 v1.03 Indent first paragraph (DPC)
ctex-fontset-windows.def    2022/07/14 v2.5.10 Windows fonts definition (CTEX)
    ctex.cfg    2022/07/14 v2.5.10 Configuration file (CTEX)
 ***********

这个吗 log.txt

muzimuzhi commented 8 months ago

使用xelatex会报错Package fontspec Error: The font "SimKai" cannot be found. }使用lualatex可以。

不知道是不是大小写敏感。

找个办法,看看 Simkai.ttf 的字体/字族名呢。如果不知道其他办法,可以用

2. 考虑将 simkai.ttf 上传到 https://fontdrop.info/ 检查字体名是否发生变化。

Update: 也许要等(能复现问题,或其他条件相同但不能复现问题的) Windows 用户,我这么瞎猜瞎问未必逮到耗子。

fangquinlan commented 8 months ago

image 我用FontCreator看也是KaiTi