Function: org-latex-guess-babel-language
org-latex-guess-babel-language is a byte-compiled function defined in
ox-latex.el.gz.
Signature
(org-latex-guess-babel-language HEADER INFO)
Documentation
Set Babel's language according to LANGUAGE keyword.
HEADER is the LaTeX header string. INFO is the plist used as a communication channel.
Insertion of guessed language only happens when Babel package has explicitly been loaded. Then it is added to the rest of package's options.
The optional argument to Babel or the mandatory argument to
abelprovide command may be "AUTO" which is then replaced
with the language of the document or
org-export-default-language unless language in question is
already loaded.
Return the new header.
Source Code
;; Defined in /usr/src/emacs/lisp/org/ox-latex.el.gz
(defun org-latex-guess-babel-language (header info)
"Set Babel's language according to LANGUAGE keyword.
HEADER is the LaTeX header string. INFO is the plist used as
a communication channel.
Insertion of guessed language only happens when Babel package has
explicitly been loaded. Then it is added to the rest of
package's options.
The optional argument to Babel or the mandatory argument to
`\babelprovide' command may be \"AUTO\" which is then replaced
with the language of the document or
`org-export-default-language' unless language in question is
already loaded.
Return the new header."
(let* ((language-code (plist-get info :language))
(plist (cdr
(assoc language-code org-latex-language-alist)))
(language (plist-get plist :babel))
(language-ini-only (plist-get plist :babel-ini-only))
;; If no language is set, or Babel package is not loaded, or
;; LANGUAGE keyword value is a language served by Babel
;; exclusively through ini files, return HEADER as-is.
(header (if (or language-ini-only
(not (stringp language-code))
(not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
header
(let ((options (save-match-data
(org-split-string (match-string 1 header) ",[ \t]*"))))
;; If LANGUAGE is already loaded, return header
;; without AUTO. Otherwise, replace AUTO with language or
;; append language if AUTO is not present. Languages that are
;; served in Babel exclusively through ini files are not added
;; to the babel argument, and must be loaded using
;; `\babelprovide'.
(replace-match
(mapconcat (lambda (option) (if (equal "AUTO" option) language option))
(cond ((member language options) (delete "AUTO" options))
((member "AUTO" options) options)
(t (append options (list language))))
", ")
t nil header 1)))))
;; If `\babelprovide[args]{AUTO}' is present, AUTO is
;; replaced by LANGUAGE.
(if (not (string-match "\\\\babelprovide\\[.*\\]{\\(.+\\)}" header))
header
(let ((prov (match-string 1 header)))
(if (equal "AUTO" prov)
(replace-regexp-in-string (format
"\\(\\\\babelprovide\\[.*\\]\\)\\({\\)%s}" prov)
(format "\\1\\2%s}"
(or language language-ini-only))
header t)
header)))))