-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi there,
I've copied the fraction snippets from this repository, however I've noticed an issue with the fractional snippet inside of the maths environments. Specifically, I use the mk
environment to get the $...$
snippet. Normally, I should be able to tab out of the dollar signs. However, if I use the trigger
$ (1+2+3)/ $
I expect this to expand into
$ \frac{1+2+3}{[cursor here]} [tab here] $ [tab here]
This expands, and I can tab into the first tabstop, but then I can't tab out of the mk
snippet. I wanted to check if this was just a mk
specific issue, and it isn't exactly. I tried this with my align*
environment snippet and it will let me tab out of the fraction and the align environment.
However, the plot thickens. If I decide to do the following
\begin{align*} % triggered with snippet
\frac{(1+2)/ }{[tabstop here]} % frac with the // snippet, and the (1+2)/ expands to \frac{1+2}{[tabstop here]}
\end{align*}
I can no longer tab into the denominator of the fraction!
Please let me know how to resolve this issue.
Snippets
Here are all of the relevant snippets, which was determined by modifying snippets with text to make sure that they were triggered.
Fraction generation
local generate_fraction = function(_, snip)
local stripped = snip.captures[1]
local depth = 0
local j = #stripped
while true do
local c = stripped:sub(j, j)
if c == "(" then
depth = depth + 1
elseif c == ")" then
depth = depth - 1
end
if depth == 0 then
break
end
j = j - 1
end
return sn(
nil,
fmta(
[[
<>\frac{<>}{<>}
]],
{ t(stripped:sub(1, j - 1)), t(stripped:sub(j + 1, -2)), i(1) }
)
)
end
Note that I have tried many things including adding another i(2)
node after the fraction so that it can tab out, but it makes no difference to any of the cases described above.
Fraction trigger
s({
trig = "(^.*\\))/",
name = "fraction",
dscr = "auto fraction 2",
trigEngine = "ecma",
snippetType = "autosnippet",
}, { d(1, generate_fraction) }, { condition = tex.in_math, show_condition = tex.in_math }),
Maths mk
snippet
I've also tried to add i(0)
snippet, but it doesn't make any difference either.
s({ trig = "mk", snippetType = "autosnippet" }, {
t("$"),
i(1),
t("$"),
}, {
callbacks = {
[-1] = {
[events.leave] = function()
vim.cmd([[
autocmd InsertCharPre <buffer> ++once lua _G.if_char_insert_space()
]])
end,
},
},
}),
Maths Align Snippet algn
s(
{ trig = "algn", snippetType = "autosnippet" },
fmt(
[[
\begin{align*}
<>
\end{align*}
<>]],
{ i(1), i(0) },
{ delimiters = "<>" }
)
),
Environment
Latest versions of NeoVim, LazyVim, LuaSnip
No issues with other snippets. I will admit that I don't have the package directly installed, but I have copied almost all of the snippets, and the ones copied are exact.
Let me know if anything else will contribute to this / any more details or snippets that are necessary. I am not sure that it's an issue with nested snippets, as I have been able to run multiple snippets inside of each other and tab out of each successfully, in more "stable" snippets.
Thanks.