1

I use xetex and fontspec to work with custom fonts like this:

\usepackage{fontspec}

\setmainfont{AGaramondPro}[Path = fonts/garamond/,%
  BoldFont = *-Bold.otf,
  BoldItalicFont = *-BoldItalic.otf,
  ItalicFont = *-Italic.otf,
  UprightFont = *-Regular.otf,
  RawFeature={%
    +onum  % odd style figures
}]
\newfontfamily{\special}[Path = fonts/garamond/,%
  BoldFont = *-Bold.otf,
  BoldItalicFont = *-BoldItalic.otf,
  ItalicFont = *-Italic.otf,
  UprightFont = *-Regular.otf,
  RawFeature={+c2sc,+scmp}]{AGaramondPro}

I keep asking myself if i can DRY it, so i define the font only once.

The font above is just an example. I have other fonts, where i would like to enable/disable certain RawFeatures for all instances without copy-pasting everywhere...

So the goal is that i can do something like

lorem {\ttfamily ipsum \special{dolor} amet} 

and dolor is then set in Garamond small capitals, and not in mono.

helt
  • 855

1 Answers1

1

You could move the repetitious code into a file such as GaramondPro.fontspec and then load that more than once with modifications. The documentation gives the example of My Charis.fontspec containing the lines:

\defaultfontfeatures[My Charis]
{
  Extension = .ttf ,
  UprightFont = CharisSILR,
  BoldFont = CharisSILB,
  ItalicFont = CharisSILI,
  BoldItalicFont = CharisSILBI,
  % <any other desired options>
}
Davislor
  • 44,045