From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language. Date: Tue, 04 Jun 2013 11:25:09 +0200 Message-ID: <87ppw26xe2.fsf_-_@pank.eu> References: <87sj12bwzj.fsf@pank.eu> <8661xvprju.fsf@somewhere.org> <87ehcj9uh7.fsf@pank.eu> <8638sz1e3b.fsf@somewhere.org> <87obbn8c36.fsf@pank.eu> <86wqqae5n4.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjnUf-0000Dw-QB for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 05:25:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjnUe-0002O8-5z for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 05:25:29 -0400 Received: from plane.gmane.org ([80.91.229.3]:34198) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjnUd-0002O2-SH for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 05:25:28 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UjnUY-0005BK-M9 for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 11:25:22 +0200 Received: from dynamic-adsl-94-34-191-111.clienti.tiscali.it ([94.34.191.111]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 Jun 2013 11:25:22 +0200 Received: from rasmus.pank by dynamic-adsl-94-34-191-111.clienti.tiscali.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 04 Jun 2013 11:25:22 +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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi Sebastien, >>> Behavior changes: >>> 1. =("AUTO" "babel" t)= works like ("AUTO" "inputenc" t) in >>> =`org-latex-default-packages-alist'=. I.e. the default >>> language is choosen (sic). >>> 2. if #+LANGUAGE: mylang then then \usepackage[mylang]{babel} in >>> outpu (sic). >> >> This message in five line. . . > > That's much clearer. Thanks, and sorry for not being specific enough if the first case. > Do I understand correctly that your patch does not change anything > for people who don't use AUTO for Babel in their > `org-latex-default-packages-alist'? Yes, and no, but mainly yes. The AUTO part should be completely autonomous to the setup you referred to. The AUTO part is always discarded. It changes behavior for your setup in that you can define a LANGUAGE that isn't a known abbreviation. Given your points the attached is a much more robust version of the patch, so thanks a lot. Examples, omitted from the commit message: Behavior changes: 1. =("AUTO" "babel" t)= works like ("AUTO" "inputenc" t) in =`org-latex-default-packages-alist'=. If a LANGUAGE-cookie is present this will be used, otherwise the default, =`org-export-default-language'= language is choose. 2. If #+LANGUAGE: mylang then then \usepackage[mylang]{babel} in output. Examples: 1. Assume ("AUTO" "babel" t) is a member of =`org-latex-default-packages-alist'= and default language is en. If =#+LANGUAGE: fr= is in the document AUTO is replaced with french. If =#+LANGUAGE: mylang= then AUTO is replaced with mylang. 2. Assume ("AUTO" "babel" t) is not a member of =`org-latex-default-packages-alist'= and assume LATEX_HEADER: \usepackage[english]{babel} and LANGUAGE: mylang. Then the exported result is \usepackage[english, mylang]{babel}. If \usepackage[AUTO,english]{babel} then As for 'robustness', the following case is handled correctly (from emacs -q with default org-latex-default-package-alist): #+LANGUAGE: da #+LATEX_HEADER: \usepackage[AUTO, danish]{babel} #+LANGUAGE: danish #+LATEX_HEADER: \usepackage[AUTO, danish]{babel} #+LANGUAGE: fr #+LATEX_HEADER: \usepackage[AUTO, danish, english]{babel} #+LANGUAGE: de #+LATEX_HEADER: \usepackage[danish, english, AUTO]{babel} Cheers, Rasmus -- Vote for proprietary math! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag_v2.patch >From 4de4fde0a5ba6d0eb8a9898e7e262f3f8fa5c6ea Mon Sep 17 00:00:00 2001 From: "rasmus.pank" Date: Sat, 1 Jun 2013 00:20:18 +0200 Subject: [PATCH] Allow AUTO argument to org-latex-guess-babel-language. * ox-latex.el (org-latex-guess-babel-language): ignore AUTO if it is the argument to (the LaTeX package) babel. * ox-latex.el (org-lat ex-guess-babel-language): if LANGUAGE: mylang and mylang is not a member =`org-latex-inputenc-alist'= use mylang (rather than discard it). * ox-latex.el (org-latex-guess-babel-language): retain case in final regexp of function. --- lisp/ox-latex.el | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index ff0ca1d..09a9103 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -910,6 +910,9 @@ 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 argument to Babel may be \"AUTO\" which is then replaced with +the language of the document or `org-export-default-language'. + Return the new header." (let ((language-code (plist-get info :language))) ;; If no language is set or Babel package is not loaded, return @@ -917,17 +920,26 @@ Return the new header." (if (or (not (stringp language-code)) (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-latex-babel-language-alist)))) - ;; If LANGUAGE is already loaded, return header. Otherwise, + (let ((options (save-match-data + ;; As with `org-latex-guess-inputenc' it only works with + ;; uppercase "AUTO + (remove "AUTO" + (org-split-string + ;; in case of [lang_one, lang_two] + (replace-regexp-in-string "[ \t\n]*" "" + (match-string 1 header)) ",")))) + (language (or + (cdr (assoc language-code + org-latex-babel-language-alist)) + language-code))) + ;; If LANGUAGE is already loaded, return header without AUTO. Otherwise, ;; append LANGUAGE to other options. - (if (member language options) header - (replace-match (mapconcat 'identity - (append options (list language)) - ",") - nil nil header 1)))))) + (replace-match (mapconcat 'identity + (if (member language options) + options + (append options (list language))) + ",") + t nil header 1))))) (defun org-latex--find-verb-separator (s) "Return a character not used in string S. -- 1.8.3 --=-=-=--