Skip to content

Commit f0c8c9f

Browse files
authored
Merge pull request #11676 from quarto-dev/bugfix/typst-unitless-image-column-widths
typst column layout: interpret unitless image widths as pixels and convert to inches
2 parents d5559d7 + 8d603b9 commit f0c8c9f

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ All changes included in 1.7:
4040
## `typst` format
4141

4242
- ([#11578](https://github.com/quarto-dev/quarto-cli/issues/11578)): Typst column layout widths use fractional `fr` units instead of percent `%` units for unitless and default widths in order to fill the enclosing block and not spill outside it.
43+
- ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts.
4344
- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.
4445

4546
## Lua Filters and extensions

src/resources/filters/layout/width.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ function widthsToFraction(layout, cols)
136136
widths[#widths+1] = 0
137137
local width = attribute(fig, "width", nil)
138138
if width then
139+
local num = tonumber(width)
140+
if num then
141+
width = string.format("%.6f", num / PANDOC_WRITER_OPTIONS.dpi) .. "in"
142+
end
139143
widths[#widths] = width
140144
end
141145
end
142146

143-
-- create virtual fig widths as needed and note the total width
147+
-- default width
144148
local defaultWidth = "1fr"
145149
for i=1,cols do
146150
if (i > #widths) or widths[i] == 0 then
@@ -149,8 +153,7 @@ function widthsToFraction(layout, cols)
149153
end
150154
-- allocate widths
151155
for i,fig in ipairs(row) do
152-
local width = widths[i];
153-
fig.attr.attributes["width"] = width
156+
fig.attr.attributes["width"] = widths[i]
154157
fig.attr.attributes["height"] = nil
155158
end
156159

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Unitless image widths in column layout
3+
format: typst
4+
keep-md: true
5+
keep-typ: true
6+
_quarto:
7+
tests:
8+
typst:
9+
ensureTypstFileRegexMatches:
10+
-
11+
['#grid\((\r\n?|\n)columns: \(1fr, 1fr, 1.041667in, 1fr, 0.260417in\), gutter: 1em, rows: 1,']
12+
13+
---
14+
15+
::: {.callout-note}
16+
17+
## Plots
18+
19+
::: {layout-ncol=5}
20+
21+
![]({{< placeholder format=svg >}})
22+
23+
![]({{< placeholder format=svg >}})
24+
25+
![]({{< placeholder format=svg >}}){width=100}
26+
27+
![]({{< placeholder format=svg >}})
28+
29+
![]({{< placeholder format=svg >}}){width=25}
30+
31+
:::
32+
:::

0 commit comments

Comments
 (0)