How to align comments in a Mathematica laptop?

I do not know if this was asked earlier or not. Simple formation. I noticed that it is sometimes difficult to match comments (----) on top of each other. There must be a problem with the font type. It just looks a little better on the screen if I can get things to align exactly on top of each other. Here is an example:

(* *) (* LEFTPANEL *) (* *) 

But actually it looks in front of me on a laptop:

enter image description here

If I move *) in the second line, one place to the left becomes the following:

enter image description here

Thus, he cannot level it. I use a cell of type Input (standard cell).

I cannot use another type of cells, like Code or such. I was wondering if anyone knew about this trick in order to achieve alignment.

thanks

EDIT 1: Displays the font used by the input cell in the stylesheet

enter image description here

EDIT 2: Using the code shown below by Alexei Popkov, the font for comments has been fixed, and now they are easily aligned. Here is a screenshot enter image description here

EDIT 3:

Well, the party didn't last long. Using SetOptions is not allowed in the demo. Too bad, because Alexei's solution worked well and made the comments aligned and looked better.

Anyway. In fact, it doesn’t matter. can live with small inconsistent comments :)

enter image description here

+7
source share
2 answers

I have no such problem with my Mathematica 7 installation, because by default for cells with Input style the Courier New monospace font is used. But if for some reason the non-monospace font is used in your installation by default, you can override the comment style inside the Notebook to use a monospace font:

 SetOptions[EvaluationNotebook[], AutoStyleOptions -> {"CommentStyle" -> {FontWeight -> Plain, FontColor -> GrayLevel[0.6`], ShowAutoStyles -> False, ShowSyntaxStyles -> False, AutoNumberFormatting -> False, FontFamily -> "Consolas"}}] 
+2
source

I have never worried about this before, as I only use inline (* -- *) comments for small comments or code for comments. If I need a multi-line comment, I would split my code into smaller parts and use text cells.

However, you can try using \[AlignmentMarker] in the rightmost *) :

 1 + 2 + 3 + (* First three \[AlignmentMarker]*) 4 + 5 + 6 + (* Next three \[AlignmentMarker]*) 7 + 8 + 9 (* Last three \[AlignmentMarker]*) 

Displayed as

screenshot


Edit in response to comment:

If you have comments between the code (without the code on the left), then perhaps put it in a GridBox (created using Ctrl-Enter and Ctrl-, ), which is commented out using (* ... *) in a white font.

Gridbox

It is hard to give the code to do the above ... but here is the Box form:

 Cell[BoxData[ RowBox[{"Manipulate", "[", "\[IndentingNewLine]", RowBox[{RowBox[{RowBox[{"a", " ", "=", " ", RowBox[{"x", "+", "1"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{StyleBox["(*", FontColor->GrayLevel[1]], "", GridBox[{{"(*", RowBox[{"Inter", "-", RowBox[{"code", Cell[""]}]}], "*)"}, {"(*", "comments", "*)"}}, GridBoxAlignment->{"Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}], " ", StyleBox["*)", FontColor->GrayLevel[1]]}], "\[IndentingNewLine]", RowBox[{"{", RowBox[{"a", ",", SuperscriptBox["a", "2"]}], "}"}]}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{"x", ",", "0", ",", "1"}], "}"}]}], "]"}]], "Input"] 
+7
source

All Articles