Work around a display bug when previewing LaTeX fragments

* lisp/org.el (org-format-latex): Change signature.
(org-toggle-latex-fragment):
* lisp/ox-html.el (org-html-format-latex): Apply signature change.
This commit is contained in:
Nicolas Goaziou 2016-06-23 00:54:39 +02:00
parent 24852ef060
commit a24f339f58
2 changed files with 140 additions and 141 deletions

View file

@ -19114,8 +19114,7 @@ for all fragments in the buffer."
(when (display-graphic-p)
(catch 'exit
(save-excursion
(let ((window-start (window-start)) msg)
(save-restriction
(let (beg end msg)
(cond
((or (equal arg '(16))
(and (equal arg '(4))
@ -19126,53 +19125,53 @@ for all fragments in the buffer."
(setq msg "Creating images for buffer...")))
((equal arg '(4))
(org-with-limited-levels (org-back-to-heading t))
(let ((beg (point))
(end (progn (org-end-of-subtree t) (point))))
(setq beg (point))
(setq end (progn (org-end-of-subtree t) (point)))
(if (org-remove-latex-fragment-image-overlays beg end)
(progn
(message "LaTeX fragment images removed from subtree")
(throw 'exit nil))
(setq msg "Creating images for subtree...")
(narrow-to-region beg end))))
(setq msg "Creating images for subtree...")))
((let ((datum (org-element-context)))
(when (memq (org-element-type datum)
'(latex-environment latex-fragment))
(let* ((beg (org-element-property :begin datum))
(end (org-element-property :end datum)))
(setq beg (org-element-property :begin datum))
(setq end (org-element-property :end datum))
(if (org-remove-latex-fragment-image-overlays beg end)
(progn (message "LaTeX fragment image removed")
(throw 'exit nil))
(narrow-to-region beg end)
(setq msg "Creating image..."))))))
(setq msg "Creating image...")))))
(t
(org-with-limited-levels
(let ((beg (if (org-at-heading-p) (line-beginning-position)
(setq beg (if (org-at-heading-p) (line-beginning-position)
(outline-previous-heading)
(point)))
(end (progn (outline-next-heading) (point))))
(setq end (progn (outline-next-heading) (point)))
(if (org-remove-latex-fragment-image-overlays beg end)
(progn
(message "LaTeX fragment images removed from section")
(throw 'exit nil))
(setq msg "Creating images for section...")
(narrow-to-region beg end))))))
(setq msg "Creating images for section...")))))
(let ((file (buffer-file-name (buffer-base-buffer))))
(org-format-latex
(concat org-preview-latex-image-directory "org-ltximg")
;; Emacs cannot overlay images from remote hosts.
;; Create it in `temporary-file-directory' instead.
beg end
;; Emacs cannot overlay images from remote hosts. Create
;; it in `temporary-file-directory' instead.
(if (or (not file) (file-remote-p file))
temporary-file-directory
default-directory)
'overlays msg 'forbuffer org-preview-latex-default-process)))
;; Work around a bug that doesn't restore window's start
;; when widening back the buffer.
(set-window-start nil window-start)
'overlays msg 'forbuffer org-preview-latex-default-process))
(message (concat msg "done")))))))
(defun org-format-latex
(prefix &optional dir overlays msg forbuffer processing-type)
"Replace LaTeX fragments with links to an image, and produce images.
(prefix &optional beg end dir overlays msg forbuffer processing-type)
"Replace LaTeX fragments with links to an image.
The function takes care of creating the replacement image.
Only consider fragments between BEG and END when those are
provided.
When optional argument OVERLAYS is non-nil, display the image on
top of the fragment instead of replacing it.
@ -19186,11 +19185,11 @@ Some of the options can be changed using the variable
(let* ((math-regexp "\\$\\|\\\\[([]\\|^[ \t]*\\\\begin{[A-Za-z0-9*]+}")
(cnt 0)
checkdir-flag)
(goto-char (point-min))
(goto-char (or beg (point-min)))
;; Optimize overlay creation: (info "(elisp) Managing Overlays").
(when (and overlays (memq processing-type '(dvipng imagemagick)))
(overlay-recenter (point-max)))
(while (re-search-forward math-regexp nil t)
(overlay-recenter (or end (point-max))))
(while (re-search-forward math-regexp end t)
(unless (and overlays
(eq (get-char-property (point) 'org-overlay-type)
'org-latex-overlay))

View file

@ -2784,8 +2784,8 @@ INFO is a plist containing export properties."
(setq latex-frag (concat latex-header latex-frag))))
(with-temp-buffer
(insert latex-frag)
(org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
nil processing-type)
(org-format-latex cache-relpath nil nil cache-dir nil
"Creating LaTeX Image..." nil processing-type)
(buffer-string))))
(defun org-html-latex-environment (latex-environment _contents info)