If you evaluate a DocumentNotebook[] expression in the front-end, it nicely displays inline, inside of an output cell in the current notebook:

DocumentNotebook displayed

For my purposes, TextCell and ExpressionCell expressions are insufficiently flexible. So (as in the question Combination of CellPrint and PrintTemporary, or DisplayForm for Cells), I'm programmatically generating some formatted output that generates raw Cell[] box expressions. For instance, the output might be

cell = Cell[TextData[{"Function ",
        TraditionalForm]], FormatType->"TraditionalForm"]}],

(where $f(x)$ will actually be some complicated expression).

Unfortunately, DocumentNotebook[] seems to require TextCell/ExpressionCell and doesn't work when given Cell[]s:

DocumentNotebook with Cell

So I tried using Notebook[] instead, which does work with Cell[]s. However, evaluating a Notebook expression doesn't display in the front-end:


It displays correctly when I run NotebookPut@Notebook@{cell}, but in a new window. How can I get it to display inline in the current notebook, like how DocumentNotebook displays? I tried wrapping it in CellPrint and in DisplayForm, but those don't work for Notebook[]s.

Relatedly, what's the difference between DocumentNotebook (and friends) and Notebook? Both appear to be intended to represent a notebook as an expression, but as I discovered they behave slightly differently.

  • $\begingroup$ I know this doesn't answer your question, but I don't know an answer off the top of my head and I gotta go sleep. But try cell = TextCell[Row[{"Function ", ExpressionCell[TraditionalForm@Defer@f[x]]}], "Subsection"] $\endgroup$
    – Rojo
    Commented May 20, 2013 at 3:50
  • $\begingroup$ Would you mind getting rid of the brackets in the question title? They make reading it quite hard and do not clarify as such - most readers will recognize the functions anyway. $\endgroup$
    – Yves Klett
    Commented May 23, 2013 at 13:11

3 Answers 3


Perhaps it's not obvious because this doesn't look like a box. But the way that DocumentNotebook, et al, get translated into Notebook is by going through MakeBoxes. Which means that RawBoxes saves the day by preserving its guts in MakeBoxes:

DocumentNotebook@{TextCell["Hello world!", "Section"], RawBoxes@cell, 
  TextCell["The solution is:", "Text"]}
  • $\begingroup$ Greaaaaaaaaaat!! $\endgroup$
    – Rojo
    Commented Oct 22, 2013 at 22:53
  • $\begingroup$ +1 Is there a way to remove the border and button? Options[DocumentNotebook] seems to bring up a lot of options but I don't see anything specific there or in the docs. $\endgroup$
    – William
    Commented Oct 24, 2013 at 3:35
  • $\begingroup$ In case anyone is interested the following automatically wraps the cells with RawBoxes and then removes the border and button to print as a single cell. $\endgroup$
    – William
    Commented Oct 29, 2013 at 2:43

Not quite tested

                Cell[CellGroupData[{cs__Cell},_]]:>cs, {1}]

So you would do Notebook[...]//embeddedNotebookForm

Example, try NotebookGet[]//embeddedNotebookForm in some notebook with stuff

  • $\begingroup$ @Silvia, but that is not a proper Notebook[...] expression. Try to NotebookPut that and you'll get errors too $\endgroup$
    – Rojo
    Commented May 20, 2013 at 20:41
  • $\begingroup$ Ah.. I see.. TextCell[..] is NOT a Cell expression! +1 $\endgroup$
    – Silvia
    Commented May 20, 2013 at 20:54
  • 2
    $\begingroup$ BTW I'm always wonder would it be possible to realize a nested Notebook, which serves like the minipage environment in LaTeX. $\endgroup$
    – Silvia
    Commented May 20, 2013 at 20:57
  • $\begingroup$ @Rojo very nice, but I had to change Replace[cells,Cell[CellGroupData[{cs__Cell},_]]:>cs, {1}] to (cells //. Cell[CellGroupData[{cs__Cell}, _]] :> cs) $\endgroup$ Commented Jun 28, 2013 at 20:24
  • 2
    $\begingroup$ @Rojo ¡Si, señor! $\endgroup$ Commented Jun 28, 2013 at 21:35

Another solution involves messing with the box structure directly.

This is just a basic example but GridBox accepts as argument cells of the form {{cell}..}. In fact this is what DocumentNotebook actually outputs Cells inside of a GridBox. Column and Row both use GridBox internally also.

A simple example would be.

        Cell[BoxData["test"], "Input"]
    ]], "Output"]

Creating a function with MakeBoxes allows you to accept a list of cells like so. You need to use a Replace to make sure that the code works for CellGroupData because GridBox doesn't support such and returning an empty string when the Cell list is empty.

CellList /: MakeBoxes[CellList[list_], form_] := If[
  Length[list] > 0,
  GridBox[Map[{#} &,
     , Cell[CellGroupData[{x___}, ___]] :> (x), {0, 1}

And print cells like so.

  Cell[BoxData["1"], "Input"],
  Cell[BoxData["2"], "Input"],
    Cell[BoxData["a"], "Input"],
    Cell[BoxData["a"], "Output"]
   }, Open]]

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.