emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
@ 2013-05-31 22:33 Rasmus
  2013-06-01  5:31 ` Achim Gratz
  2013-06-03  7:44 ` Sebastien Vauban
  0 siblings, 2 replies; 23+ messages in thread
From: Rasmus @ 2013-05-31 22:33 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]


This patch allows ox-latex to make a guess on which  language to use
if babel is a default package.  See the head of the patch.

Two notes on the funcion:

1.  As far as I remember, if more than one language is loaded the
order is not neutral one one should issue a \selectlanguage{LANG}.  

2. Perhaps it should look for babel /and/ pologlossya or whatever the
package the xelatex and perhaps lualatex uses.  Any thoughs?

–Rasmus

-- 
Together we'll stand, divided we'll fall

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag.patch --]
[-- Type: text/x-patch, Size: 2049 bytes --]

From dde65056267bcb4c1bfe23c2e66f570739bb72c7 Mon Sep 17 00:00:00 2001
From: "rasmus" <rasmus@gmx.us>
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 argument.
	* ox-latex.el (org-lat ex-guess-babel-language): use language
	if is not in =`org-latex-inputenc-alist'=.
	* ox-latex.el	 (org-latex-guess-babel-language): retain case
	in final regexp of function.

Behavior changes:
1.  =("AUTO" "babel" t)= works like ("AUTO" "inputenc" t) in
	=`org-latex-default-packages-alist'=. I.e. the default
	language is choosen.
2. if #+LANGUAGE: mylang then then \usepackage[mylang]{babel} in
	outpu.

TINYCHANGE
---
 lisp/ox-latex.el | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 3a01693..033d318 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -929,19 +929,21 @@ Return the new header."
     ;; If no language is set or Babel package is not loaded, return
     ;; HEADER as-is.
     (if (or (not (stringp language-code))
-	    (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
+	    (not (string-match "\\\\usepackage\\[\\(AUTO\\)?,?\\(.*\\)\\]{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))))
+		       (org-split-string (match-string 2 header) ",")))
+	    (language (or
+		       (cdr (assoc language-code
+				      org-latex-babel-language-alist))
+		       language-code)))
 	;; If LANGUAGE is already loaded, return header.  Otherwise,
 	;; append LANGUAGE to other options.
 	(if (member language options) header
 	  (replace-match (mapconcat 'identity
 				    (append options (list language))
 				    ",")
-			 nil nil header 1))))))
+			 t nil header 1))))))

 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
