widcardw / obsidian-asciimath

Asciimath support for Obsidian (based on asciimath-parser)
MIT License
29 stars 2 forks source link

Matrix operator #22

Open kwinso opened 10 months ago

kwinso commented 10 months ago

I've seen "limits" is defined with mathop

I've been using limits(A)_(m xx n) to define matrix name with it's size. Not a convenient thing tbh.

I wonder is it possible to add new mat or matrix operator defined with mathop, which will do this. I image the API like this:

kwinso commented 10 months ago

Also, what about some API to define these custom operators the way we do it in symbols.json (with placeholders for value)?

widcardw commented 10 months ago

asciimath-parser uses replaceBeforeTokenizing as one of its config params. It is a preprocess before the formula is passed into the parser. I can replace the matched token and replace it with common asciimath.

For example, the expression should be

[
  [/mat\(([^,]+?),([^,]+?),([^\)]+?)\)/g,
   (_, $1, $2, $3) => `limits(${$1})_(${$2} xx ${$3})`]
]

However, it's unsafe to execute user written code and inject it into the program. I haven't thought about how to implement this feature in Obsidian plugin safely.

widcardw commented 10 months ago

Also, what about some API to define these custom operators the way we do it in symbols.json (with placeholders for value)?

asciimath-parser is written in pure algorithm instead of grammar tools like antlr. So it may be hard to change the current grammar, or use it like C/C++ and define macros...