Closed
Labels
feature requestNew feature or requestgood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencemathRelated to math category, with its syntax, layout, etc.
Description
Description
There are times when I want to write some text above an arrow like this
Currently I'm using typst-cd with
#align(center)[
#commutative_diagram(
node((0, 0), [$$]),
node((0, 2), [$$]),
arr((0,0), (0,2), [injective map], "inj", label_pos: -1em)
)
]But it would be nice if there are native support for:
- long, hooked arrows
- putting text above an arrow (instead of just braces or brackets like we have now)
Use Case
As above. This can be used to describe injective maps.
Reacted by Janosh Riebesell, Wojciech Nawrocki and Sven
Metadata
Metadata
Assignees
Labels
feature requestNew feature or requestgood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencemathRelated to math category, with its syntax, layout, etc.

Activity
Enivex commentedon May 24, 2023
I don't know how typst-cd does it, but here's a typst solution that uses the symbol in your actual font
(this assumes that the arrow heads do not occupy more than 40% of the width, so it may need modification if the font has particularly large arrow heads)
mwyschan commentedon Jun 26, 2023
I'd just like to add that this syntax is also useful for denoting chemical reactions, e.g. catalysis:

In the case of reversible reactions using ⇌, I had to modify

long-symbolto shift the symbol slightly upwards (body-h+2ptseems to work), since the right arrow was getting clipped:apgrigor commentedon Jul 12, 2023
Hello! I ended up writing my own little function that places annotations on top of symbols, I based it on Enivex's solution.
In case someone finds it useful:
ice1000 commentedon Jul 12, 2023
Nice! Stolen
Enivex commentedon Jul 12, 2023
Note that there's now a package (xarrow) that does this, by @loutr, using a more flexible variant of what I did in my comment
https://typst.app/docs/packages/
DieracDelta commentedon Sep 14, 2023
This xarrow package gets confused with fractions. For example, something like:
Though, maybe I'm missing something?
laurmaedje commentedon Sep 14, 2023
You could open an issue here: https://codeberg.org/loutr/typst-xarrow/
laurmaedje commentedon Sep 18, 2023
Would it be desirable for the default arrow to scale automatically when you write
$ ->^"something long" $? Or are there cases where you don't want that?Enivex commentedon Sep 18, 2023
That would be desirable, but it would have to be quite robust. I imagine the approach in xarrow might break for certain fonts with weird arrows
laurmaedje commentedon Sep 18, 2023
@Enivex New CM arrows support the OpenType glyph construction feature. It would work just the same as
$ arrow("very long text") $.laurmaedje commentedon Sep 18, 2023
So basically, implementing this would mean stretching the
baseinAttachElem::layout_mathaccording to the max width of top and bottom attachment (if they are limits). I'm not sure if there are any unforeseen consequences on other attachment combinations though.[-]How to draw long hooked arrows?[/-][+]Make arrows in math stretchable[/+]