garymjr / nvim-snippets

Snippet support using native neovim snippets
MIT License
189 stars 13 forks source link

Error parsing some latex snippets related to math #36

Closed garymjr closed 1 week ago

garymjr commented 1 month ago

These two still cause errors when loaded by nvim-snippets. If I delete them, it works again. Let me know if I should open a separate issue for this.

Originally posted by @pitkling in https://github.com/garymjr/nvim-snippets/issues/23#issuecomment-2137530497

garymjr commented 1 month ago

This is an upstream issue with the current snippet parser in neovim. My guess is that a patch won’t be accepted for it either as it’s a not a format supported by the LSP snippets standard.

Do you know what those snippets are supposed to expand into? If I can find a way to pre-parse those values I can handle it similar to how I’m currently handling unsupported variables

pitkling commented 1 month ago

Inline Math (whose body is "$ $1 $$0" in friendly snippets) should expand to $ <tab1> $<tab0>" (where <tab…> indicates the usual snippet placeholders). The $ in the output are used by LaTeX to surround mathematical content.

From the documentation of the LSP snippet syntax, I would have actually expected that the snippet body should look more like "\$ $1 \$$0", properly escaping the literal $ signs.

Anyway, I checked how LuaSnip handles those snippet definitions, and indeed it returns the intended $ <tab1> $<tab0>". From a few tests, it seems that LuaSnip treats anything with a $ that is not a valid placeholder as literal output in the snippet. E.g., a body like "${0" expands simply to ${0, while a body like "${0}" expands to <tab0>. Interestingly, to have LuaSnip produce an output ${0} (instead of the snippet placeholder), I had to give it a a body like "\\${0}". From the LSP snippet syntax documentation, I would have assumed that this should actually be "\${0\}" or something like that, but such a body is not even recognized by LuaSnip. Or am I missing something? Nevermind, the double backslashes are necessary because of the JSON file format.

pitkling commented 1 week ago

FYI: I raised the issue with the incorrectly escaped LaTeX snippets in friendly-snippets (see rafamadriz/friendly-snippets#459) and they got recently fixed (some I found later are still pending but will probably also be fixed soon). So feel free to close this issue.

garymjr commented 1 week ago

Thanks for following up!