Tr0py / NKU-thesis-template-2020

南开大学毕业论文模板 Nankai University Thesis Template https://tr0py.github.io/NKU-thesis-template-2020/
https://tr0py.github.io/NKU-thesis-template-2020/
89 stars 14 forks source link

尝试使用系统字体 #36

Closed aqni closed 1 year ago

aqni commented 1 year ago

Discussed in https://github.com/Tr0py/NKU-thesis-template-2020/discussions/35

Originally posted by **aqni** May 17, 2023 不在模板中内嵌字体,转而使用操作系统自带的字体。 ctex红包可以根据系统的不同自动选择中文字体。 Times New Roman似乎商业操作系统和overleaf都包含。 避免内嵌字体可以规避版权风险。
aqni commented 1 year ago

测试平台:

我在overleaf上上传了一个(这里),主要区别是封面汉字偏低

aqni commented 1 year ago

texlive应该是包含一套开源中文字体 Fandol的,所以中文字体在所有平台上都可用。

但是 Times New Roman 是商业字体,仅windows、macos和overleaf自带,ubuntu和某些docker镜像等开源项目应该是不自带的。

aqni commented 1 year ago

一种解决办法是,当无法找到 Times New Roman 字体时,使用开源的类 Times New Roman字体。

一些类 Times New Roman 字体: https://tex.stackexchange.com/questions/211326/best-math-font-with-times-new-roman-in-xelatex

在 commit https://github.com/Tr0py/NKU-thesis-template-2020/commit/ea7e01f76dd45bc956a1db58bedad8a78dde9653 中,我在 Times New Roman 不可用时,使用 STIX 字体。

Tr0py commented 1 year ago

我测试了docker和ubuntu。看起来有些warning。

Package fontspec Warning: Font "FandolFang-Regular" does not contain requested
(fontspec)                Script "CJK".

Package fontspec Warning: Font "FandolSong" does not contain requested Script
(fontspec)                "CJK".

Package fontspec Info: Could not resolve font "FandolSong/I" (it probably
(fontspec)             doesn't exist).

Package fontspec Warning: Font "FandolHei-Regular" does not contain requested
(fontspec)                Script "CJK".

Package fontspec Info: Font family 'FandolHei-Regular(0)' created for font
(fontspec)             'FandolHei-Regular' with options
(fontspec)             [Script={CJK},Extension={.otf},BoldFont={FandolHei-Bold}
].
(fontspec)              
(fontspec)              This font family consists of the following NFSS
(fontspec)             series/shapes:
(fontspec)              
(fontspec)             - 'normal' (m/n) with NFSS spec.:
(fontspec)             <->"[FandolHei-Regular.otf]/OT:language=dflt;"
(fontspec)             - 'small caps'  (m/sc) with NFSS spec.: 
(fontspec)             - 'bold' (b/n) with NFSS spec.:
(fontspec)             <->"[FandolHei-Bold.otf]/OT:language=dflt;"
(fontspec)             - 'bold small caps'  (b/sc) with NFSS spec.: 

完整log和pdf: main.log main.pdf

成功触发了STIX替代Times New Roman的代码

Class nkuthesis Warning: “Times New Roman”不可用,使用“STIX”替代 on input line 22.
Tr0py commented 1 year ago

至少看起来封面的楷体不能正常显示。

可能类Unix系统需要额外的字体的安装。pkuthess有过相关文档:《TeX Live + pkuthss 安装使用傻瓜指南》中字体配置相关部分提示用户copy字体文件到指定位置后进行编译。 从这个issue https://github.com/CasperVector/pkuthss/issues/35 看起来,pkuthess也用了字体文件。

我觉得我们的两个方案分别是

  1. 用当前方案,要求使用类unix系统的用户手动添加字体,windows和overleaf正常编译。
  2. 包含所有字体文件。

好奇其他模板怎么处理字体问题的?

Tr0py commented 1 year ago

MacOS上面编译失败。找不到"FandolSong"。

Package hyperref Warning: Rerun to get /PageLabels entry.

(/usr/local/texlive/2021/texmf-dist/tex/latex/biblatex/lbx/english.lbx)
(/usr/local/texlive/2021/texmf-dist/tex/latex/biblatex/blx-case-expl3.sty)
No file main.bbl.
Package pgfplots notification 'compat/show suggested version=true': you might b
enefit from \pgfplotsset{compat=1.17} (current compat level: 1.13).

kpathsea: Running mktextfm FandolSong/OT
/usr/local/texlive/2021/texmf-dist/web2c/mktexnam: Could not map source abbreviation O for OT.
/usr/local/texlive/2021/texmf-dist/web2c/mktexnam: Need to update /usr/local/texlive/2021/texmf-dist/fonts/map/fontname/special.map?
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; ; nonstopmode; input OT
This is METAFONT, Version 2.71828182 (TeX Live 2021) (preloaded base=mf)

kpathsea: Running mktexmf OT
! I can't find file `OT'.
<*> \mode:=ljfour; mag:=1; ; nonstopmode; input OT

Please type another input file name
! Emergency stop.
<*> \mode:=ljfour; mag:=1; ; nonstopmode; input OT

Transcript written on mfput.log.
grep: OT.log: No such file or directory
mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; ; nonstopmode; input OT' failed to make OT.tfm.
kpathsea: Appending font creation commands to missfont.log.

! Package fontspec Error: The font "FandolSong" cannot be found.

For immediate help type H <return>.
 ...

l.97 \maketitle

?
aqni commented 1 year ago

其实,只要知道各系统有哪些字体,通过fallback的方式,就能至少找到一个字体。

不过,我最疑惑的是,为什么Fandol字体会找不到,理论上使用了xecjk应该就包含fandol字体了呀。

找不到Fandolsong问题也不大,主要是封面和目录在使用,我换一种实现方式应该可以规避。

aqni commented 1 year ago

至少看起来封面的楷体不能正常显示。

应该是pdf查看器的问题,在windows上我用texworks自带的pdf查看器也无法显示FandolSong字体,封面上的“南开大学”四字,在之前的实现方式中就是用的FandolSong字体。

aqni commented 1 year ago

关于ctex的字体手动配置和自动配置

自动配置项如下: image

手动配置项如下: image

在mac和windows上使用系统字体,ubuntu、overleaf、docker上自动使用Fandol字体。

但是ctex似乎无法通过自动配置在ubuntu使用思源字体,想要使用ubuntu上的思源字体需要手动配置。

这一问题可以在加载nkuthesis文档类前项ctexart传入选项来手动配置

% head
\PassOptionsToClass{fontset=ubuntu}{ctexart}
\documentclass{nkuthesis}
% other

实在有需要的话,也可以给nkuthesis声明一个选项用来设置fontset=ubuntu

Fandol字体和中易字体是比较像的,但是思源字体和中易字体能很容易的看出区别,我还是建议使用Fandol字体。

aqni commented 1 year ago

如果最新提交的代码测试没有问题的话我就创建一个pull requestt

Tr0py commented 1 year ago

MacOS可以编译了。除了字体看起来稍有不同。

image

main-macos.pdf

Tr0py commented 1 year ago

ubuntu/docker 成功编译。效果如下。感觉还可以!

main-ubuntu-docker.pdf

aqni commented 1 year ago

已合并