By cleaning up a notebook, I mean how can I hide all the codes in the notebook so that the end-users can't see it? I saw Eric Schulz's famous interactive calculus textbook, the users can't see the code, and there is no cell brackets on the right hand side of the CDF.
-
2$\begingroup$ Please consider adding a reference to the textbook. $\endgroup$– Kuba ♦Feb 27, 2017 at 6:18
-
2$\begingroup$ At least closely related: 113913, 14466, 680 $\endgroup$– Kuba ♦Feb 27, 2017 at 6:24
-
$\begingroup$ @Kuba This appears to be directly answered by mathematica.stackexchange.com/a/14470/121 therefore I am in favor of marking this as a duplicate. Do you disagree? $\endgroup$– Mr.WizardApr 10, 2019 at 7:27
-
$\begingroup$ @Mr.Wizard I agree, sorry for delay, I should not read via mobile phone because then I forget to answer. $\endgroup$– Kuba ♦Apr 10, 2019 at 18:03
2 Answers
Update
I have incorporated Kuba's improvement into the code.
Here is how I would do it.
In a working notebook (not the target notebook) put the following code.
With[{nb = target}, SetOptions[nb, ShowCellBracket -> False]; SetOptions[#, CellOpen -> False] & /@ Cells[nb, CellStyle -> "Input"];] With[{nb = taget}, SetOptions[nb, ShowCellBracket -> True]; SetOptions[#, CellOpen -> True] & /@ Cells[nb, CellStyle -> "Input"];]
The first code cell will do the clean-up. The second lets you undo it if that becomes necessary.
Now in the target notebook evaluate
EvaluationNotebook[]
This will return a notebook object which will look something like
Cut the notebook object from the target notebook.
Select the first token
target
in the working notebook and paste the notebook object over it.Do the same thing for the other
target
token.Delete the
EvaluationNotebook[]
code from the target notebook.Evaluate the first of the two code cells.
After pasting the notebook object into working notebook, that notebook should look like this:
-
1
-
Another possibility is to modify the notebooks style sheet by defining a new "Screen Environment" that hides cell brackets and closes input cells:
SetOptions[
EvaluationNotebook[],
StyleDefinitions -> Notebook[{
Cell[StyleData[StyleDefinitions->"Default.nb"]],
Cell[StyleData[All, "Working"], MenuCommandKey->"D"],
Cell[StyleData[All, "Clean"],
MenuCommandKey->"C",
ShowCellBracket->False,
MenuSortingValue -> 10000
],
Cell[StyleData["Input", "Clean"],
CellOpen->False]
},
StyleDefinitions->"PrivateStylesheetFormatting.nb"
]
]
The "Clean" environment hides cell brackets and closes input cells. I also gave it a keyboard short cut, so that using Command+c switches to the "Clean" environment, and Command+d switches back to the working environment. Here is an animation:
Note that I used the keyboard shortcuts to switch at the end of the animation.
-
$\begingroup$ Thank you for your answer! I've decided to to give the bounty to you because it provides a better solution. Thanks again! $\endgroup$ Apr 15, 2019 at 6:26