1 ;;; babel.el --- AUCTeX style for `babel.sty' version 3.9h.
3 ;; Copyright (C) 2005, 2007, 2013-2014 Free Software Foundation, Inc.
5 ;; Author: Ralf Angeli <angeli@iwi.uni-sb.de>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 ;; This file adds support for `babel.sty' version 3.9h.
33 (defvar LaTeX-babel-language-list
35 "bahasa" "indonesian" "indon" "bahasai" "bahasam" "malay" "meyalu"
44 "english" "USenglish" "american" "UKenglish" "british" "canadian"
45 "australian" "newzealand"
49 "french" "francais" "canadien" "acadian"
51 "austrian" "german" "germanb" "ngerman" "naustrian"
52 "greek" "polutonikogreek"
63 "portuges" "portuguese" "brazilian" "brazil"
76 ;; Extra languages mentioned in the `babel' manual.
77 "albanian" "hindi" "thai" "thaicjk" "latvian" "turkmen" "hungarian" "magyar"
78 "mongolian" "romansh" "lithuanian" "spanglish" "vietnamese" "japanese"
79 "pinyin" "arabinc" "farsi" "ibygreek" "bgreek" "serbianic" "frenchle"
80 "ethiop" "friulan" "frenchb")
81 "List of languages supported by the babel LaTeX package.")
83 (defun LaTeX-babel-active-languages ()
84 "Return a list of languages used in the document."
85 (let (main-language active-languages)
86 ;; Loop over options provided to class and `babel' package at load time.
88 ;; In most cases there is only one element in the alist, if
89 ;; there is more than one element, the first one should
90 ;; contain the class options of the current buffer. So we can
91 ;; take the car of `LaTeX-provided-class-options'.
92 (cdr (car LaTeX-provided-class-options))
93 (cdr (assoc "babel" LaTeX-provided-package-options))))
94 (setq elt (TeX-split-string "=" elt))
95 (if (equal (car elt) "main")
96 ;; Starting from version 3.9 of `babel' package, languages can be set
97 ;; with the following syntax:
98 ;; \usepackage[latin.medieval,main=danish,spanish.notilde]{babel}
99 ;; with `danish' being the default language. When the default
100 ;; language is set with the `main' option, we record it and append to
101 ;; the list at the end.
102 (setq main-language (car (cdr elt)))
103 ;; Get rid of the modifiers (`medieval' and `notilde' in the above
105 (setq elt (car (TeX-split-string "\\." (car elt))))
106 (if (member elt LaTeX-babel-language-list)
107 ;; Append element to `active-languages' to respect loading order.
108 ;; `babel' package uses as default language the last loaded one,
109 ;; except if it is set with the `main' option.
110 (add-to-list 'active-languages elt t))))
112 (add-to-list 'active-languages main-language t))
115 (defun TeX-arg-babel-lang (optional &optional prompt)
116 "Prompt for a language with completion and insert it as an argument."
118 (completing-read "Language: " (LaTeX-babel-active-languages)) nil))
120 (defun LaTeX-env-babel-lang (env)
121 "Prompt for a language and insert it as an argument of ENV."
122 (LaTeX-insert-environment
123 env (format "{%s}" (completing-read "Language: "
124 (LaTeX-babel-active-languages)))))
126 (defun LaTeX-babel-load-languages ()
127 "Load style files of babel active languages."
128 ;; Run style hooks for every active language in loading order, so
129 ;; `TeX-quote-language' will be correctly set.
130 (mapc 'TeX-run-style-hooks (LaTeX-babel-active-languages)))
135 (LaTeX-babel-load-languages)
136 (add-hook 'LaTeX-after-usepackage-hook 'LaTeX-babel-load-languages nil t)
139 '("selectlanguage" TeX-arg-babel-lang)
140 '("foreignlanguage" TeX-arg-babel-lang t)
142 '("iflanguage" TeX-arg-babel-lang t nil)
144 '("defineshorthand" t nil)
145 '("aliasshorthand" t nil)
146 '("languageshorthands" TeX-arg-babel-lang)
149 '("languageattribute" TeX-arg-babel-lang t))
151 (LaTeX-add-environments
152 '("otherlanguage" LaTeX-env-babel-lang)
153 '("otherlanguage*" LaTeX-env-babel-lang)
154 '("hyphenrules" LaTeX-env-babel-lang))
156 (when (and (featurep 'font-latex)
157 (eq TeX-install-font-lock 'font-latex-setup))
158 (font-latex-add-keywords '(("selectlanguage" "{")
159 ("foreignlanguage" "{{")
162 ("useshorthands" "{")
163 ("languageshorthands" "{")
165 ("shorthandoff" "{"))
167 (font-latex-add-keywords '(("defineshorthand" "{{")
168 ("aliasshorthand" "{{")
169 ("languageattribute" "{{"))
173 (defun LaTeX-babel-package-options ()
174 "Prompt for package options for the babel package."
178 '(("KeepShorthandsActive")
182 ("safe" ("none" "ref" "bib"))
183 ("math" ("active" "normal"))
185 ("main" LaTeX-babel-language-list)
186 ("headfoot" LaTeX-babel-language-list)
189 ("strings" ("generic" "unicode" "encoded"))
190 ("hyphenmap" ("off" "main" "select" "other" "other*"))
192 (mapcar 'list LaTeX-babel-language-list))))
194 ;;; babel.el ends here