From 988488669243a6a8e6649096460b16547f4edf9f Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 3 Jan 2023 16:39:51 +0800 Subject: [PATCH] org-latex-preview: Tweak baseline alignment * lisp/org-latex-preview.el (org-latex-preview--update-overlay): After doing quite a bit of testing, tweak the ascent formula to introduce a slight correction to visually improve the final result. --- lisp/org-latex-preview.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 9c48b278b..7496ff1de 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -326,7 +326,20 @@ indeed LaTeX fragments/environments.") :file (car path-info) :height (and height (cons (* height zoom) 'em)) :ascent (if (and depth height) - (ceiling (* 100 (- 1.0 (/ depth height)))) + ;; The baseline seems to tend to sit slightly + ;; lower than it should be, and a very mild + ;; bias seems to improve the visual result. + ;; From testing with a collecting of LaTeX + ;; maths fonts (cm, cmbright, arev, pxfonts, + ;; notomath, nextxsf, eulervm) decreacing the + ;; depth measurement by 0.02pt in the baseline + ;; calculation seems to work well. + ;; I have yet to come across any situation + ;; where this results in a negative depth, + ;; however we may as well ensure that never + ;; occurs. + (round (* 100 (- 1 (/ (max 0.0 (- depth 0.02)) + height)))) 'center))))) (overlay-put ov 'display image-display) (overlay-put ov 'preview-image image-display)