How to create a notebook with a properly formatted expression

后端 未结 4 1852
别那么骄傲
别那么骄傲 2021-01-14 16:16

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:<

4条回答
  •  Happy的楠姐
    2021-01-14 16:38

    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.

提交回复
热议问题