Skip to content

knitr 1.52

Latest

Choose a tag to compare

@yihui yihui released this 06 Sep 20:02
· 1 commit to master since this release

NEW FEATURES

  • Added a new chunk option fig.note to 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 .Rtyp for the Typst typesetting system (thanks, @blset #2401, @aksigkvgithub #2283). You can use code chunks and inline R expressions in .Rtyp files, knit them via knitr::knit() to .typ output, or compile to PDF directly via knit2pdf('input.Rtyp'). See https://github.com/yihui/knitr-examples/blob/master/128-minimal.Rtyp for a minimal example.

  • Added a knitr::rtyp vignette engine to build .Rtyp vignettes 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 option animation.hook (or the package option animation.fun) when it is set to a function of your own, and calls it to generate the LaTeX code for a chunk with fig.show = 'animate' instead of the default \animategraphics{}. This makes the LaTeX plot hook extensible in the same way as hook_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 as hook_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, set dev = 'agg_webp' in the chunk options. This device is available in ragg >= 1.5.0.

  • The chunk option dev.args can now customize the dev = 'gridSVG' device. Arguments are passed to both grDevices::svg() (e.g., pointsize) and gridSVG::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 (![cap1](a) ![cap2](b)), 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 via opts_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 different output_dir). The existence check (when error = TRUE) also uses the original path so that it no longer reports false negatives when root.dir differs from the output directory (thanks, @naikymen @jameelalsalam @cderv, #2171, r-lib/pkgdown#2334).

  • kable() now escapes special characters (e.g., &) in the caption argument for LaTeX and HTML output when escape = 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 alt attribute of figure images now has HTML tags stripped (via xfun::strip_html()) and is properly escaped for use in HTML attributes (via xfun::html_escape(attr = TRUE)). Previously, HTML in fig.cap (e.g., a link) could appear verbatim in alt, and double quotes in captions could break the alt attribute 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 like File 'figure/...png' not found). For more robust rendering of R Markdown to HTML, consider litedown::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 when tlmgr exists but cannot be executed (thanks, @lsandig, rstudio/rmarkdown#2612). It returns FALSE now.

  • 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 put knit() 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 as stitch(), knit_rd(), knit2wp(), rocco(), and the knitr::knitr vignette engine) now use litedown::mark() directly instead of markdown::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 the knitr::knitr vignette engine, the DESCRIPTION file needs to declare litedown as a dependency (typically in Suggests) instead of markdown.