emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [RFC] Turn \[...\] constructs into full-fledged elements
@ 2015-05-09  9:50 Nicolas Goaziou
  2015-05-09 10:24 ` Eric S Fraga
  2015-05-09 12:38 ` Sebastien Vauban
  0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Goaziou @ 2015-05-09  9:50 UTC (permalink / raw)
  To: Org Mode List

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

Hello,

I wasn't initially for such a change, but the more I think about it the
more I think it makes sense.

The point is to make \[...\] an element, which means that:

  - it cannot be inlined anymore, i.e., it has to start on a new line,
  - it cannot be filled anymore.

So basically, \[...\] will be closer to LaTeX definition.

WDYT?


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-.-an-element-instead-of-an-object.patch --]
[-- Type: text/x-diff, Size: 6727 bytes --]

From 8dba4429684684ce29ce2a984a075550313b7027 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sat, 9 May 2015 11:29:48 +0200
Subject: [PATCH] Make \[...\] an element instead of an object

* lisp/org-element.el (org-element--set-regexps): Update regexp.
(org-element--latex-begin-environment):
(org-element--latex-end-environment): Remove variable.  Change it into
a function.
(org-element-latex-environment-parser):
(org-element-paragraph-parser): Use function.
(org-element-latex-fragment-parser): Remove \[...\] constructs.

* lisp/org.el (org-latex-regexps): Update regexp for \[...\].

* testing/lisp/test-org-element.el (test-org-element/latex-environment-parser):
  Add a test.
(test-org-element/latex-fragment-parser): Remove a test.

With this change \[...\] are considered elements and cannot be inlined
anymore.  As a consequence, they will not be filled anymore and stop
paragraphs.  However such inline constructs are no longer recognized.
---
 lisp/org-element.el              | 40 +++++++++++++++++++---------------------
 lisp/org.el                      |  2 +-
 testing/lisp/test-org-element.el | 12 +++++++-----
 3 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 9037b37..31af3bc 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -172,7 +172,7 @@ specially in `org-element--object-lex'.")
 		;; Horizontal rules.
 		"-\\{5,\\}[ \t]*$" "\\|"
 		;; LaTeX environments.
-		"\\\\begin{\\([A-Za-z0-9*]+\\)}" "\\|"
+		"\\\\\\(begin{\\([A-Za-z0-9*]+\\)}\\|\\[\\)" "\\|"
 		;; Clock lines.
 		(regexp-quote org-clock-string) "\\|"
 		;; Lists.
@@ -2122,16 +2122,17 @@ CONTENTS is nil."
 ;;;; Latex Environment
 
 (defconst org-element--latex-begin-environment
-  "^[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}"
+  "^[ \t]*\\\\\\(?:begin{\\([A-Za-z0-9*]+\\)}\\|\\[\\)"
   "Regexp matching the beginning of a LaTeX environment.
-The environment is captured by the first group.
+The environment is captured by the first group.  See also
+`org-element--latex-end-environment'.")
 
