CJK字体
第一步
使用xu-cheng/latex-action@v3编译LaTeX,中文字体缺失。尝试安装Noto CJK字体,但是安装完后latex找不到字体
第二步
决定将字体文件放在项目文件夹里
环境是texlive2022,XeLaTeX编译,使用xeCJK宏包
代码是
\setCJKmainfont[
BoldFont={fonts/NotoSansCJKsc-VF.ttf},
ItalicFont={fonts/NotoSerifCJKsc-VF.ttf},
Extension=.ttf
]{fonts/NotoSerifCJKsc-VF.ttf}
包括一条警告: Font shape TU/fonts/NotoSerifCJKsc-Regular.ttf(0)/m’ undefined(Font) using TU/lmr/m/n’ instead 这是因为指定的字体不具备斜体、粗体等变体。(如果使用VF,LaTeX不一定能解析出来)
出现中文的第一处会报错: Missing number, treated as zero.
查看详细的log,
Package fontspec Info: Font family 'fonts/NotoSerifCJKsc-Regular.ttf(0)'
(fontspec) created for font 'fonts/NotoSerifCJKsc-Regular.ttf'
(fontspec) with options [Script={CJK}].
(fontspec)
(fontspec) This font family consists of the following NFSS
(fontspec) series/shapes:
(fontspec)
(fontspec) - 'normal' (m/n) with NFSS spec.:
(fontspec) <->"[fonts/NotoSerifCJKsc-Regular.ttf]/OT:script=hani;la
nguage=dflt;"
(fontspec) - 'small caps' (m/sc) with NFSS spec.:
(./main.aux)
\openout1 = `main.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 15.
LaTeX Font Info: Trying to load font information for TS1+cmr on input line 1
5.
(c:/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd
File: ts1cmr.fd 2019/12/16 v2.5j Standard LaTeX font definitions
)
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for TU/lmr/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 15.
LaTeX Font Info: ... okay on input line 15.
Package fontspec Info: Adjusting the maths setup (use [no-math] to avoid
(fontspec) this).
\symlegacymaths=\mathgroup4
LaTeX Font Info: Overwriting symbol font `legacymaths' in version `bold'
(Font) OT1/cmr/m/n --> OT1/cmr/bx/n on input line 15.
LaTeX Font Info: Redeclaring math accent \acute on input line 15.
LaTeX Font Info: Redeclaring math accent \grave on input line 15.
LaTeX Font Info: Redeclaring math accent \ddot on input line 15.
LaTeX Font Info: Redeclaring math accent \tilde on input line 15.
LaTeX Font Info: Redeclaring math accent \bar on input line 15.
LaTeX Font Info: Redeclaring math accent \breve on input line 15.
LaTeX Font Info: Redeclaring math accent \check on input line 15.
LaTeX Font Info: Redeclaring math accent \hat on input line 15.
LaTeX Font Info: Redeclaring math accent \dot on input line 15.
LaTeX Font Info: Redeclaring math accent \mathring on input line 15.
LaTeX Font Info: Redeclaring math symbol \colon on input line 15.
LaTeX Font Info: Redeclaring math symbol \Gamma on input line 15.
LaTeX Font Info: Redeclaring math symbol \Delta on input line 15.
LaTeX Font Info: Redeclaring math symbol \Theta on input line 15.
LaTeX Font Info: Redeclaring math symbol \Lambda on input line 15.
LaTeX Font Info: Redeclaring math symbol \Xi on input line 15.
LaTeX Font Info: Redeclaring math symbol \Pi on input line 15.
LaTeX Font Info: Redeclaring math symbol \Sigma on input line 15.
LaTeX Font Info: Redeclaring math symbol \Upsilon on input line 15.
LaTeX Font Info: Redeclaring math symbol \Phi on input line 15.
LaTeX Font Info: Redeclaring math symbol \Psi on input line 15.
LaTeX Font Info: Redeclaring math symbol \Omega on input line 15.
LaTeX Font Info: Redeclaring math symbol \mathdollar on input line 15.
LaTeX Font Info: Redeclaring symbol font `operators' on input line 15.
LaTeX Font Info: Encoding `OT1' has changed to `TU' for symbol font
(Font) `operators' in the math version `normal' on input line 15.
LaTeX Font Info: Overwriting symbol font `operators' in version `normal'
(Font) OT1/cmr/m/n --> TU/lmr/m/n on input line 15.
LaTeX Font Info: Encoding `OT1' has changed to `TU' for symbol font
(Font) `operators' in the math version `bold' on input line 15.
LaTeX Font Info: Overwriting symbol font `operators' in version `bold'
(Font) OT1/cmr/bx/n --> TU/lmr/m/n on input line 15.
LaTeX Font Info: Overwriting symbol font `operators' in version `normal'
(Font) TU/lmr/m/n --> TU/lmr/m/n on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathit' in version `normal'
(Font) OT1/cmr/m/it --> TU/lmr/m/it on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `normal'
(Font) OT1/cmr/bx/n --> TU/lmr/b/n on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `normal'
(Font) OT1/cmss/m/n --> TU/lmss/m/n on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `normal'
(Font) OT1/cmtt/m/n --> TU/lmtt/m/n on input line 15.
LaTeX Font Info: Overwriting symbol font `operators' in version `bold'
(Font) TU/lmr/m/n --> TU/lmr/b/n on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathit' in version `bold'
(Font) OT1/cmr/bx/it --> TU/lmr/b/it on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `bold'
(Font) OT1/cmss/bx/n --> TU/lmss/b/n on input line 15.
LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `bold'
(Font) OT1/cmtt/m/n --> TU/lmtt/b/n on input line 15.
LaTeX Font Info: Trying to load font information for TU+fonts on input line
16.
LaTeX Font Info: No file TUfonts.fd. on input line
加载 .ttf CJK 字体时,LaTeX 在 TU 编码下找不到 fonts 字体族的 .fd 文件,xeCJK 无法正确创建 NFSS 编码文件,导致 LaTeX 在处理中文字符时报错
正确的写法
\setCJKmainfont[
Path = fonts/, % 字体所在目录
Extension = .ttf, % 文件扩展名
UprightFont = NotoSerifCJKsc-Regular, % 正体
BoldFont = NotoSerifCJKsc-Bold, % 粗体
ItalicFont = NotoSerifCJKsc-Italic % 斜体
]{NotoSerifCJKsc-Regular}
PREVIOUS使用picker与toffee框架进行芯片验证