emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Don't fill displayed equations
@ 2021-09-30 17:20 Timothy
  2021-09-30 17:44 ` Timothy
  2021-09-30 18:51 ` Nicolas Goaziou
  0 siblings, 2 replies; 45+ messages in thread
From: Timothy @ 2021-09-30 17:20 UTC (permalink / raw)
  To: Org Mode List

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

Hi All,

If a displayed equation (`\[ ... \]') starts on its own line, I don’t think it
should 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.

As such, I have attached a patch which adds fill “cuts” around `\[' and
`\]', when `\[' occurs at the start of a line. This leaves the display equation
delimiters on their own line.

I think this motivation for this change is fairly clear, and so without feedback
I intend to push this in a few days, however I if anybody has comments on the way
I’m currently implementing this, I’d like to hear your thoughts.

All the best,
Timothy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-Don-t-fill-displayed-equations-into-text.patch --]
[-- Type: text/x-patch, Size: 2168 bytes --]

From d008ff3c2218e19bb501137715b05e06a0c511e3 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Fri, 1 Oct 2021 01:14:21 +0800
Subject: [PATCH] org: Don't fill displayed equations into 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 | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 405f0f0f9..daf1d91b4 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19551,10 +19551,10 @@ (defun org-fill-element (&optional justify)
 			 (org-element-property :contents-end element))))
 	   ;; Do nothing if point is at an affiliated keyword.
 	   (if (< (line-end-position) beg) t
-	     ;; Fill paragraph, taking line breaks into account.
 	     (save-excursion
 	       (goto-char beg)
 	       (let ((cuts (list beg)))
+                 ;; Cut fill on line breaks.
 		 (while (re-search-forward "\\\\\\\\[ \t]*\n" end t)
 		   (when (eq 'line-break
 			     (org-element-type
@@ -19562,6 +19562,16 @@ (defun org-fill-element (&optional justify)
 					      (org-element-context))))
 		     (push (point) cuts)))
 		 (dolist (c (delq end 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)))))
 		   (fill-region-as-paragraph c end justify)
 		   (setq end c))))
 	     t)))
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 45+ messages in thread

end of thread, other threads:[~2022-06-18  6:04 UTC | newest]

Thread overview: 45+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-30 17:20 [PATCH] Don't fill displayed equations Timothy
2021-09-30 17:44 ` Timothy
2021-09-30 18:51 ` Nicolas Goaziou
2021-09-30 18:54   ` Timothy
2021-09-30 19:02     ` Nicolas Goaziou
2021-09-30 19:17       ` Colin Baxter
2021-09-30 22:11         ` Nicolas Goaziou
2021-09-30 22:26           ` Tim Cross
2021-09-30 19:28       ` Timothy
2021-09-30 20:45       ` Timothy
2021-09-30 22:55         ` Nicolas Goaziou
2021-10-01  7:38           ` Stefan Nobis
2021-10-01 20:41             ` Nicolas Goaziou
2021-10-02  8:17               ` Org syntax: \[ \] as block element instead of inline object Max Nikulin
2021-10-02 10:47                 ` Stefan Nobis
2021-10-02  9:57               ` [PATCH] Don't fill displayed equations Stefan Nobis
2021-10-02 10:04               ` Eric S Fraga
2021-10-02 10:18                 ` Timothy
2021-10-02 11:24                   ` Eric S Fraga
2021-10-02 14:21                     ` Max Nikulin
2021-10-02 17:51                       ` Tom Gillespie
2021-10-02 18:28                         ` Timothy
2021-10-02 18:57                           ` Tom Gillespie
2021-10-02 20:25                             ` org-latex-preview and latex export blocks Timothy
2021-10-03  8:50                         ` [PATCH] Don't fill displayed equations Max Nikulin
2021-10-03 10:56                           ` Stefan Nobis
2021-10-03 12:04                             ` Max Nikulin
2021-10-04  5:57                               ` Tom Gillespie
2021-10-04 17:11                                 ` Max Nikulin
2021-10-03 12:35                           ` Ihor Radchenko
2021-10-01  7:43           ` Timothy
2021-10-02 11:06             ` Nicolas Goaziou
2021-10-02 11:24               ` Timothy
2021-10-03  8:49                 ` Ihor Radchenko
2021-10-03  8:50                   ` Timothy
2021-10-03  9:13                     ` Ihor Radchenko
2021-10-03  9:14                       ` Timothy
2021-10-03  9:41                         ` Ihor Radchenko
2021-10-03  9:42                           ` Timothy
2022-06-18  6:00                             ` Ihor Radchenko
2021-10-01 14:42         ` Greg Minshall
2021-10-04  6:05         ` Timothy
2021-10-04  7:11           ` Tom Gillespie
2021-10-04  7:15             ` Timothy
2021-10-04  8:11           ` Przemysław Pietrzak

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).