# Mathematica front-end code alignment issue

I am having a frustrating recurring issue with the frontend (Mathematica 12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)).

I will have a notebook which works just fine, all lines evaluate. Next, I will close the notebook for the day, come back the next day, open the notebook and the code within a Module will be misaligned such that it does not run (see attached image).

I will fix the alignment issue, the code will run, then I will close the notebook come back and the same thing has happened.

Thus, every time I open the notebook I have to realign the code. This only seems to happen to code within a Module.

I am not an expert with Mathematica, but have used it for a few years now. I can't see what I am doing incorrectly as the code runs perfectly (repeatedly) once the notebook is opened and the alignment issue fixed. I can work on the code and it continue to work. The error then reappears when closing and reopening the notebook.

I read that 12.1.1 had some front end issues. Indeed, I was having some of these as well e.g. code randomly formatting as a Wolfram Alpha query.

Am I missing something obvious?

*** EDITS ***

Sorry about the spelling, despite being 41 I have difficulties in that area which I cannot overcome.

I avoided posting code as the whole notebook is very complex. Here is the module code:

(* Module for plotting for the PSE *)
minXpse = 51.9;
maxXpse = 58.1;
theRangePSE = maxXpse - minXpse;
plotPseData[predPSE0_, combPSE0_, xPSE0_, polyPSE0_, polyDelta0_,
visionPSE0_, hapticPSE0_, rsqPSE0_] := Module[
{predPSE = predPSE0, combPSE = combPSE0, xPSE = xPSE0,
polyPSE = polyPSE0, polyDelta = polyDelta0,
visionPSE = visionPSE0, hapticPSE = hapticPSE0,
rsqPSE = rsqPSE0},

(* Plot the data *)

dataPlot =
ListPlot[Transpose[{predPSE, combPSE}], AspectRatio -> 1,
Frame -> True,
FrameLabel -> {"Predicted PSE" <> xLabelTag,
"Observed PSE" <> yLabelTag},
FrameStyle -> Directive[Black, 19, Thickness[0.002]],
ImageSize -> Large, BaseStyle -> {FontSize -> 22},
PlotRange -> {{minXpse, maxXpse}, {minXpse, maxXpse}},
Method -> {"AxesInFront" -> False},
PlotLabel -> Style[theTitle, Black, 24], PlotStyle -> Blue,
PlotMarkers -> {Automatic, Scaled[0.02]}];

(* Plot the fit *)

fitPlot =
ListLinePlot[Transpose[{xPSE, polyPSE}], PlotStyle -> Blue];

(* Plot the error bounds *)

boundsPlot =
ListLinePlot[{Transpose[{xPSE, polyPSE + polyDelta}],
Transpose[{xPSE, polyPSE - polyDelta}]},
PlotStyle -> {{Blue, Dashed}, {Blue, Dashed}},
Filling -> {1 -> {2}}];

(* Plot the PSE lines *)

visionPSEline =
Graphics[{Dashed, Thick, Green,
Line[{{visionPSE, minXpse}, {visionPSE, maxXpse}}]}];
hapticPSEline =
Graphics[{Dashed, Thick, Red,
Line[{{hapticPSE, minXpse}, {hapticPSE, maxXpse}}]}];

(* Plot the unity line *)

unityLine =
Graphics[{Thick, Gray,
Line[{{minXpse, minXpse}, {maxXpse, maxXpse}}]}];

(* Report the R^2 *)

rsqText =
Graphics[
Text[Style[
ToString[Superscript["R", "2"], FormatType -> StandardForm] <>
" = " <> ToString[Part[rsqPSE, 1]],
18], {minXpse + theRangePSE/2, 57.5}, {0, 0}]];

(* Show *)

Show[dataPlot, unityLine, visionPSEline, hapticPSEline, dataPlot,
fitPlot, boundsPlot, rsqText]

];


It's not feasible to post the whole code without a bunch of work. The code reads in a bunch of data files (100's).

• The red means a syntax error or missing bracket which would influence the alignment. It would help if you posted the code. Also I'm nitpicking but it's kernel not kernal. Your comments look like ( * when they should be (* but it's hard to tell from the picture. Jul 27 '20 at 15:31
• This minimal example has the same problem and red highlighting pattern: f[y_] := Module[{x = y}, ( * something *) x += 3; ( * another thing*) x *= 7 ]; It is fixed by using (* without a space. Jul 27 '20 at 15:36
• Yes, there are no spaces. As I said, the code runs just fine until I close and open the notebook. Jul 27 '20 at 15:42
• Sorry about the spelling. I am dyslexic. Despite loads of proof reading I always get things wrong. Jul 27 '20 at 15:43
• Why are there italics? I think you may have messed up the internal box structure of the cell by some accidental editing. You can inspect the cell by selecting it and executing the menu command Cell > Show Expression. It'll be long and may be hard to read. Look for a StyleBox, I suppose. Hard for me to guess what it is or how to fix it without having the cell expression. You could post it on pastebin.com and link it here. Jul 27 '20 at 16:50

Puzzle solved it seems.

(1) I went full nuclear and did a complete reinstall > this had no effect. I guess obviously, but the amount of times that works impresses me.

(2) I tried resaving with a different name as suggested by flinty > this had no effect.

(3) I got worried that the file being on OneDrive might effect things. This did not seem to be the case.

(4) Finally, prompted by Michael E2's comment about the italics, I right clicked the cells and selected "Clear Formatting". This seems to have worked.

I have no idea what that did, or how the cells became "formatted" in such a way.

I also remain puzzled why realigning the text resulted in the code working just fine when the notebook was open, but the issue reappeared when the notebook was closed and reopened.

Presumably with this action the whole notebook is reformatted and the formatting of these specific cells which were causing the issue got reinstantiated.

I have upvoted Michael E2's comment as this provoked the solution. But provided what seems to be the solution here.

Hopefully that is the correct etiquette.