diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 22b849a7d..41f541638 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -1658,8 +1658,21 @@ tests with the output of dvisvgm." (when path (with-temp-buffer (insert-file-contents path) + (unless ; When the svg is incomplete, wait for it to be completed. + (string= (buffer-substring (- (point-max) 6) (point-max)) + "") + (catch 'svg-complete + (dotimes (_ 1000) ; Check for complete svg over 1s. + (if (string= (buffer-substring (- (point-max) 6) (point-max)) + "") + (throw 'svg-complete t) + (erase-buffer) + (sit-for 0.001) + (insert-file-contents path))) + (erase-buffer))) (goto-char (point-min)) - (if (re-search-forward "]*>\n]*>\n" nil t) + (if (or (= (buffer-size) 0) + (re-search-forward "]*>\n]*>\n" nil t)) ;; We never want to show an empty SVG, instead it is better to delete ;; it and leave the LaTeX fragment without an image overlay. ;; This also works better with other parts of the system, such as