cetz-package / cetz

CeTZ: ein Typst Zeichenpaket - A library for drawing stuff with Typst.
https://cetz-package.github.io
GNU Lesser General Public License v3.0
733 stars 34 forks source link

[bug] PDF/SVG output divergence due to wrong `show`: `set` rule behavior in CeTZ #632

Closed tapyu closed 1 week ago

tapyu commented 1 week ago
#import "@preview/cetz:0.2.2"
#import cetz.draw: *
#set page(width: auto, height: auto, margin: .5cm)

#show box: set block(spacing: 0pt, fill: blue)

#cetz.canvas({
  content(
    (),
    box[
      Phase error variance

      Mean time beetween cicle slips

      Frequency unlock/drop lock
    ],
  )
})

There is a mismatch in SVG and PDF outputs:

image

Although the show: set rule is being applied in the SVG output, the spacing in not being handled correctly.

Moreover, by changing

box[
      Phase error variance

      Mean time beetween cicle slips

      Frequency unlock/drop lock
    ]

by

align(center)[
      Phase error variance

      Mean time beetween cicle slips

      Frequency unlock/drop lock
    ]

We obtain

image

If I didn't missunderstand it, the problem is twofold:

  1. align shouldn't trigger the #show box: set block rule. In fact, outside CeTZ, it doesn't happen

    #set page(width: auto, height: auto, margin: .5cm)
    #show box: set block(spacing: 0pt, fill: blue)
    
    #align(center)[
    Phase error variance
    
    Mean time beetween cicle slips
    
    Frequency unlock/drop lock
    ]

    image

  2. CeTZ is probably causing a bug in how the show: set rule is being applied, making it trigger and set the spacing wrongly, which leads to a divergence in the PDF and SVG output.

Maybe this can explain the offset observed in #621

fenjalien commented 1 week ago

621 is because the content's border is not being translated along with the content, which has nothing to do with this issue.

The difference in the SVG/PDF output should be opened as a Typst bug, CeTZ has no control over this.

The show: set rule triggers on content in a canvas because it wraps everything drawn into a box and we wrap content in a block in order to add padding to the content.