mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-22 16:04:25 +01:00
Minor sliced LaTeX preview improvements
Signed-off-by: main <magic_rb@redalder.org>
This commit is contained in:
parent
a8cd87e72f
commit
18afbadf1f
|
@ -75,18 +75,35 @@ Enable additional babel languages.
|
|||
|
||||
* Latex
|
||||
|
||||
For previews, create SVGs and not PNGs or something, use the =dvisvgm= command.
|
||||
For previews, create SVGs and not PNGs or something, use the ~dvisvgm-lua~ command.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp :results none
|
||||
(setq org-preview-latex-default-process 'dvisvgm)
|
||||
#+END_SRC
|
||||
|
||||
Adjust size of LaTeX previews.
|
||||
Actually define ~dvisvgm-lua~.
|
||||
|
||||
#+BEGIN_SRC emacs-lisp :results none
|
||||
(pcase (system-name)
|
||||
("heater" (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.75)))
|
||||
("omen" (setq org-format-latex-options (plist-put org-format-latex-options :scale 0.8))))
|
||||
#+begin_src emacs-lisp :results none
|
||||
(add-to-list
|
||||
'org-preview-latex-process-alist
|
||||
'(dvisvgm-lua
|
||||
:programs ("dvilualatex" "dvisvgm")
|
||||
:description "dvi > svg"
|
||||
:message "you need to install the programs: latex and dvisvgm."
|
||||
:image-input-type "dvi"
|
||||
:image-output-type "svg"
|
||||
:image-size-adjust (1.7 . 1.5)
|
||||
:latex-compiler ("dvilualatex -interaction nonstopmode -output-directory %o %f")
|
||||
:image-converter ("dvisvgm %f -n -b min -c %S -o %O")))
|
||||
#+end_src
|
||||
|
||||
|
||||
Adjust size of LaTeX previews.
|
||||
|
||||
,#+BEGIN_SRC emacs-lisp :results none
|
||||
(pcase (system-name)
|
||||
("heater" (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.75)))
|
||||
("omen" (setq org-format-latex-options (plist-put org-format-latex-options :scale 0.8))))
|
||||
#+END_SRC
|
||||
|
||||
To support non-breakable whitespace, create a new ~org-entity~.
|
||||
|
@ -108,19 +125,15 @@ Enable fontification for inline LaTeX blocks which convieniently also makes in f
|
|||
Normally a LaTeX preview is just one huge image which makes Emacs really jumpy and makes writing prose a really unpleasant experience. With these two functions, that's fixed. They work using mainly text properties (overlays are still involved but only one per preview, max two) so it should be fast still.
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
;;; -*- lexical-binding: t; -*-
|
||||
|
||||
(defadvice org-clear-latex-preview (after org-prop-img--org-clear-later-preview (beg end) activate)
|
||||
(save-excursion
|
||||
(goto-char beg)
|
||||
(with-silent-modifications
|
||||
(put-text-property beg end 'read-only nil)
|
||||
(if (> (count-lines beg end) 1)
|
||||
(while (search-forward "\n" end t)
|
||||
(forward-char -1)
|
||||
(put-text-property (line-beginning-position) (line-end-position) 'display nil)
|
||||
(put-text-property (line-beginning-position) (+ (line-end-position) 1) 'line-height nil)
|
||||
(forward-char 1))
|
||||
(put-text-property beg end 'display nil)
|
||||
(put-text-property beg end 'line-height nil)))
|
||||
(put-text-property beg end 'display nil)
|
||||
(put-text-property beg end 'line-height nil))
|
||||
(font-lock-fontify-region beg end)))
|
||||
|
||||
(defun org--make-preview-overlay (beg end image &optional imagetype)
|
||||
|
@ -128,9 +141,13 @@ Normally a LaTeX preview is just one huge image which makes Emacs really jumpy a
|
|||
Argument IMAGETYPE is the extension of the displayed image,
|
||||
as a string. It defaults to \"png\"."
|
||||
(let* ((imagetype (or (intern imagetype) 'png))
|
||||
(image-spec (list 'image :type imagetype :file image :relief 0 :ascent 'center))
|
||||
(image-spec (list 'image :type imagetype :file image :relief 0))
|
||||
(ov (make-overlay beg end)))
|
||||
(overlay-put ov 'org-overlay-type 'org-latex-overlay)
|
||||
(overlay-put ov
|
||||
'modification-hooks
|
||||
(list (lambda (&rest _args)
|
||||
(org-clear-latex-preview beg end))))
|
||||
(if (> (count-lines beg end) 1)
|
||||
(let ((image-height (cdr (image-size image-spec t)))
|
||||
|
||||
|
@ -155,7 +172,11 @@ Normally a LaTeX preview is just one huge image which makes Emacs really jumpy a
|
|||
(list
|
||||
(list 'slice
|
||||
0 y 1.0 dy)
|
||||
image-spec))
|
||||
(append
|
||||
image-spec
|
||||
(if (> dy (- image-height y))
|
||||
'(:ascent center)
|
||||
'(:ascent center)))))
|
||||
;; remove any fontification face so the images don't get colored
|
||||
(put-text-property (line-beginning-position) (line-end-position)
|
||||
'face
|
||||
|
@ -164,7 +185,7 @@ Normally a LaTeX preview is just one huge image which makes Emacs really jumpy a
|
|||
(forward-line 1)
|
||||
(setq y (+ y dy))))
|
||||
(if (not (> (point) endm))
|
||||
(let ((ov (make-overlay (point) endm)))
|
||||
(let ((ov (make-overlay (- (point) 1) endm)))
|
||||
|
||||
(overlay-put ov 'org-overlay-type 'org-latex-overlay)
|
||||
(overlay-put ov 'evaporate t)
|
||||
|
@ -175,8 +196,7 @@ Normally a LaTeX preview is just one huge image which makes Emacs really jumpy a
|
|||
'display
|
||||
(list image-spec))))
|
||||
(with-silent-modifications
|
||||
(put-text-property beg end 'line-height t)
|
||||
(put-text-property beg end 'read-only t))))
|
||||
(put-text-property beg end 'line-height t))))
|
||||
#+end_src
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue