summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2010-01-10 10:18:27 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2010-01-10 10:18:27 +0100
commitbb488fa3b1eaa61ea2dfe7238f9da85bc42b0ffb (patch)
tree063e6a18237afe8517031c051a9e5e0874db27fa
parent35a8ec15373251beb5621ee78fcbc75eb3706a96 (diff)
downloadorg-mode-bb488fa3b1eaa61ea2dfe7238f9da85bc42b0ffb.tar.gz
Fix \usepackage{inputenc} in LaTeX export
The option will now reflect the coding system of the file that was created by exporting the buffer.
-rwxr-xr-xlisp/ChangeLog3
-rw-r--r--lisp/org-latex.el48
2 files changed, 51 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bf7d767..0333c8c 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
2010-01-10 Carsten Dominik <carsten.dominik@gmail.com>
+ * org-latex.el (org-export-latex-fix-inputenc): New function.
+ (org-export-latex-inputenc-alist): New option.
+
* org-exp.el (org-export): New key SPC to publish enclosing
subtree.
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index 3cbff60..6c07970 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -197,6 +197,21 @@ sectioning list in the cdr."
(string :tag "Closing (unnumbered)"))
(function :tag "Hook computing sectioning"))))))
+(defcustom org-export-latex-inputenc-alist nil
+ "Alist of inputenc coding system names, and what should really be used.
+For example, adding an entry
+
+ (\"utf8\" . \"utf8x\")
+
+will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
+are written as utf8 files."
+ :group 'org-export-latex
+ :type '(repeat
+ (cons
+ (string :tag "Derived from buffer")
+ (string :tag "Use this instead"))))
+
+
(defcustom org-export-latex-emphasis-alist
'(("*" "\\textbf{%s}" nil)
("/" "\\emph{%s}" nil)
@@ -746,6 +761,7 @@ when PUB-DIR is set, use this as the publishing directory."
(run-hooks 'org-export-latex-final-hook)
(or to-buffer (save-buffer))
+ (org-export-latex-fix-inputenc)
(run-hooks 'org-export-latex-after-save-hook)
(goto-char (point-min))
(or (org-export-push-to-kill-ring "LaTeX")
@@ -1991,6 +2007,22 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
(org-if-unprotected
(replace-match "")))))
+(defun org-export-latex-fix-inputenc ()
+ "Set the codingsystem in inputenc to what the buffer is."
+ (let* ((cs buffer-file-coding-system)
+ (opt (latexenc-coding-system-to-inputenc cs)))
+ (when opt
+ ;; Translate if that is requested
+ (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
+ ;; find the \usepackage statement and replace the option
+ (goto-char (point-min))
+ (while (re-search-forward "\\\\usepackage\\[\\(.*?\\)\\]{inputenc}"
+ nil t)
+ (goto-char (match-beginning 1))
+ (delete-region (match-beginning 1) (match-end 1))
+ (insert opt))
+ (save-buffer))))
+
;;; List handling:
(defun org-export-latex-lists ()
@@ -2200,3 +2232,19 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER."
;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad
;;; org-latex.el ends here
+
+(defun org-export-latex-fix-inputenc ()
+ "Set the codingsystem in inputenc to what the buffer is."
+ (let* ((cs buffer-file-coding-system)
+ (opt (latexenc-coding-system-to-inputenc cs)))
+ (when opt
+ ;; Translate if that is requested
+ (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist) opt)))
+ ;; find the \usepackage statement and replace the option
+ (goto-char (point-min))
+ (while (re-search-forward "\\\\usepackage\\[\\(.*?\\)\\]{inputenc}"
+ nil t)
+ (goto-char (match-beginning 1))
+ (delete-region (match-beginning 1) (match-end 1))
+ (insert opt))
+ (save-buffer))))