Hello everyone,
I’m stuck and I’m begging for help.
I want to being able to display images in a grid, and for landscape pictures, I want the picture to take 2 columns of the grid, nothing too hard.
I don’t know which picture is landscape and which picture is portrait.
So, I have the following function:
#let display_portrait_landscape(img_url, content) = {
if measure(img_url).width > measure(img_url).height {
grid.cell(
colspan: 2,
content)
} else {
grid.cell(
colspan: 1,
content)
}
}
and I use it with context in the grid:
#grid(
columns:3,
rows:auto,
gutter:32pt,
align: top,
grid.cell(
colspan: 1,
image(
"pic1.jpeg",
width:100%,
height:200pt,
fit: "contain"
)
),
grid.cell(
colspan: 2,
image(
"pic1.jpeg",
width:100%,
height:200pt,
fit: "contain"
)
),
context {
display_portrait_landscape[pic2.jpeg][
#image(
"pic2.jpeg",
width:100%,
height:200pt,
fit: "contain"
)
]
}
)
I tried on the typst simulator (no error reported): when I put directly colspan:2 inside the grid (the 2 firsts pictures), it works, but when I use the function, it never draw pictures on 2 columns, event by forcing colspan:2 in every possible branches, it’s like the colspan is ignored and the picture is displayed without it. I tried using directly image() instead of content into the function, but still the same issue.
I tried to figure out the picture ratio, the first branch of the function should be triggered, no matter the picture used (which is weird IMHO).
I’ve read everything I can read on the documentation about grid, image and context, I think I’m missing something on the context thing, but I’m dont understand why even the grid doesn’t take into account the colspan from the function.
I’m stuck, some help will be really appreciated.
Thank you.