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

Labels for wires #6

Open jonsterling opened 1 year ago

jonsterling commented 1 year ago

Is there an existing issue for this?

Original problem

It would be really nice to support placing a label node on a wire, like --f--[box]--g--. I think with this feature, it would be possible for me to begin using this package.

Proposed solution

I am not certain what the most harmonious syntax for doing this would be. One tends to need a bit of flexibility in terms of where the label node is placed, how it is aligned or rotated, etc.

Alternatives considered

No response

Additional context

No response

paolobrasolin commented 1 year ago

I'll jot down a few ideas.

Generally speaking, all standard TikZ techniques work:

% these are all equivalent:
\draw (A.east.1) to[red, edge node={node [blue] {f}}] (B.west.2);
\draw (A.east.1) edge [red] node [blue] {f} (B.west.2);
\draw (A.east.1) edge [red, edge label={f}] (B.west.2);
\draw (A.east.1) edge [red, "f"[blue]] (B.west.2);

So, however complicated the situation gets, one can always use plain Tikz.

That being said, the most harmonious syntax could be obtained by injecting the last technique from above into the \wires command; something along the lines of

\wires{ A = { east.1 = B.west.2[red, "f"[blue]] } }{}

It's not pretty, but for the most common usage it reduces to

\wires{
  A = { east.1 = B.west.2["f"] },
}{
  A.east.2["g"]
}
jonsterling commented 1 year ago

@paolobrasolin Thanks! I might try the first approach... Personally my experience with cool tikz libraries is that in the end I mainly want to use the primitive (like \draw) with some useful styles attached, rather than an all-encompassing solution (like either \wires or tikzcd's matrices), because when I need to go beyond what the latter supports, it results in a lot of rewriting of code. So let me play around with the former, and I'll let you know if I think of any ideas for how such a feature might be usefully enhanced. I think already the new pgf shapes that you have defined in this library are really useful, and I probably would get a lot of mileage from just using those to start with!

paolobrasolin commented 1 year ago

Cool, @jonsterling! Then be careful about the anchor names. The current release only has west0, west1, east0 and east1, but i'm working on #2 which will make their count configurable and name them according to the format I used above.