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}
lyl
  • 2,727
  • Have you tried setting a font first? \setmainfont{TeX Gyre Bonum} or whatever font you want to use. – frabjous May 12 '22 at 02:15
  • \setmainfont{Latin Modern Roman} if you want the default font. – frabjous May 12 '22 at 02: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 May 12 '22 at 05:48
  • And, if the font name must be given expictly, how can I get the name of the default font in LaTex? – lyl May 12 '22 at 05: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. – Ulrike Fischer May 12 '22 at 07:00
  • @Ulrike Fischer. What are fd-files? Where are they? – lyl May 12 '22 at 13:07
  • tulmr.fd is in tex/latex/base. – Ulrike Fischer May 12 '22 at 13:09
  • When I use \fontname\font to print the default font, I get [lmroman10-regular]. It seems not to be Latin Modern Roman font. Then I \setmainfont{lmroman10-regular}, this causes error. So, what is on earth the name of the default font in LaTeX/XeLaTeX? – lyl May 13 '22 at 01:24

1 Answers1

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.

user202729
  • 7,143