How to write a vector arrow over a variable? Equivalent of LaTeX vec function?

Basically the title.

$arrow(V)$?
image

1 Like

Yes, perfect, I could’t find it in the docs before, thank you!

Hey, there. Same question here, but more precisely:

image

This is rended with LaTeX. The first one is equivalent to Typst arrow(V), the second one is using a specific LaTeX function stretching the arrow over the whole length of the symbol(s) below. I cannot find a proper alternative in Typst. Any (hint of an) answer, anyone?

For now, I only tweaked with horizontal space, defining a function:

#let vect(name) = $arrow(#h(1.4pt) name #h(1.4pt))$

$ vect(u) = arrow(u) $

$ vect(V) != arrow(V) $

$ vect(A B) approx arrow(A B)$

My guess is something easier should exist than what I’m doing here.

The root cause here is that Typst uses OpenType math fonts for math, and the fonts say how to build an arrow “accent” in discrete (not continuous) sizes. You actually get the same result with LaTeX when using an OpenType font:

\documentclass{article}
\usepackage{fontsetup}
\usepackage{amsmath}
\begin{document}
\[ \overrightarrow{V} \]
\end{document}

image

Typst tries to pick the best arrow size for the text beneath, but you can force it to pick another one with the size parameter:

$
  arrow(V, size: #1.2em)
$

image

Edit: it looks like LaTeX also does continuous scaling with OpenType fonts, but only for content above some size threshold, and “V” doesn’t qualify so it gets a small arrow, while “M” for example gets a much bigger one.

2 Likes

Thanks for the explanation and suggestion!

I noticed size:#1.05em is the critical value from which the arrow is going to be stretched when one letter is below, so I went for that.

Would it make sense to set this to default at all in Typst?
Where to contact dev about this topic? A ticket on GitHub?

I don’t think it would make sense to make this particular change: which size is better is rather subjective (for example I much prefer the smaller arrow here), and the value of 1.05em might work for this particular font but not for other fonts, and you might think it looks good for “V” but surely not for all letters (like “i”)…

In any case there was already an issue filed for this: The size field in math.accent does not behave as expected · Issue #7956 · typst/typst · GitHub . It was closed for the reasons given here, but I do wonder if there’s room for improvement, since math fonts do have a mechanism for making continuous sizes (I’ve just asked about it on Discord).

1 Like