Typst: image size in px is not converted when the image has fig-alt
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- lua
- Lĩnh vực
- cli, documentation
Hướng nghiên cứu
Lỗi nằm trong src/resources/filters/quarto-post/typst.lua, dòng 218-225 và 262-273. Bắt đầu bằng cách đọc mã bộ lọc để xem cách nó xử lý hình ảnh có fig-alt. Bản sửa lỗi có thể liên quan đến việc chuyển đổi đơn vị px sang inch bằng PANDOC_WRITER_OPTIONS.dpi, tương tự như cách xử lý các số thuần túy. Kiểm tra bằng cách tạo một tệp .qmd tối thiểu có hình ảnh với fig-alt và kích thước px, sau đó chạy quarto render để xác minh rằng tệp .typ được tạo không còn chứa 'px'.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
When I render to Typst, an image with fig-alt keeps its size in px. Typst has no px unit, so compiling the document fails with invalid number suffix: px. The same image without fig-alt renders fine, because Quarto converts its size to inches.
The cause is in the Typst filter, quarto-post/typst.lua. When an image has alt text, the filter doesn't pass it on to Pandoc. It writes the Typst image() call itself as a RawInline and copies the height and width values across unchanged. The filter does convert sizes before that, but only when they're plain numbers. tonumber("200px") returns nil, so 200px ends up in the Typst code as it is.
This is where the filter builds the image() call for an image with alt text:
An image without alt text goes through Pandoc's Typst writer instead, and that writer turns pixel sizes into inches:
Sizes in % still work with fig-alt, because Typst understands %.
Checked against Pandoc
I also ran the same image through Pandoc on its own, and Pandoc isn't the cause. The Pandoc 3.10 bundled with Quarto converts the size and writes the alt text correctly:
printf 'A {height="200px" alt="Quarto logo."} b\n' | quarto pandoc -f markdown -t typst
# #box(image("https://quarto.org/quarto.png", height: 2.08333in, alt: "Quarto logo."))
A comment in the filter says the raw image() call is a workaround, because Pandoc used to leave alt text out of Typst output (jgm/pandoc#11394). Pandoc 3.10 writes alt: itself now, so the workaround might not be needed any more. For the moment, it's the code path that causes this bug.
Steps to reproduce
---
format: typst
keep-typ: true
---
{height="200px"}
{height="200px" fig-alt="Quarto logo."}
Actual behavior
The generated .typ file has these two lines:
#box(image("t3_files/mediabag/quarto.png", height: 2.08333in))
#box(image("t3_files/mediabag/quarto.png", alt: "Quarto logo.", height: 200px))
Typst then stops with this error:
error: invalid number suffix: `px`
Expected behavior
I'd expect the image with fig-alt to have its size converted just like the one without it:
#box(image("t3_files/mediabag/quarto.png", alt: "Quarto logo.", height: 2.08333in))
I can see two ways to fix it. The filter could convert px values to inches with PANDOC_WRITER_OPTIONS.dpi, as it already does for plain numbers. Or, now that Pandoc 3.10 writes the alt text itself, the filter could let Pandoc handle these images as well.
Your environment
I'm on macOS. The bug happens with Quarto 1.10.18 and with the current main branch at commit 03f0fdf586b066ffa81ebefa55e5dad21e08bec0.
Quarto check output
This output comes from the development build I used to confirm the bug on main.
[✓] Checking environment information...
Quarto cache location: /Users/mcanouil/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.10.0: OK
Dart Sass version 1.101.0: OK
Deno version 2.7.14: OK
Typst version 0.15.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 99.9.9
commit: 03f0fdf586b066ffa81ebefa55e5dad21e08bec0
Path: /Users/mcanouil/Projects/quarto-dev/quarto-cli/package/dist/bin
[✓] Checking tools....................OK
TinyTeX: v2026.07
Chrome Headless Shell: (not installed)
VeraPDF: (not installed)
[✓] Checking LaTeX....................OK
Using: TinyTex
Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
Version: 2026
[✓] Checking Chrome Headless....................OK
Using: Chrome from QUARTO_CHROMIUM
Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
[✓] Checking basic markdown render....OK
ℹ R version 4.6.1 (2026-06-24)
! Config '~/.Rprofile' was loaded!
[✓] Checking R installation...........OK
Version: 4.6.1
Path: /Library/Frameworks/R.framework/Versions/4.6/Resources
LibPaths:
- /Users/mcanouil/Projects/quarto-dev/quarto-playground/renv/library/macos/R-4.6/aarch64-apple-darwin23
- /Users/mcanouil/Library/Caches/org.R-project.R/R/renv/sandbox/macos/R-4.6/aarch64-apple-darwin23/46003b10
knitr: 1.51
rmarkdown: 2.31
[✓] Checking Knitr engine render......OK
[✓] Checking Python 3 installation....OK
Version: 3.9.6
Path: /Library/Developer/CommandLineTools/usr/bin/python3
Jupyter: (None)
Jupyter is not available in this Python installation.
Install with python3 -m pip install jupyter
There is an unactivated Python environment in .venv. Did you forget to activate it?
[✓] Checking Julia installation...
- Ngôn ngữ chính
- JavaScript
- Star
- 6k
- Fork
- 458
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 54
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của quarto-dev/quarto-cli
-
accessibility documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
quarto-dev/quarto-cli#14944 ·
-
maintenance ojs-engine
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
quarto-dev/quarto-cli#14934 ·
-
accessibility bug html themes
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
quarto-dev/quarto-cli#14932 ·
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
quarto-dev/quarto-cli#14915 ·
-
binder bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
quarto-dev/quarto-cli#14907 · 3 bình luận · 1 reaction ·
Tất cả issue của quarto-dev/quarto-cli
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
Mintplex-Labs/anything-llm#6490 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
[quality] workflow-scripts guard reads test:unit:coverage as skipping the unit suite, blocking #632 Đang mởagent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
area-clientside-dartpad
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100