Skip to content

Commit 09db6b2

Browse files
committed
revert 4307aed and fix #2302 by escaping % instead
1 parent 4307aed commit 09db6b2

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: knitr
22
Type: Package
33
Title: A General-Purpose Package for Dynamic Report Generation in R
4-
Version: 1.44.3
4+
Version: 1.44.4
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("Abhraneel", "Sarma", role = "ctb"),

NEWS.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Improved the error message to contain more specific information when YAML chunk options could not be parsed (thanks, @pedropark99, #2294).
66

7+
## MAJOR CHANGES
8+
9+
- 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).
10+
711
## BUG FIXES
812

913
- Special characters in the chunk option `fig.alt` are properly escaped now (thanks, @jay-sf, #2290).
@@ -14,16 +18,12 @@
1418

1519
- Add the necessary `\newline` to the last subfigure (thanks, @slrellison, rstudio/rmarkdown#2518).
1620

21+
- Percent signs (`%`) in LaTeX figure captions and short captions are properly escaped now (thanks, @s-u, #2302).
22+
1723
## MAJOR CHANGES
1824

1925
- `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).
2026

21-
- 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).
22-
23-
## MINOR CHANGES
24-
25-
- For R Markdown documents, figure output is now wrapped in raw `latex` blocks when the output is LaTeX code (thanks, @s-u, #2302).
26-
2727
# CHANGES IN knitr VERSION 1.44
2828

2929
## NEW FEATURES

R/hooks-latex.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ hook_plot_tex = function(x, options) {
146146
}
147147
scap = if (is.null(scap) || is.na(scap)) '' else sprintf('[%s]', scap)
148148
cap = if (cap == '') '' else sprintf(
149-
'\\caption%s{%s}%s\n', scap, cap,
149+
'\\caption%s{%s}%s\n', escape_percent(scap), escape_percent(cap),
150150
create_label(lab, if (mcap) c('-', fig.cur), latex = TRUE)
151151
)
152152
fig2 = sprintf('%s\\end{%s}\n', cap, options$fig.env)
@@ -192,6 +192,9 @@ hook_plot_tex = function(x, options) {
192192
)
193193
}
194194

195+
# % -> \%, but do not touch \%
196+
escape_percent = function(x) gsub('(?<!\\\\)%', '\\\\%', x, perl = TRUE)
197+
195198
.chunk.hook.tex = function(x, options) {
196199
ai = output_asis(x, options)
197200
col = if (!ai) paste0(

R/hooks-md.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ hook_plot_md = function(x, options) {
55
if (is.null(to <- pandoc_to()) || is_html_output(to))
66
return(hook_plot_md_base(x, options))
77
if ((options$fig.show == 'animate' || is_tikz_dev(options)) && is_latex_output())
8-
return(raw_latex(hook_plot_tex(x, options)))
8+
return(hook_plot_tex(x, options))
99
office_output = to %in% c('docx', 'pptx', 'rtf', 'odt')
1010
if (need_special_plot_hook(options)) {
1111
if (is_latex_output()) {
1212
# Pandoc < 1.13 does not support \caption[]{} so suppress short caption
1313
if (is.null(options$fig.scap)) options$fig.scap = NA
14-
return(raw_latex(hook_plot_tex(x, options)))
14+
return(hook_plot_tex(x, options))
1515
}
1616
if (office_output) {
1717
if (options$fig.align != 'default') {

0 commit comments

Comments
 (0)