File: utils.R

package info (click to toggle)
r-cran-tinytex 0.56-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 276 kB
  • sloc: sh: 13; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 1,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# for xfun::session_info('tinytex')
xfun_session_info = function() {
  try_null = function(...) tryCatch(..., error = function(e) NULL)
  version_info = function(cmd) try_null(system2(cmd, '--version', stdout = TRUE))
  tweak_path()
  pdftex_info = version_info('pdflatex')[1]

  info = if (is.null(pdftex_info)) {
    version_info('tectonic')[1]  # try tectonic engine?
  } else if (grepl('TeX Live', pdftex_info, fixed = TRUE)) {
    # we get more information on tlmgr in that case
    try_null(tlmgr_version('string'))
  } else {
    # for other distributions, e.g., MiKTeX-pdfTeX 4.8 (MiKTeX 21.8)
    xfun::grep_sub('^.*\\((.*)\\)$', '\\1', pdftex_info)
  }
  if (!length(info)) return(invisible(NULL))

  paste(c('LaTeX version used: ', paste0('  ', info)), collapse = '\n')
}

# read a file without warning, and discard lines with invalid characters to
# avoid warnings in the grep() family (invalid lines in log files should be safe
# to discard in this package, although it isn't so in general)
read_lines = function(...) {
  x = readLines(..., warn = FALSE)
  x[!validEnc(x)] = ''
  x
}