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