How to create a Mathematica Notebook in Java?

前端 未结 3 1164
滥情空心
滥情空心 2021-01-14 03:30

I am looking for the prototypical \'Hello World\' program that creates a Mathematica Notebook file.

I have this working program.

 package graphica;

         


        
3条回答
  •  孤街浪徒
    2021-01-14 04:12

    A method for creating a formatted notebook file is shown here:

    How to create a notebook with a properly formatted expression

    You can box format your Mathematica code (mathCommand) using a kernel call, e.g.

    String mathCommand = "Plot[Sin[x], {x, 0, 6}]";
    mathCommand = "FullForm[ToBoxes[Defer[" + mathCommand + "]]]";
    MathKernel kernel = new MathKernel();
    kernel.Compute(mathCommand);
    mathCommand = kernel.Result.ToString();
    

    Then encapsulate it like so, and save it with .nb extension.

    Notebook[{Cell[BoxData[
    ... ( inserted box-formatted output ) ...
    ], "Input"]
    },
    WindowSize->{615, 750},
    WindowMargins->{{328, Automatic}, {Automatic, 76}},
    StyleDefinitions->"Default.nb"
    ]
    

提交回复
热议问题