Hot answers tagged

4

As Dynamic objects are only evaluated when they are visible, one can use them to print cells only when there is no ; at the end of the input. The following one removes the Out cell containing a DynamicWrapper as the Dynamic object itself, after the cells are printed. ClearAll@f f[x_] := Module[{evalCellObject}, DynamicWrapper["", evalCellObject = ...


3

This one checks if the input ended with ; and prints Echo cells if it didn't. f[x_] := If[ Cases[NotebookRead[EvaluationCell[]], BoxData[RowBox[{___, last_}]] :> last] == {";"}, Null, CellPrint[ExpressionCell[#, "Echo"]] & /@ Range[x]; ] For example: f[5] f[5]; This approach can be extended to also cover CompoundExpressions ...


3

The code below is currently broken but I'll leave it for reference. I'll attempt a full rewrite somewhat later. Thanks to gwr for testing my code and pointing out problems. The first possibility that comes to mind is the use of $PreRead and $PrePrint to set a global variable, then use the value of this variable within your function to control Cell ...


3

If you want to tweak the number of digits displayed in your notebook, run this: SetOptions[EvaluationNotebook[], PrintPrecision -> 10] As noted by Szabolcs, the default setting of PrintPrecision is 6, which is why you're only seeing that many digits in the output, even tho all the digits are still there.


3

You need to reorder the way definitions of Inactive are applied once you've defined your custom one. By default it was put at the bottom, so the "catch-all" rule is being attempted first. Unprotect[Inactive]; Inactive /: MakeBoxes[p : Inactive[myTimes][args___], form_] := MakeBoxes[Interpretation[HoldForm@myHead[args], p], form] FormatValues[Inactive] ...


1

You can use an intermediate expression that can be returned by your function, not printed as side effect. Then you can use $Post to post-process this returned expression, so that it'll result in multiple printed cells. ClearAll[multipleCellsOutput, printMultipleCellsOutput] printMultipleCellsOutput = # /. multipleCellsOutput[cells_List] :> ...



Only top voted, non community-wiki answers of a minimum length are eligible