From 41d82c78f99e3c27212e2600f7f226308bdbbb9a Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Wed, 16 Dec 2009 19:45:05 +0100 Subject: [PATCH] Fix bug with protecting LaTeX macros The regular expression was not optimal, and if there was a horizontal rule, search would not start from the beginning of the buffer but from after the rule! --- lisp/ChangeLog | 5 +++++ lisp/org-latex.el | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2681b6464..771923083 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,10 @@ 2009-12-16 Carsten Dominik + * org-latex.el (org-export-latex-preprocess): Better version of + the regular expression for protecting LaTeX macros. + (org-export-latex-preprocess): Start searching for macros to + protect from beginning of buffer. + * org-exp.el (org-export-target-internal-links): Check for protectedness earlier in the string. diff --git a/lisp/org-latex.el b/lisp/org-latex.el index bed39c46a..e481ccd21 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -1877,11 +1877,11 @@ The conversion is made depending of STRING-BEFORE and STRING-AFTER." (replace-match (org-export-latex-protect-string "\\hrule") t t))) ;; Protect LaTeX commands like \command[...]{...} or \command{...} - (let ((re (concat "\\\\[a-zA-Z]+\\(?:" - "\\[.*\\]" - "\\)?" - "\\(" (org-create-multibrace-regexp "{" "}" 3) - "\\)\\{1,3\\}"))) + (goto-char (point-min)) + (let ((re (concat + "\\\\[a-zA-Z]+" + "\\(?:\\[[^][\n]*?\\]\\)*" + "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}"))) (while (re-search-forward re nil t) (unless (save-excursion (goto-char (match-beginning 0)) (equal (char-after (point-at-bol)) ?#))