Syntactical parentheses for precise positioning of superscripts and subscripts?

Hello!
In Typst, parentheses are used both syntactically for grouping and literally as output. Is there a way to tell Typst not to use some parentheses literally?
In LaTeX, braces are used to control grouping. This allows fine-grained control of superscript and subscript positions like this:

\documentclass[12pt]{article}
\begin{document}

$f^a_b$
${f^a}_b$
${f_b}^a$

\end{document}

Yields
image
Which could be used to express meaning, for example in differential geometry.
In Typst, if I try to mimic this behavior, I get literal parentheses in output. See Typst

You can use the same trick as in How to combine italic text with superscript in mixed content? - #2 by Andrew.

$f^a_b$
$f^a""_b$
$f_b""^a$

image

Hello! That’s a workaround, but with a big downside: it doesn’t work for taller content.

$
  (integral x upright(d)x)^1""^2
$

(btw the real use case is

We say $f in T^(p, q)_X$ is homogeneous of degree $k$ if $t^k f = ((dot.c t^(-1))_*)^p times ((dot.c t)^*)^q f$.

Thanks @caby-b for the answer!

$f^a_b std.box(f^a)_b std.box(f_b)^a$

Yeah, the box isn’t really a math element, so feels even more hacky.

You can also do

$f^a_b #box($f^a$)_b #box[$f_b$]^a$

// #let box = box
#import std: box

$f^a_b box(f^a)_b box(f_b)^a$

A fairly nice solution is

$ scripts(f^a)_b $

This will not create an additional grouping container, it will just let Typst know to prefer scripts over limits and implicitly avoid automatic attachment merging.

4 Likes

That method isn’t perfect though.

$ scripts(scripts(f^a)_b)^c $

When multiple layers appear, the size continues to grow. I don’t know how LaTeX handles this under the hood.

1 Like