Let's import a notebook:
nb = ImportString["Notebook[{},TrackCellChangeTimes->False]", "NB"]
(* Notebook[{}, TrackCellChangeTimes -> False] *)
All is well so far. Now let's re-export it:
ExportString[nb, "NB"]
Now the output contains
$CellContext`TrackCellChangeTimes -> False
instead of
TrackCellChangeTimes -> False
This happens with every valid notebook or cell option that doesn't already have a corresponding symbol in the System`
context, and thus Import
creates it in Global`
instead.
Why does this happen? What's a reasonable workaround?
Notes:
I need the notebooks exported with full cache information, so I cannot export them as a plain expression.
NotebookSave
suffers from the same problem.The problem goes away if I use
"TrackCellChangeTimes"
(a string) instead ofTrackCellChangeTimes
.However, cycling such a notebook expression through
NotebookPut
andNotebookGet
"removes" the quotes and converts the string to a symbol again. Thus I do not know how to get strings for such options when importing a notebook.I am using
Import
/Export
to post-process notebooks created by the documentation tools and fix things. The unwanted$CellContext
causes subtle breakage that I did not even notice until now.