Jollywatt / typst-fletcher

Typst package for drawing diagrams with arrows, built on top of CeTZ.
MIT License
341 stars 6 forks source link

Ignore labels when centering #38

Open KillianB8 opened 4 months ago

KillianB8 commented 4 months ago

Is there a way to ignore edge labels when aligning a diagram (ie. only take into account nodes)?

In the following example, I'd like the nodes of the first diagram to line up with the nodes of the second one:

#align(center)[#diagram(
  node((0, 0), $1$),
  node((0, 1), $2$),
  edge((0, 0),(0, 1),"->","this is a very long label"),
)]
#align(center)[#diagram(
  node((0, 0), $1$),
  node((0, 1), $2$),
  edge((0, 0),(0, 1),"->"),
)]

(sorry if this isn't the place to ask this btw!)

Jollywatt commented 4 months ago

I agree I think this would be a better default.

Fletcher actually does this by default — only nodes affect the diagram's grid layout (which you can see this with debug: 1). However, the cetz canvas that hosts the diagram sets the bounding box to the entire content. Once we find out how to either 1) manually set the cetz canvas' bounding box, or 2) make labels not affect the bounds, this can be done.

Edit: perhaps diagram() should expose both behaviours with a setting to be safe.

Jollywatt commented 4 months ago

Associated cetz issue: https://github.com/cetz-package/cetz/issues/619