Skip to content

Commit 51153bc

Browse files
authored
Merge pull request #10219 from quarto-dev/bugfix/10217
`typst`: explicitly compute units in image dimensions when not given
2 parents 4398072 + 3e21fa5 commit 51153bc

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

news/changelog-1.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All changes included in 1.6:
1414

1515
- ([#10168](https://github.com/quarto-dev/quarto-cli/issues/10168)): support `csl` bibliography style.
1616
- ([#10181](https://github.com/quarto-dev/quarto-cli/issues/10181)): Remove workaround for image dimensions which is no longer necessary and mishandled image paths with spaces.
17+
- ([#10217](https://github.com/quarto-dev/quarto-cli/issues/10217)): Explicitly compute units for image dimensions in `typst` format when they're not given.
1718

1819
## Other Fixes and Improvements
1920

src/resources/filters/quarto-post/typst.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ function render_typst_fixups()
9696
traverse = "topdown",
9797
Image = function(image)
9898
image = _quarto.modules.mediabag.resolve_image_from_url(image) or image
99+
-- REMINDME 2024-09-01
100+
-- work around until https://github.com/jgm/pandoc/issues/9945 is fixed
101+
local height_as_number = tonumber(image.attributes["height"])
102+
local width_as_number = tonumber(image.attributes["width"])
103+
if image.attributes["height"] ~= nil and type(height_as_number) == "number" then
104+
image.attributes["height"] = tostring(image.attributes["height"] / PANDOC_WRITER_OPTIONS.dpi) .. "in"
105+
end
106+
if image.attributes["width"] ~= nil and type(width_as_number) == "number" then
107+
image.attributes["width"] = tostring(image.attributes["width"] / PANDOC_WRITER_OPTIONS.dpi) .. "in"
108+
end
99109
return image
100110
end,
101111
Div = function(div)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
format: typst
3+
---
4+
5+
6+
::: {.cell execution_count=1}
7+
``` {.python .cell-code}
8+
from plotnine import ggplot, geom_point, aes, stat_smooth, facet_wrap
9+
from plotnine.data import mtcars
10+
11+
(
12+
ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
13+
+ geom_point()
14+
+ stat_smooth(method="lm")
15+
+ facet_wrap("gear")
16+
)
17+
```
18+
19+
::: {.cell-output .cell-output-display}
20+
![](10217_files/figure-typst/cell-2-output-1.png){width=640 height=480}
21+
:::
22+
:::
23+
24+
67.9 KB
Loading

0 commit comments

Comments
 (0)