Skip to content

Conversation

v3natio
Copy link

@v3natio v3natio commented Apr 3, 2025

Fix for #37

I added an implementation of the treesitter helper I use for my snippets.

Essentially it just leverages the treesitter nodes to detect whether we're in math mode (where the parent node is enclosed by $ or $$), or in text mode.

Then, I modified the find_search_start function so that it won't run if we're in math mode.

The only issue now, which I need some help for, is that whenever I have inbalanced braces within mathmode, then the treesitter helper will default back to textmode, and we run back into the issue we were trying to fix. For example:

$$
\begin{flalign*}
  &\left[ d_{d \right] &&\\
\end{flalign*}
$$

This is still better than the original, as before it would return the error even when braces were balanced.

@v3natio
Copy link
Author

v3natio commented Apr 3, 2025

Also, I decided that the best course of action would be to use treesitter, as string manipulation within the find_search_start function wouldn't be proper due to the use of display mode for math (where the $ signs are not in the same line as the math).

@@ -0,0 +1,66 @@
local M = {}

local ts = require "vim.treesitter"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local ts = require "vim.treesitter"
local ts = vim.treesitter

@neo451
Copy link
Member

neo451 commented Jun 15, 2025

Somehow in my memory I replied to this lol.

The issue is still there when I test? Is it fixed?

I still don't see the point of treesitter, since if $ is not on the same line, the error is not triggered.

Just use string:match is sufficient for the bug I think.

But a in_mathzone function is also great to have, there's a discussion here: https://github.com/orgs/obsidian-nvim/discussions/156

If treesitter is not good in the end because of the imblanced brackets, look at the vimtex implementation maybe? Translate the logic to lua would be ok. ( don't fret vimscript is you don't know it, just ask gpt :)

@neo451
Copy link
Member

neo451 commented Jun 15, 2025

Also remember to rebase to main, since a lot has happened.

@neo451
Copy link
Member

neo451 commented Jul 6, 2025

@v3natio any updates or feedbacks?

@v3natio
Copy link
Author

v3natio commented Jul 6, 2025

Hi, sorry I haven't replied. I got caught up with work. I plan on working on this during next week, hopefully can come up with an implementation for math_zone as per https://github.com/orgs/obsidian-nvim/discussions/156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants