8

I am trying to use knitr in RStudio to make a pdf (using pdflatex/MiKTeX). I'm on a Windows 10 machine. This was working fine until I updated R, RStudio, and MikTeX this month (Feb 2021). I'm getting an error that says,

"Running pdflatex.exe on testdoc.tex...failed Error running C:/Users/myusername/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)"
OR C:/PROGRA~1/MiKTeX/miktex/bin/x64/pdflatex.exe

My file is named testdoc.Rnw and contains:

\documentclass{article}

\begin{document}
some text
\end{document}
  1. I have already uninstalled and reinstalled MiKTeX, R, and Rstudio trying both user and administrator. (All of my versions are current as of 2/19/2021)
  2. This problem occurs whether I use user or administrator mode.
  3. The path given in the error is the correct one.
  4. The paths when I type Sys.which("pdflatex") are correct.
  5. No Log file is created. It just gets to the part where it tries to run pdflatex and gives the error.
  6. I can build and view the .tex file that is generated using TeX Studio.
  7. My MiKTeX console is updated.
  8. I've selected "knitr" in my options and tried checking and unchecking most of the checkboxes. Closing and opening and restarting.

I would prefer not to switch to TinyTeX. I have tried every suggestion I could find in Rstudio and stack overflow posts. I have looked at log files. I notice I'm not the only one with this problem, but everyone else seems to have a different error number. Please help.

Here is the output from sessionInfo():

R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 16299)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.0.4 tools_4.0.4  

For my environment variables for "path" (and I have tried changing them at the system level) I have tried C:\PROGRA~1\MiKTeX\miktex\bin\x64\ and C:\Users\myusername\AppData\Local\Programs\MiKTeX\miktex\bin\x64\. I also tried running as both administrator and as my user. It seems to make no difference.

I did just notice based on a comment that Sys.which("pdftex") and Sys.which("pdflatex") both return the same thing and I don't know if it matters.

I can create a pdf using the tex file either in texstudio or in the command line. Here is the output from running it in the command line:

