From 2eae918538b823ac76e30592c787827d99915463 Mon Sep 17 00:00:00 2001 From: TEC Date: Fri, 1 Oct 2021 01:14:21 +0800 Subject: [PATCH] NOPUSH org: Don't fill displayed equations in text * list/org.el (org-fill-element): If a displayed equation (\[ ... \]) starts on its own line, it should not be filled into the rest of the text. I.e., some nice text \[ 1+1=2 \] more text. should not become, some nice text \[ 1+1=3 \] more text. While the above example may not look bad, with non-trivial equations this can become quite messy. --- lisp/org.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lisp/org.el b/lisp/org.el index 887962141..9e35acd3a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19242,12 +19242,23 @@ a footnote definition, try to fill the first paragraph within." (save-excursion (goto-char beg) (let ((cuts (list beg))) + ;; Cut fill on line breaks. (while (re-search-forward "\\\\\\\\[ \t]*\n" end t) (when (org-element-type-p (save-excursion (backward-char) (org-element-context)) 'line-break) (push (point) cuts))) + ;; Cut fill on displayed equations. + (while (re-search-forward "^[ \t]*\\\\\\[" end t) + (let ((el (org-element-context))) + (when (eq 'latex-fragment (org-element-type el)) + (setf cuts (append + (list (org-element-property :end el) + (- (org-element-property :end el) 2) + (+ (org-element-property :begin el) 2) + (org-element-property :begin el)) + cuts))))) (dolist (c (delq end cuts)) (fill-region-as-paragraph c end justify) (setq end c))))