Whenever I type multi-line comments in Mathematica, the standard editor automatically performs indentation. I find the indentation rather curious and annoying, with some example frustrations posted below:

enter image description here

(note that I did not add any tabs or spaces in the top comment, and that there is NO linebreak after the comma in the bottom comment).

What is the reasoning behind this convention for formatting / indenting? Are there any best practices for writing comments/documentation that actually use the automatic indenting in a useful way?

Alternatively, is there a way to toggle the indentation off for comments, while keeping indentation for regular code?

(related: https://groups.google.com/forum/#!topic/comp.soft-sys.math.mathematica/_mVsK6hDPao)

  • 1
    $\begingroup$ The notebook approach favors putting long descriptive comments into text cells next to the input cells they document. $\endgroup$
    – John Doty
    Jan 16, 2019 at 13:47
  • 3
    $\begingroup$ You can use Code cells, no auto indentation no problem. $\endgroup$
    – Kuba
    Jan 16, 2019 at 15:56
  • 1
    $\begingroup$ Or you use the standard Wolfram code editor for larger code, the so-called Wolfram Workbench. Again, nearly no pain there (well, at least with comments). $\endgroup$ Jan 16, 2019 at 16:30
  • $\begingroup$ Or use @halirutan's lovely plugin for IntelliJ. Or use a "Package" notebook. Best practice for the FE, I'd say use a package notebook and use some kind of block indent scheme. $\endgroup$
    – b3m2a1
    Jan 16, 2019 at 19:48
  • $\begingroup$ Thanks for the useful comments! I figure the main conclusion is that 1) thanks to Code Cells (either in "Package" or regular notebooks) and Text Cells, multi-line comments in regular Input Cells should rarely pop up. And 2), whoever is still unhappy with the current behaviour could use a different editor. $\endgroup$
    – Koen
    Jan 17, 2019 at 17:02


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.