[Tex/LaTex] Error with CMU Serif font

fonts

I'm trying to compile this code:

\documentclass{book}
\usepackage{fontspec}
\setmainfont{CMU Serif}
\begin{document}
  text
\end{document}

but receive this error

l.17 \setmainfont{CMU Serif}

? 

in miktex-maketfm.log it says :

2017-10-08 23:57:03,239+0200 INFO  miktex-maketfm - starting with command line: miktex-maketfm -v "CMU Serif"
2017-10-08 23:57:03,259+0200 INFO  maketfm - Running miktex-makemf.exe...
2017-10-08 23:57:03,259+0200 INFO  maketfm - running: miktex-makemf.exe --verbose "CMU Serif"
2017-10-08 23:57:03,449+0200 INFO  maketfm - Running miktex-hbf2gf.exe...
2017-10-08 23:57:03,449+0200 INFO  maketfm - running: miktex-hbf2gf.exe -g "CMU Serif" 300
2017-10-08 23:57:03,600+0200 FATAL miktex-maketfm - No creation rule for font "CMU Serif".

Previously I had problems compiling fontspec; it seemed that got solved by updating miktex, but the two may still be connected. Thank you.

Best Answer

You can use the call \setmainfont{CMU Serif} only if the font is installed as a system font (or with LuaLaTeX). How to do the installation is system dependent.

Otherwise you can call the fonts “by font name”:

\setmainfont{cmun}[
  Extension=.otf,
  UprightFont=*rm,
  ItalicFont=*ti,
  BoldFont=*bx,
  BoldItalicFont=*bi,
]
\setsansfont{cmun}[
  Extension=.otf,
  UprightFont=*ss,
  ItalicFont=*si,
  BoldFont=*sx,
  BoldItalicFont=*so,
]
\setmonofont{cmun}[
  Extension=.otf,
  UprightFont=*btl,% light version
  ItalicFont=*bto,%  light version
  BoldFont=*tb,
  BoldItalicFont=*tx,
]

For the Typewriter Text font, also tt and it can be used instead of btl and bto (if you don't plan to use boldface monospaced)