How does spacing of math with long subscripts, e.g. for sums, work? Can it be changed?

With the following math

$ sum_(k=N-log_2(N))^N 2^(-k) $ 

The distance of the actual Sum operator 2^(-k) to the sum symbol seems quite far. This is cause of the long index.

Question:
How does typst calculate the distance based on the main character (sum) or the “farest away” character that inherates from the main character?
Is it possible to avoid this and place the base near the operation(sum)?

You can use place() for the index to ignore the width of the index for the spacing around the sum. To recover the correct font size and spacing in the index, you have to use the script() function.

With the current anchor horizon + center the vertical index position is not perfectly recovered. If this bothers you, you can use the parameter dy to adjust this.

#let index(body) = place(horizon + center, $script(body)$)
$ sum_(index(k=N-log_2(N)))^N 2^(-k) $

thanks that will work, a bit hacky but it will fit the use case. Appreciate it :)

Using place seems more elegant, but there’s a separate implementation here Smashoperator Analogue - #4 by Eric

This will reduce space under the expression. Either it’s not a big deal, or you would have to compensate this with something like a show-set rule for equation-block or v.

Code
$ sum_(k=N-log_2(N))^N 2^(-k) $

#lorem(50)

#let index(body) = place(horizon + center, $script(body)$)
$ sum_(index(k=N-log_2(N)))^N 2^(-k) $

#lorem(50)

image