Skip to main content
added 36 characters in body
Source Link
Szabolcs
  • 238.9k
  • 32
  • 653
  • 1.3k

This is admittedly messy, but something along these lines might work:

insertBelowEvaluationCell[expr_] := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; NotebookWrite[EvaluationNotebook[], Cell[BoxData@ToBoxes[expr], "Print"]]) 

This function moves the insertion point just below the evaluation cell before inserting the text or expression to be printed.

Let's test it:

insertBelowEvaluationCell /@ Range[10] 

The main problem with it is that this messes with the insertion point in the notebook which can be modified interactively as well. Perhaps it's better to write the output in a separate notebook instead. Also, it does not work in command line mode (without a front end).Problems:

  • This messes with the insertion point in the notebook which can be modified interactively as well. Perhaps it's better to write the output into a separate notebook instead.

  • It does not work in command line mode (without a front end).

  • It's slow (noticeably slower than Print).

This is admittedly messy, but something along these lines might work:

insertBelowEvaluationCell[expr_] := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; NotebookWrite[EvaluationNotebook[], Cell[BoxData@ToBoxes[expr], "Print"]]) 

This function moves the insertion point just below the evaluation cell before inserting the text or expression to be printed.

Let's test it:

insertBelowEvaluationCell /@ Range[10] 

The main problem with it is that this messes with the insertion point in the notebook which can be modified interactively as well. Perhaps it's better to write the output in a separate notebook instead. Also, it does not work in command line mode (without a front end).

This is admittedly messy, but something along these lines might work:

insertBelowEvaluationCell[expr_] := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; NotebookWrite[EvaluationNotebook[], Cell[BoxData@ToBoxes[expr], "Print"]]) 

This function moves the insertion point just below the evaluation cell before inserting the text or expression to be printed.

Let's test it:

insertBelowEvaluationCell /@ Range[10] 

Problems:

  • This messes with the insertion point in the notebook which can be modified interactively as well. Perhaps it's better to write the output into a separate notebook instead.

  • It does not work in command line mode (without a front end).

  • It's slow (noticeably slower than Print).

Source Link
Szabolcs
  • 238.9k
  • 32
  • 653
  • 1.3k

This is admittedly messy, but something along these lines might work:

insertBelowEvaluationCell[expr_] := (SelectionMove[EvaluationNotebook[], After, EvaluationCell]; NotebookWrite[EvaluationNotebook[], Cell[BoxData@ToBoxes[expr], "Print"]]) 

This function moves the insertion point just below the evaluation cell before inserting the text or expression to be printed.

Let's test it:

insertBelowEvaluationCell /@ Range[10] 

The main problem with it is that this messes with the insertion point in the notebook which can be modified interactively as well. Perhaps it's better to write the output in a separate notebook instead. Also, it does not work in command line mode (without a front end).