Different math attach alignment when adding "br" and/or "tr"?

In the following example, the subscripts “T” in the middle have a different height. It seems typst aligns the bottom of the letter “C” (the blue line), but it really looks weird when the “T” letters are not aligned.

Is this wanted behavior, that attachments change their position when adding other attachments?

Code to reproduce:

#import "@preview/mannot:0.3.0": markul

#set text(
  font: "New Computer Modern",
  size: 100pt
)
#show math.equation: block.with(stroke: 1pt + red)
$
  #markul($$, outset: (bottom: 2.7pt, right: 4em), stroke: 1pt + blue)
  attach(C, bl: upright(T), br: upright(T))
  #h(-0.16em)
  attach(C, bl: upright(T), br: upright(T), tr: and)
$

Hi, welcome to the forum!

I guess this is intentional. It avoids the superscript and subscript from covering each other.
In LaTeX (with the font Computer Modern, not new), the effect is even more visible:

C_T C^a_T C^g_T

With that said, you can use Hide Function – Typst Documentation to make them aligned.

#import "@preview/mannot:0.3.0": markul

#set text(
  font: "New Computer Modern",
  size: 100pt,
)
#show math.equation: block.with(stroke: 1pt + red)
$
  #markul($$, outset: (bottom: 2.7pt, right: 4em), stroke: 1pt + blue)
  attach(C, bl: upright(T), br: upright(T), tr: #hide(sym.and)) // 👈 Here
  #h(-0.16em)
  attach(C, bl: upright(T), br: upright(T), tr: and)
$

1 Like

thank you for your extensive reply.

I did not know that LaTeX does this the same way. But I guess it makes sense that way.

Also thank you for the suggestion. I thought of using the Place Function, but it was hard to make it perfectly aligned. The solution with the hide function seems better.

The only problem is that I have to adjust every equation by hand :slightly_frowning_face: but this is fine for me

1 Like

Depending on your use case, you can do let attach = math.attach.with(tr: hide($and$)) and then use this override everywhere.

this is also a good suggestion, but a global override has side effects like turning the following equation


into

Maybe one can come up with a more sophisticated version, but I think it requires iterating the whole equation for attach functions and inserting hidden elements depending on the context. Just overwriting attach leads to side effects. E.g. also when having nested attach calls

Thus, not fitting the use case. But also this can be reverted with let attach = math.attach, or by defining the override inside a narrower nested scope.