--
1.8.3

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-05-31 22:33 [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language Rasmus
@ 2013-06-01  5:31 ` Achim Gratz
  2013-06-01 13:59   ` Rasmus
  2013-06-03  7:44 ` Sebastien Vauban
  1 sibling, 1 reply; 23+ messages in thread
From: Achim Gratz @ 2013-06-01  5:31 UTC (permalink / raw)
  To: emacs-orgmode

Rasmus writes:
> This patch allows ox-latex to make a guess on which  language to use
> if babel is a default package.  See the head of the patch.

What's the status of your copyright assignment?  You're neither listed
as a contributor nor as one of the people whose papers are in processing
(see http://orgmode.org/worg/org-contribute.html) although you've
mentioned that you might consider assigning copyright just recently.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptation for Waldorf rackAttack V1.04R1:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-01  5:31 ` Achim Gratz
@ 2013-06-01 13:59   ` Rasmus
  2013-06-01 14:07     ` Rasmus
  0 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-01 13:59 UTC (permalink / raw)
  To: Stromeko; +Cc: emacs-orgmode

Dear Achim,

> Rasmus writes:
>> This patch allows ox-latex to make a guess on which  language to use
>> if babel is a default package.  See the head of the patch.
>
> What's the status of your copyright assignment?  You're neither listed
> as a contributor nor as one of the people whose papers are in processing
> (see http://orgmode.org/worg/org-contribute.html) although you've
> mentioned that you might consider assigning copyright just recently.

I'm not assigned but I'm happy to.  Should I start the process?  I
haven't made any significant contributions to "org-core".

–Rasmus

-- 
When in doubt, do it!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-01 13:59   ` Rasmus
@ 2013-06-01 14:07     ` Rasmus
  0 siblings, 0 replies; 23+ messages in thread
From: Rasmus @ 2013-06-01 14:07 UTC (permalink / raw)
  To: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Dear Achim,
>
>> Rasmus writes:
>>> This patch allows ox-latex to make a guess on which  language to use
>>> if babel is a default package.  See the head of the patch.
>>
>> What's the status of your copyright assignment?  You're neither listed
>> as a contributor nor as one of the people whose papers are in processing
>> (see http://orgmode.org/worg/org-contribute.html) although you've
>> mentioned that you might consider assigning copyright just recently.
>
> I'm not assigned but I'm happy to.  Should I start the process?  I
> haven't made any significant contributions to "org-core".


I've send an email to assing at gnu just now. 

-- 
Powered by magic pixies!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-05-31 22:33 [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language Rasmus
  2013-06-01  5:31 ` Achim Gratz
@ 2013-06-03  7:44 ` Sebastien Vauban
  2013-06-03 13:47   ` Rasmus
  1 sibling, 1 reply; 23+ messages in thread
From: Sebastien Vauban @ 2013-06-03  7:44 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Rasmus,

Rasmus wrote:
> 1.  As far as I remember, if more than one language is loaded the
> order is not neutral one one should issue a \selectlanguage{LANG}.

If there are multiple languages, the main language is the latest loaded; that
is `english' in the following example:

    \RequirePackage[frenchb,english]{babel}

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-03  7:44 ` Sebastien Vauban
@ 2013-06-03 13:47   ` Rasmus
  2013-06-03 14:08     ` Sebastien Vauban
  0 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-03 13:47 UTC (permalink / raw)
  To: emacs-orgmode

"Sebastien Vauban" <sva-news@mygooglest.com>
writes:

> Hello Rasmus,
>
> Rasmus wrote:
>> 1.  As far as I remember, if more than one language is loaded the
>> order is not neutral one one should issue a \selectlanguage{LANG}.
>
> If there are multiple languages, the main language is the latest loaded; that
> is `english' in the following example:
>
>     \RequirePackage[frenchb,english]{babel}

So if a #+LANGUAGE: LANG cookie is present I guess it should be loaded
last.  Or a \selectlanguage{LANG} should be issued.

Non-rigorous testing suggests that it will do the former now on master
and thus presumably also in the patch.

–Rasmus

-- 
El Rey ha muerto. ¡Larga vida al Rey!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-03 13:47   ` Rasmus
@ 2013-06-03 14:08     ` Sebastien Vauban
  2013-06-03 15:10       ` Rasmus
  0 siblings, 1 reply; 23+ messages in thread
From: Sebastien Vauban @ 2013-06-03 14:08 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Rasmus wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes:
>> Rasmus wrote:
>>> 1.  As far as I remember, if more than one language is loaded the
>>> order is not neutral one one should issue a \selectlanguage{LANG}.
>>
>> If there are multiple languages, the main language is the latest loaded; that
>> is `english' in the following example:
>>
>>     \RequirePackage[frenchb,english]{babel}
>
> So if a #+LANGUAGE: LANG cookie is present I guess it should be loaded
> last.  Or a \selectlanguage{LANG} should be issued.
>
> Non-rigorous testing suggests that it will do the former now on master
> and thus presumably also in the patch.

AFAICT, this is so since a while. Nicolas implemented the above described
behavior months ago...

See http://lists.gnu.org/archive/html/emacs-orgmode/2012-06/msg00387.html.

Doesn't that work for you already in Org core as it is?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-03 14:08     ` Sebastien Vauban
@ 2013-06-03 15:10       ` Rasmus
  2013-06-04  6:45         ` Sebastien Vauban
  0 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-03 15:10 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: public-sva-news-D0wtAvR13HarG/iDocfnWg

Dear Sebastien,

>>>> 1.  As far as I remember, if more than one language is loaded the
>>>> order is not neutral one one should issue a \selectlanguage{LANG}.
>>>
>>> If there are multiple languages, the main language is the latest loaded; that
>>> is `english' in the following example:
>>>
>>>     \RequirePackage[frenchb,english]{babel}
>>
>> So if a #+LANGUAGE: LANG cookie is present I guess it should be loaded
>> last.  Or a \selectlanguage{LANG} should be issued.
>>
>> Non-rigorous testing suggests that it will do the former now on master
>> and thus presumably also in the patch.
>
> AFAICT, this is so since a while. Nicolas implemented the above described
> behavior months ago...
>
> See http://lists.gnu.org/archive/html/emacs-orgmode/2012-06/msg00387.html.
>
> Doesn't that work for you already in Org core as it is?

I'm sorry, I guess the changelog is too sparse or too unclear.  Let me
try to annotate it.

** Goal: make  bable work similar to inputenc (and try to be less 'smart') ** 

> * ox-latex.el (org-latex-guess-babel-language): ignore AUTO
> if argument.

I can now add ("AUTO" "babel" t) to
org-latex-default-packages-alist—you'll recognize this syntax from
inputenc (see org-latex-default-packages-alist).

This means allows me to load babel every time I export a LaTeX
document.  Babel is important enough that I want I always want to load
it.

Due to the exists of org-export-default-language there is's always a
replacement for AUTO.

Let's consider an example: 

1. Say, org-export-default-language is "en".

2. In my document #+LANGUAGE: fr.  Using this patch AUTO is replaced
   by 'french' when I have a LANGUAGE-cookie.  When no LANGUAGE is
   present, it defaults to org-export-default-language.  Thus, I only
   load one language and I can have a more general
   org-latex-default-packages-alist.

> * ox-latex.el (org-lat ex-guess-babel-language): use language
> if is not in =`org-latex-inputenc-alist'=.

Let's just continue the example above, but suppose I now want to write
a German document.

For instance with German there is both german and ngerman, and
apparently a germanb.  Through the LANGUAGE-cookie I can only get
ngerman (de-de) and germanb (de).  But I might want to get german for
whatever reason.  So I might try

#+LANGUAGE: german

Currently it's discarded.  But why not just pass it along when the
value of LANGUAGE is not in org-latex-babel-language-alist and assume
I know what I am doing?

> * ox-latex.el (org-latex-guess-babel-language): retain case in final
> regexp of function.

Needed for AUTO to replacing everything with uppercase.


I hope the above makes the purpose of the patch clear.  I'll try to
write better change logs in the future.

> 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. . .  

Cheers,
Rasmus

-- 
m-mm-mmm-mmmm bacon!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-03 15:10       ` Rasmus
@ 2013-06-04  6:45         ` Sebastien Vauban
  2013-06-04  9:25           ` [PATCH (new version)][ox-latex.el] " Rasmus
  0 siblings, 1 reply; 23+ messages in thread
From: Sebastien Vauban @ 2013-06-04  6:45 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Rasmus,

Rasmus wrote:
>>>>> 1.  As far as I remember, if more than one language is loaded the
>>>>> order is not neutral one one should issue a \selectlanguage{LANG}.
>>>>
>>>> If there are multiple languages, the main language is the latest loaded; that
>>>> is `english' in the following example:
>>>>
>>>>     \RequirePackage[frenchb,english]{babel}
>>>
>>> So if a #+LANGUAGE: LANG cookie is present I guess it should be loaded
>>> last.  Or a \selectlanguage{LANG} should be issued.
>>>
>>> Non-rigorous testing suggests that it will do the former now on master
>>> and thus presumably also in the patch.
>>
>> AFAICT, this is so since a while. Nicolas implemented the above described
>> behavior months ago...
>>
>> See http://lists.gnu.org/archive/html/emacs-orgmode/2012-06/msg00387.html.
>>
>> Doesn't that work for you already in Org core as it is?
>
> I'm sorry, I guess the changelog is too sparse or too unclear.  Let me
> try to annotate it.
>
> ** Goal: make  bable work similar to inputenc (and try to be less 'smart') ** 
>
>> * ox-latex.el (org-latex-guess-babel-language): ignore AUTO
>> if argument.
>
> I can now add ("AUTO" "babel" t) to
> org-latex-default-packages-alist—you'll recognize this syntax from
> inputenc (see org-latex-default-packages-alist).
>
> This means allows me to load babel every time I export a LaTeX
> document.  Babel is important enough that I want I always want to load
> it.
>
> Due to the exists of org-export-default-language there is's always a
> replacement for AUTO.
>
> Let's consider an example: 
>
> 1. Say, org-export-default-language is "en".
>
> 2. In my document #+LANGUAGE: fr.  Using this patch AUTO is replaced
>    by 'french' when I have a LANGUAGE-cookie.  When no LANGUAGE is
>    present, it defaults to org-export-default-language.  Thus, I only
>    load one language and I can have a more general
>    org-latex-default-packages-alist.
>
>> * ox-latex.el (org-lat ex-guess-babel-language): use language
>> if is not in =`org-latex-inputenc-alist'=.
>
> Let's just continue the example above, but suppose I now want to write
> a German document.
>
> For instance with German there is both german and ngerman, and
> apparently a germanb.  Through the LANGUAGE-cookie I can only get
> ngerman (de-de) and germanb (de).  But I might want to get german for
> whatever reason.  So I might try
>
> #+LANGUAGE: german
>
> Currently it's discarded.  But why not just pass it along when the
> value of LANGUAGE is not in org-latex-babel-language-alist and assume
> I know what I am doing?
>
>> * ox-latex.el (org-latex-guess-babel-language): retain case in final
>> regexp of function.
>
> Needed for AUTO to replacing everything with uppercase.
>
>
> I hope the above makes the purpose of the patch clear.  I'll try to
> write better change logs in the future.
>
>> 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. 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'?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-04  6:45         ` Sebastien Vauban
@ 2013-06-04  9:25           ` Rasmus
  2013-06-05 13:35             ` Nicolas Goaziou
  0 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-04  9:25 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2289 bytes --]

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!

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag_v2.patch --]
[-- Type: text/x-patch, Size: 2698 bytes --]

From 4de4fde0a5ba6d0eb8a9898e7e262f3f8fa5c6ea Mon Sep 17 00:00:00 2001
From: "rasmus.pank" <rasmus.pank@gmail.com>
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


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-04  9:25           ` [PATCH (new version)][ox-latex.el] " Rasmus
@ 2013-06-05 13:35             ` Nicolas Goaziou
  2013-06-06  7:46               ` Sebastien Vauban
                                 ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Nicolas Goaziou @ 2013-06-05 13:35 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

Thanks for your patch. Here are a few comments:

> It changes behavior for your setup in that you can define a LANGUAGE
> that isn't a known abbreviation.

While I think your patch is overall an improvement, I'm not convinced by
this particular point. Indeed #+LANGUAGE: expects a language code as
value, not just any string. This is important since latex backend is not
the only one to use that keyword.

For example, imagine a user in need for german smart quotes. How do you
explain to him than #+language: german will not work, but #+language: de
will?

I think special Babel needs can be handled elsewhere.

>    (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

You need to punctuate your sentence.

> +		       (remove "AUTO"

You can use `delete' instead of `remove': no need to copy the list.

> +			       (org-split-string 
> +				;; in case of [lang_one, lang_two]
> +				(replace-regexp-in-string "[ \t\n]*" ""
> +							  (match-string 1 header)) ","))))

