I want to write a notebook file by myself. I use a text editor (such as Vim) to do that, for the purpose of having full control of my code I am writing, and to really understand what is in my .nb file when I read it later on my version control repository.
So, I headed over to the following Wolfram Tutorial, Manipulating Notebooks, and learned that it is possible, and I am rather enthusiastic about it!
But I got stuck in a quite basic stage:
For example, how do I create a button, that when clicked prints the number $4\cdot5$, for example?
In the front-end, one just does
Button["Click here!", Print[4*5]]
(*20*)
Using the "Cell"->"Show Expression" tool (or pressing ⌘+⇧+e, I get the following text:
Cell[BoxData[
RowBox[{"Button", "[",
RowBox[{"\"\<Click here!\>\"", ",",
RowBox[{"Print", "[",
RowBox[{"4", "*", "5"}], "]"}]}], "]"}]], "Input",
CellChangeTimes->{{3.835353874007769*^9, 3.835353879618236*^9}},
CellLabel->"In[10]:="]
Ok so I guess I can delete the CellLabel
and CellChangeTimes
options for Cell
, but is there any possibility to make this Click here!
button shorter when typed by a human in a text editor?
Do I have to take care for all those "
, }
and RowBox
s?
Even a simple task such as assigning the symbol x
a numerical value seems too long:
Cell[
BoxData[
RowBox[{"x", "=", "2"}]], "Input"]
Is it possible to shorten it?
My .nb
now is this:
(*Low level notebook*)
Notebook[{
Cell[
"Some text","Text"
]
}
,WindowFrameElements->{"MinimizeBox","CloseBox","DocumentIcon","ResizeArea"}
,Saveable->False
,WindowTitle->"My Awesome Notebook"
]
.wl
) files. And a side node: Your button example is not really correct: What you are showing is the cell expression of the input cell that will create the button, instead of the output cell that contains the button (that one is at least a bit simpler than what you show) $\endgroup$.wl
files you mentioned, but let me ask again: there is no shortcut I can make, at least regarding the two examples I have presented above? Moreover, can you show me the "more" correct command for the button cell? $\endgroup$Button
expression, the output cell expression isCell[BoxData[ButtonBox["\<\"Click here!\"\>", Appearance->Automatic, ButtonFunction:>Print[4 5], Evaluator->Automatic, Method->"Preemptive"]], "Output", CellChangeTimes-> ..., CellLabel->....]
$\endgroup$