emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] org-latex.el: New defcustom `org-export-latex-quotes' to con


From: Bastien
Subject: [O] [PATCH] org-latex.el: New defcustom `org-export-latex-quotes' to control quotes.
Date: Mon, 11 Jul 2011 15:11:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>From 08c8be7e0403f58a16670a84dbd66d7dd34c7b43 Mon Sep 17 00:00:00 2001
From: Bastien Guerry <address@hidden>
Date: Mon, 11 Jul 2011 15:10:00 +0200
Subject: [PATCH] org-latex.el: New defcustom `org-export-latex-quotes' to
 control quotes.

* org-latex.el (org-export-latex-quotes): New defcustom.
(org-export-latex-quotation-marks): Use it.

This allows users to define what quotes they want to use as a
replacement of english double-quotes while exporting to LaTeX.

In particular, if you use the csquote package, you can configure
Org to output something like \endquote{some quoted text} instead
of "some quoted text".

Thanks to Frederik for bringing this issue up, and to Thomas S.
Dye, Nick Dokos and Stefan Nobis for elaborating this solution.
---
 lisp/org-latex.el |   53 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index e1c85ce..34ceca9 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -321,6 +321,32 @@ will be filled with the link, the second with its 
description."
   :group 'org-export-latex
   :type 'string)
 
+(defcustom org-export-latex-quotes
+  '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") 
("\\(\\s-\\|(\\)'" . "'"))
+    ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") 
("\\(\\s-\\|(\\)'" . "`")))
+  "Alist for quotes to use when converting english double-quotes.
+
+The CAR of each item in this alist is the language code.
+The CDR of each item in this alist is a list of three CONS:
+- the first CONS defines the opening quote;
+- the second CONS defines the closing quote;
+- the last CONS defines single quotes.
+
+For each item in a CONS, the first string is a regexp
+for allowed characters before/after the quote, the second
+string defines the replacement string for this quote."
+  :group 'org-export-latex
+  :type '(list
+         (cons :tag "Opening quote"
+               (string :tag "Regexp for char before") 
+               (string :tag "Replacement quote     "))
+         (cons :tag "Closing quote"
+               (string :tag "Regexp for char after ") 
+               (string :tag "Replacement quote     "))
+         (cons :tag "Single quote"
+               (string :tag "Regexp for char before") 
+               (string :tag "Replacement quote     "))))
+
 (defcustom org-export-latex-tables-verbatim nil
   "When non-nil, tables are exported verbatim."
   :group 'org-export-latex
@@ -1624,21 +1650,18 @@ links, keywords, lists, tables, fixed-width"
 
 (defun org-export-latex-quotation-marks ()
   "Export quotation marks depending on language conventions."
-  (let* ((lang (plist-get org-export-latex-options-plist :language))
-        (quote-rpl (if (equal lang "fr")
-                       '(("\\(\\s-\\)\"" "«~")
-                         ("\\(\\S-\\)\"" "~»")
-                         ("\\(\\s-\\)'" "`"))
-                     '(("\\(\\s-\\|[[(]\\)\"" "``")
-                       ("\\(\\S-\\)\"" "''")
-                       ("\\(\\s-\\|(\\)'" "`")))))
-    (mapc (lambda(l) (goto-char (point-min))
-           (while (re-search-forward (car l) nil t)
-             (let ((rpl (concat (match-string 1)
-                                (org-export-latex-protect-string
-                                 (copy-sequence (cadr l))))))
-               (org-if-unprotected-1
-                (replace-match rpl t t))))) quote-rpl)))
+  (mapc (lambda(l)
+         (goto-char (point-min))
+         (while (re-search-forward (car l) nil t)
+           (let ((rpl (concat (match-string 1)
+                              (org-export-latex-protect-string
+                               (copy-sequence (cdr l))))))
+             (org-if-unprotected-1
+              (replace-match rpl t t))))) 
+       (cdr (or (assoc (plist-get org-export-latex-options-plist :language)
+                       org-export-latex-quotes)
+                ;; falls back on english
+                (assoc "en" org-export-latex-quotes)))))
 
 (defun org-export-latex-special-chars (sub-superscript)
   "Export special characters to LaTeX.
-- 
1.7.5.2

-- 
 Bastien

reply via email to

[Prev in Thread] Current Thread [Next in Thread]