There cannot be any "\n" in the value, so you can use "[ \t]+" instead.
Also, you don't need the `replace-regexp-in-string' part:

  (org-split-string (match-string 1 header) ",[ \t]*")

> +	    (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)))))

The problem with this implementation is that it will not put LANGUAGE at
the same place AUTO was. IOW, there's no difference between:

  #+LATEX_HEADER: \usepackage[AUTO,danish]{babel}

and,

  #+LATEX_HEADER: \usepackage[danish,AUTO]{babel}

although it matters in LaTeX.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-05 13:35             ` Nicolas Goaziou
@ 2013-06-06  7:46               ` Sebastien Vauban
  2013-06-06  9:28                 ` Rasmus
  2013-06-06  9:36               ` Rasmus
  2013-06-06 21:30               ` [PATCH (v3)][ox-latex.el] " Rasmus
  2 siblings, 1 reply; 23+ messages in thread
From: Sebastien Vauban @ 2013-06-06  7:46 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello,

Nicolas Goaziou wrote:
>> It changes behavior for your setup in that you can define a LANGUAGE
>> that isn't a known abbreviation.
>
> While I think your patch is overall an improvement, I'm not convinced by
> this particular point. Indeed #+LANGUAGE: expects a language code as
> value, not just any string. This is important since latex backend is not
> the only one to use that keyword.
>
> For example, imagine a user in need for german smart quotes. How do you
> explain to him than #+language: german will not work, but #+language: de
> will?
>
> I think special Babel needs can be handled elsewhere.

That makes me think of another point: how do I say that the HTML exported
document is in American English?  By having a #+LANGUAGE: en-us specification.

But that's not a valid language for Babel when exporting to LaTeX.

So, I think we'd need some sort of alist with allowed values, and their
equivalent for LaTeX and for HTML (and for other uses?), don't we?

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-06  7:46               ` Sebastien Vauban
@ 2013-06-06  9:28                 ` Rasmus
  0 siblings, 0 replies; 23+ messages in thread
From: Rasmus @ 2013-06-06  9:28 UTC (permalink / raw)
  To: emacs-orgmode

"Sebastien Vauban" <sva-news@mygooglest.com>
writes:

> That makes me think of another point: how do I say that the HTML exported
> document is in American English?  By having a #+LANGUAGE: en-us specification.
>
> But that's not a valid language for Babel when exporting to LaTeX.
>
> So, I think we'd need some sort of alist with allowed values, and their
> equivalent for LaTeX and for HTML (and for other uses?), don't we?

That list is `org-latex-babel-language-alist'.  It has en-us and
translate it to =american=.

