From 5e7af27352ded733f1e8f0db1be0d3c154f4e80d Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 6 Jan 2024 18:09:14 +0800 Subject: [PATCH] org-latex-preview: Robustify DPI calculation * lisp/org-latex-preview.el (org-latex-preview--get-display-dpi): It was reported that on a WSLg system using pgtk that `org-latex-preview--get-display-dpi' produced an arithmetic overflow error. Inspecting the calculation performed and docstrings of functions involved, it seems we need to be more careful of the `display-mm-height' output. We now guard against it being zero or nil, which should make the DPI calculation more robust. Simply falling back to a guessed DPI of 140 is non-ideal, but probably the best we can reasonably do here. --- lisp/org-latex-preview.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lisp/org-latex-preview.el b/lisp/org-latex-preview.el index 44e943bf5..6fc43e5d3 100644 --- a/lisp/org-latex-preview.el +++ b/lisp/org-latex-preview.el @@ -2405,8 +2405,11 @@ color information for this run." The function assumes that the display has the same pixel width in the horizontal and vertical directions." (if (display-graphic-p) - (round (/ (display-pixel-height) - (/ (display-mm-height) 25.4))) + (let ((mm-height (or (display-mm-height) 0)) + (mm-per-inch 25.4)) + (if (= 0 mm-height) + 140 ; Fallback reasonable DPI + (round (/ (display-pixel-height) (/ mm-height mm-per-inch))))) (error "Attempt to calculate the dpi of a non-graphic display"))) (defun org-latex-preview--attr-color (attr)