help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Examples of use of svg.el?


From: Tomas Hlavaty
Subject: Re: Examples of use of svg.el?
Date: Fri, 01 Apr 2022 13:11:35 +0200

On Fri 01 Apr 2022 at 04:05, Eduardo Ochs <eduardoochs@gmail.com> wrote:
> I am trying to learn how to use svg.el, and I plan to use it mainly to
> plot mathematical functions. Can you recommend me links to blog
> posts/packages/demos/snippets/whatevers that show how to use svg.el?
>
> My current notes are here:
>
>   http://angg.twu.net/2022eev-svg.html

There is svg.el but I do not like it because:
- it requires gui emacs
- it is not pure, it changes the cons-tree using side-effects

I prefer doing it using pure functions, something like described in
id:87ft7zs48u.fsf@logand.com

(require 'xml)
(with-temp-buffer
  (xml-print
   '((svg
      ((xmlns . "http://www.w3.org/2000/svg";)
       (viewBox . "0 0 100 100"))
      (circle
       ((cx . "50") (cy . "50") (r . "20"))))))
  (write-file "/tmp/a.svg"))

which you can refactor anyway you like, e.g.

(defun svg (x y w h &rest body)
  `((svg
     ((xmlns . "http://www.w3.org/2000/svg";)
      (viewBox . ,(format "%s %s %s %s" x y w h)))
     ,@body)))

(defun svg-circle (cx cy r)
  `(circle
    ((cx . ,(format "%s" cx)
     (cy . ,(format "%s" cy))
     (r . ,(format "%s" r))))))

(with-temp-buffer
  (xml-print
   (svg 0 0 100 100 (svg-circle 50 50 20)))
  (write-file "/tmp/a.svg"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]