NEW FEATURES
-
Added a new chunk option
fig.noteto add a note (e.g., a source or explanatory note) below a figure, separate from its caption (thanks, @turbanisch, #2022). It works for LaTeX/PDF, HTML, and Typst output. For LaTeX, the note is emitted via a\figurenote{}command inside the figure environment; a default definition is provided (footnotesize italic) that you may override in the preamble, e.g.,\newcommand{\figurenote}[1]{\floatfoot{#1}}(with the floatrow package). For HTML, the note is placed in<p class="figure-note">inside the figure<div>, which you can style with CSS. -
Added support for a new input format
.Rtypfor the Typst typesetting system (thanks, @blset #2401, @aksigkvgithub #2283). You can use code chunks and inline R expressions in.Rtypfiles, knit them viaknitr::knit()to.typoutput, or compile to PDF directly viaknit2pdf('input.Rtyp'). See https://github.com/yihui/knitr-examples/blob/master/128-minimal.Rtyp for a minimal example. -
Added a
knitr::rtypvignette engine to build.Rtypvignettes to PDF via Typst, so packages no longer need to register their own engine for this purpose (thanks, @ggrothendieck, #2447). -
hook_plot_tex()now respects the chunk optionanimation.hook(or the package optionanimation.fun) when it is set to a function of your own, and calls it to generate the LaTeX code for a chunk withfig.show = 'animate'instead of the default\animategraphics{}. This makes the LaTeX plot hook extensible in the same way ashook_plot_html(), which has always supported these options, and allows for LaTeX packages other than animate to be used for animations, e.g. xmpmulti for beamer overlays. The built-in hooks such ashook_ffmpeg_html()generate HTML and continue to be ignored for LaTeX output, so this does not change the output of existing documents (thanks, @jolars #2452). -
Added support for
ragg::agg_webp()as a graphics device for WebP output (thanks, @heavywatal, #2434). To use this device, setdev = 'agg_webp'in the chunk options. This device is available in ragg >= 1.5.0. -
The chunk option
dev.argscan now customize thedev = 'gridSVG'device. Arguments are passed to bothgrDevices::svg()(e.g.,pointsize) andgridSVG::grid.export()(e.g.,strict), with each function receiving only the arguments it recognizes (thanks, @deepayan, #2450, #2451).
BUG FIXES
-
Figure captions are no longer dropped when a single chunk produces multiple captioned figures for Markdown-based output (e.g., HTML or PDF via Pandoc). Previously, consecutive images were emitted in one paragraph (
 ), which Pandoc treats as inline images and renders without captions. knitr now inserts a blank line after each captioned figure except the last, so Pandoc emits a separate figure (with caption) for each image (thanks, @atusy, #2032, #1524, #1760). -
knitr now emits a warning when a code chunk opens a new graphics device (e.g., via
dev.new()), because plots drawn on such devices cannot be captured by knitr and will silently fail to render in the output (thanks, @Higgs32584, #2355). -
include_graphics()now converts absolute paths to paths relative to the output directory of the rendered document (communicated by rmarkdown >= 2.32 viaopts_knit$get('rmarkdown.output_dir')) instead of knitr's working directory (the input directory), which fixes broken image paths when the input and output directories differ (e.g., rendering to a differentoutput_dir). The existence check (whenerror = TRUE) also uses the original path so that it no longer reports false negatives whenroot.dirdiffers from the output directory (thanks, @naikymen @jameelalsalam @cderv, #2171, r-lib/pkgdown#2334). -
kable()now escapes special characters (e.g.,&) in thecaptionargument for LaTeX and HTML output whenescape = TRUE(the default), just as it does for cell content and column names. Previously, an unescaped&in a caption could cause a fatal LaTeX compilation error (! Misplaced alignment tab character &.) (thanks, @mbs2016, #2436). -
The
altattribute of figure images now has HTML tags stripped (viaxfun::strip_html()) and is properly escaped for use in HTML attributes (viaxfun::html_escape(attr = TRUE)). Previously, HTML infig.cap(e.g., a link) could appear verbatim inalt, and double quotes in captions could break thealtattribute value (thanks, @cderv, #2004). -
knit2html()now renders the HTML next to the knitted Markdown and then moves it to the output location when the output is written to a different directory, so local figure resources can still be found and embedded (previously they broke with warnings likeFile 'figure/...png' not found). For more robust rendering of R Markdown to HTML, considerlitedown::fuse()instead (thanks, @LeonidasZhak, #2408). -
Due to a change in Asymptote, the output file may not be recognized or included correctly (thanks, @DeliciousRoastPotato @shangeconnew, #2025).
-
has_crop_tools()should not throw an error whentlmgrexists but cannot be executed (thanks, @lsandig, rstudio/rmarkdown#2612). It returnsFALSEnow. -
Fixed invalid LaTeX when warning/message/error is the only chunk output in Rnw documents (thanks, @codeZeilen, #2412).
-
Fixed a bug that calling
knit_exit()could putknit()in a non-functioning state when there is only a single code chunk in the input (thanks, @dlampart, #2372).
MAJOR CHANGES
knit2html()(and other functions that render Markdown to HTML, such asstitch(),knit_rd(),knit2wp(),rocco(), and theknitr::knitrvignette engine) now uselitedown::mark()directly instead ofmarkdown::mark_html(). The markdown package (>= 1.3) has become a thin wrapper of litedown, so this removes the markdown dependency (litedown is used instead) without changing the HTML output. For R packages that rely on theknitr::knitrvignette engine, theDESCRIPTIONfile needs to declarelitedownas a dependency (typically inSuggests) instead ofmarkdown.