diff --git a/DESCRIPTION b/DESCRIPTION index 0bad23d015..6ed70ae0f8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: knitr Type: Package Title: A General-Purpose Package for Dynamic Report Generation in R -Version: 1.44.3 +Version: 1.44.4 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Abhraneel", "Sarma", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index aa4e0e178c..6761764471 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,10 @@ - Improved the error message to contain more specific information when YAML chunk options could not be parsed (thanks, @pedropark99, #2294). +## MAJOR CHANGES + +- The object `opts_current` will be restored after each code chunk has finished executing. Previously, it would not be restored, which means even for inline R expressions, `opts_current$get()` will inherit chunk options from a previous code chunk (thanks, @rundel, #1988). Besides, `opts_current$get('label')` will return a unique label for inline expressions. One possible application is to construct unique figure paths via `fig_path()` (e.g., ropensci/magick#310). + ## BUG FIXES - Special characters in the chunk option `fig.alt` are properly escaped now (thanks, @jay-sf, #2290). @@ -14,16 +18,12 @@ - Add the necessary `\newline` to the last subfigure (thanks, @slrellison, rstudio/rmarkdown#2518). +- Percent signs (`%`) in LaTeX figure captions and short captions are properly escaped now (thanks, @s-u, #2302). + ## MAJOR CHANGES - `opts_current$set()` without `opts_current$lock(FALSE)` will trigger a warning instead of an error for now and it will become an error in future (#2296). -- The object `opts_current` will be restored after each code chunk has finished executing. Previously, it would not be restored, which means even for inline R expressions, `opts_current$get()` will inherit chunk options from a previous code chunk (thanks, @rundel, #1988). Besides, `opts_current$get('label')` will return a unique label for inline expressions. One possible application is to construct unique figure paths via `fig_path()` (e.g., ropensci/magick#310). - -## MINOR CHANGES - -- For R Markdown documents, figure output is now wrapped in raw `latex` blocks when the output is LaTeX code (thanks, @s-u, #2302). - # CHANGES IN knitr VERSION 1.44 ## NEW FEATURES diff --git a/R/hooks-latex.R b/R/hooks-latex.R index 2beb8d741d..4c2964df61 100644 --- a/R/hooks-latex.R +++ b/R/hooks-latex.R @@ -146,7 +146,7 @@ hook_plot_tex = function(x, options) { } scap = if (is.null(scap) || is.na(scap)) '' else sprintf('[%s]', scap) cap = if (cap == '') '' else sprintf( - '\\caption%s{%s}%s\n', scap, cap, + '\\caption%s{%s}%s\n', escape_percent(scap), escape_percent(cap), create_label(lab, if (mcap) c('-', fig.cur), latex = TRUE) ) fig2 = sprintf('%s\\end{%s}\n', cap, options$fig.env) @@ -192,6 +192,9 @@ hook_plot_tex = function(x, options) { ) } +# % -> \%, but do not touch \% +escape_percent = function(x) gsub('(?