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