RNW file: "Compile PDF" button fails after MiKTeX update

Consider the following minimal RNW file (test.Rnw):


Clicking the "Compile PDF" button in RStudio gives the following error message (and no PDF is being produced):

Running pdflatex.exe on test.tex...failed
Error running C:/Users/myname/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)

I'm encountering this issue on 4 different machines and strongly suspect that it arises from the interplay of RStudio and MiKTeX:

  1. All machines run Windows 10 and had MiKTeX, R and RStudio in more-or-less recent versions installed.
  2. In this baseline scenario, "Compile PDF" used to work on all machines.
  3. As soon as I perform a full update of MiKTeX, the error quotes above occurs.
  4. Updating RStudio and R (including installed packages) to their latest versions has no effect.
  5. Completely re-installing RStudio and MiKTeX has no effect.

All this might sound like MiKTeX is the culprit, however:

  1. If I knit the RNW file to get test.tex and compile this TEX file from the command line (or TeXStudio), it compiles without issues.
  2. system2(command = "pdflatex.exe", args = "test.tex") from within R also works. By the way, Sys.which("pdflatex") points to "C:\\Users\\myname\\AppData\\Local\\Programs\\MiKTeX\\miktex\\bin\\x64\\pdflatex.exe", which is the correct path.
  3. Even knit2pdf("test.Rnw") works flawlessly.

Only RStudio's "Compile PDF" button does not work. I also checked "C:\Users\myname\AppData\Local\MiKTeX\miktex\log\pdflatex.log". As far as I understand it, it shows no errors:

2021-03-19 17:14:01,791+0100 INFO pdflatex - this process (10020) started by 'rsession' with command line: C:/Users/myname/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe --version
2021-03-19 17:14:01,799+0100 INFO pdflatex - allowing known shell commands
2021-03-19 17:14:01,809+0100 INFO pdflatex - this process (10020) finishes with exit code 0

By the way, producing PDF output from RMD files causes no issues, but I guess this is because pandoc does not use the local LaTeX distribution.

I did try tinytex::install_tinytex() and in fact, this solves the issue. However, I have no(t much) control over the affected machines and therefore must use MiKTeX. Therefore, resorting to TinyTeX is not an option.

Any help in identifying and solving this issue is highly appreciated!
Please let me know if I can provide any further debug information.

Update – I found this related bug report: https://github.com/rstudio/rstudio/issues/9019.

Can you try with setting RStudio option to use tinytex ?
You may also try with the daily version of RStudio : https://dailies.rstudio.com/ (you can install a portable one on windows with the zip file which won't remove the other one you have)

it is in global options in Sweave options. You can also access with CTRL+MAJ+P to open command palette and seaching for "tinytex".

Just to precise tinytex the R package is different thant TinyTeX the LaTeX distribution. The former should work with MikTeX too.

Just some hints if you want to try.

Thanks for your reply, @cderv!

I tried (today's) daily version: The problem persists but using the tinytex option solves the issue. (I was not aware that tinytex can be "enabled" for RStudio without changing PATH system-wide, as it's the case with tinytex::install_tinytex().)

Interestingly, in the stable version of RStudio enabling the tinytex option seems to have no effect. Even the output remains "Running pdflatex.exe on test.tex...failed" instead of "Compiling document with tinytex ... completed" as printed by the daily build.

This option does not activate TinyTeX, as the distribution you get when doing tinytex::install_tinytex(). It will make RStudio uses tinytex the R package as rmarkdown does.

This is because the daily version fixed an issue with that. So for now you need the daily.

You can share in the rstudio issue what works for you maybe.

Thanks @cderv, that's a nice workaround (although I'm still really curious how RStudio calls pdflatex and which change in MikTeX broke this).

I posted an update in the GitHub thread.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.