2

Q: how do I get smartparens not to insert a pair of ``LaTeX'' quotes?

The goal

I set up smartparens to insert a pair of quotation marks unless point is just before a word or just after it, where * is point:

some text * some more text ==> some text "*" some more text *some text ==> "*some text some text* ==> some text"* 

I have it set up for text-mode and org-mode like so:

(sp-local-pair '(text-mode org-mode) "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p)) 

The problem

LaTeX is goofy with ``double quotes'' and `single quotes'. That is: double quotes are done with two backticks on the front and two ticks at the end. This doesn't work:

(sp-local-pair '(latex-mode) "\"" nil :unless '(sp-point-before-word-p sp-point-after-word-p)) 

The ugly "solution"

After much tinkering, the following works somewhat:

(with-eval-after-load "latex" (sp-local-pair '(latex-mode) "`" nil :unless '(sp-point-before-word-p)) (sp-local-pair '(latex-mode) "'" nil :unless '(sp-point-after-word-p)) (sp-local-pair '(latex-mode) "``" nil :unless '(sp-point-before-word-p)) (sp-local-pair '(latex-mode) "''" nil :unless '(sp-point-after-word-p))) 

But that seems a little ludicrous for such simple functionality. It's also far from perfect, in that I get new and sometimes baffling errors from yasnippet, of all things.

The mournful appeal

Am I missing some simple, LaTeX-specific way of doing this?

10
  • Sorry, what does "LaTex is goofy" mean? Doesn't work how? Commented Mar 1, 2017 at 21:29
  • @Tyler: edited: an opening quote is comprised of two backticks, and a closing quote is comprised of two ticks (ie, apostrophes). Commented Mar 1, 2017 at 21:34
  • Sorry, I don't understand what you want to eventually achieve: do you want an easy way to insert ``LaTeX'' quotes? Do you use AUCTeX? Commented Mar 2, 2017 at 8:08
  • @giordano: yes, I'm using AUCTeX. smartparens inserts pairs of parentheses, quotes, etc. When I enter ", it gives me a pair of LaTeX quotes. I want it to do that except when point is just before the start of a word (when I want it to insert just the opening quote) or just after the end of a word (when I want it to insert just the closing quote). Commented Mar 2, 2017 at 13:18
  • Why not just use C-q " in the special situations? Commented Mar 3, 2017 at 8:34

1 Answer 1

1

I believe I have it. The goal is to get smartparens to:

  • insert a pair of ``LaTeX quotes''
  • unless at the beginning of a word, when it inserts the ``opening quote
  • unless at the end of a word, when it inserts the closing quote''

Here's the code:

(require 'smartparens-latex) (sp-local-pair '(tex-mode plain-tex-mode latex-mode LaTeX-mode) "``" "''" :trigger "\"" :unless '(sp-latex-point-after-backslash sp-point-before-word-p sp-point-after-word-p) :pre-handlers '(sp-latex-pre-slurp-handler) :post-handlers '(sp-latex-skip-double-quote)) (sp-local-pair '(tex-mode plain-tex-mode latex-mode LaTeX-mode) "`" "'" :trigger "'" :unless '(sp-latex-point-after-backslash sp-point-before-word-p sp-point-after-word-p) :pre-handlers '(sp-latex-pre-slurp-handler) :post-handlers '(sp-latex-skip-double-quote)) 

Note that this modifies the settings I found when digging around in the code base in smartparens-latex.

NB: this only seems to work if you redefine the local pair for both the double quotes and the single quotes. If you do only the former, this is what you get when trying to insert a double quote at the beginning of a word:

``'gasp, clutch my pearls 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.