Skip to content

Commit

Permalink
when fonts are missing, latexmk() cannot install font packages automa…
Browse files Browse the repository at this point in the history
…tically because the relevant info is available in missfont.log instead of filename.log: https://d.cosx.org/d/419258/17
  • Loading branch information
yihui committed Mar 1, 2019
1 parent 843f8ed commit e84b573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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"),
Expand Down
23 changes: 18 additions & 5 deletions R/latex.R
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
})))
}

Expand All @@ -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()
Expand Down

0 comments on commit e84b573

Please sign in to comment.