nb = CreateDocument[];
(*NotebookWrite[nb, Cell["New content", "Subsection"]];*)
ExampleData[{"TestImage", "JellyBeans"}] //
NotebookWrite[nb,
Cell[BoxData[MakeBoxes[#, StandardForm]], "Output"]] &
You have to convert the expression you want to display to boxes. MakeBoxes[]
is HoldAllComplete
, so you have to evaluate the code that produces the image (even if the "code" is simply a variable) before passing the resulting image to MakeBoxes
. You can use With[]
instead of a pure function, if you prefer.
When trying to figure this stuff, the menu command Cell > Show Expression can be helpful, in case you hadn't run across it yet. You can use it to see how the system creates the cells you type and compute and mimic it.