Skip to content

Commit ffa7d39

Browse files
claude: fix fig-alt not propagated to Typst image alt text (#14108)
The fig-alt attribute on computed figures (R/Python code chunks) was not being propagated to Typst's image(alt: "...") parameter, causing PDF/UA-1 validation failures. The propagation logic in figures.lua only handled HTML and LaTeX outputs. Refactored to make fig-alt propagation format-agnostic so it works for Typst and any future formats. Closes #14108 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9e9160b commit ffa7d39

2 files changed

Lines changed: 44 additions & 13 deletions

File tree

‎src/resources/filters/quarto-pre/figures.lua‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@ end
2828
return
2929
end
3030

31-
-- propagate fig-alt
32-
if _quarto.format.isHtmlOutput() then
33-
-- read the fig-alt text and set the image alt
34-
local altText = attribute(float, kFigAlt, nil)
35-
if altText ~= nil then
31+
-- propagate fig-alt to Image elements for accessibility
32+
local altText = attribute(float, kFigAlt, nil)
33+
if altText ~= nil then
34+
if _quarto.format.isHtmlOutput() then
35+
-- HTML: set alt on the float itself
3636
float.attributes["alt"] = altText
37-
float.attributes[kFigAlt] = nil
38-
return float
39-
end
40-
elseif _quarto.format.isLatexOutput() then
41-
-- propagate fig-alt to Image elements for LaTeX (enables \includegraphics[alt={...}])
42-
local altText = attribute(float, kFigAlt, nil)
43-
if altText ~= nil then
37+
else
38+
-- LaTeX, Typst, and other formats: propagate to Image elements
39+
-- (enables \includegraphics[alt={...}] for LaTeX, image(alt: "...") for Typst)
4440
float.content = _quarto.ast.walk(float.content, {
4541
Image = function(image)
4642
image.attributes["alt"] = altText
4743
return image
4844
end
4945
})
50-
float.attributes[kFigAlt] = nil
5146
end
47+
float.attributes[kFigAlt] = nil
48+
end
49+
50+
if _quarto.format.isLatexOutput() then
5251
return forward_pos_and_env(float)
5352
end
53+
54+
if altText ~= nil then
55+
return float
56+
end
5457
end,
5558
Figure = function(figure)
5659
if _quarto.format.isLatexOutput() then
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Typst fig-alt propagation for computed figures"
3+
format:
4+
typst:
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
typst:
9+
noErrors: default
10+
ensureTypstFileRegexMatches:
11+
- # Patterns that MUST be found - fig-alt propagated to image(alt: ...)
12+
- 'image\("typst-fig-alt-propagation_files/figure-typst/fig-test-plot-1\.svg",\s*alt:\s*"Scatter plot showing speed versus stopping distance from the cars dataset"'
13+
- # Patterns that must NOT be found
14+
[]
15+
---
16+
17+
## Computed figure with fig-alt
18+
19+
This tests that `fig-alt` on code chunks is propagated to Typst's `image(alt: ...)` parameter.
20+
21+
```{r}
22+
#| label: fig-test-plot
23+
#| fig-cap: "A plot of the cars dataset"
24+
#| fig-alt: "Scatter plot showing speed versus stopping distance from the cars dataset"
25+
plot(cars)
26+
```
27+
28+
See @fig-test-plot.

0 commit comments

Comments
 (0)