gtg922r / obsidian-numerals

An obsidian plugin which turns a math code block into a full featured calculator
Other
391 stars 8 forks source link

[Feature Request] Write results in the note #22

Open RobertoHRO opened 1 year ago

RobertoHRO commented 1 year ago

First of all - I have been waiting for so long for such a plugin! - Thank you so much! Here is my feature request: Can you write the results of the calculations including the unit in the note? The feature could look like this: image All the results the user wants to be displayed will be written to the note: image

If an existing note with math-blocks is opened and the math-blocks are evaluated by obsidian-numerals and the results in the note and from obsidian-numerals differ - you could indicate this and ask the user for permission to update.

gtg922r commented 1 year ago

I've been thinking about this a ton, I definitely agree this feature needs to exist. It bothers me the results aren't saved into the plain text.

I need to think about the right syntax for when to do this. As you indicate I think using the result annotation syntax might be a good place to start.

Adding autocomplete is almost done and I think I might take this on next.

akehrer commented 1 year ago

I also wanted to say thank your for this plugin.

Using the result annotation would be similar to how Calca handles it, so the consistency there would be nice to have. Another plus is that now all the information is there when copy/pasting or sharing the raw markdown file.

mofosyne commented 1 year ago

By the way, I'm a bit iffy about using => for results annotation (looks too similar to C equal or more than operator).

Just wondering what you think about := as result annotator indicator instead? Plus it would give the user an option between showing just the results on the fly or making sure the results is recorded into the text file as well.

That's how I've been manually recording results from https://speqmath.com/ which puts their results annotation in a new line and I wanted to keep it more compact in my personal notes (before this plugin existed).

e.g.

    a = 1+1 := 2
    b = $3
    c = a * b := $6 AUD

Also you may want to add some consistent attribute metadata when using results annotation so you know when the last time it was run (and any other enviromental variables that may be lost if that block is copied and pasted). This would be useful when opening the file in a non obsidian text editor.

The adhoc standard is shown in https://talk.commonmark.org/t/consistent-attribute-syntax/272

I've double checked if adding {} would interfere with obsidian rendering of codeblocks and it did not break anything still.

```math {lastupdated="2000-01-23T01:23:45.678+09:00"}
a = 1+1 := 2
b = $3 := $3 AUD
c = a * b := $6 AUD
```
RobertoHRO commented 1 year ago

To check if I have understood you correctly, is this what you intend to do?
c = a * b := $6 writes to the mardown file and renders the result in the obsidian reader/life view. And c = a * b => $6 only renders the result in the obsidian reader/life view.


I like the suggestion of putting the last modified timestamp in the file. It is also helpful (may be necessary) when trying to automatically modify the md file.

mofosyne commented 1 year ago

Yes that's correct on both count (I do wonder if this plugin has comparison operators and if so what would it be... still bit iffy on the existence of => but is outside the scope of this discussion)

tjaska commented 1 year ago

By the way, I'm a bit iffy about using => for results annotation (looks too similar to C equal or more than operator).

Just wondering what you think about := as result annotator indicator instead? Plus it would give the user an option between showing just the results on the fly or making sure the results is recorded into the text file as well.

Wanted to throw my 2 cents in here regarding this suggestion. := is used as a variable assignment operator for some languages (AHK, Golang), while the greater/less than or equal is always the other way around. For alternatives, perhaps -> or >>, but current one is sensible as well, IMHO.

Btw, superb plugin, @gtg922r 💯

mofosyne commented 11 months ago

By the way, I've been thinking about my proposal for ':='... I think you can actually get away with just '=' but you need a very very robust heuristic to solve all edge cases.

I've been attempting to tackle this problem in this project https://github.com/mofosyne/QuickMathsJS-WebCalc .

And if it works out, I would not mind if others take the insight from this into obsidian numerals.

Currently adding more test and so far it's passing, but I suspect I'm missing other problems. Happy to receive contributions. It's all in browser javascript so should be easy for you to download and try improving it.

To try it out, head to http://www.quickmathjs.com/ and copy

a = 5
b = a + 1 = 9
c = b + 1
d = c + 1 = 
d =  2

which would output

a = 5
b = a + 1 = 6
c = b + 1
d = c + 1 = 8
d = 8

I think we can get away with this heuristic, because there is really only one statement and no control flows to worry about.

mofosyne commented 11 months ago

Rejigged the syntax and looks like I'm now settling down to this syntax:

a = 5
b = 7
c = a + b = 12
  = 12

1 + 1
    = 2

  c = 12

Based on context c = a + b = 12 can be deduced as <var>=<exp>=<ans>.

While = by itself is = <ans>

And c = 12 is <var> = <ans> when there is at least 2 spaces or more on the start of a line.

I'm done with this miniproject now, so hopefully this syntax will give this plugin some ideas to borrow regarding how to figure where to place results.

gtg922r commented 6 months ago

Thanks for the thoughts on syntax all. I settled in a syntax that will expand to other numerals features, and thats using @[]. Unfortunately, I admit the syntax is not particularly intuitive, and I'm open to considering other options.

I've added experimental support in Numerals Beta 1.4. Wrapping any variable name in @[], for example @[meaningOfLife], will insert the value of the variable after :: when the block next renders. The raw text of the note will be modified to say: @[meaningOfLife::42]. This has the intentional side-effect of allowing you to set dataview values on a page using numerals.

Please see the release notes and I'd love your help testing out this feature! Please see the README for instructions how to beta test using BRAT