Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2023-01-11 Thread Ihor Radchenko
Daniel Fleischer  writes:

> Ihor Radchenko  writes:
>
>> Can you try to test the attached patch?
>
> Looks good. Now these work again: `cdlatex-dollar`, inserting symbols
> using ` outside math environments and inserting cdlatex environments
> with completion also outside math environments. Need to make sure the
> issue of the OP didn't regress.

Applied onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=dfcf500df

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2023-01-07 Thread Ihor Radchenko
Daniel Fleischer  writes:

> BTW, I haven't follow any discussions about org syntax and math
> environments inside org (the use of \...[\] instead $...$ etc.) These
> usecases I mentioned are what I'm used to and perhaps they are not
> consistent with changes made to the org syntax, demanding every math
> should be inside a math environment for easier parsing and you still
> managed to solve that without all the previous regexps.

We did not make changes to syntax. Just decided to aim towards less
visibility of $..$ in the documentation.

At the end, we don't want to break existing documents, just to
discourage people from using $...$ syntax.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2023-01-07 Thread Daniel Fleischer
Ihor Radchenko  writes:

> Can you try to test the attached patch?

Looks good. Now these work again: `cdlatex-dollar`, inserting symbols
using ` outside math environments and inserting cdlatex environments
with completion also outside math environments. Need to make sure the
issue of the OP didn't regress.

BTW, I haven't follow any discussions about org syntax and math
environments inside org (the use of \...[\] instead $...$ etc.) These
usecases I mentioned are what I'm used to and perhaps they are not
consistent with changes made to the org syntax, demanding every math
should be inside a math environment for easier parsing and you still
managed to solve that without all the previous regexps.

Thank you,

-- 
Daniel Fleischer



Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2023-01-07 Thread Ihor Radchenko
Daniel Fleischer  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
> eqn
>stopped working.

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

Can you try to test the attached patch?

>From bce44c75b73fa0b935a9f991624a292e061f5c73 Mon Sep 17 00:00:00 2001
Message-Id: 
From: Ihor Radchenko 
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 
Link: https://orgmode.org/list/m2cz7sj5zt@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  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  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  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  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


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 


Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2023-01-06 Thread Daniel Fleischer
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
eqn
   stopped working.

Previously org-cdlatex worked perfectly, you could insert \alpha using
`a and it compiled to HTML/latex (without $$), have $...$ compiled into
an inline equation and insert latex environment like
\begin{align}...\end{align} without explicit math environment and was
also compiled perfectly to HTML/latex.

-- 
Daniel Fleischer



Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2022-12-18 Thread Justin Silverman
That makes sense. Yes it breaks some of my snippets which have a condition 
texmathp (I don't write latex without enclosing in latex math environment in 
org).
Its an easy enough fix for me though:

(add-hook 'org-cdlatex-mode-hook
  (lambda () (advice-remove 'texmathp 'org--math-always-on)))

does the trick.

Justin 

Ihor Radchenko  writes:

> Justin Silverman  writes:
>
>> Thanks for the quick response. I just had a chance to check it out. 
>> Unfortunately (unless I am mistaken), with the change, `texmathp' is now 
>> always returning t... which is not very helpful.
>
> Not exactly. I just tried to follow the docstring
>
> (defun org--math-always-on (orig-fun  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.
> `\\[org-cdlatex-mode-map]'"
>
> So, `texmathp' will return t outside latex, inside inline latex, and
> _maybe_ inside latex environments. Only inside latex environments, Org
> delegates the job to `textmathp'.
>
> Let me know if this change broke any real workflows.


Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2022-12-14 Thread Ihor Radchenko
Justin Silverman  writes:

> Thanks for the quick response. I just had a chance to check it out. 
> Unfortunately (unless I am mistaken), with the change, `texmathp' is now 
> always returning t... which is not very helpful.

Not exactly. I just tried to follow the docstring

(defun org--math-always-on (orig-fun  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.
`\\[org-cdlatex-mode-map]'"

So, `texmathp' will return t outside latex, inside inline latex, and
_maybe_ inside latex environments. Only inside latex environments, Org
delegates the job to `textmathp'.

Let me know if this change broke any real workflows.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2022-12-13 Thread Justin Silverman
Thanks for the quick response. I just had a chance to check it out. 
Unfortunately (unless I am mistaken), with the change, `texmathp' is now always 
returning t... which is not very helpful.

Justin 

Ihor Radchenko  writes:

> Justin Silverman  writes:
>
>> texmathp when used in org-mode seems to have problems with multiline align* 
>> environments.
>>
>> Consider the following math environment: 
>>
>>
>> \begin{align*}
>> y_{i} &~ f(mu_{i}) 
>> |
>> \end{align*}
>>
>> where cursor is at `|'. With cursor at this point try `(texmathp)'. I get 
>> `nil'. It seems to only
>> be a problem on the start of a blank line.
>
> Thanks for reporting!
> Fixed on main.
> 


Re: [BUG] issue with texmathp [9.6 (release_9.6-22-g78d283 @ /home/jds6696/.emacs.d/straight/build/org-mode/)]

2022-12-10 Thread Ihor Radchenko
Justin Silverman  writes:

> texmathp when used in org-mode seems to have problems with multiline align* 
> environments.
>
> Consider the following math environment: 
>
>
> \begin{align*}
> y_{i} &\sim f(\mu_{i}) \\ 
> |
> \end{align*}
>
> where cursor is at `|'. With cursor at this point try `(texmathp)'. I get 
> `nil'. It seems to only be a problem on the start of a blank line.

Thanks for reporting!
Fixed on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f01390cf0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at