I would love to be able to use the power of Mathematica's patterns to find and replace within my code. I have searched for this on google, and so far I've come up with this: http://reference.wolfram.com/workbench/index.jsp?topic=/com.wolfram.eclipse.help/html/tasks/patterns/findreplace.html
Which seems to suggest that I would need another program, Mathematica Workbench, to do so? Can anyone explain what this is to me? I guess this would involve paying some money to Wolfram
I also had a go with the code written in this thread. It seems to work part of the time, but has some undesirable features (or at least, undesirable to me!).
I want to replace all instances of k[i_] with Subscript[k,i] in my code (and I'm sure I would use this for more complex things later on too if I can get it to work now). Here are the current problems that I have, when I run NBReplace[k[i_ ], Subscript[k,i]]
*) Not all cases of k[_] are covered in my code. I can't see why this would be. I don't understand the code for the function in detail, but it looks to me like it should cover all cases
*) The code currently replaces k[_] with k\_Subscript\_i. I guess maybe I need to change an 'InputForm' somewhere to something else? Or I need to get rid of the code that's changing things to be strings?
*) The code replaces the k[_] in the function call itself, how can I make an exception for this cell?
Any help would be greatly appreciated
InputForminside theNotebookWritecall toStandardForm. Also, please use code blocks for your code, not $\LaTeX$ markup. – Oleksandr R. May 22 '16 at 01:49NBReplacethat specifies the notebook, rather than usingSelectedNotebook[]to operate on the current one. – Oleksandr R. May 22 '16 at 01:58momcononshell4d = {k[1]\[CircleDot]k[2] -> s, k[3]\[CircleDot]k[4] -> s, k[1]\[CircleDot]k[3] -> t, k[2]\[CircleDot]k[4] -> t, k[1]\[CircleDot]k[4] -> u, k[2]\[CircleDot]k[3] -> u};– Jojo May 24 '16 at 10:17momcononshell4d = {k[1]\[CircleDot]k[2] -> s, k[3]\[CircleDot]Subscript[k, i] -> s, Subscript[k, i]\[CircleDot]Subscript[k, i] -> t, Subscript[k, i]\[CircleDot]Subscript[k, i] -> t, Subscript[k, i]\[CircleDot]Subscript[k, i] -> u, Subscript[k, i]\[CircleDot]Subscript[k, i] -> u};– Jojo May 24 '16 at 10:19k[_]here have been covered by the code. If this is still unclear please explain why and I will try to further elucidate what I mean – Jojo May 24 '16 at 10:21momcononshell4d={Subscript[k, 1]\[CircleDot]Subscript[k, 2]->s,Subscript[k, 3]\[CircleDot]Subscript[k, 4]->s,Subscript[k, 1]\[CircleDot]Subscript[k, 3]->t,Subscript[k, 2]\[CircleDot]Subscript[k, 4]->t,Subscript[k, 1]\[CircleDot]Subscript[k, 4]->u,Subscript[k, 2]\[CircleDot]Subscript[k, 3]->u};You would be better off to add this example to the question and to change all equation markup to code blocks at the same time. – Oleksandr R. May 24 '16 at 12:43iwith the correct number. I'm very surprised this works for me and not for you. I have tried justCases[HoldComplete[k[1]], target : k[i_] :> (target -> Subscript[k, i]), Infinity]!to try to abstract out the part of the code that isn't working, and it gives{k[1] -> Subscript[k, i]}as the output, not replacingi. Do you know why this is? – Jojo May 24 '16 at 13:02NotebookFindfunction, instead of the specific case which is being considered at the point that the code encounters it? Thanks again for your help – Jojo May 24 '16 at 13:03{k[1] -> Subscript[k, 1]}for me, as it certainly should. Maybe you have some invisible characters or other structures in your notebook. – Oleksandr R. May 24 '16 at 13:07Table[\n k[i], {i,5}], where the \n is a newline in my notebook, which is necessary for the problem to arise. NBReplace doesn't replace inside this statement, and the error I get isSyntax::sntxf: "Table[ " cannot be followed by "k[i], {i, 5}]", even though what I've written is valid Mathematica code. Do you know why it doesn't like this? – Jojo May 25 '16 at 09:53