Skip to content

Commit

Permalink
fix rstudio/bookdown#663: if a log file contains warnings, don't dele…
Browse files Browse the repository at this point in the history
…te it
  • Loading branch information
yihui committed Dec 20, 2018
1 parent eacaaf1 commit 7a889fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions 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.9.3
Version: 0.9.4
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 All @@ -20,4 +20,4 @@ URL: https://github.com/yihui/tinytex
BugReports: https://github.com/yihui/tinytex/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.0
RoxygenNote: 6.1.1
11 changes: 10 additions & 1 deletion R/latex.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ latexmk_emu = function(
on.exit({
files2 = exist_files(aux_files)
files3 = setdiff(files2, files1)
if (keep_log) files3 = setdiff(files3, logfile)
if (keep_log || latex_warning(logfile)) files3 = setdiff(files3, logfile)
if (clean) unlink(files3)
}, add = TRUE)

Expand Down Expand Up @@ -302,6 +302,15 @@ show_latex_error = function(file, logfile = gsub('[.]tex$', '.log', basename(fil
}
}

# whether a LaTeX log file contains warnings
latex_warning = function(file) {
if (!file.exists(file)) return(FALSE)
x = readLines(file, warn = FALSE)
if (length(i <- grep(r <- '^LaTeX Warning:', x)) == 0) return(FALSE)
warning(paste(c('LaTeX Warning(s):', gsub(r, ' ', x[i])), collapse = '\n'), call. = FALSE)
TRUE
}

# check the version of latexmk
check_latexmk_version = function() {
out = system2('latexmk', '-v', stdout = TRUE)
Expand Down

0 comments on commit 7a889fb

Please sign in to comment.