When Mathematica evaluates a cell, it gives the Input cell and Output cell the CellLabels In[$Line]:=
and Out[$Line]=
where $Line is a counter that gets incremented on each evaluated input.
If you input something like TraditionalForm[expr]
or TeXForm[expr]
(or any other *Form from $OutputForms
) then the name of the form also gets added to the Output cell's label. eg Out[1]//TraditionalForm=
.
I can't find any way of customising these labels.
They can be disabled in the Preferences dialog.
They don't seem to be in the StyleSheet options for Input and Output cells - although the options pertaining to the CellLabel behaviour are there.
Nor in the Notebook options - although in the Option Inspector: Notebook Options > Evaluation Options > EvaluationCompletionAction can modify the CellLabels by adding a TimeStamp. It can also show the Timing in the StatusArea, bit it gets removed as soon as something else prints there.
Nor any of the init.m type configuration files.
So, does anyone know where these CellLabels are generated?
In particular, I am interested in adding the Timing
to the CellLabel for Output cells.
Another way of doing this would be to set EvaluationCompletionAction -> "ShowTiming" which will display timing information in the status bar of the notebook window after each evaluation.
OK, the discussion on Physics Forums has lead to this quite hackish solution (now cleaned up a little):
SetAttributes[Timeit, HoldAll]
Timeit[x_] := With[{t = Timing[x]}, Module[{out, form},
If[TrueQ[MemberQ[$OutputForms, Head[t[[2]]]]],
out = First[t[[2]]]; form = "//" <> ToString[Head[t[[2]]]],
out = t[[2]]; form = ""];
If[out === Null, Null,
CellPrint[ExpressionCell[t[[2]], "Output", CellLabelAutoDelete -> False,
CellLabel -> StringJoin["(", ToString[t[[1]]], ")",
"Out[", ToString[$Line], "]", form, "="]]];
Unprotect[Out]; Out[$Line] = out; Protect[Out]; out;]];]
$Pre = Timeit;
To make the CellLabels persistent so that you don't lose the timing when you Save and Load the notebook, you can modify the stylesheet so that the Output cells have the option CellLabelAutoDelete -> True
. (Edit: Now added to the CellPrint
command.)
Any better solutions are more than welcome.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With