1

I have the following document, which uses fonts stored in a fonts/ directory (specifically several subdirectories of fonts/), as well as defined font subfamilies. I'm trying to compile it into a PDF using latexmk:

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.75in]{geometry}


\usepackage[colorlinks=true]{hyperref}
\usepackage{metalogo}

\usepackage{fontspec}
\setmainfont{FRABK.TTF}[
  ItalicFont = FRABKIT.TTF,
  BoldFont = FRAMD.TTF,
  BoldItalicFont = FRAMDIT.TTF,
  FontFace = {db}{n}{ Font = FRADM.TTF, Path = fonts/franklin-gothic/ },
  FontFace = {db}{i}{ Font = FRADMIT.TTF, Path = fonts/franklin-gothic/ },
  Path = fonts/franklin-gothic/
]
\setsansfont{CGOR45W.TTF}[
  ItalicFont=CGOR46W.TTF,
  BoldFont=CGOR65W.TTF,
  BoldItalicFont=CGOR66W.TTF,
  Path = fonts/cg-omega/
]
\setmonofont{CONSOLA.TTF}[
  ItalicFont=CONSOLAI.TTF,
  BoldFont=CONSOLAB.TTF,
  BoldItalicFont=CONSOLAZ.TTF,
  Path = fonts/consolas/
]
\newcommand{\lmr}{\fontfamily{lmr}\selectfont} % Latin Modern Roman
\newcommand{\lmss}{\fontfamily{lmss}\selectfont} % Latin Modern Sans
\newcommand{\lmtt}{\fontfamily{lmtt}\selectfont} % Latin Modern Mono


\begin{document}


\section{Foo}
\fontseries{db}\selectfont
Demibold text \\
\normalfont
\textbf{Medium text} \\
Normal text


\noindent
  \hrulefill \par
\noindent
  \hypersetup{linkcolor=gray}
  \small
  \url{http://www.example.org/} \hfill \textbf{Date}


\end{document}

Since I'm using fontspec, this would require xelatex. However, when I run latexmk -pdf -xelatex main.tex, I receive:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "kernel/key-unknown"
!
! The key 'fontspec/Path' is unknown and is being ignored.
!
! See the LaTeX3 documentation for further information.
!
! For immediate help type H <return>.
!...............................................

l.17 ]

