emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] new (LaTeX) exporter and date formatting


From: Nicolas Goaziou
Subject: Re: [O] new (LaTeX) exporter and date formatting
Date: Thu, 14 Jun 2012 13:42:08 +0200

Hello,

Andreas Leha <address@hidden> writes:

>>> Side note:
>>> Ideally, in my opinion, the LaTeX-exporter would honor the
>>> "#+LANGUAGE: XX"
>>> setting and change the babel-settings accordingly
>>
>> That seems reasonable. Is there any translation table between language
>> symbols and Babel options?
>
> Not that I am aware of.  But we could start one quite easily.  I got
> this list of LaTeX-babel supported languages from
> http://www.tug.org/texlive/Contents/live/texmf-dist/doc/generic/babel/babel.pdf:
> (just a quick hack...)

The following patch should add the language option according to LANGUAGE
keywords if babel package is explicitly loaded in preamble.

Is it what you had in mind? I'm a bit reluctant to load babel package if
not present.


Regards,

-- 
Nicolas Goaziou
>From 1f9a6385e961e61d8b5e5e4d56889c7b2bd9f82b Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
Date: Thu, 14 Jun 2012 12:57:35 +0200
Subject: [PATCH] org-e-latex: Set Babel language according to LANGUAGE
 keyword

* contrib/lisp/org-e-latex.el (org-e-latex-babel-language-alist): New
  variable.
(org-e-latex--guess-babel-language): New function.
(org-e-latex-template): Set babel language according to LANGUAGE keyword.
---
 contrib/lisp/org-e-latex.el |   93 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 83 insertions(+), 10 deletions(-)

diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el
index 287556f..6feb8cf 100644
--- a/contrib/lisp/org-e-latex.el
+++ b/contrib/lisp/org-e-latex.el
@@ -147,6 +147,63 @@ structure of the values.")
 
 
 
+;;; Internal Variables
+
+(defconst org-e-latex-babel-language-alist
+  '(("af" . "afrikaans")
+    ("bg" . "bulgarian")
+    ("bt-br" . "brazilian")
+    ("ca" . "catalan")
+    ("cs" . "czech")
+    ("cy" . "welsh")
+    ("da" . "danish")
+    ("de" . "german")
+    ("de" . "germanb")
+    ("de-at" . "austrian")
+    ("de-at" . "naustrian")
+    ("de-de" . "ngerman")
+    ("el" . "greek")
+    ("en" . "english")
+    ("en-au" . "australian")
+    ("en-ca" . "canadian")
+    ("en-gb" . "british")
+    ("en-ie" . "irish")
+    ("en-nz" . "newzealand")
+    ("en-us" . "american")
+    ("es" . "spanish")
+    ("et" . "estonian")
+    ("eu" . "basque")
+    ("fi" . "finnish")
+    ("fr" . "frenchb")
+    ("fr-ca" . "canadien")
+    ("gl" . "galician")
+    ("hr" . "croatian")
+    ("hu" . "hungarian")
+    ("id" . "indonesian")
+    ("is" . "icelandic")
+    ("it" . "italian")
+    ("la" . "latin")
+    ("ms" . "malay")
+    ("nl" . "dutch")
+    ("no-no" . "nynorsk")
+    ("pl" . "polish")
+    ("pt" . "portuguese")
+    ("ro" . "romanian")
+    ("ru" . "russian")
+    ("sa" . "sanskrit")
+    ("sb" . "uppersorbian")
+    ("sk" . "slovak")
+    ("sl" . "slovene")
+    ("sq" . "albanian")
+    ("sr" . "serbian")
+    ("sv" . "swedish")
+    ("ta" . "tamil")
+    ("tr" . "turkish")
+    ("uk" . "ukrainian"))
+  "Alist between language code and corresponding Babel option.")
+
+
+
 ;;; User Configurable Variables
 
 (defgroup org-export-e-latex nil
@@ -815,12 +872,26 @@ For non-floats, see `org-e-latex--wrap-label'."
                label-str
                (org-export-data (car caption) info))))))
 
+(defun org-e-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.  Return the new header."
+  (let ((language-code (plist-get info :language)))
+    ;; If no language is set, return HEADER as-is.
+    (if (not (stringp language-code)) header
+      (if (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header))
+         header
+       (let ((options (save-match-data
+                        (org-split-string (match-string 1 header) ",")))
+             (language (cdr (assoc language-code
+                                   org-e-latex-babel-language-alist))))
+         (if (member language options) header
+           (replace-match (mapconcat 'identity (cons language options) ",")
+                          nil nil header 1)))))))
+
 (defun org-e-latex--guess-inputenc (header)
   "Set the coding system in inputenc to what the buffer is.
-
-HEADER is the LaTeX header string.
-
-Return the new header."
+HEADER is the LaTeX header string.  Return the new header."
   (let* ((cs (or (ignore-errors
                   (latexenc-coding-system-to-inputenc
                    buffer-file-coding-system))
@@ -936,12 +1007,14 @@ holding export options."
                          "^[ \t]*\\\\documentclass\\(\\[.*?\\]\\)"
                          class-options header t nil 1)
                       header))))
-         (org-e-latex--guess-inputenc
-          (org-splice-latex-header
-           document-class-string
-           org-export-latex-default-packages-alist ; defined in org.el
-           org-export-latex-packages-alist nil ; defined in org.el
-           (plist-get info :latex-header-extra))))))
+         (org-e-latex--guess-babel-language
+          (org-e-latex--guess-inputenc
+           (org-splice-latex-header
+            document-class-string
+            org-export-latex-default-packages-alist ; defined in org.el
+            org-export-latex-packages-alist nil ; defined in org.el
+            (plist-get info :latex-header-extra)))
+          info))))
      ;; 3. Define alert if not yet defined.
      "\\providecommand{\\alert}[1]{\\textbf{#1}}\n"
      ;; 4. Possibly limit depth for headline numbering.
-- 
1.7.10.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]