Mc-Zen / quill

Effortlessly create quantum circuit diagrams in Typst.
https://typst.app/universe/package/quill
MIT License
40 stars 2 forks source link

A slice with a midstick on top of it has a background #1

Closed SekoiaTree closed 6 months ago

SekoiaTree commented 7 months ago

A slice with a background color, combined with a midstick, will have an extra background color.

Minimal example:

#import "@preview/quill:0.2.0" : *
#quantum-circuit({
  let group = gategroup.with(stroke: (dash: "dotted", thickness: 1pt), fill: aqua)
  quantum-circuit(
    row-spacing: 6pt,
    column-spacing: 16pt,
    group(2, 1, label: "Wow"), $H$, [\ ],
    setwire(0), midstick($dots.v$), [\ ],
  ) 
})

image

Workaround: redefine draw-unboxed-gate and midstick.

  let draw-unboxed-gate(gate, draw-params) = box(
    inset: draw-params.padding, 
    fill: if gate.fill != none {gate.fill} else { none }, 
    gate.content
  )
  let midstick(content, label: none) = gate(content, draw-function: draw-unboxed-gate, label: label)
Mc-Zen commented 7 months ago

Hi @SekoiaTree ,

The reason for it being non-transparent is so that the underlying wires are overdrawn. To illustrate, let's add some wires: image

Initially, I spent a lot of effort to allow transparent gates and everything but it turned out very tricky with many special cases. It seemed better to not allow transparent gates. For gates, this seems okay to me but I have to admit that I did not think of your case with midstick.

I see two solutions: 1) We can add a fill parameter to midstick(), so you can pass the same background color to it. To use it now, just add the following code to your file:

#let midstick(content, fill: none, label: none) = gate(content, draw-function: draw-functions.draw-unboxed-gate, label: label, fill: fill)

and use it with midstick(fill: aqua, ...)

2) The other option is to rewrite a lot of the internals and make transparent gates and co. happen. This is a large effort for not too many benefits but I won't quite say that it will not happen ;)

Thanks for pointing this out!

SekoiaTree commented 7 months ago

I don't know hugely much of the internals, but can't you "just" have slice pass its own background color as the default setting for the fill?

Edit: Ah, there's no concept of "on top of", so a gate can't know it's on top of a slice.

Mc-Zen commented 7 months ago

Precisely. Just like similar packages in LaTeX, gategroup does not actually "group" the elements that it covers. It is just drawn below.

Mc-Zen commented 6 months ago

With 6ebf10, a fill parameter has been added to midstick. With the new release (v0.2.1), this feature is available (package pull request pending).