obsidian-latex-suite icon indicating copy to clipboard operation
obsidian-latex-suite copied to clipboard

Replacements with "$\d" or "[[\d"

Open Shesh6 opened this issue 1 year ago • 5 comments

I've been trying to implement a text-mode regex snippet to convert any number to math mode after writing: e.g 3 -> $ 3 $. I quickly discovered that basically any snippet which inserts a $ followed by a digit is bound to spaz out and crash the plugin.

I think this is due to the detection of the tabstop syntax. May I suggest adding an option to escape the $ character's tabstop functionality in the replacement syntax, seeing as it's a crucial symbol for working with LaTeX?

My current workaround is 3 -> $ \hspace{0pt}3 $ which works but it's messy.

A similar issue occurs with double brackets as far as I can tell. I use snippets to auto-prettify my Obsidian links and I'd run into problems if I was using numerical note titles or headers.

(P.S. Didn't want to add an issue for this, but I'm in love with this plugin (thank you), and I'm wondering if you considered a page/google sheet where members of the community can share our custom snippets!)

Edit: Funny that I needed to escape out of the $ symbols on GitHub to convey my issue correctly, and found out they don't have that feature either.

Shesh6 avatar Sep 06 '22 19:09 Shesh6

Hello! Glad you're enjoying the plugin.

I think this is due to the detection of the tabstop syntax. May I suggest adding an option to escape the $ character's tabstop functionality in the replacement syntax, seeing as it's a crucial symbol for working with LaTeX?

Yep, the problem is caused by the detection of tabstop syntax. I can add the ability to escape the $ character by inserting a \ before it.

A similar issue occurs with double brackets as far as I can tell. I use snippets to auto-prettify my Obsidian links and I'd run into problems if I was using numerical note titles or headers.

Could you describe the problem with [[ brackets in more detail? It doesn't involve the $ character, so what happens there?

I'm wondering if you considered a page/google sheet where members of the community can share our custom snippets!

Good idea! I just opened this discussion page where people can share snippets with others, and I'll add a link to it in the readme.

artisticat1 avatar Sep 08 '22 19:09 artisticat1

Could you describe the problem with [[ brackets in more detail? It doesn't involve the $ character, so what happens there?

It's barely an issue on second thought, still I'll explain myself:

In the regex replacement syntax, [[\d]] is used to insert a captured group.

A clear example for this being an issue, if perhaps unlikely: if one were to use a note naming system that includes digits as note names, and would want to use regex to insert a markdown link to note "0", the replacement "[[0]]" would conflict with the captured group syntax.

However, looking in the code it seems that it's looking for "[["+(i-1)+"]]" explicitly so I believe this is indeed safe against all other potential issues.

Shesh6 avatar Sep 08 '22 20:09 Shesh6

I see. Yeah, this seems unlikely to be an issue so I'll stick to simply adding the ability to escape the $ character for now.

artisticat1 avatar Sep 09 '22 21:09 artisticat1