Hi Ihor,

On 11 Aug 2023, Ihor Radchenko wrote:

Ok. Would you mind adding a commit message, as described in https://orgmode.org/worg/org-contribute.html#first-patch?

Patch attached. I also attached a test file.

And do I understand correctly that no changes in https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-lilypond.html are needed?

Probably not, but I'll check.

--
Jonathan
commit 8916c9ebbefb1b1d448e0e39998f9b9a3b054680
Author: Jonathan Gregory <j...@autistici.org>
Date:   Wed Aug 16 09:47:09 2023 -0300

    lisp/ob-lilypond.el: Prevent full page results in basic-mode
    
    * ob-lilypond.el (org-babel-lilypond-paper-settings): New variable.
    Link: https://list.orgmode.org/87a5w15jur.fsf@localhost/
    
    TINYCHANGE

diff --git a/lisp/ob-lilypond.el b/lisp/ob-lilypond.el
index 9693b89e2..ad8371c5f 100644
--- a/lisp/ob-lilypond.el
+++ b/lisp/ob-lilypond.el
@@ -175,31 +175,51 @@ specific arguments to =org-babel-tangle=."
   (if (org-babel-tangle nil "yes" "lilypond")
       (org-babel-lilypond-execute-tangled-ly) nil))
 
+;; https://lilypond.org/doc/v2.24/Documentation/usage/other-programs
+(defvar org-babel-lilypond-paper-settings
+  "#(if (ly:get-option 'use-paper-size-for-page)
+            (begin (ly:set-option 'use-paper-size-for-page #f)
+                   (ly:set-option 'tall-page-formats '%s)))
+\\paper {
+  indent=0\\mm
+  tagline=\"\"
+  oddFooterMarkup=##f
+  oddHeaderMarkup=##f
+  bookTitleMarkup=##f
+  scoreTitleMarkup=##f
+}\n"
+  "The paper settings required to generate music fragments.
+They are needed for mixing music and text in basic-mode.")
+
 (defun org-babel-lilypond-process-basic (body params)
   "Execute a lilypond block in basic mode."
   (let* ((out-file (cdr (assq :file params)))
+         (file-type (file-name-extension out-file))
 	 (cmdline (or (cdr (assq :cmdline params))
 		      ""))
 	 (in-file (org-babel-temp-file "lilypond-")))
 
     (with-temp-file in-file
-      (insert (org-babel-expand-body:generic body params)))
+      (insert
+       (format org-babel-lilypond-paper-settings file-type)
+       (org-babel-expand-body:generic body params)))
     (org-babel-eval
      (concat
       org-babel-lilypond-ly-command
       " -dbackend=eps "
       "-dno-gs-load-fonts "
       "-dinclude-eps-fonts "
-      (or (cdr (assoc (file-name-extension out-file)
-		      '(("pdf" . "--pdf ")
-			("ps" . "--ps ")
-			("png" . "--png "))))
+      (or (assoc-default file-type
+                         '(("pdf" . "--pdf ")
+			   ("eps" . "--eps ")))
 	  "--png ")
       "--output="
       (file-name-sans-extension out-file)
       " "
       cmdline
-      in-file) "")) nil)
+      in-file)
+     ""))
+  nil)
 
 (defun org-babel-prep-session:lilypond (_session _params)
   "Return an error because LilyPond exporter does not support sessions."
#+title: Test
#+PROPERTY: header-args:lilypond :noweb yes :exports results
#+PROPERTY: header-args:lilypond :prologue (org-babel-ref-resolve "settings[]")

Some text.

#+begin_src lilypond :file myfile.pdf
\score {
  \new Staff \relative c' {
    \tempo 4 = 160
    c4 e g b
    c4 b d c
    \tempo 4 = 96
    d,4 fis a cis
    d4 cis e d
  }
  \layout { }
  \midi { }
}
#+end_src

#+results:
[[file:myfile.pdf]]

Click [[file:myfile.midi][here]] to listen to the MIDI output.

#+name: settings
#+begin_src lilypond :exports none
\version "2.24.1"
% More lilypond settings here...
#+end_src

Reply via email to