Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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:

Mathematica graphics

I added the tag "Confidential" to all of the cells. This is what it looks like:

Mathematica graphics

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:

Mathematica graphics

Now, I'm sure this won't work in all cases, but perhaps will serve as a starting point.

share|improve this answer

I haven't figured out how to add a "Content Removed" label or to hide entire groups of cells, but you can use Style Sheets and the Printout environment to at least automatically Close cells with the style "Confidential" while printing.

With this method I think you would need to have a different Confidential style for each cell type (code, text, etc.) that you intend to use. Here is a simple example with only one.

From a new Notebook I choose Format > Edit Stylesheet... and add these two cells:

Cell[StyleData["Confidential"]]

Cell[StyleData["Confidential", "Printout"],
 CellOpen->False]

Then in the main Notebook I create two cells, one Text and the other Confidential:

Mathematica graphics

Upon changing the Screen Environment to Printout (under the Format menu) I see:

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.