Add tex distribution to PATH for R studio

2019-05-06 07:00发布

问题:

I have recently begun using knitr with Rstudio. I ran into the "No tex installation detected. Please install TeX before compiling." error in both my Ubuntu and windows OS's.

After some research I was able to amend the issue in Ubuntu by adding the directory of my tex installation to PATH. I did this by including the following line in Renviron.site

PATH=/usr/local/texlive/2013/bin:${PATH}

However, the issue remains for my windows installation. I was unable to find the Renviron.site file, so I created one in the same directory of Renviron, and added the location of my tex installation in windows:

PATH=C:\texlive\2013\bin\win32:${PATH}

However this does not solve my problem and Rstudio is still unable to find my tex packages, such that

file.exists(Sys.which('texi2dvi'))

Returns FALSE.

How should I proceed?

回答1:

R will always source the Rprofile.site file first. On Windows, the file is in the C:\Program Files\R\R-n.n.n\etc directory.

see here: Add TeX path to R Studio - Ubuntu and here: Customizing Startup



回答2:

I found package tinytex to be of interest. It allows to install a minimal tex distrib without administrator privilege, takes care of path, and useful function to add missing tex packages. Works well with knitr

It is written by Xie Yihui author of knitr.



回答3:

Let me build up to @HeavenZone's answer:

You should go onto

C:\Program Files\R\R-n.n.n\etc

directory and give permissions to modify the files in on the folder. This can be done by doing

Right click->Properties->Security->Edit->Select Users->In Permissions list tick->Write

Once you're done you should open the file Renviron.site on the directory etc. And add a line like

PATH=C:\Program Files\MiKTeX 2.9\miktex\bin\64:${PATH}

I wrote a new line, assume that the definitions are concatenated. Perhaps you need also \pdflatex.exe in the above path.

Once you have this, restart Rstudio and it should grasp now the latex distribution.

I would probably change the title of this question to include that this is the Windows version so that it is easy to look for it, however my edit was rejected so I leave it to someone else...