? h
|'''''''''''''''''''''''''''''''''''''''''''''''
| The module 'fontspec' does not have a key called fontspec/Path'.
| Check that you have spelled the key name correctly.
|...............................................

Why is fontspec/Path unknown, and how can I get it to be recognized? Is my latexmk invocation incorrect, perhaps causing it not to use xelatex at a time when it should?

More generally, could this be alleviated by better methods of organizing the font definitions or how the document is compiled?

Tim Parenti
  • 1,251
  • It looks as if you can't use the Path key inside the FontFace key. I'm not sure if this is intended and you should make a bug report https://github.com/wspr/fontspec/issues. But in your case it is probably not needed anyway. – Ulrike Fischer Sep 09 '15 at 07:31
  • Right. As long as you can copy or symlink the font file, you can work around it, but this doesn’t seem to let you declare a different path for a semibold or small-caps variant you downloaded separately. It doesn’t work inside BoldFeatures or ItalicFeatures, either. As a workaround, you should be able to stick symlinks in a directory fontspec can search. – Davislor Sep 09 '15 at 08:45
  • 1
    It's quite difficult internally to allow fontspec to choose fonts from different locations (unfortunately). You can blame my poor programming practises. Some testing indicates that this error occurs because fontspec CAN find the font, so if you just delete the nested Path = ... setting you might fix the problem. – Will Robertson Sep 21 '15 at 03:00
  • 1
    Actually I mucked around a little more in fontspec and I think this will be fixed in the next CTAN release. – Will Robertson Sep 21 '15 at 03:36
  • 1
    @WillRobertson I don't know why it hadn't occurred to me to simply assume it didn't need to be told twice. It works perfectly now! – Tim Parenti Sep 22 '15 at 06:42

2 Answers2

2

Per Will Robertson's comment, actually, fontspec can find the font; it just doesn't need to be told the location twice. Applying the following diff got rid of the error:

-       FontFace = {db}{n}{ Font = FRADM.TTF, Path = fonts/franklin-gothic/ },
-       FontFace = {db}{i}{ Font = FRADMIT.TTF, Path = fonts/franklin-gothic/ }
+       FontFace = {db}{n}{ Font = FRADM.TTF },
+       FontFace = {db}{i}{ Font = FRADMIT.TTF }

Full example

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=0.75in]{geometry}


\usepackage[colorlinks=true]{hyperref}
\usepackage{metalogo}

\usepackage{fontspec}
\setmainfont{FRABK.TTF}[
  ItalicFont = FRABKIT.TTF,
  BoldFont = FRAMD.TTF,
  BoldItalicFont = FRAMDIT.TTF,
  FontFace = {db}{n}{ Font = FRADM.TTF },
  FontFace = {db}{i}{ Font = FRADMIT.TTF },
  Path = fonts/franklin-gothic/
]
\setsansfont{CGOR45W.TTF}[
  ItalicFont=CGOR46W.TTF,
  BoldFont=CGOR65W.TTF,
  BoldItalicFont=CGOR66W.TTF,
  Path = fonts/cg-omega/
]
\setmonofont{CONSOLA.TTF}[
  ItalicFont=CONSOLAI.TTF,
  BoldFont=CONSOLAB.TTF,
  BoldItalicFont=CONSOLAZ.TTF,
  Path = fonts/consolas/
]
\newcommand{\lmr}{\fontfamily{lmr}\selectfont} % Latin Modern Roman
\newcommand{\lmss}{\fontfamily{lmss}\selectfont} % Latin Modern Sans
\newcommand{\lmtt}{\fontfamily{lmtt}\selectfont} % Latin Modern Mono


\begin{document}


\section{Foo}
\fontseries{db}\selectfont
Demibold text \\
\normalfont
\textbf{Medium text} \\
Normal text


\noindent
  \hrulefill \par
\noindent
  \hypersetup{linkcolor=gray}
  \small
  \url{http://www.example.org/} \hfill \textbf{Date}


\end{document}

Expected output

Tim Parenti
  • 1,251
1

Simplest answer:

Copy the font files to ~/.fonts/, re-run fc-cache, then load them by their human-readable names.

More Comprehensive, Revised:

My first answer missed that your problem was your demibold fonts not working. Here’s how you do that. To test this, I put symlinks for all the Libertine fonts with slightly-altered names in a fonts/ directory so that there would be no possibility of XeLaTeX or LuaLaTeX finding them in their original locations.

\documentclass{article}
\usepackage{iftex}

\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{cmbright}
%% Load without Biolinum, or it will replace CM Bright,
%% and without sb, or it will replace bold:
\usepackage[libertine]{libertine}

\else % Assume a Unicode engine.
\usepackage{fontspec}

%% COPY and RENAME the Libertine files to test the engine's ability to find them.
\setmainfont{Libertine_R.otf}[
              Path = fonts/,
              FontFace = {sb}{n}{ Font = Libertine_RZ.otf},
              FontFace = {sb}{it}{ Font = Libertine_RZI.otf},
              BoldFont = {Libertine_RB.otf},
              ItalicFont = {Libertine_RI.otf},
              BoldItalicFont = {Libertine_RBI.otf},
            ]
\defaultfontfeatures{Scale=MatchLowercase}
\setsansfont[ FontFace = {sb}{n}{CMU Bright SemiBold},
              FontFace = {sb}{it}{CMU Bright SemiBold Oblique},
            ]{CMU Bright}

\fi         % \ifPDFTeX

\DeclareOldFontCommand{\sbseries}{\fontseries{sb}\selectfont}{\mathbf}
\DeclareTextFontCommand{\textsb}{\sbseries}

\begin{document}

\framebox[10cm][s]{
\rmfamily \makebox[2.5cm][c]{Normal} \makebox[2.5cm][c]{\mdseries Medium} \makebox[2.5cm][c]{\sbseries Semibold} \makebox[2.5cm][c]{\bfseries Bold} \normalfont
} \par
\framebox[10cm][s]{
\makebox[2.5cm][c]{\textsf{Normal}} \makebox[2.5cm][c]{\textsf{\textmd{Medium}}}\makebox[2.5cm][c]{\textsf{\textsb{Semibold}}} \makebox[2.5cm][c]{\textsf{\textbf{Bold}}}
}

\end{document}

Note that there’s no need to declare \inputenc in either, because they accept UTF-8 by default, and \newfontfamily exists to do what you wanted with \lmr. Also, the usual series name for semibold fonts is {sb}.

Normal Medium Bold Semibold output

Additional Notes

There are a few differences from your example, but they're minor. As in the original, this solution puts the custom fonts in a fonts/ subdirectory. The \ifPDFTeX block is only there so the example will compile on PDFLaTeX and provide reference output. Finally, the \defaultfontfeatures command has the cosmetic effect of scaling all the fonts loaded by fontspec to the same x-height.

Davislor
  • 44,045
  • Options can go after the filename in a current fontspec. The manual is correct. This is rather useful if you have longuish options - the fontname is nearer to the setmainfont command. – Ulrike Fischer Sep 09 '15 at 07:33
  • ? What do mean by bugged? It's the decision of the author how the syntax of a command should look and there is no law that optional arguments should be before the mandatory arguments. – Ulrike Fischer Sep 09 '15 at 07:47
  • Huh. I try it again and it worked. – Davislor Sep 09 '15 at 07:50
  • I was initially thinking that the cause of the problem was the arguments after the fontname not working, but after testing again, I was mistaken. Will edit. – Davislor Sep 09 '15 at 07:51
  • All right, new answer that fixes his actual problem. – Davislor Sep 09 '15 at 08:24
  • @Lorehead, unfortunately your example above is vastly different from the example I provided. In particular, I'm not at all understanding the motivation behind bringing in iftex and setting \defaultfontfeatures. I also need to store the fonts locally to this particular project, so referring to them globally is not viable. Could you edit to be a little more clear what you've changed from above, why, and to what effect? – Tim Parenti Sep 20 '15 at 20:22
  • Unfortunately, I won't be able to work on any LaTeX for the next several days. However: the iftex block is just so it compiles in PDFTeX at all. The \defaultfontfeatures is cosmetic, and just scales all the fonts to the same height. This example put the fonts in a local fonts/ directory, too. – Davislor Sep 20 '15 at 20:36
  • Put the explanation you requested in an edit. – Davislor Sep 20 '15 at 22:12