Org LaTeX preview is fuzzy on retina displays

2019-03-20 15:05发布

问题:

I have been using Emacs 24.4 for all my math/scientific notes. org-latex-preview is fantastic for this! But recently, I upgraded to a macbook pro with retina display, and I now see that all my equations in org-mode are... fuzzy. Is there a setting I can change to up-res these?

Here is a screenshot:

Thanks!

回答1:

A couple of years back, I decided to fix this and wrote a patch to add dvisvgm as a render option for latex previews. While this worked great, I never submitted it (no time or knowledge on how to officially patch org).

Today, I was thrilled to discover that org-mode v9.0.6, now has this feature!

To activate, first check that you have dvisvgm on your system. Then update org-mode and add the following line to your init.el file:

(setq org-latex-create-formula-image-program 'dvisvgm)

And presto!



回答2:

I have tried the emacs-mac-port

If I create 2 files foo.png foo@2x.png on the same dir ,this will work.



回答3:

By default orgmode latex preview do not support retina, so on mac with retina screen, latex preview will be fuzzy.
However, we can hack org.el to achieve the function. Just follow steps below:

get the proper version of emacs

To instead use the Yamamoto Mitsuharu version of Emacs 25.1 (with more mac-specific features):

brew tap railwaycat/emacsmacport
brew install emacs-mac

and finally link it to your Applications folder:

brew linkapps emacs-mac

this version emacs will support retina image display.

change org-format-latex-options

change scale from 1.0 to 2.0, to generate 2x size image.

delete org.elc

add function to org.el

(defun galaxy-compose-image-filename-2x(image-file-name)
  (concat (file-name-directory image-file-name) (file-name-base image-file-name) "@2x." (file-name-extension image-file-name)))

and eval the function.

modify function org-format-latex

change fragment:

(unless (file-exists-p movefile)
  (org-create-formula-image value movefile options forbuffer processing-type)

to

(unless (file-exists-p movefile)
  (org-create-formula-image value movefile options forbuffer processing-type)
  (setq filename-2x (galaxy-compose-image-filename-2x movefile))
  (rename-file movefile filename-2x)
  (call-process-shell-command "convert" nil nil nil nil (concat "\"" filename-2x "\" -scale \"50%\" -quality \"100%\"" ) (concat "\"" movefile "\"" )))

and eval the function.

Now, you can preview latex with 2x size image for mac retina screen.