Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typst column layout: interpret unitless image widths as pixels and convert to inches #11676

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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.

## 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}

:::
:::
Loading