2

I am running R 4.0.5 on Window 10. It's a new laptop with a very recent R, RStudio, and tinytex installations. I have a notebook file that works fine when I knit to Word. But when I try to knit to PDF, I get the following error:

output file: intro_R_notebook_1.knit.md

Error: LaTeX failed to compile intro_R_notebook_1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. In addition: Warning message: In system2(..., stdout = if (use_file_stdout()) f1 else FALSE, stderr = f2) : '"pdflatex"' not found Execution halted

No LaTeX installation detected (LaTeX is required to create PDF output). You should install a LaTeX distribution for your platform: https://www.latex-project.org/get/

If you are not sure, you may install TinyTeX in R: tinytex::install_tinytex()

Otherwise consider MiKTeX on Windows - http://miktex.org

MacTeX on macOS - https://tug.org/mactex/ (NOTE: Download with Safari rather than Chrome strongly recommended)

Linux: Use system package manager

In the YAML I have have the following for the pdf part: output:

pdf_document: default

It looks like RStudio can't find the tinytex executable file. The file is located here on my PC (note: I changed part of the path to 'johndoe'):

C:\Users\johndoe\Documents\R\R-4.0.5\library\tinytex

This path is different that where tintex installed itself on my other (4 year old) laptop, which looks like this:

C:\Users\johndoe\Documents\R\win-library\4.0\tinytex

So we can see that the folder names are somewhat different, because the first case uses /library/ (the one not working by the way), and the second case uses /win-library/ (that one is working OK).

I am not sure if I have to modify the Windows 10 PATH environment variable to address this. That was not necessary on my other Windows laptop which runs tinytex OK. I tried removing and re-installing the rmarkdown package with dep=TRUE, which was suggested in another post. I also tried installing MikTex out of desperation, but that did not work. Not sure what to try next.

2 Answers2

3

Installing the R package tinytex is not enough. The message says:

You should install a LaTeX distribution for your platform [...] If you are not sure, you may install TinyTeX in R: tinytex::install_tinytex()

Did you try that?

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • I tried the command you suggested and it worked. I tried it before but for some reason it did not work. Can you comment on what is the difference between the command you showed above and the standard way of installing a package in R (i.e. install.packages("tinytex"). – cookie monster May 19 '21 at 23:10
  • Even though I can knit to PDF now, it does not make sense, because you wrote that installing the R package tinytex "is not enough. What more is needed then ? Does a separate Latex distribution get installed when I enter "tinytex::install_tinytex()" ?? As far as I know all I have done so far is install the package tinytex. – cookie monster May 19 '21 at 23:20
  • 1
    I don't understand why you don't understand the two sentences: 1. Installing the R package tinytex is not enough. 2. You should install a LaTeX distribution for your platform. That means an R package is not a LaTeX distribution. You need LaTeX. TinyTeX is a LaTeX distribution, which can be installed via the command above. Does that make sense now? – Yihui Xie May 20 '21 at 13:24
  • Thank you. It makes sense now and the problem is solved. – cookie monster May 29 '21 at 23:10
0

In Console:

First Check if you have the 'tinytex' package already installed in R tinytex:::is_tinytex()

it will return TRUE or FALSE

If FALSE, then install it using

tinytex::install_tinytex()

It might take some time. Once it is done, check again

tinytex:::is_tinytex()

If installed, it will return TRUE [1] TRUE

then,

library(tinytex)

You should not get any errors anymore. Now you can proceed with your report-making.