Mac – Why does Emacs replace quotation marks incorrectly in LaTeX mode

auctexemacslatex

When writing LaTeX documents in Emacs, it usually automatically replaces quotation marks " by `` or '', as it should. But sometimes, it incorrectly replaces by "` and "' instead. I am observing this in Emacs 23.4 supplied as version 23.4+1-4ubuntu1 in Ubuntu 13.04.

It happens in the below example:

\documentclass[danish]{article}
\usepackage{babel}
\begin{document}
This is a "`test"'.
\end{document}

My guess is that babel and the language option danish is causing this together with AUCTeX. If I change it to english and reset AUCTeX, the problem disappears. If I change it back to danish and reset AUCTeX it re-appears.
How can I fix this?

Best Answer

AUCTeX has a special support for many languages, for example it can help inserting quotes. For more information see the AUCTeX manual.

If you don't like the default style of quotes inserted by AUCTeX for a specific language, you can override it customizing the TeX-quote-language-alist variable. To do that add this to your .emacs:

(setq TeX-quote-language-alist '(("danish" "``" "''" t)))

In this way pressing " button twice you will get `` or '' according to context. Instead, if you want to insert `` and '' pressing " button just once, add the following code to your .emacs:

(add-hook 'TeX-language-dk-hook
      (lambda ()
        (setq TeX-quote-language `("danish" "``" "''" ,TeX-quote-after-quote))))