setmonofont にカスタム フォント ファミリを割り当てる

setmonofont にカスタム フォント ファミリを割り当てる

これらのコマンドを 2 回記述するよりも簡単な方法はありますか?

\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}

関連情報