[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Choose paper size and layout with command line options?
From: |
Knute Snortum |
Subject: |
Re: Choose paper size and layout with command line options? |
Date: |
Sun, 7 Aug 2022 20:11:54 -0700 |
On Sun, Aug 7, 2022 at 4:03 PM M Sun <chris.corsair@gmail.com> wrote:
>
> Hi all,
>
> I’m writing a sheet targeting two different paper sizes, with some
> layout adjustments. My goal is to be able to specify (maybe
> indirectly) the paper size in command line, without changing the
> lilypond file itself. My initial set up was this:
>
> \version "2.23.2"
> #(set! paper-alist
> (cons '("kobo" . (cons (* 15.7 cm) (* 20.9 cm))) paper-alist))
> #(set-global-staff-size 18)
> \paper {
> top-margin = 0
> bottom-margin = 0
> left-margin = 5
> right-margin = 0
> }
> #(set-default-paper-size "kobo")
> \score { \new Staff {a b c}}
>
> As you can see this is a cramped layout for a small paper size. Now I
> also want a version with a normal layout on us-letter size, so I
> removed the set-global-staff-size line, and the paper block, and
> changed the paper size to “letter”. The file became this:
>
> \version "2.23.2"
> #(set! paper-alist
> (cons '("kobo" . (cons (* 15.7 cm) (* 20.9 cm))) paper-alist))
> #(set-default-paper-size "letter")
> \score { \new Staff {a b c}}
>
> These worked. But like I mentioned my goal is to be able to switch
> between these two setups in command line, without changing the file.
> My idea was to set a variable in the command line using “-e”, and in
> the file choose the layout and paper size based on the variable.
> Here’s my code:
>
> \version "2.23.2"
>
> #(define (configOutput spec)
> (cond
> ((eqv? spec 'letter) (set-default-paper-size "letter"))
> ((eqv? spec 'kobo)
> (set! paper-alist
> (cons '("kobo" . (cons (* 15.7 cm) (* 20.9 cm))) paper-alist))
> (set-global-staff-size 18)
> #{ \paper {
> top-margin = 0
> bottom-margin = 0
> left-margin = 5
> right-margin = 0 }
> #}
> (set-default-paper-size "kobo"))
> (default nil)))
>
> #(use-modules (guile-user))
> #(configOutput output-spec)
>
> \score { \new Staff {a b c}}
>
> Then in the shell I ran a command like this:
>
> lilypond -e "(define-public output-spec 'kobo)" test.ly
>
> This produced the output with the “kobo” paper size. Or I could change
> that “kobo” to “letter” and it’d produce with the “letter” paper size.
>
> This *almost* worked, except that the \paper block didn’t take effect.
> This is where I’m lost. How should I make this work?
I believe it's as easy as:
lilypond -dpaper-size="kobo" test.ly
--
Knute Snortum