0

In the example below, I add some features to the default LaTeX font by \addfontfeatures and compiled by XeLatex, but all of these features does not work. Why and how to make them work?

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\addfontfeatures{Color=123456,Opacity=0.3,Scale=5}
ABCD
\end{document}
8
  • Have you tried setting a font first? \setmainfont{TeX Gyre Bonum} or whatever font you want to use.
    – frabjous
    Commented May 12, 2022 at 2:15
  • \setmainfont{Latin Modern Roman} if you want the default font.
    – frabjous
    Commented May 12, 2022 at 2:25
  • Though I don't give the font name expictly, I think LaTex will allocate a default font. Why does \addfontfeatures not apply its features to this default font?
    – lyl
    Commented May 12, 2022 at 5:48
  • And, if the font name must be given expictly, how can I get the name of the default font in LaTex?
    – lyl
    Commented May 12, 2022 at 5:50
  • look into the log. There is a large warning: Package fontspec Warning: \addfontfeature(s) ignored on line 41; it cannot be used with a font that wasn't selected by a fontspec command. The default fonts are loaded with fd-files. Commented May 12, 2022 at 7:00

1 Answer 1

0

As mentioned in the comment: adding \setmainfont{Latin Modern Roman} at the begin of the document works.

\documentclass{article}
\usepackage{fontspec}
\begin{document}
\setmainfont{Latin Modern Roman}
\addfontfeatures{Color=123456,Opacity=0.3,Scale=5}
ABCD
\end{document}

Some extra information.

  1. The default font is Latin Modern Roman.

    Where and how does fontspec.sty specify the default font (Latin Modern Roman)?

    Why is Latin Modern the default font with xelatex and lualatex?

  2. This answer explains what .fd file do. How do fonts work in LaTeX?

  3. \fontname\font does not necessarily give the family name. Quote from fontspec documentation:

    fontspec documentation

    Experimentally, it looks like \fontname will give whatever you pass as input to \font command.

    \documentclass{article}
    \usepackage{fontspec}
    \begin{document}
    
    \font\abc=[[[lmroman9-regular\relax
    \abc
    \fontname\font
    
    \font\deg={Latin Modern Roman}\relax
    \deg
    \fontname\font
    
    \end{document}
    

    output image

  4. I don't know why fontspec and LaTeX core does not work together out of the box.

You must log in to answer this question.

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