[R-SIG-Mac] checking for pdflatex

Matt Denwood md at sund.ku.dk
Mon Mar 16 09:45:08 CET 2015


On 15 Mar 2015, at 23:21, John Fox <jfox at mcmaster.ca> wrote:

> Dear Ian,
> 
> Thanks for this. Please see below:
> 
>> -----Original Message-----
>> From: Ian Gow [mailto:iandgow at gmail.com]
>> Sent: March-15-15 5:07 PM
>> To: John Fox
>> Cc: r-sig-mac at 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.

This has been discussed on this forum before.  In a nutshell:  a (questionable) design decision from Apple over which R.app has no control!  For info:
http://tex.stackexchange.com/questions/208181/why-did-my-tex-related-gui-program-stop-working-in-mac-os-x-yosemite

> 
>> 
>>> 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.

I don’t think you can, although you can approximate this by setting the PATH to everywhere that pdflatex *might* be installed e.g.:

Sys.setenv(PATH=paste(Sys.getenv('PATH'),"/opt/local/bin:/opt/local/sbin:/usr/texbin:/usr/local/bin: …. etc …. ",sep=':’))    
Sys.which("pdflatex")

I realise that this is not an ideal solution, so somebody may have a better one.  You could also theoretically try parsing the .basrc / .profile files, but I’m not sure if this is recommended practice (i.e. the fact that these are not parsed automatically is supposed to be a security measure)???

Cheers,

Matt


> 
> 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 at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mac
> 
> 
> ---
> This email has been checked for viruses by Avast antivirus software.
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list