From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: new (LaTeX) exporter and date formatting Date: Thu, 14 Jun 2012 13:42:08 +0200 Message-ID: <874nqe9l2n.fsf@gmail.com> References: <87ehqbxrz1.fsf@med.uni-goettingen.de> <87sjerav34.fsf@gmail.com> <871umay444.fsf@med.uni-goettingen.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:60206) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sf8UN-0003ig-Fy for emacs-orgmode@gnu.org; Thu, 14 Jun 2012 07:45:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sf8UK-0000IY-26 for emacs-orgmode@gnu.org; Thu, 14 Jun 2012 07:45:23 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:64496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sf8UJ-0000HT-MO for emacs-orgmode@gnu.org; Thu, 14 Jun 2012 07:45:19 -0400 Received: by wgbds1 with SMTP id ds1so1177108wgb.30 for ; Thu, 14 Jun 2012 04:45:17 -0700 (PDT) In-Reply-To: <871umay444.fsf@med.uni-goettingen.de> (Andreas Leha's message of "Wed, 23 May 2012 23:33:31 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Andreas Leha Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Andreas Leha 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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-e-latex-Set-Babel-language-according-to-LANGUAGE.patch Content-Description: set babel language >From 1f9a6385e961e61d8b5e5e4d56889c7b2bd9f82b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou 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 --=-=-=--