–Rasmus

-- 
Send from my Emacs

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (new version)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-05 13:35             ` Nicolas Goaziou
  2013-06-06  7:46               ` Sebastien Vauban
@ 2013-06-06  9:36               ` Rasmus
  2013-06-06 21:30               ` [PATCH (v3)][ox-latex.el] " Rasmus
  2 siblings, 0 replies; 23+ messages in thread
From: Rasmus @ 2013-06-06  9:36 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:

>> It changes behavior for your setup in that you can define a LANGUAGE
>> that isn't a known abbreviation.
>
> While I think your patch is overall an improvement, I'm not convinced by
> this particular point. Indeed #+LANGUAGE: expects a language code as
> value, not just any string. This is important since latex backend is not
> the only one to use that keyword.

We can discard this, of course.  

> For example, imagine a user in need for german smart quotes. How do you
> explain to him than #+language: german will not work, but #+language: de
> will?

A combination of `org-latex-babel-language-alist' and 'look at the
output' and feeble explanations of translations :)

How do we explain that to use his favorite babel, perhaps his own
"germanme", is not available extending org-latex-babel-language-alist?
Of course, in this case it's just a matter of using a LATEX_HEADER, so
it's not worth arguing about, and I'm happy to remove it.

> I think special Babel needs can be handled elsewhere.

Was this related to the above?

> You need to punctuate your sentence.

OK.

>> +		       (remove "AUTO"
>
> You can use `delete' instead of `remove': no need to copy the list.

