1

Is there an easier way instead of writing those commands twice?

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

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

I'm having something like \setmonofont{\codefont} in mind but that doesn't seem to work.

  • I don't think there is. See also http://tex.stackexchange.com/questions/29457/xetex-package-fontspec-use-previously-defined-newfontfamily-with-setmainfont You should show us a full minimal example of your document and explain a bit, why you are doing such thing. – LaRiFaRi Feb 19 '16 at 16:04

2 Answers2

1

I'm not sure why you want to do that way; however, you can specify an NFSS family name corresponding to \codefont:

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

\renewcommand{\ttdefault}{Inconsolata}

Full test, where I used Inconsolatazi4 and commented the Path line.

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

enter image description here

egreg
  • 1,121,712
  • Perfect. Although I hoped \setmonofont or \setmainfont would accept a reference to a custom font family and I wouldn't have to use \renewcommand{...}{...} – user3105453 Feb 19 '16 at 16:22
  • 1
    @user3105453 Actually I can't understand why you're doing that way instead of just using \setmonofont. – egreg Feb 19 '16 at 16:42
0

Youcan use \newfontfamily{}[]{} command in XeLaTeX and it's syntax is similar with \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}
Giorgi
  • 1,069