3

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.

9
  • 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
    Commented Mar 29, 2023 at 16:02
  • @NickD I did. It didn't work on my side.
    – Sam7919
    Commented Mar 29, 2023 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
    Commented Mar 29, 2023 at 17:05
  • Never mind: I changed it with inkscape. @stardiviner's solution works fine for me (and is easily reverted too).
    – NickD
    Commented Mar 29, 2023 at 17:11
  • @NickD I added the SVG image.
    – Sam7919
    Commented Mar 29, 2023 at 19:15

1 Answer 1

3

Add this to your .emacs, followed by

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

Credit for this answer: NickD

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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