3

I've grown fond of electric-quote-mode in Emacs as a convenient way to get curved quotes in my documents. However, I can't seem to get it to work with either AUCTeX or BibTeX mode.

I'm aware AUCTeX has it's own support for quote insertion, which is quite advanced, interacting with babel and so on. But I'm a csquotes user and have in my preamble:

\usepackage[autostyle]{csquotes}
  \MakeAutoQuote{“}{”}
  \MakeAutoQuote*{‘}{’} % innerquotes

Correspondingly, I have in my .emacs (under use-package's :custom):

(LaTeX-csquotes-open-quote "“")
(LaTeX-csquotes-close-quote "”")
(LaTeX-csquotes-quote-after-quote nil)

I also have there:

(custom-set-variables
  ...
  '(electric-quote-mode t)
  ...
  )

AUCTeX support for quotes works of course, but has some inconveniences. First, it uses a different keyboard key for inserting quotes (double quote for AUCTeX and backtick for everything else with electric quote mode). Second, I can't seem to find a way to insert curved single quotes. Third, neither alternative works at all in BibTeX mode.

For quite sometime, I thought this problem had to do with something in my document which got parsed by AUCTeX. Indeed, opening a blank buffer and manually changing to LaTeX-mode gets me a buffer with a working electric quote mode. But, in testing further, I don't think this is the case. Consider the following minimal document:

\documentclass{article}

\begin{document}

\end{document}

If I let AUCTeX parse this document, producing the following auto/test.el:

(TeX-add-style-hook
 "test"
 (lambda ()
   (TeX-run-style-hooks
    "latex2e"
    "article"
    "art10"))
 :latex)

And then reopen it, electric-quote-mode no longer works (the backtick key inserts a plain backtick).

One possible source of conflict I considered is the math mode prefix, which is mapped to the backtick key by default. But I don't usually enable LaTeX-math-mode and even setting LaTeX-math-abbrev-prefix to "'" I still could not get electric quote mode to work.

In checking the keymap to the backtik (C-h k backtick) I see that it is mapped to self-insert-command in both LaTeX-mode and BibTeX-mode.

Any thoughts on why this fails and how I could get it to work?

0

For the record, I was able to solve this issue for AUCTeX by debugging my init file and find a workaround for BibTeX by getting a better grasp of electric-quote-mode.

As to the problems with AUCTeX, the culprit was that I, when moving to use-package, added the following to my init file:

(use-package latex
  :ensure auctex
  :mode ("\\.tex\\'" . TeX-latex-mode)

  ... etc ...)

I don't really recall why I've set it to TeX-latex-mode. I've actually researched quite a lot around to move AUCTeX to use-package, perhaps too much...

The fact is that either:

(use-package latex
  :ensure auctex
  :mode ("\\.tex\\'" . LaTeX-mode)

  ... etc ...)

or, even simpler:

(use-package latex
  :ensure auctex
  :defer t

  ... etc ...)

gets the job done and, with a working electric-quote-mode. I don't know why the problem arose in the first place, but that fixed it.

As to BibTeX-mode, the problem is that electric-quote-mode is designed to work only in paragraphs, comments and strings, according to the state of, respectively, electric-quote-paragraph, electric-quote-comment and electric-quote-string (the first two being t and the third nil, by default).

I don't know what Emacs considers a BibTeX buffer (not even outside an entry, electric quote works). But, this suggested the following workaround. I can comment the line of interest with C-x C-;. With the line commented, electric-quote then works. I edit the line to my desire, and uncomment it back with C-x C-;. That's less than optimal, of course, but should be enough for the eventual case when a title contains quotes within it, which is the only actual case I can think of where this is needed.

I leave this answer, in case anyone gets into the same trouble. But if anyone with more knowledge of the inner workings of these things would like to provide an actual explanation of what went wrong, I'll gladly accept that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.