# how to reference paper variables in a music function

4 messages
Open this post in threaded view
|

## how to reference paper variables in a music function

 I have a complex Mutopia submission that requires different formatting for A4 and Letter sized paper (it's too tight on the page to trust lilypond's spacing algorithms on the same source without paper specific tweaks). So I'd like to define a music function (see "ifLetter" below) that can sense the paper choice and select either of two music definitions accordingly. In the demo below, I'd like to switch output between music-one (one system) and music-two (two systems) depending upon which paper size is set.  But I'm just guessing about how to reference the documented variable "paper-width" to compare to the value 8.5\in.  In the attempt below, the condition always evaluates to ##f and produces two systems on letter size paper (I want music-one for letter paper). I'd prefer testing a variable whose value was "letter" (rather than 8.5 inches) but I couldn't find such a variable documented (paper-size?, default-paper-size?). I've seen ly:output-def-lookup, but that requires a props or layout that is not obvious how to access within a music function. The code below produces the expected results when the condition (eqv? 'paper:paper-width (* 8.5 25.4))is rewritten as(eqv? 1 1) or (eqv? 1 2). BTW, documented spacing examples suggest that the construct (* 8.5 in) should be effective in scheme, but I get a compile error indicating that "in" is unbound, so I've written in 25.4 as a literal. BTW2, I've similarly been unable to access the paper variable page-count within a music function. Thx, Jeff -- \version "2.18.2" \paper{    page-count = #1    %#(set-paper-size "a4")      %uncomment to test specific paper size    #(set-paper-size "letter")  %uncomment to test specific paper size } music-one = { a b c d e f g } music-two = { a b c d \break e f g } ifLetter = #(define-music-function (parser location musL musE) (ly:music? ly:music?)     (if (eqv? 'paper:paper-width (* 8.5 25.4)) musL musE )     ) \score { \ifLetter \music-one \music-two } _______________________________________________ lilypond-user mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/lilypond-user
Open this post in threaded view
|

