]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
* scm/parser-ly-from-scheme.scm: rename from ly-from-scheme.scm
[lilypond.git] / scm / define-markup-commands.scm
1 ;;;; define-markup-commands.scm -- markup commands
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 2000--2005  Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;;                  Jan Nieuwenhuizen <janneke@gnu.org>
7
8
9 ;;; markup commands
10 ;;;  * each markup function should have a doc string with
11 ;;     syntax, description and example. 
12
13 (use-modules (ice-9 regex))
14
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;; utility functions
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
18
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
21
22
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;; geometric shapes
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26
27 (def-markup-command (draw-circle layout props radius thickness fill)
28   (number? number? boolean?)
29   "A circle of radius @var{radius}, thickness @var{thickness} and
30 optionally filled."
31   (make-circle-stencil radius thickness fill))
32
33 (def-markup-command (triangle layout props filled) (boolean?)
34   "A triangle, filled or not"
35   (let*
36       ((th (chain-assoc-get 'thickness props  0.1))
37        (size (chain-assoc-get 'font-size props 0))
38        (ex (* (magstep size)
39               0.8
40               (chain-assoc-get 'baseline-skip props 2))))
41
42     (ly:make-stencil
43      `(polygon '(0.0 0.0
44                      ,ex 0.0
45                      ,(* 0.5 ex)
46                      ,(* 0.86 ex))
47            ,th
48            ,filled)
49
50      (cons 0 ex)
51      (cons 0 (* .86 ex))
52      )))
53
54 (def-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."
58   (let* ((th (chain-assoc-get 'thickness props  0.1))
59          (size (chain-assoc-get 'font-size props 0))
60          (pad
61           (* (magstep size)
62              (chain-assoc-get 'circle-padding props 0.2)))
63          (m (interpret-markup layout props arg)))
64     (circle-stencil m th pad)))
65
66 (def-markup-command (with-url layout props url arg) (string? markup?)
67   "Add a link to URL @var{url} around @var{arg}. This only works in
68 the PDF backend."
69   (let* ((stil (interpret-markup layout props arg))
70          (xextent (ly:stencil-extent stil X))
71          (yextent (ly:stencil-extent stil Y))
72          (old-expr (ly:stencil-expr stil))
73          (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
74     (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
75
76
77 (def-markup-command (beam layout props width slope thickness)
78   (number? number? number?)
79   "Create a beam with the specified parameters."
80   (let* ((y (* slope width))
81          (yext (cons (min 0 y) (max 0 y)))
82          (half (/ thickness 2)))
83
84     (ly:make-stencil
85      `(polygon ',(list 
86                   0 (/ thickness -2)
87                     width (+ (* width slope)  (/ thickness -2))
88                     width (+ (* width slope)  (/ thickness 2))
89                     0 (/ thickness 2))
90                ,(ly:output-def-lookup layout 'blotdiameter)
91                #t)
92      (cons 0 width)
93      (cons (+ (- half) (car yext))
94            (+ half (cdr yext))))))
95
96 (def-markup-command (box layout props arg) (markup?)
97   "Draw a box round @var{arg}.  Looks at @code{thickness},
98 @code{box-padding} and @code{font-size} properties to determine line
99 thickness and padding around the markup."
100   (let* ((th (chain-assoc-get 'thickness props  0.1))
101          (size (chain-assoc-get 'font-size props 0))
102          (pad (* (magstep size)
103                  (chain-assoc-get 'box-padding props 0.2)))
104          (m (interpret-markup layout props arg)))
105     (box-stencil m th pad)))
106
107 (def-markup-command (filled-box layout props xext yext blot)
108   (number-pair? number-pair? number?)
109   "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
110   (ly:round-filled-box
111    xext yext blot))
112
113 (def-markup-command (whiteout layout props arg) (markup?)
114   "Provide a white underground for @var{arg}"
115   (let* ((stil (interpret-markup layout props
116                                  (make-with-color-markup black arg)))
117          (white
118           (interpret-markup layout props
119                             (make-with-color-markup
120                              white
121                              (make-filled-box-markup
122                               (ly:stencil-extent stil X)
123                               (ly:stencil-extent stil Y)
124                               0.0)))))
125
126     (ly:stencil-add white stil)))
127
128 (def-markup-command (pad-markup layout props padding arg) (number? markup?)
129   "Add space around a markup object."
130
131   (let*
132       ((stil (interpret-markup layout props arg))
133        (xext (ly:stencil-extent stil X))
134        (yext (ly:stencil-extent stil Y)))
135
136     (ly:make-stencil
137      (ly:stencil-expr stil)
138      (interval-widen xext padding)
139      (interval-widen yext padding))))
140
141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
142 ;; space
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144
145 ;;FIXME: is this working? 
146 (def-markup-command (strut layout props) ()
147   "Create a box of the same height as the space in the current font."
148   (let ((m (Text_interface::interpret_markup layout props " ")))
149     (ly:make-stencil (ly:stencil-expr m)
150                      '(1000 . -1000)
151                      (ly:stencil-extent m X)
152                      )))
153
154
155 ;; todo: fix negative space
156 (def-markup-command (hspace layout props amount) (number?)
157   "This produces a invisible object taking horizontal space.
158 @example 
159 \\markup @{ A \\hspace #2.0 B @} 
160 @end example
161 will put extra space between A and B, on top of the space that is
162 normally inserted before elements on a line.
163 "
164   (if (> amount 0)
165       (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
166       (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
167
168
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 ;; importing graphics.
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
172
173 (def-markup-command (stencil layout props stil) (ly:stencil?)
174   "Stencil as markup"
175   stil)
176
177 (define bbox-regexp
178   (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
179
180 (define (get-postscript-bbox string)
181   "Extract the bbox from STRING, or return #f if not present."
182   (let*
183       ((match (regexp-exec bbox-regexp string)))
184     
185     (if match
186         (map (lambda (x)
187                (string->number (match:substring match x)))
188              (cdr (iota 5)))
189              
190         #f)))
191
192 (def-markup-command (epsfile layout props file-name) (string?)
193   "Inline an EPS image. The image is scaled such that 10 PS units is
194 one staff-space."
195
196   (if (ly:get-option 'safe)
197       (interpret-markup layout props "not allowed in safe") 
198       (let*
199           ((contents (ly:gulp-file file-name))
200            (bbox (get-postscript-bbox contents))
201            (scaled-bbox
202             (if bbox
203                 (map (lambda (x) (/ x 10)) bbox)
204                 (begin
205                   (ly:warning (_ "can't find bounding box of `~a'")
206                            file-name)
207                   '()))))
208         
209
210         (if bbox
211             
212             (ly:make-stencil
213              (list
214               'embedded-ps
215               (string-append
216
217                ; adobe 5002.
218                "BeginEPSF "
219                "0.1 0.1 scale "
220                (format "\n%%BeginDocument: ~a\n" file-name)
221                contents
222                "%%EndDocument\n"
223                "EndEPSF\n"
224                ))
225              (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
226              (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
227             
228             (ly:make-stencil "" '(0 . 0) '(0 . 0))))))  
229
230
231 (def-markup-command (postscript layout props str) (string?)
232   "This inserts @var{str} directly into the output as a PostScript
233 command string.  Due to technicalities of the output backends,
234 different scales should be used for the @TeX{} and PostScript backend,
235 selected with @code{-f}. 
236
237
238 For the TeX backend, the following string prints a rotated text
239
240 @cindex rotated text
241
242 @verbatim
243 0 0 moveto /ecrm10 findfont 
244 1.75 scalefont setfont 90 rotate (hello) show
245 @end verbatim
246
247 @noindent
248 The magical constant 1.75 scales from LilyPond units (staff spaces) to
249 TeX dimensions.
250
251 For the postscript backend, use the following
252
253 @verbatim
254 gsave /ecrm10 findfont 
255  10.0 output-scale div 
256  scalefont setfont 90 rotate (hello) show grestore 
257 @end verbatim
258 "
259   ;; FIXME
260   (ly:make-stencil
261    (list 'embedded-ps str)
262    '(0 . 0) '(0 . 0)))
263
264
265 (def-markup-command (score layout props score) (ly:score?)
266   "Inline an image of music."
267   (let* ((output (ly:score-embedded-format score layout)))
268
269     (if (ly:music-output? output)
270         (paper-system-stencil
271          (vector-ref (ly:paper-score-paper-systems output) 0))
272         (begin
273           (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
274           empty-stencil))))
275
276 (def-markup-command (null layout props) ()
277   "An empty markup with extents of a single point"
278
279   point-stencil)
280
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
282 ;; basic formatting.
283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
284
285 (def-markup-command (simple layout props str) (string?)
286   "A simple text string; @code{\\markup @{ foo @}} is equivalent with
287 @code{\\markup @{ \\simple #\"foo\" @}}."
288   (interpret-markup layout props str))
289
290
291 ;; TODO: use font recoding.
292 ;;                    (make-line-markup
293 ;;                     (map make-word-markup (string-tokenize str)))))
294
295 (define-public empty-markup
296   (make-simple-markup ""))
297
298 ;; helper for justifying lines.
299 (define (get-fill-space word-count line-width text-widths)
300   "Calculate the necessary paddings between each two adjacent texts.
301         The lengths of all texts are stored in @var{text-widths}.
302         The normal formula for the padding between texts a and b is:
303         padding = line-width/(word-count - 1) - (length(a) + length(b))/2
304         The first and last padding have to be calculated specially using the
305         whole length of the first or last text.
306         Return a list of paddings.
307 "
308   (cond
309    ((null? text-widths) '())
310    
311    ;; special case first padding
312    ((= (length text-widths) word-count)
313     (cons 
314      (- (- (/ line-width (1- word-count)) (car text-widths))
315         (/ (car (cdr text-widths)) 2))
316      (get-fill-space word-count line-width (cdr text-widths))))
317    ;; special case last padding
318    ((= (length text-widths) 2)
319     (list (- (/ line-width (1- word-count))
320              (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
321    (else
322     (cons 
323      (- (/ line-width (1- word-count))
324         (/ (+ (car text-widths) (car (cdr text-widths))) 2))
325      (get-fill-space word-count line-width (cdr text-widths))))))
326
327 (def-markup-command (fill-line layout props markups)
328   (markup-list?)
329   "Put @var{markups} in a horizontal line of width @var{line-width}.
330    The markups are spaced/flushed to fill the entire line.
331    If there are no arguments, return an empty stencil."
332  
333   (let* ((orig-stencils
334           (map (lambda (x) (interpret-markup layout props x))
335                markups))
336          (stencils
337           (map (lambda (stc)
338                  (if (ly:stencil-empty? stc)
339                      point-stencil
340                      stc)) orig-stencils))
341          (text-widths
342           (map (lambda (stc)
343                  (if (ly:stencil-empty? stc)
344                      0.0
345                      (interval-length (ly:stencil-extent stc X))))
346                stencils))
347          (text-width (apply + text-widths))
348          (text-dir (chain-assoc-get 'text-direction props RIGHT))
349          (word-count (length stencils))
350          (word-space (chain-assoc-get 'word-space props))
351          (line-width (chain-assoc-get 'linewidth props))
352          (fill-space
353                 (cond
354                         ((= word-count 1) 
355                                 (list
356                                         (/ (- line-width text-width) 2)
357                                         (/ (- line-width text-width) 2)))
358                         ((= word-count 2)
359                                 (list
360                                         (- line-width text-width)))
361                         (else 
362                                 (get-fill-space word-count line-width text-widths))))
363          (fill-space-normal
364           (map (lambda (x)
365                  (if (< x word-space)
366                      word-space
367                      x))
368                fill-space))
369                                         
370          (line-stencils (if (= word-count 1)
371                             (list
372                              point-stencil
373                              (car stencils)
374                              point-stencil)
375                             stencils)))
376
377     (if (= text-dir LEFT)
378         (set! line-stencils (reverse line-stencils)))
379
380     (if (null? (remove ly:stencil-empty? orig-stencils))
381         empty-stencil
382         (stack-stencils-padding-list X
383                                      RIGHT fill-space-normal line-stencils))))
384         
385 (def-markup-command (line layout props args) (markup-list?)
386   "Put @var{args} in a horizontal line.  The property @code{word-space}
387 determines the space between each markup in @var{args}."
388   (let*
389       ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
390        (space    (chain-assoc-get 'word-space props))
391        (text-dir (chain-assoc-get 'text-direction props RIGHT)) 
392        )
393
394     
395     (if (= text-dir LEFT)
396         (set! stencils (reverse stencils)))
397     
398
399     (stack-stencil-line
400      space
401      (remove ly:stencil-empty? stencils))))
402
403
404 (define (wordwrap-stencils stencils
405                            justify base-space line-width text-dir)
406   
407   "Perform simple wordwrap, return stencil of each line."
408   
409   (define space (if justify
410                     
411                     ;; justify only stretches lines.
412                     (* 0.7 base-space)
413                     base-space))
414        
415   (define (take-list width space stencils
416                      accumulator accumulated-width)
417     "Return (head-list . tail) pair, with head-list fitting into width"
418     (if (null? stencils)
419         (cons accumulator stencils)
420         (let*
421             ((first (car stencils))
422              (first-wid (cdr (ly:stencil-extent (car stencils) X)))
423              (newwid (+ space first-wid accumulated-width))
424              )
425
426           (if
427            (or (null? accumulator)
428                (< newwid width))
429
430            (take-list width space
431                       (cdr stencils)
432                       (cons first accumulator)
433                       newwid)
434              (cons accumulator stencils))
435            )))
436
437     (let loop
438         ((lines '())
439          (todo stencils))
440
441       (let*
442           ((line-break (take-list line-width space todo
443                                  '() 0.0))
444            (line-stencils (car line-break))
445            (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
446                                               line-stencils))))
447
448            (line-word-space (cond
449                              ((not justify) space)
450
451                              ;; don't stretch last line of paragraph.
452                              ;; hmmm . bug - will overstretch the last line in some case. 
453                              ((null? (cdr line-break))
454                               base-space)
455                              ((null? line-stencils) 0.0)
456                              ((null? (cdr line-stencils)) 0.0)
457                              (else (/ space-left (1- (length line-stencils))))))
458
459            (line (stack-stencil-line
460                   line-word-space
461                   (if (= text-dir RIGHT)
462                       (reverse line-stencils)
463                       line-stencils))))
464
465         (if (pair? (cdr line-break))
466             (loop (cons line lines)
467                   (cdr line-break))
468
469             (begin
470               (if (= text-dir LEFT)
471                   (set! line
472                         (ly:stencil-translate-axis line
473                                                    (- line-width (interval-end (ly:stencil-extent line X)))
474                                                    X)))
475               (reverse (cons line lines))
476               
477             )))
478
479       ))
480
481
482 (define (wordwrap-markups layout props args justify)
483   (let*
484       ((baseline-skip (chain-assoc-get 'baseline-skip props))
485        (line-width (chain-assoc-get 'linewidth props))
486        (word-space (chain-assoc-get 'word-space props))
487        (text-dir (chain-assoc-get 'text-direction props RIGHT)) 
488        (lines (wordwrap-stencils
489                (remove ly:stencil-empty?
490                        (map (lambda (m) (interpret-markup layout props m)) args))
491                justify word-space line-width
492                text-dir)
493                ))
494
495     (stack-lines DOWN 0.0 baseline-skip lines)))
496
497 (def-markup-command (justify layout props args) (markup-list?)
498   "Like wordwrap, but with lines stretched to justify the margins.
499 Use @code{\\override #'(linewidth . X)} to set linewidth, where X
500 is the number of staff spaces."
501
502   (wordwrap-markups layout props args #t))
503
504 (def-markup-command (wordwrap layout props args) (markup-list?)
505   "Simple wordwrap.  Use @code{\\override #'(linewidth . X)} to set
506 linewidth, where X is the number of staff spaces."
507
508   (wordwrap-markups layout props args #f))
509
510 (define (wordwrap-string layout props justify arg) 
511   (let*
512       ((baseline-skip (chain-assoc-get 'baseline-skip props))
513        (line-width (chain-assoc-get 'linewidth props))
514        (word-space (chain-assoc-get 'word-space props))
515        (para-strings (regexp-split arg "\n[ \t\n]*\n[ \t\n]*"))
516        
517        (text-dir (chain-assoc-get 'text-direction props RIGHT)) 
518        (list-para-words (map (lambda (str)
519                                (regexp-split str "[ \t\n]+"))
520                              para-strings))
521        (para-lines (map (lambda (words)
522                           (let*
523                               ((stencils
524                                 (remove
525                                  ly:stencil-empty? (map 
526                                       (lambda (x)
527                                         (interpret-markup layout props x))
528                                       words)))
529                                (lines (wordwrap-stencils stencils
530                                                          justify word-space
531                                                          line-width text-dir
532                                                          )))
533
534                             lines))
535                         
536                         list-para-words)))
537
538     (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
539
540
541 (def-markup-command (wordwrap-string layout props arg) (string?)
542   "Wordwrap a string. Paragraphs may be separated with double newlines"
543   (wordwrap-string layout props  #f arg))
544   
545 (def-markup-command (justify-string layout props arg) (string?)
546   "Justify a string. Paragraphs may be separated with double newlines"
547   (wordwrap-string layout props #t arg))
548
549
550 (def-markup-command (wordwrap-field layout props symbol) (symbol?)
551    (let* ((m (chain-assoc-get symbol props)))
552      (if (string? m)
553       (interpret-markup layout props
554        (list wordwrap-string-markup m))
555       (ly:make-stencil '()  '(1 . -1) '(1 . -1)))))
556
557 (def-markup-command (justify-field layout props symbol) (symbol?)
558    (let* ((m (chain-assoc-get symbol props)))
559      (if (string? m)
560       (interpret-markup layout props
561        (list justify-string-markup m))
562       (ly:make-stencil '()  '(1 . -1) '(1 . -1)))))
563
564
565
566 (def-markup-command (combine layout props m1 m2) (markup? markup?)
567   "Print two markups on top of each other."
568   (let* ((s1 (interpret-markup layout props m1))
569          (s2 (interpret-markup layout props m2)))
570     (ly:stencil-add s1 s2)))
571
572 ;;
573 ;; TODO: should extract baseline-skip from each argument somehow..
574 ;; 
575 (def-markup-command (column layout props args) (markup-list?)
576   "Stack the markups in @var{args} vertically.  The property
577 @code{baseline-skip} determines the space between each markup in @var{args}."
578   (stack-lines
579    -1 0.0 (chain-assoc-get 'baseline-skip props)
580    (remove ly:stencil-empty?
581            (map (lambda (m) (interpret-markup layout props m)) args))))
582
583 (def-markup-command (dir-column layout props args) (markup-list?)
584   "Make a column of args, going up or down, depending on the setting
585 of the @code{#'direction} layout property."
586   (let* ((dir (chain-assoc-get 'direction props)))
587     (stack-lines
588      (if (number? dir) dir -1)
589      0.0
590      (chain-assoc-get 'baseline-skip props)
591      (map (lambda (x) (interpret-markup layout props x)) args))))
592
593 (def-markup-command (center-align layout props args) (markup-list?)
594   "Put @code{args} in a centered column. "
595   (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
596          (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
597     (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
598
599 (def-markup-command (vcenter layout props arg) (markup?)
600   "Align @code{arg} to its Y center. "
601   (let* ((mol (interpret-markup layout props arg)))
602     (ly:stencil-aligned-to mol Y CENTER)))
603
604 (def-markup-command (hcenter layout props arg) (markup?)
605   "Align @code{arg} to its X center. "
606   (let* ((mol (interpret-markup layout props arg)))
607     (ly:stencil-aligned-to mol X CENTER)))
608
609 (def-markup-command (right-align layout props arg) (markup?)
610   "Align @var{arg} on its right edge. "
611   (let* ((m (interpret-markup layout props arg)))
612     (ly:stencil-aligned-to m X RIGHT)))
613
614 (def-markup-command (left-align layout props arg) (markup?)
615   "Align @var{arg} on its left edge. "
616   (let* ((m (interpret-markup layout props arg)))
617     (ly:stencil-aligned-to m X LEFT)))
618
619 (def-markup-command (general-align layout props axis dir arg)  (integer? number? markup?)
620   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
621   (let* ((m (interpret-markup layout props arg)))
622     (ly:stencil-aligned-to m axis dir)))
623
624 (def-markup-command (halign layout props dir arg) (number? markup?)
625   "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
626 left-aligned, while @code{+1} is right. Values in between interpolate
627 alignment accordingly."
628   (let* ((m (interpret-markup layout props arg)))
629     (ly:stencil-aligned-to m X dir)))
630
631
632 (def-markup-command (pad-around layout props amount arg) (number? markup?)
633
634   "Add padding @var{amount} all around @var{arg}. "
635   
636   (let*
637       ((m (interpret-markup layout props arg))
638        (x (ly:stencil-extent m X))
639        (y (ly:stencil-extent m Y)))
640     
641        
642     (ly:make-stencil (ly:stencil-expr m)
643                      (interval-widen x amount)
644                      (interval-widen y amount))
645    ))
646
647
648 (def-markup-command (pad-x layout props amount arg) (number? markup?)
649
650   "Add padding @var{amount} around @var{arg} in the X-direction. "
651   (let*
652       ((m (interpret-markup layout props arg))
653        (x (ly:stencil-extent m X))
654        (y (ly:stencil-extent m Y)))
655     
656        
657     (ly:make-stencil (ly:stencil-expr m)
658                      (interval-widen x amount)
659                      y)
660    ))
661
662
663 (def-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir?  markup?)
664
665   "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}.  "
666   
667   (let* ((m1 (interpret-markup layout props arg1))
668          (m2 (interpret-markup layout props arg2)))
669
670     (ly:stencil-combine-at-edge m1 axis dir m2 0.0 0.0)
671   ))
672
673 (def-markup-command (transparent layout props arg) (markup?)
674   "Make the argument transparent"
675   (let*
676       ((m (interpret-markup layout props arg))
677        (x (ly:stencil-extent m X))
678        (y (ly:stencil-extent m Y)))
679     
680
681     
682     (ly:make-stencil ""
683                      x y)))
684
685
686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
687 ;; property
688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
689
690 (def-markup-command (fromproperty layout props symbol) (symbol?)
691   "Read the @var{symbol} from property settings, and produce a stencil
692   from the markup contained within. If @var{symbol} is not defined, it
693   returns an empty markup"
694   (let* ((m (chain-assoc-get symbol props)))
695     (if (markup? m)
696         (interpret-markup layout props m)
697         (ly:make-stencil '()  '(1 . -1) '(1 . -1)))))
698
699
700 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
701   "Apply the @var{procedure} markup command to
702 @var{arg}. @var{procedure} should take a single argument."
703   (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
704     (set-object-property! anonymous-with-signature
705                           'markup-signature
706                           (list markup?))
707     (interpret-markup layout props (list anonymous-with-signature arg))))
708
709
710
711 (def-markup-command (override layout props new-prop arg) (pair? markup?)
712   "Add the first argument in to the property list.  Properties may be
713 any sort of property supported by @internalsref{font-interface} and
714 @internalsref{text-interface}, for example
715
716 @verbatim
717 \\override #'(font-family . married) \"bla\"
718 @end verbatim
719
720 "
721   (interpret-markup layout (cons (list new-prop) props) arg))
722
723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
724 ;; fonts.
725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
726
727
728 (def-markup-command (bigger layout props arg) (markup?)
729   "Increase the font size relative to current setting"
730   (interpret-markup layout props
731    `(,fontsize-markup 1 ,arg)))
732
733 (def-markup-command (smaller layout props arg) (markup?)
734   "Decrease the font size relative to current setting"
735   (interpret-markup layout props
736    `(,fontsize-markup -1 ,arg)))
737
738 (def-markup-command larger (markup?) bigger-markup)
739
740 (def-markup-command (finger layout props arg) (markup?)
741   "Set the argument as small numbers."
742   (interpret-markup layout
743                     (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
744                     arg))
745
746
747 (def-markup-command (fontsize layout props increment arg) (number? markup?)
748   "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
749
750   (let* ((fs (chain-assoc-get 'font-size props 0))
751          (bs (chain-assoc-get 'baseline-skip props 2)) 
752          (entries (list
753                    (cons 'baseline-skip (* bs (magstep increment)))
754                    (cons 'font-size (+ fs increment )))))
755
756     (interpret-markup layout (cons entries props) arg)))
757   
758
759
760 ;; FIXME -> should convert to font-size.
761 (def-markup-command (magnify layout props sz arg) (number? markup?)
762   "Set the font magnification for the its argument. In the following
763 example, the middle A will be 10% larger:
764 @example
765 A \\magnify #1.1 @{ A @} A
766 @end example
767
768 Note: magnification only works if a font-name is explicitly selected.
769 Use @code{\\fontsize} otherwise."
770   (interpret-markup
771    layout 
772    (prepend-alist-chain 'font-magnification sz props)
773    arg))
774
775 (def-markup-command (bold layout props arg) (markup?)
776   "Switch to bold font-series"
777   (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
778
779 (def-markup-command (sans layout props arg) (markup?)
780   "Switch to the sans serif family"
781   (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
782
783 (def-markup-command (number layout props arg) (markup?)
784   "Set font family to @code{number}, which yields the font used for
785 time signatures and fingerings.  This font only contains numbers and
786 some punctuation. It doesn't have any letters.  "
787   (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
788
789 (def-markup-command (roman layout props arg) (markup?)
790   "Set font family to @code{roman}."
791   (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
792
793 (def-markup-command (huge layout props arg) (markup?)
794   "Set font size to +2."
795   (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
796
797 (def-markup-command (large layout props arg) (markup?)
798   "Set font size to +1."
799   (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
800
801 (def-markup-command (normalsize layout props arg) (markup?)
802   "Set font size to default."
803   (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
804
805 (def-markup-command (small layout props arg) (markup?)
806   "Set font size to -1."
807   (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
808
809 (def-markup-command (tiny layout props arg) (markup?)
810   "Set font size to -2."
811   (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
812
813 (def-markup-command (teeny layout props arg) (markup?)
814   "Set font size to -3."
815   (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
816
817 (def-markup-command (caps layout props arg) (markup?)
818   "Set @code{font-shape} to @code{caps}."
819   (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
820
821 (def-markup-command (dynamic layout props arg) (markup?)
822   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
823 @b{z}, @b{p}, and @b{r}.  When producing phrases, like ``pi@`{u} @b{f}'', the
824 normal words (like ``pi@`{u}'') should be done in a different font.  The
825 recommend font for this is bold and italic"
826   (interpret-markup
827    layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
828
829 (def-markup-command (text layout props arg) (markup?)
830   "Use a text font instead of music symbol or music alphabet font."  
831
832   ;; ugh - latin1
833   (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
834                     arg))
835
836
837 (def-markup-command (italic layout props arg) (markup?)
838   "Use italic @code{font-shape} for @var{arg}. "
839   (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
840
841 (def-markup-command (typewriter layout props arg) (markup?)
842   "Use @code{font-family} typewriter for @var{arg}."
843   (interpret-markup
844    layout (prepend-alist-chain 'font-family 'typewriter props) arg))
845
846 (def-markup-command (upright layout props arg) (markup?)
847   "Set font shape to @code{upright}.  This is the opposite of @code{italic}."
848   (interpret-markup
849    layout (prepend-alist-chain 'font-shape 'upright props) arg))
850
851 (def-markup-command (medium layout props arg) (markup?)
852   "Switch to medium font-series (in contrast to bold)."
853   (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
854                     arg))
855
856 (def-markup-command (normal-text layout props arg) (markup?)
857   "Set all font related properties (except the size) to get the default normal text font, no matter what font was used earlier."
858   ;; ugh - latin1
859   (interpret-markup layout
860                     (cons '((font-family . roman) (font-shape . upright)
861                             (font-series . medium) (font-encoding . latin1))
862                           props)
863                     arg))
864
865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
866 ;; symbols.
867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
868
869 (def-markup-command (doublesharp layout props) ()
870   "Draw a double sharp symbol."
871
872   (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
873
874 (def-markup-command (sesquisharp layout props) ()
875   "Draw a 3/2 sharp symbol."
876   (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
877
878 (def-markup-command (sharp layout props) ()
879   "Draw a sharp symbol."
880   (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
881
882 (def-markup-command (semisharp layout props) ()
883   "Draw a semi sharp symbol."
884   (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
885
886 (def-markup-command (natural layout props) ()
887   "Draw a natural symbol."
888   (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
889
890 (def-markup-command (semiflat layout props) ()
891   "Draw a semiflat."
892   (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
893
894 (def-markup-command (flat layout props) ()
895   "Draw a flat symbol."
896   (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
897
898 (def-markup-command (sesquiflat layout props) ()
899   "Draw a 3/2 flat symbol."
900   (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
901
902 (def-markup-command (doubleflat layout props) ()
903   "Draw a double flat symbol."
904   (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
905
906 (def-markup-command (with-color layout props color arg) (color? markup?)
907   "Draw @var{arg} in color specified by @var{color}"
908
909   (let* ((stil (interpret-markup layout props arg)))
910
911     (ly:make-stencil (list 'color color (ly:stencil-expr stil))
912                      (ly:stencil-extent stil X)
913                      (ly:stencil-extent stil Y))))
914
915 \f
916 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
917 ;; glyphs
918 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
919
920
921 (def-markup-command (arrow-head layout props axis direction filled)
922   (integer? ly:dir? boolean?)
923   "produce an arrow head in specified direction and axis. Use the filled head if @var{filled} is  specified."
924   (let*
925       ((name (format "arrowheads.~a.~a~a"
926                      (if filled
927                          "close"
928                          "open")
929                      axis
930                      direction)))
931     (ly:font-get-glyph
932      (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
933                                      props))
934      name)))
935
936 (def-markup-command (musicglyph layout props glyph-name) (string?)
937   "This is converted to a musical symbol, e.g. @code{\\musicglyph
938 #\"accidentals.0\"} will select the natural sign from the music font.
939 See @usermanref{The Feta font} for  a complete listing of the possible glyphs."
940   (ly:font-get-glyph
941    (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
942                                    props))
943    glyph-name))
944
945 (def-markup-command (lookup layout props glyph-name) (string?)
946   "Lookup a glyph by name."
947   (ly:font-get-glyph (ly:paper-get-font layout props)
948                      glyph-name))
949
950 (def-markup-command (char layout props num) (integer?)
951   "Produce a single character, e.g. @code{\\char #65} produces the 
952 letter 'A'."
953   (ly:get-glyph (ly:paper-get-font layout props) num))
954
955
956 (define number->mark-letter-vector (make-vector 25 #\A))
957
958 (do ((i 0 (1+ i))
959      (j 0 (1+ j)))
960     ((>= i 26))
961   (if (= i (- (char->integer #\I) (char->integer #\A)))
962       (set! i (1+ i)))
963   (vector-set! number->mark-letter-vector j
964                (integer->char (+ i (char->integer #\A)))))
965
966 (define number->mark-alphabet-vector (list->vector
967   (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
968
969 (define (number->markletter-string vec n)
970   "Double letters for big marks."
971   (let* ((lst (vector-length vec)))
972     
973     (if (>= n lst)
974         (string-append (number->markletter-string vec (1- (quotient n lst)))
975                        (number->markletter-string vec (remainder n lst)))
976         (make-string 1 (vector-ref vec n)))))
977
978 (def-markup-command (markletter layout props num) (integer?)
979   "Make a markup letter for @var{num}.  The letters start with A to Z
980  (skipping I), and continues with double letters."
981   (Text_interface::interpret_markup layout props
982     (number->markletter-string number->mark-letter-vector num)))
983
984 (def-markup-command (markalphabet layout props num) (integer?)
985    "Make a markup letter for @var{num}.  The letters start with A to Z
986  and continues with double letters."
987    (Text_interface::interpret_markup layout props
988      (number->markletter-string number->mark-alphabet-vector num)))
989
990 \f
991 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
992 ;; the note command.
993 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
994
995
996 ;; TODO: better syntax.
997
998 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
999   "Construct a note symbol, with stem.  By using fractional values for
1000 @var{dir}, you can obtain longer or shorter stems."
1001   (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1002          (size (chain-assoc-get 'font-size props 0))
1003          (stem-length (* (magstep size) (max 3 (- log 1))))
1004          (head-glyph (ly:font-get-glyph
1005                       font
1006                       (string-append "noteheads.s" (number->string (min log 2)))))
1007          (stem-thickness 0.13)
1008          (stemy (* dir stem-length))
1009          (attachx (if (> dir 0)
1010                       (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
1011                       0))
1012          (attachy (* dir 0.28))
1013          (stem-glyph (and (> log 0)
1014                           (ly:round-filled-box
1015                            (cons attachx (+ attachx  stem-thickness))
1016                            (cons (min stemy attachy)
1017                                  (max stemy attachy))
1018                            (/ stem-thickness 3))))
1019          (dot (ly:font-get-glyph font "dots.dot"))
1020          (dotwid (interval-length (ly:stencil-extent dot X)))
1021          (dots (and (> dot-count 0)
1022                     (apply ly:stencil-add
1023                            (map (lambda (x)
1024                                   (ly:stencil-translate-axis
1025                                    dot  (* (+ 1 (* 2 x)) dotwid) X))
1026                                 (iota dot-count 1)))))
1027          (flaggl (and (> log 2)
1028                       (ly:stencil-translate
1029                        (ly:font-get-glyph font
1030                                           (string-append "flags."
1031                                                          (if (> dir 0) "u" "d")
1032                                                          (number->string log)))
1033                        (cons (+ attachx (/ stem-thickness 2)) stemy)))))
1034     (if flaggl
1035         (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1036     (if (ly:stencil? stem-glyph)
1037         (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1038         (set! stem-glyph head-glyph))
1039     (if (ly:stencil? dots)
1040         (set! stem-glyph
1041               (ly:stencil-add
1042                (ly:stencil-translate-axis
1043                 dots
1044                 (+ (if (and (> dir 0) (> log 2))
1045                        (* 1.5 dotwid)
1046                        0)
1047                    ;; huh ? why not necessary?
1048                    ;;(cdr (ly:stencil-extent head-glyph X))
1049                    dotwid)
1050                 X)
1051                stem-glyph)))
1052     stem-glyph))
1053
1054 (define-public log2 
1055   (let ((divisor (log 2)))
1056     (lambda (z) (inexact->exact (/ (log z) divisor)))))
1057
1058 (define (parse-simple-duration duration-string)
1059   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1060   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1061     (if (and match (string=? duration-string (match:substring match 0)))
1062         (let ((len  (match:substring match 1))
1063               (dots (match:substring match 2)))
1064           (list (cond ((string=? len "breve") -1)
1065                       ((string=? len "longa") -2)
1066                       ((string=? len "maxima") -3)
1067                       (else (log2 (string->number len))))
1068                 (if dots (string-length dots) 0)))
1069         (ly:error (_ "not a valid duration string: ~a") duration-string))))
1070
1071 (def-markup-command (note layout props duration dir) (string? number?)
1072   "This produces a note with a stem pointing in @var{dir} direction, with
1073 the @var{duration} for the note head type and augmentation dots. For
1074 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1075 a shortened down stem."
1076   (let ((parsed (parse-simple-duration duration)))
1077     (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1078
1079 \f
1080 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1081 ;; translating.
1082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1083
1084 (def-markup-command (lower layout props amount arg) (number? markup?)
1085   "
1086 Lower @var{arg}, by the distance @var{amount}.
1087 A negative @var{amount} indicates raising, see also @code{\raise}.
1088 "
1089   (ly:stencil-translate-axis (interpret-markup layout props arg)
1090                              (- amount) Y))
1091
1092
1093 (def-markup-command (raise layout props amount arg) (number? markup?)
1094   "
1095 Raise @var{arg}, by the distance @var{amount}.
1096 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1097 @c
1098 @lilypond[verbatim,fragment,relative=1]
1099  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
1100 @end lilypond
1101 The argument to @code{\\raise} is the vertical displacement amount,
1102 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
1103 raise objects in relation to their surrounding markups.
1104
1105 If the text object itself is positioned above or below the staff, then
1106 @code{\\raise} cannot be used to move it, since the mechanism that
1107 positions it next to the staff cancels any shift made with
1108 @code{\\raise}. For vertical positioning, use the @code{padding}
1109 and/or @code{extra-offset} properties. "
1110   (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1111
1112 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1113   "Make a fraction of two markups."
1114   (let* ((m1 (interpret-markup layout props arg1))
1115          (m2 (interpret-markup layout props arg2)))
1116     (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1117     (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1118     (let* ((x1 (ly:stencil-extent m1 X))
1119            (x2 (ly:stencil-extent m2 X))
1120            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
1121            ;; should stack mols separately, to maintain LINE on baseline
1122            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
1123       (set! stack
1124             (ly:stencil-aligned-to stack Y CENTER))
1125       (set! stack
1126             (ly:stencil-aligned-to stack X LEFT))
1127       ;; should have EX dimension
1128       ;; empirical anyway
1129       (ly:stencil-translate-axis stack 0.75 Y))))
1130
1131
1132
1133
1134
1135 (def-markup-command (normal-size-super layout props arg) (markup?)
1136   "Set @var{arg} in superscript with a normal font size."
1137   (ly:stencil-translate-axis
1138    (interpret-markup layout props arg)
1139    (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1140
1141 (def-markup-command (super layout props arg) (markup?)
1142   "
1143 @cindex raising text
1144 @cindex lowering text
1145 @cindex moving text
1146 @cindex translating text
1147
1148 @cindex @code{\\super}
1149
1150
1151 Raising and lowering texts can be done with @code{\\super} and
1152 @code{\\sub}:
1153
1154 @lilypond[verbatim,fragment,relative=1]
1155  c1^\\markup { E \"=\" mc \\super \"2\" }
1156 @end lilypond
1157
1158 "
1159   (ly:stencil-translate-axis
1160    (interpret-markup
1161     layout
1162     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1163     arg)
1164    (* 0.5 (chain-assoc-get 'baseline-skip props))
1165    Y))
1166
1167 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
1168   "This translates an object. Its first argument is a cons of numbers
1169 @example
1170 A \\translate #(cons 2 -3) @{ B C @} D
1171 @end example
1172 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1173 surroundings. This command cannot be used to move isolated scripts
1174 vertically, for the same reason that @code{\\raise} cannot be used for
1175 that.
1176
1177 "
1178   (ly:stencil-translate (interpret-markup  layout props arg)
1179                         offset))
1180
1181 (def-markup-command (sub layout props arg) (markup?)
1182   "Set @var{arg} in subscript."
1183   (ly:stencil-translate-axis
1184    (interpret-markup
1185     layout
1186     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1187     arg)
1188    (* -0.5 (chain-assoc-get 'baseline-skip props))
1189    Y))
1190
1191 (def-markup-command (normal-size-sub layout props arg) (markup?)
1192   "Set @var{arg} in subscript, in a normal font size."
1193   (ly:stencil-translate-axis
1194    (interpret-markup layout props arg)
1195    (* -0.5 (chain-assoc-get 'baseline-skip props))
1196    Y))
1197 \f
1198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1199 ;; brackets.
1200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1201
1202 (def-markup-command (hbracket layout props arg) (markup?)
1203   "Draw horizontal brackets around @var{arg}."  
1204   (let ((th 0.1) ;; todo: take from GROB.
1205         (m (interpret-markup layout props arg)))
1206     (bracketify-stencil m X th (* 2.5 th) th)))
1207
1208 (def-markup-command (bracket layout props arg) (markup?)
1209   "Draw vertical brackets around @var{arg}."  
1210   (let ((th 0.1) ;; todo: take from GROB.
1211         (m (interpret-markup layout props arg)))
1212     (bracketify-stencil m Y th (* 2.5 th) th)))
1213
1214 (def-markup-command (bracketed-y-column layout props indices args)
1215   (list? markup-list?)
1216   "Make a column of the markups in @var{args}, putting brackets around
1217 the elements marked in @var{indices}, which is a list of numbers."
1218   (define (sublist lst start stop)
1219     (take (drop lst start) (- (1+ stop) start)))
1220
1221   (define (stencil-list-extent ss axis)
1222     (cons
1223      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1224      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1225   
1226
1227   (define (stack-stencils-vertically stencils bskip last-stencil)
1228     (cond
1229      ((null? stencils) '())
1230      ((not (ly:stencil? last-stencil))
1231       (cons (car stencils)
1232             (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1233      (else
1234       (let* ((orig (car stencils))
1235              (dir (chain-assoc-get 'direction  props DOWN))
1236              (new (ly:stencil-moved-to-edge last-stencil Y dir
1237                                             orig
1238                                             0.1 bskip)))
1239
1240         (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1241
1242   (define (make-brackets stencils indices acc)
1243     (if (and stencils
1244              (pair? indices)
1245              (pair? (cdr indices)))
1246         (let* ((encl (sublist stencils (car indices) (cadr indices)))
1247                (x-ext (stencil-list-extent encl X))
1248                (y-ext (stencil-list-extent encl Y))
1249                (thick 0.10)
1250                (pad 0.35)
1251                (protusion (* 2.5 thick))
1252                (lb
1253                 (ly:stencil-translate-axis 
1254                  (ly:bracket Y y-ext thick protusion)
1255                  (- (car x-ext) pad) X))
1256                (rb (ly:stencil-translate-axis
1257                     (ly:bracket Y y-ext thick (- protusion))
1258                     (+ (cdr x-ext) pad) X)))
1259
1260           (make-brackets
1261            stencils (cddr indices)
1262            (append
1263             (list lb rb)
1264             acc)))
1265         acc))
1266
1267   (let* ((stencils
1268           (map (lambda (x)
1269                  (interpret-markup
1270                   layout
1271                   props
1272                   x)) args))
1273          (leading
1274           (chain-assoc-get 'baseline-skip props))
1275          (stacked (stack-stencils-vertically
1276                    (remove ly:stencil-empty? stencils) 1.25 #f))
1277          (brackets (make-brackets stacked indices '())))
1278
1279     (apply ly:stencil-add
1280            (append stacked brackets))))
1281 \f
1282
1283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1284 ;; size indications arrow
1285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1286