Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-insert pair for pairs starting with \ #325

Open
pyfb78 opened this issue Jun 18, 2021 · 6 comments
Open

Auto-insert pair for pairs starting with \ #325

pyfb78 opened this issue Jun 18, 2021 · 6 comments

Comments

@pyfb78
Copy link

pyfb78 commented Jun 18, 2021

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.

@LunarWatcher
Copy link

LunarWatcher commented Jun 18, 2021

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.

@pyfb78
Copy link
Author

pyfb78 commented Jun 18, 2021

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?

@LunarWatcher
Copy link

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

LunarWatcher added a commit to LunarWatcher/auto-pairs that referenced this issue Jun 19, 2021
@LunarWatcher
Copy link

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)

@pyfb78
Copy link
Author

pyfb78 commented Jun 19, 2021

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.

@LunarWatcher
Copy link

LunarWatcher commented Jun 19, 2021

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)

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

No branches or pull requests

2 participants