How to refer to function argument in math mode

I’m using the fletcher package to create the following diagram
#diagram({
let (PZ, PY) = ((0,0), (0,1))
node(PZ, $P(Z)$)
node(PY, $P(Y)$)
edge(PY, PZ, “->”, $f^*$, right)
edge(PZ, PY, “->”, $∃_f$, shift:-0.5)
edge(PZ, PY, “->”, $∀_f$, shift:0.5, label-side:left)
})

However since this notation is bulky and I need these type of diagrams a lot, I would like to write it in the form

#diagram($
P(Z) edge(“d”, ->, ∃_f, shift:0.5) edge(“d”, ->, ∃_f, shift:-0.5)

P(Y) edge(“u”, ->, f^*)$)

However this is not creating the same diagram, as the arrows don’t get shifted - my understanding is that it isn’t interpreting shift:0.5 correctly because I am in math mode. How can I fix this?

Thanks!

Welcome to the typst Discourse! You can put your code examples between ``` markers to make them more readable. See here for other tips.

It’s a bit hard to know what you have in mind with your second example without seeing a complete (minimal) working example. But generally speaking I think it’s a bad idea to try and do everything in math mode. Writing edge(PY, PZ, "->", $f^*$, right) makes a lot of sense: the dollar signs show what part is actually a math formula. The diagram itself is not a formula.

If you really want to use this shortcut form, I think you’ll have layout problems with the nodes since they are not coded to be math elements. I suppose you could get some things to work, like the edges. To fix the particular issue you have mentioned with shift, you will have to write shift: #(-0.5). I think you will quickly find that the savings in $ characters are quickly lost by the workarounds required to make other things work in math mode :slight_smile:

1 Like