yangsheng6810 / org-latex-impatient

Instant Previews LaTeX snippets in Org-mode
GNU General Public License v3.0
148 stars 10 forks source link

No previews when latex/MPS mode enabled in orgmode #18

Closed deb75 closed 1 year ago

deb75 commented 1 year ago

With recent packages update, I noticed that whenever the cursor enters in a math environment, the major mode changes from orgmode to latex/MPS. This seems to break the org-latex-impatient previews.

\begin{equation} <= works if cursor on this line
a = b +c           <= does not work whatever you type
\end{equation} <= also works when cursor on this line

I tried to add this :

(use-package org-latex-impatient
  :defer t
  :hook
  (org-mode . org-latex-impatient-mode)
  (LaTeX-math-mode . org-latex-impatient-mode)
  (LaTeX-mode . org-latex-impatient-mode)

to the org-latex-impatient config, but this does nothing.

How could I reenable the previews as you type within math environments ?

Regards

deb75 commented 1 year ago

Or perhaps is it better to prevent emacs from changing of major mode from org to latex/MPS whenever you enter in a math environment. Do you know how to perform this ?

yangsheng6810 commented 1 year ago

What do you mean by "recent packages update"? An update of Emacs and/or Org-mode? Does the major mode change occur if you start Emacs with emacs -Q?

It would be great if you could share a minimal reproducible example with Emacs and Org mode version (preferable their git hash). I cannot reproduce it on Emacs 30 at 75f0484 and Org-mode f7aa8c19f.

deb75 commented 1 year ago

By recent update, I mean orgmode 9.6.3 and emacs at 30.0.50-cd9e65e1. Update operated with package-list-packages two days ago.

The major mode change is (I think) due to poly-org-latex-inner-mode, I opened an issue https://github.com/polymode/poly-org/issues/46 because it breaks several things.

There are no particular settings except that of loading poly-org. Unloading it solves the issue.

What I do not understand is why org-latex-impatient-mode does not work even when I add :

(LaTeX-math-mode . org-latex-impatient-mode)
  (LaTeX-mode . org-latex-impatient-mode)

to its configuration. In your README, it is said that org-latex-impatient-mode is experimental for latex file.

vspinu commented 1 year ago

I see 3 options:

Regarding the font-lock in indirect buffer error I have no idea to be frank. Font lock should not be directly activated in those buffers.

deb75 commented 1 year ago

Thanks for your sound answer, I chose the first option. Regards

yangsheng6810 commented 1 year ago

Currently, org-latex-impatient first checks if the major mode is a derived mode of either org-mode, latex-mode (LaTeX-mode is derived from it), or markdown-mode. If not, it hides the preview posframe and suspend action. Math fragment detection is by looking at the face of letters.

Since I am not familiar with poly-org, I would suggest the following starting steps if you want to hack for yourself:

  1. Figure out the major mode when your cursor is in the "a=b+c" part (press C-h v, then type "major-mode"), suppose it is some-special-latex-mode
  2. Search for (derived-mode-p 'latex-mode) in the file, and replace all of them with (or (derived-mode-p 'latex-mode) (derived-mode-p 'some-special-latex-mode))
  3. Figure out the faces of letters in the "a=b+c" part by M-x describe-char when your cursor is in the region, and modify org-latex-impatient--tex-in-latex-p accordingly.

Note: this is only a starting point. Unfortunately, I didn't consider supporting major-mode other than org-mode when I started the project, making it non-trivial to add support for additional modes.