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.

5
  • Why do you do this definition of \Mono? You can use \ttfamily instead. Specific settings can be changed later on using \addfontfeatures.
    – TeXnician
    Aug 9, 2017 at 12:33
  • Could you please make some example which features you actually try to enable/disable? Have you looked into the documentation (including the points on \addfontfeatures)?
    – TeXnician
    Aug 9, 2017 at 13:51
  • Welcome to TeX.SX! Please provide a compilable document, not just a fragment.
    – Bobyandbob
    Dec 13, 2017 at 10:22
  • 1
    Do not redefine the command \special! That is a very important TeX primitive. Jan 29, 2019 at 22:04
  • my googlefu is insufficient. Havent been able to find the implications of redefineing \special. @HenriMenke what happens though?
    – helt
    Jan 30, 2019 at 12:27

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .