From 56924d69a2090dfeedf4b35ca33e10a48cbc42b5 Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias Date: Sun, 18 Sep 2022 13:56:05 +0200 Subject: [PATCH] lisp/ox-latex.el: Add properties for arbitrary LaTeX code. * (org-latex-headline): The `PRESEC' and `POSTSEC' properties prepend and postpend arbitrary LaTeX code to a section, respectively. --- lisp/ox-latex.el | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 1eb70ab20..a8c9aecd2 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2322,22 +2322,32 @@ holding contextual information." (and (string-match-p "\\" v) (string-match-p "\\" v) (format "\\stopcontents[level-%d]" level))))) - info t))))) - (if (and opt-title - (not (equal opt-title full-text)) - (string-match "\\`\\\\\\(.+?\\){" section-fmt)) - (format (replace-match "\\1[%s]" nil nil section-fmt 1) - ;; Replace square brackets with parenthesis - ;; since square brackets are not supported in - ;; optional arguments. - (replace-regexp-in-string - "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title)) - full-text - (concat headline-label pre-blanks contents)) - ;; Impossible to add an alternative heading. Fallback to - ;; regular sectioning format string. - (format section-fmt full-text - (concat headline-label pre-blanks contents)))))))) + info t)))) + ;; `PRESEC' and `POSTSEC' properties for arbitrary LaTeX code. + (pre-sec (let ((beg (org-element-property :begin headline))) + (goto-char beg) + (org-entry-get nil "PRESEC"))) + (post-sec (let ((beg (org-element-property :begin headline))) + (goto-char beg) + (org-entry-get nil "POSTSEC")))) + (concat + (when pre-sec (format "%s\n\n" pre-sec)) + (if (and opt-title + (not (equal opt-title full-text)) + (string-match "\\`\\\\\\(.+?\\){" section-fmt)) + (format (replace-match "\\1[%s]" nil nil section-fmt 1) + ;; Replace square brackets with parenthesis + ;; since square brackets are not supported in + ;; optional arguments. + (replace-regexp-in-string + "\\[" "(" (replace-regexp-in-string "\\]" ")" opt-title)) + full-text + (concat headline-label pre-blanks contents)) + ;; Impossible to add an alternative heading. Fallback to + ;; regular sectioning format string. + (format section-fmt full-text + (concat headline-label pre-blanks contents))) + (when post-sec (format "%s\n\n" post-sec)))))))) (defun org-latex-format-headline-default-function (todo _todo-type priority text tags _info) -- 2.37.3