From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Andreas Leha <andreas.leha@med.uni-goettingen.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: new (LaTeX) exporter and date formatting
Date: Thu, 14 Jun 2012 13:42:08 +0200 [thread overview]
Message-ID: <874nqe9l2n.fsf@gmail.com> (raw)
In-Reply-To: <871umay444.fsf@med.uni-goettingen.de> (Andreas Leha's message of "Wed, 23 May 2012 23:33:31 +0200")
[-- 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
next prev parent reply other threads:[~2012-06-14 11:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874nqe9l2n.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=andreas.leha@med.uni-goettingen.de \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).