TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to setup AUCTeX so that it loads the spelling dictionary in the same language as the language used by polyglossia? For example, is it possible to load the Danish ispell dictionary when a document includes \usepackage{polyglossia} and \setdefaultlanguage{danish}?

The answer to How can I make AUCTeX use the spelling dictionary in the same language as babel is loaded with? does not seem to apply to this case.

share|improve this question
up vote 8 down vote accepted

I can't test this, as I don't have multiple dictionaries on hand. But it should get you started if it doesn't work completely (to be added to your .emacs):

;; replace the language names and dictionary paths below to suit your setup:

(defvar my-dicts 
  '(("danish" . "path-to-my-danish-dictionary") 
    ("english" . "path-to-my-english-dictionary"))
  "An alist of dictionaries to pick from")

(defun polyglossia-check ()
  "If polyglossia is loaded, sets the dictionary to the value in my-dicts
   corresponding to the value of setdefaultlanguage or setmainlanguage."
      (= (shell-command (concat "grep polyglossia " default-directory
                              TeX-auto-local "/*"))
        (re-search-forward "\\(setdefaultlanguage\\|setmainlanguage\\){")
        (let ((lang (buffer-substring (point) (mark))))
          (setq ispell-local-dictionary (cdr (assoc lang my-dicts)))))))

(add-hook 'TeX-auto-cleanup-hook 'polyglossia-check)

The hook will run the whenever your document is parsed. I'm not sure how often this happens. If it doesn't seem to work, try calling M-x polyglossia-check explicitly.

share|improve this answer
The \setdefaultlanguage command can be called also \setmainlanguage and many people use the latter in analogy to the \setmainfont command of fontspec. – egreg Jul 24 '12 at 16:58
@egreg, switched to a regexp search, which should work for either form now. – Tyler Jul 24 '12 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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