jiangmiao/auto-pairs

Auto-insert pair for pairs starting with \

Opened this issue · 6 comments

I use auto-pairs for autocompleting "(" : ")", "[" : "]", "{" : "}". I was wondering if there was any way for me to auto-complete "\[" : "\]" when I am writing latex. Same with "\(" : "\)". I read that it disables auto-completion when the pairs start with "\". Is there any way to disable that? Thanks.

Last I checked, it only ignores pairs that are prefixed with a \. As an immediate hack, that means '\[' as an opening pair should be fine (because escaping that would be typing \\[, so the first backslash shouldn't break it). You may need to use '\\[' to make sure the backslash isn't interpreted, though - that's at least a requirement in my fork, and there isn't a big diverge on that front IIRC.

Last I checked, it only ignores pairs that are prefixed with a . As an immediate hack, that means '\[' as an opening pair should be fine (because escaping that would be typing \\[, so the first backslash shouldn't break it). You may need to use '\\[' to make sure the backslash isn't interpreted, though - that's at least a requirement in my fork, and there isn't a big diverge on that front IIRC.
After I put the installed auto-pairs using vim-plug, I put the line

au Filetype tex let b:AutoPairs = AutoPairsDefine({'$':'$','\\[':'\\]'})
However, it only inserts the pairs for $. It doesn't autocomplete for the second pair I put. Am I doing anything wrong?

Looked into it - there's a fundamental flaw in pair escaping that essentially disables single-byte pairs with a preceding backslash. Looking into patching it

I've (theoretically) fixed this -- you'll need to switch to my fork to use it, though (I'd merge it in, but the original maintainer is missing; there's other issues pointing this out in case you need to verify). Don't mind the CI error, that's just the Mac VM for some reason not starting -- blame GitHub.

You don't need to escape the backslash in the close pair, though. Works fine with:

let g:AutoPairs = autopairs#AutoPairsDefine([{'open': '\\[', 'close': '\]', 'filetype': 'tex'}])

('$': '$' is already defined as a default pair, and is therefore unnecessary to define)

I've (theoretically) fixed this -- you'll need to switch to my fork to use it, though (I'd merge it in, but the original maintainer is missing; there's other issues pointing this out in case you need to verify). Don't mind the CI error, that's just the Mac VM for some reason not starting -- blame GitHub.

You don't need to escape the backslash in the close pair, though. Works fine with:

let g:AutoPairs = autopairs#AutoPairsDefine([{'open': '\\[', 'close': '\]', 'filetype': 'tex'}])

('$': '$' is already defined as a default pair, and is therefore unnecessary to define)
I switched to your fork and when I type \[, nothing happens. I have to type \\[ for me to get the other pair which is \]. So, I'm left with \\[ | \]. | is the cursor. I tried to switch the command you gave me to
let g:AutoPairs = autopairs#AutoPairsDefine([{'open': '\[', 'close': '\]', 'filetype': 'tex'}]),
but as expected with that, it doesn't work.

The bugfix hasn't been tagged yet (upd.: has been tagged now) - make sure you're using the master branch and not a tagged version like the readme recommends (it's usually fine, just not while testing fixes to bugs)