]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
* lily/staff-symbol-referencer.cc (get_position): emergency
[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--2004  Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;;                  Jan Nieuwenhuizen <janneke@gnu.org>
7
8 ;;; markup commands
9 ;;; TODO:
10 ;;;  * each markup function should have a doc string with
11 ;;     syntax, description and example. 
12
13
14 (def-markup-command (stencil paper props stil) (ly:stencil?)
15   "Stencil as markup"
16   stil)
17
18
19 (def-markup-command (score paper props score) (ly:score?)
20   (let*
21       ((systems (ly:score-embedded-format score paper))
22        (1st (vector-ref systems 0))
23        (stencil (ly:paper-system-stencil 1st)) )
24
25     (ly:stencil-align-to! stencil Y CENTER)
26     stencil))
27
28 (def-markup-command (simple paper props str) (string?)
29   "A simple text string; @code{\\markup @{ foo @}} is equivalent with
30 @code{\\markup @{ \\simple #\"foo\" @}}."
31     (interpret-markup paper props str))
32
33 (def-markup-command (encoded-simple paper props sym str) (symbol? string?)
34   "A text string, encoded with encoding @var{sym}. "
35   (Text_item::interpret_string paper
36                                props sym str))
37
38 ;; TODO: use font recoding.
39 ;;                    (make-line-markup
40 ;;                     (map make-word-markup (string-tokenize str)))))
41
42 (define-public empty-markup
43   (make-simple-markup ""))
44
45 ;;(def-markup-command (fill-line paper props line-width markups)
46 ;;  (number? markup-list?)
47 ;; no parser tag -- should make number? markuk-list? thingy
48 (def-markup-command (fill-line paper props markups)
49   (markup-list?)
50   "Put @var{markups} in a horizontal line of width @var{line-width}.
51    The markups are spaced/flushed to fill the entire line."
52
53   (let* ((stencils (map (lambda (x) (interpret-markup paper props x))
54                         markups))
55          (text-width (apply + (map interval-length
56                                    (map (lambda (x)
57                                           (ly:stencil-extent x X))
58                                         stencils))))
59         (word-count (length markups))
60         (word-space (chain-assoc-get 'word-space props))
61         (line-width (chain-assoc-get 'linewidth props))
62         (fill-space (if (< line-width text-width)
63                         word-space
64                         (/ (- line-width text-width)
65                            (if (= word-count 1) 2 (- word-count 1)))))
66         (line-stencils (if (= word-count 1)
67                            (map (lambda (x) (interpret-markup paper props x))
68                                 (list (make-simple-markup "")
69                                       (make-stencil-markup (car stencils))
70                                       (make-simple-markup "")))
71                                 stencils)))
72     (stack-stencil-line fill-space line-stencils)))
73   
74 (define (font-markup qualifier value)
75   (lambda (paper props arg)
76     (interpret-markup paper
77                       (prepend-alist-chain qualifier value props)
78                       arg)))
79
80 (def-markup-command (line paper props args) (markup-list?)
81   "Put @var{args} in a horizontal line.  The property @code{word-space}
82 determines the space between each markup in @var{args}."
83   (stack-stencil-line
84    (chain-assoc-get 'word-space props)
85    (map (lambda (m) (interpret-markup paper props m)) args)))
86
87 (def-markup-command (combine paper props m1 m2) (markup? markup?)
88   "Print two markups on top of each other."
89   (let*
90       ((s1 (interpret-markup paper props m1))
91        (s2 (interpret-markup paper props m2)))
92              
93     (ly:stencil-add s1 s2)))
94
95 (def-markup-command (finger paper props arg) (markup?)
96   "Set the argument as small numbers."
97   (interpret-markup paper
98                     (cons '((font-size . -5) (font-family . number)) props)
99                     arg))
100
101 (def-markup-command (fontsize paper props mag arg) (number? markup?)
102   "This sets the relative font size, e.g.
103 @example
104 A \\fontsize #2 @{ B C @} D
105 @end example
106
107
108 This will enlarge the B and the C by two steps.
109 "
110   (interpret-markup
111    paper 
112    (prepend-alist-chain 'font-size mag props)
113    arg))
114
115 (def-markup-command (magnify paper props sz arg) (number? markup?)
116   "This sets the font magnification for the its argument. In the following
117 example, the middle A will be 10% larger:
118 @example
119 A \\magnify #1.1 @{ A @} A
120 @end example
121
122 Note: magnification only works if a font-name is explicitly selected.
123 Use @code{\\fontsize} otherwise."
124
125   (interpret-markup
126    paper 
127    (prepend-alist-chain 'font-magnification sz props)
128    arg))
129
130 (def-markup-command (bold paper props arg) (markup?)
131   "Switch to bold font-series"
132   (interpret-markup paper (prepend-alist-chain 'font-series 'bold props) arg))
133
134 (def-markup-command (sans paper props arg) (markup?)
135   "Switch to the sans-serif family"
136   (interpret-markup paper (prepend-alist-chain 'font-family 'sans props) arg))
137
138 (def-markup-command (number paper props arg) (markup?)
139   "Set font family to @code{number}, which yields the font used for
140 time signatures and fingerings.  This font only contains numbers and
141 some punctuation. It doesn't have any letters.  "
142   (interpret-markup paper (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
143
144 (def-markup-command (roman paper props arg) (markup?)
145   "Set font family to @code{roman}."
146   (interpret-markup paper (prepend-alist-chain 'font-family 'roman props) arg))
147
148 (def-markup-command (huge paper props arg) (markup?)
149   "Set font size to +2."
150   (interpret-markup paper (prepend-alist-chain 'font-size 2 props) arg))
151
152 (def-markup-command (large paper props arg) (markup?)
153   "Set font size to +1."
154   (interpret-markup paper (prepend-alist-chain 'font-size 1 props) arg))
155
156 (def-markup-command (normalsize paper props arg) (markup?)
157   "Set font size to default."
158   (interpret-markup paper (prepend-alist-chain 'font-size 0 props) arg))
159
160 (def-markup-command (small paper props arg) (markup?)
161   "Set font size to -1."
162   (interpret-markup paper (prepend-alist-chain 'font-size -1 props) arg))
163
164 (def-markup-command (tiny paper props arg) (markup?)
165   "Set font size to -2."
166   (interpret-markup paper (prepend-alist-chain 'font-size -2 props) arg))
167
168 (def-markup-command (teeny paper props arg) (markup?)
169   "Set font size to -3."
170   (interpret-markup paper (prepend-alist-chain 'font-size -3 props) arg))
171
172 (def-markup-command (caps paper props arg) (markup?)
173   "Set font shape to @code{caps}."
174   (interpret-markup paper (prepend-alist-chain 'font-shape 'caps props) arg))
175
176 (def-markup-command (latin-i paper props arg) (markup?)
177   "TEST latin1 encoding."
178   (interpret-markup paper (prepend-alist-chain 'font-shape 'latin1 props) arg))
179
180 (def-markup-command (dynamic paper props arg) (markup?)
181   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
182 @b{z}, @b{p}, and @b{r}.  When producing phrases, like ``pi@`{u} @b{f}'', the
183 normal words (like ``pi@`{u}'') should be done in a different font.  The
184 recommend font for this is bold and italic"
185   (interpret-markup
186    paper (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
187
188 (def-markup-command (italic paper props arg) (markup?)
189   "Use italic @code{font-shape} for @var{arg}. "
190   (interpret-markup paper (prepend-alist-chain 'font-shape 'italic props) arg))
191
192 (def-markup-command (typewriter paper props arg) (markup?)
193   "Use @code{font-family} typewriter for @var{arg}."
194   (interpret-markup
195    paper (prepend-alist-chain 'font-family 'typewriter props) arg))
196
197 (def-markup-command (upright paper props arg) (markup?)
198   "Set font shape to @code{upright}."
199   (interpret-markup
200    paper (prepend-alist-chain 'font-shape 'upright props) arg))
201
202 (def-markup-command (doublesharp paper props) ()
203   "Draw a double sharp symbol."
204
205   (interpret-markup paper props (markup #:musicglyph "accidentals-4")))
206 (def-markup-command (sesquisharp paper props) ()
207   "Draw a 3/2 sharp symbol."
208   (interpret-markup paper props (markup #:musicglyph "accidentals-3")))
209
210 (def-markup-command (sharp paper props) ()
211   "Draw a sharp symbol."
212   (interpret-markup paper props (markup #:musicglyph "accidentals-2")))
213 (def-markup-command (semisharp paper props) ()
214   "Draw a semi sharp symbol."
215   (interpret-markup paper props (markup #:musicglyph "accidentals-1")))
216 (def-markup-command (natural paper props) ()
217   "Draw a natural symbol."
218
219   (interpret-markup paper props (markup #:musicglyph "accidentals-0")))
220 (def-markup-command (semiflat paper props) ()
221   "Draw a semiflat."
222   (interpret-markup paper props (markup #:musicglyph "accidentals--1")))
223 (def-markup-command (flat paper props) ()
224   "Draw a flat symbol."
225   
226   (interpret-markup paper props (markup #:musicglyph "accidentals--2")))
227 (def-markup-command (sesquiflat paper props) ()
228   "Draw a 3/2 flat symbol."
229   
230   (interpret-markup paper props (markup #:musicglyph "accidentals--3")))
231 (def-markup-command (doubleflat paper props) ()
232   "Draw a double flat symbol."
233
234   (interpret-markup paper props (markup #:musicglyph "accidentals--4")))
235
236
237 (def-markup-command (column paper props args) (markup-list?)
238   "Stack the markups in @var{args} vertically."
239   (stack-lines
240    -1 0.0 (chain-assoc-get 'baseline-skip props)
241    (map (lambda (m) (interpret-markup paper props m)) args)))
242
243 (def-markup-command (dir-column paper props args) (markup-list?)
244   "Make a column of args, going up or down, depending on the setting
245 of the @code{#'direction} layout property."
246   (let* ((dir (chain-assoc-get 'direction props)))
247     (stack-lines
248      (if (number? dir) dir -1)
249      0.0
250       (chain-assoc-get 'baseline-skip props)
251      (map (lambda (x) (interpret-markup paper props x)) args))))
252
253 (def-markup-command (center-align paper props args) (markup-list?)
254   "Put @code{args} in a centered column. "
255   (let* ((mols (map (lambda (x) (interpret-markup paper props x)) args))
256          (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
257     (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) mols)))
258
259 (def-markup-command (vcenter paper props arg) (markup?)
260   "Align @code{arg} to its center. "
261   (let* ((mol (interpret-markup paper props arg)))
262     (ly:stencil-align-to! mol Y CENTER)
263     mol))
264
265 (def-markup-command (right-align paper props arg) (markup?)
266   (let* ((m (interpret-markup paper props arg)))
267     (ly:stencil-align-to! m X RIGHT)
268     m))
269
270 (def-markup-command (left-align paper props arg) (markup?)
271   "Align @var{arg} on its left edge. "
272   
273   (let* ((m (interpret-markup paper props arg)))
274     (ly:stencil-align-to! m X LEFT)
275     m))
276
277 (def-markup-command (general-align paper props axis dir arg)  (integer? number? markup?)
278   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
279   (let* ((m (interpret-markup paper props arg)))
280
281     (ly:stencil-align-to! m axis dir)
282     m
283   ))
284
285 (def-markup-command (halign paper props dir arg) (number? markup?)
286   "Set horizontal alignment. If @var{dir} is -1, then it is
287 left-aligned, while+1 is right. Values in between interpolate alignment
288 accordingly."
289
290   
291   (let* ((m (interpret-markup paper props arg)))
292     (ly:stencil-align-to! m X dir)
293     m))
294
295 (def-markup-command (musicglyph paper props glyph-name) (string?)
296   "This is converted to a musical symbol, e.g. @code{\\musicglyph
297 #\"accidentals-0\"} will select the natural sign from the music font.
298 See @usermanref{The Feta font} for  a complete listing of the possible glyphs.
299 "
300   (ly:find-glyph-by-name
301    (ly:paper-get-font paper (cons '((font-encoding . fetaMusic))
302                                   props))
303    glyph-name))
304
305
306 (def-markup-command (lookup paper props glyph-name) (string?)
307   "Lookup a glyph by name."
308   (ly:find-glyph-by-name (ly:paper-get-font paper props)
309                          glyph-name))
310
311 (def-markup-command (char paper props num) (integer?)
312   "This produces a single character, e.g. @code{\\char #65} produces the 
313 letter 'A'."
314   (ly:get-glyph (ly:paper-get-font paper props) num))
315
316 (def-markup-command (raise paper props amount arg) (number? markup?)
317   "
318 This  raises  @var{arg}, by the distance @var{amount}.
319 A negative @var{amount} indicates lowering:
320 @c
321 @lilypond[verbatim,fragment,relative=1]
322  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
323 @end lilypond
324 The argument to @code{\\raise} is the vertical displacement amount,
325 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
326 raise objects in relation to their surrounding markups.
327
328 If the text object itself is positioned above or below the staff, then
329 @code{\\raise} cannot be used to move it, since the mechanism that
330 positions it next to the staff cancels any shift made with
331 @code{\\raise}. For vertical positioning, use the @code{padding}
332 and/or @code{extra-offset} properties. "
333
334   
335   (ly:stencil-translate-axis (interpret-markup paper props arg)
336                               amount Y))
337
338 (def-markup-command (fraction paper props arg1 arg2) (markup? markup?)
339   "Make a fraction of two markups."
340   
341   (let* ((m1 (interpret-markup paper props arg1))
342          (m2 (interpret-markup paper props arg2)))
343     (ly:stencil-align-to! m1 X CENTER)
344     (ly:stencil-align-to! m2 X CENTER)    
345     (let* ((x1 (ly:stencil-extent m1 X))
346            (x2 (ly:stencil-extent m2 X))
347            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
348            ;; should stack mols separately, to maintain LINE on baseline
349            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
350       (ly:stencil-align-to! stack Y CENTER)
351       (ly:stencil-align-to! stack X LEFT)
352       ;; should have EX dimension
353       ;; empirical anyway
354       (ly:stencil-translate-axis stack 0.75 Y))))
355
356
357 ;; TODO: better syntax.
358
359 (def-markup-command (note-by-number paper props log dot-count dir) (number? number? number?)
360   "Construct a note symbol, with stem.  By using fractional values for
361 @var{dir}, you can obtain longer or shorter stems."
362   
363   (let* ((font (ly:paper-get-font paper (cons '((font-encoding . fetaMusic)) props)))
364          (stemlen (max 3 (- log 1)))
365          (headgl (ly:find-glyph-by-name
366                   font
367                   (string-append "noteheads-" (number->string (min log 2)))))
368          (stemth 0.13)
369          (stemy (* dir stemlen))
370          (attachx (if (> dir 0)
371                       (- (cdr (ly:stencil-extent headgl X)) stemth)
372                       0))
373          (attachy (* dir 0.28))
374          (stemgl (and (> log 0)
375                       (ly:round-filled-box
376                        (cons attachx (+ attachx  stemth))
377                        (cons (min stemy attachy)
378                              (max stemy attachy))
379                        (/ stemth 3))))
380          (dot (ly:find-glyph-by-name font "dots-dot"))
381          (dotwid (interval-length (ly:stencil-extent dot X)))
382          (dots (and (> dot-count 0)
383                     (apply ly:stencil-add
384                            (map (lambda (x)
385                                   (ly:stencil-translate-axis
386                                    dot  (* (+ 1 (* 2 x)) dotwid) X) )
387                                 (iota dot-count 1)))))
388          (flaggl (and (> log 2)
389                       (ly:stencil-translate
390                        (ly:find-glyph-by-name font
391                                               (string-append "flags-"
392                                                              (if (> dir 0) "u" "d")
393                                                              (number->string log)))
394                        (cons (+ attachx (/ stemth 2)) stemy)))))
395     (if flaggl
396         (set! stemgl (ly:stencil-add flaggl stemgl)))
397     (if (ly:stencil? stemgl)
398         (set! stemgl (ly:stencil-add stemgl headgl))
399         (set! stemgl headgl))
400     (if (ly:stencil? dots)
401         (set! stemgl
402               (ly:stencil-add
403                (ly:stencil-translate-axis dots
404                                            (+ (if (and (> dir 0) (> log 2))
405                                                   (* 1.5 dotwid)
406                                                   0)
407                                               ;; huh ? why not necessary?
408                                               ;;(cdr (ly:stencil-extent headgl X))
409                                               dotwid)
410                                            X)
411                stemgl)))
412     stemgl))
413
414 (use-modules (ice-9 regex))
415
416 (define-public log2 
417   (let ((divisor (log 2)))
418     (lambda (z) (inexact->exact (/ (log z) divisor)))))
419
420 (define (parse-simple-duration duration-string)
421   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
422   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
423     (if (and match (string=? duration-string (match:substring match 0)))
424         (let ((len  (match:substring match 1))
425               (dots (match:substring match 2)))
426           (list (cond ((string=? len "breve")  -1)
427                       ((string=? len "longa")  -2)
428                       ((string=? len "maxima") -3)
429                       (else (log2 (string->number len))))
430                 (if dots (string-length dots) 0)))
431         (error "This is not a valid duration string:" duration-string))))
432
433 (def-markup-command (note paper props duration dir) (string? number?)
434   "This produces a note with a stem pointing in @var{dir} direction, with
435 the @var{duration} for the note head type and augmentation dots. For
436 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
437 a shortened down stem."
438   
439   (let ((parsed (parse-simple-duration duration)))
440     (note-by-number-markup paper props (car parsed) (cadr parsed) dir)))
441
442 (def-markup-command (normal-size-super paper props arg) (markup?)
443   "A superscript which does not use a smaller font."
444   
445   (ly:stencil-translate-axis (interpret-markup
446                                paper
447                                props arg)
448                               (* 0.5  (chain-assoc-get 'baseline-skip props))
449                               Y))
450
451 (def-markup-command (super paper props arg) (markup?)
452   "
453 @cindex raising text
454 @cindex lowering text
455 @cindex moving text
456 @cindex translating text
457
458 @cindex @code{\\super}
459
460
461 Raising and lowering texts can be done with @code{\\super} and
462 @code{\\sub}:
463
464 @lilypond[verbatim,fragment,relative=1]
465  c1^\\markup { E \"=\" mc \\super \"2\" }
466 @end lilypond
467
468 "
469   
470   (ly:stencil-translate-axis
471    (interpret-markup
472     paper
473     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
474     arg)
475    (* 0.5 (chain-assoc-get 'baseline-skip props))
476    Y))
477
478 (def-markup-command (translate paper props offset arg) (number-pair? markup?)
479   "This translates an object. Its first argument is a cons of numbers
480 @example
481 A \\translate #(cons 2 -3) @{ B C @} D
482 @end example
483 This moves `B C' 2 spaces to the right, and 3 down, relative to its
484 surroundings. This command cannot be used to move isolated scripts
485 vertically, for the same reason that @code{\\raise} cannot be used for
486 that.
487
488 . "
489   (ly:stencil-translate (interpret-markup  paper props arg)
490                          offset))
491
492 (def-markup-command (sub paper props arg) (markup?)
493   "Set @var{arg} in subscript."
494   
495   (ly:stencil-translate-axis
496    (interpret-markup
497     paper
498     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
499     arg)
500    (* -0.5 (chain-assoc-get 'baseline-skip props))
501    Y))
502
503 (def-markup-command (normal-size-sub paper props arg) (markup?)
504   "Set @var{arg} in subscript, in a normal font size."
505
506   (ly:stencil-translate-axis
507    (interpret-markup paper props arg)
508    (* -0.5 (chain-assoc-get 'baseline-skip props))
509    Y))
510
511 (def-markup-command (hbracket paper props arg) (markup?)
512   "Draw horizontal brackets around @var{arg}."  
513   (let ((th 0.1) ;; todo: take from GROB.
514         (m (interpret-markup paper props arg)))
515     (bracketify-stencil m X th (* 2.5 th) th)))
516
517 (def-markup-command (bracket paper props arg) (markup?)
518   "Draw vertical brackets around @var{arg}."  
519   (let ((th 0.1) ;; todo: take from GROB.
520         (m (interpret-markup paper props arg)))
521     (bracketify-stencil m Y th (* 2.5 th) th)))
522
523 ;; todo: fix negative space
524 (def-markup-command (hspace paper props amount) (number?)
525   "This produces a invisible object taking horizontal space.
526 @example 
527 \\markup @{ A \\hspace #2.0 B @} 
528 @end example
529 will put extra space between A and B, on top of the space that is
530 normally inserted before elements on a line.
531 "
532   (if (> amount 0)
533       (ly:make-stencil "" (cons 0 amount) '(-1 . 1) )
534       (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
535
536 (def-markup-command (override paper props new-prop arg) (pair? markup?)
537   "Add the first argument in to the property list.  Properties may be
538 any sort of property supported by @internalsref{font-interface} and
539 @internalsref{text-interface}, for example
540
541 @verbatim
542 \\override #'(font-family . married) \"bla\"
543 @end verbatim
544
545 "
546   (interpret-markup paper (cons (list new-prop) props) arg))
547
548 (def-markup-command (smaller paper props arg) (markup?)
549   "Decrease the font size relative to current setting"
550   (let* ((fs (chain-assoc-get 'font-size props 0))
551          (entry (cons 'font-size (- fs 1))))
552     (interpret-markup paper (cons (list entry) props) arg)))
553
554
555 (def-markup-command (bigger paper props arg) (markup?)
556   "Increase the font size relative to current setting"
557   (let* ((fs (chain-assoc-get 'font-size props 0))
558          (entry (cons 'font-size (+ fs 1))))
559     (interpret-markup paper (cons (list entry) props) arg)))
560
561 (def-markup-command larger (markup?)
562   bigger-markup)
563
564 (def-markup-command (box paper props arg) (markup?)
565   "Draw a box round @var{arg}"
566   
567   (let ((th 0.1)
568         (pad 0.2)
569         (m (interpret-markup paper props arg)))
570     (box-stencil m th pad)))
571
572 (def-markup-command (strut paper props) ()
573   
574   "Create a box of the same height as the space in the current font.
575
576 FIXME: is this working? 
577 "
578   
579   (let ((m (Text_item::interpret_markup paper props " ")))
580     (ly:stencil-set-extent! m X '(1000 . -1000))
581     m))
582
583 (define number->mark-letter-vector (make-vector 25 #\A))
584
585 (do ((i 0 (1+ i))
586      (j 0 (1+ j)))
587     ((>= i 26))
588   (if (= i (- (char->integer #\I) (char->integer #\A)))
589       (set! i (1+ i)))
590   (vector-set! number->mark-letter-vector j
591                (integer->char (+ i (char->integer #\A)))))
592
593 (define (number->markletter-string n)
594   "Double letters for big marks."
595   (let*
596       ((l (vector-length number->mark-letter-vector)))
597     
598   (if (>= n l)
599       (string-append (number->markletter-string (1- (quotient n l)))
600                      (number->markletter-string (remainder n l)))
601       (make-string 1 (vector-ref number->mark-letter-vector n)))))
602
603
604 (def-markup-command (markletter paper props num) (integer?)
605    "Make a markup letter for @var{num}.  The letters start with A to Z
606  (skipping I), and continues with double letters."
607  
608    (Text_item::interpret_markup paper props (number->markletter-string num)))
609
610
611
612
613 (def-markup-command (bracketed-y-column paper props indices args)
614   (list? markup-list?)
615   "Make a column of the markups in @var{args}, putting brackets around
616 the elements marked in @var{indices}, which is a list of numbers."
617
618     (define (sublist l start stop)
619     (take (drop l start)  (- (1+ stop) start)) )
620
621   (define (stencil-list-extent ss axis)
622     (cons
623      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
624      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
625             
626   (define (stack-stencils stencils bskip last-stencil)
627     (cond
628      ((null? stencils) '())
629      ((not last-stencil)
630       (cons (car stencils)
631             (stack-stencils (cdr stencils) bskip (car stencils))))
632      (else
633       (let*
634           ((orig (car stencils))
635            (dir (chain-assoc-get 'direction  props DOWN))
636            (new (ly:stencil-moved-to-edge last-stencil Y dir
637                                           orig
638                                           0.1 bskip))
639            )
640
641         (cons new (stack-stencils (cdr stencils) bskip new))))
642     ))
643
644   (define (make-brackets stencils indices acc)
645     (if (and stencils
646              (pair? indices)
647              (pair? (cdr indices)))
648         (let*
649             ((encl (sublist stencils (car indices) (cadr indices)))
650              (x-ext (stencil-list-extent encl X))
651              (y-ext (stencil-list-extent encl Y))
652              (thick 0.10)
653              (pad 0.35)
654              (protusion (* 2.5 thick))
655              (lb
656               (ly:stencil-translate-axis 
657                (ly:bracket Y y-ext thick protusion)
658                (- (car x-ext) pad) X))
659              (rb (ly:stencil-translate-axis
660                   (ly:bracket Y y-ext thick (- protusion))
661                   (+ (cdr x-ext) pad) X))
662              )
663
664           (make-brackets
665            stencils (cddr indices)
666            (append
667             (list lb rb)
668              acc)))
669         acc))
670
671   (let*
672       ((stencils
673         (map (lambda (x)
674                (interpret-markup
675                 paper
676                 props
677                 x)) args))
678        (leading
679          (chain-assoc-get 'baseline-skip props))
680        (stacked (stack-stencils stencils 1.25 #f))
681        (brackets (make-brackets stacked indices '()))
682        )
683
684     (apply ly:stencil-add
685            (append stacked brackets)
686            )))
687
688
689              
690
691   
692   
693
694