1
$\begingroup$

When writing a Mathematica sentence (with default input style), you get your code written in a fixed-width font (Consolas, for instance, in Windows). However, small blank spaces are added to separate different parts of the code, and those spaces are variable-width, not fixed-width.

This happens even with comments; see what I mean:

enter image description here

Can this option be disabled, so that the code can be really aligned?


UPDATE

Actually, I really do not know whether they are extra small spaces or just a way in which the padding of characters is modified, but the result is what I tried to show above.

$\endgroup$
  • 1
    $\begingroup$ related: 156424 $\endgroup$ – Kuba Oct 16 '17 at 17:07
4
$\begingroup$

If you write code in Input cells, do not try to align it. Mathematica aligns it for you automatically. Also, do not use huge comment blocks. Use Text cells for long pieces of text.

If you want to align code yourself, use Code cells, not input cells. Automatic alignment and spacing is not active in Code cells.

See Format menu, Style, to insert a cell of a certain style. You can also use keyboard shortcuts. By default, Command-8 is a Code cell, Command-7 is a Text cell. On Windows/Linux use Alt instead of Command.


Personally, I use Code cells when I intend to copy the code into a plain text file, and need to control how it will appear there.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.