Unfortunately, I have to convert code created by mathtype into real latex code. My converted creates hideous expressions like

\textstyleMTConvertedEquation{{\textbackslash}[\{X\_k\} {\textbackslash}equiv {\textbackslash}left(
\{\{X\_\{1,k\}\},...,\{X\_\{n,k\}\}\} {\textbackslash}right){\textbackslash}]}

I would like to globally convert expressions like these to latex code, by replacing the matched curly braces with $'s. Obviously, the % character will match up the braces but I don't know how to incorporate this fact into a global command, i.e., I'd like to construct a command of this form, but don't know how to identify the matched brace.

:g/\\textstyleMTConvertedEquation{.*<matched brace>/s//\$\1\$/g

Thanks for any suggestions!


I am not sure if I understand you correctly and you didn't provide an example, how it is supposed to look afterwards. So here is how I would do, what I think you want to be done:

:g/\\textstyleMTConvertedEquation{/:exe ":norm! 0dt{c%$\<C-R>\"$"

You might need to remove the extra brace before/after the '$', which could be done in a single step like this:

:g/\\textstyleMTConvertedEquation{/:exe ":norm! 0dt{c%$\<C-R>=getreg('\"')[1:-2]\<CR>$"
  • Thanks, this is great, Christian. One question: I can't seem to find an example in which the addition of the exclamation point after norm is actually necessary. It doesn't appear to be in this case. Could you give me an example please? – Leo Simon Sep 28 '15 at 15:21
  • Well, using :norm! rather than :norm protects you from mappings the user might have. For example, you don't know what the normal mode key d will be mapped to and this would break your :g command, if the keys work differently. Therefore use the :norm! command, so that mappings never will be taken into acount. – Christian Brabandt Sep 28 '15 at 15:26
  • One more question, Christian? For some reason I don't seem to be able to modify the above to make the changes for a specific range. For example, I would expect the following to work :.,$/\\textstyle etc, but I get a "no range allowed error. So my question is, how can I do the above type of construction: /pattern/:exe for a specific range? Thanks! – Leo Simon Oct 10 '15 at 23:52
  • If you need a range, you can add the range to the :g command. – Christian Brabandt Oct 11 '15 at 7:37
  • I've been trying to use this syntax with a regular expression, but I can't get it to work, specifically g/\\001/:exe "norm! 0dt[a-zA-Z]" which I would have expected to delete from the beginning of each line to the first occurance of an alphabetic character, but it doesn't work. Could you advise please? – Leo Simon May 14 '16 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.