Question

On Windows, how could I instruct R to call TeXlive instead of MikTeX?

I've got R set up on my Linux and Windows machines. On my Windows machines, I happen to have both MikTeX and TeXlive available. For reasons I won't go into I'd like R to call TeXlive. At this time, R is picking up MikTeX instead.

I'm guessing I would need to set TEXINPUTS inside my Renviron file, or something similar. But I haven't been able to find precise instructions online. Help will be appreciated.

UPDATE: Here are different things I tried: changing the order of TeXlive and MikTeX in the PATH. Removing MikTeX from the path. Neither worked, MikTeX is still being picked up.

I couldn't find the relevant documentation for R, but I did find some hints in the RStudio documentation, so I attempted to solve the problem within RStudio. I successfully defined the RSTUDIO_PDFLATEX environment variable:

Sys.getenv('RSTUDIO_PDFLATEX')
[1] "C:/texlive/2012/bin/win32"

[Reference: http://www.rstudio.com/ide/docs/authoring/latex_program?version=0.97.312&mode=desktop]

but MikTeX is still called upon.

Sys.which("pdflatex")
                                         pdflatex 
"C:\\PROGRA~2\\MIKTEX~1.9\\miktex\\bin\\pdflatex.exe" 

UPDATE 2: Another thing I've tried: While texlive is already on my PATH, just in case I added it from within R.

Sys.setenv("PATH" = paste(Sys.getenv("PATH"),"C:/texlive/2012/bin/win32",sep=":"))

I also tried to set the path to pdflatex as returned by Sys.which("pdflatex") with the following:

Sys.setenv(pdflatex="C:/texlive/2012/bin/win32")

as well as variants with PDFLATEX or "PDFLATEX", but that doesn't help. I have also removed everything from the path except the path to texlive:

Sys.setenv("PATH" = "C:/texlive/2012/bin/win32")

That gives me the desired path

Sys.which("pdflatex")
                                 pdflatex 
"C:\\texlive\\2012\\bin\\win32\\pdflatex.exe" 

However, running texi2dvi fails:

tools::texi2pdf(Out)
Error in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet,  : 
pdflatex is not available
Was it helpful?

Solution

I was confronted with the same issue in a similar project and spent some time understanding the tricks. The fact that MikTeX comes out selected even if you cleaned up the path results from the somewhat exasperating fact (especially for *nix-oriented devs like me and others) that on installing MikTeX, a fairly big number of Windows registry entries is set. The portable MikTeX (win32 only) distro is the sole exception to this. So if you do need MikTeX on board, my advice is just to do what I did:

  1. uninstall your current MikTeX distro
  2. cleanup the registry (ccleaner worked out well)
  3. install the portable win32 MikTeX distro

Now check that your path does include your TeXlive bin directory path again.
If you use pandoc for creating pdf files from Rmarkdown or other markdown languages, a convenient way to work around path issues is to specify the --latex-engine option and add the full filepath as an argument. Below is a possible command line, adapted from the RStudio IDE:
path/to/pandoc.exe -V papersize=A4 +RTS -K512m -RTS file.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output file.pdf --template path/to/default.tex --highlight-style tango --latex-engine /path/to/pdflatex.exe --variable geometry:margin=1in

OTHER TIPS

I'm pretty sure you need to add paths here in your global environment variables. See: http://statmath.wu.ac.at/software/R/qfin/ and http://www.howtogeek.com/51807/how-to-create-and-use-global-system-environment-variables/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top