Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
deb75 opened this issue Apr 5, 2023 · 6 comments
Closed

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

deb75 opened this issue Apr 5, 2023 · 6 comments

Comments

@deb75
Copy link

deb75 commented Apr 5, 2023

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
Copy link
Author

deb75 commented Apr 5, 2023

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
Copy link
Owner

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
Copy link
Author

deb75 commented Apr 6, 2023

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 polymode/poly-org#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
Copy link

vspinu commented Apr 6, 2023

I see 3 options:

  • Don't switch to latex buffer. This way you get the LaTeX highlighting but you are kept in the base buffer
    (oset poly-org-latex-innermode :keep-in-mode 'host)
  • Remove the latex innermode from the polymode configuration so that you can edit the formulas in org-mode instead of latex mode
   (delq 'poly-org-latex-innermode (oref poly-org-polymode :innermodes))
  • I don't know how org-latex-impatient works but I presume there is a function which is placed in post-command-hook. You can advice that function to always execute in the host buffer (in org mode). Like in these examples.

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
Copy link
Author

deb75 commented Apr 6, 2023

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

@deb75 deb75 closed this as completed Apr 6, 2023
@yangsheng6810
Copy link
Owner

yangsheng6810 commented Apr 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants