How to set exponent baseline for a specific character?

Hi,
I have a document with muliple occurences of $x^2^p$. I find that as is, the equation looks ambiguous and could be interpreted as $x^(2p)$. So, to avoid ambiguity, I would like to raise the exponent by a few pixels.

I came up with this solution:

#show math.equation: it => {
  show "p": i => text(baseline: -2pt)[p]
  it
}

This solution fixes my problem, but introduces a new one, that is that every p (even those not in the exponent) are now awkwardly shifted up.

Does anyone have suggestions for how to fix this? TIA!

Edit: Also, I realise I could make a special “raised” glyph and use that instead of p. This would work, but I am trying to avoid re-writing large parts of the document.

Alternatively, I wouldn’t bother trying to shift up and down the attachments. I think it would be more straightforward, and clearer to the reader if you just write

$(x^2)^p$

instead

That is not what I am trying to achieve. Recall that

$x^2^p = x^(2^p) != (x^2)^p = x^(2p)$

I understand that, I am suggesting an alternative solution that does not require complicated scripting for the maths. You can simply remove the ambiguity by writing either (x^2)^p or x^(2^p)

Unfortunately, this fix still does not work for me.

Not only does

x^2^p

Render exactly the same as

x^(2^p)

But adding more parentheses

x^((2^p))

Still runs into the same ambiguity, just with more parentheses. Maybe it’s an issue with the fonts I am using, but I find that it is ambiguous even with the default font.

Ah indeed, testing with x^((2^p)) (need to add more parenthesis because of ^(...)'s syntax, the difference isn’t so clear

image

How about this?

$x^(2#super(baseline: -1em, $p$))$

image

Thanks. It works, but is a bit annoying to use. If no-one comes up with an automated way of achieving this, i’ll use your technique.

It’s perfectly possible to automate it to a certain extent, you just need to write a show rule like you did in your first try. The most difficult part is getting rid of edge cases, because you don’t want to replace all p, just 2^p probably. I would just suggest using a variable

#let 2p = $2#super(baseline: -1em, $p$)$
1 Like

Another option is to create a function. This is not as convenient as a show rule when writing the document, but has the benefit of only ever affecting things that it should (no false triggering of the show rule)

#let eexp(v) = {
  let (low, mid, high) = v.split("^")
  return $#low^(#mid#super(baseline: -1em, $#high$))$
}

$#eexp("x^2^p")$

$w=2#eexp("a^b^c")$
Output

image

1 Like