io12 / org-fragtog

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them
MIT License
397 stars 14 forks source link

org fragtog mode stops working after a single error #29

Closed thibautbenjamin closed 3 years ago

thibautbenjamin commented 3 years ago

I have just tried using org-fragtog mode and I really like the idea, I was looking for exactly this package. However I noticed a small issue with the way errors are handled, which is probably due to a weird appear I have.

When I type the following snippet normally

\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}

everything works exactly as intended, and this looks like a very cool mode. But I tend to write first begin{} and then fill in the braces with pmatrix. If I do that, when I move the cursor out of the braces, the hook to the org-fragtog--post-cmd fires although I haven't finished typing. Of course, since there is no \end, this is not a valid LaTeX code and the preview fails, I get the following error reported in the *Messages* buffer Error in post-command-hook (org-fragtog--post-cmd): (error "File \"/tmp/orgtexIuM9v8.dvi\" wasn’t produced. Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.")

Just firing the error would be ok, but after this error, fragtog mode stops working completely, and I have to toggle manually the latex-preview again.

I am pretty new to emacs lisp, so not sure what the fix should be. I am wondering if catching the error with

(ignore-error (org-latex-preview))

could be a correct fix

io12 commented 3 years ago

Thanks! Fixed in https://github.com/io12/org-fragtog/commit/f501a40a49c007f7115ec8669b935fed1539c6e3. That was very close to the fix but I used ignore-errors instead of ignore-error.

thibautbenjamin commented 3 years ago

Thanks a lot, and thanks for your work, I love this package