Hello Urs,

On 14.02.2013 20:50, Urs Liska wrote:
Hi list,

maybe it's an academic question, but maybe it also triggers the curiosity of some Scheme-hackers ;-)
I wouldn't call it academic - if want to build some kind of workflow, you will face the need for creating several pdfs from one ly-file.
Is it possible to write something (probably a Scheme function) that lets LilyPond compile a file twice with a different file included or a different command line option?
... you can process a book object in scheme as often you like (ly:process-book)
Or is it possible from within a document to launch a second LilyPond instance with an arbitrary command line option set?
You can play with schemes 'system' command, but I wouldn't use that, to call lilypond - it is already running.
The background is: I want to create a scenario where I can compile two different pdf files in one run. The two files should have a different first-page-number and a different filename suffix. I would like to have two versions of a score starting on odd and even pages. (Afterwards I want to include the appropriate file in a LaTeX document, depending on the page in the document.)

I can imagine doing this with two layout include files (like 'start-odd.ily' and 'start-even.ily') or with a function that directly writes the right commands depending on command line options (like '-dstartodd' or 'dstarteven').

So maybe the easiest way would be to have a function that triggers two separate lilypond runs on the same file, providing different command line options. I'd then have a main .ly file as usual that includes one of two style sheets depending on the presence of command line options, but I would explicitely run lilypond on a 'master' file that doesn't actually contain music but only controls the build process.
My approach is using a book variable. A scheme-function then sets all given paper vars in the book paper before it starts processing it with ly:process-book. The example file creates writeBook.pdf (odd version), writeBook-even.pdf and writeBook-music.midi.

HTH

Best, Jan-Peter

\version "2.16.0"

% process a book with ly:book-process
% book - the book
% paper - the paper
% layout - layout or midi block
writeBook =
#(define-void-function (parser location book paper layout file)
   (ly:book? list? ly:output-def? string?)
   ; set all given paper vars in book paper
   (for-each (lambda (p)
               (if (pair? p)
                   (ly:output-def-set-variable! (ly:book-paper book) (car p)(cdr p))))
     paper)
   (ly:book-process book #{ \paper {} #} layout file))

% get the current output name
myname = #(ly:parser-output-name parser)

% our book
mybook = \book {
  \paper {
    % odd/even header with pagenumber
    oddHeaderMarkup = \markup \fill-line {
      \null \bold \fromproperty #'page:page-number-string
    }
    evenHeaderMarkup = \markup \fill-line {
      \bold \fromproperty #'page:page-number-string \null
    }
  }
  % innovative music
  \relative c'' {
    bes4 a c b cis a fis d c1
  }
}


% write a pdf with first-page-number = 3 (odd)
% no to 'odd' suffix, to let frescobaldi display the result
\writeBook #mybook #'((first-page-number . 3)) \layout {} #(format "~A" myname)
% write a pdf with first-page-number = 2 (even)
\writeBook #mybook #'((first-page-number . 2)) \layout {} #(format "~A-even" myname)
% write a midi file
\writeBook #mybook #'() \midi {
  \tempo 4 = 120
} #(format "~A-music" myname)
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to