How do I center accent correctly?

Hi. I have a typographical question. When I write a k with a hat over, the hat is unfortunately not centered correctly - it is especially bad if I use an upright sans serif font. Does anyone know of an elegant solution to this problem?

Here is a comparison of how it looks in Typst and LaTeX. I would like the result to resemble the LaTeX typography.

Typst
Screenshot 2025-08-20 at 15.21.18

LaTeX
hat_k_,_hat_math

Can you give the Typst and LaTeX code and the Typst version you’re using?

Here’s what I see:

Typst 0.13.1 with default math font (New Computer Modern Math):

$ hat(k), e_(hat(k)) $

image

LaTeX (texlive 2024) with same math font as Typst:

\documentclass{article}
\usepackage{fontsetup} % loads New Computer Modern
\begin{document}
\[ \hat{k}, e_{\hat{k}} \]
\end{document}

LaTeX with default math font (Computer Modern):

\documentclass{article}
\begin{document}
\[ \hat{k}, e_{\hat{k}} \]
\end{document}

1 Like

(I reproduced it with the following code.)

$
  hat(k),
  hat(upright(sans(k))),
  e_hat(upright(sans(k)))
$

2 Likes

Thanks for your reply Sijo. Curious that we get different results.

I am using the latest Typst version (0.13.1) and the default math font.

To reproduce. Open an empty document in Typst. And paste the following code:
$
hat(k), e_(hat(k)), hat(upright(sans(k))), e_(hat(upright(sans(k)))),
$
This gives me the result:
Screenshot 2025-08-21 at 12.11.29

Compare this to LaTeXiT with the following preamble:

\documentclass[10pt]{article}

The LaTeX code is (in display mode):

\hat{k}, e_{\hat{k}}, \hat{\mathsf{k}}, e_{\hat{\mathsf{k}}}

And this gives me the result:
hat_k_,e_hat_k

Minor detail: In my original example I had overwritten the weight of the math font, which means the accents had a little more vertical spacing than usual, but this is not related to my alignment issue. So now, I have explained the minimal reproducible example above.

This is affected by the font used in math mode:

$hat(upright(sans(k)))$
#show math.equation: set text(font: "Fira Math")
$hat(upright(sans(k)))$


Also, a box can be used as a work-around, though it may have negative effects on other parts of the layout and will very quickly become annoying to enter into the document:

$hat(upright(sans(k)))$
$hat(#box($upright(sans(k))$))$

1 Like