TransWikia.com

Mathematica front-end code alignment issue

Mathematica Asked by flyingmind on August 16, 2020

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.

I am running the latest version, freshly reinstalled today.

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).

Arrow shows the inserted misalignmnet

One Answer

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.

Thanks for your help.

Answered by flyingmind on August 16, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP