將自訂字體系列指派給 setmonofont

將自訂字體系列指派給 setmonofont

有沒有更簡單的方法而不是兩次編寫這些命令?

\newfontfamily\codefont[
  Scale=MatchLowercase,
  Path = fonts/]
  {Inconsolata-dz}

\setmonofont[
  Scale=MatchLowercase,
  Path = fonts/]
  {Inconsolata-dz}

\setmonofont{\codefont}心裡有類似的想法,但似乎行不通。

答案1

我不確定你為什麼要這樣做;但是,您可以指定對應的 NFSS 系列名稱\codefont

\newfontfamily\codefont[
  NFSSFamily=Inconsolata,
  Scale=MatchLowercase,
  Path = fonts/
]{Inconsolata-dz}

\renewcommand{\ttdefault}{Inconsolata}

完整測試,我使用Inconsolatazi4並評論了該Path行。

\documentclass{article}
\usepackage{fontspec}

\newfontfamily\codefont[
  NFSSFamily=Inconsolata,
  Scale=MatchLowercase,
%  Path = fonts/
]{Inconsolatazi4}

\renewcommand{\ttdefault}{Inconsolata}

\begin{document}

This should be Inconsolata: {\codefont Test of mono font}

This should be Inconsolata: \texttt{Test of mono font}

\end{document}

在此輸入影像描述

答案2

您可以在 XeLaTeX 中使用\newfontfamily{}[]{}命令,其語法類似於\setmainfont

\documentclass{article}
\usepackage{fontspec}
\setmainfont[Extension=.ttf]{f1}
\newfontfamily{\myone}[Extension=.ttf]{f2}
\newfontfamily{\mytwo}[
    BoldFont = f3_bold.ttf,
    ItalicFont = f3_italic.ttf,
    BoldItalicFont = f3_bold_italic.ttf
    ]{f3.ttf}

\begin{document}

fhsdfhhrth

{\myone gfhjjrjtyjsdjry}

{\mytwo dshthrsht\textbf{rjrtj} rtjjtrjjt \textit{dfhdhsrh} }

gthfrshtr

\end{document}

相關內容