gtg922r / obsidian-numerals

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

Latex Input support #27

Open mayurankv opened 1 year ago

mayurankv commented 1 year ago

Would it be possible to add latex support for the functions that mathjs supports? This would allow users who commonly type in latex to not use different syntaxes and be able to use other existing autocompletion tools!

EDIT: To clarify I meant without dropping of the . My title is a little bit misleading so apologies.

gtg922r commented 1 year ago

Can you give some example use cases to help me understand the request?

mayurankv commented 1 year ago

So rather than using a=fraction(1/3)*(sin(1.5*pi))^2, I would want to use a=\frac{1}{3}*(\sin(1.5*\pi))^{2}.

Functions

I understand this isn't the most straightforward request. In many cases, simply ignoring the preceding backslash would make things work. I would only expect this to be implemented for extremely basic functions like fraction or those which work without the backslash in front. i.e. sin works so \sin should work but comb is not an accepted function so I would not expect \comb to work (combinatorics). The only basic function I can think off that would need to be implemented differently is just fraction which goes from fraction(x/y) to \frac{x}{y}. In addition treating {} bracket pairs as () pairs would presumably work just fine for things like powers.

Essentially for functions the following rules could apply:

  1. If the function is not in a specially handled list (i.e. fraction), then treat \func{x_1}{x_2},...,{x_n} as math.func(x_1,x_2,...,x_n). Similarly \single_arg_func(x) should be treated as math.single_arg_func(x).
    • If the function is not defined in math.js, then throw an undefined function error i.e. \nonsense{3} should be treated the same as nonsense(3).
  2. If the function is specially handled, then carry out that special handling i.e. special handling on frac: \frac{4}{5} -> frac(4,5) -> fraction(4/5) (This could hypothetically solved by changing the fraction syntax too).
  3. Exceptions would be non functionally applied things like powers so that should just treat {} as brackets.

Variables

This bit is hopefully quite a bit simpler, but allow for variables to be typed out using latex. This would be akin to allowing \vec{a} to be a variable name that is rendered in latex or a_{i,j} to be a variable name rendered properly. Currently using {} gives an Unexpected operator error. In reality any variable name is a placeholder that should not really affect the program up to parsing.

Totally understand if this isn't something you want to pursue but I really do think the small addition of variables would be a big boost and proper treatment of latex functions would make this invaluable! Please let me know if you have any thoughts.

mayurankv commented 1 year ago

Just wondering if you've managed to have a think about this? (No worries if not!)

mccann-kristian commented 1 year ago

I use latex to take math notes in obsidian, compatibility would be nice

usirg commented 2 months ago

Writing latex with e.g. Latex Suite is super efficient and can even be customized.

For example, one can write @b to get \beta etc.

If Numerals would be interoperable with latex, this would already take care of e.g. #69, at least partially.

Another nice improvement would be the ability to write latex in comments. For example, I'd like to write this:

# Let $h$ be the hypotenuse of right triangle $\triangle{ABC}$:
h=5cm
# Let $@a$ be one of its angles:
@a=30
# Then the opposite $o$ of $@a$ is:
o=h\sin{@a}

I understand that it may be difficult to enable this.

usirg commented 2 months ago

To follow up on my post above, being able to write latex inside a math block will be less important with the features of global variables currently under development. Because then it's possible to interleave latex and numerals sections.