otter.nvim icon indicating copy to clipboard operation
otter.nvim copied to clipboard

Feature request: activate otter in LaTeX math blocks

Open kamalsacranie opened this issue 2 years ago • 7 comments

Was wondering if it would be possible to activate otter when you are either in:

$$
...
$$

or

This is my equation:

\begin{...}
...
\begin{...}

kamalsacranie avatar Mar 01 '23 18:03 kamalsacranie

Not yet, but a couple of days ago the markdown treesitter grammar got support for latex chunks (https://github.com/MDeiml/tree-sitter-markdown/commit/7e7aa9a25ca9729db9fe22912f8f47bdb403a979). This will make it straightforward to write a query to get the latex content. But in order to use that I will have to make some internal changes in https://github.com/jmbuhr/otter.nvim/blob/8b46caf113918c26a9247031d6482709078ec907/lua/otter/keeper.lua#L20 because right now it only supports one query per buffer and that captures both the language and the content (e.g. a code chunk in markdown).

That being said, if you are just after completion for math symbols I find that it is convenient to enable them for the whole document anyways, so there is not need for a separate treatment of math blocks. Here are some examples: https://www.youtube.com/watch?v=Lc_kMYVIS5I

jmbuhr avatar Mar 01 '23 22:03 jmbuhr

This should be solved with the latest update that can use injections to find code chunks.

jmbuhr avatar Jun 18 '23 09:06 jmbuhr

@jmbuhr do you have a sample configuration? I can't get this to work :/

Myzel394 avatar Nov 14 '23 14:11 Myzel394

from what I can see markdown_inline parser needs to be called for this, since the injections in the markdown parser only include code blocks

anuramat avatar Jan 11 '25 23:01 anuramat

Indeed, I just realized that this doesn't currently work because the parser for the document is markdown, which itself injects the markdown-inline parser into blocks, which then can inject latex. However, otter currently doesn't support multiple levels of injections. This is a good use case to show why we might want this.

jmbuhr avatar Jan 12 '25 09:01 jmbuhr

Does this also prevent fenced latex code blocks from working?

Jakobuo avatar May 08 '25 19:05 Jakobuo

No, fenced code blocks should be only one level of injections, so it should work.

jmbuhr avatar May 08 '25 22:05 jmbuhr