3

I am struggling with font selection. I just cant seem to get a grasp on this.

I have a document class I'm developing which uses Latin Modern Roman, Trajan Pro, and Trajan Pro Bold. My needs are to define the Trajan fonts to small caps and bold small caps while using LRM for everything else.

I cannot figure out why the following [options] causes an error, or how to get around it.

\documentclass[11pt]{article}

\usepackage{geometry}           %for page layout
\geometry{hmargin={1in,1in},vmargin={0.75in,0.75in},marginparwidth={0.8in},marginparsep={0in}}

\usepackage{fontspec}   %for xelatex unicode
    \setmainfont{Latin Modern Roman}[
        UprightFeatures = {SmallCapsFont=TrajanPro-Regular.otf},
        BoldFeatures = {SmallCapsFont=TrajanPro-Bold.otf},
    ]

\begin{document}

Here is some {\bfseries\scshape Boldface SmallCaps} text

Here is some {\bfseries\uppercase{Boldface Uppercase}} text

Here is some {\bfseries Boldface} text

Here is some {\scshape SmallCaps} text

Here is some \uppercase{Uppercase} text

Here is some {Regular} text

\end{document}

As an edit, I have added the following work around code I have been using for almost 5 years. This works just fine. everywhere I would want to type \scshape I just have typed \sffamily instead. I know its wrong to do so but in over 5 years of trying to figure out a better way I never have.

\RequirePackage{fontspec}           %for xelatex unicode
    \setmainfont{Latin Modern Roman}
%        BoldFont = ⟨font name⟩ 
%        ItalicFont = ⟨font name⟩ 
%        BoldItalicFont = ⟨font name⟩ 
%        SlantedFont = ⟨font name⟩ 
%        BoldSlantedFont = ⟨font name⟩ 
%        SmallCapsFont = ⟨font name⟩


    \setsansfont{TrajanPro-Regular.otf}[
        BoldFont=TrajanPro-Bold.otf
%        ItalicFont = ⟨font name⟩ 
%        BoldItalicFont = ⟨font name⟩ 
%        SlantedFont = ⟨font name⟩ 
%        BoldSlantedFont = ⟨font name⟩ 
%        SmallCapsFont = ⟨font name⟩
    ]

As one more edit, LRM is a system installed font, the Trajan fonts are two files I keep with my projects in the root directory. I would like to be able to put them into a font folder inside the root, but one step at a time.

1 Answer 1

5

I haven't got Trajan-Pro, so I have substituted something else that will be obviously different than LMR (TexGyreHeros).

\documentclass[11pt]{article}

\usepackage{geometry}           %for page layout
\geometry{hmargin={1in,1in},vmargin={0.75in,0.75in},marginparwidth={0.8in},marginparsep={0in}}

\usepackage{fontspec}  %% running under LuaLaTeX

\setmainfont{Latin Modern Roman}[
        SmallCapsFeatures={Letters=SmallCaps}, % <=== See Section 4.1 of Fontspec documentation.  
        UprightFeatures = {SmallCapsFont=texgyreheros-regular.otf},
        BoldFeatures = {SmallCapsFont=texgyreheros-bold.otf},
    ]


\begin{document}
Here is some {\bfseries\scshape Boldface SmallCaps} text

Here is some {\bfseries\uppercase{Boldface Uppercase}} text

Here is some {\bfseries Boldface} text

Here is some {\scshape SmallCaps} text

Here is some \uppercase{Uppercase} text

Here is some {Regular} text
\end{document}

enter image description here

The one change made is to add the line SmallCapsFeatures={Letters=SmallCaps}, for the reasons discussed in the Fontspec documentation in Section 4.1.

This code works on my system under LuaLaTeX, but not XeLaTeX -- perhaps because I do not have LMR installed as a system font; for LuaLaTeX, LMR is the default font. To test that idea, the following code substitutes one of my system fonts for LMR (TeX Gyre Termes):

%% using the free Tex Gyre fonts, which I have installed as system fonts
\setmainfont{TeXGyreTermesX}[
     SmallCapsFeatures={Letters=SmallCaps}, % <=== See Section 4.1 of Fontspec documentation.  
     UprightFeatures = {SmallCapsFont=texgyreheros-regular.otf}, 
     BoldFeatures = {SmallCapsFont=texgyreheros-bold.otf},
    ]

With this change, I get the same result for either LuaLaTeX or XeLaTeX:

enter image description here

Two additional notes may be helpful. First, Will Robertson has recently recommended using explicit file names, rather than the "human-readable" system names TUGBoat 39 (2018). Second, the SmallCapsFeatures can be embedded into the the other features, so that you have additional control for upright or bold:

\setmainfont{texgyretermes}[
Extension = {.otf},
UprightFont = {*-regular}, 
ItalicFont = {*-italic},
BoldFont = {*-bold}, 
BoldItalicFont = {*-bolditalic},
UprightFeatures = {SmallCapsFont=texgyreheros-regular.otf, SmallCapsFeatures={Letters=SmallCaps, Color=992211}},
BoldFeatures    = {SmallCapsFont=/Users/John/Library/Fonts/FiraGO-Heavy.otf,   SmallCapsFeatures={Letters=SmallCaps, Color=112299}, Color = FF4422},
]

Your can give the full path to your Trajan-Pro font files, e.g., as I have done here for FiraGO-Heavy. enter image description here

7
  • Well this worked, but just like for you only when I switched to luaLaTeX. The peculiar part is that it complains about not being able to find the Trajan font, not the LMR. Ive been using XeLaTeX ever since I started, is there any disadvantage between switching to LuaLaTeX?
    – Bob
    Aug 12, 2019 at 2:21
  • In terms of advantages/disadvantages, I prefer LuaLaTeX because I use a lot of code in my work (which lua supports). XeTeX has been around longer, but Lua seems to have been more actively developed in recent years. My personal opinion is in favor of Lua at this point.
    – John
    Aug 12, 2019 at 2:41
  • Actually it seems that the extra line isnt needed when using LuaLaTeX. My initial code works just fine. So either we are still doing something wrong, or there is a broken relation with XeLaTeX and fontspec.
    – Bob
    Aug 12, 2019 at 6:20
  • I definitely do need the extra line in order to get small caps with my font installations under LuaLaTeX. If I comment it out, the two phrases meant to be small caps revert to titlecase. I think the differing behavior we are seeing may relate to differences in our font installations. I have edited the example to include a case where both the main font and the font features use system fonts, which brings LuaLaTeX and XeLaTeX into agreement. Also, made the feature font names lower case, to match the file names (LuaLaTeX didn't notice the previous capitals)
    – John
    Aug 12, 2019 at 12:51
  • Thank you for all your help with this matter. Something is very wrong on my end I think. I am using Overleaf for my work, and as a test I made two binary equivalent projects. One of them compiles even when it should not (given the statement from my last comment) and the other cannot compile at all. I will look into getting my hands on the files for LMR and put them into the root directory as a next test.
    – Bob
    Aug 13, 2019 at 5:28

You must log in to answer this question.

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