From e84b5730a985feb39f52f2a1dc755454d6de3524 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Fri, 1 Mar 2019 11:08:30 -0600 Subject: [PATCH] when fonts are missing, latexmk() cannot install font packages automatically because the relevant info is available in missfont.log instead of filename.log: https://d.cosx.org/d/419258/17 --- DESCRIPTION | 2 +- R/latex.R | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ea09b9744..9b9dc950f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: tinytex Type: Package Title: Helper Functions to Install and Maintain 'TeX Live', and Compile 'LaTeX' Documents -Version: 0.10.7 +Version: 0.10.8 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person(family = "RStudio, Inc.", role = "cph"), diff --git a/R/latex.R b/R/latex.R index 7a16d2ea0..b8f3609d3 100644 --- a/R/latex.R +++ b/R/latex.R @@ -398,7 +398,8 @@ file_rename = function(from, to) { parse_packages = function( log, text = readLines(log), files = detect_files(text), quiet = rep(FALSE, 3) ) { - pkgs = character(); quiet = rep_len(quiet, length.out = 3); x = files + pkgs = character(); quiet = rep_len(quiet, length.out = 3) + x = unique(c(files, miss_font())) if (length(x) == 0) { if (!quiet[1]) message( 'I was unable to find any missing LaTeX packages from the error log', @@ -466,10 +467,7 @@ detect_files = function(text) { v = gsub(p, '\\1', z) if (length(v) == 0) return(v) if (!(p %in% r[1:4])) return(if (p == r[5]) 'epstopdf' else v) - if (p == r[4]) return(paste0(v, '.sty')) - i = !grepl('[.]', v) - v[i] = paste0(v[i], '[.](tfm|afm|mf|otf)') - v + if (p == r[4]) paste0(v, '.sty') else font_ext(v) }))) } @@ -478,6 +476,21 @@ parse_install = function(...) { tlmgr_install(parse_packages(...)) } +# check missfont.log and detect the missing font packages +miss_font = function() { + if (!file.exists(f <- 'missfont.log')) return() + on.exit(unlink(f), add = TRUE) + x = gsub('\\s*$', '', readLines(f)) + x = unique(gsub('.+\\s+', '', x)) + if (length(x)) font_ext(x) +} + +font_ext = function(x) { + i = !grepl('[.]', x) + x[i] = paste0(x[i], '[.](tfm|afm|mf|otf)') + x +} + # it should be rare that we need to manually run texhash texhash = function() { tweak_path()