0

It's my first Markdown report, and i try to write it directly on a PDF. I need to use Times New Roman font but the export fail:

Package fontspec Error: The font "Times New Roman" cannot be found.

I've already tried these code

font-family: Times New Roman

or

mainfont: Times New Roman

or


header-includes:

- \usepackage{fontspec}

- \setmainfont{Times New Roman}

but none of these codes work.

Thanks !

MyNameIsCaleb
  • 4,409
  • 1
  • 13
  • 31
qlamb
  • 15
  • 1
  • 5
  • 1
    Which engine do you use for compiling? You used both pdflatex and xelatex as tags, please advise which of both is true – samcarter_is_at_topanswers.xyz Apr 26 '19 at 16:48
  • Are you sure you have "Times New Roman" with this spelling installed on your system? – Ralf Stubner Apr 26 '19 at 20:52
  • I use xelatex but I tried with luatex too, and both did not work .. – qlamb Apr 27 '19 at 09:45
  • I think it is, but I can't see because I work on Rstudio.cloud – qlamb Apr 27 '19 at 10:58
  • 1
    Try one listed in http://www.tug.dk/FontCatalogue/ – mb21 Apr 30 '19 at 12:13
  • 1
    As for the fonts in the LaTeX font catalogue: Sticks Too, Stix (2), TeX Gyre Termes, TX Fonts, URW Nimbus Roman, and XITS are all Times (New Roman) like fonts. At least URW Nimus Roman, i.e. `mathptmx.sty`, should be available on rstudio.cloud, since it is a required part of every LaTeX distribution. – Ralf Stubner Apr 30 '19 at 21:17

1 Answers1

0

As @RalfStubner has already mentioned, you can use TeX Gyre Termes to embed a font like Times New Roman.

Install tex-gyre

In order to use TeX Gyre Termes, you need to install tex-gyre package from CTAN. If you have installed @Yihui's TinyTeX, type the following code to R console.

tinytex::tlmgr_install("tex-gyre")

The code above is equivalent to executing the code below in your bash.

tlmgr install tex-gyre

Provide .tex file to specify font(s) you want

Setting mainfont: in the YAML header should also work. However, here I show how to set fonts by including a .tex file, say font-config.tex for instance, to the YAML section. By the font-config.tex file, you can configure more detailed options, like Scale=MatchUppercase.

In the following font-config.tex, TeX Gyre Termes, or Times New Roman is set as the main font (\rmfamily) and TeX Gyre Heros, so-called Helvetica or Arial is specified as the san serif font (\sffamily). Save the file in your current directory.

font-config.tex

\usepackage{fontspec}

%rmfamily
\setmainfont[Scale=MatchUppercase]{TeX Gyre Termes} %Times New Roman

%sffamily
\setsansfont[Scale=1]{TeX Gyre Heros} %So called Helvetica, Arial

Include font-config.tex into the YAML header

You can call the font-config.tex from the YAML header, as shown below.

---
title: "The definitive MWE"
subtitle: "Oh, yeah"
author: "CLR"
output:
  bookdown::pdf_document2:
    number_sections: true
    latex_engine: xelatex #or lualatex
    keep_tex: true
    includes:
      in_header: 
        - font-config.tex
---

*Hellow world!* in Times New Roman.

\textsf{Hellow world!} in Helvetica. 
Carlos Luis Rivera
  • 3,108
  • 18
  • 45