paolobrasolin / string-diagrams

Create string diagrams with LaTeX!
https://www.ctan.org/pkg/string-diagrams
LaTeX Project Public License v1.3c
13 stars 2 forks source link

Advanced adjacencies syntax #11

Open paolobrasolin opened 1 year ago

paolobrasolin commented 1 year ago

After #5 I've been giving some more thought to #6.

Right now the syntax for \wires is

\wires[<tikz keys>]{
  <source node> = {
    <source anchor> = <target node>.<target anchor>,
    <source anchor> = <target node>.<target anchor>,
    ...
  },
  <source node> = { ... },
  ...
}

Now, this is a two-levels nested prop, so you cannot repeat keys; specifically:

While this is not a big deal when using numbered ports, it immediately becomes annoying when we use the boundary node to connect multiple boxes:

\wires{
  % you can't
  @ = {
    west = A.west.1,
    west = A.west.2,
  },
  % nor
  @ = { west = B.west.1 },
  @ = { west = B.west.2 },
}

Of course you can just flip source and target to make this work, but this structure is inherently directional so you just create a different problem.

One solution is allowing the inner level to be a clist instead of an anchor name:

\wires{
  @ = { west = { A.west.1, A.west.2 } },
  @.west = { B.west.1, B.west.2 },
}

If we can treat a single node name as a one-element clist in a trivial way, than this could be nice even at implementation level.

The only alternative i can think of is providing a separate list-of-pairs based command:

\wires*{
  { @.west, A.west.1 },
  { @.west, A.west.2 },
  { @.west, B.west.1 },
  { @.west, B.west.2 },
}

However, I strongly dislike the aesthetics of it.

Another issue emerged in #6 is providing non-global TikZ styles. I think this can also be solved by allowing richer syntax:

\wires[<tikz keys>]{ % global level
  <source node> = [<tikz keys>]{ ... }, % bundle level
  <source node> = { <source anchor> = [<tikz keys>]<target node>.<target anchor>, ... }, % wire level
  % and, if we implement the syntax discussed above,
  <source node>.<source anchor> = [<tikz keys>]{ ... },
  <source node>.<source anchor> = { [<tikz keys>]<target node>.<target anchor>, ... },
  <source node> = { <source anchor> = [<tikz keys>]{ ... } },
  <source node> = { <source anchor> = { [<tikz keys>]<target node>.<target anchor>, ... } },
}

Now: would this actually be a good idea?