]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
* scm/output-ps.scm (utf8-string): add utf8-string for completeness.
[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--2004  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 center. "
336   (let* ((mol (interpret-markup layout props arg)))
337     (ly:stencil-align-to! mol Y CENTER)
338     mol))
339
340 (def-markup-command (right-align layout props arg) (markup?)
341   "Align @var{arg} on its right edge. "
342   (let* ((m (interpret-markup layout props arg)))
343     (ly:stencil-align-to! m X RIGHT)
344     m))
345
346 (def-markup-command (left-align layout props arg) (markup?)
347   "Align @var{arg} on its left edge. "
348   (let* ((m (interpret-markup layout props arg)))
349     (ly:stencil-align-to! m X LEFT)
350     m))
351
352 (def-markup-command (general-align layout props axis dir arg)  (integer? number? markup?)
353   "Align @var{arg} in @var{axis} direction to the @var{dir} side."
354   (let* ((m (interpret-markup layout props arg)))
355     (ly:stencil-align-to! m axis dir)
356     m))
357
358 (def-markup-command (halign layout props dir arg) (number? markup?)
359   "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
360 left-aligned, while @code{+1} is right. Values in between interpolate
361 alignment accordingly."
362   (let* ((m (interpret-markup layout props arg)))
363     (ly:stencil-align-to! m X dir)
364     m))
365
366 (def-markup-command (musicglyph layout props glyph-name) (string?)
367   "This is converted to a musical symbol, e.g. @code{\\musicglyph
368 #\"accidentals.0\"} will select the natural sign from the music font.
369 See @usermanref{The Feta font} for  a complete listing of the possible glyphs."
370   (ly:font-get-glyph
371    (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
372                                    props))
373    glyph-name))
374
375 (def-markup-command (lookup layout props glyph-name) (string?)
376   "Lookup a glyph by name."
377   (ly:font-get-glyph (ly:paper-get-font layout props)
378                      glyph-name))
379
380 (def-markup-command (char layout props num) (integer?)
381   "Produce a single character, e.g. @code{\\char #65} produces the 
382 letter 'A'."
383   (ly:get-glyph (ly:paper-get-font layout props) num))
384
385 (def-markup-command (raise layout props amount arg) (number? markup?)
386   "
387 This  raises  @var{arg}, by the distance @var{amount}.
388 A negative @var{amount} indicates lowering:
389 @c
390 @lilypond[verbatim,fragment,relative=1]
391  c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
392 @end lilypond
393 The argument to @code{\\raise} is the vertical displacement amount,
394 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
395 raise objects in relation to their surrounding markups.
396
397 If the text object itself is positioned above or below the staff, then
398 @code{\\raise} cannot be used to move it, since the mechanism that
399 positions it next to the staff cancels any shift made with
400 @code{\\raise}. For vertical positioning, use the @code{padding}
401 and/or @code{extra-offset} properties. "
402   (ly:stencil-translate-axis (interpret-markup layout props arg)
403                              amount Y))
404
405 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
406   "Make a fraction of two markups."
407   (let* ((m1 (interpret-markup layout props arg1))
408          (m2 (interpret-markup layout props arg2)))
409     (ly:stencil-align-to! m1 X CENTER)
410     (ly:stencil-align-to! m2 X CENTER)    
411     (let* ((x1 (ly:stencil-extent m1 X))
412            (x2 (ly:stencil-extent m2 X))
413            (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
414            ;; should stack mols separately, to maintain LINE on baseline
415            (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
416       (ly:stencil-align-to! stack Y CENTER)
417       (ly:stencil-align-to! stack X LEFT)
418       ;; should have EX dimension
419       ;; empirical anyway
420       (ly:stencil-translate-axis stack 0.75 Y))))
421
422
423 ;; TODO: better syntax.
424
425 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
426   "Construct a note symbol, with stem.  By using fractional values for
427 @var{dir}, you can obtain longer or shorter stems."
428   (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
429          (size (chain-assoc-get 'font-size props 0))
430          (stem-length (* (magstep size) (max 3 (- log 1))))
431          (head-glyph (ly:font-get-glyph
432                       font
433                       (string-append "noteheads.s" (number->string (min log 2)))))
434          (stem-thickness 0.13)
435          (stemy (* dir stem-length))
436          (attachx (if (> dir 0)
437                       (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
438                       0))
439          (attachy (* dir 0.28))
440          (stem-glyph (and (> log 0)
441                           (ly:round-filled-box
442                            (cons attachx (+ attachx  stem-thickness))
443                            (cons (min stemy attachy)
444                                  (max stemy attachy))
445                            (/ stem-thickness 3))))
446          (dot (ly:font-get-glyph font "dots-dot"))
447          (dotwid (interval-length (ly:stencil-extent dot X)))
448          (dots (and (> dot-count 0)
449                     (apply ly:stencil-add
450                            (map (lambda (x)
451                                   (ly:stencil-translate-axis
452                                    dot  (* (+ 1 (* 2 x)) dotwid) X))
453                                 (iota dot-count 1)))))
454          (flaggl (and (> log 2)
455                       (ly:stencil-translate
456                        (ly:font-get-glyph font
457                                           (string-append "flags."
458                                                          (if (> dir 0) "u" "d")
459                                                          (number->string log)))
460                        (cons (+ attachx (/ stem-thickness 2)) stemy)))))
461     (if flaggl
462         (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
463     (if (ly:stencil? stem-glyph)
464         (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
465         (set! stem-glyph head-glyph))
466     (if (ly:stencil? dots)
467         (set! stem-glyph
468               (ly:stencil-add
469                (ly:stencil-translate-axis dots
470                                           (+ (if (and (> dir 0) (> log 2))
471                                                  (* 1.5 dotwid)
472                                                  0)
473                                              ;; huh ? why not necessary?
474                                              ;;(cdr (ly:stencil-extent head-glyph X))
475                                              dotwid)
476                                           X)
477                stem-glyph)))
478     stem-glyph))
479
480 (use-modules (ice-9 regex))
481
482 (define-public log2 
483   (let ((divisor (log 2)))
484     (lambda (z) (inexact->exact (/ (log z) divisor)))))
485
486 (define (parse-simple-duration duration-string)
487   "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
488   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
489     (if (and match (string=? duration-string (match:substring match 0)))
490         (let ((len  (match:substring match 1))
491               (dots (match:substring match 2)))
492           (list (cond ((string=? len "breve")  -1)
493                       ((string=? len "longa")  -2)
494                       ((string=? len "maxima") -3)
495                       (else (log2 (string->number len))))
496                 (if dots (string-length dots) 0)))
497         (error "This is not a valid duration string:" duration-string))))
498
499 (def-markup-command (note layout props duration dir) (string? number?)
500   "This produces a note with a stem pointing in @var{dir} direction, with
501 the @var{duration} for the note head type and augmentation dots. For
502 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
503 a shortened down stem."
504   (let ((parsed (parse-simple-duration duration)))
505     (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
506
507 (def-markup-command (normal-size-super layout props arg) (markup?)
508   "Set @var{arg} in superscript with a normal font size."
509   (ly:stencil-translate-axis (interpret-markup
510                               layout
511                               props arg)
512                              (* 0.5  (chain-assoc-get 'baseline-skip props))
513                              Y))
514
515 (def-markup-command (super layout props arg) (markup?)
516   "
517 @cindex raising text
518 @cindex lowering text
519 @cindex moving text
520 @cindex translating text
521
522 @cindex @code{\\super}
523
524
525 Raising and lowering texts can be done with @code{\\super} and
526 @code{\\sub}:
527
528 @lilypond[verbatim,fragment,relative=1]
529  c1^\\markup { E \"=\" mc \\super \"2\" }
530 @end lilypond
531
532 "
533   (ly:stencil-translate-axis
534    (interpret-markup
535     layout
536     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
537     arg)
538    (* 0.5 (chain-assoc-get 'baseline-skip props))
539    Y))
540
541 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
542   "This translates an object. Its first argument is a cons of numbers
543 @example
544 A \\translate #(cons 2 -3) @{ B C @} D
545 @end example
546 This moves `B C' 2 spaces to the right, and 3 down, relative to its
547 surroundings. This command cannot be used to move isolated scripts
548 vertically, for the same reason that @code{\\raise} cannot be used for
549 that.
550
551 "
552   (ly:stencil-translate (interpret-markup  layout props arg)
553                         offset))
554
555 (def-markup-command (sub layout props arg) (markup?)
556   "Set @var{arg} in subscript."
557   (ly:stencil-translate-axis
558    (interpret-markup
559     layout
560     (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
561     arg)
562    (* -0.5 (chain-assoc-get 'baseline-skip props))
563    Y))
564
565 (def-markup-command (normal-size-sub layout props arg) (markup?)
566   "Set @var{arg} in subscript, in a normal font size."
567   (ly:stencil-translate-axis
568    (interpret-markup layout props arg)
569    (* -0.5 (chain-assoc-get 'baseline-skip props))
570    Y))
571
572 (def-markup-command (hbracket layout props arg) (markup?)
573   "Draw horizontal brackets around @var{arg}."  
574   (let ((th 0.1) ;; todo: take from GROB.
575         (m (interpret-markup layout props arg)))
576     (bracketify-stencil m X th (* 2.5 th) th)))
577
578 (def-markup-command (bracket layout props arg) (markup?)
579   "Draw vertical brackets around @var{arg}."  
580   (let ((th 0.1) ;; todo: take from GROB.
581         (m (interpret-markup layout props arg)))
582     (bracketify-stencil m Y th (* 2.5 th) th)))
583
584 ;; todo: fix negative space
585 (def-markup-command (hspace layout props amount) (number?)
586   "This produces a invisible object taking horizontal space.
587 @example 
588 \\markup @{ A \\hspace #2.0 B @} 
589 @end example
590 will put extra space between A and B, on top of the space that is
591 normally inserted before elements on a line.
592 "
593   (if (> amount 0)
594       (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
595       (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
596
597 (def-markup-command (override layout props new-prop arg) (pair? markup?)
598   "Add the first argument in to the property list.  Properties may be
599 any sort of property supported by @internalsref{font-interface} and
600 @internalsref{text-interface}, for example
601
602 @verbatim
603 \\override #'(font-family . married) \"bla\"
604 @end verbatim
605
606 "
607   (interpret-markup layout (cons (list new-prop) props) arg))
608
609 (def-markup-command (smaller layout props arg) (markup?)
610   "Decrease the font size relative to current setting"
611   (let* ((fs (chain-assoc-get 'font-size props 0))
612          (entry (cons 'font-size (- fs 1))))
613     (interpret-markup layout (cons (list entry) props) arg)))
614
615 (def-markup-command (bigger layout props arg) (markup?)
616   "Increase the font size relative to current setting"
617   (let* ((fs (chain-assoc-get 'font-size props 0))
618          (entry (cons 'font-size (+ fs 1))))
619     (interpret-markup layout (cons (list entry) props) arg)))
620
621 (def-markup-command larger (markup?) bigger-markup)
622
623 (def-markup-command (box layout props arg) (markup?)
624   "Draw a box round @var{arg}.  Looks at @code{thickness} and
625 @code{box-padding} properties to determine line thickness and padding
626 around the markup."
627   (let ((th (chain-assoc-get 'thickness props  0.1))
628         (pad (chain-assoc-get 'box-padding props 0.2))
629         (m (interpret-markup layout props arg)))
630     (box-stencil m th pad)))
631
632 ;;FIXME: is this working? 
633 (def-markup-command (strut layout props) ()
634   "Create a box of the same height as the space in the current font."
635   (let ((m (Text_interface::interpret_markup layout props " ")))
636     (ly:stencil-set-extent! m X '(1000 . -1000))
637     m))
638
639 (define number->mark-letter-vector (make-vector 25 #\A))
640
641 (do ((i 0 (1+ i))
642      (j 0 (1+ j)))
643     ((>= i 26))
644   (if (= i (- (char->integer #\I) (char->integer #\A)))
645       (set! i (1+ i)))
646   (vector-set! number->mark-letter-vector j
647                (integer->char (+ i (char->integer #\A)))))
648
649 (define number->mark-alphabet-vector (list->vector
650   (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
651
652 (define (number->markletter-string vec n)
653   "Double letters for big marks."
654   (let* ((lst (vector-length vec)))
655     
656     (if (>= n lst)
657         (string-append (number->markletter-string vec (1- (quotient n lst)))
658                        (number->markletter-string vec (remainder n lst)))
659         (make-string 1 (vector-ref vec n)))))
660
661 (def-markup-command (markletter layout props num) (integer?)
662   "Make a markup letter for @var{num}.  The letters start with A to Z
663  (skipping I), and continues with double letters."
664   (Text_interface::interpret_markup layout props
665     (number->markletter-string number->mark-letter-vector num)))
666
667 (def-markup-command (markalphabet layout props num) (integer?)
668    "Make a markup letter for @var{num}.  The letters start with A to Z
669  and continues with double letters."
670    (Text_interface::interpret_markup layout props
671      (number->markletter-string number->mark-alphabet-vector num)))
672
673 (def-markup-command (bracketed-y-column layout props indices args)
674   (list? markup-list?)
675   "Make a column of the markups in @var{args}, putting brackets around
676 the elements marked in @var{indices}, which is a list of numbers."
677   (define (sublist lst start stop)
678     (take (drop lst start) (- (1+ stop) start)))
679
680   (define (stencil-list-extent ss axis)
681     (cons
682      (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
683      (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
684   
685   (define (stack-stencils stencils bskip last-stencil)
686     (cond
687      ((null? stencils) '())
688      ((not (ly:stencil? last-stencil))
689       (cons (car stencils)
690             (stack-stencils (cdr stencils) bskip (car stencils))))
691      (else
692       (let* ((orig (car stencils))
693              (dir (chain-assoc-get 'direction  props DOWN))
694              (new (ly:stencil-moved-to-edge last-stencil Y dir
695                                             orig
696                                             0.1 bskip)))
697
698         (cons new (stack-stencils (cdr stencils) bskip new))))))
699
700   (define (make-brackets stencils indices acc)
701     (if (and stencils
702              (pair? indices)
703              (pair? (cdr indices)))
704         (let* ((encl (sublist stencils (car indices) (cadr indices)))
705                (x-ext (stencil-list-extent encl X))
706                (y-ext (stencil-list-extent encl Y))
707                (thick 0.10)
708                (pad 0.35)
709                (protusion (* 2.5 thick))
710                (lb
711                 (ly:stencil-translate-axis 
712                  (ly:bracket Y y-ext thick protusion)
713                  (- (car x-ext) pad) X))
714                (rb (ly:stencil-translate-axis
715                     (ly:bracket Y y-ext thick (- protusion))
716                     (+ (cdr x-ext) pad) X)))
717
718           (make-brackets
719            stencils (cddr indices)
720            (append
721             (list lb rb)
722             acc)))
723         acc))
724
725   (let* ((stencils
726           (map (lambda (x)
727                  (interpret-markup
728                   layout
729                   props
730                   x)) args))
731          (leading
732           (chain-assoc-get 'baseline-skip props))
733          (stacked (stack-stencils
734                    (remove ly:stencil-empty? stencils) 1.25 #f))
735          (brackets (make-brackets stacked indices '())))
736
737     (apply ly:stencil-add
738            (append stacked brackets))))