Menu

Documentation about Emacs' Graphics Support

SVG Support

SVG Logo

"Out of the box" Support

Since Emacs version ‑tbf‑, Emacs can display Scalable Vector Graphics (SVG) files out of the box. Using C-C C-C, you can switch between showing the graphics and showing the underlying SVG file. For the latter ‑ as SVG is pure XML ‑ the nXML mode is used. nXML mode allows you to edit the SVG file as you normally would edit any XML file.

Issues

As I write this, I use Emacs version 25.1.1 under MS Windows 10 Pro 21H2. I have observed the following issues, when viewing SVG content in Emacs:

Create and Manipulate SVG Files Using ELISP and svg.el

The ELISP package svg.el is part of standard Emacs since version 26.1. svg.el is due to Lars Magne Ingebrigtsen and Felix Klee.

The main purpose of svg.el is to programmatically create and manipulate SVG files using Emacs LISP.

In year 2014, Lars published the video https://www.youtube.com/watch?v=FWQB_9QcGI0. It show Emacs LISP code and below SVG file content, that changes in real-time (or may be after a key stroke). See also https://emacs.stackexchange.com/questions/46305/svg-in-realtime

Regards the LISP functions, that svg.el provides, see https://www.gnu.org/software/emacs/manual/html_node/elisp/SVG-Images.html

Example

The following grey circle SVG graphics was created using ELISP:

‑ Text before image is in a separate paragraph ‑

testSVG.el.svg ‑ Text immediately after image is in the same paragraph that contains the SVG ‑

The ELISP source code had been embedded in an org-mode document like so:

‑ Text before image is in a separate paragraph ‑
#+BEGIN_SRC emacs-lisp :exports results :results link file :file testSVG.el.svg
    (let ((svg (svg-create 200 200 :stroke-width 5 :stroke "green")))
      (svg-circle svg 100 100 50 :fill-color "gray" )
      (with-temp-buffer
        (svg-print svg)
        (buffer-string)))
#+END_SRC
#+RESULTS:
[[file:testSVG.el.svg]]
‑ Text immediately after image is in the same paragraph that contains the SVG ‑

Hence the SVG graphics can be changed by changing the ELISP source code. Note the :exports results setting: it suppresses the export of the ELISP source code when exporting to HTML code. The default is to show the ELISP code in the export.

Draw SVG Using the Easy Draw package

The purpose of the Easy Draws package is to create and edit SVG in Emacs by using the mouse and the keyboard and draw on a canvas directly in Emacs. Please see more detail here.

Draw SVG Using canvas-mode

Similarely to Easy Draw, there is canvas-mode due to Anand Tamariya. He published under https://gitlab.com/atamariya/emacs/-/blob/dev/lisp/svg.el an extended version of svg.al, that adds canvas-mode. Anand proposed in https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg00798.html to have canvas-mode added to the built-in svg.el.


Last change: 2023-11-14
© 2002-2023 Dr. Thomas Redelberger redethogmx.de

Close menu