I have a Mathematica expression generated by another program, which I would like to open in a notebook, properly formatted. For instance, the other program generates this:<
Unless you create the BoxData
expressions explicitly there is no way to format your expression without actually invoking at least the Mathematica FrontEnd.
The closest I can think of is that you add the following:
SelectionMove[EvaluationNotebook[], Next, EvaluationCell];
FrontEndExecute[{FrontEndToken[FrontEnd`InputNotebook[],
"SelectionConvert", "StandardForm"]}];
Plot[{Exp[x], Interpolation[Table[{k/5, Exp[(1/5)*(k - 1/2)]}, {k, 0, 5}],
InterpolationOrder -> 0][x]}, {x, 0, 1},
Filling -> {1 -> {{2}, {Yellow, Orange}}},
PlotLabel -> Style["Formatting", Blue, FontFamily -> "Courier"],
Evaluated -> True]
SelectionMove[EvaluationNotebook[], After, GeneratedCell];
which automatically formats the Plot
command when the cell is evaluated.
(BTW: You probably should either add Evaluate
in front of the list or add the (not-so-well documented) Evaluate->True
option.