quarto-dev / quarto-dev/quarto-cli

animation.hook is ignored for LaTeX output in the knitr engine

Open
#14,814 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

engines-knitr enhancement figures latex
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

The animation.hook chunk option works for HTML output but has no effect for LaTeX/PDF output.

For a chunk with fig.show: animate, we only inject a default hook when the format is not LaTeX

https://github.com/quarto-dev/quarto-cli/blob/d4cb49f1e70fb34e4cdf38edbb2f938c3ce7cc21/src/resources/rmd/hooks.R#L115-L126

The HTML branch then delegates to knitr's hook_animation(), so a user-supplied hook is honored there. The LaTeX branch instead calls our own latex_animation(), which always emits \animategraphics{} and never looks at animation.hook

https://github.com/quarto-dev/quarto-cli/blob/d4cb49f1e70fb34e4cdf38edbb2f938c3ce7cc21/src/resources/rmd/hooks.R#L1170-L1206

It also adds a dependency on the LaTeX animate package unconditionally

https://github.com/quarto-dev/quarto-cli/blob/d4cb49f1e70fb34e4cdf38edbb2f938c3ce7cc21/src/resources/rmd/hooks.R#L713-L718

Upstream knitr changed this in yihui/knitr#2452: hook_plot_tex() now calls a user-supplied animation.hook (or the package option animation.fun) to generate the LaTeX code, so LaTeX packages other than animate can be used, xmpmulti for beamer overlays being the motivating example. The built-in hooks (ffmpeg, gifski, scianimator, r2swf) generate HTML and keep being ignored for LaTeX. Our latex_animation() is a port of knitr's code from before that change.

So with the next knitr release this will work in .Rmd but not in .qmd.

We could port the same logic into latex_animation(): when animation.hook is a function and is not one of knitr's built-in HTML hooks, call it instead of emitting \animategraphics{}, and skip the animate dependency in that case.

Two things to sort out if we do this. Our schema documents animation-hook with default: ffmpeg while we actually inject gifski for non-LaTeX output, and it is typed as a string with completions, so a function can only be passed with the classic R chunk syntax ({r, animation.hook=my_hook}) and not with #| YAML.

https://github.com/quarto-dev/quarto-cli/blob/d4cb49f1e70fb34e4cdf38edbb2f938c3ce7cc21/src/resources/schema/cell-figure.yml#L219-L235

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/resources/rmd/hooks.R, especially latex_animation(), the animation dependency handling, and the linked hook setup; then inspect src/resources/schema/cell-figure.yml. Compare the current logic with knitr's hook_plot_tex() behavior. Done means a non-built-in animation.hook is honored for LaTeX/PDF output and the animate dependency is not added when that hook supplies the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, r
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.