From a48fe32c4cfc6dede73818b4d54bde571b7e2872 Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Fri, 21 Aug 2009 06:44:29 +0100 Subject: [PATCH] LaTeX export: Avoid footnote processing in LATEX_HEADER lines Nick Dokos writes: > I define a LaTeX macro at the top of my document, like so: > > ,---- > | ... > | #+LATEX_HEADER: \newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}% > | #+LATEX_HEADER: #1\ignorespaces > | #+LATEX_HEADER: } > | ... > `---- > > and export - I get the following inserted: > > ,---- > | ... > | \begin{document} > | > | > | > | > | > | \$\^{}{1}\$ FOOTNOTE DEFINITION NOT FOUND: 1 > | ... > `---- > > Obviously, the macro argument spec is mistaken for a footnote. --- lisp/ChangeLog | 4 +++ lisp/org-footnote.el | 74 +++++++++++++++++++++++--------------------- lisp/org.el | 4 +++ 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dc28366a2..e86907890 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2009-08-21 Carsten Dominik + + * org.el (org-in-commented-line): New function. + 2009-08-20 Carsten Dominik * org.el (org-hide-block-toggle): Make folded blocks searchable. diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 3fbecfe8b..b5bc49822 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -363,42 +363,44 @@ referenced sequence." ;; Now find footnote references, and extract the definitions (goto-char (point-min)) (while (re-search-forward org-footnote-re nil t) - (org-if-unprotected - (setq def (match-string 4) - idef def - ref (or (match-string 1) (match-string 2)) - before (char-to-string (char-after (match-beginning 0)))) - (if (equal ref "fn:") (setq ref nil)) - (if (and ref (setq a (assoc ref ref-table))) - (progn - (setq marker (nth 1 a)) - (unless (nth 2 a) (setf (caddr a) def))) - (setq marker (number-to-string (incf count)))) - (save-match-data - (if def - (setq def (org-trim def)) - (save-excursion - (goto-char (point-min)) - (if (not (re-search-forward (concat "^\\[" (regexp-quote ref) - "\\]") nil t)) - (setq def nil) - (setq beg (match-beginning 0)) - (setq beg1 (match-end 0)) - (re-search-forward - (org-re "^[ \t]*$\\|^\\*+ \\|^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]") - nil 'move) - (setq def (buffer-substring beg1 (or (match-beginning 0) - (point-max)))) - (goto-char beg) - (skip-chars-backward " \t\n\t") - (delete-region (1+ (point)) (match-beginning 0)))))) - (unless sort-only - (replace-match (concat before "[" marker "]")) - (and idef - org-footnote-fill-after-inline-note-extraction - (fill-paragraph))) - (if (not a) (push (list ref marker def (if idef t nil)) ref-table)))) - + (unless (org-in-commented-line) + (org-if-unprotected + (setq def (match-string 4) + idef def + ref (or (match-string 1) (match-string 2)) + before (char-to-string (char-after (match-beginning 0)))) + (if (equal ref "fn:") (setq ref nil)) + (if (and ref (setq a (assoc ref ref-table))) + (progn + (setq marker (nth 1 a)) + (unless (nth 2 a) (setf (caddr a) def))) + (setq marker (number-to-string (incf count)))) + (save-match-data + (if def + (setq def (org-trim def)) + (save-excursion + (goto-char (point-min)) + (if (not (re-search-forward (concat "^\\[" (regexp-quote ref) + "\\]") nil t)) + (setq def nil) + (setq beg (match-beginning 0)) + (setq beg1 (match-end 0)) + (re-search-forward + (org-re "^[ \t]*$\\|^\\*+ \\|^\\[\\([0-9]+\\|fn:[-_[:word:]]+\\)\\]") + nil 'move) + (setq def (buffer-substring beg1 (or (match-beginning 0) + (point-max)))) + (goto-char beg) + (skip-chars-backward " \t\n\t") + (delete-region (1+ (point)) (match-beginning 0)))))) + (unless sort-only + (replace-match (concat before "[" marker "]")) + (and idef + org-footnote-fill-after-inline-note-extraction + (fill-paragraph))) + (if (not a) (push (list ref marker def (if idef t nil)) + ref-table))))) + ;; First find and remove the footnote section (goto-char (point-min)) (cond diff --git a/lisp/org.el b/lisp/org.el index 7075ad15e..33811e5f9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15547,6 +15547,10 @@ With prefix arg UNCOMPILED, load the uncompiled versions." (display-buffer buf) (sit-for 0)))) +(defun org-in-commented-line () + "Is point in a line starting with `#'?" + (equal (char-after (point-at-bol)) ?#)) + (defun org-goto-marker-or-bmk (marker &optional bookmark) "Go to MARKER, widen if necessary. When marker is not live, try BOOKMARK." (if (and marker (marker-buffer marker)