emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* new (LaTeX) exporter and date formatting
@ 2012-05-23  6:55 Andreas Leha
  2012-05-23 13:24 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Leha @ 2012-05-23  6:55 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

I am exporting a document containing dates like this inactive one
[2011-10-17 Mo].

I do not want to change the displaying of dates in org mode (as that
breaks indentation and point movement).  But I'd like this to be
exported as "Mo, 17.10.2011".  How do I do that?

I found
,----
| org-e-latex-inactive-timestamp-format is a variable defined in `org-e-latex.el'.
| Its value is "\\textit{%s}"
`----
but I have no idea what to change that to or whether that is the correct
place to achieve the different data format at all.

Side note:
Ideally, in my opinion, the LaTeX-exporter would honor the
"#+LANGUAGE: XX"
setting and change the babel-settings accordingly and offer the option
to format the date/time-stamps differently for different languages.


Regards,
Andreas

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

* Re: new (LaTeX) exporter and date formatting
  2012-05-23  6:55 new (LaTeX) exporter and date formatting Andreas Leha
@ 2012-05-23 13:24 ` Nicolas Goaziou
  2012-05-23 21:33   ` Andreas Leha
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-05-23 13:24 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> I am exporting a document containing dates like this inactive one
> [2011-10-17 Mo].
>
> I do not want to change the displaying of dates in org mode (as that
> breaks indentation and point movement).  But I'd like this to be
> exported as "Mo, 17.10.2011".  How do I do that?
>
> I found
> ,----
> | org-e-latex-inactive-timestamp-format is a variable defined in `org-e-latex.el'.
> | Its value is "\\textit{%s}"
> `----
> but I have no idea what to change that to or whether that is the correct
> place to achieve the different data format at all.

Since you want to change contents, and not only markup, this isn't the
correct place.

You can either add a filter in `org-export-filter-timestamp-functions',
or implement your own function to handle timestamp objects. If you
choose the latter, you can install the function in
`org-e-latex-translate-alist' to overwrite current latex exporter
behaviour, or use `org-export-define-derived-backend' to implement your
own back-end.

Assuming you want to overwrite current behaviour, something along the
lines of the following (untested) should do the work:

#+begin_src emacs-lisp
(defun my-e-latex-timestamp (timestamp contents info)
  (let ((value (org-translate-time (org-element-property :value timestamp))))
    (setq value
          (replace-regexp-in-string
           org-ts-regexp1
           (lambda (text)
             (concat (save-match-data (org-trim (match-string 5 value))) ", "
                     (substring text 0 (1- (match-beginning 5)))
                     (substring text (match-end 5))))
           value))
    (case (org-element-property :type timestamp)
      ((active active-range) (format org-e-latex-active-timestamp-format value))
      ((inactive inactive-range)
       (format org-e-latex-inactive-timestamp-format value))
      (otherwise (format org-e-latex-diary-timestamp-format value)))))

(add-to-list 'org-e-latex-translate-alist 'my-e-latex-timestamp)
#+end_src

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

> and offer the option to format the date/time-stamps differently for
> different languages.

I won't bother doing this, but export engine internals probably permit
it.


Regards,

-- 
Nicolas Goaziou

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

* Re: new (LaTeX) exporter and date formatting
  2012-05-23 13:24 ` Nicolas Goaziou
@ 2012-05-23 21:33   ` Andreas Leha
  2012-06-14 11:42     ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Leha @ 2012-05-23 21:33 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

>> I am exporting a document containing dates like this inactive one
>> [2011-10-17 Mo].
>>
>> I do not want to change the displaying of dates in org mode (as that
>> breaks indentation and point movement).  But I'd like this to be
>> exported as "Mo, 17.10.2011".  How do I do that?
>>

[...]

>
> You can either add a filter in `org-export-filter-timestamp-functions',
> or implement your own function to handle timestamp objects. If you
> choose the latter, you can install the function in
> `org-e-latex-translate-alist' to overwrite current latex exporter
> behaviour, or use `org-export-define-derived-backend' to implement your
> own back-end.
>
> Assuming you want to overwrite current behaviour, something along the
> lines of the following (untested) should do the work:
>
> #+begin_src emacs-lisp
> (defun my-e-latex-timestamp (timestamp contents info)
>   (let ((value (org-translate-time (org-element-property :value timestamp))))
>     (setq value
>           (replace-regexp-in-string
>            org-ts-regexp1
>            (lambda (text)
>              (concat (save-match-data (org-trim (match-string 5 value))) ", "
>                      (substring text 0 (1- (match-beginning 5)))
>                      (substring text (match-end 5))))
>            value))
>     (case (org-element-property :type timestamp)
>       ((active active-range) (format org-e-latex-active-timestamp-format value))
>       ((inactive inactive-range)
>        (format org-e-latex-inactive-timestamp-format value))
>       (otherwise (format org-e-latex-diary-timestamp-format value)))))
>
> (add-to-list 'org-e-latex-translate-alist 'my-e-latex-timestamp)
> #+end_src

