我对自定义字体有一个很大的问题,.ttf
我好几个小时都无法理解。
我的工作流程是在本地编写 latex 代码,将其签入 CI,然后编译并将 pdf 部署到网站。我使用Trebuchet MS
位于工作目录中并签入 git 的。
在我的计算机上,一切运行正常,看起来符合预期。但在 CI 上,我收到以下警告:
[...]
LaTeX Font Warning: Font shape `TU/Trebuchet_MS.ttf(1)/bx/n' undefined
66 (Font) using `TU/Trebuchet_MS.ttf(1)/m/n' instead on input line 47
[...]
当然,结果是预期的:不同的章节和小节标题。
我的工作目录如下所示:
├── file.tex
└── fonts/
├── Trebuchet_MS_Bold_Italic.ttf
├── Trebuchet_MS_Bold.ttf
├── Trebuchet_MS_Italic.ttf
└── Trebuchet_MS.ttf
我的 tex 代码如下所示:
%&program=xelatex
\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\usepackage{enumitem}
\usepackage{scrlayer-scrpage}
\usepackage{graphicx}
\setmainfont[
Path = fonts/,
BoldFont = Trebuchet_MS_Bold.ttf,
ItalicFont = Trebuchet_MS_Italic.ttf,
BoldItalicFont = Trebuchet_MS_Bold_Italic.ttf
]{Trebuchet_MS.ttf}
\newfontfamily\sectionfont[
Path = fonts/,
BoldFont = Trebuchet_MS_Bold.ttf,
ItalicFont = Trebuchet_MS_Italic.ttf,
BoldItalicFont = Trebuchet_MS_Bold_Italic.ttf
]{Trebuchet_MS.ttf}
\setkomafont{section}{\fontsize{14pt}{14pt}\sectionfont\selectfont}
\setkomafont{subsection}{\fontsize{12pt}{12pt}\selectfont\sectionfont}
\chead{\includegraphics[width=1.65cm]{img/logo.png}}
\setlength\headheight{75pt}
\renewcommand\thesection{§\arabic{section}}
\sloppy
\begin{document}
\begin{center}
{\textbf{\huge{Large Heading}}}\newline
issue \today
\end{center}
\begin{section}{Section Heading} % <---
Some text.
\begin{subsection}{Subsection Heading} % <---
Some more text.
\end{subsection}
\end{section}
\end{document}
我确实检查了两台机器上的版本:
- 我的机器是 macOS
XeTex Version 3.14159265-2.6-0.999992 (TeX Live 2020)
- CI 就是 Ubuntu
XeTex Version 3.14159265-2.6-0.999991 (TeX Live 2019/Debian)
所以对我来说,这看起来只是一个很小的差异,因此不太可能是这个原因造成的。另外,我相信我的 Mac 上有一个更老的版本,当时它已经可以正常工作了,但我不确定。
谢谢你的帮助!
编辑:运行时xelatex -output-driver="xdvipdfmx -vv" file
我得到以下输出:
[...]
[[2] [3] [4<FONTMAP:/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map><FONTMAP:/var/lib/texmf/fonts/map/dvipdfmx/updmap/kanjix.map><FONTMAP:/usr/share/texlive/texmf-dist/fonts/map/dvipdfmx/ckx.map>No dvi filename specified, reading standard input.
[...]
[5><AGL:pdfglyphlist.txt><AGL:glyphlist.txt>[1(Image:img/logo.png[./img/logo.png][PNG])<./fonts/[email protected]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS_Bold.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS_Bold.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
<NATIVE-FONTMAP:./fonts/Trebuchet_MS_Bold.ttf/0/H/65536/0/0>
fontmap: ./fonts/Trebuchet_MS_Bold.ttf/0/H/65536/0/0 -> ./fonts/Trebuchet_MS_Bold.ttf(Identity-H)
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "./fonts/Trebuchet_MS_Bold.ttf".
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS_Bold.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS_Bold.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
(CID:TrebuchetMS-Bold)
pdf_font>> Type0 font "./fonts/Trebuchet_MS_Bold.ttf" cmap_id=<Identity-H,0> opened at font_id=<./fonts/Trebuchet_MS_Bold.ttf/0/H/65536/0/0,0>.><./fonts/[email protected]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
<NATIVE-FONTMAP:./fonts/Trebuchet_MS.ttf/0/H/65536/0/0>
fontmap: ./fonts/Trebuchet_MS.ttf/0/H/65536/0/0 -> ./fonts/Trebuchet_MS.ttf(Identity-H)
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "./fonts/Trebuchet_MS.ttf".
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
(CID:TrebuchetMS)
pdf_font>> Type0 font "./fonts/Trebuchet_MS.ttf" cmap_id=<Identity-H,0> opened at font_id=<./fonts/Trebuchet_MS.ttf/0/H/65536/0/0,1>.><./fonts/[email protected]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
fontmap: ./fonts/Trebuchet_MS.ttf/0/H/65536/0/0 -> ./fonts/Trebuchet_MS.ttf(Identity-H)[map:<00>]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
(CID:TrebuchetMS)
pdf_font>> Type0 font "./fonts/Trebuchet_MS.ttf" cmap_id=<Identity-H,0> opened at font_id=<./fonts/Trebuchet_MS.ttf/0/H/65536/0/0,2>.>][2]<./fonts/[email protected]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
fontmap: ./fonts/Trebuchet_MS.ttf/0/H/65536/0/0 -> ./fonts/Trebuchet_MS.ttf(Identity-H)[map:<00>]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
(CID:TrebuchetMS)
pdf_font>> Type0 font "./fonts/Trebuchet_MS.ttf" cmap_id=<Identity-H,0> opened at font_id=<./fonts/Trebuchet_MS.ttf/0/H/65536/0/0,3>.>][3][4][5 [6]][6
[7<./fonts/[email protected]]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS_Bold.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS_Bold.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
fontmap: ./fonts/Trebuchet_MS_Bold.ttf/0/H/65536/0/0 -> ./fonts/Trebuchet_MS_Bold.ttf(Identity-H)[map:<00>]
xdvipdfmx:warning: File name="./fonts/Trebuchet_MS_Bold.ttf" format="opentype fonts" might be found in different location than I expected:
xdvipdfmx:warning: >> ./fonts/Trebuchet_MS_Bold.ttf
xdvipdfmx:warning: >> Please adjust your TEXMF as conformant with:
xdvipdfmx:warning: >> http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts
xdvipdfmx:warning: >> I searched it with fooling kpathsea as progname="dvipdfmx" format="other binary files".
xdvipdfmx:warning: >> Default search path for this format file is:
xdvipdfmx:warning: >> /nonesuch
xdvipdfmx:warning: >> Please read "README" file.
(CID:TrebuchetMS-Bold)
pdf_font>> Type0 font "./fonts/Trebuchet_MS_Bold.ttf" cmap_id=<Identity-H,0> opened at font_id=<./fonts/Trebuchet_MS_Bold.ttf/0/H/65536/0/0,4>.>][7 [8] (./agb.aux)][8]
otf_cmap>> Creating ToUnicode CMap for "./fonts/Trebuchet_MS_Bold.ttf"...
otf_cmap>> Creating ToUnicode CMap for "./fonts/Trebuchet_MS.ttf"...
(CID:./fonts/Trebuchet_MS_Bold.ttf[SBUEJS+TrebuchetMS-Bold][CIDFontType2][21 glyphs (Max CID: 108)][12245 bytes])(CID:./fonts/Trebuchet_MS.ttf[QIPVEC+TrebuchetMS][CIDFontType2][77 glyphs (Max CID: 197)][31017 bytes])(CID)(CID)(CID)
[...]
我还尝试“调整我的 TEXMF 以符合http://www.tug.org/ftp/tex/tds-1.1/tds.html#Fonts“但该 URL 只返回 404。
我还注意到,像 这样的{\textbf{\huge{Testline}}}
操作按预期工作 - 字体正确,而且也是粗体。这更令人困惑,因为显然字体已加载并正常工作。只是不适用于\section
和\subsection
。
编辑:因此,我尝试使用 Ubuntu 包在 CI 机器上安装字体ttf-mscorefonts-installer
。根据apt-get
日志,一切正常,我可以在 中找到字体/usr/share/fonts/truetype/msttcorefonts
。我还mktexlsr
按照建议运行这里。
我将字体选择更改为
\setmainfont{Trebuchet MS}
\newfontfamily\sectionfont{Trebuchet MS}
我仍然从 XeLaTex 获得类似的日志,但这次我得到了
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
538 pdf_font>> The -m <00> option will be assumed for "/usr/share/fonts/truetype/msttcorefonts/trebuc.ttf".
539 (CID:TrebuchetMS)
另外。但至少 TEXMF 一致性声明已经消失了。