Thanks.

> There cannot be any "\n" in the value, so you can use "[ \t]+" instead.
> Also, you don't need the `replace-regexp-in-string' part:
>   (org-split-string (match-string 1 header) ",[ \t]*")

I didn't know it was a repexp, thanks!

> The problem with this implementation is that it will not put LANGUAGE at
> the same place AUTO was. IOW, there's no difference between:
>
>   #+LATEX_HEADER: \usepackage[AUTO,danish]{babel}
>
> and,
>
>   #+LATEX_HEADER: \usepackage[danish,AUTO]{babel}
>
> although it matters in LaTeX.

Sure that's wasn't part of the 'deal', but I can see how it would
matter, and it makes more sense in this way.

I'll see if I can fix these bugs.  Thanks for the feedback.

–Rasmus

-- 
Powered by magic pixies!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-05 13:35             ` Nicolas Goaziou
  2013-06-06  7:46               ` Sebastien Vauban
  2013-06-06  9:36               ` Rasmus
@ 2013-06-06 21:30               ` Rasmus
  2013-06-07 12:35                 ` Nicolas Goaziou
  2 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-06 21:30 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 381 bytes --]


Hi, 

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Thanks for your patch. Here are a few comments:

is the attached patch better?

It replaced AUTO with LANG when LANG is recognized and preserve
position and LANG is the argument to LANGUAGE.  I don't know if this
patch uses the most efficient way of replacing AUTO with LANG (see the
dotimes).

–Rasmus

-- 
C is for Cookie

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag.patch --]
[-- Type: text/x-patch, Size: 2451 bytes --]

From 8c97851cb499280bee035d835783bbf17943334e Mon Sep 17 00:00:00 2001
From: "rasmus.pank" <rasmus.pank@gmail.com>
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): replace AUTO with
  language if AUTO is the option of the LaTeX package Babel.

* ox-latex.el (org-latex-guess-babel-language): retain case in final
replace-match of the function.
---
 lisp/ox-latex.el | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index ff0ca1d..0628514 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
@@ -918,16 +921,24 @@ Return the new header."
 	    (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
 	header
       (let ((options (save-match-data
-		       (org-split-string (match-string 1 header) ",")))
+		       (org-split-string (match-string 1 header) ",[ \t]*")))
 	    (language (cdr (assoc language-code
 				  org-latex-babel-language-alist))))
-	;; If LANGUAGE is already loaded, return header.  Otherwise,
-	;; append LANGUAGE to other options.
-	(if (member language options) header
-	  (replace-match (mapconcat 'identity
-				    (append options (list language))
+	;; If LANGUAGE is already loaded, return header without AUTO.
+	;; Otherwise, replace AUTO with language or append language if
+	;; no AUTO is not present.
+	(replace-match (mapconcat 'identity
+				  (if language
+				      (cond ((member language options)
+					     (delete "AUTO") options)
+					    ((member "AUTO" options)
+					     (dotimes (n (length options) options)
+					       (if (equal "AUTO" (nth n options))
+						   (setf (nth n options) language))))
+					    (t (append options (list language))))
+				    (delete "AUTO" options))
 				    ",")
-			 nil nil header 1))))))
+				  t nil header 1)))))
 
 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-06 21:30               ` [PATCH (v3)][ox-latex.el] " Rasmus
