Skip to content

Commit

Permalink
Merge pull request #11676 from quarto-dev/bugfix/typst-unitless-image…
Browse files Browse the repository at this point in the history
…-column-widths

typst column layout: interpret unitless image widths as pixels and convert to inches
  • Loading branch information
cscheid authored Jan 17, 2025
2 parents d5559d7 + 8d603b9 commit f0c8c9f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ All changes included in 1.7:
## `typst` format

- ([#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.
- ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts.
- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.

## Lua Filters and extensions
Expand Down
9 changes: 6 additions & 3 deletions src/resources/filters/layout/width.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ function widthsToFraction(layout, cols)
widths[#widths+1] = 0
local width = attribute(fig, "width", nil)
if width then
local num = tonumber(width)
if num then
width = string.format("%.6f", num / PANDOC_WRITER_OPTIONS.dpi) .. "in"
end
widths[#widths] = width
end
end

-- create virtual fig widths as needed and note the total width
-- default width
local defaultWidth = "1fr"
for i=1,cols do
if (i > #widths) or widths[i] == 0 then
Expand All @@ -149,8 +153,7 @@ function widthsToFraction(layout, cols)
end
-- allocate widths
for i,fig in ipairs(row) do
local width = widths[i];
fig.attr.attributes["width"] = width
fig.attr.attributes["width"] = widths[i]
fig.attr.attributes["height"] = nil
end

Expand Down
32 changes: 32 additions & 0 deletions tests/docs/smoke-all/typst/layout/unitless-image-width.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Unitless image widths in column layout
format: typst
keep-md: true
keep-typ: true
_quarto:
tests:
typst:
ensureTypstFileRegexMatches:
-
['#grid\((\r\n?|\n)columns: \(1fr, 1fr, 1.041667in, 1fr, 0.260417in\), gutter: 1em, rows: 1,']

---

::: {.callout-note}

## Plots

::: {layout-ncol=5}

![]({{< placeholder format=svg >}})

![]({{< placeholder format=svg >}})

![]({{< placeholder format=svg >}}){width=100}

![]({{< placeholder format=svg >}})

![]({{< placeholder format=svg >}}){width=25}

:::
:::

0 comments on commit f0c8c9f

Please sign in to comment.