情況

情況

這是一個 XeLaTeX 問題。使用fontspecXeLaTeX多年後問這個問題似乎很愚蠢。我想我總是能找到解決方法。這一次,我想要一個明確的答案。

情況

伺服器(編譯器/建置系統)在後台運行,全天候從版本控制儲存庫產生文件(以及其他操作)。文件由多個客戶端上的人工編輯。不能假設任何機器上的系統字體都是相同的。有兩件事在所有機器上都是相同的(或至少應該是): 1. TeX Live 版本/MikTeX。 2. 儲存庫檔案。這意味著我加載的任何字體都應該是:

  1. TeX Live 內建字體(假設與 MikTeX 相同)
  2. 儲存庫中的字體文件

非系統字體fc-list -f "%{family}\n" | sort -u基於 UNIX 的機器上所列出的。

載入字體fontspec

字體規範,字體有多種載入方式:

  1. 帶有擴展名的檔案名

例如

\setmainfont{texgyrepagella-regular.otf}
\let\texgyrepagellaregular\normalfont % create semantically relevant macro (name+font) to be consistent with other \newfontfamily macros
  1. 不含副檔名但具有作為參數給出的路徑構造表達式的檔名:

例如

\setmainfont{texgyrepagella}[
Path = /Users/will/Fonts/ ,
UprightFont = *-regular ,
BoldFont = *-bold ,]

我想避免透過鍵入/usr/local/texlive/<YEAR>/[...] 來載入字體,因為它們可能不位於同一位置。

試圖

\documentclass{article}
\usepackage{fontspec}
\setmonofont{Inconsolata}
\newcommand\escapedlog[1]{\par\ttfamily #1\par}
\begin{document}
Keep it simple.
\escapedlog{Hello}
\end{document}

日誌輸出(錯誤)

我想我知道這裡發生了什麼事。fontspec僅檢查系統字體列表fc-list -f "%{family}\n" | sort -u

kpathsea: Running mktextfm inconsolata
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input inconsolata
This is METAFONT, Version 2.7182818 (TeX Live 2015) (preloaded base=mf)


kpathsea: Running mktexmf inconsolata
! I can't find file `inconsolata'.
<*> ...our; mag:=1; nonstopmode; input inconsolata

Please type another input file name
! Emergency stop.
<*> ...our; mag:=1; nonstopmode; input inconsolata

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


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! fontspec error: "font-not-found"
!
! The font "inconsolata" cannot be found.
!
! See the fontspec documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.3 \setmonofont{inconsolata}

?

傳統套餐

根據這個列表,我應該安裝該字體。

TeX live 中安裝了哪些字型包?

答案1

您不需要給出明確的路徑,只要字體位於 XeTeX 搜尋的目錄中即可。相關的(偽)環境變數是

% TrueType outline fonts.
TTFONTS = .;$TEXMF/fonts/{truetype,opentype}//;$OSFONTDIR//

% OpenType outline fonts.
OPENTYPEFONTS = .;$TEXMF/fonts/{opentype,truetype}//;$OSFONTDIR//

使用者可以在環境中設定變量OSFONTDIR,但設定OPENTYPEFONTS和是由連結到的庫TTFFONTS執行的任務,因此使用者可以kpsexetex不是需要設定它們:一旦xetex啟動它們就會自動設定。

根據作業系統的不同,您可以讓系統識別目前 TeX 發行版中的字體。正如 TeX Live 安裝指南中所述,在大多數 GNU/Linux 系統上,您可以執行

cp $(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf
fc-cache -fsv

具有超級使用者權限(sudo或類似權限),TeX Live OpenType 和 TrueType 字型將可供作業系統使用。

第一個命令應在每年的 TeX Live 版本發布後加載,第二個命令應在安裝更新或新字體時運行tlmgr。我在我的 GNU/Linux 機器上這樣做。

這是一個範例,其中\testpath定義族只是為了交叉檢查是否\testkpse足夠。

\documentclass{article}
\usepackage{fontspec}

\newfontfamily{\testkpse}{Inconsolatazi4}[
  Extension=.otf,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
]

\newfontfamily{\testpath}{Inconsolatazi4}[
  Extension=.otf,
  Path=/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
]

\newfontfamily{\testfc}{Inconsolatazi4}

\begin{document}
\pagestyle{empty}

{\testkpse Inconsolata \bfseries Bold}

{\testpath Inconsolata \bfseries Bold}

{\testfc Inconsolata \bfseries Bold}

\end{document}

運行這個例子

xelatex -output-driver="xdvipdfmx -vv" test

終端機上會顯示以下訊息

<FONTMAP:/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map><FONTMAP:/usr/local/texlive/2016/texmf-var/fonts/map/dvipdfmx/updmap/kanjix.map><FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/map/dvipdfmx/ckx.map>No dvi filename specified, reading standard input.
stdin -> incons.pdf
DVI Comment:  XeTeX output 2016.06.09:1437
<AGL:texglyphlist.txt><AGL:pdfglyphlist.txt><AGL:glyphlist.txt>[1</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]<NATIVE-FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf/0/H/65536/0/0>
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf".
(CID:Inconsolatazi4-Regular)
pdf_font>> Type0 font "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf" cmap_id=<Identity-H,0> opened at font_id=</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf/0/H/65536/0/0,0>.
></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]<NATIVE-FONTMAP:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf/0/H/65536/0/0>
pdf_font>> Input encoding "Identity-H" requires at least 2 bytes.
pdf_font>> The -m <00> option will be assumed for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf".
(CID:Inconsolatazi4-Bold)
pdf_font>> Type0 font "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf" cmap_id=<Identity-H,0> opened at font_id=</usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf/0/H/65536/0/0,1>.
></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]></usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/[email protected]>]
otf_cmap>> Creating ToUnicode CMap for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf"...

otf_cmap>> Creating ToUnicode CMap for "/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf"...
(CID:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Regular.otf[CIDFontType0])(CID:/usr/local/texlive/2016/texmf-dist/fonts/opentype/public/inconsolata/Inconsolatazi4-Bold.otf[CIDFontType0])

這表明在每種情況下都選擇了正確的字體。

在此輸入影像描述

答案2

使用

 \setmonofont{Inconsolatazi4}

或者

 \setmonofont[
   BoldFont=Inconsolatazi4-Bold.otf]{Inconsolatazi4-Regular.otf}

預設情況下fontconfig,用於xetex/xelatex搜尋字體檔案的 不掃描 TeX 字體目錄。但是xetex/xelatex使用kpsewhich,它會找到具有全名的字體的原因。人們可以將這些文件放入系統字體目錄或擴展fontconfig.然後就可以使用符號名稱了。

相關內容