]> 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--2005  Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;;;                  Jan Nieuwenhuizen <janneke@gnu.org>
7
8 ;;; markup commands
9 ;;;  * each markup function should have a doc string with
10 ;;     syntax, description and example. 
11
12 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
13 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
14
15 (def-markup-command (stencil layout props stil) (ly:stencil?)
16   "Stencil as markup"
17   stil)
18
19 (def-markup-command (score layout props score) (ly:score?)
20   "Inline an image of music."
21   (let* ((systems (ly:score-embedded-format score layout)))
22
23     (if (= 0 (vector-length systems))
24         (begin
25           (ly:warn "No systems found in \\score markup. Did you forget \\layout?")
26           empty-markup)
27         (begin
28           (let* ((stencil (ly:paper-system-stencil (vector-ref systems 0)))) 
29
30             (ly:stencil-align-to! stencil Y CENTER)
31             stencil)))))
32
33 (def-markup-command (simple layout props str) (string?)
34   "A simple text string; @code{\\markup @{ foo @}} is equivalent with
35 @code{\\markup @{ \\simple #\"foo\" @}}."
36   (interpret-markup layout props str))
37
38 (def-markup-command (encoded-simple layout props sym str) (symbol? string?)
39   "A text string, encoded with encoding @var{sym}. See
40 @usermanref{Text encoding} for more information."
41   (Text_interface::interpret_string layout
42                                     props sym str))
43
44
45 ;; TODO: use font recoding.
46 ;;                    (make-line-markup
47 ;;                     (map make-word-markup (string-tokenize str)))))
48
49 (define-public empty-markup
50   (make-simple-markup ""))
51
52
53 (def-markup-command (postscript layout props str) (string?)
54   "This inserts @var{str} directly into the output as a PostScript
55 command string.  Due to technicalities of the output backends,
56 different scales should be used for the @TeX{} and PostScript backend,
57 selected with @code{-f}. 
58
59
60 For the TeX backend, the following string prints a rotated text
61
62 @cindex rotated text
63
64 @verbatim
65 0 0 moveto /ecrm10 findfont 
66 1.75 scalefont setfont 90 rotate (hello) show
67 @end verbatim
68
69 @noindent
70 The magical constant 1.75 scales from LilyPond units (staff spaces) to
71 TeX dimensions.
72
73 For the postscript backend, use the following
74
75 @verbatim
76 gsave /ecrm10 findfont 
77  10.0 output-scale div 
78  scalefont setfont 90 rotate (hello) show grestore 
79 @end verbatim
80 "
81   ;; FIXME
82   (ly:make-stencil
83    (list 'embedded-ps str)
84    '(0 . 0) '(0 . 0)))
85
86 ;;(def-markup-command (fill-line layout props line-width markups)
87 ;;  (number? markup-list?)
88 ;; no parser tag -- should make number? markuk-list? thingy
89 (def-markup-command (fill-line layout props markups)
90   (markup-list?)
91   "Put @var{markups} in a horizontal line of width @var{line-width}.
92    The markups are spaced/flushed to fill the entire line.
93    If there are no arguments, return an empty stencil.
94 "
95   (let* ((orig-stencils
96           (map (lambda (x) (interpret-markup layout props x))
97                markups))
98          (stencils
99           (map (lambda (stc)
100                  (if (ly:stencil-empty? stc)
101                      point-stencil
102                      stc)) orig-stencils))
103          (text-width (apply +
104                             (map (lambda (stc)
105                                    (if (ly:stencil-empty? stc)
106                                        0.0
107                                        (interval-length (ly:stencil-extent stc X))))
108                                  stencils)))
109          (word-count (length stencils))
110          (word-space (chain-assoc-get 'word-space props))
111          (line-width (chain-assoc-get 'linewidth props))
112          (fill-space (if (< line-width text-width)
113                          word-space
114                          (/ (- line-width text-width)
115                             (if (= word-count 1) 2 (- word-count 1)))))
116          (line-stencils (if (= word-count 1)
117                             (list
118                              point-stencil
119                              (car stencils)
120                              point-stencil)
121                             stencils)))
122
123     (if (null? (remove ly:stencil-empty? orig-stencils))
124         empty-stencil
125         (stack-stencils X RIGHT fill-space line-stencils))))
126
127 (define (font-markup qualifier value)
128   (lambda (layout props arg)
129     (interpret-markup layout
130                       (prepend-alist-chain qualifier value props)
131                       arg)))
132
133
134 (def-markup-command (line layout props args) (markup-list?)
135   "Put @var{args} in a horizontal line.  The property @code{word-space}
136 determines the space between each markup in @var{args}."
137   (stack-stencil-line
138    (chain-assoc-get 'word-space props)
139    (remove ly:stencil-empty?
140            (map (lambda (m) (interpret-markup layout props m)) args))))
141
142 (def-markup-command (fromproperty layout props symbol) (symbol?)
143   "Read the @var{symbol} from property settings, and produce a stencil
144   from the markup contained within. If @var{symbol} is not defined, it
145   returns an empty markup"
146   (let* ((m (chain-assoc-get symbol props)))
147     (if (markup? m)
148         (interpret-markup layout props m)
149         (ly:make-stencil '()  '(1 . -1) '(1 . -1)))))
150
151
152 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
153   "Apply the @var{procedure} markup command to
154 @var{arg}. @var{procedure} should take a single argument."
155   (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
156     (set-object-property! anonymous-with-signature
157                           'markup-signature
158                           (list markup?))
159     (interpret-markup layout props (list anonymous-with-signature arg))))
160
161
162 (def-markup-command (combine layout props m1 m2) (markup? markup?)
163   "Print two markups on top of each other."
164   (let* ((s1 (interpret-markup layout props m1))
165          (s2 (interpret-markup layout props m2)))
166     (ly:stencil-add s1 s2)))
167
168 (def-markup-command (finger layout props arg) (markup?)
169   "Set the argument as small numbers."
170   (interpret-markup layout
171                     (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
172                     arg))
173
174 (def-markup-command (fontsize layout props mag arg) (number? markup?)
175   "This sets the relative font size, e.g.
176 @example
177 A \\fontsize #2 @{ B C @} D
178 @end example
179
180
181 This will enlarge the B and the C by two steps.
182 "
183   (interpret-markup
184    layout 
185    (prepend-alist-chain 'font-size mag props)
186    arg))
187
188 (def-markup-command (magnify layout props sz arg) (number? markup?)
189   "This sets the font magnification for the its argument. In the following
190 example, the middle A will be 10% larger:
191 @example
192 A \\magnify #1.1 @{ A @} A
193 @end example
194
195 Note: magnification only works if a font-name is explicitly selected.
196 Use @code{\\fontsize} otherwise."
197   (interpret-markup
198    layout 
199    (prepend-alist-chain 'font-magnification sz props)
200    arg))
201
202 (def-markup-command (bold layout props arg) (markup?)
203   "Switch to bold font-series"
204   (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
205
206 (def-markup-command (sans layout props arg) (markup?)
207   "Switch to the sans serif family"
208   (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
209
210 (def-markup-command (number layout props arg) (markup?)
211   "Set font family to @code{number}, which yields the font used for
212 time signatures and fingerings.  This font only contains numbers and
213 some punctuation. It doesn't have any letters.  "
214   (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
215
216 (def-markup-command (roman layout props arg) (markup?)
217   "Set font family to @code{roman}."
218   (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
219
220 (def-markup-command (huge layout props arg) (markup?)
221   "Set font size to +2."
222   (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
223
224 (def-markup-command (large layout props arg) (markup?)
225   "Set font size to +1."
226   (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
227
228 (def-markup-command (normalsize layout props arg) (markup?)
229   "Set font size to default."
230   (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
231
232 (def-markup-command (small layout props arg) (markup?)
233   "Set font size to -1."
234   (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
235
236 (def-markup-command (tiny layout props arg) (markup?)
237   "Set font size to -2."
238   (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
239
240 (def-markup-command (teeny layout props arg) (markup?)
241   "Set font size to -3."
242   (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
243
244 (def-markup-command (caps layout props arg) (markup?)
245   "Set @code{font-shape} to @code{caps}."
246   (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
247
248 ;(def-markup-command (latin-i layout props arg) (markup?)
249 ;  "TEST latin1 encoding."
250 ;  (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
251
252 (def-markup-command (dynamic layout props arg) (markup?)
253   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
254 @b{z}, @b{p}, and @b{r}.  When producing phrases, like ``pi@`{u} @b{f}'', the
255 normal words (like ``pi@`{u}'') should be done in a different font.  The
256 recommend font for this is bold and italic"
257   (interpret-markup
258    layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
259
260 (def-markup-command (italic layout props arg) (markup?)
261   "Use italic @code{font-shape} for @var{arg}. "
262   (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
263
264 (def-markup-command (typewriter layout props arg) (markup?)
265   "Use @code{font-family} typewriter for @var{arg}."
266   (interpret-markup
267    layout (prepend-alist-chain 'font-family 'typewriter props) arg))
268
269 (def-markup-command (upright layout props arg) (markup?)
270   "Set font shape to @code{upright}."
271   (interpret-markup
272    layout (prepend-alist-chain 'font-shape 'upright props) arg))
273
274 (def-markup-command (doublesharp layout props) ()
275   "Draw a double sharp symbol."
276
277   (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
278 (def-markup-command (sesquisharp layout props) ()
279   "Draw a 3/2 sharp symbol."
280   (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
281
282 (def-markup-command (sharp layout props) ()
283   "Draw a sharp symbol."
284   (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
285
286 (def-markup-command (semisharp layout props) ()
287   "Draw a semi sharp symbol."
288   (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
289
290 (def-markup-command (natural layout props) ()
291   "Draw a natural symbol."
292   (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
293
294 (def-markup-command (semiflat layout props) ()
295   "Draw a semiflat."
296   (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
297
298 (def-markup-command (flat layout props) ()
299   "Draw a flat symbol."
300   (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
301
302 (def-markup-command (sesquiflat layout props) ()
303   "Draw a 3/2 flat symbol."
304   (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
305
306 (def-markup-command (doubleflat layout props) ()
307   "Draw a double flat symbol."
308   (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
309
310 (def-markup-command (column layout props args) (markup-list?)
311   "Stack the markups in @var{args} vertically.  The property
312 @code{baseline-skip} determines the space between each markup in @var{args}."
313   (stack-lines
314    -1 0.0 (chain-assoc-get 'baseline-skip props)
315    (remove ly:stencil-empty?
316            (map (lambda (m) (interpret-markup layout props m)) args))))
317
318 (def-markup-command (dir-column layout props args) (markup-list?)
319   "Make a column of args, going up or down, depending on the setting
320 of the @code{#'direction} layout property."
321   (let* ((dir (chain-assoc-get 'direction props)))
322     (stack-lines
323      (if (number? dir) dir -1)
324      0.0
325      (chain-assoc-get 'baseline-skip props)
326      (map (lambda (x) (interpret-markup layout props x)) args))))
327
328 (def-markup-command (center-align layout props args) (markup-list?)
329   "Put @code{args} in a centered column. "
330   (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
331          (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
332     (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
333
334 (def-markup-command (vcenter layout props arg) (markup?)
335   "Align @code{arg} to its Y center. "
336   (let* ((mol (interpret-markup layout props arg)))
337     (ly:stencil-align-to! mol Y CENTER)
338     mol))
339
340 (def-markup-command (hcenter layout props arg) (markup?)
341   "Align @code{arg} to its X center. "
342   (let* ((mol (interpret-markup layout props arg)))
343     (ly:stencil-align-to! mol X CENTER)
344     mol))
345
346 (def-markup-command (right-align layout props arg) (markup?)
347   "Align @var{arg} on its right edge. "
348   (let* ((m (interpret-markup layout props arg)))
349     (ly:stencil-align-to! m X RIGHT)
350     m))
351
352 (def-markup-command (left-align layout props arg) (markup?)
353   "Align @var{arg} on its left edge. "
354   (let* ((m (interpret-markup layout props arg)))
355     (ly:stencil-align-to! m X LEFT)
356     m))
357
358 (def-markup-command (general-align layout props axis dir arg)  (integer? number? markup?)
359   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
360   (let* ((m (interpret-markup layout props arg)))
361     (ly:stencil-align-to! m axis dir)
362     m))
363
364 (def-markup-command (halign layout props dir arg) (number? markup?)
365   "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
366 left-aligned, while @code{+1} is right. Values in between interpolate
367 alignment accordingly."
368   (let* ((m (interpret-markup layout props arg)))
369     (ly:stencil-align-to! m X dir)
370     m))
371
372 (def-markup-command (musicglyph layout props glyph-name) (string?)
373   "This is converted to a musical symbol, e.g. @code{\\musicglyph
374 #\"accidentals.0\"} will select the natural sign from the music font.
375 See @usermanref{The Feta font} for  a complete listing of the possible glyphs."
376   (ly:font-get-glyph
377    (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
378                                    props))
379    glyph-name))
380
381 (def-markup-command (lookup layout props glyph-name) (string?)
382   "Lookup a glyph by name."
383   (ly:font-get-glyph (ly:paper-get-font layout props)
384                      glyph-name))
385
386 (def-markup-command (char layout props num) (integer?)
387   "Produce a single character, e.g. @code{\\char #65} produces the 
388 letter 'A'."
389   (ly:get-glyph (ly:paper-get-font layout props) num))
390
391 (def-markup-command (raise layout props amount arg) (number? markup?)
392   "
393 This  raises  @var{arg}, by the distance @var{amount}.
394 A negative @var{amount} indicates lowering:
395 @c
396 @lilypond[verbatim,fragment,relative=1]
397  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
398 @end lilypond
399 The argument to @code{\\raise} is the vertical displacement amount,
400 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
401 raise objects in relation to their surrounding markups.
402
403 If the text object itself is positioned above or below the staff, then
404 @code{\\raise} cannot be used to move it, since the mechanism that
405 positions it next to the staff cancels any shift made with
406 @code{\\raise}. For vertical positioning, use the @code{padding}
407 and/or @code{extra-offset} properties. "
408   (ly:stencil-translate-axis (interpret-markup layout props arg)
409                              amount Y))
410
411 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
412   "Make a fraction of two markups."
413   (let* ((m1 (interpret-markup layout props arg1))
414          (m2 (interpret-markup layout props arg2)))
415     (ly:stencil-align-to! m1 X CENTER)
416     (ly:stencil-align-to! m2 X CENTER)    
417     (let* ((x1 (ly:stencil-extent m1 X))
418            (x2 (ly:stencil-extent m2 X))
419            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
420            ;; should stack mols separately, to maintain LINE on baseline
421            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
422       (ly:stencil-align-to! stack Y CENTER)
423       (ly:stencil-align-to! stack X LEFT)
424       ;; should have EX dimension
425       ;; empirical anyway
426       (ly:stencil-translate-axis stack 0.75 Y))))
427
428
429 ;; TODO: better syntax.
430
431 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
432   "Construct a note symbol, with stem.  By using fractional values for
433 @var{dir}, you can obtain longer or shorter stems."
434   (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
435          (size (chain-assoc-get 'font-size props 0))
436          (stem-length (* (magstep size) (max 3 (- log 1))))
437          (head-glyph (ly:font-get-glyph
438                       font
439                       (string-append "noteheads.s" (number->string (min log 2)))))
440          (stem-thickness 0.13)
441          (stemy (* dir stem-length))
442          (attachx (if (> dir 0)
443                       (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
444                       0))
445          (attachy (* dir 0.28))
446          (stem-glyph (and (> log 0)
447                           (ly:round-filled-box
448                            (cons attachx (+ attachx  stem-thickness))
449                            (cons (min stemy attachy)
450                                  (max stemy attachy))
451                            (/ stem-thickness 3))))
452          (dot (ly:font-get-glyph font "dots-dot"))
453          (dotwid (interval-length (ly:stencil-extent dot X)))
454          (dots (and (> dot-count 0)
455                     (apply ly:stencil-add
456                            (map (lambda (x)
457                                   (ly:stencil-translate-axis
458                                    dot  (* (+ 1 (* 2 x)) dotwid) X))
459                                 (iota dot-count 1)))))
460          (flaggl (and (> log 2)
461                       (ly:stencil-translate
462                        (ly:font-get-glyph font
463                                           (string-append "flags."
464                                                          (if (> dir 0) "u" "d")
465                                                          (number->string log)))
466                        (cons (+ attachx (/ stem-thickness 2)) stemy)))))
467     (if flaggl
468         (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
469     (if (ly:stencil? stem-glyph)
470         (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
471         (set! stem-glyph head-glyph))
472     (if (ly:stencil? dots)
473         (set! stem-glyph
474               (ly:stencil-add
475                (ly:stencil-translate-axis dots
476                                           (+ (if (and (> dir 0) (> log 2))
477                                                  (* 1.5 dotwid)
478                                                  0)
479                                              ;; huh ? why not necessary?
480                                              ;;(cdr (ly:stencil-extent head-glyph X))
481                                              dotwid)
482                                           X)
483                stem-glyph)))
484     stem-glyph))
485
486 (use-modules (ice-9 regex))
487
488 (define-public log2 
489   (let ((divisor (log 2)))
490     (lambda (z) (inexact->exact (/ (log z) divisor)))))
491
492 (define (parse-simple-duration duration-string)
493   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
494   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
495     (if (and match (string=? duration-string (match:substring match 0)))
496         (let ((len  (match:substring match 1))
497               (dots (match:substring match 2)))
498           (list (cond ((string=? len "breve")  -1)
499                       ((string=? len "longa")  -2)
500                       ((string=? len "maxima") -3)
501                       (else (log2 (string->number len))))
502                 (if dots (string-length dots) 0)))
503         (error "This is not a valid duration string:" duration-string))))
504
505 (def-markup-command (note layout props duration dir) (string? number?)
506   "This produces a note with a stem pointing in @var{dir} direction, with
507 the @var{duration} for the note head type and augmentation dots. For
508 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
509 a shortened down stem."
510   (let ((parsed (parse-simple-duration duration)))
511     (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
512
513 (def-markup-command (normal-size-super layout props arg) (markup?)
514   "Set @var{arg} in superscript with a normal font size."
515   (ly:stencil-translate-axis (interpret-markup
516                               layout
517                               props arg)
518                              (* 0.5  (chain-assoc-get 'baseline-skip props))
519                              Y))
520
521 (def-markup-command (super layout props arg) (markup?)
522   "
523 @cindex raising text
524 @cindex lowering text
525 @cindex moving text
526 @cindex translating text
527
528 @cindex @code{\\super}
529
530
531 Raising and lowering texts can be done with @code{\\super} and
532 @code{\\sub}:
533
534 @lilypond[verbatim,fragment,relative=1]
535  c1^\\markup { E \"=\" mc \\super \"2\" }
536 @end lilypond
537
538 "
539   (ly:stencil-translate-axis
540    (interpret-markup
541     layout
542     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
543     arg)
544    (* 0.5 (chain-assoc-get 'baseline-skip props))
545    Y))
546
547 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
548   "This translates an object. Its first argument is a cons of numbers
549 @example
550 A \\translate #(cons 2 -3) @{ B C @} D
551 @end example
552 This moves `B C' 2 spaces to the right, and 3 down, relative to its
553 surroundings. This command cannot be used to move isolated scripts
554 vertically, for the same reason that @code{\\raise} cannot be used for
555 that.
556
557 "
558   (ly:stencil-translate (interpret-markup  layout props arg)
559                         offset))
560
561 (def-markup-command (sub layout props arg) (markup?)
562   "Set @var{arg} in subscript."
563   (ly:stencil-translate-axis
564    (interpret-markup
565     layout
566     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
567     arg)
568    (* -0.5 (chain-assoc-get 'baseline-skip props))
569    Y))
570
571 (def-markup-command (beam layout props width slope thickness) (number? number? number?)
572   "Create a beam with the specified parameters."
573
574   (let*
575       ((y (* slope width))
576        (yext (cons (min 0 y) (max 0 y)))
577        (half (/ thickness 2)))
578        
579     (ly:make-stencil
580      (list 'beam width
581            slope
582            thickness
583            (ly:output-def-lookup layout 'blotdiameter))
584      (cons 0 width)
585      (cons (+ (- half) (car yext))
586            (+ half (cdr yext))))
587
588     ))
589
590
591 (def-markup-command (normal-size-sub layout props arg) (markup?)
592   "Set @var{arg} in subscript, in a normal font size."
593   (ly:stencil-translate-axis
594    (interpret-markup layout props arg)
595    (* -0.5 (chain-assoc-get 'baseline-skip props))
596    Y))
597
598 (def-markup-command (hbracket layout props arg) (markup?)
599   "Draw horizontal brackets around @var{arg}."  
600   (let ((th 0.1) ;; todo: take from GROB.
601         (m (interpret-markup layout props arg)))
602     (bracketify-stencil m X th (* 2.5 th) th)))
603
604 (def-markup-command (bracket layout props arg) (markup?)
605   "Draw vertical brackets around @var{arg}."  
606   (let ((th 0.1) ;; todo: take from GROB.
607         (m (interpret-markup layout props arg)))
608     (bracketify-stencil m Y th (* 2.5 th) th)))
609
610 ;; todo: fix negative space
611 (def-markup-command (hspace layout props amount) (number?)
612   "This produces a invisible object taking horizontal space.
613 @example 
614 \\markup @{ A \\hspace #2.0 B @} 
615 @end example
616 will put extra space between A and B, on top of the space that is
617 normally inserted before elements on a line.
618 "
619   (if (> amount 0)
620       (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
621       (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
622
623 (def-markup-command (override layout props new-prop arg) (pair? markup?)
624   "Add the first argument in to the property list.  Properties may be
625 any sort of property supported by @internalsref{font-interface} and
626 @internalsref{text-interface}, for example
627
628 @verbatim
629 \\override #'(font-family . married) \"bla\"
630 @end verbatim
631
632 "
633   (interpret-markup layout (cons (list new-prop) props) arg))
634
635 (def-markup-command (smaller layout props arg) (markup?)
636   "Decrease the font size relative to current setting"
637   (let* ((fs (chain-assoc-get 'font-size props 0))
638          (entry (cons 'font-size (- fs 1))))
639     (interpret-markup layout (cons (list entry) props) arg)))
640
641 (def-markup-command (bigger layout props arg) (markup?)
642   "Increase the font size relative to current setting"
643   (let* ((fs (chain-assoc-get 'font-size props 0))
644          (entry (cons 'font-size (+ fs 1))))
645     (interpret-markup layout (cons (list entry) props) arg)))
646
647 (def-markup-command larger (markup?) bigger-markup)
648
649 (def-markup-command (box layout props arg) (markup?)
650   "Draw a box round @var{arg}.  Looks at @code{thickness},
651 @code{box-padding} and @code{font-size} properties to determine line
652 thickness and padding around the markup."
653   (let* ((th (chain-assoc-get 'thickness props  0.1))
654          (size (chain-assoc-get 'font-size props 0))
655          (pad
656           (* (magstep size)
657              (chain-assoc-get 'box-padding props 0.2)))
658          (m (interpret-markup layout props arg)))
659     (box-stencil m th pad)))
660
661 ;;FIXME: is this working? 
662 (def-markup-command (strut layout props) ()
663   "Create a box of the same height as the space in the current font."
664   (let ((m (Text_interface::interpret_markup layout props " ")))
665     (ly:stencil-set-extent! m X '(1000 . -1000))
666     m))
667
668 (define number->mark-letter-vector (make-vector 25 #\A))
669
670 (do ((i 0 (1+ i))
671      (j 0 (1+ j)))
672     ((>= i 26))
673   (if (= i (- (char->integer #\I) (char->integer #\A)))
674       (set! i (1+ i)))
675   (vector-set! number->mark-letter-vector j
676                (integer->char (+ i (char->integer #\A)))))
677
678 (define number->mark-alphabet-vector (list->vector
679   (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
680
681 (define (number->markletter-string vec n)
682   "Double letters for big marks."
683   (let* ((lst (vector-length vec)))
684     
685     (if (>= n lst)
686         (string-append (number->markletter-string vec (1- (quotient n lst)))
687                        (number->markletter-string vec (remainder n lst)))
688         (make-string 1 (vector-ref vec n)))))
689
690 (def-markup-command (markletter layout props num) (integer?)
691   "Make a markup letter for @var{num}.  The letters start with A to Z
692  (skipping I), and continues with double letters."
693   (Text_interface::interpret_markup layout props
694     (number->markletter-string number->mark-letter-vector num)))
695
696 (def-markup-command (markalphabet layout props num) (integer?)
697    "Make a markup letter for @var{num}.  The letters start with A to Z
698  and continues with double letters."
699    (Text_interface::interpret_markup layout props
700      (number->markletter-string number->mark-alphabet-vector num)))
701
702 (def-markup-command (bracketed-y-column layout props indices args)
703   (list? markup-list?)
704   "Make a column of the markups in @var{args}, putting brackets around
705 the elements marked in @var{indices}, which is a list of numbers."
706   (define (sublist lst start stop)
707     (take (drop lst start) (- (1+ stop) start)))
708
709   (define (stencil-list-extent ss axis)
710     (cons
711      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
712      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
713   
714   (define (stack-stencils stencils bskip last-stencil)
715     (cond
716      ((null? stencils) '())
717      ((not (ly:stencil? last-stencil))
718       (cons (car stencils)
719             (stack-stencils (cdr stencils) bskip (car stencils))))
720      (else
721       (let* ((orig (car stencils))
722              (dir (chain-assoc-get 'direction  props DOWN))
723              (new (ly:stencil-moved-to-edge last-stencil Y dir
724                                             orig
725                                             0.1 bskip)))
726
727         (cons new (stack-stencils (cdr stencils) bskip new))))))
728
729   (define (make-brackets stencils indices acc)
730     (if (and stencils
731              (pair? indices)
732              (pair? (cdr indices)))
733         (let* ((encl (sublist stencils (car indices) (cadr indices)))
734                (x-ext (stencil-list-extent encl X))
735                (y-ext (stencil-list-extent encl Y))
736                (thick 0.10)
737                (pad 0.35)
738                (protusion (* 2.5 thick))
739                (lb
740                 (ly:stencil-translate-axis 
741                  (ly:bracket Y y-ext thick protusion)
742                  (- (car x-ext) pad) X))
743                (rb (ly:stencil-translate-axis
744                     (ly:bracket Y y-ext thick (- protusion))
745                     (+ (cdr x-ext) pad) X)))
746
747           (make-brackets
748            stencils (cddr indices)
749            (append
750             (list lb rb)
751             acc)))
752         acc))
753
754   (let* ((stencils
755           (map (lambda (x)
756                  (interpret-markup
757                   layout
758                   props
759                   x)) args))
760          (leading
761           (chain-assoc-get 'baseline-skip props))
762          (stacked (stack-stencils
763                    (remove ly:stencil-empty? stencils) 1.25 #f))
764          (brackets (make-brackets stacked indices '())))
765
766     (apply ly:stencil-add
767            (append stacked brackets))))