5
$\begingroup$

I opened a notebook that I had recently made only to discover that all cells except the first one (an initialization cell) have been removed and all titles/subtitles except the first one have been replaced with Null: Notebook where almost everything has been replaced/deleted for some reason

When looking at the contents of the notebook with a text editor it looks like all the cells, except for the first few, contain ExpressionUUID rules and that's about it:

Cell[CellGroupData[{ Cell[, "Chapter",ExpressionUUID->"66a71787-6d65-43a3-9b8f-34451bd45f4a"], Cell[, "Text",ExpressionUUID->"e7bade7e-7eb6-4d94-be86-47010d44f9d9"], Cell[, "Input",ExpressionUUID->"831f561d-3f2d-45fc-90c8-3d915228040b"], Cell[, "Input",ExpressionUUID->"902ce406-b2f0-4389-b2b9-af7876aae1a1"] }, Open ]], ... 

Does anyone know what the cause of such a problem could be? It happened to me twice now, and I don't have a clue what causes this behaviour.

I did notice very odd behaviour with this notebook before: often when moving the cursor with arrow keys, the code font would change to a serif-type font. I couldn't identify the trigger for this behaviour as well so I didn't want to post about it.

$\endgroup$
3
  • $\begingroup$ You should contact Tech Support. $\endgroup$ Commented Mar 31, 2023 at 17:08
  • $\begingroup$ Hi @Gert! Did you ever find out anything about this? I have had this problem multiple times in multiple files, so I'm trying to see if there is some pattern. I use Linux, and I sync these files using Dropbox across different computers. Also, in both occasions, the erased content was inside a section that was collapsed. $\endgroup$ Commented Dec 10, 2024 at 1:41
  • $\begingroup$ @anonymous: While I don't have proof for this I did notice that these problems started occurring once I started syncing files using the cloud. They also stopped occurring when I stopped syncing files. Typically Mathematica gives a warning if a file you're editing has changed in the background but I never received such a warning so I'm not really sure this is the issue. $\endgroup$ Commented Dec 10, 2024 at 21:04

1 Answer 1

6
$\begingroup$

I ran into this problem as well! While I don't know specifically what caused it, it seems to have something to do with how cloud storage interferes with Mathematica's file change protection. I have not figured out how to prevent it from happening other than to keep the file saved locally.

Mathematica's tech support gave me a fix that got my notebook working again though. For me, the problem seemed to be isolated to the .nb, while the underlying binary was unchanged, so the solution is a command that recreates the notebook from the binary. You can run the command in a new notebook, substituting the path to your .nb file, and it will attempt to make an uncorrupted copy that you can save normally. Use it at your own risk, I can't guarantee that it will work for you but it worked for me.

RecreateNotebook[fileName_String] := Module[ {nb = NotebookCreate[], strm = OpenRead[fileName, BinaryFormat -> True], result, cell, tmpChar, beginPos, endPos}, While[(result = Find[strm, {"Cell[\"", "Cell[BoxData[", "Cell[TextData["}]) =!= EndOfFile, beginPos = SetStreamPosition[strm, StreamPosition[strm] - StringLength[result]]; Quiet[ cell = Check[ Read[strm, Expression], tmpChar = " "; endPos = StreamPosition[strm]; While[tmpChar =!= "," && endPos > beginPos + 1, SetStreamPosition[strm, --endPos]; tmpChar = Read[strm, Character]]; If[endPos > beginPos, SetStreamPosition[strm, beginPos]; ToExpression@ StringJoin@ ReadList[strm, Character, endPos - beginPos], $Failed] ]]; If[Head[cell] === Cell, NotebookWrite[nb, cell, After]];]; Close[strm];] RecreateNotebook["path/to/your/notebook.nb"] 

I should mention, this worked for me in Mathematica 14.0.0.0 running macOS Sequoia version 15.3 YMMV

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.