3

I have a long math file where $$ $$ was used for display math. I want to change these to \[ \] to make it look neater. I don't know whether I can use the find/replace function in TeXworks to alternate between replacing by \[ and \], and I'm not enough of a programmer to solve this with a batch program.

Is there an easy fix?

  • 3
    This is perhaps a job better suited for sed or perl. I am sure, there are scripts for this on the net, which can be called from TeXWorks. Welcome to TeX.SX by the way;-) –  Jun 05 '15 at 18:18
  • 2
    You could also do it with Python (see e.g. this question). You can search with your favorite search engine using the keywords language (python, perl, etc.) and replace odd occurrences (or alternating string replace). But depending on the length of you document, it could be worth doing it by hand. – anderstood Jun 05 '15 at 18:24
  • 1
    Try regular expressions. Are you on a windows system? – Bernard Jun 05 '15 at 18:36
  • 1
    I don't think there's an easy answer without programming. I think if you use find/replace this way: find/replace ($$ with \[ ) on every other case (manually clicking to the other case) and then ending with find/replace all ($$ with \]) it wouldn't take that long. A lot of mindless clicking though... – DJP Jun 05 '15 at 18:38
  • A related posting: Can I get $$…$$ to behave like \[…\]? If you can run LuaLaTeX instead of pdfLaTeX, you may be able to leave all $$ unchanged -- and let a Lua function replace the $$ symbols intelligently, "on the fly", with either \[ or \]. – Mico Jun 05 '15 at 18:39
  • If you use vim then you can define two macros, one and two, so that one changes the next $$ to \[ and calls two and then two changes the next $$ to \] and calls one. You can also use multi-line regular expressions but they are more prone to fail on corner cases. –  Jun 05 '15 at 19:02
  • Texworks can find and replace regular expressions, see http://tex.stackexchange.com/questions/99703/how-to-replace-with-command-in-texworks – Alex Jun 05 '15 at 19:43

0 Answers0