When producing a notebook with both code and text, I often end up with pieces of code, or even entire chapters, that I don't want to be shown on the final output.
I generally hide or close them by hand, but this is time consuming, susceptible of error, and leaves big white spaces everywhere.
I'm searching for a way of, by tagging a cell or entire chapter (a "group head") as confidential, on the moment of the printing its content is substituted by a "content removed" warning cell (if possible, a different warning for a list of different tags that are included in the search).
Don't know if it can be managed on a style sheet specification (something that I know very little of) or just code (on a MMA theme that I also know very little), or both. I don't mind that a “cleaned” replica of my notebook is temporally generated, just for the printing formatting.
Answer
Here is a starting point, which people with palette creation experience could expand on to create a "one click" solution. First, my setup:
File number 1: "confidential.nb" with two sections and two text cells. I selected the entire first section and hit CTRL+J to bring up the cell tags:
I added the tag "Confidential" to all of the cells. This is what it looks like:
I then created a second notebook "confidential-purge.nb" with the following. First, open the notebook silently (Visible->False
).
SetDirectory[NotebookDirectory[]]
nb = NotebookOpen[
FileNameJoin[{NotebookDirectory[], "confidential.nb"}],
Visible -> False]
Translate the NotebookObject
into an expression that can be manipulated, and replace every non-section occurance of a cell with the "Confidential" tag with some arbitrary text:
nbConf = NotebookGet[nb] /.
Cell[t_, a_, b___, CellTags -> "Confidential", c___] /;
a =!= "Section" :>
Cell["CONFIDENTIAL", a, b, CellTags -> "Confidential", c];
Save the output to a file:
NotebookPrint[nbConf, FileNameJoin[{NotebookDirectory[], "test.pdf"}]]
The result:
Now, I'm sure this won't work in all cases, but perhaps will serve as a starting point.
Comments
Post a Comment