Skip to content

Commit

Permalink
do not modify PATH under Mac; use kpsewhich() to find kpsewhich
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Aug 22, 2013
1 parent 90154fc commit d425711
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# CHANGES IN knitr VERSION 1.5

## MINOR CHANGES

- `knitr:::.onLoad()` no longer modifies the `PATH` variable when `/usr/texbin` is not in `PATH` under Mac OS

# CHANGES IN knitr VERSION 1.4

## NOTE
Expand Down
9 changes: 8 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ isFALSE = function(x) identical(x, FALSE)

## check latex packages; if not exist, copy them over to ./
test_latex_pkg = function(name, path) {
res = try(system(sprintf('kpsewhich %s.sty', name), intern = TRUE), silent = TRUE)
res = try(system(sprintf('%s %s.sty', kpsewhich(), name), intern = TRUE), silent = TRUE)
if (inherits(res, 'try-error') || !length(res)) {
warning("unable to find LaTeX package '", name, "'; will use a copy from knitr")
file.copy(path, '.')
Expand Down Expand Up @@ -518,3 +518,10 @@ set_html_dev = function() {
png(tempfile()); dev.off()
}, silent = TRUE), 'try-error')) 'svg' else 'png')
}

# locate kpsewhich especially for Mac OS because /usr/texbin may not be in PATH
kpsewhich = function() {
if (Sys.info()['sysname'] != 'Darwin' || !file.exists(x <- '/usr/texbin/kpsewhich')
|| nzchar(Sys.which('kpsewhich')))
'kpsewhich' else x
}
6 changes: 0 additions & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
.onLoad = function(lib, pkg) {
register_vignette_engines(pkg)
# add /usr/texbin to PATH for Mac OS
if (Sys.info()['sysname'] != 'Darwin') return()
if (!file_test('-d', texbin <- '/usr/texbin')) return()
path = strsplit(Sys.getenv('PATH'), ':')[[1L]]
if (texbin %in% path) return()
Sys.setenv(PATH = paste(c(path, texbin), collapse = ':'))
}

0 comments on commit d425711

Please sign in to comment.