forked from mirrors/org-mode
org-latex-preview: Do not show empty SVG fragments
* lisp/org-latex-preview.el (org-latex-preview--svg-make-fg-currentColor): When an SVG is empty, delete it. This will cause `org-latex-preview--cache-image' to give nil as the path. When the provided path is nil, do nothing. (org-latex-preview--update-overlay): If the image path is nil, do attempt to place an image. If an error is recorded and there is no image this causes the text to be shown with the error face. (org-latex-preview--cleanup-callback): If the image path is nil, do not try to delete it.
This commit is contained in:
parent
1931fc2131
commit
a3087aba81
|
@ -320,7 +320,7 @@ indeed LaTeX fragments/environments.")
|
||||||
(height (plist-get (cdr path-info) :height))
|
(height (plist-get (cdr path-info) :height))
|
||||||
(depth (plist-get (cdr path-info) :depth))
|
(depth (plist-get (cdr path-info) :depth))
|
||||||
(image-display
|
(image-display
|
||||||
(and path-info
|
(and (car path-info)
|
||||||
(list 'image
|
(list 'image
|
||||||
:type (plist-get (cdr path-info) :image-type)
|
:type (plist-get (cdr path-info) :image-type)
|
||||||
:file (car path-info)
|
:file (car path-info)
|
||||||
|
@ -341,8 +341,9 @@ indeed LaTeX fragments/environments.")
|
||||||
(round (* 100 (- 1 (/ (max 0.0 (- depth 0.02))
|
(round (* 100 (- 1 (/ (max 0.0 (- depth 0.02))
|
||||||
height))))
|
height))))
|
||||||
'center)))))
|
'center)))))
|
||||||
(overlay-put ov 'display image-display)
|
(when image-display
|
||||||
(overlay-put ov 'preview-image image-display)
|
(overlay-put ov 'display image-display)
|
||||||
|
(overlay-put ov 'preview-image image-display))
|
||||||
(overlay-put
|
(overlay-put
|
||||||
ov 'face
|
ov 'face
|
||||||
(cond
|
(cond
|
||||||
|
@ -1041,7 +1042,7 @@ The path of the created LaTeX file is returned."
|
||||||
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
|
'(".dvi" ".xdv" ".pdf" ".tex" ".aux" ".log"
|
||||||
".svg" ".png" ".jpg" ".jpeg" ".out"))))
|
".svg" ".png" ".jpg" ".jpeg" ".out"))))
|
||||||
(dolist (img images)
|
(dolist (img images)
|
||||||
(delete-file img))
|
(and img (delete-file img)))
|
||||||
(dolist (ext clean-exts)
|
(dolist (ext clean-exts)
|
||||||
(when (file-exists-p (concat basename ext))
|
(when (file-exists-p (concat basename ext))
|
||||||
(delete-file (concat basename ext))))))
|
(delete-file (concat basename ext))))))
|
||||||
|
@ -1196,16 +1197,24 @@ tests with the output of dvisvgm."
|
||||||
(coding-system-for-write 'utf-8)
|
(coding-system-for-write 'utf-8)
|
||||||
;; Prevent any file handlers (specifically
|
;; Prevent any file handlers (specifically
|
||||||
;; `image-file-handler') from being called.
|
;; `image-file-handler') from being called.
|
||||||
(file-name-handler-alist nil))
|
(file-name-handler-alist nil)
|
||||||
(with-temp-buffer
|
(path (plist-get svg-fragment :path)))
|
||||||
(insert-file-contents (plist-get svg-fragment :path))
|
(when path
|
||||||
(goto-char (point-min))
|
(with-temp-buffer
|
||||||
(when (re-search-forward "<g fill='\\(#[0-9a-f]\\{6\\}\\)'" nil t)
|
(insert-file-contents path)
|
||||||
(let* ((same-color (format "\\(?:fill\\|stroke\\)='\\(%s\\)'" (match-string 1))))
|
(goto-char (point-min))
|
||||||
(replace-match "currentColor" t t nil 1)
|
(if (re-search-forward "<svg[^>]*>\n<g[^>]*>\n</svg>" nil t)
|
||||||
(while (re-search-forward same-color nil t)
|
;; We never want to show an empty SVG, instead it is better to delete
|
||||||
(replace-match "currentColor" t t nil 1)))
|
;; it and leave the LaTeX fragment without an image overlay.
|
||||||
(write-region nil nil (plist-get svg-fragment :path) nil 0)))))
|
;; This also works better with other parts of the system, such as
|
||||||
|
;; the display of errors.
|
||||||
|
(delete-file path)
|
||||||
|
(when (re-search-forward "<g fill='\\(#[0-9a-f]\\{6\\}\\)'" nil t)
|
||||||
|
(let* ((same-color (format "\\(?:fill\\|stroke\\)='\\(%s\\)'" (match-string 1))))
|
||||||
|
(replace-match "currentColor" t t nil 1)
|
||||||
|
(while (re-search-forward same-color nil t)
|
||||||
|
(replace-match "currentColor" t t nil 1)))
|
||||||
|
(write-region nil nil path nil 0)))))))
|
||||||
|
|
||||||
(defconst org-latex-preview--dvipng-dpi-pt-factor 0.5144
|
(defconst org-latex-preview--dvipng-dpi-pt-factor 0.5144
|
||||||
"Factor that converts dvipng reported depth at 140 DPI to pt.
|
"Factor that converts dvipng reported depth at 140 DPI to pt.
|
||||||
|
|
Loading…
Reference in New Issue