I found
math.js plugin for tw a while ago. However I didn't managed to do what I wanted with it. I wanted to set a field value with a math expression. I remember I managed to do it with a macro and a $set variable, but I think that is not very clean. Instead, I thought that making an alternative action-setfield widget was the right thing to do. So I took @mklauber plugin and wrote the widget.
See the following examples to get an Idea of what is possible with this:
This button raises the field "test2" to the power of 2 each time it is clicked:
<$action-setfield-mathjs $tiddler=<<currentTiddler>> $field="test2" $eval="test2^2" />
Click to raise <b>{{!!test2}}</b> to the power of 2
You can also manipulate data tiddlers. In the following, the data tiddler [[ExampleData]] is updated with math operations:
<$action-setfield-mathjs $tiddler="ExampleData" $index="y" $eval="y+1" />
Click to increment y ( {{ExampleData##y}} )
<$action-setfield-mathjs $tiddler="ExampleData" $index="x" $eval="x+1" />
Click to increment x ( {{ExampleData##x}} )
The tiddler fields or the data tiddler indexes are set as the math.js scope, so you can use the names in the math.js expressions.
The main motivation for this was having a simple increment button :) But it is quite powerful. Hope you can come up with great use cases for this.