## Re: how to reference paper variables in a music function

 On Wed 28 Nov 2018 at 23:12:20 (-0700), Jeff Olson wrote: > I have a complex Mutopia submission that requires different formatting > for A4 and Letter sized paper (it's too tight on the page to trust > lilypond's spacing algorithms on the same source without paper > specific tweaks). > > So I'd like to define a music function (see "ifLetter" below) that can > sense the paper choice and select either of two music definitions > accordingly. > > In the demo below, I'd like to switch output between music-one (one > system) and music-two (two systems) depending upon which paper size is > set.  But I'm just guessing about how to reference the documented > variable "paper-width" to compare to the value 8.5\in.  In the attempt > below, the condition always evaluates to ##f and produces two systems > on letter size paper (I want music-one for letter paper). > > I'd prefer testing a variable whose value was "letter" (rather than > 8.5 inches) but I couldn't find such a variable documented > (paper-size?, default-paper-size?). > > I've seen ly:output-def-lookup, but that requires a props or layout > that is not obvious how to access within a music function. > > The code below produces the expected results when the condition (eqv? > 'paper:paper-width (* 8.5 25.4))is rewritten as(eqv? 1 1) or (eqv? 1 > 2). > > BTW, documented spacing examples suggest that the construct (* 8.5 in) > should be effective in scheme, but I get a compile error indicating > that "in" is unbound, so I've written in 25.4 as a literal. > > BTW2, I've similarly been unable to access the paper variable > page-count within a music function. > \paper{ >   page-count = #1 >   %#(set-paper-size "a4")      %uncomment to test specific paper size >   #(set-paper-size "letter")  %uncomment to test specific paper size > } > ifLetter = > #(define-music-function (parser location musL musE) (ly:music? ly:music?) >    (if (eqv? 'paper:paper-width (* 8.5 25.4)) musL musE ) >    ) > > \score { \ifLetter \music-one \music-two } You're editing one % character to switch between paper sizes, so why not: % ifLetter = \paper { #(set-paper-size "a4") } % uncomment for A4  ifLetter = \paper { #(set-paper-size "letter") } % uncomment for Letter Cheers, David. _______________________________________________ lilypond-user mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/lilypond-user
 In reply to this post by Jeff Olson Am Do., 29. Nov. 2018 um 09:34 Uhr schrieb Jeff Olson <[hidden email]>: > > I have a complex Mutopia submission that requires different formatting > for A4 and Letter sized paper (it's too tight on the page to trust > lilypond's spacing algorithms on the same source without paper specific > tweaks). > > So I'd like to define a music function (see "ifLetter" below) that can > sense the paper choice and select either of two music definitions > accordingly. > > In the demo below, I'd like to switch output between music-one (one > system) and music-two (two systems) depending upon which paper size is > set.  But I'm just guessing about how to reference the documented > variable "paper-width" to compare to the value 8.5\in.  In the attempt > below, the condition always evaluates to ##f and produces two systems on > letter size paper (I want music-one for letter paper). > > I'd prefer testing a variable whose value was "letter" (rather than 8.5 > inches) but I couldn't find such a variable documented (paper-size?, > default-paper-size?). > > I've seen ly:output-def-lookup, but that requires a props or layout that > is not obvious how to access within a music function. > > The code below produces the expected results when the condition (eqv? > 'paper:paper-width (* 8.5 25.4))is rewritten as(eqv? 1 1) or (eqv? 1 2). > > BTW, documented spacing examples suggest that the construct (* 8.5 in) > should be effective in scheme, but I get a compile error indicating that > "in" is unbound, so I've written in 25.4 as a literal. > > BTW2, I've similarly been unable to access the paper variable page-count > within a music function. > > Thx, > Jeff > -- > \version "2.18.2" > > \paper{ >    page-count = #1 >    %#(set-paper-size "a4")      %uncomment to test specific paper size >    #(set-paper-size "letter")  %uncomment to test specific paper size > } > > music-one = { a b c d e f g } > music-two = { a b c d \break e f g } > > ifLetter = > #(define-music-function (parser location musL musE) (ly:music? ly:music?) >     (if (eqv? 'paper:paper-width (* 8.5 25.4)) musL musE ) >     ) > > \score { \ifLetter \music-one \music-two } There are several paper-variables, ofcourse accessible _in_ \paper: %% to have access to 'pretty-print' it's not part of \paper but present in ly-files #(define pretty-print pretty-print) \paper {    page-count = #1    #(set-paper-size "letter")    #(pretty-print       (list         in         page-count         paper-width         papersizename)) } => (25.4 1 215.9 "letter") Looking from elsewhere you need to go for (ly:output-def-lookup $defaultpaper ...): #(pretty-print (list (ly:output-def-lookup$defaultpaper 'in)     (ly:output-def-lookup $defaultpaper 'page-count) (ly:output-def-lookup$defaultpaper 'paper-width)     (ly:output-def-lookup $defaultpaper 'papersizename))) => (25.4 () 210.0 "a4") So your function could be: \paper { page-count = #1 #(set-paper-size "letter") } music-one = { a^"one" b c d e f g } music-two = { a^"two" b c d \break e f g } ifLetter = #(define-music-function (parser location musL musE) (ly:music? ly:music?) (if (equal? (ly:output-def-lookup$defaultpaper 'papersizename) "letter")         musL musE)) \score { \ifLetter \music-one \music-two } Cheers,   Harm _______________________________________________ lilypond-user mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/lilypond-user
 In reply to this post by David Wright Thanks, David, for your prompt reply.  Unfortunately I do not have the ability to alter the source in any way (including commenting out lines) once the source has been submitted to Mutopia.  Their process is to specify the paper size on the lilypond command line; any code like those set-paper-size commands that would interfere has to be commented out.  I think Harm's solution would help lots of frustrated Mutopia people who tear their hair out over trying to make the exact same source file generate satisfactory output on two different paper sizes. Thx again, Jeff On 11/29/2018 9:26 AM, David Wright wrote: On Wed 28 Nov 2018 at 23:12:20 (-0700), Jeff Olson wrote:  I have a complex Mutopia submission that requires different formatting for A4 and Letter sized paper (it's too tight on the page to trust lilypond's spacing algorithms on the same source without paper specific tweaks). So I'd like to define a music function (see "ifLetter" below) that can sense the paper choice and select either of two music definitions accordingly. In the demo below, I'd like to switch output between music-one (one system) and music-two (two systems) depending upon which paper size is set.  But I'm just guessing about how to reference the documented variable "paper-width" to compare to the value 8.5\in.  In the attempt below, the condition always evaluates to ##f and produces two systems on letter size paper (I want music-one for letter paper). I'd prefer testing a variable whose value was "letter" (rather than 8.5 inches) but I couldn't find such a variable documented (paper-size?, default-paper-size?). I've seen ly:output-def-lookup, but that requires a props or layout that is not obvious how to access within a music function. The code below produces the expected results when the condition (eqv? 'paper:paper-width (* 8.5 25.4))is rewritten as(eqv? 1 1) or (eqv? 1 2). BTW, documented spacing examples suggest that the construct (* 8.5 in) should be effective in scheme, but I get a compile error indicating that "in" is unbound, so I've written in 25.4 as a literal. BTW2, I've similarly been unable to access the paper variable page-count within a music function.  \paper{   page-count = #1   %#(set-paper-size "a4")      %uncomment to test specific paper size   #(set-paper-size "letter")  %uncomment to test specific paper size }  ifLetter = #(define-music-function (parser location musL musE) (ly:music? ly:music?)    (if (eqv? 'paper:paper-width (* 8.5 25.4)) musL musE )    ) \score { \ifLetter \music-one \music-two }  You're editing one % character to switch between paper sizes, so why not: % ifLetter = \paper { #(set-paper-size "a4") } % uncomment for A4 ifLetter = \paper { #(set-paper-size "letter") } % uncomment for Letter Cheers, David.  -- o_ Jeff Olson (\___\/_____/) jjocanoe ~ ~ ~ / ~ ~ ~ ~ @gmail.com  _______________________________________________ lilypond-user mailing list [hidden email] https://lists.gnu.org/mailman/listinfo/lilypond-user