cetz-package/cetz

`canvas()` does not pass the correct figure dimensions to `grid()`

Closed this issue · 2 comments

Consider this MWE:

#import "@preview/cetz:0.2.2": canvas, draw//, plot, decorations
#set page(width: auto, height: auto, margin: .5cm)

#let draw_layers(divisor) = {
  canvas({
    draw.merge-path(fill: red, {
      divisor
      draw.line((1, 1), (1, 2))
      draw.line((1, 2), (0, 2))
    },
    stroke: 0pt)
    
    divisor

    draw.merge-path(fill: blue, {
      divisor
      draw.line((1, 1), (1, 0))
      draw.line((1, 0), (0, 0))
    },
    stroke: 0pt)
  })
}

#grid(
    columns: (1fr, 1fr),
    rows: (1fr, 1fr),
    gutter: 90pt,
    draw_layers(draw.line((0, 1), (1, 1))),
    draw_layers(draw.line((0, 1), (1, 1))),
    draw_layers(draw.line((0, 1), (1, 1))),
    draw_layers(draw.line((0, 1), (1, 1))),
  )

It results in

image

Cetz doesn't seem to be able to correctly pass the image ratio (height x width) to grid() so that the correct page height and width can be automatically defined.

Does not work with native Typst drawing commands either (replace canvas(...) with rect(width: 1cm, height: 1cm)), so it seems to be a Typst bug.

This issue was addressed in typst/typst#4176 and is related to a conflict between auto and frac, thus having nothing to do it cetz