emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using org-latex-preview in other major modes


From: Tony Zorman
Subject: Re: Using org-latex-preview in other major modes
Date: Mon, 08 Apr 2024 08:23:55 +0200
User-agent: Notmuch/0.38.3, Emacs 30.0.50

On Sun, Apr 07 2024 10:48, Karthik Chikmagalur wrote:
> [… 14 lines elided …]
>
> There are two issues with numbering:
> - providing an Org-agnostic API point to attach a numbering table to, and
> - calculating the new numbering table in LaTeX (or other major-modes).
>
> For The first issue, we need a way to provide an updated numbering table
> during the auto-regeneration of edited fragments.  Currently this is
> done implicitly by calling `org-latex-preview--place-from-elements' from
> the `--regenerate-overlay` function.
>
> The second requires fast numbering table updates.  We do it in Org by
> mapping over the org-element cache (see
> `org-latex-preview--get-numbered-environments').  Even this is too slow
> sometimes, so we suspend numbering updates when live-previewing until
> the cursor exits the fragment.  Parsing the LaTeX buffer from point to
> the end when (re)generating each preview is going to be too slow, so
> you'll have to create some kind of cache and update it incrementally.

Thanks for taking a look! It indeed seems that caching will be the most
work to properly implement. However, I'm quite happy to not care about
numbers for now and make sure the other stuff works correctly first
before tackling this.

> [… 14 lines elided …]
>
> `org-latex-preview-auto--detect-fragments-in-change' is written for
> speed. It only does quick text-matching and is thus mostly Org-agnostic,
> except for a call to a numbering calculation near the end.  This should
> be easy to adapt.  The problem is the function it calls,
> `org-latex-preview-auto--maybe-track-element-here', which finds the
> bounds of the inserted LaTeX fragment using org-element and
> conditionally sets up a preview overlay.  You will need an equivalent of
> this for LaTeX-mode.
>
> Since you have auto-mode working already, live previews should be quite
> easy to add.  From what I can see, you only need to provide your own
> `org-latex-preview-live--ensure-overlay'.  This function creates the
> preview overlay next to or under the LaTeX fragment.  All the other live
> preview code only changes overlay properties or calls
> `--regenerate-overlay`, which you've already implemented.

Besides `org-latex-preview-auto--maybe-track-element-here`, I was mostly
talking about `org-latex-preview-live--src-buffer-setup` and
`org-latex-preview-live--ensure-overlay`, which I think will be the main
targets. The latter seems to be quite a straightforward translation
(especially my current constraints of not caring about environments),
but the former seems to require a bit more work. Then again, maybe I'm
being too negative—after taking another quick look at the code I think
you're right in that this should not be impossible to overcome.

I'll try to conjure up some time this week to get live previews up and
running; will report back if I hit any unforeseen major bumps.

  Tony

-- 
Tony Zorman | https://tony-zorman.com/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]