This doesnāt need to be an issue, Iām just not sure how to utilize Katex to actually perform simple calculations. Is this possible with Katex or am I misunderstanding how this works?
Thanks,
Alex
This doesnāt need to be an issue, Iām just not sure how to utilize Katex to actually perform simple calculations. Is this possible with Katex or am I misunderstanding how this works?
Thanks,
Alex
Hi Alex,
Thank you for the question.
You can write equations using math plugin but it does not support ācalculatingā.
I guess KaTeX even does not have such feature.
Itās basically for writing equations in LaTeX syntax.
You can create an issue on their GitHub repository if youād suggest it.
Could I request some sort of functionality within Inkdrop? If itās not trivially easy, forget about it, but it would be great if I could do simple equations within tables. Iām using this for my DnD notes.
Actually, I think it would be a super fun way to learn Node⦠Do you have any guidance for how I could go about making this myself?
Iām thinking Iād want some sort of inline math ability, so Iād look for characters similarly to how KaTeX searches for $1+1$ to display, right? So Iād be thinking of something like ^1+1^
Iāve got a scaffolded repo set up: https://github.com/arkag/inkdrop-calc
I donāt know how you are going to build a calculator based on KaTeX format, but I guess itād be hard.
You can get started by forking the math plugin though.
Instead of trying to build such a calculator yourself, itād be a lot easier to just use math.jsā evaluate
. Although math.js doesnāt have a KaTeX parser, simple expressions like ā1 + 1ā in KaTeX is also parseable by math.js. See https://mathjs.org/docs/expressions/syntax.html for math.jsā full syntax.
Huh, how would I go about using that? I was already thinking of leveraging a library for that, but are you saying I wouldnāt need a plugin at all?
You would still need a plugin to use the library with Inkdrop. I think the easiest way would be to create an Inkdrop command which checks if text is selected in the editor, and if so, evaluate it using math.js and replace the selected text with the result.
This code is not tested, but I imagine something like this in a command may work:
// Retrieve the CodeMirror instance of the editor
const { cm } = inkdrop.getActiveEditor();
// Get the selected text
const selected = cm.getSelection();
if (selected !== '') {
// Evaluate selected text using math.js
// TODO: Import math.js
// TODO: Catch any errors, it is not guaranteed that the selected text is a valid math.js expression
const evaluated = mathjs.evaluate(selected);
// Replace selection with math.js result
cm.replaceSelection(evaluated);
}
@Alex made a plugin ācalcā here:
https://my.inkdrop.app/plugins/calc
Thanks a lot for the contribution, @Alex and @jmerle !
Closing it.