This is pdfTeX, Version 3.141592653-2.6-1.40.22 (MiKTeX 21.2)
entering extended mode
(testdoc.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18> xparse <2020-03-03>
(C:\Program Files\MiKTeX\tex/latex/base\article.cls
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
(C:\Program Files\MiKTeX\tex/latex/base\size10.clo))
(C:\Program Files\MiKTeX\tex/latex/graphics\graphicx.sty
(C:\Program Files\MiKTeX\tex/latex/graphics\keyval.sty)
(C:\Program Files\MiKTeX\tex/latex/graphics\graphics.sty
(C:\Program Files\MiKTeX\tex/latex/graphics\trig.sty)
(C:\Program Files\MiKTeX\tex/latex/graphics-cfg\graphics.cfg)
(C:\Program Files\MiKTeX\tex/latex/graphics-def\pdftex.def)))
(C:\Program Files\MiKTeX\tex/latex/graphics\color.sty
(C:\Program Files\MiKTeX\tex/latex/graphics-cfg\color.cfg))
(C:\Users\myusername\AppData\Roaming\MiKTeX\tex/latex/framed\framed.sty)
(C:\Program Files\MiKTeX\tex/latex/base\alltt.sty)
(C:\Users\myusername\AppData\Roaming\MiKTeX\tex/latex/upquote\upquote.sty)
(C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def)
No file testdoc.aux.
(C:\Program Files\MiKTeX\tex/context/base/mkii\supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (C:\Program Files\MiKTeX\tex/latex/epstopdf-pkg\epstopdf-base.sty) [1{C:/User
s/myusername/AppData/Local/MiKTeX/pdftex/config/pdftex.map}] (testdoc.aux) )<C:/Pro
gram Files/MiKTeX/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on testdoc.pdf (1 page, 12954 bytes).
Transcript written on testdoc.log.
johnjohn
  • 716
  • 2
  • 9
  • 17
  • do u you also have 'cygwin' installed on your machine? what is the output in the Terminal of `pdftex -version` – GWD Feb 22 '21 at 02:40
  • No I don't have cygwin (that I know of - there is file called cygwin.hpp in one of my R directories). From the command prompt: This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 21.1) – Ben Elizabeth Ward Feb 22 '21 at 20:42
  • Can u provide below my edit above the output of `sessionInfo()` as well as the Terminal outputs of `which pdftex` and some per infos like `perl -version` and `where perl` potentially `which perl` You can format it nicely in here by using backticks \` (attention NOT single quotes) for inline or triple backticks \`\`\` at the beginning and the end when copy/pasting blocks of code – GWD Feb 22 '21 at 23:18
  • @GWD Out of curiosity, why is Perl involved here? – CL. Feb 23 '21 at 09:06
  • Look "exit code -1073740791". https://stackoverflow.com/questions/49432873/process-finished-with-exit-code-1073740791-0xc0000409-pycharm https://tex.stackexchange.com/questions/397397/problem-using-python-package-with-miktex https://stackoverflow.com/questions/50562192/process-finished-with-exit-code-1073740791-0xc0000409-pycharm-error – sidcoder Feb 23 '21 at 13:31
  • 1
    @CL. I have seen a couple of times how pdflatex would go belly up when there were perl versions getting in each others way – GWD Feb 23 '21 at 16:02
  • @sidcoder I looked at that and at my pathtext. I see .COM;.EXE;.BAT;.CMD;.VBS;.JS;.JSE;.WSF;.WSH;.MSC I do not know if any of this matters, but maybe you could explain? – Ben Elizabeth Ward Feb 24 '21 at 15:32
  • @GWD I don't know if I have perl on my system (or if I do how I can find out). I went to the cmd prompt and typed `perl -v` and it wasn't recognized. Is there another thing I should look at? The only file I found searching that had "perl" was an R file for regular expressions. – Ben Elizabeth Ward Feb 24 '21 at 15:37
  • @BenElizabethWard - have you tried running `C:/Users/YOUR-YOUSER-NAME/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe path\to\your\file\testdoc.tex` in (your or an) external Terminal ie outside of the RStudio one? – GWD Feb 24 '21 at 19:38
  • @GWD I currently have everything set up to use the system install so I looked at `C:/Program Files/MiKTeX/miktex/bin/x64/pdflatex.exe` and it ran and returned `This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 21.1) **` Right now my MiKTeX isn't installed in my user directory. And this problem occurs whether I run as Admin or as Me. – Ben Elizabeth Ward Feb 24 '21 at 21:14
  • `which` and `where` do not seem to be Windows utilities (Command Prompt response: `'which' is not recognized as an internal or external command, operable program or batch file.`). Perhaps the comment suggesting using them is from someone on a Unix system. – randy Sep 11 '21 at 20:10

2 Answers2

0

Ok based on your input so far I would guess that you are witnessing a variation of this "issue" Latex Error: 'Sweave.sty' not found?.
So my first attempt would be to make MiKTeX aware of that additional texmf folder ie R_HOME/share/texmf via
its Admin Console: Settings -> Directories [Tab] clik the + sign and add that path there (as mentioned in the linked answer do not go further down the path than texmf - eg into tex folder or so from there).

I think this should at least give you the chance to > pdflatex testdoc.tex [this command in Terminal - under the assumption that you are in the folder containing testdoc.tex which RStudio should have created from testdoc.Rnw and pdlatex can be found via your PATH].

As far as the rest goes (ie making RStudio correctly knit a Sweave .Rnw doc without tinytex) from within RStudio via clicking 'Compile PDF' there - I do have a strong feeling tha you have discovered a bug there. I am just not fully sure which maintainers (the ones at RStudio or the one at MiKTeX) should be informed about it. Probably better idea ie more efficient to post it to the RStudio folks since they have more resources there that will get in touch with edocevoli (MiKTeX maintainer) in case it is on his side.

Respectively here is the dupe I was looking for ... https://tex.stackexchange.com/questions/582041/r-sweave-does-not-compile-to-pdf a rather unsatisfying temporary solution to downgrade MiKTeX and not update packages (potentially earliest version of this issue: https://tex.stackexchange.com/questions/582041/r-sweave-does-not-compile-to-pdf)

@Ben Elizabeth Ward - I created a ticket with RStudio linking (sort of reopening) to a prior issue connected to 'tinytex' - which is not involved here imo (see: #9019)

GWD
  • 1,387
  • 10
  • 22
-1

I have the same problem mentioned in the post. I personally use the following programs:

  1. Miktex and Tekmaker
  2. Work on W10
  3. R and R Studio

I also work with RSweave and it is not possible for me to use the "Compile PDF" button (with knitr) to generate the corresponding pdf file, but if the .tex file is created, however, if you open Textmaker and run the .tex file from there, it will successfully generate the pdf file.

The error shown in the console when trying to compile the pdf is:

Running error C: /Users/Daniel/AppData/Local/Programs/MiKTeX/miktex/bin/x64/pdflatex.exe (exit code -1073740791)

Otherwise, the commands Sys.which ("pdftex") and Sys.which ("pdflatex") show the correct paths.

I also tried reinstalling several times, to no avail. I will be installing an old version of Miktex, I will be informed of the results. '

(EDIT)

Hello, as I mentioned above, I will comment on the results.

I installed an old version of Miktex, specifically 20.10. The process was like this:

  1. I uninstalled Miktex (latest version)
  2. I rebooted
  3. I installed version 20.10
  4. I rebooted
  5. And it worked, I could generate my pdf files from Rstudio, using Rsweave.

Greetings, and I hope this solution will serve you (at least until they correct the error in future versions)

PS: I suppose it is a miktex error (I am not an expert on the subject), because while researching I came to the error that pdflatex.exe could not access the writing of log files, which are designated in Miktex. It was my experience, luck!

Daniel F
  • 11
  • 1