How to make underbrace and attach not waste so much space?

I sometimes have code like this:

$ underbrace(x times y, "trivially" 0 "because some long stuff") A attach(=)^"another long explanation" 0 $

and I really don’t like the spacing.

I’ve found this solution, but is there some general solution you can use for stuff above and below?

It sounds like you want something similar to \clap in LaTeX, which one could implement with pad:

#let clap(it, x: 0pt, top: 0pt, bottom: 0pt) = context {
  let w = measure(it).width
  pad(x: -w/2 + x, top: top, bottom: bottom, it)
}

$
  underbrace(
    x times y,
    #clap[trivially $0$ because some long stuff]
  )
  A attach(=)^#clap(x: 2em, bottom: 0.5em)[another long explanation] 0
$

image

The x and bottom arguments in the second #clap call are used to add some padding to make it look less awful.

Compared with the place solution in the linked thread, this solution with pad will maintain the vertical spacing taken by the underbrace annotation.

3 Likes

Ok this works mostly, but for example on

$ min brace underbrace(norm(x)_2^2, = norm(x - 0_n)_2^2) | underbrace(norm(x)_2^2 leq norm(y)_2^2, "überflüssig"), x in cl(M)} $

When I use the clap function, it just looks like a line underneath

The information about the parent equation’s size (display, inline, script, sscript) is lost for nested equations when they are wrapped in non-mathy elements such as pad, box or block. This is also visible in @sijo’s reply where the $0$ is shown in the larger inline size instead of the intended script size. You can explicitly set the size though by replacing the it in the clap function with $script(it)$.

See also my reply in Smashoperator Analogue - #4 by Eric for a similarly defined clap function.

2 Likes

You can drop attach().

1 Like