#Aligning superscript and subscript when not a function

8 messages · Page 1 of 1 (latest)

stuck willow
#

This is sort of a continuation of this question. However, in that question, the problematic superscript was being added through a function, so the function could inspect the content and handle the superscript accordingly. I just want to add a superscript directly:

#let frobnorm(x) = $norm(#x)_upright(F)$
$ frobnorm(A)^2 $

I know I could just make a function like

#let pow2(it) = {
  if it.func() == math.equation {
    it = it.body
  }
  if it.func() == math.attach and it.has("b") {
    $it.base_it.b^2$
  }
  else {
    $#it^2$
  }
}

but to me, frobnorm(A)^2 is both more writable and more readable than pow2(frobnorm(A)). The other question is kind of old so I was wondering if there's any update to how the expected spacing can be achieved?

Discord

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

#

?render

#let frobnorm(x) = $norm(#x)_upright(F)$
#let pow2(it) = {
  if it.func() == math.equation { it = it.body }
  if it.func() == math.attach and it.has("b") { $it.base_it.b^2$ }
  else { $#it^2$ }
}
$ frobnorm(A)^2 "vs" pow2(frobnorm(A)) $
spiral cedar
# stuck willow ?render ``` #let frobnorm(x) = $norm(#x)_upright(F)$ #let pow2(it) = { if it.f...

?render

#let frobnorm(x) = $norm(#x)_upright(F)$
#let pow2(it) = {
  if it.func() == math.equation { it = it.body }
  if it.func() == math.attach and it.has("b") { $it.base_it.b^2$ }
  else { $#it^2$ }
}
#show math.attach: it => {
  if it.has("t") and it.base.body.func() == math.attach and it.base.body.has("b") {
    $it.base.body.base_it.base.body.b^it.t$
  } else {
    it
  }
}
$frobnorm(A)^2 "vs" pow2(frobnorm(A))$
spiral cedar
#

This does something similar to the pow function but for every occurrence of attach
This if-condition is so specific that it probably won't match anywhere where it's not intended

stuck willow
#

This is perfect, thank you so much! 🙌

spiral cedar
#

You're welcome :)