5
$\begingroup$

I am using a standard notebook file in which code is showing different plots.

How can I hide all code cells with Sytle: Input so that I can Export the Notebook to a pdf file which is showing only the plots?

For example:

enter image description here

In this plot I can hide the LisPlot command by the menu (Cell->Cell Properties->Open (disable)).

Question: Does a command exists to hide all input cells at once?

$\endgroup$
3
  • 2
    $\begingroup$ Possible duplicate of How can I clean up a notebook? $\endgroup$
    – m_goldberg
    Commented Mar 4, 2017 at 21:19
  • $\begingroup$ My answer to this question gives instructions of how to do what you are asking. you might want to leave out the line SetOptions[nb, ShowCellBracket -> False]; $\endgroup$
    – m_goldberg
    Commented Mar 4, 2017 at 21:23
  • $\begingroup$ @m_goldberg your solution leaves a gap in place of input cell so in case of multiple input cells there will be strange gaps in the pdf. It also affects the Input cell in general, not in printing context. Additionaly, I'd argue that if this one is close enough to be a duplicate then both, this and yours, should be closed as a duplicate of one of topics linked in my answer. $\endgroup$
    – Kuba
    Commented Mar 5, 2017 at 9:53

1 Answer 1

3
$\begingroup$

It seems that there isn't any perfect solution for this problem in a closely realted: Is there a way to hide or toggle the visibility of code?

Here are alternatives:


Quick fix

If you don't want to play with styles and want a quick solution you can just clone a notebook and delete "Input" cells before printing:

NotebookDelete @ Cells[ 
    NotebookPut @ NotebookGet[ notebook ]
  , CellStyle -> {"Input"} 
]

Persiting solution

If you want this to be a fixed property of a notebook then we can combine

how to affect style for PDF exported notebook with

how to create an invisible cell

and create private styles for our notebook (or edit alterady existing private styles if that is the case)

SetOptions[
    EvaluationNotebook[]
  , StyleDefinitions -> Notebook[{
        Cell[StyleData[StyleDefinitions -> "Default.nb"]]
      , Cell[
            StyleData["Input", "Printout"]
          , CellElementSpacings -> {"CellMinHeight" -> 0, "ClosedCellHeight" -> 0}
          , Background -> Hue[.8]
          , CellMargins -> -2
          , CellOpen -> False
          , CellFrame -> 0
          , ShowCellBracket -> False
        ]
    }]
]
$\endgroup$
3
  • $\begingroup$ Your solution with the first snipplet of code is great. Can you give an example on how I have to use the SetOptions code. Thank you. $\endgroup$
    – mrz
    Commented Mar 6, 2017 at 11:25
  • 1
    $\begingroup$ @mrz evaluate it in a notebook you want to be affected or replace EvaluationNotebook[] with NotebookObject which points to that notebook. Then try to print to pdf. $\endgroup$
    – Kuba
    Commented Mar 6, 2017 at 11:27
  • $\begingroup$ I like your solution with SetOptions very much, because it does not change the notebook and only removes the input cells and the cell brackets at right when printing. Great ... $\endgroup$
    – mrz
    Commented Mar 6, 2017 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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