Skip to content

Commit

Permalink
pin the CTAN mirror by default after installing TinyTeX, instead of u…
Browse files Browse the repository at this point in the history
…sing the random mirror picked by mirror.ctan.org
  • Loading branch information
yihui committed Apr 14, 2022
1 parent c3a71c7 commit 626949f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinytex
Type: Package
Title: Helper Functions to Install and Maintain TeX Live, and Compile LaTeX Documents
Version: 0.38.1
Version: 0.38.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person(family = "RStudio, PBC", role = "cph"),
Expand Down
17 changes: 14 additions & 3 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#' via \code{xfun::github_releases('yihui/tinytex-releases')}). By default, it
#' installs the latest daily build of TinyTeX. If \code{version = 'latest'},
#' it installs the latest Github release of TinyTeX.
#' @param repository The CTAN repository to set. You can find available
#' @param repository The CTAN repository to set. By default, it is the
#' repository automatically chosen by \code{https://mirror.ctan.org} (which is
#' usually the fastest one to your location). You can find available
#' repositories at \code{https://ctan.org/mirrors}), e.g.,
#' \code{'http://mirrors.tuna.tsinghua.edu.cn/CTAN/'}, or
#' \code{'https://mirror.las.iastate.edu/tex-archive/'}. In theory, this
Expand All @@ -29,7 +31,7 @@
#' for the default installation directories on different platforms.
#' @export
install_tinytex = function(
force = FALSE, dir = 'auto', version = 'daily', repository = 'ctan',
force = FALSE, dir = 'auto', version = 'daily', repository = 'auto',
extra_packages = if (is_tinytex()) tl_pkgs(), add_path = TRUE
) {
if (!is.logical(force)) stop('The argument "force" must take a logical value.')
Expand All @@ -48,9 +50,9 @@ install_tinytex = function(
user_dir = normalizePath(dir, mustWork = FALSE)
}

https = grepl('^https://', repository)
repository = normalize_repo(repository)
not_ctan = repository != 'ctan'
https = grepl('^https://', repository)

owd = setwd(tempdir()); on.exit(setwd(owd), add = TRUE)

Expand Down Expand Up @@ -129,6 +131,7 @@ need_source_install = function() {
normalize_repo = function(url) {
# don't normalize the url if users passes I(url) or 'ctan' or NULL
if (is.null(url) || url == 'ctan' || inherits(url, 'AsIs')) return(url)
if (url == 'auto') return(auto_repo())
url = sub('/+$', '', url)
if (!grepl('/tlnet$', url)) {
url2 = paste0(url, '/systems/texlive/tlnet')
Expand All @@ -138,6 +141,14 @@ normalize_repo = function(url) {
url
}

# get the automatic CTAN mirror returned from mirror.ctan.org
auto_repo = function() {
x = curlGetHeaders('https://mirror.ctan.org/systems/texlive/tlnet')
x = xfun::grep_sub('^location: ([^[:space:]]+)\\s*$', '\\1', x)
x = tail(x, 1)
if (length(x) == 1) x else 'ctan'
}

win_app_dir = function(..., error = TRUE) {
d = Sys.getenv('APPDATA')
if (d == '') {
Expand Down
8 changes: 5 additions & 3 deletions man/install_tinytex.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 626949f

Please sign in to comment.