1

When I open SVG files in Emacs they appear blurry. The SVG files themselves are fine (when I open them in Firefox they scale perfectly). My Emacs is compiled with svg support (librsvg), so it should use that for rendering, right?

(init-image-library 'svg)

returns t.

Additionally, I looked at the image overlay properties with describe-char and I'm seeing

(image :type svg :file "/home/matt/src/blog/org/img/test.svg" :scale 1.726482213438735)

which as far as I can tell looks right.

I did notice that display-mm-width and height were way too big and I thought that might be giving librsvg a wrong DPI, so I changed them with

(setq display-mm-dimensions-alist '(t . (126 . 37)))

But that had no effect, even after clearing the image cache.

I also thought maybe imagemagick was getting in the way, so I disabled imagemagick for svg with

(add-to-list 'imagemagick-types-inhibit 'SVG)
(imagemagick-register-types)

but that also had no effect.

How can I get SVGs to display properly?

I'm using Emacs v28, although I had the same issue with 27 and if I remember correctly, 26 as well. In any event I don't think it's a version issue.


Edit: I was able to get this to work by changing the dvisvgm command options I was using to generate the file. I still don't understand what the issue was because firefox was able to display the SVG fine in either case.


Edit 2: Here's a MWE of the issue. Note the comment above is wrong, I'd simply changed the dvisvgm scale with the -c flag. This hides the issue, but doesn't seem to fix it and messes up image sizes.

I start with a tex document input:

\documentclass{standalone}
\usepackage{xcolor}

\begin{document}
$a=b+c$
\end{document}

then convert it to pdf with

pdflatex file.tex

and then use dvisvgm with

dvisvgm --pdf file.pdf -n -b min -c 1 -o file.svg

Here's how it appears in an emacs buffer after several image-increase-size commands: enter image description here

Here's the same file zoomed to 300% in my browser enter image description here

In reference to the first edit, here's what happens when I change the dvisvgm scale (-c) to 10 enter image description here

That looks nice now, but its much larger and when you zoom in you start to see the blurriness reappear enter image description here

  • could you post the dvisvgm parameters you currently have and, if you remember, the previous settings? – Wojciech Gac Feb 7 at 10:51
  • @WojciechGac I've updated the question with more specific information. Let me know if I've omitted any other useful info. – MattHusz Feb 7 at 18:05
1

This is a known issue with Emacs, documented as issue #1 in bug report 40845. I've copied that portion of the report here for convenience

Manually scaling an image, as is done for the second image, doesn't re-render the svg: is scales the bitmap-rendered version of it, causing blurriness.

There's a patch in that chain, although it doesn't seem to have been thoroughly tested and has not yet been accepted. I'll update this answer when there's a fix in master.


As of August 23, 2020 this is now fixed (see linked bug report for details).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.