@ 2013-06-07 12:35                 ` Nicolas Goaziou
  2013-06-07 13:16                   ` Rasmus
  2013-06-07 15:26                   ` Rasmus
  0 siblings, 2 replies; 23+ messages in thread
From: Nicolas Goaziou @ 2013-06-07 12:35 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:

> is the attached patch better?

It is, thank you. Here is another round of comments.

> +	(replace-match (mapconcat 'identity
> +				  (if language
> +				      (cond ((member language options)
> +					     (delete "AUTO") options)
> +					    ((member "AUTO" options)
> +					     (dotimes (n (length options) options)
> +					       (if (equal "AUTO" (nth n options))
> +						   (setf (nth n options) language))))
> +					    (t (append options (list language))))
> +				    (delete "AUTO" options))

I suggest to use something like this instead:

  (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)))))

> -			 nil nil header 1))))))
> +				  t nil header 1)))))

Why do you need to use a non-nil FIXEDCASE argument here?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-07 12:35                 ` Nicolas Goaziou
@ 2013-06-07 13:16                   ` Rasmus
  2013-06-07 13:25                     ` Nicolas Goaziou
  2013-06-07 15:26                   ` Rasmus
  1 sibling, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-07 13:16 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> Rasmus <rasmus@gmx.us> writes:
>
>> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> is the attached patch better?
>
> It is, thank you. Here is another round of comments.

>> +	(replace-match (mapconcat 'identity
>> +				  (if language
>> +				      (cond ((member language options)
>> +					     (delete "AUTO") options)
>> +					    ((member "AUTO" options)
>> +					     (dotimes (n (length options) options)
>> +					       (if (equal "AUTO" (nth n options))
>> +						   (setf (nth n options) language))))
>> +					    (t (append options (list language))))
>> +				    (delete "AUTO" options))
>
> I suggest to use something like this instead:
>
>   (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)))))
>
>> -			 nil nil header 1))))))
>> +				  t nil header 1)))))

It looks more elegant.  I'll try to incorporate it and prepare a v4.

> Why do you need to use a non-nil FIXEDCASE argument here?

When I don't 

#+LANGUAGE: en
#+LATEX_HEADER: \usepackage[AUTO]{babel}

becomes 

\usepackage[ENGLISH]{babel}. . .

Why?  I don't know. . .  Fixedcase solves it.

-- 
Summon the Mothership!

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-07 13:16                   ` Rasmus
@ 2013-06-07 13:25                     ` Nicolas Goaziou
  0 siblings, 0 replies; 23+ messages in thread
From: Nicolas Goaziou @ 2013-06-07 13:25 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:

>> I suggest to use something like this instead:
>>
>>   (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)))))
>>
>
> It looks more elegant.  I'll try to incorporate it and prepare a v4.

OK. But I forgot to add "," as mapconcat's third argument.

>> Why do you need to use a non-nil FIXEDCASE argument here?
>
> When I don't 
>
> #+LANGUAGE: en
> #+LATEX_HEADER: \usepackage[AUTO]{babel}
>
> becomes 
>
> \usepackage[ENGLISH]{babel}. . .

Good point.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-07 12:35                 ` Nicolas Goaziou
  2013-06-07 13:16                   ` Rasmus
@ 2013-06-07 15:26                   ` Rasmus
  2013-06-09  7:55                     ` Nicolas Goaziou
  1 sibling, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-07 15:26 UTC (permalink / raw)
  To: n.goaziou; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

Nicolas Goaziou <n.goaziou@gmail.com> writes:
 
> It is, thank you. Here is another round of comments.

v4 attached.

--
C is for Cookie

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag.patch --]
[-- Type: text/x-patch, Size: 2298 bytes --]

From 2126f295e7137c1b90a8524108de4a7aaeac7e9f Mon Sep 17 00:00:00 2001
From: "rasmus.pank" <rasmus.pank@gmail.com>
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): replace AUTO with
  language if AUTO is the option of the LaTeX package Babel.

* ox-latex.el (org-latex-guess-babel-language): retain case in final
replace-match of the function.
---
 lisp/ox-latex.el | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index ff0ca1d..3bfab1c 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
@@ -918,16 +921,19 @@ Return the new header."
 	    (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
 	header
       (let ((options (save-match-data
-		       (org-split-string (match-string 1 header) ",")))
+		       (org-split-string (match-string 1 header) ",[ \t]*")))
 	    (language (cdr (assoc language-code
 				  org-latex-babel-language-alist))))
-	;; If LANGUAGE is already loaded, return header.  Otherwise,
-	;; append LANGUAGE to other options.
-	(if (member language options) header
-	  (replace-match (mapconcat 'identity
-				    (append options (list language))
-				    ",")
-			 nil nil header 1))))))
+	;; If LANGUAGE is already loaded, return header without AUTO.
+	;; Otherwise, replace AUTO with language or append language if
+	;; AUTO is not present.
+	(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)))))
 
 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH (v3)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-07 15:26                   ` Rasmus
