Spaces around binary operators in superscript

I’m wondering how to get “the right” operator spacing in a superscript?

$e^(i(omega t - k' x' + l' y'))$

$i(omega t - k' x' + l' y')$

As you can see, there is no space around the binary operators when they are in the superscript. As a result, there is visually more space between k' and x' than between and k'.

Perhaps is there an “exponentiation” function as a separate function from the superscripting function ^ ?

I don’t want to be adding a pair of thins for each binary operator . . .

Indeed in scripts there is less spacing around binary operators than in full size. That’s how math is usually typeset (it’s the same in LaTeX) but I agree it looks weird in this example, though I would “blame” the prime for the added spacing more than the + for lacking space.

I don’t think there’s a reliable way to adjust the spacing automatically for “prime followed with binary operator”. And there’s also no way to detect in a show rule if you are in script or not.

You could add a general rule to remove spacing after prime:

#show sym.prime: x => x + h(-0.2em)

but there’s a reason why the spacing is here (for example with the above rule the primes almost touch the closing parentheses which looks bad).

Or you could add a show rule for attach, to apply some rules to all the attachments. For example, using an ugly hack to avoid infinite recursion:

#let spaced-plus(it) = {
  show sym.plus: x => h(0.2em) + x + h(0.2em)
  it
}

#show math.attach: it => {
  if bibliography.title == [x] { return it } // avoid infinite recursion
  let (base, ..rest) = it.fields()
  set bibliography(title: [x])
  math.attach(
    base,
    ..for (k, v) in rest { if v != none { ((k): spaced-plus(v)) } }
  )
}

$e^(i(omega t - k' x' + l' y'))$

image

but it’s still not balanced (with the prime’s extra spacing), and you have to do the same for every operator (like minus which is not handled here) and I’m sure this solution will introduce issues of its own.

In such cases I find it far cleaner and more robust to add some thin spaces manually at the right places, as unsatisfactory as it may be.

There is a predefined exp operator if that’s what you mean.

1 Like

I’ve compared a comparable output from LaTeX and I found Typst’s output is weirder. The spacings around the binary operators aren’t as much reduced as in Typst. I’ve been using LaTeX for 30 years and am lately exploring Typst. I’ve never noticed this reduced spacing problem in LaTeX.

But I’ve already shown you the inline version $i(omega t - k' x' + l' y')$, which doesn’t look weird because there is ample spacing around the binary operators.

As a test, please remove the primes and see the result. It still looks weird. Typst needs a little bit more around-operator space in scripts!

I intend to ask the prime-spacing problem in another thread. Please let us come back to my original question: How to increase the around-operator spacing in an exponent? There must a global setting.

Sorry I wasn’t clear. As you say, there is less spacing in scripts. Therefore, I imagined a function expotentiate(e, i (omega t - k' x' + l' y') ) to typeset the “raised” math using normal spacing rules.

Here’s with LaTeX (TeXLive 2024 with pdftex):

\documentclass{article}
\usepackage{amsmath}
\begin{document}
$e^{i(\omega t - k' x' + l' y')}$
\end{document}

image

And Typst (using the same font weight as LaTeX for comparison but it doesn’t really make a difference):

#show math.equation: set text(weight: "regular")
$e^(i(omega t - k' x' + l' y'))$

I cannot really see the difference…

I don’t think there’s one… You can submit a feature request on the GitHub issue tracker.

I see… there’s no such function currently.

2 Likes