5

I have problem with running my .rnw (I am running Sweave) files in RStudio due to this error message:

Writing to file test.tex
Processing code chunks with options ...

You can now run (pdf)latex on 'test.tex'
Running pdflatex.exe on test.tex...failed
Error running C:/PROGRA~1/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)

I have default instalation of MiKTeX and from what I see in my PC I downloaded version 21.2. I have been checking for updates and there aren't any new ones. I use freshly reinstaled Windows 10 as OS with freshly instaled R, RStudio and MiKTeX. So there should not be any interferance with another MiKTeX version.

When I check path to my MiKTeX in RStudio with this code: Sys.which("pdflatex") then I get this response:

                                              pdflatex 
"C:\\PROGRA~1\\MiKTeX\\miktex\\bin\\x64\\pdflatex.exe" 

I have also tried enabling shell escape commands in Tools/Global Options but this did not work also. I have no idea what could be wrong here. Do you have any idea how to fix this issue?

Thank you for your time and effort.

Gregor G.
  • 57
  • 3
  • 8
  • 1
    @StackMan https://stackoverflow.com/users/15330028/stackman says: "I have the exact same problem except on Win2019. I have tried any number of things (like pretty much everything here https://tex.stackexchange.com/questions/267299/how-to-fix-the-sorry-but-c-miktex-pdftex-exe-did-not-succeed-error ) but no change. My best guess is that it's missing some packages. But which ones? If I find out, I'll let you know. If anyone else knows, I know I'd appreciate the answer." – Ben Bolker Mar 05 '21 at 21:36

3 Answers3

2

I had the same problem and only solution that I came up was uninstalling MikTex and installing TinyTex.

tinytex::install_tinytex()
icam
  • 21
  • 3
2

I too had this problem after updating MikTex and RStudio.

The pdflatex log showed that RStudio first calls pdflatex --version and then the error occurs. I concluded that RStudio didn't like the answer.

Edit 2:

So far, this seems correct and I have updated both MikTex and RStudio to the latest versions.

I would guess that installing an older version of MikTex works because the older pdflatex returns a version message that RStudio knows how to deal with.

My solution is this:

  1. In your R directory create a file, pdflatex.cmd
  2. In the same directory create a file rs.cmd (or any other name you want)

These files are:

---------- 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.8 (MiKTeX 21.10)

----------- pdflatex.cmd -------------

The version returned is the first line of the output of "pdflatex --version"

----------- rs.cmd -------------

@echo off

rem Start RStudio with specific environment variables    
set RSTUDIO_PDFLATEX=pdflatex.cmd    
set PATH=%PATH%;"C:\Program Files\RStudio\bin\";..
start /D "C:\Program Files\RStudio\" rstudio.exe

----------- rs.cmd -------------

To use it, start RStudio with the rs command.

Now, clicking the 'Compile PDF' button successfully runs and compiles the pdf and opens it in the viewer.

There are some limitations:

  • The previous project environment is not completely restored; you may have to re-open some files.
  • The output of the pdflatex command is not captured by RStudio. If you have latex errors you may have to run pdflatex in a command shell to inspect them.

The real answer, of course, is for RStudio to correctly deal with the "--version" response but this is working for me now.

Rich

Rich
  • 36
  • 4
1

Simple solution

You don't have uninstall RStudio. Just go to the Menu, click on "Tools", select "Global Options", look for Sweave from the menu list, under "LaTex Editing and Compilation", check "Use tinytex when compiling .tex files", click on "Apply", and "Okay".

Go back to your Sweave document and compile again. It will work. You can also select "RStudio Viewer" under PDF preview, if you wish to see preview.