Add TeX path to R Studio - Ubuntu

不想你离开。 提交于 2019-12-07 09:48:46

问题


I'm having the same issue as this question:

When I open any .Rnw file, R Studio says that I have no TeX Distribution installed: I'm using Ubuntu 14.04 w/ Gnome and TeXLive 2014.

I include the line PATH=/usr/local/texlive/2014/bin:${PATH} in the Renviron.site file, which now looks like:

##                      Emacs please make this -*- R -*-
## empty Renviron.site for R on Debian
##
## Copyright (C) 2008 Dirk Eddelbuettel and GPL'ed
##
## see help(Startup) for documentation on ~/.Renviron and Renviron.site

# ## Example ~/.Renviron on Unix
# R_LIBS=~/R/library
# PAGER=/usr/local/bin/less

# ## Example .Renviron on Windows
# R_LIBS=C:/R/library
# MY_TCLTK="c:/Program Files/Tcl/bin"

# ## Example of setting R_DEFAULT_PACKAGES (from R CMD check)
# R_DEFAULT_PACKAGES='utils,grDevices,graphics,stats'
# # this loads the packages in the order given, so they appear on
# # the search path in reverse order.

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

However the problem persists. How can I fix this and run Sweave or knitR?


回答1:


If anyone faces the same problem, I opened R Studio and checked the pdflatex installation with

> Sys.which("pdflatex")
pdflatex 
  "" 

Which show that it is in fact empty, so I run the command Sys.getenv("PATH")to check the current PATH:

Sys.getenv("PATH")
[1]   "/usr/local/texlive/2014/bin:/usr/local/texlive/2014/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

To add my pdflatex Path, I had to find the pdflatex file on my texlive directory, which was /usr/local/texlive/2014/bin/x86_64-linux, then I added this to my current Path:

> Sys.setenv(PATH=paste(Sys.getenv("PATH"),"/usr/local/texlive/2014/bin/x86_64-linux",sep=":"))

And now it works perfectly

EDIT: the solution above works only for the open session and is only temporary, you have to run the code everytime you open a new session. I'm still trying to find a permanent solution




回答2:


see this page: Customizing Startup, modify this file /usr/lib/R/etc/Rprofile.site, and put your code in this file. It looks like a permanent solution maybe.

===

i saw this file /etc/environment is the same as the output of Sys.getenv("PATH"), so i think that sys.getenv("PATH") reads file /etc/environment.

Therefore the better way is to modify this file /etc/environment adding this code :/usr/local/texlive/2017/bin/x86_64-linux​.

after i did it, i tried source /etc/envronment and restarted Rstudio, but it didn't work.

Finally it makes sense after i restarted my ubuntu system. ^_^

I hope my poor English expression is clear enough.



来源:https://stackoverflow.com/questions/30601171/add-tex-path-to-r-studio-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!