Am 28.03.2014 20:44, schrieb David Kastrup:
Simon Albrecht <simon.albre...@mail.de> writes:
Hello,
I'm just creating a style sheet and want to create a scheme function
which sets the paper margins. However it seems the paper variables
aren't bound and I don't know why. A simple example would be:
\version "2.19.3"
test =
#(define-scheme-function (parser location num) (number?)
#{ \paper {
top-margin = #(* num paper-height)
}
#}
)
\test 0.1
{ c'1 }
Help is very much appreciated :-)
It is a scoping problem: the scope of # inside of #{ ... #} is that of
the embedding. Try something like
test =
#(define-scheme-function (parser location num) (number?)
#{ \paper { top-margin
$(* num (module-ref (current-module) 'paper-height)) } #})
\paper { \test 0.9 }
{ c'1 }
I am somewhat irritated that a plain
\test 0.9
does not work just as well. I thought I had done something to make that
work at one point of time, but apparently not so.
Attached you find the resulting function with a test score; the
'portrait version now works perfectly, only I can’t get the 'landscape
version to work as well (but I don’t need it for current work).
All the best,
Simon
% copyright by Simon Albrecht 2014
% licensed as Creative Common (BY-SA)
\version "2.19.3"
%% use inside \paper {}
typeArea =
#(define-scheme-function
;; size: optional paper size specification as defined in scm/paper.scm
;; orientation: 'portrait or 'landscape
;; ratio: typeAreaWidth/typeAreaHeight
;;;; examples:
;;;; portrait: standard 3/2, smaller would be 8/5 and 5/3
;;;; landscape: standard 5/4, smaller would be 6/5, larger 4/3
(parser location sz orientation ratio)
((string? "a4") symbol? rational?)
(_i "Calculate paper margins for DIN A paper formats so that:
â the width-to-height ratio of the type area is @var{ratio}
â the upper corners of the type area are on the diagonals of imaginary double pages
â the lower corners of the type area are on the diagonals of the page
which is supposed to make a pleasant visual appearance")
(cond
((and (eq? orientation 'portrait) (< ratio (sqrt 2)))
(ly:warning "Type area ratio has to be larger than square root
of 2 (1,414â¦). Using default margins"))
((and (eq? orientation 'landscape) (> ratio (sqrt 2)))
(ly:warning "Type area ratio has to be smaller than square root
of 2 (1,414â¦). Using default margins"))
(else
(cond ((eq? orientation 'portrait)
#{ \paper {
#(set-paper-size sz)
top-margin = $(*
(module-ref (current-module) 'paper-height)
(/ (- (numerator ratio)
(* (denominator ratio) (sqrt 2)))
(- (* 4 (numerator ratio))
(* 3 (denominator ratio) (sqrt 2))) ))
bottom-margin = #(* (module-ref (current-module) 'top-margin) 2)
left-margin = #(* (module-ref (current-module) 'top-margin) (sqrt 2))
right-margin = #(* (module-ref (current-module) 'top-margin) (sqrt 2)) }
#} )
((eq? 'orientation 'landscape)
#{ \paper {
#(set-paper-size sz orientation)
left-margin = $(*
(module-ref (current-module) 'paper-width)
(/ (- (numerator ratio)
(* (denominator ratio) (sqrt 2)))
(- (* 1.5 (numerator ratio))
(* 2 (denominator ratio) (sqrt 2))) ))
right-margin = #(module-ref (current-module) 'left-margin)
bottom-margin = #(* 0.5 (module-ref (current-module) 'left-margin) (sqrt 2))
top-margin = #(* (module-ref (current-module) 'bottom-margin) 0.5) }
#} )))
))
\paper {
\typeArea #'landscape #5/4
}
{ c'1 }
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user