Thanks a lot for that elaborate response.  It got me where I wanted to be!

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

| LaTeX babel  | lang symbol |
|--------------+-------------|
| acadian      | ??          |
| albanian     | sq          |
| afrikaans    | af          |
| american     | en-us       |
| australian   | en-au       |
| austrian     | de-at       |
| bahasa       | ??          |
| indonesian   | id          |
| indon        | ??          |
| bahasai      | ??          |
| malay        | ms          |
| meyalu       | ??          |
| bahasam      | ??          |
| basque       | eu          |
| brazil       | bt-br       |
| brazilian    | bt-br       |
| breton       | ??          |
| british      | en-gb       |
| bulgarian    | bg          |
| canadian     | en-ca       |
| canadien     | fr-ca       |
| catalan      | ca          |
| croatian     | hr          |
| czech        | cs          |
| danish       | da          |
| dutch        | nl          |
| english      | en          |
| esperanto    | ??          |
| estonian     | et          |
| finnish      | fi          |
| francais     | fr          |
| frenchb      | fr          |
| french       | fr          |
| galician     | gl          |
| german       | de          |
| germanb      | de          |
| greek        | el          |
| hungarian    | hu          |
| icelandic    | is          |
| interlingua  | ??          |
| irish        | en-ie       |
| italian      | it          |
| latin        | la          |
| lowersorbian | sr          |
| magyar       | ??          |
| nagari       | ??          |
| naustrian    | de-at       |
| newzealand   | en-nz       |
| ngerman      | de-de       |
| norsk        | no-no       |
| samin        | ??          |
| nynorsk      | no-no       |
| polish       | pl          |
| portuges     | pt          |
| portuguese   | pt          |
| romanian     | ro          |
| russian      | ru          |
| sanskrit     | sa          |
| scottish     | en-gb       |
| serbian      | sr          |
| slovak       | sk          |
| slovene      | sl          |
| spanish      | es          |
| swedish      | sv          |
| tamil        | ta          |
| turkish      | tr          |
| ukrainian    | uk          |
| uppersorbian | sb          |
| welsh        | cy          |
| UKenglish    | en-gb       |
| USenglish    | en-us       |


Regards,
Andreas

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

* Re: new (LaTeX) exporter and date formatting
  2012-05-23 21:33   ` Andreas Leha
@ 2012-06-14 11:42     ` Nicolas Goaziou
  2012-06-14 13:16       ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-06-14 11:42 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

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

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: set babel language --]
[-- Type: text/x-patch, Size: 4442 bytes --]

From 1f9a6385e961e61d8b5e5e4d56889c7b2bd9f82b Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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.")
 
 
 \f
+;;; 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.")
+
+
+\f
 ;;; 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


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

* Re: new (LaTeX) exporter and date formatting
  2012-06-14 11:42     ` Nicolas Goaziou
@ 2012-06-14 13:16       ` Sebastien Vauban
  2012-06-14 16:49         ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-06-14 13:16 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Nicolas,

Nicolas Goaziou wrote:
> Andreas Leha <andreas.leha-A1rZ2h3LdSKGMSlLMZIubhS11BummzK+@public.gmane.org> writes:
>>>>
>>>> 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.

I think this will be a great addition!

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

At first sight, I had no particular opinion about whether it's better to load
or not Babel by default.

After thinking about it, I think you're right NOT loading it by default. Babel
plays with cat codes for `:' among others, and can conflict with isodate IIRC.
Hence, better let the user decide to really include it or not.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: new (LaTeX) exporter and date formatting
  2012-06-14 13:16       ` Sebastien Vauban
@ 2012-06-14 16:49         ` Nicolas Goaziou
  2012-06-15 12:42           ` Andreas Leha
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-06-14 16:49 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hello,

"Sebastien Vauban"
<wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:

>> The following patch should add the language option according to LANGUAGE
>> keywords if babel package is explicitly loaded in preamble.
>
> I think this will be a great addition!

Albeit a very limited one: guessed language in only added when babel
package is loaded _and_ it is different from the one set by the user.

If there is no objection, I'll push a slightly refactored version of
that patch.


Regards,

-- 
Nicolas Goaziou

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

* Re: new (LaTeX) exporter and date formatting
  2012-06-14 16:49         ` Nicolas Goaziou
@ 2012-06-15 12:42           ` Andreas Leha
  2012-06-15 14:17             ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Leha @ 2012-06-15 12:42 UTC (permalink / raw)
  To: emacs-orgmode

Hi Nicolas,

