2

For nearly three weeks now EmacsForMacOSX natively supports viewing SVG figures inline (hurray!).

As expected, and unlike raster images, SVG figures typically have no background.

It is sufficient to set

(setq org-startup-with-inline-images t)

and then the line

[[./figure.svg]]

in an org-mode file will appear inline.

inline SVG image in Emacs

That's exactly how the SVG figures, whether output to HTML or PDF, will need to be—since the background will be white. But while writing (and being rather partial to a dark Emacs background) I'd like to see the figure on a white background.

How do I force SVG figures to appear inline on a white background?

Also, since C-ha svg brings up nothing yet, a second(ary) question is worth asking here: how can I set the width of SVG figures in the Emacs frame? (Their width is already consistent and determined by the width of the printed page.)

The SVG image above

For reference, here is the SVG image used above.

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    width="200" height="150"
    viewBox="0 0 200 150"
    version="1.1">
    <g>
        <path d="M 10 10 L 190 10 L 190 140 L 10 140 z"
            fill="none" stroke="blue" stroke-width="5" />
        <circle cx="100" cy="75" r="50"
            fill="none" stroke="blue" stroke-width="5" />
    </g>
</svg>

Such an image meant for a light (white) background will in general be unusable on a dark (black) background, hence the question.

Related

This solution, which doesn't work for me, attempts to solve the problem through org-mode—but in any case the issue is now one of SVG.

Sam
  • 317
  • 1
  • 11
  • Did you try @stardiviner's solution using `advice`? AFAICT, it should work (IOW, it's not an SVG issue, it's an Emacs `create-image` issue). – NickD Mar 29 '23 at 16:02
  • @NickD I did. It didn't work on my side. – Sam Mar 29 '23 at 16:07
  • Strange: it worked for me but the image I used already had a light blue background. I'd like to try with a transparent image: can you point me to the one you used? – NickD Mar 29 '23 at 17:05
  • Never mind: I changed it with `inkscape`. @stardiviner's [solution](https://emacs.stackexchange.com/a/37927/14825) works fine for me (and is easily reverted too). – NickD Mar 29 '23 at 17:11
  • @NickD I added the SVG image. – Sam Mar 29 '23 at 19:15
  • @NickD I tried again with a minimal .emacs, and it's still no good. The only modification I made is to replace ` :type '(choice color (const nil)))` with ` :type '(choice color (const white)))`. Is that also what you did on your side? – Sam Mar 29 '23 at 19:21
  • No, that does not change the value. I assume you have put the code in a file and you've loaded the file. Do `C-h v org-inline-image-background` and hit `Customize`; click on the value menu and hit `Color`l then click on the choice and click on a color; then hit `Apply`. Now try previewing. – NickD Mar 29 '23 at 19:38
  • @NickD Perfect. Your call. Delete the question? – Sam Mar 29 '23 at 20:39
  • The question is fine, but it might be a good idea for you to provide an answer summarizing the comments and filling in any gaps. – NickD Mar 29 '23 at 21:34

1 Answers1

2

Add this to your .emacs, followed by

(setq org-inline-image-background "white")

Credit for this answer: NickD

Sam
  • 317
  • 1
  • 11