0
$\begingroup$

This question has probably been asked before, but I cannot find it.

Before I used mathematica I have worked with VisualStudio from MS (C++), Python (PyCharm), Java (Eclipse, NetBeans).

In all that IDEs it is possible to format the source code, so that is easy readable.

In mathematica I am looking for a solution which makes out of the following example code:

Do[x = i; Do[y = j; Do[z = k;, {k, 1, 3}];, {j, 1, 3}];, {i, 1, 3}]

the formatted code:

Do[
   x = i; 
   Do[
      y = j; 
      Do[
         z = k;
         , {k, 1, 3}
      ];
      , {j, 1, 3}
   ];
   , {i, 1, 3}
]
$\endgroup$
  • 2
    $\begingroup$ use code cell instead of Input cell if you want to be able to format the code as you want without the notebook forcing its own rules. There is no build-in pretty formatter in the official notebook interface. (may be Wolfram workbench has one, I do not use it). But not needed if one uses the Input cell. $\endgroup$ – Nasser Sep 25 '16 at 7:57
  • $\begingroup$ Do I have to right click to the cell and select Style->Code? How is then my example one-liner formatted? $\endgroup$ – mrz Sep 25 '16 at 8:01
  • 2
    $\begingroup$ Programmatic formatting for Mathematica code - possible? $\endgroup$ – Kuba Sep 25 '16 at 8:02
  • 1
    $\begingroup$ I mean you can do right-click then InsertNewCell-> and select 'code' Now you can write free format. I.e. you can format the code manually as you want. $\endgroup$ – Nasser Sep 25 '16 at 8:03
  • $\begingroup$ Ok. So it is not possible later on to reformat a whole code block. I have to check Kubas link. $\endgroup$ – mrz Sep 25 '16 at 8:04

Your Answer

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

Browse other questions tagged or ask your own question.