0

Possible Duplicate:
Matching brackets in a string
Is there a way around using [[ and ]] for Part in Mathematica?

OK, today looks like the day for asking typesetting questions!

This is something I always wondered if there is a solution for. Many times, I write Part notation just the normal way like this x[[3]] but what I prefer is the solid notation, which is

enter image description here

The reason I do not enter it as above the first time, is that it is faster to type x[[3]] because I do not have to type x ESC [[ ESC 3 ESC ]] ESC each time, and also many times I simply forget.

Then what I do, is later on, I go over the whole code looking for each normal [[ ]] and then change it to the solid [[ ]] . But this is boring.

I tried to use the editor to do a replace every [[ with the solid [[ and then replace all every ]] with the solid ]] but that did not work. It broke the code.

So my question is: Is there a way to automatically do this change? It would require lexical scanning and analysis of the code, as one can just change any [[ seen with a solid [[.

Thanks

Community
  • 1
  • 1
Nasser
  • 12,459
  • 6
  • 43
  • 98
  • 1
    Also: http://stackoverflow.com/questions/5461688/how-do-i-get-auto-conversion-of-part-double-brackets-on-paste and http://stackoverflow.com/questions/5776158/matching-brackets-in-a-string – abcd Dec 14 '11 at 04:21
  • 1
    You can't simply replace every `]]` with `〛`, because there are ways it can crop up other than by using `Part`, which is why it broke your code. For e.g., `f[a,g[b]]`. See the discussions in the above links – abcd Dec 14 '11 at 04:27
  • This is not a duplicate question and you should not have been so quick to down vote it. I am asking for a batch replacement. I know about the short cuts, but that is not my question. If there is no possible way to do this automatically, then fine. I am just asking. – Nasser Dec 14 '11 at 04:31
  • You could use **Cell > Convert To > StandardForm**, but that will affect a lot more in addition to the `Part` notation. – Brett Champion Dec 14 '11 at 04:32
  • 1
    Nothwithstanding Yoda's links I always use convert to standard form but rather than use keystrokes I just use the contextual menu -- this saves some micro joules of energy. So anywhere in your cell right click and choose CovertTo > StandardForm. Brett mentions that this does many other things. Of those many other things the main drawback IMO is that it deletes comments. – Mike Honeychurch Dec 14 '11 at 04:39
  • @NasserM.Abbasi Please explain how this is _not_ a duplicate of any of those 3 links. I voted to close this as a duplicate, as did another user at this point (hopefully, an mma user). As for the downvote, it could've been anyone. Perhaps you shouldn't be so quick to point fingers at people the next time ;) – abcd Dec 14 '11 at 04:39
  • @BrettChampion. thanks, I know about this, but as you said, this will change everything, I just want all the [[ ]] in the code changed only. – Nasser Dec 14 '11 at 04:41
  • @yoda: I'd argue that this question is distinct enough in that NasserM.Abbasi is looking for a way to change *existing code in a notebook* to use the single character version. If it were code that he was about to write or copy-paste, then yes it is a duplicate of those two questions. – Mike Bailey Dec 14 '11 at 04:43
  • @yoda, the links to the questions you have do not answer my question, and they are not the same. Those ask how to enter the solid [[]] quickly. I am asking something different, which is batch replacement. But if you really want to close the question, feel free to do so. – Nasser Dec 14 '11 at 04:45
  • 1
    Nasser & @MikeBantegui: [Mr.Wizard's question](http://stackoverflow.com/questions/5776158/matching-brackets-in-a-string) on matching the brackets correctly does exactly that. Parsing it correctly boils down to counting the brackets and keeping track of them correctly, especially for `]]`. You can use a solution from there, clean up and package into a function and run it on your block of code. You might have to wrap some `HoldForms` and use `ToExpression`/`ToString` etc. where ever necessary, but otherwise, it's the same. – abcd Dec 14 '11 at 04:51
  • @Nasser, I don't take pleasure in closing. Admittedly, I think it's a duplicate and I've voted as such. Note that it takes 4 other users to agree with me for it to actually be closed. – abcd Dec 14 '11 at 04:52
  • @yoda: Taking a look at Mr. Wizard's question, I'd have to agree. I must have missed that when I was reading the comments. – Mike Bailey Dec 14 '11 at 05:02
  • I agree with @Yoda, it is an exact duplicate. However, the (closed) question will form a useful reference so that hopefully the question does not get duplicated again. – Simon Dec 14 '11 at 06:36
  • 1
    Nasser: You question mentions that you don't like typing `ESC [[ ESC`, neither do I. So I modified my [KeyEventTranslations.tr](http://stackoverflow.com/a/7327476/421225) file to include ``Item[KeyEvent["[", Modifiers -> {Control}], FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], "\[LeftDoubleBracket]", After]}]], Item[KeyEvent["]", Modifiers -> {Control}], FrontEndExecute[{FrontEnd`NotebookWrite[FrontEnd`InputNotebook[], "\[RightDoubleBracket]", After]}]]`` – Simon Dec 14 '11 at 06:46

0 Answers0