Everything is in the title. I have many LaTeX files written with the rather obsolete syntax $foo$ and $$bar$$ that I wish to convert respectively in \\(foo\\) and \\[bar\\]. I am using vim so I guess a regular expression will do but a script would also be perfectly fine. I have been looking around but without success.
Edit: following kirilloid's useful reply, I wish to mention to I would like to use this also in the case foo and bar are not only words, but expressions containing spaces (but no $s obviously).
Use
:%s/\V$$\v(\_.{-})\V$$/\\[\1\\]/g
:%s/\v\$([^$]+)\$/\\(\1\\)/g
Differences from @kirilloid answer are the following:
\v, disables need to escape most meta-characters) and very nomagic (everything but backslash have their literal meanings) modes for readability$$ strings (\_ adds newline to ., \_. is the only construct that really means any character, . does not include newline). {-} (\{-} in magic, nomagic and very nomagic modes) is the non-greedy variant of *.$: any but newline), but it requires for you to ensure that there $$ always starts outline formula and $ always starts inline one. You may want to restrict the replace to the lines where this is true by either replacing % in front of command with {first_line_number},{last_line_number} or selecting them visually, typing : ('<,'> will appear at the start of command line) and proceeding to type s/... command without leading :%.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With