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