Skip to content

Commit feed41c

Browse files
unitless image widths interpreted as pixels and converted
to inches, in generation of column layout
1 parent 46a7609 commit feed41c

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

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)