1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 (define-markup-command (draw-circle layout props radius thickness fill)
28 (number? number? boolean?)
29 "A circle of radius @var{radius}, thickness @var{thickness} and
31 (make-circle-stencil radius thickness fill))
33 (define-markup-command (triangle layout props filled) (boolean?)
34 "A triangle, filled or not"
36 ((th (chain-assoc-get 'thickness props 0.1))
37 (size (chain-assoc-get 'font-size props 0))
40 (chain-assoc-get 'baseline-skip props 2))))
54 (define-markup-command (circle layout props arg) (markup?)
55 "Draw a circle around @var{arg}. Use @code{thickness},
56 @code{circle-padding} and @code{font-size} properties to determine line
57 thickness and padding around the markup."
59 (let* ((th (chain-assoc-get 'thickness props 0.1))
60 (size (chain-assoc-get 'font-size props 0))
63 (chain-assoc-get 'circle-padding props 0.2)))
64 (m (interpret-markup layout props arg)))
65 (circle-stencil m th pad)))
67 (define-markup-command (with-url layout props url arg) (string? markup?)
68 "Add a link to URL @var{url} around @var{arg}. This only works in
70 (let* ((stil (interpret-markup layout props arg))
71 (xextent (ly:stencil-extent stil X))
72 (yextent (ly:stencil-extent stil Y))
73 (old-expr (ly:stencil-expr stil))
74 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
75 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
78 (define-markup-command (beam layout props width slope thickness)
79 (number? number? number?)
80 "Create a beam with the specified parameters."
81 (let* ((y (* slope width))
82 (yext (cons (min 0 y) (max 0 y)))
83 (half (/ thickness 2)))
88 width (+ (* width slope) (/ thickness -2))
89 width (+ (* width slope) (/ thickness 2))
91 ,(ly:output-def-lookup layout 'blot-diameter)
94 (cons (+ (- half) (car yext))
95 (+ half (cdr yext))))))
97 (define-markup-command (box layout props arg) (markup?)
98 "Draw a box round @var{arg}. Looks at @code{thickness},
99 @code{box-padding} and @code{font-size} properties to determine line
100 thickness and padding around the markup."
102 (let* ((th (chain-assoc-get 'thickness props 0.1))
103 (size (chain-assoc-get 'font-size props 0))
104 (pad (* (magstep size)
105 (chain-assoc-get 'box-padding props 0.2)))
106 (m (interpret-markup layout props arg)))
107 (box-stencil m th pad)))
109 (define-markup-command (filled-box layout props xext yext blot)
110 (number-pair? number-pair? number?)
111 "Draw a box with rounded corners of dimensions @var{xext} and
112 @var{yext}. For example,
114 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
116 create a box extending horizontally from -0.3 to 1.8 and
117 vertically from -0.3 up to 1.8, with corners formed from a
118 circle of diameter 0 (ie sharp corners)."
122 (define-markup-command (rotate layout props ang arg) (number? markup?)
123 "Rotate object with @var{ang} degrees around its center."
124 (let* ((stil (interpret-markup layout props arg)))
125 (ly:stencil-rotate stil ang 0 0)))
128 (define-markup-command (whiteout layout props arg) (markup?)
129 "Provide a white underground for @var{arg}"
130 (let* ((stil (interpret-markup layout props arg))
132 (interpret-markup layout props
133 (make-with-color-markup
135 (make-filled-box-markup
136 (ly:stencil-extent stil X)
137 (ly:stencil-extent stil Y)
140 (ly:stencil-add white stil)))
142 (define-markup-command (pad-markup layout props padding arg) (number? markup?)
143 "Add space around a markup object."
146 ((stil (interpret-markup layout props arg))
147 (xext (ly:stencil-extent stil X))
148 (yext (ly:stencil-extent stil Y)))
151 (ly:stencil-expr stil)
152 (interval-widen xext padding)
153 (interval-widen yext padding))))
155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
159 ;;FIXME: is this working?
160 (define-markup-command (strut layout props) ()
161 "Create a box of the same height as the space in the current font."
162 (let ((m (ly:text-interface::interpret-markup layout props " ")))
163 (ly:make-stencil (ly:stencil-expr m)
165 (ly:stencil-extent m X)
169 ;; todo: fix negative space
170 (define-markup-command (hspace layout props amount) (number?)
171 "This produces a invisible object taking horizontal space.
173 \\markup @{ A \\hspace #2.0 B @}
175 will put extra space between A and B, on top of the space that is
176 normally inserted before elements on a line.
179 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
180 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
184 ;; importing graphics.
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 (define-markup-command (stencil layout props stil) (ly:stencil?)
192 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
194 (define (get-postscript-bbox string)
195 "Extract the bbox from STRING, or return #f if not present."
197 ((match (regexp-exec bbox-regexp string)))
201 (string->number (match:substring match x)))
206 (define-markup-command (epsfile layout props axis size file-name) (number? number? string?)
207 "Inline an EPS image. The image is scaled along @var{axis} to
210 (if (ly:get-option 'safe)
211 (interpret-markup layout props "not allowed in safe")
212 (eps-file->stencil axis size file-name)
215 (define-markup-command (postscript layout props str) (string?)
216 "This inserts @var{str} directly into the output as a PostScript
217 command string. Due to technicalities of the output backends,
218 different scales should be used for the @TeX{} and PostScript backend,
219 selected with @code{-f}.
222 For the TeX backend, the following string prints a rotated text
227 0 0 moveto /ecrm10 findfont
228 1.75 scalefont setfont 90 rotate (hello) show
232 The magical constant 1.75 scales from LilyPond units (staff spaces) to
235 For the postscript backend, use the following
238 gsave /ecrm10 findfont
239 10.0 output-scale div
240 scalefont setfont 90 rotate (hello) show grestore
248 gsave currentpoint translate
257 (define-markup-command (score layout props score) (ly:score?)
258 "Inline an image of music."
259 (let* ((output (ly:score-embedded-format score layout)))
261 (if (ly:music-output? output)
262 (paper-system-stencil
263 (vector-ref (ly:paper-score-paper-systems output) 0))
265 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
268 (define-markup-command (null layout props) ()
269 "An empty markup with extents of a single point"
273 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
279 (define-markup-command (simple layout props str) (string?)
280 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
281 @code{\\markup @{ \\simple #\"foo\" @}}."
282 (interpret-markup layout props str))
284 (define-markup-command (tied-lyric layout props str) (string?)
286 "Like simple-markup, but use tie characters for ~ tilde symbols."
288 (if (string-contains str "~")
290 ((parts (string-split str #\~))
291 (tie-str (ly:wide-char->utf-8 #x203f))
292 (joined (list-join parts tie-str))
293 (join-stencil (interpret-markup layout props tie-str))
296 (interpret-markup layout
299 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
301 (make-line-markup joined)))
302 ;(map (lambda (s) (interpret-markup layout props s)) parts))
303 (interpret-markup layout props str)))
306 ;; TODO: use font recoding.
308 ;; (map make-word-markup (string-tokenize str)))))
310 (define-public empty-markup
311 (make-simple-markup ""))
313 ;; helper for justifying lines.
314 (define (get-fill-space word-count line-width text-widths)
315 "Calculate the necessary paddings between each two adjacent texts.
316 The lengths of all texts are stored in @var{text-widths}.
317 The normal formula for the padding between texts a and b is:
318 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
319 The first and last padding have to be calculated specially using the
320 whole length of the first or last text.
321 Return a list of paddings.
324 ((null? text-widths) '())
326 ;; special case first padding
327 ((= (length text-widths) word-count)
329 (- (- (/ line-width (1- word-count)) (car text-widths))
330 (/ (car (cdr text-widths)) 2))
331 (get-fill-space word-count line-width (cdr text-widths))))
332 ;; special case last padding
333 ((= (length text-widths) 2)
334 (list (- (/ line-width (1- word-count))
335 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
338 (- (/ line-width (1- word-count))
339 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
340 (get-fill-space word-count line-width (cdr text-widths))))))
342 (define-markup-command (fill-line layout props markups)
344 "Put @var{markups} in a horizontal line of width @var{line-width}.
345 The markups are spaced/flushed to fill the entire line.
346 If there are no arguments, return an empty stencil."
348 (let* ((orig-stencils
349 (map (lambda (x) (interpret-markup layout props x))
353 (if (ly:stencil-empty? stc)
355 stc)) orig-stencils))
358 (if (ly:stencil-empty? stc)
360 (interval-length (ly:stencil-extent stc X))))
362 (text-width (apply + text-widths))
363 (text-dir (chain-assoc-get 'text-direction props RIGHT))
364 (word-count (length stencils))
365 (word-space (chain-assoc-get 'word-space props 1))
366 (prop-line-width (chain-assoc-get 'line-width props #f))
367 (line-width (if prop-line-width prop-line-width
368 (ly:output-def-lookup layout 'line-width)))
373 (/ (- line-width text-width) 2)
374 (/ (- line-width text-width) 2)))
377 (- line-width text-width)))
379 (get-fill-space word-count line-width text-widths))))
387 (line-stencils (if (= word-count 1)
394 (if (= text-dir LEFT)
395 (set! line-stencils (reverse line-stencils)))
397 (if (null? (remove ly:stencil-empty? orig-stencils))
399 (stack-stencils-padding-list X
400 RIGHT fill-space-normal line-stencils))))
402 (define-markup-command (line layout props args) (markup-list?)
403 "Put @var{args} in a horizontal line. The property @code{word-space}
404 determines the space between each markup in @var{args}."
406 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
407 (space (chain-assoc-get 'word-space props))
408 (text-dir (chain-assoc-get 'text-direction props RIGHT))
411 (if (= text-dir LEFT)
412 (set! stencils (reverse stencils)))
417 (remove ly:stencil-empty? stencils))))
420 (define (wordwrap-stencils stencils
421 justify base-space line-width text-dir)
423 "Perform simple wordwrap, return stencil of each line."
425 (define space (if justify
427 ;; justify only stretches lines.
431 (define (take-list width space stencils
432 accumulator accumulated-width)
433 "Return (head-list . tail) pair, with head-list fitting into width"
435 (cons accumulator stencils)
437 ((first (car stencils))
438 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
439 (newwid (+ space first-wid accumulated-width))
443 (or (null? accumulator)
446 (take-list width space
448 (cons first accumulator)
450 (cons accumulator stencils))
458 ((line-break (take-list line-width space todo
460 (line-stencils (car line-break))
461 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
464 (line-word-space (cond
465 ((not justify) space)
467 ;; don't stretch last line of paragraph.
468 ;; hmmm . bug - will overstretch the last line in some case.
469 ((null? (cdr line-break))
471 ((null? line-stencils) 0.0)
472 ((null? (cdr line-stencils)) 0.0)
473 (else (/ space-left (1- (length line-stencils))))))
475 (line (stack-stencil-line
477 (if (= text-dir RIGHT)
478 (reverse line-stencils)
481 (if (pair? (cdr line-break))
482 (loop (cons line lines)
486 (if (= text-dir LEFT)
488 (ly:stencil-translate-axis line
489 (- line-width (interval-end (ly:stencil-extent line X)))
491 (reverse (cons line lines))
498 (define (wordwrap-markups layout props args justify)
500 ((baseline-skip (chain-assoc-get 'baseline-skip props))
501 (prop-line-width (chain-assoc-get 'line-width props #f))
502 (line-width (if prop-line-width prop-line-width
503 (ly:output-def-lookup layout 'line-width)))
504 (word-space (chain-assoc-get 'word-space props))
505 (text-dir (chain-assoc-get 'text-direction props RIGHT))
506 (lines (wordwrap-stencils
507 (remove ly:stencil-empty?
508 (map (lambda (m) (interpret-markup layout props m)) args))
509 justify word-space line-width
513 (stack-lines DOWN 0.0 baseline-skip lines)))
515 (define-markup-command (justify layout props args) (markup-list?)
516 "Like wordwrap, but with lines stretched to justify the margins.
517 Use @code{\\override #'(line-width . X)} to set line-width, where X
518 is the number of staff spaces."
520 (wordwrap-markups layout props args #t))
522 (define-markup-command (wordwrap layout props args) (markup-list?)
523 "Simple wordwrap. Use @code{\\override #'(line-width . X)} to set
524 line-width, where X is the number of staff spaces."
526 (wordwrap-markups layout props args #f))
528 (define (wordwrap-string layout props justify arg)
530 ((baseline-skip (chain-assoc-get 'baseline-skip props))
531 (line-width (chain-assoc-get 'line-width props))
532 (word-space (chain-assoc-get 'word-space props))
534 (para-strings (regexp-split
535 (string-regexp-substitute "\r" "\n"
536 (string-regexp-substitute "\r\n" "\n" arg))
537 "\n[ \t\n]*\n[ \t\n]*"))
539 (text-dir (chain-assoc-get 'text-direction props RIGHT))
540 (list-para-words (map (lambda (str)
541 (regexp-split str "[ \t\n]+"))
543 (para-lines (map (lambda (words)
547 ly:stencil-empty? (map
549 (interpret-markup layout props x))
551 (lines (wordwrap-stencils stencils
560 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
563 (define-markup-command (wordwrap-string layout props arg) (string?)
564 "Wordwrap a string. Paragraphs may be separated with double newlines"
565 (wordwrap-string layout props #f arg))
567 (define-markup-command (justify-string layout props arg) (string?)
568 "Justify a string. Paragraphs may be separated with double newlines"
569 (wordwrap-string layout props #t arg))
572 (define-markup-command (wordwrap-field layout props symbol) (symbol?)
573 (let* ((m (chain-assoc-get symbol props)))
575 (interpret-markup layout props
576 (list wordwrap-string-markup m))
577 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
579 (define-markup-command (justify-field layout props symbol) (symbol?)
580 - (let* ((m (chain-assoc-get symbol props)))
582 (interpret-markup layout props
583 (list justify-string-markup m))
584 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
588 (define-markup-command (combine layout props m1 m2) (markup? markup?)
589 "Print two markups on top of each other."
590 (let* ((s1 (interpret-markup layout props m1))
591 (s2 (interpret-markup layout props m2)))
592 (ly:stencil-add s1 s2)))
595 ;; TODO: should extract baseline-skip from each argument somehow..
597 (define-markup-command (column layout props args) (markup-list?)
598 "Stack the markups in @var{args} vertically. The property
599 @code{baseline-skip} determines the space between each markup in @var{args}."
602 ((arg-stencils (map (lambda (m) (interpret-markup layout props m)) args))
603 (skip (chain-assoc-get 'baseline-skip props)))
608 (remove ly:stencil-empty? arg-stencils))))
611 (define-markup-command (dir-column layout props args) (markup-list?)
612 "Make a column of args, going up or down, depending on the setting
613 of the @code{#'direction} layout property."
614 (let* ((dir (chain-assoc-get 'direction props)))
616 (if (number? dir) dir -1)
618 (chain-assoc-get 'baseline-skip props)
619 (map (lambda (x) (interpret-markup layout props x)) args))))
621 (define-markup-command (center-align layout props args) (markup-list?)
622 "Put @code{args} in a centered column. "
623 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
624 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
626 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
628 (define-markup-command (vcenter layout props arg) (markup?)
629 "Align @code{arg} to its Y center. "
630 (let* ((mol (interpret-markup layout props arg)))
631 (ly:stencil-aligned-to mol Y CENTER)))
633 (define-markup-command (hcenter layout props arg) (markup?)
634 "Align @code{arg} to its X center. "
635 (let* ((mol (interpret-markup layout props arg)))
636 (ly:stencil-aligned-to mol X CENTER)))
638 (define-markup-command (right-align layout props arg) (markup?)
639 "Align @var{arg} on its right edge. "
640 (let* ((m (interpret-markup layout props arg)))
641 (ly:stencil-aligned-to m X RIGHT)))
643 (define-markup-command (left-align layout props arg) (markup?)
644 "Align @var{arg} on its left edge. "
645 (let* ((m (interpret-markup layout props arg)))
646 (ly:stencil-aligned-to m X LEFT)))
648 (define-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
649 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
650 (let* ((m (interpret-markup layout props arg)))
651 (ly:stencil-aligned-to m axis dir)))
653 (define-markup-command (halign layout props dir arg) (number? markup?)
654 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
655 left-aligned, while @code{+1} is right. Values in between interpolate
656 alignment accordingly."
657 (let* ((m (interpret-markup layout props arg)))
658 (ly:stencil-aligned-to m X dir)))
662 (define-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
663 "Set the dimensions of @var{arg} to @var{x} and @var{y}."
665 (let* ((m (interpret-markup layout props arg)))
666 (ly:make-stencil (ly:stencil-expr m) x y)))
669 (define-markup-command (pad-around layout props amount arg) (number? markup?)
671 "Add padding @var{amount} all around @var{arg}. "
674 ((m (interpret-markup layout props arg))
675 (x (ly:stencil-extent m X))
676 (y (ly:stencil-extent m Y)))
679 (ly:make-stencil (ly:stencil-expr m)
680 (interval-widen x amount)
681 (interval-widen y amount))
685 (define-markup-command (pad-x layout props amount arg) (number? markup?)
687 "Add padding @var{amount} around @var{arg} in the X-direction. "
689 ((m (interpret-markup layout props arg))
690 (x (ly:stencil-extent m X))
691 (y (ly:stencil-extent m Y)))
694 (ly:make-stencil (ly:stencil-expr m)
695 (interval-widen x amount)
700 (define-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
702 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}. "
704 (let* ((m1 (interpret-markup layout props arg1))
705 (m2 (interpret-markup layout props arg2)))
707 (ly:stencil-combine-at-edge m1 axis dir m2 0.0 0.0)
710 (define-markup-command (transparent layout props arg) (markup?)
711 "Make the argument transparent"
713 ((m (interpret-markup layout props arg))
714 (x (ly:stencil-extent m X))
715 (y (ly:stencil-extent m Y)))
723 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
724 (number-pair? number-pair? markup?)
725 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space"
728 ((m (interpret-markup layout props arg))
729 (x (ly:stencil-extent m X))
730 (y (ly:stencil-extent m Y)))
732 (ly:make-stencil (ly:stencil-expr m)
733 (interval-union x-ext x)
734 (interval-union y-ext y))))
737 (define-markup-command (hcenter-in layout props length arg)
739 "Center @var{arg} horizontally within a box of extending
740 @var{length}/2 to the left and right."
742 (interpret-markup layout props
743 (make-pad-to-box-markup
744 (cons (/ length -2) (/ length 2))
746 (make-hcenter-markup arg))))
749 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
751 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
753 (define-markup-command (fromproperty layout props symbol) (symbol?)
754 "Read the @var{symbol} from property settings, and produce a stencil
755 from the markup contained within. If @var{symbol} is not defined, it
756 returns an empty markup"
757 (let* ((m (chain-assoc-get symbol props)))
759 (interpret-markup layout props m)
760 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
763 (define-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
764 "Apply the @var{procedure} markup command to
765 @var{arg}. @var{procedure} should take a single argument."
766 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
767 (set-object-property! anonymous-with-signature
770 (interpret-markup layout props (list anonymous-with-signature arg))))
774 (define-markup-command (override layout props new-prop arg) (pair? markup?)
775 "Add the first argument in to the property list. Properties may be
776 any sort of property supported by @internalsref{font-interface} and
777 @internalsref{text-interface}, for example
780 \\override #'(font-family . married) \"bla\"
784 (interpret-markup layout (cons (list new-prop) props) arg))
786 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
790 (define-markup-command (verbatim-file layout props name) (string?)
791 "Read the contents of a file, and include verbatimly"
795 (if (ly:get-option 'safe)
796 "verbatim-file disabled in safe mode"
798 ((str (ly:gulp-file name))
799 (lines (string-split str #\nl)))
801 (make-typewriter-markup
802 (make-column-markup lines)))
805 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
810 (define-markup-command (bigger layout props arg) (markup?)
811 "Increase the font size relative to current setting"
812 (interpret-markup layout props
813 `(,fontsize-markup 1 ,arg)))
815 (define-markup-command (smaller layout props arg) (markup?)
816 "Decrease the font size relative to current setting"
817 (interpret-markup layout props
818 `(,fontsize-markup -1 ,arg)))
820 (define-markup-command larger (markup?) bigger-markup)
822 (define-markup-command (finger layout props arg) (markup?)
823 "Set the argument as small numbers."
824 (interpret-markup layout
825 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
829 (define-markup-command (fontsize layout props increment arg) (number? markup?)
830 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
832 (let* ((fs (chain-assoc-get 'font-size props 0))
833 (bs (chain-assoc-get 'baseline-skip props 2))
835 (cons 'baseline-skip (* bs (magstep increment)))
836 (cons 'font-size (+ fs increment )))))
838 (interpret-markup layout (cons entries props) arg)))
842 ;; FIXME -> should convert to font-size.
843 (define-markup-command (magnify layout props sz arg) (number? markup?)
844 "Set the font magnification for the its argument. In the following
845 example, the middle A will be 10% larger:
847 A \\magnify #1.1 @{ A @} A
850 Note: magnification only works if a font-name is explicitly selected.
851 Use @code{\\fontsize} otherwise."
854 (prepend-alist-chain 'font-magnification sz props)
857 (define-markup-command (bold layout props arg) (markup?)
858 "Switch to bold font-series"
859 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
861 (define-markup-command (sans layout props arg) (markup?)
862 "Switch to the sans serif family"
863 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
865 (define-markup-command (number layout props arg) (markup?)
866 "Set font family to @code{number}, which yields the font used for
867 time signatures and fingerings. This font only contains numbers and
868 some punctuation. It doesn't have any letters. "
869 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
871 (define-markup-command (roman layout props arg) (markup?)
872 "Set font family to @code{roman}."
873 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
875 (define-markup-command (huge layout props arg) (markup?)
876 "Set font size to +2."
877 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
879 (define-markup-command (large layout props arg) (markup?)
880 "Set font size to +1."
881 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
883 (define-markup-command (normalsize layout props arg) (markup?)
884 "Set font size to default."
885 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
887 (define-markup-command (small layout props arg) (markup?)
888 "Set font size to -1."
889 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
891 (define-markup-command (tiny layout props arg) (markup?)
892 "Set font size to -2."
893 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
895 (define-markup-command (teeny layout props arg) (markup?)
896 "Set font size to -3."
897 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
899 (define-markup-command (fontCaps layout props arg) (markup?)
900 "Set @code{font-shape} to @code{caps}."
901 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
904 (define-markup-command (smallCaps layout props text) (markup?)
905 "Turn @code{text}, which should be a string, to small caps.
907 \\markup \\smallCaps \"Text between double quotes\"
910 (define (make-small-caps-markup chars)
913 ((char-whitespace? (car chars))
914 (markup #:fontsize -2 #:simple (string-upcase (list->string (cdr chars)))))
917 #:fontsize -2 #:simple (string-upcase (list->string chars))))))
918 (define (make-not-small-caps-markup chars)
921 ((char-whitespace? (car chars))
922 (markup #:simple (list->string (cdr chars))))
925 #:simple (list->string chars)))))
926 (define (small-caps-aux done-markups current-chars rest-chars small? after-space?)
927 (cond ((null? rest-chars)
928 ;; the end of the string: build the markup
929 (make-line-markup (reverse! (cons ((if small?
930 make-small-caps-markup
931 make-not-small-caps-markup)
932 (reverse! current-chars))
934 ((char-whitespace? (car rest-chars))
936 (small-caps-aux done-markups current-chars (cdr rest-chars) small? #t))
937 ((or (and small? (char-lower-case? (car rest-chars)))
938 (and (not small?) (not (char-lower-case? (car rest-chars)))))
940 ;; add the char to the current char list
941 (small-caps-aux done-markups
942 (cons (car rest-chars)
944 (cons #\space current-chars)
951 ;; make a markup with current chars, and start a new list with new char
952 (small-caps-aux (cons ((if small?
953 make-small-caps-markup
954 make-not-small-caps-markup)
955 (reverse! current-chars))
958 (list (car rest-chars) #\space)
959 (list (car rest-chars)))
963 (interpret-markup layout props (small-caps-aux (list)
965 (cons #\space (string->list text))
969 (define-markup-command (caps layout props arg) (markup?)
970 (interpret-markup layout props (make-smallCaps-markup arg)))
972 (define-markup-command (dynamic layout props arg) (markup?)
973 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
974 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
975 normal words (like ``pi@`{u}'') should be done in a different font. The
976 recommend font for this is bold and italic"
978 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
980 (define-markup-command (text layout props arg) (markup?)
981 "Use a text font instead of music symbol or music alphabet font."
984 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
988 (define-markup-command (italic layout props arg) (markup?)
989 "Use italic @code{font-shape} for @var{arg}. "
990 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
992 (define-markup-command (typewriter layout props arg) (markup?)
993 "Use @code{font-family} typewriter for @var{arg}."
995 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
997 (define-markup-command (upright layout props arg) (markup?)
998 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1000 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1002 (define-markup-command (medium layout props arg) (markup?)
1003 "Switch to medium font-series (in contrast to bold)."
1004 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1007 (define-markup-command (normal-text layout props arg) (markup?)
1008 "Set all font related properties (except the size) to get the default normal text font, no matter what font was used earlier."
1010 (interpret-markup layout
1011 (cons '((font-family . roman) (font-shape . upright)
1012 (font-series . medium) (font-encoding . latin1))
1016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1020 (define-markup-command (doublesharp layout props) ()
1021 "Draw a double sharp symbol."
1023 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
1025 (define-markup-command (sesquisharp layout props) ()
1026 "Draw a 3/2 sharp symbol."
1027 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
1029 (define-markup-command (sharp layout props) ()
1030 "Draw a sharp symbol."
1031 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
1033 (define-markup-command (semisharp layout props) ()
1034 "Draw a semi sharp symbol."
1035 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
1037 (define-markup-command (natural layout props) ()
1038 "Draw a natural symbol."
1039 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
1041 (define-markup-command (semiflat layout props) ()
1043 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
1045 (define-markup-command (flat layout props) ()
1046 "Draw a flat symbol."
1047 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
1049 (define-markup-command (sesquiflat layout props) ()
1050 "Draw a 3/2 flat symbol."
1051 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
1053 (define-markup-command (doubleflat layout props) ()
1054 "Draw a double flat symbol."
1055 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
1057 (define-markup-command (with-color layout props color arg) (color? markup?)
1058 "Draw @var{arg} in color specified by @var{color}"
1060 (let* ((stil (interpret-markup layout props arg)))
1062 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1063 (ly:stencil-extent stil X)
1064 (ly:stencil-extent stil Y))))
1067 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1072 (define-markup-command (arrow-head layout props axis direction filled)
1073 (integer? ly:dir? boolean?)
1074 "produce an arrow head in specified direction and axis. Use the filled head if @var{filled} is specified."
1076 ((name (format "arrowheads.~a.~a~a"
1083 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1087 (define-markup-command (musicglyph layout props glyph-name) (string?)
1088 "This is converted to a musical symbol, e.g. @code{\\musicglyph
1089 #\"accidentals.0\"} will select the natural sign from the music font.
1090 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
1092 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1096 (define-markup-command (lookup layout props glyph-name) (string?)
1097 "Lookup a glyph by name."
1098 (ly:font-get-glyph (ly:paper-get-font layout props)
1101 (define-markup-command (char layout props num) (integer?)
1102 "Produce a single character, e.g. @code{\\char #65} produces the
1105 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1107 (define number->mark-letter-vector (make-vector 25 #\A))
1112 (if (= i (- (char->integer #\I) (char->integer #\A)))
1114 (vector-set! number->mark-letter-vector j
1115 (integer->char (+ i (char->integer #\A)))))
1117 (define number->mark-alphabet-vector (list->vector
1118 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1120 (define (number->markletter-string vec n)
1121 "Double letters for big marks."
1122 (let* ((lst (vector-length vec)))
1125 (string-append (number->markletter-string vec (1- (quotient n lst)))
1126 (number->markletter-string vec (remainder n lst)))
1127 (make-string 1 (vector-ref vec n)))))
1129 (define-markup-command (markletter layout props num) (integer?)
1130 "Make a markup letter for @var{num}. The letters start with A to Z
1131 (skipping I), and continues with double letters."
1132 (ly:text-interface::interpret-markup layout props
1133 (number->markletter-string number->mark-letter-vector num)))
1135 (define-markup-command (markalphabet layout props num) (integer?)
1136 "Make a markup letter for @var{num}. The letters start with A to Z
1137 and continues with double letters."
1138 (ly:text-interface::interpret-markup layout props
1139 (number->markletter-string number->mark-alphabet-vector num)))
1143 (define-markup-command (slashed-digit layout props num) (integer?)
1144 "A feta number, with slash. This is for use in the context of
1145 figured bass notation"
1147 ((mag (magstep (chain-assoc-get 'font-size props 0)))
1150 (chain-assoc-get 'thickness props 0.16)))
1152 (number-stencil (interpret-markup layout
1153 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1154 (number->string num)))
1155 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1157 (num-y (ly:stencil-extent number-stencil Y))
1162 ,(car num-x) ,(- (interval-center num-y) dy)
1163 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1167 (ly:stencil-add number-stencil
1169 ((= num 5) (ly:stencil-translate slash-stencil
1170 ;;(cons (* mag -0.05) (* mag 0.42))
1171 (cons (* mag -0.00) (* mag -0.07))
1174 ((= num 7) (ly:stencil-translate slash-stencil
1175 ;;(cons (* mag -0.05) (* mag 0.42))
1176 (cons (* mag -0.00) (* mag -0.15))
1180 (else slash-stencil)))
1183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1184 ;; the note command.
1185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1188 ;; TODO: better syntax.
1190 (define-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1191 "Construct a note symbol, with stem. By using fractional values for
1192 @var{dir}, you can obtain longer or shorter stems."
1193 (define (get-glyph-name-candidates dir log style)
1194 (map (lambda (dir-name)
1195 (format "noteheads.~a~a~a" dir-name (min log 2)
1196 (if (and (symbol? style)
1197 (not (equal? 'default style)))
1198 (symbol->string style)
1200 (list (if (= dir UP) "u" "d")
1203 (define (get-glyph-name font cands)
1206 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1207 (get-glyph-name font (cdr cands))
1210 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1211 (size-factor (magstep (chain-assoc-get 'font-size props 0)))
1212 (style (chain-assoc-get 'style props '()))
1213 (stem-length (* size-factor (max 3 (- log 1))))
1214 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates dir log style)))
1215 (head-glyph (ly:font-get-glyph font head-glyph-name))
1216 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1217 (stem-thickness (* size-factor 0.13))
1218 (stemy (* dir stem-length))
1219 (attach-off (cons (interval-index
1220 (ly:stencil-extent head-glyph X)
1221 (* dir (car attach-indices)))
1222 (* dir ; fixme, this is inconsistent between X & Y.
1224 (ly:stencil-extent head-glyph Y)
1225 (cdr attach-indices)))))
1226 (stem-glyph (and (> log 0)
1227 (ly:round-filled-box
1228 (ordered-cons (car attach-off)
1229 (+ (car attach-off) (* (- dir) stem-thickness)))
1230 (cons (min stemy (cdr attach-off))
1231 (max stemy (cdr attach-off)))
1232 (/ stem-thickness 3))))
1234 (dot (ly:font-get-glyph font "dots.dot"))
1235 (dotwid (interval-length (ly:stencil-extent dot X)))
1236 (dots (and (> dot-count 0)
1237 (apply ly:stencil-add
1239 (ly:stencil-translate-axis
1240 dot (* (+ 1 (* 2 x)) dotwid) X))
1241 (iota dot-count 1)))))
1242 (flaggl (and (> log 2)
1243 (ly:stencil-translate
1244 (ly:font-get-glyph font
1245 (string-append "flags."
1246 (if (> dir 0) "u" "d")
1247 (number->string log)))
1248 (cons (+ (car attach-off) (/ stem-thickness 2)) stemy)))))
1250 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1251 (if (ly:stencil? stem-glyph)
1252 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1253 (set! stem-glyph head-glyph))
1254 (if (ly:stencil? dots)
1257 (ly:stencil-translate-axis
1259 (+ (if (and (> dir 0) (> log 2))
1262 ;; huh ? why not necessary?
1263 ;;(cdr (ly:stencil-extent head-glyph X))
1270 (let ((divisor (log 2)))
1271 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1273 (define (parse-simple-duration duration-string)
1274 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1275 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1276 (if (and match (string=? duration-string (match:substring match 0)))
1277 (let ((len (match:substring match 1))
1278 (dots (match:substring match 2)))
1279 (list (cond ((string=? len "breve") -1)
1280 ((string=? len "longa") -2)
1281 ((string=? len "maxima") -3)
1282 (else (log2 (string->number len))))
1283 (if dots (string-length dots) 0)))
1284 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1286 (define-markup-command (note layout props duration dir) (string? number?)
1287 "This produces a note with a stem pointing in @var{dir} direction, with
1288 the @var{duration} for the note head type and augmentation dots. For
1289 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1290 a shortened down stem."
1291 (let ((parsed (parse-simple-duration duration)))
1292 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1299 (define-markup-command (lower layout props amount arg) (number? markup?)
1301 Lower @var{arg}, by the distance @var{amount}.
1302 A negative @var{amount} indicates raising, see also @code{\\raise}.
1304 (ly:stencil-translate-axis (interpret-markup layout props arg)
1308 (define-markup-command (translate-scaled layout props offset arg) (number-pair? markup?)
1309 "Translate @var{arg} by @var{offset}, scaling the offset by the @code{font-size}."
1312 ((factor (magstep (chain-assoc-get 'font-size props 0)))
1313 (scaled (cons (* factor (car offset))
1314 (* factor (cdr offset)))))
1316 (ly:stencil-translate (interpret-markup layout props arg)
1319 (define-markup-command (raise layout props amount arg) (number? markup?)
1321 Raise @var{arg}, by the distance @var{amount}.
1322 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1324 @lilypond[verbatim,fragment,relative=1]
1325 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
1327 The argument to @code{\\raise} is the vertical displacement amount,
1328 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1329 raise objects in relation to their surrounding markups.
1331 If the text object itself is positioned above or below the staff, then
1332 @code{\\raise} cannot be used to move it, since the mechanism that
1333 positions it next to the staff cancels any shift made with
1334 @code{\\raise}. For vertical positioning, use the @code{padding}
1335 and/or @code{extra-offset} properties. "
1336 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1338 (define-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1339 "Make a fraction of two markups."
1340 (let* ((m1 (interpret-markup layout props arg1))
1341 (m2 (interpret-markup layout props arg2)))
1342 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1343 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1344 (let* ((x1 (ly:stencil-extent m1 X))
1345 (x2 (ly:stencil-extent m2 X))
1346 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
1347 ;; should stack mols separately, to maintain LINE on baseline
1348 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
1350 (ly:stencil-aligned-to stack Y CENTER))
1352 (ly:stencil-aligned-to stack X LEFT))
1353 ;; should have EX dimension
1355 (ly:stencil-translate-axis stack 0.75 Y))))
1361 (define-markup-command (normal-size-super layout props arg) (markup?)
1362 "Set @var{arg} in superscript with a normal font size."
1363 (ly:stencil-translate-axis
1364 (interpret-markup layout props arg)
1365 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1367 (define-markup-command (super layout props arg) (markup?)
1369 @cindex raising text
1370 @cindex lowering text
1372 @cindex translating text
1374 @cindex @code{\\super}
1377 Raising and lowering texts can be done with @code{\\super} and
1380 @lilypond[verbatim,fragment,relative=1]
1381 c1^\\markup { E \"=\" mc \\super \"2\" }
1385 (ly:stencil-translate-axis
1388 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1390 (* 0.5 (chain-assoc-get 'baseline-skip props))
1393 (define-markup-command (translate layout props offset arg) (number-pair? markup?)
1394 "This translates an object. Its first argument is a cons of numbers
1396 A \\translate #(cons 2 -3) @{ B C @} D
1398 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1399 surroundings. This command cannot be used to move isolated scripts
1400 vertically, for the same reason that @code{\\raise} cannot be used for
1404 (ly:stencil-translate (interpret-markup layout props arg)
1407 (define-markup-command (sub layout props arg) (markup?)
1408 "Set @var{arg} in subscript."
1409 (ly:stencil-translate-axis
1412 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1414 (* -0.5 (chain-assoc-get 'baseline-skip props))
1417 (define-markup-command (normal-size-sub layout props arg) (markup?)
1418 "Set @var{arg} in subscript, in a normal font size."
1419 (ly:stencil-translate-axis
1420 (interpret-markup layout props arg)
1421 (* -0.5 (chain-assoc-get 'baseline-skip props))
1424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1426 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1428 (define-markup-command (hbracket layout props arg) (markup?)
1429 "Draw horizontal brackets around @var{arg}."
1430 (let ((th 0.1) ;; todo: take from GROB.
1431 (m (interpret-markup layout props arg)))
1432 (bracketify-stencil m X th (* 2.5 th) th)))
1434 (define-markup-command (bracket layout props arg) (markup?)
1435 "Draw vertical brackets around @var{arg}."
1436 (let ((th 0.1) ;; todo: take from GROB.
1437 (m (interpret-markup layout props arg)))
1438 (bracketify-stencil m Y th (* 2.5 th) th)))
1440 (define-markup-command (bracketed-y-column layout props indices args)
1441 (list? markup-list?)
1442 "Make a column of the markups in @var{args}, putting brackets around
1443 the elements marked in @var{indices}, which is a list of numbers.
1447 ;; DROPME? This command is a relic from the old figured bass implementation.
1450 (define (sublist lst start stop)
1451 (take (drop lst start) (- (1+ stop) start)))
1453 (define (stencil-list-extent ss axis)
1455 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1456 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1459 (define (stack-stencils-vertically stencils bskip last-stencil)
1461 ((null? stencils) '())
1462 ((not (ly:stencil? last-stencil))
1463 (cons (car stencils)
1464 (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1466 (let* ((orig (car stencils))
1467 (dir (chain-assoc-get 'direction props DOWN))
1468 (new (ly:stencil-moved-to-edge last-stencil Y dir
1472 (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1474 (define (make-brackets stencils indices acc)
1477 (pair? (cdr indices)))
1478 (let* ((encl (sublist stencils (car indices) (cadr indices)))
1479 (x-ext (stencil-list-extent encl X))
1480 (y-ext (stencil-list-extent encl Y))
1483 (protusion (* 2.5 thick))
1485 (ly:stencil-translate-axis
1486 (ly:bracket Y y-ext thick protusion)
1487 (- (car x-ext) pad) X))
1488 (rb (ly:stencil-translate-axis
1489 (ly:bracket Y y-ext thick (- protusion))
1490 (+ (cdr x-ext) pad) X)))
1493 stencils (cddr indices)
1506 (chain-assoc-get 'baseline-skip props))
1507 (stacked (stack-stencils-vertically
1508 (remove ly:stencil-empty? stencils) 1.25 #f))
1509 (brackets (make-brackets stacked indices '())))
1511 (apply ly:stencil-add
1512 (append stacked brackets))))
1515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1516 ;; size indications arrow
1517 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;