On Tue, Apr 15 2025, Karthik Chikmagalur <karthikchikmaga...@gmail.com> wrote:

>>> Basically, we need a specialized parser that will guess that a given
>>> paragraph of text is actually an incomplete or broken latex fragment.
>>> You may try writing one. For example, by additionally checking paragraph
>>> elements to be latex-like.
>>
>> Alternatively, why not fix Karthik's stated problem with some analogue
>> to `org-insert-structure-template'? E.g. `org-insert-latex-environment'.
>
> The problem is deletion, not insertion of environments.  The
> live-preview capability of the new org-latex-preview feature is confused
> by the state of the Org element when you delete the \end{FOO} line of
> the environment.
>
> Here is an example.  An environment is being previewed live, and edited:
>
> https://share.karthinks.com/olp-live-preview-deletion-bug.mp4
>
> When you delete the \begin{FOO} line and move the cursor away, the live
> preview disappears as it should, because the Org element is no longer a
> LaTeX environment.  But when you delete the \end{FOO} line, the preview
> doesn't clear because the start of the element, at \begin{FOO}, is still
> a LaTeX fragment.  Fixing this is subtle.

I fear you may be over-committed to a certain way of thinking about
this: that is, you are convinced it is the job of a preview tool to
compensate for ill-formed LaTeX code. That is a really large demand.

Maybe it is better to think about how to provide editing tools that
circumvent common mistakes (like removing \end{FOO}).

My suggestion would be to add an `org-insert/delete-latex-environment'
   that could also delete matching pairs of environment delimiters.

Leo

Reply via email to