@ 2013-06-09  7:55                     ` Nicolas Goaziou
  2013-06-11 23:12                       ` [PATCH (v5)][ox-latex.el] " Rasmus
  0 siblings, 1 reply; 23+ messages in thread
From: Nicolas Goaziou @ 2013-06-09  7:55 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>  
>> It is, thank you. Here is another round of comments.
>
> v4 attached.

Thank you.

The patch looks good, but the feature needs to be documented. I think
you could add a paragraph in `org-latex-classes' docstring, below the
first reference to "AUTO".

> Subject: [PATCH] Allow AUTO argument to org-latex-guess-babel-language.
>
> * ox-latex.el (org-latex-guess-babel-language): replace AUTO with
>   language if AUTO is the option of the LaTeX package Babel.
>
> * ox-latex.el (org-latex-guess-babel-language): retain case in final
> replace-match of the function.

You don't need to make two entries for the same function.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v5)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-09  7:55                     ` Nicolas Goaziou
@ 2013-06-11 23:12                       ` Rasmus
  2013-06-12 13:27                         ` Nicolas Goaziou
  0 siblings, 1 reply; 23+ messages in thread
From: Rasmus @ 2013-06-11 23:12 UTC (permalink / raw)
  To: n.goaziou; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 351 bytes --]

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> The patch looks good, but the feature needs to be documented. I think
> you could add a paragraph in `org-latex-classes' docstring, below the
> first reference to "AUTO".

v5! Documentation added.  Let me know if more stuff needs to be
polished.

–Rasmus

-- 
May contains speling mistake

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-AUTO-argument-to-org-latex-guess-babel-languag.patch --]
[-- Type: text/x-patch, Size: 2947 bytes --]

From 7f1cc30ccbedfa7c5689dbf8408011e64db75230 Mon Sep 17 00:00:00 2001
From: "rasmus.pank" <rasmus.pank@gmail.com>
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): replace AUTO with
  language if AUTO is the option of the LaTeX package Babel.  *
  (org-latex-classes): updated documentation with respect
  to =`org-latex-guess-babel-language'=
---
 lisp/ox-latex.el | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index df3de4c..d409cf8 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -261,6 +261,14 @@ replaced with a coding system derived from
 `buffer-file-coding-system'.  See also the variable
 `org-latex-inputenc-alist' for a way to influence this mechanism.
 
+Likewise, if your header contains \"\\usepackage[AUTO]{babel}\",
+AUTO will be replaced with the export language as specified by
+the LANGUAGE keyword or `org-export-default-language'.  Note that
+constructions such as
+\"\\usepackage[french, AUTO, english]{babel}\"
+are permitted.  For more information refer to
+`org-latex-guess-babel-language'.
+
 The sectioning structure
 ------------------------
 
