Skip to main content
Participant
March 14, 2024
Question

GREP for formula superscript

  • March 14, 2024
  • 3 replies
  • 538 views

Hello, 
may anyone help to convert X^(2-x)(4-x) + 18y to the part after ^ in superscript (only this part: "^(2-x)(4/6) " before +)?


This topic has been closed for replies.

3 replies

Community Expert
March 15, 2024

You say after ^ but then say only this part "^(2-x)(4/6)" before +

where ^ is part of what you want to find after?
Do you want to include the ^ or not?

 

Anyway if you want to include it 

(?<=\^)(\(.*?\)\(.*?\))(?= *\+)

 If you don't

\^(\(.*?\)\(.*?\))(?= *\+)
m1b
Community Expert
Community Expert
March 14, 2024

Hi @Eunice36085839l2u9, this is one of those questions that is easy to answer correctly, but the answer probably won't help you, because your example cannot capture the actuality.

 

But here's the easy answer, and maybe it will help.

 

\^\S+

 

If you put this into a grep style to trigger a "superscript" character style you will get this:

 

It simply makes everything superscript from the caret (^) onwards and stops before a space.

 

Do you want the caret removed? Probably. But if you do, the grep style won't work. But you could hide it like this:

Edit: I added a demo .indd file so you can look at this and type some formulas to test.

 

Or maybe you could use the greps I specified to do a Find/Change Grep to set a character style. That way you'd more-easily be able to override any false superscripts that occurred.

 

Another approach would be to look around for any online equation editors that could export as svg. I think there are some, but I don't know them off hand.

- Mark

Community Expert
March 15, 2024

That works except where if somewhere there was no space before the plus (4/6)+ the plus is found

m1b
Community Expert
Community Expert
March 15, 2024

Yep. If this method is to work, then probably some spaces would need to be added manually. Note that, for presentation purposes, they could zero-width or thin spaces.

James Gifford—NitroPress
Legend
March 14, 2024

I believe the only way to apply superscript would be by using a Character Style; that is, use GREP to select the superscript string and apply the style.

 

It may be difficult to write a GREP string that can distinguish the end of a complex string like that, though, unless there is some kind of consistent marker, separator or terminator, or the strings are consistent in format.