]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
*** empty log message ***
[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
553   (let*
554       ((arg-stencils (map (lambda (m) (interpret-markup layout props m)) args))
555        (skip (chain-assoc-get 'baseline-skip props)))
556
557     
558     (stack-lines
559      -1 0.0 skip
560      (remove ly:stencil-empty? arg-stencils))))
561
562
563 (def-markup-command (dir-column layout props args) (markup-list?)
564   "Make a column of args, going up or down, depending on the setting
565 of the @code{#'direction} layout property."
566   (let* ((dir (chain-assoc-get 'direction props)))
567     (stack-lines
568      (if (number? dir) dir -1)
569      0.0
570      (chain-assoc-get 'baseline-skip props)
571      (map (lambda (x) (interpret-markup layout props x)) args))))
572
573 (def-markup-command (center-align layout props args) (markup-list?)
574   "Put @code{args} in a centered column. "
575   (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
576          (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
577     
578     (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
579
580 (def-markup-command (vcenter layout props arg) (markup?)
581   "Align @code{arg} to its Y center. "
582   (let* ((mol (interpret-markup layout props arg)))
583     (ly:stencil-aligned-to mol Y CENTER)))
584
585 (def-markup-command (hcenter layout props arg) (markup?)
586   "Align @code{arg} to its X center. "
587   (let* ((mol (interpret-markup layout props arg)))
588     (ly:stencil-aligned-to mol X CENTER)))
589
590 (def-markup-command (right-align layout props arg) (markup?)
591   "Align @var{arg} on its right edge. "
592   (let* ((m (interpret-markup layout props arg)))
593     (ly:stencil-aligned-to m X RIGHT)))
594
595 (def-markup-command (left-align layout props arg) (markup?)
596   "Align @var{arg} on its left edge. "
597   (let* ((m (interpret-markup layout props arg)))
598     (ly:stencil-aligned-to m X LEFT)))
599
600 (def-markup-command (general-align layout props axis dir arg)  (integer? number? markup?)
601   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
602   (let* ((m (interpret-markup layout props arg)))
603     (ly:stencil-aligned-to m axis dir)))
604
605 (def-markup-command (halign layout props dir arg) (number? markup?)
606   "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
607 left-aligned, while @code{+1} is right. Values in between interpolate
608 alignment accordingly."
609   (let* ((m (interpret-markup layout props arg)))
610     (ly:stencil-aligned-to m X dir)))
611
612
613
614 (def-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
615   "Set the dimensions of @var{arg} to @var{x} and @var{y}."
616   
617   (let* ((m (interpret-markup layout props arg)))
618     (ly:make-stencil (ly:stencil-expr m) x y)))
619
620
621 (def-markup-command (pad-around layout props amount arg) (number? markup?)
622
623   "Add padding @var{amount} all around @var{arg}. "
624   
625   (let*
626       ((m (interpret-markup layout props arg))
627        (x (ly:stencil-extent m X))
628        (y (ly:stencil-extent m Y)))
629     
630        
631     (ly:make-stencil (ly:stencil-expr m)
632                      (interval-widen x amount)
633                      (interval-widen y amount))
634    ))
635
636
637 (def-markup-command (pad-x layout props amount arg) (number? markup?)
638
639   "Add padding @var{amount} around @var{arg} in the X-direction. "
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                      y)
649    ))
650
651
652 (def-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir?  markup?)
653
654   "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}.  "
655   
656   (let* ((m1 (interpret-markup layout props arg1))
657          (m2 (interpret-markup layout props arg2)))
658
659     (ly:stencil-combine-at-edge m1 axis dir m2 0.0 0.0)
660   ))
661
662 (def-markup-command (transparent layout props arg) (markup?)
663   "Make the argument transparent"
664   (let*
665       ((m (interpret-markup layout props arg))
666        (x (ly:stencil-extent m X))
667        (y (ly:stencil-extent m Y)))
668     
669
670     
671     (ly:make-stencil ""
672                      x y)))
673
674
675 (def-markup-command (pad-to-box layout props x-ext y-ext arg) (number-pair? number-pair? markup?)
676   "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space"
677
678   (let*
679       ((m (interpret-markup layout props arg))
680        (x (ly:stencil-extent m X))
681        (y (ly:stencil-extent m Y)))
682
683     (ly:make-stencil (ly:stencil-expr m)
684                      (interval-union x-ext x)
685                      (interval-union y-ext y))))
686
687
688
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
690 ;; property
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
692
693 (def-markup-command (fromproperty layout props symbol) (symbol?)
694   "Read the @var{symbol} from property settings, and produce a stencil
695   from the markup contained within. If @var{symbol} is not defined, it
696   returns an empty markup"
697   (let* ((m (chain-assoc-get symbol props)))
698     (if (markup? m)
699         (interpret-markup layout props m)
700         (ly:make-stencil '()  '(1 . -1) '(1 . -1)))))
701
702
703 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
704   "Apply the @var{procedure} markup command to
705 @var{arg}. @var{procedure} should take a single argument."
706   (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
707     (set-object-property! anonymous-with-signature
708                           'markup-signature
709                           (list markup?))
710     (interpret-markup layout props (list anonymous-with-signature arg))))
711
712
713
714 (def-markup-command (override layout props new-prop arg) (pair? markup?)
715   "Add the first argument in to the property list.  Properties may be
716 any sort of property supported by @internalsref{font-interface} and
717 @internalsref{text-interface}, for example
718
719 @verbatim
720 \\override #'(font-family . married) \"bla\"
721 @end verbatim
722
723 "
724   (interpret-markup layout (cons (list new-prop) props) arg))
725
726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
727 ;; files
728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
729
730 (def-markup-command (verbatim-file layout props name) (string?)
731   "Read the contents of a file, and include verbatimly"
732
733   (interpret-markup
734    layout props
735    (if  (ly:get-option 'safe)
736         "verbatim-file disabled in safe mode"
737         (let*
738             ((str (ly:gulp-file name))
739              (lines (string-split str #\nl)))
740
741           (make-typewriter-markup
742            (make-column-markup lines)))
743         )))
744
745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
746 ;; fonts.
747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
748
749
750 (def-markup-command (bigger layout props arg) (markup?)
751   "Increase the font size relative to current setting"
752   (interpret-markup layout props
753    `(,fontsize-markup 1 ,arg)))
754
755 (def-markup-command (smaller layout props arg) (markup?)
756   "Decrease the font size relative to current setting"
757   (interpret-markup layout props
758    `(,fontsize-markup -1 ,arg)))
759
760 (def-markup-command larger (markup?) bigger-markup)
761
762 (def-markup-command (finger layout props arg) (markup?)
763   "Set the argument as small numbers."
764   (interpret-markup layout
765                     (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
766                     arg))
767
768
769 (def-markup-command (fontsize layout props increment arg) (number? markup?)
770   "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
771
772   (let* ((fs (chain-assoc-get 'font-size props 0))
773          (bs (chain-assoc-get 'baseline-skip props 2)) 
774          (entries (list
775                    (cons 'baseline-skip (* bs (magstep increment)))
776                    (cons 'font-size (+ fs increment )))))
777
778     (interpret-markup layout (cons entries props) arg)))
779   
780
781
782 ;; FIXME -> should convert to font-size.
783 (def-markup-command (magnify layout props sz arg) (number? markup?)
784   "Set the font magnification for the its argument. In the following
785 example, the middle A will be 10% larger:
786 @example
787 A \\magnify #1.1 @{ A @} A
788 @end example
789
790 Note: magnification only works if a font-name is explicitly selected.
791 Use @code{\\fontsize} otherwise."
792   (interpret-markup
793    layout 
794    (prepend-alist-chain 'font-magnification sz props)
795    arg))
796
797 (def-markup-command (bold layout props arg) (markup?)
798   "Switch to bold font-series"
799   (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
800
801 (def-markup-command (sans layout props arg) (markup?)
802   "Switch to the sans serif family"
803   (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
804
805 (def-markup-command (number layout props arg) (markup?)
806   "Set font family to @code{number}, which yields the font used for
807 time signatures and fingerings.  This font only contains numbers and
808 some punctuation. It doesn't have any letters.  "
809   (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
810
811 (def-markup-command (roman layout props arg) (markup?)
812   "Set font family to @code{roman}."
813   (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
814
815 (def-markup-command (huge layout props arg) (markup?)
816   "Set font size to +2."
817   (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
818
819 (def-markup-command (large layout props arg) (markup?)
820   "Set font size to +1."
821   (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
822
823 (def-markup-command (normalsize layout props arg) (markup?)
824   "Set font size to default."
825   (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
826
827 (def-markup-command (small layout props arg) (markup?)
828   "Set font size to -1."
829   (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
830
831 (def-markup-command (tiny layout props arg) (markup?)
832   "Set font size to -2."
833   (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
834
835 (def-markup-command (teeny layout props arg) (markup?)
836   "Set font size to -3."
837   (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
838
839 (def-markup-command (caps layout props arg) (markup?)
840   "Set @code{font-shape} to @code{caps}."
841   (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
842
843 (def-markup-command (dynamic layout props arg) (markup?)
844   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
845 @b{z}, @b{p}, and @b{r}.  When producing phrases, like ``pi@`{u} @b{f}'', the
846 normal words (like ``pi@`{u}'') should be done in a different font.  The
847 recommend font for this is bold and italic"
848   (interpret-markup
849    layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
850
851 (def-markup-command (text layout props arg) (markup?)
852   "Use a text font instead of music symbol or music alphabet font."  
853
854   ;; ugh - latin1
855   (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
856                     arg))
857
858
859 (def-markup-command (italic layout props arg) (markup?)
860   "Use italic @code{font-shape} for @var{arg}. "
861   (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
862
863 (def-markup-command (typewriter layout props arg) (markup?)
864   "Use @code{font-family} typewriter for @var{arg}."
865   (interpret-markup
866    layout (prepend-alist-chain 'font-family 'typewriter props) arg))
867
868 (def-markup-command (upright layout props arg) (markup?)
869   "Set font shape to @code{upright}.  This is the opposite of @code{italic}."
870   (interpret-markup
871    layout (prepend-alist-chain 'font-shape 'upright props) arg))
872
873 (def-markup-command (medium layout props arg) (markup?)
874   "Switch to medium font-series (in contrast to bold)."
875   (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
876                     arg))
877
878 (def-markup-command (normal-text layout props arg) (markup?)
879   "Set all font related properties (except the size) to get the default normal text font, no matter what font was used earlier."
880   ;; ugh - latin1
881   (interpret-markup layout
882                     (cons '((font-family . roman) (font-shape . upright)
883                             (font-series . medium) (font-encoding . latin1))
884                           props)
885                     arg))
886
887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
888 ;; symbols.
889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
890
891 (def-markup-command (doublesharp layout props) ()
892   "Draw a double sharp symbol."
893
894   (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
895
896 (def-markup-command (sesquisharp layout props) ()
897   "Draw a 3/2 sharp symbol."
898   (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
899
900 (def-markup-command (sharp layout props) ()
901   "Draw a sharp symbol."
902   (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
903
904 (def-markup-command (semisharp layout props) ()
905   "Draw a semi sharp symbol."
906   (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
907
908 (def-markup-command (natural layout props) ()
909   "Draw a natural symbol."
910   (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
911
912 (def-markup-command (semiflat layout props) ()
913   "Draw a semiflat."
914   (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
915
916 (def-markup-command (flat layout props) ()
917   "Draw a flat symbol."
918   (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
919
920 (def-markup-command (sesquiflat layout props) ()
921   "Draw a 3/2 flat symbol."
922   (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
923
924 (def-markup-command (doubleflat layout props) ()
925   "Draw a double flat symbol."
926   (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
927
928 (def-markup-command (with-color layout props color arg) (color? markup?)
929   "Draw @var{arg} in color specified by @var{color}"
930
931   (let* ((stil (interpret-markup layout props arg)))
932
933     (ly:make-stencil (list 'color color (ly:stencil-expr stil))
934                      (ly:stencil-extent stil X)
935                      (ly:stencil-extent stil Y))))
936
937 \f
938 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
939 ;; glyphs
940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
941
942
943 (def-markup-command (arrow-head layout props axis direction filled)
944   (integer? ly:dir? boolean?)
945   "produce an arrow head in specified direction and axis. Use the filled head if @var{filled} is  specified."
946   (let*
947       ((name (format "arrowheads.~a.~a~a"
948                      (if filled
949                          "close"
950                          "open")
951                      axis
952                      direction)))
953     (ly:font-get-glyph
954      (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
955                                      props))
956      name)))
957
958 (def-markup-command (musicglyph layout props glyph-name) (string?)
959   "This is converted to a musical symbol, e.g. @code{\\musicglyph
960 #\"accidentals.0\"} will select the natural sign from the music font.
961 See @usermanref{The Feta font} for  a complete listing of the possible glyphs."
962   (ly:font-get-glyph
963    (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
964                                    props))
965    glyph-name))
966
967 (def-markup-command (lookup layout props glyph-name) (string?)
968   "Lookup a glyph by name."
969   (ly:font-get-glyph (ly:paper-get-font layout props)
970                      glyph-name))
971
972 (def-markup-command (char layout props num) (integer?)
973   "Produce a single character, e.g. @code{\\char #65} produces the 
974 letter 'A'."
975   (ly:get-glyph (ly:paper-get-font layout props) num))
976
977
978 (define number->mark-letter-vector (make-vector 25 #\A))
979
980 (do ((i 0 (1+ i))
981      (j 0 (1+ j)))
982     ((>= i 26))
983   (if (= i (- (char->integer #\I) (char->integer #\A)))
984       (set! i (1+ i)))
985   (vector-set! number->mark-letter-vector j
986                (integer->char (+ i (char->integer #\A)))))
987
988 (define number->mark-alphabet-vector (list->vector
989   (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
990
991 (define (number->markletter-string vec n)
992   "Double letters for big marks."
993   (let* ((lst (vector-length vec)))
994     
995     (if (>= n lst)
996         (string-append (number->markletter-string vec (1- (quotient n lst)))
997                        (number->markletter-string vec (remainder n lst)))
998         (make-string 1 (vector-ref vec n)))))
999
1000 (def-markup-command (markletter layout props num) (integer?)
1001   "Make a markup letter for @var{num}.  The letters start with A to Z
1002  (skipping I), and continues with double letters."
1003   (ly:text-interface::interpret-markup layout props
1004     (number->markletter-string number->mark-letter-vector num)))
1005
1006 (def-markup-command (markalphabet layout props num) (integer?)
1007    "Make a markup letter for @var{num}.  The letters start with A to Z
1008  and continues with double letters."
1009    (ly:text-interface::interpret-markup layout props
1010      (number->markletter-string number->mark-alphabet-vector num)))
1011
1012
1013
1014 (def-markup-command (slashed-digit layout props num) (integer?)
1015   "A feta number, with slash. This is for use in the context of
1016 figured bass notation"
1017   (let*
1018       ((mag (magstep (chain-assoc-get 'font-size props 0)))
1019        (thickness
1020         (* mag
1021            (chain-assoc-get 'thickness props 0.16)))
1022        (dy (* mag 0.15))
1023        (number-stencil (interpret-markup layout
1024                                          (prepend-alist-chain 'font-encoding 'fetaNumber props)
1025                                          (number->string num)))
1026        (num-x (interval-widen (ly:stencil-extent number-stencil X)
1027                               (* mag 0.2)))
1028        (num-y (ly:stencil-extent number-stencil Y))
1029        (slash-stencil 
1030         (ly:make-stencil
1031          `(draw-line
1032            ,thickness
1033            ,(car num-x) ,(- (interval-center num-y) dy)
1034            ,(cdr num-x) ,(+ (interval-center num-y) dy))
1035          num-x num-y
1036          )))
1037
1038     (ly:stencil-add number-stencil
1039                     (cond
1040                      ((= num 5) (ly:stencil-translate slash-stencil
1041                                                       ;;(cons (* mag -0.05) (* mag 0.42))
1042                                                       (cons (* mag -0.00) (* mag -0.07))
1043
1044                                                       ))
1045                      ((= num 7) (ly:stencil-translate slash-stencil
1046                                                       ;;(cons (* mag -0.05) (* mag 0.42))
1047                                                       (cons (* mag -0.00) (* mag -0.15))
1048
1049                                                       ))
1050                      
1051                      (else slash-stencil)))
1052     ))
1053 \f
1054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1055 ;; the note command.
1056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1057
1058
1059 ;; TODO: better syntax.
1060
1061 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1062   "Construct a note symbol, with stem.  By using fractional values for
1063 @var{dir}, you can obtain longer or shorter stems."
1064   (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1065          (size (chain-assoc-get 'font-size props 0))
1066          (stem-length (* (magstep size) (max 3 (- log 1))))
1067          (head-glyph (ly:font-get-glyph
1068                       font
1069                       (string-append "noteheads.s" (number->string (min log 2)))))
1070          (stem-thickness 0.13)
1071          (stemy (* dir stem-length))
1072          (attachx (if (> dir 0)
1073                       (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
1074                       0))
1075          (attachy (* dir 0.28))
1076          (stem-glyph (and (> log 0)
1077                           (ly:round-filled-box
1078                            (cons attachx (+ attachx  stem-thickness))
1079                            (cons (min stemy attachy)
1080                                  (max stemy attachy))
1081                            (/ stem-thickness 3))))
1082          (dot (ly:font-get-glyph font "dots.dot"))
1083          (dotwid (interval-length (ly:stencil-extent dot X)))
1084          (dots (and (> dot-count 0)
1085                     (apply ly:stencil-add
1086                            (map (lambda (x)
1087                                   (ly:stencil-translate-axis
1088                                    dot  (* (+ 1 (* 2 x)) dotwid) X))
1089                                 (iota dot-count 1)))))
1090          (flaggl (and (> log 2)
1091                       (ly:stencil-translate
1092                        (ly:font-get-glyph font
1093                                           (string-append "flags."
1094                                                          (if (> dir 0) "u" "d")
1095                                                          (number->string log)))
1096                        (cons (+ attachx (/ stem-thickness 2)) stemy)))))
1097     (if flaggl
1098         (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1099     (if (ly:stencil? stem-glyph)
1100         (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1101         (set! stem-glyph head-glyph))
1102     (if (ly:stencil? dots)
1103         (set! stem-glyph
1104               (ly:stencil-add
1105                (ly:stencil-translate-axis
1106                 dots
1107                 (+ (if (and (> dir 0) (> log 2))
1108                        (* 1.5 dotwid)
1109                        0)
1110                    ;; huh ? why not necessary?
1111                    ;;(cdr (ly:stencil-extent head-glyph X))
1112                    dotwid)
1113                 X)
1114                stem-glyph)))
1115     stem-glyph))
1116
1117 (define-public log2 
1118   (let ((divisor (log 2)))
1119     (lambda (z) (inexact->exact (/ (log z) divisor)))))
1120
1121 (define (parse-simple-duration duration-string)
1122   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1123   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1124     (if (and match (string=? duration-string (match:substring match 0)))
1125         (let ((len  (match:substring match 1))
1126               (dots (match:substring match 2)))
1127           (list (cond ((string=? len "breve") -1)
1128                       ((string=? len "longa") -2)
1129                       ((string=? len "maxima") -3)
1130                       (else (log2 (string->number len))))
1131                 (if dots (string-length dots) 0)))
1132         (ly:error (_ "not a valid duration string: ~a") duration-string))))
1133
1134 (def-markup-command (note layout props duration dir) (string? number?)
1135   "This produces a note with a stem pointing in @var{dir} direction, with
1136 the @var{duration} for the note head type and augmentation dots. For
1137 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1138 a shortened down stem."
1139   (let ((parsed (parse-simple-duration duration)))
1140     (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1141
1142 \f
1143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1144 ;; translating.
1145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1146
1147 (def-markup-command (lower layout props amount arg) (number? markup?)
1148   "
1149 Lower @var{arg}, by the distance @var{amount}.
1150 A negative @var{amount} indicates raising, see also @code{\\raise}.
1151 "
1152   (ly:stencil-translate-axis (interpret-markup layout props arg)
1153                              (- amount) Y))
1154
1155
1156 (def-markup-command (raise layout props amount arg) (number? markup?)
1157   "
1158 Raise @var{arg}, by the distance @var{amount}.
1159 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1160 @c
1161 @lilypond[verbatim,fragment,relative=1]
1162  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
1163 @end lilypond
1164 The argument to @code{\\raise} is the vertical displacement amount,
1165 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
1166 raise objects in relation to their surrounding markups.
1167
1168 If the text object itself is positioned above or below the staff, then
1169 @code{\\raise} cannot be used to move it, since the mechanism that
1170 positions it next to the staff cancels any shift made with
1171 @code{\\raise}. For vertical positioning, use the @code{padding}
1172 and/or @code{extra-offset} properties. "
1173   (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1174
1175 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1176   "Make a fraction of two markups."
1177   (let* ((m1 (interpret-markup layout props arg1))
1178          (m2 (interpret-markup layout props arg2)))
1179     (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1180     (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1181     (let* ((x1 (ly:stencil-extent m1 X))
1182            (x2 (ly:stencil-extent m2 X))
1183            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
1184            ;; should stack mols separately, to maintain LINE on baseline
1185            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
1186       (set! stack
1187             (ly:stencil-aligned-to stack Y CENTER))
1188       (set! stack
1189             (ly:stencil-aligned-to stack X LEFT))
1190       ;; should have EX dimension
1191       ;; empirical anyway
1192       (ly:stencil-translate-axis stack 0.75 Y))))
1193
1194
1195
1196
1197
1198 (def-markup-command (normal-size-super layout props arg) (markup?)
1199   "Set @var{arg} in superscript with a normal font size."
1200   (ly:stencil-translate-axis
1201    (interpret-markup layout props arg)
1202    (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1203
1204 (def-markup-command (super layout props arg) (markup?)
1205   "
1206 @cindex raising text
1207 @cindex lowering text
1208 @cindex moving text
1209 @cindex translating text
1210
1211 @cindex @code{\\super}
1212
1213
1214 Raising and lowering texts can be done with @code{\\super} and
1215 @code{\\sub}:
1216
1217 @lilypond[verbatim,fragment,relative=1]
1218  c1^\\markup { E \"=\" mc \\super \"2\" }
1219 @end lilypond
1220
1221 "
1222   (ly:stencil-translate-axis
1223    (interpret-markup
1224     layout
1225     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1226     arg)
1227    (* 0.5 (chain-assoc-get 'baseline-skip props))
1228    Y))
1229
1230 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
1231   "This translates an object. Its first argument is a cons of numbers
1232 @example
1233 A \\translate #(cons 2 -3) @{ B C @} D
1234 @end example
1235 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1236 surroundings. This command cannot be used to move isolated scripts
1237 vertically, for the same reason that @code{\\raise} cannot be used for
1238 that.
1239
1240 "
1241   (ly:stencil-translate (interpret-markup  layout props arg)
1242                         offset))
1243
1244 (def-markup-command (sub layout props arg) (markup?)
1245   "Set @var{arg} in subscript."
1246   (ly:stencil-translate-axis
1247    (interpret-markup
1248     layout
1249     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1250     arg)
1251    (* -0.5 (chain-assoc-get 'baseline-skip props))
1252    Y))
1253
1254 (def-markup-command (normal-size-sub layout props arg) (markup?)
1255   "Set @var{arg} in subscript, in a normal font size."
1256   (ly:stencil-translate-axis
1257    (interpret-markup layout props arg)
1258    (* -0.5 (chain-assoc-get 'baseline-skip props))
1259    Y))
1260 \f
1261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1262 ;; brackets.
1263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1264
1265 (def-markup-command (hbracket layout props arg) (markup?)
1266   "Draw horizontal brackets around @var{arg}."  
1267   (let ((th 0.1) ;; todo: take from GROB.
1268         (m (interpret-markup layout props arg)))
1269     (bracketify-stencil m X th (* 2.5 th) th)))
1270
1271 (def-markup-command (bracket layout props arg) (markup?)
1272   "Draw vertical brackets around @var{arg}."  
1273   (let ((th 0.1) ;; todo: take from GROB.
1274         (m (interpret-markup layout props arg)))
1275     (bracketify-stencil m Y th (* 2.5 th) th)))
1276
1277 (def-markup-command (bracketed-y-column layout props indices args)
1278   (list? markup-list?)
1279   "Make a column of the markups in @var{args}, putting brackets around
1280 the elements marked in @var{indices}, which is a list of numbers.
1281
1282 "
1283 ;;
1284 ;; DROPME? This command is a relic from the old figured bass implementation.
1285 ;;
1286   
1287   (define (sublist lst start stop)
1288     (take (drop lst start) (- (1+ stop) start)))
1289
1290   (define (stencil-list-extent ss axis)
1291     (cons
1292      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1293      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1294   
1295
1296   (define (stack-stencils-vertically stencils bskip last-stencil)
1297     (cond
1298      ((null? stencils) '())
1299      ((not (ly:stencil? last-stencil))
1300       (cons (car stencils)
1301             (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1302      (else
1303       (let* ((orig (car stencils))
1304              (dir (chain-assoc-get 'direction  props DOWN))
1305              (new (ly:stencil-moved-to-edge last-stencil Y dir
1306                                             orig
1307                                             0.1 bskip)))
1308
1309         (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1310
1311   (define (make-brackets stencils indices acc)
1312     (if (and stencils
1313              (pair? indices)
1314              (pair? (cdr indices)))
1315         (let* ((encl (sublist stencils (car indices) (cadr indices)))
1316                (x-ext (stencil-list-extent encl X))
1317                (y-ext (stencil-list-extent encl Y))
1318                (thick 0.10)
1319                (pad 0.35)
1320                (protusion (* 2.5 thick))
1321                (lb
1322                 (ly:stencil-translate-axis 
1323                  (ly:bracket Y y-ext thick protusion)
1324                  (- (car x-ext) pad) X))
1325                (rb (ly:stencil-translate-axis
1326                     (ly:bracket Y y-ext thick (- protusion))
1327                     (+ (cdr x-ext) pad) X)))
1328
1329           (make-brackets
1330            stencils (cddr indices)
1331            (append
1332             (list lb rb)
1333             acc)))
1334         acc))
1335
1336   (let* ((stencils
1337           (map (lambda (x)
1338                  (interpret-markup
1339                   layout
1340                   props
1341                   x)) args))
1342          (leading
1343           (chain-assoc-get 'baseline-skip props))
1344          (stacked (stack-stencils-vertically
1345                    (remove ly:stencil-empty? stencils) 1.25 #f))
1346          (brackets (make-brackets stacked indices '())))
1347
1348     (apply ly:stencil-add
1349            (append stacked brackets))))
1350 \f
1351
1352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1353 ;; size indications arrow
1354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1355