reddit / emacs

Scaling latex previews along with text?

karthink · 2022-02-09 01:53
Does anyone have some elisp handy that scales latex previews along with text when using `text-scale-adjust`? I want to do this in both latex and org buffers, which use two different functions/features for this (preview-latex and org-latex-preview). If using dvipng (as opposed to to the dvisvgm method) I'm not looking to regenerate the previews at the new size, it's OK if it stretches out the images when increasing the text scale.
karthink · 2022-02-25 08:24
Since there doesn't seem to be, I wrote a cheap version of it: (defun my/text-scale-adjust-latex-previews () (pcase major-mode ('latex-mode (dolist (ov (overlays-in (point-min) (point-max))) (if (eq (overlay-get ov 'category) 'preview-overlay) (my/zoom-latex-preview ov)))) ('org-mode (dolist (ov (overlays-in (point-min) (point-max))) (if (eq (overlay-get ov 'org-overlay-type) 'org-latex-overlay) (my/zoom-latex-preview ov)))))) (defun my/zoom-latex-preview (ov) (overlay-put ov 'display (cons 'image (plist-put (cdr (overlay-get ov 'display)) :scale (+ 1.0 (* 0.25 text-scale-mode-amount)))))) (add-hook 'text-scale-mode-hook #'my/text-scale-adjust-latex-previews)
_viz_ · 2022-02-25 14:29
I never bothered to look into this since resizing, e.g. org inline images, were really choppy but it looks my I had the wrong impression. Thank you for this snippet! Btw, why not use derived-mode-p?
karthink · 2022-02-26 03:19
I forgot `derived-mode-p` exists! I have some odd elisp practices. I use `dolist` instead of `mapc`, check the major-mode variable instead of using `derived-mode-p` etc.