Skip to content

Commit 71ab9c4

Browse files
claude: Fix image alt text propagation to LaTeX for PDF accessibility
Preserve markdown image captions and fig-alt attributes as alt text for \includegraphics[alt={...}] in LaTeX output. This enables PDF/UA compliance by ensuring alt text is embedded in the PDF. The fix preserves image captions as the alt attribute before clearing them for figure handling. Also propagates fig-alt from FloatRefTarget to Image elements for LaTeX output. Closes #13248 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ecdb3a9 commit 71ab9c4

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

news/changelog-1.9.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ All changes included in 1.9:
4545

4646
- ([#4426](https://github.com/quarto-dev/quarto-cli/issues/4426)): Add `pdf-standard` option for PDF/A, PDF/UA, and PDF version control. Supports standards like `a-2b`, `ua-1`, and versions `1.7`, `2.0`. Works with both LaTeX and Typst formats.
4747
- ([#10291](https://github.com/quarto-dev/quarto-cli/issues/10291)): Fix detection of babel hyphenation warnings with straight-quote format instead of backtick-quote format.
48+
- ([#13248](https://github.com/quarto-dev/quarto-cli/issues/13248)): Fix image alt text not being passed to LaTeX `\includegraphics[alt={...}]` for PDF accessibility. Markdown image captions and `fig-alt` attributes are now preserved for PDF/UA compliance.
4849
- ([#13661](https://github.com/quarto-dev/quarto-cli/issues/13661)): Fix LaTeX compilation errors when using `mermaid-format: svg` with PDF/LaTeX output. SVG diagrams are now written directly without HTML script tags. Note: `mermaid-format: png` is recommended for best compatibility. SVG format requires `rsvg-convert` (or Inkscape with `use-rsvg-convert: false`) in PATH for conversion to PDF, and may experience text clipping in diagrams with multi-line labels.
4950
- ([rstudio/tinytex-releases#49](https://github.com/rstudio/tinytex-releases/issues/49)): Fix detection of LuaTeX-ja missing file errors by matching both "File" and "file" in error messages.
5051
- ([#13667](https://github.com/quarto-dev/quarto-cli/issues/13667)): Fix LaTeX compilation error with Python error output containing caret characters.

src/resources/filters/layout/latex.lua

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ function latexCell(cell, vAlign, endOfRow, endOfTable)
332332
-- see if it's a captioned figure
333333
if image and #image.caption > 0 then
334334
caption = image.caption:clone()
335+
-- preserve caption as alt attribute for PDF accessibility before clearing
336+
if not image.attributes["alt"] then
337+
image.attributes["alt"] = pandoc.utils.stringify(image.caption)
338+
end
335339
tclear(image.caption)
336340
elseif tbl then
337341
caption = pandoc.utils.blocks_to_inlines(tbl.caption.long)
@@ -380,6 +384,10 @@ function latexCell(cell, vAlign, endOfRow, endOfTable)
380384
if image and #image.caption > 0 then
381385
local caption = image.caption:clone()
382386
markupLatexCaption(cell, caption)
387+
-- preserve caption as alt attribute for PDF accessibility before clearing
388+
if not image.attributes["alt"] then
389+
image.attributes["alt"] = pandoc.utils.stringify(image.caption)
390+
end
383391
tclear(image.caption)
384392
content:insert(pandoc.RawBlock("latex", "\\raisebox{-\\height}{"))
385393
content:insert(pandoc.Para(image))
@@ -658,9 +666,13 @@ end
658666
function latexImageFigure(image)
659667

660668
return renderLatexFigure(image, function(figure)
661-
669+
662670
-- make a copy of the caption and clear it
663671
local caption = image.caption:clone()
672+
-- preserve caption as alt attribute for PDF accessibility before clearing
673+
if #image.caption > 0 and not image.attributes["alt"] then
674+
image.attributes["alt"] = pandoc.utils.stringify(image.caption)
675+
end
664676
tclear(image.caption)
665677

666678
-- get align

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ end
3838
return float
3939
end
4040
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
44+
float.content = _quarto.ast.walk(float.content, {
45+
Image = function(image)
46+
image.attributes["alt"] = altText
47+
return image
48+
end
49+
})
50+
float.attributes[kFigAlt] = nil
51+
end
4152
return forward_pos_and_env(float)
4253
end
4354
end,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: "UA-1 image with alt text"
3+
lang: en
4+
pdf-standard: ua-1
5+
keep-tex: true
6+
_quarto:
7+
tests:
8+
pdf:
9+
noErrors: default
10+
ensureLatexFileRegexMatches:
11+
# Alt text MUST be passed to \includegraphics[alt={...}] for PDF/UA
12+
- ['\\DocumentMetadata\{', 'pdfstandard=\{ua-1\}', 'tagging=on', 'includegraphics\[.*alt=']
13+
- []
14+
printsMessage:
15+
# Should NOT warn about missing alt text since we provided it
16+
level: WARN
17+
regex: "PDF accessibility:.*Missing alt text"
18+
negate: true
19+
---
20+
21+
# Test Document
22+
23+
This image has alt text which should be passed through to LaTeX's `\includegraphics[alt={...}]` for PDF/UA compliance.
24+
25+
![Test image description](test-image.png)

0 commit comments

Comments
 (0)