@@ -910,6 +918,10 @@ 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'
+unless language in question is already loaded.
+
 Return the new header."
   (let ((language-code (plist-get info :language)))
     ;; If no language is set or Babel package is not loaded, return
@@ -918,16 +930,19 @@ Return the new header."
 	    (not (string-match "\\\\usepackage\\[\\(.*\\)\\]{babel}" header)))
 	header
       (let ((options (save-match-data
-		       (org-split-string (match-string 1 header) ",")))
+		       (org-split-string (match-string 1 header) ",[ \t]*")))
 	    (language (cdr (assoc language-code
 				  org-latex-babel-language-alist))))
-	;; If LANGUAGE is already loaded, return header.  Otherwise,
-	;; append LANGUAGE to other options.
-	(if (member language options) header
-	  (replace-match (mapconcat 'identity
-				    (append options (list language))
-				    ",")
-			 nil nil header 1))))))
+	;; If LANGUAGE is already loaded, return header without AUTO.
+	;; Otherwise, replace AUTO with language or append language if
+	;; AUTO is not present.
+	(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)))))
 
 (defun org-latex--find-verb-separator (s)
   "Return a character not used in string S.
-- 
1.8.3


^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH (v5)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-11 23:12                       ` [PATCH (v5)][ox-latex.el] " Rasmus
@ 2013-06-12 13:27                         ` Nicolas Goaziou
  2013-06-12 14:32                           ` Rasmus
  0 siblings, 1 reply; 23+ messages in thread
From: Nicolas Goaziou @ 2013-06-12 13:27 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> v5! Documentation added.  Let me know if more stuff needs to be
> polished.

Applied. Thank you!

Note that commit message's first line mustn't end with a period.
Moreover, I slightly changed phrasing in `org-latex-classes' in order to
insist on the fact that `org-export-default-language' is a language
code, not a language /per se/. Eventually, I added TINYCHANGE since,
AFAIK, you haven't signed FSF papers yet.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH (v5)][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language.
  2013-06-12 13:27                         ` Nicolas Goaziou
@ 2013-06-12 14:32                           ` Rasmus
  0 siblings, 0 replies; 23+ messages in thread
From: Rasmus @ 2013-06-12 14:32 UTC (permalink / raw)
  To: n.goaziou; +Cc: emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Applied. Thank you!
>
> Note that commit message's first line mustn't end with a period.
> Moreover, I slightly changed phrasing in `org-latex-classes' in order to
> insist on the fact that `org-export-default-language' is a language
> code, not a language /per se/. Eventually, I added TINYCHANGE since,
> AFAIK, you haven't signed FSF papers yet.

Yeah, it is a TINYCHANGE.  Anyway, papers are on their way to the FSF.

–Rasmus

-- 
Hvor meget poesi tror De kommer ud af et glas isvand?

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2013-06-12 14:32 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-31 22:33 [PATCH][ox-latex.el] Allow AUTO argument to org-latex-guess-babel-language Rasmus
2013-06-01  5:31 ` Achim Gratz
2013-06-01 13:59   ` Rasmus
2013-06-01 14:07     ` Rasmus
2013-06-03  7:44 ` Sebastien Vauban
2013-06-03 13:47   ` Rasmus
2013-06-03 14:08     ` Sebastien Vauban
2013-06-03 15:10       ` Rasmus
2013-06-04  6:45         ` Sebastien Vauban
2013-06-04  9:25           ` [PATCH (new version)][ox-latex.el] " Rasmus
2013-06-05 13:35             ` Nicolas Goaziou
2013-06-06  7:46               ` Sebastien Vauban
2013-06-06  9:28                 ` Rasmus
2013-06-06  9:36               ` Rasmus
2013-06-06 21:30               ` [PATCH (v3)][ox-latex.el] " Rasmus
2013-06-07 12:35                 ` Nicolas Goaziou
2013-06-07 13:16                   ` Rasmus
2013-06-07 13:25                     ` Nicolas Goaziou
2013-06-07 15:26                   ` Rasmus
2013-06-09  7:55                     ` Nicolas Goaziou
2013-06-11 23:12                       ` [PATCH (v5)][ox-latex.el] " Rasmus
2013-06-12 13:27                         ` Nicolas Goaziou
2013-06-12 14:32                           ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).