From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [bug?, org-element] latex-environment delimiters must be at BOL
Date: Tue, 22 Jul 2014 15:28:33 +0200 [thread overview]
Message-ID: <874my9ldz2.fsf@gmx.us> (raw)
In-Reply-To: <87d2cxg16m.fsf@nicolasgoaziou.fr> (Nicolas Goaziou's message of "Tue, 22 Jul 2014 12:03:45 +0200")
[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]
Hi,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>> +(defconst org-element--latex-begin-environment
>> + "^[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}"
>
> I overlooked this in the previous patch. This regexp is not correct, as
> it matches, e.g.
>
> \begin{ab*cd}
>
> A more accurate regexp is
>
> "^[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}"
Note that the maint/master version of org-element--current-element
does not including a trailing "^". I
> I realize that `org-element--current-element' is wrong here. I fixed it
> in maint, which probably means that you will need to deal with a merge
> conflict.
I'm not sure the location of stars matter much in a technical sense,
though I have never come across any environments using stars other
than for the last character.
This document compiles fine, although it is an exercise is obscurity:
\documentclass{minimal}
\newenvironment{ab*cd}[1]{\bfseries{#1}}{}
\newenvironment{*abcd}[1]{\bfseries{#1}}{}
\begin{document}
\begin{ab*cd} x \end{ab*cd}
\begin{*abcd} x \end{*abcd}
\end{document}
I'm happy to accept only stars in the end, though.
>> + ;; The following format string also matches optional arguments:
>> + ;; "^[ \t]*\\\\begin{\\([A-Za-z0-9*]+\\)}\\(\\[.*?\\]\\|{.*?}\\)*[ \t]*?"
>
> I think this comment is not necessary.
It's a nice regexp. . .
>> + "Format string matching the beginning of a LaTeX environment.
>> +
>> +Usage example:
>> + (format org-element--latex-begin-environment ENV)
>> +where ENV is a LaTeX environment.
>
> `org-element--latex-begin-environment' is not a format string.
> `org-element--latex-end-environment' is.
True.
> You can remove this part. Add that the environment is put in group 1,
> though.
>
> Otherwise, the patch looks good. Feel free to apply it with suggested
> changes.
Sorry, I can't push to Org-git. But a patch is attached.
Thanks again,
Rasmus
--
This is the kind of tedious nonsense up with which I will not put
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-element.el-Allow-one-line-LaTeX-environments.patch --]
[-- Type: text/x-diff, Size: 4595 bytes --]
From fce1bff7789f90a9fa16cc318233166faf961a29 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Tue, 22 Jul 2014 15:09:03 +0200
Subject: [PATCH] org-element.el: Allow one-line LaTeX environments
* org-element.el (org-element--latex-begin-environment,
org-element--latex-end-environment): New format strings to identify
beginning and ending of LaTeX environments.
(org-element-latex-environment-parser, org-element-paragraph-parser,
org-element--current-element): Use `org-element--latex-begin-environment'
and `org-element--latex-end-environment'.
* test-org-element.el (test-org-element/latex-environment-parser):
Add tests.
---
lisp/org-element.el | 23 +++++++++++++++++------
testing/lisp/test-org-element.el | 22 +++++++++++++++++++++-
2 files changed, 38 insertions(+), 7 deletions(-)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index bfbba5e..75fccc5 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2084,6 +2084,18 @@ CONTENTS is nil."
;;;; Latex Environment
+(defconst org-element--latex-begin-environment
+ "^[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}"
+ "Regexp matching the beginning of a LaTeX environment.
+The environment is captured by the first group.
+
+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-environment-parser (limit affiliated)
"Parse a LaTeX environment.
@@ -2100,8 +2112,8 @@ Assume point is at the beginning of the latex environment."
(save-excursion
(let ((case-fold-search t)
(code-begin (point)))
- (looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
- (if (not (re-search-forward (format "^[ \t]*\\\\end{%s}[ \t]*$"
+ (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))
;; Incomplete latex environment: parse it as a paragraph.
@@ -2219,11 +2231,10 @@ Assume point is at the beginning of the paragraph."
(org-match-string-no-properties 1)))
limit t)))
;; Stop at valid latex environments.
- (and (looking-at
- "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
+ (and (looking-at org-element--latex-begin-environment)
(save-excursion
(re-search-forward
- (format "^[ \t]*\\\\end{%s}[ \t]*$"
+ (format org-element--latex-end-environment
(regexp-quote
(org-match-string-no-properties 1)))
limit t)))
@@ -3707,7 +3718,7 @@ element it has to parse."
(goto-char (car affiliated))
(org-element-keyword-parser limit nil))
;; LaTeX Environment.
- ((looking-at "[ \t]*\\\\begin{\\([A-Za-z0-9]+\\*?\\)}")
+ ((looking-at org-element--latex-begin-environment)
(org-element-latex-environment-parser limit affiliated))
;; Drawer and Property Drawer.
((looking-at org-drawer-regexp)
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 04ef1ce..0ca0f8a 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1310,9 +1310,29 @@ e^{i\\pi}+1=0
(eq 'latex-environment
(org-test-with-temp-text "\\begin{env}{arg}\nvalue\n\\end{env}"
(org-element-type (org-element-at-point)))))
+ ;; Allow environments without newline after \begin{.}.
+ (should
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env}{arg}something\nvalue\n\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; Allow one-line environments.
+ (should
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env}{arg}something\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; Should not allow different tags.
+ (should-not
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env*}{arg}something\\end{env}"
+ (org-element-type (org-element-at-point)))))
+ ;; LaTeX environments must be on separate lines.
+ (should-not
+ (eq 'latex-environment
+ (org-test-with-temp-text "\\begin{env} x \\end{env} y"
+ (org-element-type (org-element-at-point)))))
(should-not
(eq 'latex-environment
- (org-test-with-temp-text "\\begin{env}{arg} something\nvalue\n\\end{env}"
+ (org-test-with-temp-text "y \\begin{env} x<point> \\end{env}"
(org-element-type (org-element-at-point)))))
;; Handle non-empty blank line at the end of buffer.
(should
--
2.0.2
next prev parent reply other threads:[~2014-07-22 13:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-10 11:54 [bug?, org-element] latex-environment delimiters must be at BOL Rasmus
2014-07-16 13:04 ` Nicolas Goaziou
2014-07-18 15:49 ` Rasmus
2014-07-20 17:49 ` Nicolas Goaziou
2014-07-21 9:29 ` Rasmus
2014-07-22 7:54 ` Nicolas Goaziou
2014-07-22 9:08 ` Rasmus
2014-07-22 10:03 ` Nicolas Goaziou
2014-07-22 13:28 ` Rasmus [this message]
2014-07-23 8:29 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874my9ldz2.fsf@gmx.us \
--to=rasmus@gmx.us \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.