Vincent
Vincent

Reputation: 723

Rstudio fails to run pdflatex

There are several similar questions here, but no answers.

If I compile an Rnw-file in Rstudio using knitr (that is to say: by clicking the "Compile PDF" button, but in Global Options I specified that the program should use knitr rather than sweave) Rstudio manages to produce a .tex file, but not to compile it into pdf. Instead I get the following error:

Error running C:/Users/vincent/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)

Rstudio makes it sound like the problem is with MikTex, but if I take the .tex file it produces, open in in Texmaker and compile it there (using 'Quick Build') it works fine. So personally I suspect that Rstudio is doing something wrong.

Is there a way to see what Rstudio is trying to do and why it doesn't work?

(I had to reinstall everything (Tex, Rstudio etc) and since then I have this problem.)

I am using Rstudio 2023.12.1 for (not directly relevant) reasons explained here.

Upvotes: 1

Views: 216

Answers (1)

Rich
Rich

Reputation: 31

I had this problem quite a while ago; I just updated RStudio and Miktex and the problem is still there.

When RStudio runs pdflatex it does a version check and, apparently, doesn't like the answer.

My work-around - which still works - is as follows:

Create a Windows .cmd file like this in the R directory called pdflatex.cmd:


@echo off

if %1 == --version goto version

pdflatex.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

goto :eof

:version

echo MiKTeX-pdfTeX 4.19 (MiKTeX 24.4)

RStudio calls "pdflatex" - no extension - so it gets the .cmd file because Windows looks for files with the .cmd extension first unless the extension is supplied, as above, so the .cmd file calls the real pdflatex in all other circumstances.

The drawback to this workaround is that there is no automatic view of the output. I sort the file window on date and open the pdf from there.

Tip: I use SumatraPDF as my pdf viewer. If you keep it open with your output pdf it will update every time you regenerate it.

Upvotes: 3

Related Questions