>>> The following patch should add the language option according to LANGUAGE
>>> keywords if babel package is explicitly loaded in preamble.
>>
>> I think this will be a great addition!

I just made some quick test of your patch and it works great!  So I
completely agree.

>
> Albeit a very limited one: guessed language in only added when babel
> package is loaded _and_ it is different from the one set by the user.

I do not mind.  I can have '#+LATEX_HEADER: \usepackage[en]{babel}' in
all my .org files by default and have the exporter override the language
setting based on the '#+LANGUAGE:' tag.

>
> If there is no objection, I'll push a slightly refactored version of
> that patch.
>

Pleas do so.  And a big thanks for that addition!

Regards,
Andreas

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

* Re: new (LaTeX) exporter and date formatting
  2012-06-15 12:42           ` Andreas Leha
@ 2012-06-15 14:17             ` Nicolas Goaziou
  2012-06-15 14:36               ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas Goaziou @ 2012-06-15 14:17 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> I do not mind.  I can have '#+LATEX_HEADER: \usepackage[en]{babel}' in
> all my .org files by default and have the exporter override the language
> setting based on the '#+LANGUAGE:' tag.

I've pushed the patch. Thanks for the language list.

Note that LANGUAGE doesn't override Babel package's options, but append
another language to them if not already specified.

Hence,

  #+LATEX_HEADER: \usepackage[english]{babel}
  #+LANGUAGE: fr

will produce

  \usepackage[frenchb,english]{babel}


Should it replace previous language instead?


Regards,

-- 
Nicolas Goaziou

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

* Re: new (LaTeX) exporter and date formatting
  2012-06-15 14:17             ` Nicolas Goaziou
@ 2012-06-15 14:36               ` Sebastien Vauban
  2012-06-15 15:31                 ` Nicolas Goaziou
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-06-15 14:36 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Nicolas,

Nicolas Goaziou wrote:
> Andreas Leha <andreas.leha-A1rZ2h3LdSKGMSlLMZIubhS11BummzK+@public.gmane.org> writes:
>
>> I do not mind.  I can have '#+LATEX_HEADER: \usepackage[en]{babel}' in
>> all my .org files by default and have the exporter override the language
>> setting based on the '#+LANGUAGE:' tag.
>
> I've pushed the patch. Thanks for the language list.
>
> Note that LANGUAGE doesn't override Babel package's options, but append
> another language to them if not already specified.
>
> Hence,
>
>   #+LATEX_HEADER: \usepackage[english]{babel}
>   #+LANGUAGE: fr
>
> will produce
>
>   \usepackage[frenchb,english]{babel}

That's wrong a the main language is the latest loaded (here: english).

> Should it replace previous language instead?

I would think so, or at least suffixed, instead of being prefixed.

Of course, this is related to the question: do we allow or want multiple
languages in one document? If the answer is yes in LaTeX, how do we do in Org,
and for the HTML export (for which the value of #+LANGUAGE is also used).

Honestly, I don't care that much about one or the other, as I don't have to
type documents with multiple languages inside them. Or, if I would, I would
accept to insert LaTeX code inside my Org file to fix whatever needs to!

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: new (LaTeX) exporter and date formatting
  2012-06-15 14:36               ` Sebastien Vauban
@ 2012-06-15 15:31                 ` Nicolas Goaziou
  0 siblings, 0 replies; 10+ messages in thread
From: Nicolas Goaziou @ 2012-06-15 15:31 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ



Hello,

"Sebastien Vauban"
<wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:

> That's wrong a the main language is the latest loaded (here: english).

Good point.

>> Should it replace previous language instead?
>
> I would think so, or at least suffixed, instead of being prefixed.

From now, it will be suffixed.

> Of course, this is related to the question: do we allow or want multiple
> languages in one document? If the answer is yes in LaTeX, how do we do in Org,
> and for the HTML export (for which the value of #+LANGUAGE is also
> used).

This is unrelated to HTML. Each back-end handles #+LANGUAGE: keyword as
needed, if at all. There's no global specification about that keyword.

Moreover, it's simpler to implement that way.  So, if there is no
drawback with having two languages, let's keep it simple.


Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2012-06-15 15:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-23  6:55 new (LaTeX) exporter and date formatting Andreas Leha
2012-05-23 13:24 ` Nicolas Goaziou
2012-05-23 21:33   ` Andreas Leha
2012-06-14 11:42     ` Nicolas Goaziou
2012-06-14 13:16       ` Sebastien Vauban
2012-06-14 16:49         ` Nicolas Goaziou
2012-06-15 12:42           ` Andreas Leha
2012-06-15 14:17             ` Nicolas Goaziou
2012-06-15 14:36               ` Sebastien Vauban
2012-06-15 15:31                 ` Nicolas Goaziou

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