>From df91d417df3223c0698e56be219f8f1a303ce566 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 8 Jul 2015 14:12:21 +0200 Subject: [PATCH 8/9] ox-latex: Add polyglossia support * ox-latex.el (org-latex-guess-polyglossia-language): New function. (org-latex-template): Apply new function. --- lisp/ox-latex.el | 61 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index ff42843..058d7f8 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1195,6 +1195,45 @@ Return the new header." ", ") t nil header 1))))) +(defun org-latex-guess-polyglossia-language (header info) + "Set the Polyglossia language according to the LANGUAGE keyword. + +HEADER is the LaTeX header string. INFO is the plist used as +a communication channel. + +Insertion of guessed language only happens when the Polyglossia +package has been explicitly loaded. + +The argument to Polyglossia may be \"AUTO\" which is then +replaced with the language of the document or +`org-export-default-language'. Note, the language is really set +using \setdefaultlanguage and not as an option to the package. + +Return the new header." + (let ((language-code (plist-get info :language))) + ;; If no language is set or Polyglossia is not loaded, return + ;; HEADER as-is. + (if (or (not (stringp language-code)) + (not (string-match "\\\\usepackage\\[?\\(.*?\\)?\\]?{polyglossia}" header))) + header + (let* ((language (cdr (assoc language-code + org-latex-babel-language-alist))) + (options (or (org-string-nw-p (match-string 1 header)) "AUTO")) + (languages (save-match-data + (org-split-string + (replace-regexp-in-string + "AUTO" (if (string-match-p language options) "" language) + options t) + ",[ \t]*"))) + (main-language-set (string-match-p "\\\\setmainlanguage{.*?}" header))) + (replace-match + (concat "\\usepackage{polyglossia}\n" + (when (and languages (not main-language-set)) + (format "\\setmainlanguage{%s}" (pop languages))) + (when languages + (format "\n\\setotherlanguage{%s}\n" (mapconcat 'identity languages ", ")))) + t t header 0))))) + (defun org-latex--find-verb-separator (s) "Return a character not used in string S. This is used to choose a separator for constructs like \\verb." @@ -1349,16 +1388,18 @@ holding export options." class-options header t nil 1))))) (if (not document-class-string) (user-error "Unknown LaTeX class `%s'" class) - (org-latex-guess-babel-language - (org-latex-guess-inputenc - (org-element-normalize-string - (org-splice-latex-header - document-class-string - org-latex-default-packages-alist - org-latex-packages-alist nil - (concat (org-element-normalize-string - (plist-get info :latex-header)) - (plist-get info :latex-header-extra))))) + (org-latex-guess-polyglossia-language + (org-latex-guess-babel-language + (org-latex-guess-inputenc + (org-element-normalize-string + (org-splice-latex-header + document-class-string + org-latex-default-packages-alist + org-latex-packages-alist nil + (concat (org-element-normalize-string + (plist-get info :latex-header)) + (plist-get info :latex-header-extra))))) + info) info))) ;; Possibly limit depth for headline numbering. (let ((sec-num (plist-get info :section-numbers))) -- 2.4.5