tecosaur / org-latex-preview-todos

A tracker for the Org LaTeX Preview effort on https://git.tecosaur.net/tec/org-mode
4 stars 0 forks source link

DPI issues with emacs-pgtk + WSLg #7

Closed karthink closed 6 months ago

karthink commented 6 months ago

Running org-latex-preview returns an arithmetic overflow error with the function org-latex-preview--get-display-dpi. Report from user:

Does it support emacs-pgtk? It returns an arithmetic overflow error with function =(org-latex-preview--get-display-dpi)=. 
I'm using emacs in archwsl with wslg. It works well in normal emacs, but when I switch to emacs-pgtk (for dark-theme titlebar), I face the error.
tecosaur commented 6 months ago

Looking at the implementation, I think the only way this can happen is if display-mm-height is zero. The docstring also says it can be nil, so I'm going to update the function to this:

(defun org-latex-preview--get-display-dpi ()
  "Get the DPI of the display.
The function assumes that the display has the same pixel width in
the horizontal and vertical directions."
  (if (display-graphic-p)
      (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")))
tecosaur commented 6 months ago

https://git.tecosaur.net/tec/org-mode/commit/2ab8a6983c74