John: It might be useful to see how TeX editors (TeXShop, TeXWorks, Texpad, etc.) do this. I guess if there’s a way, these programs would use it.
Other software I have seen use a “look in all the usual locations” approach to solve a similar problem. Finally, I can find a few using locate. It seems I a few versions lying around on my computer: Mac-Pro:~ igow$ locate pdflatex | grep -e \/pdflatex$ /Volumes/mac_part/opt/local/bin/pdflatex /Volumes/mac_part/opt/local/libexec/texlive/texbin/pdflatex /Volumes/mac_part/usr/local/texlive/2011/bin/universal-darwin/pdflatex /Volumes/mac_part/usr/local/texlive/2011/bin/x86_64-darwin/pdflatex /opt/local/bin/pdflatex /opt/local/libexec/texlive/texbin/pdflatex But in fact, I probably just have two versions. In R: > pdftexs <- system(" locate pdflatex | grep -e \\/pdflatex$", intern=TRUE) > > get_version <- function(path) { + return(system(paste(path, " --version"), intern=TRUE)[1]) + } > > cbind(pdftexs, unlist(lapply(pdftexs, get_version))) pdftexs [1,] "/Volumes/mac_part/opt/local/bin/pdflatex" [2,] "/Volumes/mac_part/opt/local/libexec/texlive/texbin/pdflatex" [3,] "/Volumes/mac_part/usr/local/texlive/2011/bin/universal-darwin/pdflatex" [4,] "/Volumes/mac_part/usr/local/texlive/2011/bin/x86_64-darwin/pdflatex" [5,] "/opt/local/bin/pdflatex" [6,] "/opt/local/libexec/texlive/texbin/pdflatex" [1,] "pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014/MacPorts 2014_6)" [2,] "pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014/MacPorts 2014_6)" [3,] "pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011)" [4,] "pdfTeX 3.1415926-2.3-1.40.12 (TeX Live 2011)" [5,] "pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014/MacPorts 2014_6)" [6,] "pdfTeX 3.14159265-2.6-1.40.15 (TeX Live 2014/MacPorts 2014_6)" -Ian > On Mar 15, 2015, at 6:21 PM, John Fox <j...@mcmaster.ca> wrote: > > Dear Ian, > > Thanks for this. Please see below: > >> -----Original Message----- >> From: Ian Gow [mailto:iand...@gmail.com] >> Sent: March-15-15 5:07 PM >> To: John Fox >> Cc: r-sig-mac@r-project.org >> Subject: Re: [R-SIG-Mac] checking for pdflatex >> >> I think it's driven by the PATH variable, which appears to differ for me >> between RStudio and R from Terminal on the one hand and R.app on the >> other. > > Yes, I understand that, though I don't understand why there's a difference > in the path. > >> >>> Sys.getenv("PATH") >> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin" >>> Sys.which("pdflatex") >> pdflatex >> "" >> >> If I add >> >> Sys.setenv(PATH=paste(Sys.getenv("PATH"),"/opt/local/bin", sep=":")) >> >> to ~/.Rprofile then R.app finds pdflatex (from MacPorts in my case). >> >>> Sys.which("pdflatex") >> pdflatex >> "/opt/local/bin/pdflatex" >>> Sys.getenv("PATH") >> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/local/bin" > > The problem for me is to determine whether pdflatex is installed *without* > knowing in advance where it's installed. I haven't described the purpose of > this, and, in the interest of brevity, won't for the time-being, but it may > also prove necessary to determine where pdflatex resides. > > Best, > John > >> >> >> On 15 Mar 2015, at 16:46, John Fox wrote: >> >>> Dear list members, >>> >>> I need to determine whether pdflatex is installed and have been doing >>> that via Sys.which("pdflatex"). This works when R is run in a terminal >>> window (or in RStudio): >>> >>>> Sys.which("pdflatex") >>> pdflatex >>> "/usr/texbin/pdflatex" >>> >>> but not from R.app: >>> >>>> Sys.which("pdflatex") >>> pdflatex >>> "" >>> >>> The session info is the same in both cases: >>> >>> -------------- snip ---------------- >>> >>>> sessionInfo() >>> R version 3.1.3 (2015-03-09) >>> Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X >>> 10.10.2 (Yosemite) >>> >>> locale: >>> [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF- >> 8 >>> >>> attached base packages: >>> [1] stats graphics grDevices utils datasets methods base >>> >>> -------------- snip ---------------- >>> >>> Why is the result different? Is there a better way to check for the >>> presence of pdflatex? >>> >>> Any help would be appreciated. >>> >>> Thanks, >>> John >>> >>> ------------------------------------------------ >>> John Fox, Professor >>> McMaster University >>> Hamilton, Ontario, Canada >>> http://socserv.mcmaster.ca/jfox/ >>> >>> _______________________________________________ >>> R-SIG-Mac mailing list >>> R-SIG-Mac@r-project.org >>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac > > > --- > This email has been checked for viruses by Avast antivirus software. > http://www.avast.com _______________________________________________ R-SIG-Mac mailing list R-SIG-Mac@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac