Skip to content

Conversation

@mcanouil
Copy link
Contributor

@mcanouil mcanouil commented Jan 10, 2026

Introduce support for alt text in images within the Typst writer, enhancing accessibility.
Behaviour is by design consistent with LaTeX and HTML writers.

TO-DO: Check if the following files need to account for alt as well

  • test/command/9945.md this might now get an alternative-text not expected at the time.

echo '![Caption "some title"](image.png){alt="Alt text describing the image"}' | pandoc -f markdown -t typst
echo '![](image.png){alt="Alt text describing the image"}' | pandoc -f markdown -t typst

This was identified in Quarto CLI that the alt-text was not forwarded.

Resolves quarto-dev/quarto-cli#13868

@mcanouil mcanouil force-pushed the feat/typst-image-alt-text branch from cf221db to 9b0df51 Compare January 10, 2026 21:44
@mcanouil
Copy link
Contributor Author

As expected, the old test now breaks because it is missing the alt-text generated similarly to LateX and HTML

2026-01-10T22:52:08.1982438Z     9236.md
2026-01-10T22:52:08.2923875Z       #1:                                                                                      FAIL (0.01s)
2026-01-10T22:52:08.2924508Z         --- test/command/9236.md
2026-01-10T22:52:08.2924933Z         +++ pandoc -t typst
2026-01-10T22:52:08.2925448Z         +   1 #figure(image("command/minimal.svg", alt: "minimal", width: 3in),
2026-01-10T22:52:08.2926050Z         -   1 #figure(image("command/minimal.svg", width: 3in),
2026-01-10T22:52:08.2926503Z         +   7 #figure(image("command/minimal.svg", alt: "minimal", height: 2in, width: 3in),
2026-01-10T22:52:08.2926997Z         -   7 #figure(image("command/minimal.svg", height: 2in, width: 3in),
2026-01-10T22:52:08.2927403Z         +  13 #figure(image("command/minimal.svg", alt: "minimal"),
2026-01-10T22:52:08.2927754Z         -  13 #figure(image("command/minimal.svg"),
2026-01-10T22:52:08.2928036Z         +  19 And inline:
2026-01-10T22:52:08.2928450Z         +  20 #box(image("command/minimal.svg", alt: "minimal", height: 2in)) and
2026-01-10T22:52:08.2929232Z         +  21 #box(image("command/minimal.svg", alt: "minimal")).
2026-01-10T22:52:08.2929625Z         -  19 And inline: #box(image("command/minimal.svg", height: 2in)) and
2026-01-10T22:52:08.2929994Z         -  20 #box(image("command/minimal.svg")).
2026-01-10T22:52:08.2930261Z         
2026-01-10T22:52:08.2930499Z         Use -p '/9236.md.#1/' to rerun this test only.

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented Jan 11, 2026

I can't seem to make a suggested edit due to the content being markdown.

We discovered a couple other test cases in my version of this.


```
% pandoc -f markdown -t typst
![Caption](test.png){alt="A \"quoted\" phrase and C:\\path\\file"}
^D
#figure(image("test.png", alt: "A \"quoted\" phrase and C:\\path\\file"),
  caption: [
    Caption
  ]
)

```

```
% pandoc -f html -t typst
<img src="data:image/png;base64,iVBORw0KGgo=" alt="A small red dot">
^D
#box(image.decode("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><image xlink:href=\"data:image/png;base64,iVBORw0KGgo=\" /></svg>", alt: "A small red dot"))

```

gordonwoodhull added a commit to quarto-dev/quarto-cli that referenced this pull request Jan 11, 2026
Closes #13868

Workaround for Pandoc not passing alt text to Typst image() calls.
When an image has alt text (from caption or explicit alt attribute),
emit raw Typst with image(..., alt: "...") for accessibility.

This is a temporary fix until jgm/pandoc#11394 is merged upstream.

- Add alt text handling in render_typst_fixups() Image filter
- Alt parameter placed second after filename (matches Pandoc PR)
- Escape backslashes and quotes in alt text
- Add comprehensive test coverage with unique test images
- Replace test-image.png with smaller penrose.svg

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@mcanouil
Copy link
Contributor Author

@gordonwoodhull Do you see something else regarding Quarto use?

@gordonwoodhull
Copy link
Contributor

gordonwoodhull commented Jan 11, 2026

I’ve implemented a character-for-character equivalent workaround in Quarto as part of quarto-dev/quarto-cli#13857, since we probably won’t update our Pandoc again until 1.10.

@mcanouil mcanouil marked this pull request as ready for review January 11, 2026 21:00
gordonwoodhull added a commit to quarto-dev/quarto-cli that referenced this pull request Jan 13, 2026
Closes #13868

Workaround for Pandoc not passing alt text to Typst image() calls.
When an image has alt text (from caption or explicit alt attribute),
emit raw Typst with image(..., alt: "...") for accessibility.

This is a temporary fix until jgm/pandoc#11394 is merged upstream.

- Add alt text handling in render_typst_fixups() Image filter
- Alt parameter placed second after filename (matches Pandoc PR)
- Escape backslashes and quotes in alt text
- Add comprehensive test coverage with unique test images
- Replace test-image.png with smaller penrose.svg

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No upstream support for alt-text in Typst

2 participants