-See also `org-element--latex-end-environment'.")
-
-(defconst org-element--latex-end-environment
-  "\\\\end{%s}[ \t]*$"
-  "Format string matching the ending of a LaTeX environment.
-See also `org-element--latex-begin-environment'.")
+(defun org-element--latex-end-environment (environment)
+  "Build regexp matching the end of a LaTeX environment.
+See also `org-element--latex-begin-environment'."
+  (if environment
+      (format "\\\\end{%s}[ \t]*$" (regexp-quote environment))
+    "\\][ \t]*$"))
 
 (defun org-element-latex-environment-parser (limit affiliated)
   "Parse a LaTeX environment.
@@ -2150,9 +2151,8 @@ Assume point is at the beginning of the latex environment."
     (let ((case-fold-search t)
 	  (code-begin (point)))
       (looking-at org-element--latex-begin-environment)
-      (if (not (re-search-forward (format org-element--latex-end-environment
-					  (regexp-quote (match-string 1)))
-				  limit t))
+      (if (not (re-search-forward
+		(org-element--latex-end-environment (match-string 1)) limit t))
 	  ;; Incomplete latex environment: parse it as a paragraph.
 	  (org-element-paragraph-parser limit affiliated)
 	(let* ((code-end (progn (forward-line) (point)))
@@ -2254,8 +2254,7 @@ Assume point is at the beginning of the paragraph."
 		       ((looking-at org-element--latex-begin-environment)
 			(save-excursion
 			  (re-search-forward
-			   (format org-element--latex-end-environment
-				   (regexp-quote (match-string 1)))
+			   (org-element--latex-end-environment (match-string 1))
 			   limit t)))
 		       ((looking-at "[ \t]*#\\+\\(\\S-+\\)\\[.*\\]:")
 			(member-ignore-case (match-string 1)
@@ -2961,13 +2960,12 @@ Assume point is at the beginning of the LaTeX fragment."
 				    '(?\s ?\t ?\n ?, ?.)))
 			 (looking-at "\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|$\\)")
 			 (point)))
-		(case (char-after (1+ (point)))
-		  (?\( (search-forward "\\)" nil t))
-		  (?\[ (search-forward "\\]" nil t))
-		  (otherwise
-		   ;; Macro.
-		   (and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
-			(match-end 0))))))
+		(if (eq (char-after (1+ (point))) ?\()
+		    (search-forward "\\)" nil t)
+		  ;; Macro.
+		  (and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\
+\\|\\({[^{}\n]*}\\)\\)*")
+		       (match-end 0)))))
 	     (post-blank (if (not after-fragment) (throw 'no-object nil)
 			   (goto-char after-fragment)
 			   (skip-chars-forward " \t")))
diff --git a/lisp/org.el b/lisp/org.el
index ac9d06d..1fbc8c9 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -543,7 +543,7 @@ An entry can be toggled between COMMENT and normal with
     ("$1" "\\([^$]\\|^\\)\\(\\$[^ 	\r\n,;.$]\\$\\)\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|\000\\|$\\)" 2 nil)
     ("$"  "\\([^$]\\|^\\)\\(\\(\\$\\([^ 	\r\n,;.$][^$\n\r]*?\\(\n[^$\n\r]*?\\)\\{0,2\\}[^ 	\r\n,.$]\\)\\$\\)\\)\\(\\s.\\|\\s-\\|\\s(\\|\\s)\\|\\s\"\\|\000\\|$\\)" 2 nil)
     ("\\(" "\\\\([^\000]*?\\\\)" 0 nil)
-    ("\\[" "\\\\\\[[^\000]*?\\\\\\]" 0 nil)
+    ("\\[" "^[ \t]*\\\\\\[[^\000]*?\\\\\\][ \t]*$" 0 nil)
     ("$$" "\\$\\$[^\000]*?\\$\\$" 0 nil))
   "Regular expressions for matching embedded LaTeX.")
 
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index d7eb8e4..a0ac8e6 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1375,9 +1375,15 @@ Paragraph"
 
 (ert-deftest test-org-element/latex-environment-parser ()
   "Test `latex-environment' parser."
+  ;; Standard test.
   (should
    (org-test-with-temp-text "\\begin{equation}\ne^{i\\pi}+1=0\n\\end{equation}"
      (org-element-map (org-element-parse-buffer) 'latex-environment 'identity)))
+  ;; Allow shorthand for "equation*" environment.
+  (should
+   (eq 'latex-environment
+       (org-test-with-temp-text "\\[e^{i\\pi}+1=0\n\\]"
+	 (org-element-type (org-element-at-point)))))
   ;; Allow nested environments.
   (should
    (equal
@@ -1420,7 +1426,7 @@ e^{i\\pi}+1=0
   (should-not
    (eq 'latex-environment
        (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
-				(org-element-type (org-element-at-point)))))
+	 (org-element-type (org-element-at-point)))))
   ;; LaTeX environments must be on separate lines.
   (should-not
    (eq 'latex-environment
@@ -1476,10 +1482,6 @@ e^{i\\pi}+1=0
    (eq 'latex-fragment
        (org-test-with-temp-text "\\(a\\)"
 	 (org-element-type (org-element-context)))))
-  (should
-   (eq 'latex-fragment
-       (org-test-with-temp-text "\\[a\\]"
-	 (org-element-type (org-element-context)))))
   ;; Test fragment at the beginning of an item.
   (should
    (eq 'latex-fragment
-- 
2.4.0


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

* Re: [RFC] Turn \[...\] constructs into full-fledged elements
  2015-05-09  9:50 [RFC] Turn \[...\] constructs into full-fledged elements Nicolas Goaziou
@ 2015-05-09 10:24 ` Eric S Fraga
  2015-05-09 12:38 ` Sebastien Vauban
  1 sibling, 0 replies; 4+ messages in thread
From: Eric S Fraga @ 2015-05-09 10:24 UTC (permalink / raw)
  To: Org Mode List

On Saturday,  9 May 2015 at 11:50, Nicolas Goaziou wrote:

[...]

> So basically, \[...\] will be closer to LaTeX definition.
>
> WDYT?

I'm happy with this proposal.  

thanks,
eric
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.1, Org release_8.3beta-1104-gbce77d

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

* Re: [RFC] Turn \[...\] constructs into full-fledged elements
  2015-05-09  9:50 [RFC] Turn \[...\] constructs into full-fledged elements Nicolas Goaziou
  2015-05-09 10:24 ` Eric S Fraga
@ 2015-05-09 12:38 ` Sebastien Vauban
  2015-05-09 13:57   ` Marcin Borkowski
  1 sibling, 1 reply; 4+ messages in thread
From: Sebastien Vauban @ 2015-05-09 12:38 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Nicolas Goaziou wrote:
> The point is to make \[...\] an element, which means that:
>
>   - it cannot be inlined anymore, i.e., it has to start on a new line,
>   - it cannot be filled anymore.
>
> So basically, \[...\] will be closer to LaTeX definition.

Nitpick: I thought that \[...\] could be inlined in LaTeX.

But, whatever your choice/change, I'll be happy with it.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: [RFC] Turn \[...\] constructs into full-fledged elements
  2015-05-09 12:38 ` Sebastien Vauban
@ 2015-05-09 13:57   ` Marcin Borkowski
  0 siblings, 0 replies; 4+ messages in thread
From: Marcin Borkowski @ 2015-05-09 13:57 UTC (permalink / raw)
  To: emacs-orgmode


On 2015-05-09, at 14:38, Sebastien Vauban <sva-news@mygooglest.com> wrote:

> Nicolas Goaziou wrote:
>> The point is to make \[...\] an element, which means that:
>>
>>   - it cannot be inlined anymore, i.e., it has to start on a new line,
>>   - it cannot be filled anymore.
>>
>> So basically, \[...\] will be closer to LaTeX definition.

+1

> Nitpick: I thought that \[...\] could be inlined in LaTeX.

If by "inlined", you mean "inlined in the source code", then yes.  But
OTOH, /almost/ everything in LaTeX could be inlined in this sense
(except for stuff like {verbatim}, \obeylines etc.), so basically
a typical LaTeX document /could/ be written as one, long line (using
\par's as paragraph separators).

> But, whatever your choice/change, I'll be happy with it.
>
> Best regards,
>   Seb

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

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

end of thread, other threads:[~2015-05-09 13:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-09  9:50 [RFC] Turn \[...\] constructs into full-fledged elements Nicolas Goaziou
2015-05-09 10:24 ` Eric S Fraga
2015-05-09 12:38 ` Sebastien Vauban
2015-05-09 13:57   ` Marcin Borkowski

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