> > All of the edge cases we discussed off-list have been addressed, but I
> > have no doubt that several more exist.  If you find more please document
> > the steps to reproduce them.
> 
> Ok. Let's me play around with weird staff.
 
I got confused because we were discussing live-preview behavior in
org-src buffers.  The behavior of live-preview re: latex export blocks
is a new issue.  I'm assuming that you could not break live-previews +
org-src buffers after I updated the implementation of
org-latex-preview-live--src-buffer-setup.

Onto this issue:

> > > #+begin_src latex :var val=test[]
> > >   \(x = z\)
> > > #+end_src
> > > 
> > > #+RESULTS:
> > > #+begin_export latex
> > > \(x = z\)
> > > #+end_export
> > > 
> > > #+begin_export latex
> > > \(x=z\)
> > > #+end_export
> > > 
> > > export blocks are not previewed as is, but they do get previewed when I
> > > evaluate latex src block.

>> I don't follow.  Are you saying that when
>> org-latex-preview-mode-display-live is set, an export latex block that's
>> the result of a latex src block is live previewed when it is being
>> edited in an org-src buffer?  Even though it shouldn't be.
>
> 1. make repro
> 2. (require 'ob-latex) (require 'org-latex-preview) (setq 
> org-latex-preview-live t)
> 3. Open the above
> 4. M-x org-latex-preview-mode
> 5. C-c C-x C-l
> 6. Note that equations inside #+begin_export... are NOT previewed
> 7. Go to begin_src, C-c C-c
> 8. Observe equation inside begin_export results being previewed

Okay, I can reproduce this.  I can't find a way to fix it though.  Here
is what's happening.  When I hit C-c C-c inside

#+begin_src latex
  \(x = z\)
#+end_src

ob-latex first inserts the result as a latex fragment, not an export
block:

#+begin_src latex
  \(x = z\)
#+end_src

#+RESULTS:
\(x = z\)

When this happens, the after-change-handler for live-previews calls
(org-element-context) and sees a latex-fragment, not an export block.
So it renders the preview.

In a separate buffer change afterwards, the export block delimiters are
added, turning it into

#+begin_src latex
  \(x = z\)
#+end_src

#+RESULTS:
#+begin_export latex
\(x = z\)
#+end_export

Now the (org-element-context) returns an export-block element, but it is
too late.  The preview has already been generated.

There are two ways I can see to fix this:

- Make ob-latex/org-babel-insert-result insert the full result (export
latex block containing the fragment) in one `insert' call.

- Make a special case in
org-latex-preview-mode--maybe-track-element-here to check if the
insertion is happening in the vicinity of a #+RESULTS marker.  This is a
heuristic/hack that can fail in many ways, and it will slow down buffer
tracking for live previews, so I don't want to do this.

If you have any ideas let me know.

> Also, I note that make repro complains about org-loaddefs on olp
> branch. Not sure what is going on, but it is not the case on main.

Here is the output of make repro for me:

--8<---------------cut here---------------start------------->8---
-*- mode: compilation; default-directory: "~/.emacs.d/elpaca/repos/org/" -*-
Compilation started at Sun Feb  1 14:44:54

make repro
make -C doc cleanall;  make -C etc cleanall;  make -C lisp cleanall;
make[1]: Entering directory '/home/karthik/.emacs.d/elpaca/repos/org/doc'
rm -f *.pdf *.html *.info *_letter.tex org-version.inc org-version.tex \
      *.aux *.cp *.cps *.dvi *.fn *.fns *.ky *.kys *.pg *.pgs *.toc \
              *.tp *.tps *.vr *.vrs *.log *.ps
rm -f org.texi orgguide.texi
rm -fr guide manual
make[1]: Leaving directory '/home/karthik/.emacs.d/elpaca/repos/org/doc'
make[1]: Entering directory '/home/karthik/.emacs.d/elpaca/repos/org/etc'
make[1]: Nothing to be done for 'cleanall'.
make[1]: Leaving directory '/home/karthik/.emacs.d/elpaca/repos/org/etc'
make[1]: Entering directory '/home/karthik/.emacs.d/elpaca/repos/org/lisp'
rm -f org-version.el org-loaddefs.el org-version.elc org-loaddefs.elc 
org-install.elc
rm -f *.elc
make[1]: Leaving directory '/home/karthik/.emacs.d/elpaca/repos/org/lisp'
rm -fr /tmp/tmp-orgtest || { \
  find /tmp/tmp-orgtest -type d -exec chmod u+w {} + && \
  rm -fr /tmp/tmp-orgtest ; \
}
rm -f .git/hooks/commit-msg .git/hooks/commit-msg-files.awk 
.git/hooks/post-commit .git/hooks/pre-commit .git/hooks/prepare-commit-msg 
.git/hooks/pre-push
find . \( -name \*~ -o -name \*# -o -name .#\* \) -exec rm -f {} +
find testing mk \( -name \*~ -o -name \*.elc \) -exec rm -f {} +
make -C lisp autoloads
make[1]: Entering directory '/home/karthik/.emacs.d/elpaca/repos/org/lisp'
rm -f org-version.el org-loaddefs.el org-version.elc org-loaddefs.elc 
org-install.elc
org-version: 9.8-pre (release_9.7.39-911-g52ca57)
Loading /home/karthik/.emacs.d/elpaca/repos/org/lisp/org-compat.el (source)...
Loading /home/karthik/.emacs.d/elpaca/repos/org/mk/org-fixup.el (source)...
org-loaddefs: 9.8-pre (release_9.7.39-911-g52ca57)
Loading /home/karthik/.emacs.d/elpaca/repos/org/lisp/org-compat.el (source)...
Loading /home/karthik/.emacs.d/elpaca/repos/org/mk/org-fixup.el (source)...
  INFO     Scraping 131 files for loaddefs... 
  INFO     Scraping 131 files for loaddefs...89% 
  INFO     Scraping 131 files for loaddefs...done
  GEN      org-loaddefs.el
make[1]: Leaving directory '/home/karthik/.emacs.d/elpaca/repos/org/lisp'

Compilation finished at Sun Feb  1 14:44:55, duration 1.00 s
--8<---------------cut here---------------end--------------->8---

What should I be looking for here?

Karthik

Reply via email to