Skip to content

Commit

Permalink
Add support for generating graphics
Browse files Browse the repository at this point in the history
In particular, we redefine show(URL) to use ImageMagick to convert the
image to one with the desired format and filename.
  • Loading branch information
d-torrance committed Dec 28, 2023
1 parent 334f77e commit 0b26ee5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ob-M2.el
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,27 @@ last statement in BODY, as elisp."
(concat "{" (mapconcat #'ob-M2-var-to-macaulay2 var ", ") "}")
(prin1-to-string var)))

(defun org-babel-expand-body:M2 (body params)

Check failure on line 137 in ob-M2.el

View workflow job for this annotation

GitHub Actions / check

"org-babel-expand-body:M2" doesn't start with package's prefix "ob-M2".

Check failure on line 137 in ob-M2.el

View workflow job for this annotation

GitHub Actions / check

`org-babel-expand-body:M2' contains a non-standard separator `:', use hyphens instead (see Elisp Coding Conventions).
"Expand BODY with PARAMS for Macaulay2 code.
Graphics generation will only work if ImageMagick is installed."
(let ((graphics-file (and (member "graphics" (assq :result-params params))
(org-babel-graphical-output-file params))))
(org-babel-expand-body:generic
body params
(nconc (org-babel-variable-assignments:M2 params)
(when graphics-file
(list (concat
"show URL := url -> run(\"convert \" | first url | \" "
graphics-file "\")")))))))

(defun org-babel-execute:M2 (body params)
"Execute a block of Macaulay2 code in BODY using PARAMS with org-babel.
This function is called by `org-babel-execute-src-block'"
(let* ((processed-params (org-babel-process-params params))
(session (ob-M2-initiate-session
(cdr (assq :session processed-params))))
(result-type (cdr (assq :result-type processed-params)))
(full-body (org-babel-expand-body:generic
body params
(org-babel-variable-assignments:M2 params)))
(full-body (org-babel-expand-body:M2 body params))
(result (org-babel-script-escape
(org-trim
(if (string= session "none")
Expand Down

0 comments on commit 0b26ee5

Please sign in to comment.