jneug / typst-finite

Typst-setting finite automata with CeTZ.
MIT License
59 stars 1 forks source link

Two transitions from single source to single destination? #6

Closed SuperKenVery closed 1 month ago

SuperKenVery commented 1 month ago

I want to do something like this:

+ #automaton((
  s1: (s1: "a", s1: "b", s2: "a"),
))

But I got duplicate key error. I know I can do

s1: (s1: ("a","b"), s2: "a")

But that would make it a single curve. I want two curves. Is that possible?

Thanks for your great work!

jneug commented 1 month ago

You will need to draw the states yourself on a CeTZ canvas, but it is possible:

#cetz.canvas({
  import finite.draw: *

  state((0,0), "q0")
  state((4,0), "q1")
  transition("q0", "q1", inputs:1)
  transition("q0", "q1", inputs:0, curve:left)
})

See section II.4 of the manual for more details.

SuperKenVery commented 1 month ago

Thanks, but I think it would be great if it's supported without manually calling canvas. Is that planned?

I think we might mainly need to change: https://github.com/jneug/typst-finite/blob/042cd1f8f154ffba9978e5e649e9128c13f3c8f8/cmd.typ#L116-L147

But I'm too bad in typst that I tried and failed...

jneug commented 1 month ago

This won't be possible, since a Typst dict can't have duplicate keys. I would have to change the structure of the input dict and I don't think this is a common enough thing to warrant this. Especially since it is already possible by using canvas.

SuperKenVery commented 1 month ago

Thanks a lot for your work, it's already awesome even if it doesn't support this.


However, I think implementing this doesn't require a dict having duplicate keys. For example,

s1: (s1: ("a","b"), s2: "a")

Here, s1 corresponds to a tuple, and we can expand that to two transitions. Currently we transform the tuple to a string with commas, but maybe we could re-define what a tuple means here?


I tried again and got a prototype: https://github.com/SuperKenVery/typst-finite/commit/1136d65607a1ea3c44acb3b961aaa9396bf74b2c Maybe you could have a look if you're interested 😄

It's only a draft. Things not working:

image

But it shows the possibility 🎉