Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2302: wrap figure output in raw latex blocks for Markdown output #2303

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

- 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).
Expand All @@ -22,6 +18,12 @@

- `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
Expand Down
4 changes: 2 additions & 2 deletions R/hooks-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ hook_plot_md = function(x, options) {
if (is.null(to <- pandoc_to()) || is_html_output(to))
return(hook_plot_md_base(x, options))
if ((options$fig.show == 'animate' || is_tikz_dev(options)) && is_latex_output())
return(hook_plot_tex(x, options))
return(raw_latex(hook_plot_tex(x, options)))
office_output = to %in% c('docx', 'pptx', 'rtf', 'odt')
if (need_special_plot_hook(options)) {
if (is_latex_output()) {
# Pandoc < 1.13 does not support \caption[]{} so suppress short caption
if (is.null(options$fig.scap)) options$fig.scap = NA
return(hook_plot_tex(x, options))
return(raw_latex(hook_plot_tex(x, options)))
}
if (office_output) {
if (options$fig.align != 'default') {
Expand Down