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


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

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.

  • 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 '17 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 '17 at 13:51
  • Welcome to TeX.SX! Please provide a compilable document, not just a fragment. – Bobyandbob Dec 13 '17 at 10:22
  • 1
    Do not redefine the command \special! That is a very important TeX primitive. – Henri Menke Jan 29 at 22:04
  • my googlefu is insufficient. Havent been able to find the implications of redefineing \special. @HenriMenke what happens though? – helt Jan 30 at 12:27

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.