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