joeyuping / quick_latex_obsidian

MIT License
327 stars 21 forks source link

Shorthands are difficult to edit #39

Closed Nemoos-0 closed 2 years ago

Nemoos-0 commented 2 years ago

I had some trouble editing the custom shorthands since they are all in the same text field. It would be nicer to have multiple fields or even a separate file that the plugin would read at startup, this way the shorthands could be easier to sort and edit.

I was thinking about separating them into classes using the syntax class.foo for example

lorenz.xx' = \gamma (x - vt) o.rotor\vec{\nabla} \times \vec{}

I saw this is possible, but the single line editing makes it tedious.

Nemoos-0 commented 2 years ago

I created a little python script to make the process easier (the second and last line are used to copy the shorthand string to the clipboard, but can be deleted).

import yaml
import pyperclip

shorthand_dict = {}

with open("shorthand.yaml", "r") as stream:
    try:
        shorthand_dict = yaml.safe_load(stream)
    except yaml.YAMLError as e:
        print(e)

def listify(s_dict: dict):
    s_list = []

    for key, value in s_dict.items():
        if type(value) is dict:
            s_list += [f'{key}.{e}' for e in listify(value)]
        else:
            s_list.append(f'{key}: {value}')

    return s_list

shorthand_list = listify(shorthand_dict)
shorthand_str = ', '.join(shorthand_list)
print(shorthand_str)

# Copy the shorthand string to the clipboard
pyperclip.copy(shorthand_str)

Just put a file named shorthand.yaml in the same folder as the script and run it. Here is an example of how the file may look like:

# Symbols
s:
  x: \times
  all: \forall
  ex: \exists
  prop: \propto

# Operator
o:
  sq: \sqrt{}
  grad: \vec{\nabla}

and the output:

s.x: \times, s.all: \forall, s.ex: \exists, s.prop: \propto, o.sq: \sqrt{}, o.grad: \vec{\nabla}

Hope it can be helpful.

mayurankv commented 2 years ago

I too would love a slightly easier method to edit the shorthands, for me even just having the textfield allow multiple lines and having each shorthand on a new line would be enough!

joeyuping commented 2 years ago

Resolved in v2.3.0, please update and take a look! (try uninstall and reinstall the plugin to see the new default list of shorthands)