12

Is there a way I can "find and replace" text inside equations?

e.g.: I need to replace all $\hat v$ by $v$.

Since MathJax doesn't work here: Replace a "v with a ^ on top" by a "v".

Pedro77
  • 1,861
  • 8
  • 31
  • 41
  • Word uses different character codes for math variables than for normal writing. You can use `Alt+X` to find the character code of a character, then type that character code into the search box and use `Alt+X` again to find it. See https://superuser.com/questions/1127176/how-to-replace-characters-in-math-equations-in-microsoft-word – user7868 Jun 25 '21 at 00:50

2 Answers2

9

There is, but with limitations, and it's clumsy.

  1. Change all your equations to "Linear" (instead of "Professional").
    • For example, select all, go to the Equation tab, and click "Linear" on the left side.
    • Caution: Professional->Linear->Professional doesn't necessarily leave your equations unchanged. I have noticed that MathML imports from MathJax-node often change when I round-trip this way. Test your equations before you do a bulk conversion, or make backup copies!
  2. Within one of your Linear-mode equations, select the text you want to find (v^ for $\hat v$ in linear mode).
  3. Hit Alt+F11 to get to the VBA editor
  4. Hit Ctl+G to get to the Immediate pane
  5. Type/paste in this line and hit Enter:

    Selection.Find.Text=Selection.Text
    

    This copies the exact text you have selected in the equation into the "Find what" field of the Find dialog. A normal copy/paste won't work because you will get the normal text equivalents of the equation characters. Selecting text outside of an equation also won't work, for the same reason.

  6. Close the VBA editor and go back to Word.
  7. Hit Ctl+F. You will see that the "Find" box is filled in with the equation symbols, e.g., v^. As long as you don't change that text, you can hit Find Next to go to the next equation that (1) contains exactly that text and (2) is in Linear mode. It doesn't work for me if the equations are built up ("Professional") mode.
  8. When done searching, change your equations back to Professional mode.

A reason Find doesn't work in equations like it does in body text is that the symbols in new-style equations are not the same as the corresponding symbols outside of equations. See Unicode Tech Note (UTN) #28 for the exact symbols and Unicode codepoints used for operators, and Charbase's list for the codepoints used for script characters.

cxw
  • 1,689
  • 1
  • 16
  • 27
  • This works! I have searched for this everywhere and finally found it! With a little macro programming this process can be done automatically and works like a gem! – Tony Jun 16 '17 at 18:17
  • @Tony glad to hear it! Would you be willing to post your macro as an additional answer for the benefit of future readers? I will cheerfully upvote it :) . Thanks for the feedback! – cxw Jun 16 '17 at 19:33
  • A detailed answer, indeed. And the last paragraph is actually sufficient for some uses, just copy and paste a specific Unicode symbol into the search field. – Maxim Yurkin Sep 02 '22 at 07:17
0

I found out that, inside the equation, you can change some pieces of it to "Regular text" (I don't know if this is the translation used by Microsoft, I'm a Spanish user and for us it's "Texto normal"). This way you can use find and replace directly.