From c5338b69d77386071d5ae2baf119d4d7e3b2001c Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 21 Jan 2009 10:23:49 +0100 Subject: [PATCH] LaTeX export: Properly protect entire LaTeX environments LaTeX environments should be left as they are, fully protected. There was a regular expression error in the code doing this. --- lisp/ChangeLog | 7 ++++ lisp/org-export-latex.el | 88 +++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 41 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a4d0751f3..d608a8aa1 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2009-01-21 Carsten Dominik + + * org-export-latex.el (org-export-latex-preprocess): Fix bug in + environment detection. Also, do real changes only in unprotected + places. + + 2009-01-20 Carsten Dominik * org-export-latex.el (org-export-latex-quotation-marks): Use diff --git a/lisp/org-export-latex.el b/lisp/org-export-latex.el index c85ac2000..3d4b117bf 100644 --- a/lisp/org-export-latex.el +++ b/lisp/org-export-latex.el @@ -1278,11 +1278,11 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." ;; Preserve latex environments (goto-char (point-min)) - (while (re-search-forward "^[ \t]*\\begin{\\([a-zA-Z]+\\)}" nil t) + (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\)}" nil t) (let* ((start (progn (beginning-of-line) (point))) (end (or (and (re-search-forward - (concat "^[ \t]*\\end{" (match-string 1) "}" nil t) - (point-at-eol))) + (concat "^[ \t]*\\\\end{" (match-string 1) "}") nil t) + (point-at-eol)) (point-max)))) (add-text-properties start end '(org-protected t)))) @@ -1306,8 +1306,9 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (goto-char (point-min)) (let ((case-fold-search nil) rpl) (while (re-search-forward "\\([^+_]\\)LaTeX" nil t) - (replace-match (org-export-latex-protect-string - (concat (match-string 1) "\\LaTeX{}")) t t))) + (org-if-unprotected + (replace-match (org-export-latex-protect-string + (concat (match-string 1) "\\LaTeX{}")) t t)))) ;; Convert blockquotes (goto-char (point-min)) @@ -1328,7 +1329,8 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." ;; Convert horizontal rules (goto-char (point-min)) (while (re-search-forward "^----+.$" nil t) - (replace-match (org-export-latex-protect-string "\\hrule") t t)) + (org-if-unprotected + (replace-match (org-export-latex-protect-string "\\hrule") t t))) ;; Protect LaTeX commands like \command[...]{...} or \command{...} (goto-char (point-min)) @@ -1347,57 +1349,61 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (while (re-search-forward (concat "<<>>?\\((INVISIBLE)\\)?") nil t) - (replace-match - (org-export-latex-protect-string - (format "\\label{%s}%s" (save-match-data (org-solidify-link-text - (match-string 1))) - (if (match-string 2) "" (match-string 1)))) t t)) + (org-if-unprotected + (replace-match + (org-export-latex-protect-string + (format "\\label{%s}%s" (save-match-data (org-solidify-link-text + (match-string 1))) + (if (match-string 2) "" (match-string 1)))) t t))) ;; Delete @<...> constructs ;; Thanks to Daniel Clemente for this regexp (goto-char (point-min)) (while (re-search-forward "@<\\(?:[^\"\n]\\|\".*\"\\)*?>" nil t) - (replace-match "")) + (org-if-unprotected + (replace-match ""))) ;; When converting to LaTeX, replace footnotes ;; FIXME: don't protect footnotes from conversion (when (plist-get org-export-latex-options-plist :footnotes) (goto-char (point-min)) (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t) - (when (save-match-data - (save-excursion (beginning-of-line) - (looking-at "[^:|#]"))) - (let ((foot-beg (match-beginning 0)) - (foot-end (match-end 0)) - (foot-prefix (match-string 0)) - footnote footnote-rpl) - (save-excursion - (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix)) - nil t)) - (replace-match "$^{\\1}$") - (replace-match "") - (let ((end (save-excursion - (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t) - (match-beginning 0) (point-max))))) - (setq footnote (concat (org-trim (buffer-substring (point) end)) - " ")) ; prevent last } being part of a link - (delete-region (point) end)) - (goto-char foot-beg) - (delete-region foot-beg foot-end) - (unless (null footnote) - (setq footnote-rpl (format "\\footnote{%s}" footnote)) - (add-text-properties 0 10 '(org-protected t) footnote-rpl) - (add-text-properties (1- (length footnote-rpl)) - (length footnote-rpl) - '(org-protected t) footnote-rpl) - (insert footnote-rpl))) - )))) + (org-if-unprotected + (when (save-match-data + (save-excursion (beginning-of-line) + (looking-at "[^:|#]"))) + (let ((foot-beg (match-beginning 0)) + (foot-end (match-end 0)) + (foot-prefix (match-string 0)) + footnote footnote-rpl) + (save-excursion + (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix)) + nil t)) + (replace-match "$^{\\1}$") + (replace-match "") + (let ((end (save-excursion + (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t) + (match-beginning 0) (point-max))))) + (setq footnote (concat (org-trim (buffer-substring (point) end)) + " ")) ; prevent last } being part of a link + (delete-region (point) end)) + (goto-char foot-beg) + (delete-region foot-beg foot-end) + (unless (null footnote) + (setq footnote-rpl (format "\\footnote{%s}" footnote)) + (add-text-properties 0 10 '(org-protected t) footnote-rpl) + (add-text-properties (1- (length footnote-rpl)) + (length footnote-rpl) + '(org-protected t) footnote-rpl) + (insert footnote-rpl))) + ))))) ;; Remove footnote section tag for LaTeX (goto-char (point-min)) (while (re-search-forward (concat "^" footnote-section-tag-regexp) nil t) - (replace-match "")))) + (org-if-unprotected + (replace-match ""))))) ;;; List handling: