emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Daniel Fleischer <danflscr@gmail.com>
Cc: Justin Silverman <jsilve24@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]
Date: Sat, 07 Jan 2023 11:23:07 +0000	[thread overview]
Message-ID: <87ilhimvvo.fsf@localhost> (raw)
In-Reply-To: <m2cz7sj5zt.fsf@gmail.com>

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

Daniel Fleischer <danflscr@gmail.com> writes:

> I just found this thread after math-related things stopped working. I
> have two use cases that don't work now:
>
> 1. Inserting a dollar pair $$ using `cdlatex-dollar` (it thinks we're
> inside a math environment).
>
> 2. Inserting of cdlatex environments using their built-in completions, e.g.
>         ali<TAB>
>         eqn<TAB>
>    stopped working.

Thanks for reporting!
So, the docstring was erroneous at the end.

Can you try to test the attached patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-cdlatex-mode-Fix-regression-from-f01390cf05.patch --]
[-- Type: text/x-patch, Size: 3600 bytes --]

From bce44c75b73fa0b935a9f991624a292e061f5c73 Mon Sep 17 00:00:00 2001
Message-Id: <bce44c75b73fa0b935a9f991624a292e061f5c73.1673090538.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 7 Jan 2023 14:17:26 +0300
Subject: [PATCH] org-cdlatex-mode: Fix regression from f01390cf05

* lisp/org.el (org--math-always-on): Rename to `org--math-p' and only
override `texmathp' when current command is `cdlatex-math-symbol' or
when we are inside Org LaTeX math fragment.  Only these two scenarios
are the places where `texmathp' may not work properly in Org files.
We must not return t outside latex fragments as initially suggested by
the docstring because it would break, for example, `cdlatex-dollar'
command.
(org-cdlatex-mode): Use the new function name for advice.
* lisp/org-compat.el (org--math-always-on): Declare obsolete.

Reported-by: Daniel Fleischer <danflscr@gmail.com>
Link: https://orgmode.org/list/m2cz7sj5zt.fsf@gmail.com
---
 lisp/org-compat.el |  3 +++
 lisp/org.el        | 27 ++++++++++++++++-----------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 6c5085255..0f6dc831a 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -568,6 +568,9 @@ (defun org-let2 (list1 list2 &rest body) ;FIXME: Where did our karma go?
 (make-obsolete 'org-let "to be removed" "9.6")
 (make-obsolete 'org-let2 "to be removed" "9.6")
 
+(define-obsolete-function-alias 'org--math-always-on
+  'org--math-p "9.7")
+
 (defun org-compatible-face (inherits specs)
   "Make a compatible face specification.
 If INHERITS is an existing face and if the Emacs version supports
diff --git a/lisp/org.el b/lisp/org.el
index ae6250e52..44c41a729 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15434,13 +15434,15 @@ (define-minor-mode org-cdlatex-mode
     (cdlatex-compute-tables))
   (unless org-cdlatex-texmathp-advice-is-done
     (setq org-cdlatex-texmathp-advice-is-done t)
-    (advice-add 'texmathp :around #'org--math-always-on)))
+    (advice-add 'texmathp :around #'org--math-p)))
 
-(defun org--math-always-on (orig-fun &rest args)
-  "Always return t in Org buffers.
-This is because we want to insert math symbols without dollars even outside
-the LaTeX math segments.  If Org mode thinks that point is actually inside
-an embedded LaTeX fragment, let `texmathp' do its job.
+(defun org--math-p (orig-fun &rest args)
+  "Return t inside math fragments or running `cdlatex-math-symbol'.
+This function is intended to be an :around advice for `texmathp'.
+
+If Org mode thinks that point is actually inside
+an embedded LaTeX environment, return t when the environment is math
+or let `texmathp' do its job otherwise.
 `\\[org-cdlatex-mode-map]'"
   (interactive)
   (cond
@@ -15450,11 +15452,14 @@ (defun org--math-always-on (orig-fun &rest args)
     t)
    (t
     (let ((element (org-element-context)))
-      (or (not (org-inside-LaTeX-fragment-p element))
-          (if (not (eq (org-element-type element) 'latex-fragment))
-              (apply orig-fun args)
-            (setq texmathp-why '("Org mode embedded math" . 0))
-	    t))))))
+      (when (org-inside-LaTeX-fragment-p element)
+        (pcase (substring-no-properties
+                (org-element-property :value element)
+                0 2)
+          ((or "\\(" "\\[" (pred (string-match-p (rx string-start "$"))))
+           (setq texmathp-why '("Org mode embedded math" . 0))
+           t)
+          (_ (apply orig-fun args))))))))
 
 (defun turn-on-org-cdlatex ()
   "Unconditionally turn on `org-cdlatex-mode'."
-- 
2.38.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

  reply	other threads:[~2023-01-07 11:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 16:48 [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)] Justin Silverman
2022-12-10  9:25 ` Ihor Radchenko
2022-12-13 19:48   ` Justin Silverman
2022-12-14  8:15     ` Ihor Radchenko
2022-12-18 15:17       ` Justin Silverman
2023-01-06 10:45       ` Daniel Fleischer
2023-01-07 11:23         ` Ihor Radchenko [this message]
2023-01-07 13:49           ` Daniel Fleischer
2023-01-07 15:03             ` Ihor Radchenko
2023-01-11 11:00             ` Ihor Radchenko

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilhimvvo.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=danflscr@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jsilve24@gmail.com \
    /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 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).