Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference in rendering of arrows in Tikz and Quiver #111

Open
pbustillo05 opened this issue Aug 18, 2021 · 2 comments
Open

Difference in rendering of arrows in Tikz and Quiver #111

pbustillo05 opened this issue Aug 18, 2021 · 2 comments
Labels
discussion ongoing discussion

Comments

@pbustillo05
Copy link

I tried to dig into the PGF/TikZ and the tikz-cd manuals today to understand how the curves of the arrows are computed there. I noticed several disparities with what quiver seems to be doing. I say "seems to be doing" because I'm not completely sure of how the algorithm of quiver works. I looked at the source code a bit (but I don't really read JavaScript) and I played around with the software to understand its behavior, so it's a lot of guess work. Essentially the differences come down to this:

  • Shapes of the surronding boxes of the cells and positions of their "center". In tikz-cd, the boxes surronding the nodes are of the shape "asymmetric rectangles" (explained in section 4.1 of the tikz-cd manual). Two features of this shape are important: its corners are straight (like a normal rectangle) and its "center" is aligned with the math axis (elevated by default from "axis_height" or $\sigma_{22}$ of the document's math font from the baseline). In quiver, the boxes surronding the nodes seem to be rectangles with rounded corners and their "center" seems to be the geometrical center of the formula. As the Bézier curves of the arrows are computed using those "centers" (except in tikz-cd when using horizontal arrows essentially), and as the curves tries to avoid being inside the surronding box of the cell, those differences give different rendering.
  • Starting and ending points of the bended arrows. In tikz-cd, when using a "path to" (for example when using the "curve" key defined in quiver.sty), it looks like the control points of the Bézier curve are first computed using the "centers" of domain/codomain cells. The tangents at the starting and ending points of the path are then intersected with the surronding boxed of the domain and codomain cells respectively. Then it seems like those intersections are then used as new starting and ending points for the Bézier curve (while keeping the exact same controls). In quiver, it looks like the controls points are first computed similarly with the "centers" of the domain/codomain cells. But then a different process is used: the curve itself seems to be intersected with the surronding boxes and "clipped" to avoid them.

I suppose it's similar when the ending/starting points of the arrows are labels of other arrows, rather than cells (although I didn't explore this situation). Of course this is a lot of guess work so correct me if I'm mistaken. The difference of rendering between tikz-cd and quiver is only slightly noticable with straight arrows. However, with bended arrows the difference is very noticable. Is there a way to correct the differences above?

(also just out of curiosity, as I digged into the ways arrows are bended and rendered, I wondered: what's the reason behind using the "curve" key for fixed heights bending of arrows, rather than using the more common "bend right" and "bend left" keys?)

@varkor varkor added the discussion ongoing discussion label Aug 26, 2021
@varkor
Copy link
Owner

varkor commented Aug 26, 2021

Thank you for this analysis: I have been aware that there are differences in how the positions and bouncing boxes were calculated, but did not dig into precisely what they were, so this is helpful. I personally think the diagrams in quiver are more aesthetic in this regard, so I would prefer to instead output modified TiKZ that matches the quiver diagrams, rather than modify quiver to look more like the default TikZ styles. But as I am not an expert with TikZ, it will take some time to figure out how to do this effectively.

(also just out of curiosity, as I digged into the ways arrows are bended and rendered, I wondered: what's the reason behind using the "curve" key for fixed heights bending of arrows, rather than using the more common "bend right" and "bend left" keys?)

The bend commands are very inflexible, and just allow you to specify an angle. It can be difficult to predict what the result will look like without rendering it, and often the most aesthetic curves are not possible this way. I find that curve (i.e. specifying a height, rather than an angle) is much more natural, and makes it easy to produce the correct TikZ code from quiver.

@pbustillo05
Copy link
Author

pbustillo05 commented Aug 26, 2021

I agree that quiver often looks better! It's not a matter of correcting quiver to make it look like TikZ (or the opposite), but probably a matter of choosing each time the best option (and modifying the other).

For example, I think TikZ-CD idea of offsetting the center of the box by the "math axis height" is very cool. Their boxes look nicer in my opinion, except that rounded corners make more sense. So this could be a matter of rounding the corners of the "asymmetrical rectangle" shape, and matching it on quiver.

But for paths, in general the idea of quiver is more aesthetically pleasing. I'll try to think more about how the TikZ code can be modified to have better looking arrows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion ongoing discussion
Projects
None yet
Development

No branches or pull requests

2 participants