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

Conversation

gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented Dec 13, 2024

Follow-up to #11658.

Currently, the following example will fail because it generates Typst output with unitless lengths:

---
title: Unitless image widths in column layout
format: typst
---

::: {.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}

:::
:::

For the images, we already interpret unitless image widths as pixels and convert to inches:

-- REMINDME 2024-09-01
-- work around until https://github.com/jgm/pandoc/issues/9945 is fixed
local height_as_number = tonumber(image.attributes["height"])
local width_as_number = tonumber(image.attributes["width"])
if image.attributes["height"] ~= nil and type(height_as_number) == "number" then
image.attributes["height"] = tostring(image.attributes["height"] / PANDOC_WRITER_OPTIONS.dpi) .. "in"
end
if image.attributes["width"] ~= nil and type(width_as_number) == "number" then
image.attributes["width"] = tostring(image.attributes["width"] / PANDOC_WRITER_OPTIONS.dpi) .. "in"
end

But we also need to use the converted widths for the layout.

Alternatively / in the the long run, we could contribute the fix to Pandoc instead.

jgm/pandoc#9945

@cscheid
Copy link
Collaborator

cscheid commented Dec 13, 2024

Can we make sure we've checked for how unitless dimensions are interpreted in other formats/settings? I'm thinking specifically:

  • format: latex
  • fig-width: N in knitr code cells

@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented Dec 13, 2024

Sure. LaTeX works mostly the same - looks like it needs some margin/padding on its images, and it will not accept SVG placeholders.

In the example from above the 3rd placeholder image has unitless width=100 and the 5th has width=25.

One can recognize that the LaTeX output

image

has the same intent as Typst output (if not the same execution)

image

fig-width is new to me, will check.

@cscheid
Copy link
Collaborator

cscheid commented Dec 13, 2024

Great, thanks. I don't think we need to (or can) do a perfect job here because units are also not a format-agnostic concept, but it will help us to know a bit more of the current behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants