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