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.
This commit is contained in:
TEC 2021-10-01 01:14:21 +08:00
parent 145aec1036
commit 2eae918538
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 11 additions and 0 deletions

View File

@ -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))))