How to avoid consecutive subscripts to continue to "dip" in inline math?

I don’t know how to explain this clearly so here’s an example.

$(x_(n_k))_(k in NN)$, $(x_n)_(n in NN_0)$

The n_k is above the k in NN, while in LaTeX every subscript just stays on the same “level”.
I think this feature can look a bit messy when al lot of math is used in some paragraphs?

I’ve tried setting show-rules and looked at the docs of the sizing options but can’t make sense of this all.
Hopefully it’s clear and somebody can help, thanks.

Latex:


Typst:
subscript

Hello @Junot!
Typst automatically scales the delimiters according to the content’s size with left/right.

What happens here is that the attachment (lower right) is always relative to the size of the delimiter. The bigger the parenthesis, the lower “n_k” will be. You can read more about attach in docs.

Briefly, what you need to do is the following: attach the scripts to something else! For our purposes, we can use a zero width space (sym.zws) so it doesn’t affect the layout.

The resulting output looks like this:

$(x_(n_k))_(k in NN)$, $(x_n)_(n in NN_0)$

#show math.attach : it => {
  if it.base.func() == math.lr {
    let attachments = it.fields()
    _ = attachments.remove("base")
    it.base
    math.attach(sym.zws, ..attachments)
  } else {
    it
  }
}
$(x_(n_k))_(k in NN)$, $(x_n)_(n in NN_0)$

Note that this does not change the delimiter scaling, or affect further nested attachments. IMO this is a pretty safe way to do this. See

2 Likes

If you are fine with small parentheses, then just escape them. Document how to escape lr delimiter auto-scaling by Andrew15-5 · Pull Request #6410 · typst/typst · GitHub

$\(x_(n_k)\)_(k in NN)$, $\(x_n\)_(n in NN_0)$

image

Disabling delimiter auto-scaling doesn't change vertical position of attached subscripts · Issue #6486 · typst/typst · GitHub.

2 Likes

Thank you, that’s a good solution. I was thinking about the delimiters but didn’t know how to implement a solution like this. Thanks!

1 Like

This is also a very reasonable option, I like the way it looks. A small downside is just the “effort” of typing the escape characters for every time i need to want to have this result, especially because in this case I’m working on an already quite extensive document, to which editing all cases like this would be quite tedious (I know some good vim macros could come in handy but still :)…).

If Superscript text doesn't move down when parentheses scaling is decreased · Issue #5101 · typst/typst · GitHub is fixed in a certain way, then set math.lr(size: 1em) would be enough.

1 Like