]> git.donarmstrong.com Git - lilypond.git/blob - scm/define-markup-commands.scm
[notation reference] One more line length fix.
[lilypond.git] / scm / define-markup-commands.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2000--2011  Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;;                  Jan Nieuwenhuizen <janneke@gnu.org>
5 ;;;;
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
10 ;;;;
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;;; GNU General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 ;;;
20 ;;; Markup commands and markup-list commands definitions.
21 ;;;
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-markup-command' macro.
25 ;;;
26 ;;; Usage:
27 ;;;
28 ;;; (define-markup-command (command-name layout props args...)
29 ;;;   args-signature
30 ;;;   [ #:category category ]
31 ;;;   [ #:properties property-bindings ]
32 ;;;   documentation-string
33 ;;;   ..body..)
34 ;;;
35 ;;; with:
36 ;;;   command-name
37 ;;;     the name of the markup command
38 ;;;
39 ;;;   layout and props
40 ;;;     arguments that are automatically passed to the command when it
41 ;;;     is interpreted.
42 ;;;     `layout' is an output def, which properties can be accessed
43 ;;;     using `ly:output-def-lookup'.
44 ;;;     `props' is a list of property settings which can be accessed
45 ;;;     using `chain-assoc-get' (more on that below)
46 ;;;
47 ;;;   args...
48 ;;;     the command arguments.
49 ;;;     There is no limitation on the order of command arguments.
50 ;;;     However, markup functions taking a markup as their last
51 ;;;     argument are somewhat special as you can apply them to a
52 ;;;     markup list, and the result is a markup list where the
53 ;;;     markup function (with the specified leading arguments) has
54 ;;;     been applied to every element of the original markup list.
55 ;;;
56 ;;;     Since replicating the leading arguments for applying a
57 ;;;     markup function to a markup list is cheap mostly for
58 ;;;     Scheme arguments, you avoid performance pitfalls by just
59 ;;;     using Scheme arguments for the leading arguments of markup
60 ;;;     functions that take a markup as their last argument.
61 ;;;
62 ;;;   args-signature
63 ;;;     the arguments signature, i.e., a list of type predicates which
64 ;;;     are used to type check the arguments, and also to define the general
65 ;;;     argument types (markup, markup-list, scheme) that the command is
66 ;;;     expecting.
67 ;;;     For instance, if a command expects a number, then a markup, the
68 ;;;     signature would be: (number? markup?)
69 ;;;
70 ;;;   category
71 ;;;     for documentation purpose, builtin markup commands are grouped by
72 ;;;     category.  This can be any symbol.  When documentation is generated,
73 ;;;     the symbol is converted to a capitalized string, where hyphens are
74 ;;;     replaced by spaces.
75 ;;;
76 ;;;   property-bindings
77 ;;;     this is used both for documentation generation, and to ease
78 ;;;     programming the command itself.  It is list of
79 ;;;        (property-name default-value)
80 ;;;     or (property-name)
81 ;;;     elements.  Each property is looked-up in the `props' argument, and
82 ;;;     the symbol naming the property is bound to its value.
83 ;;;     When the property is not found in `props', then the symbol is bound
84 ;;;     to the given default value.  When no default value is given, #f is
85 ;;;     used instead.
86 ;;;     Thus, using the following property bindings:
87 ;;;       ((thickness 0.1)
88 ;;;        (font-size 0))
89 ;;;     is equivalent to writing:
90 ;;;       (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;;             (font-size (chain-assoc-get 'font-size props 0)))
92 ;;;         ..body..)
93 ;;;     When a command `B' internally calls an other command `A', it may
94 ;;;     desirable to see in `B' documentation all the properties and
95 ;;;     default values used by `A'.  In that case, add `A-markup' to the
96 ;;;     property-bindings of B.  (This is used when generating
97 ;;;     documentation, but won't create bindings.)
98 ;;;
99 ;;;   documentation-string
100 ;;;     the command documentation string (used to generate manuals)
101 ;;;
102 ;;;   body
103 ;;;     the command body.  The function is supposed to return a stencil.
104 ;;;
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
107
108 (use-modules (ice-9 regex))
109
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111 ;; utility functions
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
113
114 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
115 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
116
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118 ;; geometric shapes
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120
121 (define-markup-command (draw-line layout props dest)
122   (number-pair?)
123   #:category graphic
124   #:properties ((thickness 1))
125   "
126 @cindex drawing lines within text
127
128 A simple line.
129 @lilypond[verbatim,quote]
130 \\markup {
131   \\draw-line #'(4 . 4)
132   \\override #'(thickness . 5)
133   \\draw-line #'(-3 . 0)
134 }
135 @end lilypond"
136   (let ((th (* (ly:output-def-lookup layout 'line-thickness)
137                thickness))
138         (x (car dest))
139         (y (cdr dest)))
140     (make-line-stencil th 0 0 x y)))
141
142 (define-markup-command (draw-hline layout props)
143   ()
144   #:category graphic
145   #:properties ((draw-line-markup)
146                 (line-width)
147                 (span-factor 1))
148   "
149 @cindex drawing a line across a page
150
151 Draws a line across a page, where the property @code{span-factor}
152 controls what fraction of the page is taken up.
153 @lilypond[verbatim,quote]
154 \\markup {
155   \\column {
156     \\draw-hline
157     \\override #'(span-factor . 1/3)
158     \\draw-hline
159   }
160 }
161 @end lilypond"
162   (interpret-markup layout
163                     props
164                     (markup #:draw-line (cons (* line-width
165                                                   span-factor)
166                                                0))))
167
168 (define-markup-command (draw-circle layout props radius thickness filled)
169   (number? number? boolean?)
170   #:category graphic
171   "
172 @cindex drawing circles within text
173
174 A circle of radius @var{radius} and thickness @var{thickness},
175 optionally filled.
176
177 @lilypond[verbatim,quote]
178 \\markup {
179   \\draw-circle #2 #0.5 ##f
180   \\hspace #2
181   \\draw-circle #2 #0 ##t
182 }
183 @end lilypond"
184   (make-circle-stencil radius thickness filled))
185
186 (define-markup-command (triangle layout props filled)
187   (boolean?)
188   #:category graphic
189   #:properties ((thickness 0.1)
190                 (font-size 0)
191                 (baseline-skip 2))
192   "
193 @cindex drawing triangles within text
194
195 A triangle, either filled or empty.
196
197 @lilypond[verbatim,quote]
198 \\markup {
199   \\triangle ##t
200   \\hspace #2
201   \\triangle ##f
202 }
203 @end lilypond"
204   (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
205     (ly:make-stencil
206      `(polygon '(0.0 0.0
207                      ,ex 0.0
208                      ,(* 0.5 ex)
209                      ,(* 0.86 ex))
210            ,thickness
211            ,filled)
212      (cons 0 ex)
213      (cons 0 (* .86 ex)))))
214
215 (define-markup-command (circle layout props arg)
216   (markup?)
217   #:category graphic
218   #:properties ((thickness 1)
219                 (font-size 0)
220                 (circle-padding 0.2))
221   "
222 @cindex circling text
223
224 Draw a circle around @var{arg}.  Use @code{thickness},
225 @code{circle-padding} and @code{font-size} properties to determine line
226 thickness and padding around the markup.
227
228 @lilypond[verbatim,quote]
229 \\markup {
230   \\circle {
231     Hi
232   }
233 }
234 @end lilypond"
235   (let ((th (* (ly:output-def-lookup layout 'line-thickness)
236                thickness))
237          (pad (* (magstep font-size) circle-padding))
238          (m (interpret-markup layout props arg)))
239     (circle-stencil m th pad)))
240
241 (define-markup-command (with-url layout props url arg)
242   (string? markup?)
243   #:category graphic
244   "
245 @cindex inserting URL links into text
246
247 Add a link to URL @var{url} around @var{arg}.  This only works in
248 the PDF backend.
249
250 @lilypond[verbatim,quote]
251 \\markup {
252   \\with-url #\"http://lilypond.org/web/\" {
253     LilyPond ... \\italic {
254       music notation for everyone
255     }
256   }
257 }
258 @end lilypond"
259   (let* ((stil (interpret-markup layout props arg))
260          (xextent (ly:stencil-extent stil X))
261          (yextent (ly:stencil-extent stil Y))
262          (old-expr (ly:stencil-expr stil))
263          (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
264
265     (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
266
267 (define-markup-command (page-link layout props page-number arg)
268   (number? markup?)
269   #:category other
270   "
271 @cindex referencing page numbers in text
272
273 Add a link to the page @var{page-number} around @var{arg}.  This only works
274 in the PDF backend.
275
276 @lilypond[verbatim,quote]
277 \\markup {
278   \\page-link #2  { \\italic { This links to page 2... } }
279 }
280 @end lilypond"
281   (let* ((stil (interpret-markup layout props arg))
282          (xextent (ly:stencil-extent stil X))
283          (yextent (ly:stencil-extent stil Y))
284          (old-expr (ly:stencil-expr stil))
285          (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
286
287     (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
288
289 (define-markup-command (with-link layout props label arg)
290   (symbol? markup?)
291   #:category other
292   "
293 @cindex referencing page labels in text
294
295 Add a link to the page holding label @var{label} around @var{arg}.  This
296 only works in the PDF backend.
297
298 @lilypond[verbatim,quote]
299 \\markup {
300   \\with-link #\"label\" {
301     \\italic { This links to the page containing the label... }
302   }
303 }
304 @end lilypond"
305   (let* ((arg-stencil (interpret-markup layout props arg))
306          (x-ext (ly:stencil-extent arg-stencil X))
307          (y-ext (ly:stencil-extent arg-stencil Y)))
308     (ly:make-stencil
309      `(delay-stencil-evaluation
310        ,(delay (ly:stencil-expr
311                 (let* ((table (ly:output-def-lookup layout 'label-page-table))
312                        (page-number (if (list? table)
313                                         (assoc-get label table)
314                                         #f))
315                        (link-expr (list 'page-link page-number
316                                         `(quote ,x-ext) `(quote ,y-ext))))
317                   (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
318 arg-stencil)))))
319      x-ext
320      y-ext)))
321
322
323 (define-markup-command (beam layout props width slope thickness)
324   (number? number? number?)
325   #:category graphic
326   "
327 @cindex drawing beams within text
328
329 Create a beam with the specified parameters.
330 @lilypond[verbatim,quote]
331 \\markup {
332   \\beam #5 #1 #2
333 }
334 @end lilypond"
335   (let* ((y (* slope width))
336          (yext (cons (min 0 y) (max 0 y)))
337          (half (/ thickness 2)))
338
339     (ly:make-stencil
340      `(polygon ',(list
341                   0 (/ thickness -2)
342                     width (+ (* width slope)  (/ thickness -2))
343                     width (+ (* width slope)  (/ thickness 2))
344                     0 (/ thickness 2))
345                ,(ly:output-def-lookup layout 'blot-diameter)
346                #t)
347      (cons 0 width)
348      (cons (+ (- half) (car yext))
349            (+ half (cdr yext))))))
350
351 (define-markup-command (underline layout props arg)
352   (markup?)
353   #:category font
354   #:properties ((thickness 1) (offset 2))
355   "
356 @cindex underlining text
357
358 Underline @var{arg}.  Looks at @code{thickness} to determine line
359 thickness, and @code{offset} to determine line y-offset.
360
361 @lilypond[verbatim,quote]
362 \\markup \\fill-line {
363   \\underline \"underlined\"
364   \\override #'(offset . 5)
365   \\override #'(thickness . 1)
366   \\underline \"underlined\"
367   \\override #'(offset . 1)
368   \\override #'(thickness . 5)
369   \\underline \"underlined\"
370 }
371 @end lilypond"
372   (let* ((thick (ly:output-def-lookup layout 'line-thickness))
373          (underline-thick (* thickness thick))
374          (markup (interpret-markup layout props arg))
375          (x1 (car (ly:stencil-extent markup X)))
376          (x2 (cdr (ly:stencil-extent markup X)))
377          (y (* thick (- offset)))
378          (line (make-line-stencil underline-thick x1 y x2 y)))
379     (ly:stencil-add markup line)))
380
381 (define-markup-command (box layout props arg)
382   (markup?)
383   #:category font
384   #:properties ((thickness 1)
385                 (font-size 0)
386                 (box-padding 0.2))
387   "
388 @cindex enclosing text within a box
389
390 Draw a box round @var{arg}.  Looks at @code{thickness},
391 @code{box-padding} and @code{font-size} properties to determine line
392 thickness and padding around the markup.
393
394 @lilypond[verbatim,quote]
395 \\markup {
396   \\override #'(box-padding . 0.5)
397   \\box
398   \\line { V. S. }
399 }
400 @end lilypond"
401   (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
402                 thickness))
403          (pad (* (magstep font-size) box-padding))
404          (m (interpret-markup layout props arg)))
405     (box-stencil m th pad)))
406
407 (define-markup-command (filled-box layout props xext yext blot)
408   (number-pair? number-pair? number?)
409   #:category graphic
410   "
411 @cindex drawing solid boxes within text
412 @cindex drawing boxes with rounded corners
413
414 Draw a box with rounded corners of dimensions @var{xext} and
415 @var{yext}.  For example,
416 @verbatim
417 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
418 @end verbatim
419 creates a box extending horizontally from -0.3 to 1.8 and
420 vertically from -0.3 up to 1.8, with corners formed from a
421 circle of diameter@tie{}0 (i.e., sharp corners).
422
423 @lilypond[verbatim,quote]
424 \\markup {
425   \\filled-box #'(0 . 4) #'(0 . 4) #0
426   \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
427   \\filled-box #'(1 . 8) #'(0 . 7) #0.2
428   \\with-color #white
429   \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
430 }
431 @end lilypond"
432   (ly:round-filled-box
433    xext yext blot))
434
435 (define-markup-command (rounded-box layout props arg)
436   (markup?)
437   #:category graphic
438   #:properties ((thickness 1)
439                 (corner-radius 1)
440                 (font-size 0)
441                 (box-padding 0.5))
442   "@cindex enclosing text in a box with rounded corners
443    @cindex drawing boxes with rounded corners around text
444 Draw a box with rounded corners around @var{arg}.  Looks at @code{thickness},
445 @code{box-padding} and @code{font-size} properties to determine line
446 thickness and padding around the markup; the @code{corner-radius} property
447 makes it possible to define another shape for the corners (default is 1).
448
449 @lilypond[quote,verbatim,relative=2]
450 c4^\\markup {
451   \\rounded-box {
452     Overtura
453   }
454 }
455 c,8. c16 c4 r
456 @end lilypond"
457   (let ((th (* (ly:output-def-lookup layout 'line-thickness)
458                thickness))
459         (pad (* (magstep font-size) box-padding))
460         (m (interpret-markup layout props arg)))
461     (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
462                     m)))
463
464 (define-markup-command (rotate layout props ang arg)
465   (number? markup?)
466   #:category align
467   "
468 @cindex rotating text
469
470 Rotate object with @var{ang} degrees around its center.
471
472 @lilypond[verbatim,quote]
473 \\markup {
474   default
475   \\hspace #2
476   \\rotate #45
477   \\line {
478     rotated 45°
479   }
480 }
481 @end lilypond"
482   (let* ((stil (interpret-markup layout props arg)))
483     (ly:stencil-rotate stil ang 0 0)))
484
485 (define-markup-command (whiteout layout props arg)
486   (markup?)
487   #:category other
488   "
489 @cindex adding a white background to text
490
491 Provide a white background for @var{arg}.
492
493 @lilypond[verbatim,quote]
494 \\markup {
495   \\combine
496     \\filled-box #'(-1 . 10) #'(-3 . 4) #1
497     \\whiteout whiteout
498 }
499 @end lilypond"
500   (stencil-whiteout (interpret-markup layout props arg)))
501
502 (define-markup-command (pad-markup layout props amount arg)
503   (number? markup?)
504   #:category align
505   "
506 @cindex padding text
507 @cindex putting space around text
508
509 Add space around a markup object.
510
511 @lilypond[verbatim,quote]
512 \\markup {
513   \\box {
514     default
515   }
516   \\hspace #2
517   \\box {
518     \\pad-markup #1 {
519       padded
520     }
521   }
522 }
523 @end lilypond"
524   (let*
525       ((stil (interpret-markup layout props arg))
526        (xext (ly:stencil-extent stil X))
527        (yext (ly:stencil-extent stil Y)))
528
529     (ly:make-stencil
530      (ly:stencil-expr stil)
531      (interval-widen xext amount)
532      (interval-widen yext amount))))
533
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
535 ;; space
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
537
538 (define-markup-command (strut layout props)
539   ()
540   #:category other
541   "
542 @cindex creating vertical spaces in text
543
544 Create a box of the same height as the space in the current font."
545   (let ((m (ly:text-interface::interpret-markup layout props " ")))
546     (ly:make-stencil (ly:stencil-expr m)
547                      '(0 . 0)
548                      (ly:stencil-extent m X)
549                      )))
550
551 ;; todo: fix negative space
552 (define-markup-command (hspace layout props amount)
553   (number?)
554   #:category align
555   #:properties ((word-space))
556   "
557 @cindex creating horizontal spaces in text
558
559 Create an invisible object taking up horizontal space @var{amount}.
560
561 @lilypond[verbatim,quote]
562 \\markup {
563   one
564   \\hspace #2
565   two
566   \\hspace #8
567   three
568 }
569 @end lilypond"
570   (let ((corrected-space (- amount word-space)))
571     (if (> corrected-space 0)
572         (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
573         (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
574
575 ;; todo: fix negative space
576 (define-markup-command (vspace layout props amount)
577  (number?)
578  #:category align
579  "
580 @cindex creating vertical spaces in text
581
582 Create an invisible object taking up vertical space
583 of @var{amount} multiplied by 3.
584
585 @lilypond[verbatim,quote]
586 \\markup {
587     \\center-column {
588     one
589     \\vspace #2
590     two
591     \\vspace #5
592     three
593   }
594 }
595 @end lilypond"
596   (let ((amount (* amount 3.0)))
597     (if (> amount 0)
598         (ly:make-stencil "" (cons 0 0) (cons 0 amount))
599         (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
600
601
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 ;; importing graphics.
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
605
606 (define-markup-command (stencil layout props stil)
607   (ly:stencil?)
608   #:category other
609   "
610 @cindex importing stencils into text
611
612 Use a stencil as markup.
613
614 @lilypond[verbatim,quote]
615 \\markup {
616   \\stencil #(make-circle-stencil 2 0 #t)
617 }
618 @end lilypond"
619   stil)
620
621 (define bbox-regexp
622   (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
623
624 (define (get-postscript-bbox string)
625   "Extract the bbox from STRING, or return #f if not present."
626   (let*
627       ((match (regexp-exec bbox-regexp string)))
628
629     (if match
630         (map (lambda (x)
631                (string->number (match:substring match x)))
632              (cdr (iota 5)))
633
634         #f)))
635
636 (define-markup-command (epsfile layout props axis size file-name)
637   (number? number? string?)
638   #:category graphic
639   "
640 @cindex inlining an Encapsulated PostScript image
641
642 Inline an EPS image.  The image is scaled along @var{axis} to
643 @var{size}.
644
645 @lilypond[verbatim,quote]
646 \\markup {
647   \\general-align #Y #DOWN {
648     \\epsfile #X #20 #\"context-example.eps\"
649     \\epsfile #Y #20 #\"context-example.eps\"
650   }
651 }
652 @end lilypond"
653   (if (ly:get-option 'safe)
654       (interpret-markup layout props "not allowed in safe")
655       (eps-file->stencil axis size file-name)
656       ))
657
658 (define-markup-command (postscript layout props str)
659   (string?)
660   #:category graphic
661   "
662 @cindex inserting PostScript directly into text
663 This inserts @var{str} directly into the output as a PostScript
664 command string.
665
666 @lilypond[verbatim,quote]
667 ringsps = #\"
668   0.15 setlinewidth
669   0.9 0.6 moveto
670   0.4 0.6 0.5 0 361 arc
671   stroke
672   1.0 0.6 0.5 0 361 arc
673   stroke
674   \"
675
676 rings = \\markup {
677   \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
678   \\postscript #ringsps
679 }
680
681 \\relative c'' {
682   c2^\\rings
683   a2_\\rings
684 }
685 @end lilypond"
686   ;; FIXME
687   (ly:make-stencil
688    (list 'embedded-ps
689          (format #f "
690 gsave currentpoint translate
691 0.1 setlinewidth
692  ~a
693 grestore
694 "
695                  str))
696    '(0 . 0) '(0 . 0)))
697
698 (define-markup-command (path layout props thickness commands) (number? list?)
699   #:category graphic
700   #:properties ((line-cap-style 'round)
701                 (line-join-style 'round)
702                 (filled #f))
703   "
704 @cindex paths, drawing
705 @cindex drawing paths
706 Draws a path with line thickness @var{thickness} according to the
707 directions given in @var{commands}.  @var{commands} is a list of
708 lists where the @code{car} of each sublist is a drawing command and
709 the @code{cdr} comprises the associated arguments for each command.
710
711 Line-cap styles and line-join styles may be customized by
712 overriding the @code{line-cap-style} and @code{line-join-style}
713 properties, respectively.  Available line-cap styles are
714 @code{'butt}, @code{'round}, and @code{'square}.  Available
715 line-join styles are @code{'miter}, @code{'round}, and
716 @code{'bevel}.
717
718 The property @code{filled} specifies whether or not the path is
719 filled with color.
720
721 There are seven commands available to use in the list
722 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
723 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
724 @code{closepath}.  Note that the commands that begin with @emph{r}
725 are the relative variants of the other three commands.
726
727 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
728 @code{rlineto} take 2 arguments; they are the X and Y coordinates
729 for the destination point.
730
731 The commands @code{curveto} and @code{rcurveto} create cubic
732 Bézier curves, and take 6 arguments; the first two are the X and Y
733 coordinates for the first control point, the second two are the X
734 and Y coordinates for the second control point, and the last two
735 are the X and Y coordinates for the destination point.
736
737 The @code{closepath} command takes zero arguments and closes the
738 current subpath in the active path.
739
740 Note that a sequence of commands @emph{must} begin with a
741 @code{moveto} or @code{rmoveto} to work with the SVG output.
742
743 @lilypond[verbatim,quote]
744 samplePath =
745   #'((moveto 0 0)
746      (lineto -1 1)
747      (lineto 1 1)
748      (lineto 1 -1)
749      (curveto -5 -5 -5 5 -1 0)
750      (closepath))
751
752 \\markup {
753   \\path #0.25 #samplePath
754 }
755 @end lilypond"
756   (let* ((half-thickness (/ thickness 2))
757          (current-point '(0 . 0))
758          (set-point (lambda (lst) (set! current-point lst)))
759          (relative? (lambda (x)
760                       (string-prefix? "r" (symbol->string (car x)))))
761          ;; For calculating extents, we want to modify the command
762          ;; list so that all coordinates are absolute.
763          (new-commands (map (lambda (x)
764                               (cond
765                                 ;; for rmoveto, rlineto
766                                 ((and (relative? x) (eq? 3 (length x)))
767                                  (let ((cp (cons
768                                              (+ (car current-point)
769                                                 (second x))
770                                              (+ (cdr current-point)
771                                                 (third x)))))
772                                    (set-point cp)
773                                    (list (car cp)
774                                          (cdr cp))))
775                                 ;; for rcurveto
776                                 ((and (relative? x) (eq? 7 (length x)))
777                                  (let* ((old-cp current-point)
778                                         (cp (cons
779                                               (+ (car old-cp)
780                                                  (sixth x))
781                                               (+ (cdr old-cp)
782                                                  (seventh x)))))
783                                    (set-point cp)
784                                    (list (+ (car old-cp) (second x))
785                                          (+ (cdr old-cp) (third x))
786                                          (+ (car old-cp) (fourth x))
787                                          (+ (cdr old-cp) (fifth x))
788                                          (car cp)
789                                          (cdr cp))))
790                                 ;; for moveto, lineto
791                                 ((eq? 3 (length x))
792                                  (set-point (cons (second x)
793                                                   (third x)))
794                                  (drop x 1))
795                                 ;; for curveto
796                                 ((eq? 7 (length x))
797                                  (set-point (cons (sixth x)
798                                                   (seventh x)))
799                                  (drop x 1))
800                                 ;; keep closepath for filtering;
801                                 ;; see `without-closepath'.
802                                 (else x)))
803                             commands))
804          ;; path-min-max does not accept 0-arg lists,
805          ;; and since closepath does not affect extents, filter
806          ;; out those commands here.
807          (without-closepath (filter (lambda (x)
808                                       (not (equal? 'closepath (car x))))
809                                     new-commands))
810          (extents (path-min-max
811                     ;; set the origin to the first moveto
812                     (list (list-ref (car without-closepath) 0)
813                           (list-ref (car without-closepath) 1))
814                     without-closepath))
815          (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
816          (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
817          (command-list (fold-right append '() commands)))
818
819     ;; account for line thickness
820     (set! X-extent (interval-widen X-extent half-thickness))
821     (set! Y-extent (interval-widen Y-extent half-thickness))
822
823     (ly:make-stencil
824       `(path ,thickness `(,@',command-list)
825              ',line-cap-style ',line-join-style ,filled)
826       X-extent
827       Y-extent)))
828
829 (define-markup-command (score layout props score)
830   (ly:score?)
831   #:category music
832   #:properties ((baseline-skip))
833   "
834 @cindex inserting music into text
835
836 Inline an image of music.
837
838 @lilypond[verbatim,quote]
839 \\markup {
840   \\score {
841     \\new PianoStaff <<
842       \\new Staff \\relative c' {
843         \\key f \\major
844         \\time 3/4
845         \\mark \\markup { Allegro }
846         f2\\p( a4)
847         c2( a4)
848         bes2( g'4)
849         f8( e) e4 r
850       }
851       \\new Staff \\relative c {
852         \\clef bass
853         \\key f \\major
854         \\time 3/4
855         f8( a c a c a
856         f c' es c es c)
857         f,( bes d bes d bes)
858         f( g bes g bes g)
859       }
860     >>
861     \\layout {
862       indent = 0.0\\cm
863       \\context {
864         \\Score
865         \\override RehearsalMark
866           #'break-align-symbols = #'(time-signature key-signature)
867         \\override RehearsalMark
868           #'self-alignment-X = #LEFT
869       }
870       \\context {
871         \\Staff
872         \\override TimeSignature
873           #'break-align-anchor-alignment = #LEFT
874       }
875     }
876   }
877 }
878 @end lilypond"
879   (let ((output (ly:score-embedded-format score layout)))
880
881     (if (ly:music-output? output)
882         (stack-stencils Y DOWN baseline-skip
883                         (map paper-system-stencil
884                              (vector->list
885                               (ly:paper-score-paper-systems output))))
886         (begin
887           (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
888           empty-stencil))))
889
890 (define-markup-command (null layout props)
891   ()
892   #:category other
893   "
894 @cindex creating empty text objects
895
896 An empty markup with extents of a single point.
897
898 @lilypond[verbatim,quote]
899 \\markup {
900   \\null
901 }
902 @end lilypond"
903   point-stencil)
904
905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
906 ;; basic formatting.
907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
908
909 (define-markup-command (simple layout props str)
910   (string?)
911   #:category font
912   "
913 @cindex simple text strings
914
915 A simple text string; @code{\\markup @{ foo @}} is equivalent with
916 @code{\\markup @{ \\simple #\"foo\" @}}.
917
918 Note: for creating standard text markup or defining new markup commands,
919 the use of @code{\\simple} is unnecessary.
920
921 @lilypond[verbatim,quote]
922 \\markup {
923   \\simple #\"simple\"
924   \\simple #\"text\"
925   \\simple #\"strings\"
926 }
927 @end lilypond"
928   (interpret-markup layout props str))
929
930 (define-markup-command (tied-lyric layout props str)
931   (string?)
932   #:category music
933   #:properties ((word-space))
934   "
935 @cindex simple text strings with tie characters
936
937 Like simple-markup, but use tie characters for @q{~} tilde symbols.
938
939 @lilypond[verbatim,quote]
940 \\markup {
941   \\tied-lyric #\"Lasciate~i monti\"
942 }
943 @end lilypond"
944   (if (string-contains str "~")
945       (let*
946           ((half-space (/ word-space 2))
947            (parts (string-split str #\~))
948            (tie-str (markup #:hspace half-space
949                             #:musicglyph "ties.lyric"
950                             #:hspace half-space))
951            (joined  (list-join parts tie-str))
952            (join-stencil (interpret-markup layout props tie-str))
953            )
954
955         (interpret-markup layout
956                           props
957                           (make-concat-markup joined)))
958       (interpret-markup layout props str)))
959
960 (define-public empty-markup
961   (make-simple-markup ""))
962
963 ;; helper for justifying lines.
964 (define (get-fill-space word-count line-width word-space text-widths)
965   "Calculate the necessary paddings between each two adjacent texts.
966   The lengths of all texts are stored in @var{text-widths}.
967   The normal formula for the padding between texts a and b is:
968   padding = line-width/(word-count - 1) - (length(a) + length(b))/2
969   The first and last padding have to be calculated specially using the
970   whole length of the first or last text.
971   All paddings are checked to be at least word-space, to ensure that
972   no texts collide.
973   Return a list of paddings."
974   (cond
975    ((null? text-widths) '())
976
977    ;; special case first padding
978    ((= (length text-widths) word-count)
979     (cons
980      (- (- (/ line-width (1- word-count)) (car text-widths))
981         (/ (car (cdr text-widths)) 2))
982      (get-fill-space word-count line-width word-space (cdr text-widths))))
983    ;; special case last padding
984    ((= (length text-widths) 2)
985     (list (- (/ line-width (1- word-count))
986              (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
987    (else
988     (let ((default-padding
989             (- (/ line-width (1- word-count))
990                (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
991       (cons
992        (if (> word-space default-padding)
993            word-space
994            default-padding)
995        (get-fill-space word-count line-width word-space (cdr text-widths)))))))
996
997 (define-markup-command (fill-line layout props args)
998   (markup-list?)
999   #:category align
1000   #:properties ((text-direction RIGHT)
1001                 (word-space 0.6)
1002                 (line-width #f))
1003   "Put @var{markups} in a horizontal line of width @var{line-width}.
1004 The markups are spaced or flushed to fill the entire line.
1005 If there are no arguments, return an empty stencil.
1006
1007 @lilypond[verbatim,quote]
1008 \\markup {
1009   \\column {
1010     \\fill-line {
1011       Words evenly spaced across the page
1012     }
1013     \\null
1014     \\fill-line {
1015       \\line { Text markups }
1016       \\line {
1017         \\italic { evenly spaced }
1018       }
1019       \\line { across the page }
1020     }
1021   }
1022 }
1023 @end lilypond"
1024   (let* ((orig-stencils (interpret-markup-list layout props args))
1025          (stencils
1026           (map (lambda (stc)
1027                  (if (ly:stencil-empty? stc)
1028                      point-stencil
1029                      stc)) orig-stencils))
1030          (text-widths
1031           (map (lambda (stc)
1032                  (if (ly:stencil-empty? stc)
1033                      0.0
1034                      (interval-length (ly:stencil-extent stc X))))
1035                stencils))
1036          (text-width (apply + text-widths))
1037          (word-count (length stencils))
1038          (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1039          (fill-space
1040           (cond
1041            ((= word-count 1)
1042             (list
1043              (/ (- line-width text-width) 2)
1044              (/ (- line-width text-width) 2)))
1045            ((= word-count 2)
1046             (list
1047              (- line-width text-width)))
1048            (else
1049             (get-fill-space word-count line-width word-space text-widths))))
1050
1051          (line-contents (if (= word-count 1)
1052                             (list
1053                              point-stencil
1054                              (car stencils)
1055                              point-stencil)
1056                             stencils)))
1057
1058     (if (null? (remove ly:stencil-empty? orig-stencils))
1059         empty-stencil
1060         (begin
1061           (if (= text-direction LEFT)
1062               (set! line-contents (reverse line-contents)))
1063           (set! line-contents
1064                 (stack-stencils-padding-list
1065                  X RIGHT fill-space line-contents))
1066           (if (> word-count 1)
1067               ;; shift s.t. stencils align on the left edge, even if
1068               ;; first stencil had negative X-extent (e.g. center-column)
1069               ;; (if word-count = 1, X-extents are already normalized in
1070               ;; the definition of line-contents)
1071               (set! line-contents
1072                     (ly:stencil-translate-axis
1073                      line-contents
1074                      (- (car (ly:stencil-extent (car stencils) X)))
1075                      X)))
1076           line-contents))))
1077
1078 (define-markup-command (line layout props args)
1079   (markup-list?)
1080   #:category align
1081   #:properties ((word-space)
1082                 (text-direction RIGHT))
1083   "Put @var{args} in a horizontal line.  The property @code{word-space}
1084 determines the space between markups in @var{args}.
1085
1086 @lilypond[verbatim,quote]
1087 \\markup {
1088   \\line {
1089     one two three
1090   }
1091 }
1092 @end lilypond"
1093   (let ((stencils (interpret-markup-list layout props args)))
1094     (if (= text-direction LEFT)
1095         (set! stencils (reverse stencils)))
1096     (stack-stencil-line
1097      word-space
1098      (remove ly:stencil-empty? stencils))))
1099
1100 (define-markup-command (concat layout props args)
1101   (markup-list?)
1102   #:category align
1103   "
1104 @cindex concatenating text
1105 @cindex ligatures in text
1106
1107 Concatenate @var{args} in a horizontal line, without spaces in between.
1108 Strings and simple markups are concatenated on the input level, allowing
1109 ligatures.  For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1110 equivalent to @code{\"fi\"}.
1111
1112 @lilypond[verbatim,quote]
1113 \\markup {
1114   \\concat {
1115     one
1116     two
1117     three
1118   }
1119 }
1120 @end lilypond"
1121   (define (concat-string-args arg-list)
1122     (fold-right (lambda (arg result-list)
1123                   (let ((result (if (pair? result-list)
1124                                     (car result-list)
1125                                   '())))
1126                     (if (and (pair? arg) (eqv? (car arg) simple-markup))
1127                       (set! arg (cadr arg)))
1128                     (if (and (string? result) (string? arg))
1129                         (cons (string-append arg result) (cdr result-list))
1130                       (cons arg result-list))))
1131                 '()
1132                 arg-list))
1133
1134   (interpret-markup layout
1135                     (prepend-alist-chain 'word-space 0 props)
1136                     (make-line-markup (if (markup-command-list? args)
1137                                           args
1138                                           (concat-string-args args)))))
1139
1140 (define (wordwrap-stencils stencils
1141                            justify base-space line-width text-dir)
1142   "Perform simple wordwrap, return stencil of each line."
1143   (define space (if justify
1144                     ;; justify only stretches lines.
1145                     (* 0.7 base-space)
1146                     base-space))
1147   (define (take-list width space stencils
1148                      accumulator accumulated-width)
1149     "Return (head-list . tail) pair, with head-list fitting into width"
1150     (if (null? stencils)
1151         (cons accumulator stencils)
1152         (let* ((first (car stencils))
1153                (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1154                (newwid (+ space first-wid accumulated-width)))
1155           (if (or (null? accumulator)
1156                   (< newwid width))
1157               (take-list width space
1158                          (cdr stencils)
1159                          (cons first accumulator)
1160                          newwid)
1161               (cons accumulator stencils)))))
1162   (let loop ((lines '())
1163              (todo stencils))
1164     (let* ((line-break (take-list line-width space todo
1165                                   '() 0.0))
1166            (line-stencils (car line-break))
1167            (space-left (- line-width
1168                           (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1169                                         line-stencils))))
1170            (line-word-space (cond ((not justify) space)
1171                                   ;; don't stretch last line of paragraph.
1172                                   ;; hmmm . bug - will overstretch the last line in some case.
1173                                   ((null? (cdr line-break))
1174                                    base-space)
1175                                   ((null? line-stencils) 0.0)
1176                                   ((null? (cdr line-stencils)) 0.0)
1177                                   (else (/ space-left (1- (length line-stencils))))))
1178            (line (stack-stencil-line line-word-space
1179                                      (if (= text-dir RIGHT)
1180                                          (reverse line-stencils)
1181                                          line-stencils))))
1182       (if (pair? (cdr line-break))
1183           (loop (cons line lines)
1184                 (cdr line-break))
1185           (begin
1186             (if (= text-dir LEFT)
1187                 (set! line
1188                       (ly:stencil-translate-axis
1189                        line
1190                        (- line-width (interval-end (ly:stencil-extent line X)))
1191                        X)))
1192             (reverse (cons line lines)))))))
1193
1194 (define-markup-list-command (wordwrap-internal layout props justify args)
1195   (boolean? markup-list?)
1196   #:properties ((line-width #f)
1197                 (word-space)
1198                 (text-direction RIGHT))
1199   "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1200   (wordwrap-stencils (remove ly:stencil-empty?
1201                              (interpret-markup-list layout props args))
1202                      justify
1203                      word-space
1204                      (or line-width
1205                          (ly:output-def-lookup layout 'line-width))
1206                      text-direction))
1207
1208 (define-markup-command (justify layout props args)
1209   (markup-list?)
1210   #:category align
1211   #:properties ((baseline-skip)
1212                 wordwrap-internal-markup-list)
1213   "
1214 @cindex justifying text
1215
1216 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1217 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1218 @var{X}@tie{}is the number of staff spaces.
1219
1220 @lilypond[verbatim,quote]
1221 \\markup {
1222   \\justify {
1223     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1224     do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1225     Ut enim ad minim veniam, quis nostrud exercitation ullamco
1226     laboris nisi ut aliquip ex ea commodo consequat.
1227   }
1228 }
1229 @end lilypond"
1230   (stack-lines DOWN 0.0 baseline-skip
1231                (wordwrap-internal-markup-list layout props #t args)))
1232
1233 (define-markup-command (wordwrap layout props args)
1234   (markup-list?)
1235   #:category align
1236   #:properties ((baseline-skip)
1237                 wordwrap-internal-markup-list)
1238   "Simple wordwrap.  Use @code{\\override #'(line-width . @var{X})} to set
1239 the line width, where @var{X} is the number of staff spaces.
1240
1241 @lilypond[verbatim,quote]
1242 \\markup {
1243   \\wordwrap {
1244     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1245     do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1246     Ut enim ad minim veniam, quis nostrud exercitation ullamco
1247     laboris nisi ut aliquip ex ea commodo consequat.
1248   }
1249 }
1250 @end lilypond"
1251   (stack-lines DOWN 0.0 baseline-skip
1252                (wordwrap-internal-markup-list layout props #f args)))
1253
1254 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1255   (boolean? string?)
1256   #:properties ((line-width)
1257                 (word-space)
1258                 (text-direction RIGHT))
1259   "Internal markup list command used to define @code{\\justify-string} and
1260 @code{\\wordwrap-string}."
1261   (let* ((para-strings (regexp-split
1262                         (string-regexp-substitute
1263                          "\r" "\n"
1264                          (string-regexp-substitute "\r\n" "\n" arg))
1265                         "\n[ \t\n]*\n[ \t\n]*"))
1266          (list-para-words (map (lambda (str)
1267                                  (regexp-split str "[ \t\n]+"))
1268                                para-strings))
1269          (para-lines (map (lambda (words)
1270                             (let* ((stencils
1271                                     (remove ly:stencil-empty?
1272                                             (map (lambda (x)
1273                                                    (interpret-markup layout props x))
1274                                                  words))))
1275                               (wordwrap-stencils stencils
1276                                                  justify word-space
1277                                                  line-width text-direction)))
1278                           list-para-words)))
1279     (apply append para-lines)))
1280
1281 (define-markup-command (wordwrap-string layout props arg)
1282   (string?)
1283   #:category align
1284   #:properties ((baseline-skip)
1285                 wordwrap-string-internal-markup-list)
1286   "Wordwrap a string.  Paragraphs may be separated with double newlines.
1287
1288 @lilypond[verbatim,quote]
1289 \\markup {
1290   \\override #'(line-width . 40)
1291   \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1292       adipisicing elit, sed do eiusmod tempor incididunt ut labore
1293       et dolore magna aliqua.
1294
1295
1296       Ut enim ad minim veniam, quis nostrud exercitation ullamco
1297       laboris nisi ut aliquip ex ea commodo consequat.
1298
1299
1300       Excepteur sint occaecat cupidatat non proident, sunt in culpa
1301       qui officia deserunt mollit anim id est laborum\"
1302 }
1303 @end lilypond"
1304   (stack-lines DOWN 0.0 baseline-skip
1305                (wordwrap-string-internal-markup-list layout props #f arg)))
1306
1307 (define-markup-command (justify-string layout props arg)
1308   (string?)
1309   #:category align
1310   #:properties ((baseline-skip)
1311                 wordwrap-string-internal-markup-list)
1312   "Justify a string.  Paragraphs may be separated with double newlines
1313
1314 @lilypond[verbatim,quote]
1315 \\markup {
1316   \\override #'(line-width . 40)
1317   \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1318       adipisicing elit, sed do eiusmod tempor incididunt ut labore
1319       et dolore magna aliqua.
1320
1321
1322       Ut enim ad minim veniam, quis nostrud exercitation ullamco
1323       laboris nisi ut aliquip ex ea commodo consequat.
1324
1325
1326       Excepteur sint occaecat cupidatat non proident, sunt in culpa
1327       qui officia deserunt mollit anim id est laborum\"
1328 }
1329 @end lilypond"
1330   (stack-lines DOWN 0.0 baseline-skip
1331                (wordwrap-string-internal-markup-list layout props #t arg)))
1332
1333 (define-markup-command (wordwrap-field layout props symbol)
1334   (symbol?)
1335   #:category align
1336   "Wordwrap the data which has been assigned to @var{symbol}.
1337
1338 @lilypond[verbatim,quote]
1339 \\header {
1340   title = \"My title\"
1341   myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1342     elit, sed do eiusmod tempor incididunt ut labore et dolore
1343     magna aliqua.  Ut enim ad minim veniam, quis nostrud
1344     exercitation ullamco laboris nisi ut aliquip ex ea commodo
1345     consequat.\"
1346 }
1347
1348 \\paper {
1349   bookTitleMarkup = \\markup {
1350     \\column {
1351       \\fill-line { \\fromproperty #'header:title }
1352       \\null
1353       \\wordwrap-field #'header:myText
1354     }
1355   }
1356 }
1357
1358 \\markup {
1359   \\null
1360 }
1361 @end lilypond"
1362   (let* ((m (chain-assoc-get symbol props)))
1363     (if (string? m)
1364         (wordwrap-string-markup layout props m)
1365         empty-stencil)))
1366
1367 (define-markup-command (justify-field layout props symbol)
1368   (symbol?)
1369   #:category align
1370   "Justify the data which has been assigned to @var{symbol}.
1371
1372 @lilypond[verbatim,quote]
1373 \\header {
1374   title = \"My title\"
1375   myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1376     elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1377     aliqua.  Ut enim ad minim veniam, quis nostrud exercitation ullamco
1378     laboris nisi ut aliquip ex ea commodo consequat.\"
1379 }
1380
1381 \\paper {
1382   bookTitleMarkup = \\markup {
1383     \\column {
1384       \\fill-line { \\fromproperty #'header:title }
1385       \\null
1386       \\justify-field #'header:myText
1387     }
1388   }
1389 }
1390
1391 \\markup {
1392   \\null
1393 }
1394 @end lilypond"
1395   (let* ((m (chain-assoc-get symbol props)))
1396     (if (string? m)
1397         (justify-string-markup layout props m)
1398         empty-stencil)))
1399
1400 (define-markup-command (combine layout props arg1 arg2)
1401   (markup? markup?)
1402   #:category align
1403   "
1404 @cindex merging text
1405
1406 Print two markups on top of each other.
1407
1408 Note: @code{\\combine} cannot take a list of markups enclosed in
1409 curly braces as an argument; the follow example will not compile:
1410
1411 @example
1412 \\combine @{ a list @}
1413 @end example
1414
1415 @lilypond[verbatim,quote]
1416 \\markup {
1417   \\fontsize #5
1418   \\override #'(thickness . 2)
1419   \\combine
1420     \\draw-line #'(0 . 4)
1421     \\arrow-head #Y #DOWN ##f
1422 }
1423 @end lilypond"
1424   (let* ((s1 (interpret-markup layout props arg1))
1425          (s2 (interpret-markup layout props arg2)))
1426     (ly:stencil-add s1 s2)))
1427
1428 ;;
1429 ;; TODO: should extract baseline-skip from each argument somehow..
1430 ;;
1431 (define-markup-command (column layout props args)
1432   (markup-list?)
1433   #:category align
1434   #:properties ((baseline-skip))
1435   "
1436 @cindex stacking text in a column
1437
1438 Stack the markups in @var{args} vertically.  The property
1439 @code{baseline-skip} determines the space between markups
1440 in @var{args}.
1441
1442 @lilypond[verbatim,quote]
1443 \\markup {
1444   \\column {
1445     one
1446     two
1447     three
1448   }
1449 }
1450 @end lilypond"
1451   (let ((arg-stencils (interpret-markup-list layout props args)))
1452     (stack-lines -1 0.0 baseline-skip
1453                  (remove ly:stencil-empty? arg-stencils))))
1454
1455 (define-markup-command (dir-column layout props args)
1456   (markup-list?)
1457   #:category align
1458   #:properties ((direction)
1459                 (baseline-skip))
1460   "
1461 @cindex changing direction of text columns
1462
1463 Make a column of @var{args}, going up or down, depending on the
1464 setting of the @code{direction} layout property.
1465
1466 @lilypond[verbatim,quote]
1467 \\markup {
1468   \\override #`(direction . ,UP) {
1469     \\dir-column {
1470       going up
1471     }
1472   }
1473   \\hspace #1
1474   \\dir-column {
1475     going down
1476   }
1477   \\hspace #1
1478   \\override #'(direction . 1) {
1479     \\dir-column {
1480       going up
1481     }
1482   }
1483 }
1484 @end lilypond"
1485   (stack-lines (if (number? direction) direction -1)
1486                0.0
1487                baseline-skip
1488                (interpret-markup-list layout props args)))
1489
1490 (define (general-column align-dir baseline mols)
1491   "Stack @var{mols} vertically, aligned to  @var{align-dir} horizontally."
1492
1493   (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1494          (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1495          (stacked-extent (ly:stencil-extent stacked-stencil X)))
1496     (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1497
1498 (define-markup-command (center-column layout props args)
1499   (markup-list?)
1500   #:category align
1501   #:properties ((baseline-skip))
1502   "
1503 @cindex centering a column of text
1504
1505 Put @code{args} in a centered column.
1506
1507 @lilypond[verbatim,quote]
1508 \\markup {
1509   \\center-column {
1510     one
1511     two
1512     three
1513   }
1514 }
1515 @end lilypond"
1516   (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1517
1518 (define-markup-command (left-column layout props args)
1519   (markup-list?)
1520   #:category align
1521   #:properties ((baseline-skip))
1522  "
1523 @cindex text columns, left-aligned
1524
1525 Put @code{args} in a left-aligned column.
1526
1527 @lilypond[verbatim,quote]
1528 \\markup {
1529   \\left-column {
1530     one
1531     two
1532     three
1533   }
1534 }
1535 @end lilypond"
1536   (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1537
1538 (define-markup-command (right-column layout props args)
1539   (markup-list?)
1540   #:category align
1541   #:properties ((baseline-skip))
1542  "
1543 @cindex text columns, right-aligned
1544
1545 Put @code{args} in a right-aligned column.
1546
1547 @lilypond[verbatim,quote]
1548 \\markup {
1549   \\right-column {
1550     one
1551     two
1552     three
1553   }
1554 }
1555 @end lilypond"
1556   (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1557
1558 (define-markup-command (vcenter layout props arg)
1559   (markup?)
1560   #:category align
1561   "
1562 @cindex vertically centering text
1563
1564 Align @code{arg} to its Y@tie{}center.
1565
1566 @lilypond[verbatim,quote]
1567 \\markup {
1568   one
1569   \\vcenter
1570   two
1571   three
1572 }
1573 @end lilypond"
1574   (let* ((mol (interpret-markup layout props arg)))
1575     (ly:stencil-aligned-to mol Y CENTER)))
1576
1577 (define-markup-command (center-align layout props arg)
1578   (markup?)
1579   #:category align
1580   "
1581 @cindex horizontally centering text
1582
1583 Align @code{arg} to its X@tie{}center.
1584
1585 @lilypond[verbatim,quote]
1586 \\markup {
1587   \\column {
1588     one
1589     \\center-align
1590     two
1591     three
1592   }
1593 }
1594 @end lilypond"
1595   (let* ((mol (interpret-markup layout props arg)))
1596     (ly:stencil-aligned-to mol X CENTER)))
1597
1598 (define-markup-command (right-align layout props arg)
1599   (markup?)
1600   #:category align
1601   "
1602 @cindex right aligning text
1603
1604 Align @var{arg} on its right edge.
1605
1606 @lilypond[verbatim,quote]
1607 \\markup {
1608   \\column {
1609     one
1610     \\right-align
1611     two
1612     three
1613   }
1614 }
1615 @end lilypond"
1616   (let* ((m (interpret-markup layout props arg)))
1617     (ly:stencil-aligned-to m X RIGHT)))
1618
1619 (define-markup-command (left-align layout props arg)
1620   (markup?)
1621   #:category align
1622   "
1623 @cindex left aligning text
1624
1625 Align @var{arg} on its left edge.
1626
1627 @lilypond[verbatim,quote]
1628 \\markup {
1629   \\column {
1630     one
1631     \\left-align
1632     two
1633     three
1634   }
1635 }
1636 @end lilypond"
1637   (let* ((m (interpret-markup layout props arg)))
1638     (ly:stencil-aligned-to m X LEFT)))
1639
1640 (define-markup-command (general-align layout props axis dir arg)
1641   (integer? number? markup?)
1642   #:category align
1643   "
1644 @cindex controlling general text alignment
1645
1646 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1647
1648 @lilypond[verbatim,quote]
1649 \\markup {
1650   \\column {
1651     one
1652     \\general-align #X #LEFT
1653     two
1654     three
1655     \\null
1656     one
1657     \\general-align #X #CENTER
1658     two
1659     three
1660     \\null
1661     \\line {
1662       one
1663       \\general-align #Y #UP
1664       two
1665       three
1666     }
1667     \\null
1668     \\line {
1669       one
1670       \\general-align #Y #3.2
1671       two
1672       three
1673     }
1674   }
1675 }
1676 @end lilypond"
1677   (let* ((m (interpret-markup layout props arg)))
1678     (ly:stencil-aligned-to m axis dir)))
1679
1680 (define-markup-command (halign layout props dir arg)
1681   (number? markup?)
1682   #:category align
1683   "
1684 @cindex setting horizontal text alignment
1685
1686 Set horizontal alignment.  If @var{dir} is @code{-1}, then it is
1687 left-aligned, while @code{+1} is right.  Values in between interpolate
1688 alignment accordingly.
1689
1690 @lilypond[verbatim,quote]
1691 \\markup {
1692   \\column {
1693     one
1694     \\halign #LEFT
1695     two
1696     three
1697     \\null
1698     one
1699     \\halign #CENTER
1700     two
1701     three
1702     \\null
1703     one
1704     \\halign #RIGHT
1705     two
1706     three
1707     \\null
1708     one
1709     \\halign #-5
1710     two
1711     three
1712   }
1713 }
1714 @end lilypond"
1715   (let* ((m (interpret-markup layout props arg)))
1716     (ly:stencil-aligned-to m X dir)))
1717
1718 (define-markup-command (with-dimensions layout props x y arg)
1719   (number-pair? number-pair? markup?)
1720   #:category other
1721   "
1722 @cindex setting extent of text objects
1723
1724 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1725   (let* ((m (interpret-markup layout props arg)))
1726     (ly:make-stencil (ly:stencil-expr m) x y)))
1727
1728 (define-markup-command (pad-around layout props amount arg)
1729   (number? markup?)
1730   #:category align
1731   "Add padding @var{amount} all around @var{arg}.
1732
1733 @lilypond[verbatim,quote]
1734 \\markup {
1735   \\box {
1736     default
1737   }
1738   \\hspace #2
1739   \\box {
1740     \\pad-around #0.5 {
1741       padded
1742     }
1743   }
1744 }
1745 @end lilypond"
1746   (let* ((m (interpret-markup layout props arg))
1747          (x (ly:stencil-extent m X))
1748          (y (ly:stencil-extent m Y)))
1749     (ly:make-stencil (ly:stencil-expr m)
1750                      (interval-widen x amount)
1751                      (interval-widen y amount))))
1752
1753 (define-markup-command (pad-x layout props amount arg)
1754   (number? markup?)
1755   #:category align
1756   "
1757 @cindex padding text horizontally
1758
1759 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1760
1761 @lilypond[verbatim,quote]
1762 \\markup {
1763   \\box {
1764     default
1765   }
1766   \\hspace #4
1767   \\box {
1768     \\pad-x #2 {
1769       padded
1770     }
1771   }
1772 }
1773 @end lilypond"
1774   (let* ((m (interpret-markup layout props arg))
1775          (x (ly:stencil-extent m X))
1776          (y (ly:stencil-extent m Y)))
1777     (ly:make-stencil (ly:stencil-expr m)
1778                      (interval-widen x amount)
1779                      y)))
1780
1781 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1782   (integer? ly:dir? markup? markup?)
1783   #:category align
1784   "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1785   (let ((m1 (interpret-markup layout props arg1))
1786         (m2 (interpret-markup layout props arg2)))
1787     (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1788
1789 (define-markup-command (transparent layout props arg)
1790   (markup?)
1791   #:category other
1792   "Make @var{arg} transparent.
1793
1794 @lilypond[verbatim,quote]
1795 \\markup {
1796   \\transparent {
1797     invisible text
1798   }
1799 }
1800 @end lilypond"
1801   (let* ((m (interpret-markup layout props arg))
1802          (x (ly:stencil-extent m X))
1803          (y (ly:stencil-extent m Y)))
1804     (ly:make-stencil "" x y)))
1805
1806 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1807   (number-pair? number-pair? markup?)
1808   #:category align
1809   "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1810
1811 @lilypond[verbatim,quote]
1812 \\markup {
1813   \\box {
1814     default
1815   }
1816   \\hspace #4
1817   \\box {
1818     \\pad-to-box #'(0 . 10) #'(0 . 3) {
1819       padded
1820     }
1821   }
1822 }
1823 @end lilypond"
1824   (let* ((m (interpret-markup layout props arg))
1825          (x (ly:stencil-extent m X))
1826          (y (ly:stencil-extent m Y)))
1827     (ly:make-stencil (ly:stencil-expr m)
1828                      (interval-union x-ext x)
1829                      (interval-union y-ext y))))
1830
1831 (define-markup-command (hcenter-in layout props length arg)
1832   (number? markup?)
1833   #:category align
1834   "Center @var{arg} horizontally within a box of extending
1835 @var{length}/2 to the left and right.
1836
1837 @lilypond[quote,verbatim]
1838 \\new StaffGroup <<
1839   \\new Staff {
1840     \\set Staff.instrumentName = \\markup {
1841       \\hcenter-in #12
1842       Oboe
1843     }
1844     c''1
1845   }
1846   \\new Staff {
1847     \\set Staff.instrumentName = \\markup {
1848       \\hcenter-in #12
1849       Bassoon
1850     }
1851     \\clef tenor
1852     c'1
1853   }
1854 >>
1855 @end lilypond"
1856   (interpret-markup layout props
1857                     (make-pad-to-box-markup
1858                      (cons (/ length -2) (/ length 2))
1859                      '(0 . 0)
1860                      (make-center-align-markup arg))))
1861
1862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1863 ;; property
1864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1865
1866 (define-markup-command (fromproperty layout props symbol)
1867   (symbol?)
1868   #:category other
1869   "Read the @var{symbol} from property settings, and produce a stencil
1870 from the markup contained within.  If @var{symbol} is not defined, it
1871 returns an empty markup.
1872
1873 @lilypond[verbatim,quote]
1874 \\header {
1875   myTitle = \"myTitle\"
1876   title = \\markup {
1877     from
1878     \\italic
1879     \\fromproperty #'header:myTitle
1880   }
1881 }
1882 \\markup {
1883   \\null
1884 }
1885 @end lilypond"
1886   (let ((m (chain-assoc-get symbol props)))
1887     (if (markup? m)
1888         (interpret-markup layout props m)
1889         empty-stencil)))
1890
1891 (define-markup-command (on-the-fly layout props procedure arg)
1892   (symbol? markup?)
1893   #:category other
1894   "Apply the @var{procedure} markup command to @var{arg}.
1895 @var{procedure} should take a single argument."
1896   (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1897     (set-object-property! anonymous-with-signature
1898                           'markup-signature
1899                           (list markup?))
1900     (interpret-markup layout props (list anonymous-with-signature arg))))
1901
1902 (define-markup-command (footnote layout props mkup note)
1903   (markup? markup?)
1904   #:category other
1905   #:properties ((raise 0.5)
1906                 (padding 0.0))
1907   "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
1908
1909 @lilypond[verbatim,quote]
1910 \\markup {
1911   \\footnote a b
1912   \\override #'(padding . 0.2)
1913   \\footnote c d
1914 }
1915 @end lilypond"
1916   (let* ((markup-stencil (interpret-markup layout props mkup))
1917          (auto-numbering (ly:output-def-lookup layout
1918                                                'footnote-auto-numbering))
1919          (footnote-hash (gensym "footnote"))
1920          (stencil-seed 0)
1921          (gauge-stencil (if auto-numbering
1922                             (interpret-markup
1923                               layout
1924                               props
1925                               ((ly:output-def-lookup
1926                                  layout
1927                                  'footnote-numbering-function)
1928                                 stencil-seed))
1929                             empty-stencil))
1930          (x-ext (if auto-numbering
1931                     (ly:stencil-extent gauge-stencil X)
1932                     '(0 . 0)))
1933          (y-ext (if auto-numbering
1934                     (ly:stencil-extent gauge-stencil Y)
1935                     '(0 . 0)))
1936          (footnote-number
1937            (if auto-numbering
1938              `(delay-stencil-evaluation
1939                 ,(delay
1940                   (ly:stencil-expr
1941                     (let* ((table
1942                             (ly:output-def-lookup layout
1943                                                   'number-footnote-table))
1944                            (footnote-stencil (if (list? table)
1945                                                  (assoc-get footnote-hash
1946                                                             table)
1947                                                  empty-stencil))
1948                            (footnote-stencil (if (ly:stencil? footnote-stencil)
1949                                                  footnote-stencil
1950                                                  (begin
1951                                                    (ly:programming-error
1952 "Cannot find correct footnote for a markup object.")
1953                                                    empty-stencil)))
1954                            (gap (- (interval-length x-ext)
1955                                    (interval-length
1956                                      (ly:stencil-extent footnote-stencil X))))
1957                            (y-trans (- (+ (cdr y-ext)
1958                                           raise)
1959                                        (cdr (ly:stencil-extent footnote-stencil
1960                                                                Y)))))
1961                       (ly:stencil-translate footnote-stencil
1962                                             (cons gap y-trans))))))
1963              '()))
1964          (main-stencil (ly:stencil-combine-at-edge
1965                          markup-stencil
1966                          X
1967                          RIGHT
1968                          (ly:make-stencil footnote-number x-ext y-ext)
1969                          padding)))
1970   (ly:stencil-add
1971     main-stencil
1972     (ly:make-stencil
1973       `(footnote ,footnote-hash ,(interpret-markup layout props note))
1974       '(0 . 0)
1975       '(0 . 0)))))
1976
1977 (define-markup-command (override layout props new-prop arg)
1978   (pair? markup?)
1979   #:category other
1980   "
1981 @cindex overriding properties within text markup
1982
1983 Add the argument @var{new-prop} to the property list.  Properties
1984 may be any property supported by @rinternals{font-interface},
1985 @rinternals{text-interface} and
1986 @rinternals{instrument-specific-markup-interface}.
1987
1988 @lilypond[verbatim,quote]
1989 \\markup {
1990   \\line {
1991     \\column {
1992       default
1993       baseline-skip
1994     }
1995     \\hspace #2
1996     \\override #'(baseline-skip . 4) {
1997       \\column {
1998         increased
1999         baseline-skip
2000       }
2001     }
2002   }
2003 }
2004 @end lilypond"
2005   (interpret-markup layout (cons (list new-prop) props) arg))
2006
2007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2008 ;; files
2009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2010
2011 (define-markup-command (verbatim-file layout props name)
2012   (string?)
2013   #:category other
2014   "Read the contents of file @var{name}, and include it verbatim.
2015
2016 @lilypond[verbatim,quote]
2017 \\markup {
2018   \\verbatim-file #\"simple.ly\"
2019 }
2020 @end lilypond"
2021   (interpret-markup layout props
2022                     (if  (ly:get-option 'safe)
2023                          "verbatim-file disabled in safe mode"
2024                          (let* ((str (ly:gulp-file name))
2025                                 (lines (string-split str #\nl)))
2026                            (make-typewriter-markup
2027                             (make-column-markup lines))))))
2028
2029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030 ;; fonts.
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032
2033
2034 (define-markup-command (smaller layout props arg)
2035   (markup?)
2036   #:category font
2037   "Decrease the font size relative to the current setting.
2038
2039 @lilypond[verbatim,quote]
2040 \\markup {
2041   \\fontsize #3.5 {
2042     some large text
2043     \\hspace #2
2044     \\smaller {
2045       a bit smaller
2046     }
2047     \\hspace #2
2048     more large text
2049   }
2050 }
2051 @end lilypond"
2052   (interpret-markup layout props
2053    `(,fontsize-markup -1 ,arg)))
2054
2055 (define-markup-command (larger layout props arg)
2056   (markup?)
2057   #:category font
2058   "Increase the font size relative to the current setting.
2059
2060 @lilypond[verbatim,quote]
2061 \\markup {
2062   default
2063   \\hspace #2
2064   \\larger
2065   larger
2066 }
2067 @end lilypond"
2068   (interpret-markup layout props
2069    `(,fontsize-markup 1 ,arg)))
2070
2071 (define-markup-command (finger layout props arg)
2072   (markup?)
2073   #:category font
2074   "Set @var{arg} as small numbers.
2075
2076 @lilypond[verbatim,quote]
2077 \\markup {
2078   \\finger {
2079     1 2 3 4 5
2080   }
2081 }
2082 @end lilypond"
2083   (interpret-markup layout
2084                     (cons '((font-size . -5) (font-encoding . fetaText)) props)
2085                     arg))
2086
2087 (define-markup-command (abs-fontsize layout props size arg)
2088   (number? markup?)
2089   #:category font
2090   "Use @var{size} as the absolute font size to display @var{arg}.
2091 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2092
2093 @lilypond[verbatim,quote]
2094 \\markup {
2095   default text font size
2096   \\hspace #2
2097   \\abs-fontsize #16 { text font size 16 }
2098   \\hspace #2
2099   \\abs-fontsize #12 { text font size 12 }
2100 }
2101 @end lilypond"
2102   (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2103          (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2104          (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2105          (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2106          (magnification (/ size ref-size)))
2107     (interpret-markup layout
2108                       (cons `((baseline-skip . ,(* magnification ref-baseline))
2109                               (word-space . ,(* magnification ref-word-space))
2110                               (font-size . ,(magnification->font-size magnification)))
2111                             props)
2112                       arg)))
2113
2114 (define-markup-command (fontsize layout props increment arg)
2115   (number? markup?)
2116   #:category font
2117   #:properties ((font-size 0)
2118                 (word-space 1)
2119                 (baseline-skip 2))
2120   "Add @var{increment} to the font-size.  Adjusts @code{baseline-skip}
2121 accordingly.
2122
2123 @lilypond[verbatim,quote]
2124 \\markup {
2125   default
2126   \\hspace #2
2127   \\fontsize #-1.5
2128   smaller
2129 }
2130 @end lilypond"
2131   (let ((entries (list
2132                   (cons 'baseline-skip (* baseline-skip (magstep increment)))
2133                   (cons 'word-space (* word-space (magstep increment)))
2134                   (cons 'font-size (+ font-size increment)))))
2135     (interpret-markup layout (cons entries props) arg)))
2136
2137 (define-markup-command (magnify layout props sz arg)
2138   (number? markup?)
2139   #:category font
2140   "
2141 @cindex magnifying text
2142
2143 Set the font magnification for its argument.  In the following
2144 example, the middle@tie{}A is 10% larger:
2145
2146 @example
2147 A \\magnify #1.1 @{ A @} A
2148 @end example
2149
2150 Note: Magnification only works if a font name is explicitly selected.
2151 Use @code{\\fontsize} otherwise.
2152
2153 @lilypond[verbatim,quote]
2154 \\markup {
2155   default
2156   \\hspace #2
2157   \\magnify #1.5 {
2158     50% larger
2159   }
2160 }
2161 @end lilypond"
2162   (interpret-markup
2163    layout
2164    (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2165    arg))
2166
2167 (define-markup-command (bold layout props arg)
2168   (markup?)
2169   #:category font
2170   "Switch to bold font-series.
2171
2172 @lilypond[verbatim,quote]
2173 \\markup {
2174   default
2175   \\hspace #2
2176   \\bold
2177   bold
2178 }
2179 @end lilypond"
2180   (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2181
2182 (define-markup-command (sans layout props arg)
2183   (markup?)
2184   #:category font
2185   "Switch to the sans serif font family.
2186
2187 @lilypond[verbatim,quote]
2188 \\markup {
2189   default
2190   \\hspace #2
2191   \\sans {
2192     sans serif
2193   }
2194 }
2195 @end lilypond"
2196   (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2197
2198 (define-markup-command (number layout props arg)
2199   (markup?)
2200   #:category font
2201   "Set font family to @code{number}, which yields the font used for
2202 time signatures and fingerings.  This font contains numbers and
2203 some punctuation; it has no letters.
2204
2205 @lilypond[verbatim,quote]
2206 \\markup {
2207   \\number {
2208     0 1 2 3 4 5 6 7 8 9 . ,
2209   }
2210 }
2211 @end lilypond"
2212   (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2213
2214 (define-markup-command (roman layout props arg)
2215   (markup?)
2216   #:category font
2217   "Set font family to @code{roman}.
2218
2219 @lilypond[verbatim,quote]
2220 \\markup {
2221   \\sans \\bold {
2222     sans serif, bold
2223     \\hspace #2
2224     \\roman {
2225       text in roman font family
2226     }
2227     \\hspace #2
2228     return to sans
2229   }
2230 }
2231 @end lilypond"
2232   (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2233
2234 (define-markup-command (huge layout props arg)
2235   (markup?)
2236   #:category font
2237   "Set font size to +2.
2238
2239 @lilypond[verbatim,quote]
2240 \\markup {
2241   default
2242   \\hspace #2
2243   \\huge
2244   huge
2245 }
2246 @end lilypond"
2247   (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2248
2249 (define-markup-command (large layout props arg)
2250   (markup?)
2251   #:category font
2252   "Set font size to +1.
2253
2254 @lilypond[verbatim,quote]
2255 \\markup {
2256   default
2257   \\hspace #2
2258   \\large
2259   large
2260 }
2261 @end lilypond"
2262   (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2263
2264 (define-markup-command (normalsize layout props arg)
2265   (markup?)
2266   #:category font
2267   "Set font size to default.
2268
2269 @lilypond[verbatim,quote]
2270 \\markup {
2271   \\teeny {
2272     this is very small
2273     \\hspace #2
2274     \\normalsize {
2275       normal size
2276     }
2277     \\hspace #2
2278     teeny again
2279   }
2280 }
2281 @end lilypond"
2282   (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2283
2284 (define-markup-command (small layout props arg)
2285   (markup?)
2286   #:category font
2287   "Set font size to -1.
2288
2289 @lilypond[verbatim,quote]
2290 \\markup {
2291   default
2292   \\hspace #2
2293   \\small
2294   small
2295 }
2296 @end lilypond"
2297   (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2298
2299 (define-markup-command (tiny layout props arg)
2300   (markup?)
2301   #:category font
2302   "Set font size to -2.
2303
2304 @lilypond[verbatim,quote]
2305 \\markup {
2306   default
2307   \\hspace #2
2308   \\tiny
2309   tiny
2310 }
2311 @end lilypond"
2312   (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2313
2314 (define-markup-command (teeny layout props arg)
2315   (markup?)
2316   #:category font
2317   "Set font size to -3.
2318
2319 @lilypond[verbatim,quote]
2320 \\markup {
2321   default
2322   \\hspace #2
2323   \\teeny
2324   teeny
2325 }
2326 @end lilypond"
2327   (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2328
2329 (define-markup-command (fontCaps layout props arg)
2330   (markup?)
2331   #:category font
2332   "Set @code{font-shape} to @code{caps}
2333
2334 Note: @code{\\fontCaps} requires the installation and selection of
2335 fonts which support the @code{caps} font shape."
2336   (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2337
2338 ;; Poor man's caps
2339 (define-markup-command (smallCaps layout props arg)
2340   (markup?)
2341   #:category font
2342   "Emit @var{arg} as small caps.
2343
2344 Note: @code{\\smallCaps} does not support accented characters.
2345
2346 @lilypond[verbatim,quote]
2347 \\markup {
2348   default
2349   \\hspace #2
2350   \\smallCaps {
2351     Text in small caps
2352   }
2353 }
2354 @end lilypond"
2355   (define (char-list->markup chars lower)
2356     (let ((final-string (string-upcase (reverse-list->string chars))))
2357       (if lower
2358           (markup #:fontsize -2 final-string)
2359           final-string)))
2360   (define (make-small-caps rest-chars currents current-is-lower prev-result)
2361     (if (null? rest-chars)
2362         (make-concat-markup
2363           (reverse! (cons (char-list->markup currents current-is-lower)
2364                           prev-result)))
2365         (let* ((ch (car rest-chars))
2366                (is-lower (char-lower-case? ch)))
2367           (if (or (and current-is-lower is-lower)
2368                   (and (not current-is-lower) (not is-lower)))
2369               (make-small-caps (cdr rest-chars)
2370                                (cons ch currents)
2371                                is-lower
2372                                prev-result)
2373               (make-small-caps (cdr rest-chars)
2374                                (list ch)
2375                                is-lower
2376                                (if (null? currents)
2377                                    prev-result
2378                                    (cons (char-list->markup
2379                                             currents current-is-lower)
2380                                          prev-result)))))))
2381   (interpret-markup layout props
2382     (if (string? arg)
2383         (make-small-caps (string->list arg) (list) #f (list))
2384         arg)))
2385
2386 (define-markup-command (caps layout props arg)
2387   (markup?)
2388   #:category font
2389   "Copy of the @code{\\smallCaps} command.
2390
2391 @lilypond[verbatim,quote]
2392 \\markup {
2393   default
2394   \\hspace #2
2395   \\caps {
2396     Text in small caps
2397   }
2398 }
2399 @end lilypond"
2400   (interpret-markup layout props (make-smallCaps-markup arg)))
2401
2402 (define-markup-command (dynamic layout props arg)
2403   (markup?)
2404   #:category font
2405   "Use the dynamic font.  This font only contains @b{s}, @b{f}, @b{m},
2406 @b{z}, @b{p}, and @b{r}.  When producing phrases, like
2407 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2408 done in a different font.  The recommended font for this is bold and italic.
2409 @lilypond[verbatim,quote]
2410 \\markup {
2411   \\dynamic {
2412     sfzp
2413   }
2414 }
2415 @end lilypond"
2416   (interpret-markup
2417    layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2418
2419 (define-markup-command (text layout props arg)
2420   (markup?)
2421   #:category font
2422   "Use a text font instead of music symbol or music alphabet font.
2423
2424 @lilypond[verbatim,quote]
2425 \\markup {
2426   \\number {
2427     1, 2,
2428     \\text {
2429       three, four,
2430     }
2431     5
2432   }
2433 }
2434 @end lilypond"
2435
2436   ;; ugh - latin1
2437   (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2438                     arg))
2439
2440 (define-markup-command (italic layout props arg)
2441   (markup?)
2442   #:category font
2443   "Use italic @code{font-shape} for @var{arg}.
2444
2445 @lilypond[verbatim,quote]
2446 \\markup {
2447   default
2448   \\hspace #2
2449   \\italic
2450   italic
2451 }
2452 @end lilypond"
2453   (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2454
2455 (define-markup-command (typewriter layout props arg)
2456   (markup?)
2457   #:category font
2458   "Use @code{font-family} typewriter for @var{arg}.
2459
2460 @lilypond[verbatim,quote]
2461 \\markup {
2462   default
2463   \\hspace #2
2464   \\typewriter
2465   typewriter
2466 }
2467 @end lilypond"
2468   (interpret-markup
2469    layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2470
2471 (define-markup-command (upright layout props arg)
2472   (markup?)
2473   #:category font
2474   "Set @code{font-shape} to @code{upright}.  This is the opposite
2475 of @code{italic}.
2476
2477 @lilypond[verbatim,quote]
2478 \\markup {
2479   \\italic {
2480     italic text
2481     \\hspace #2
2482     \\upright {
2483       upright text
2484     }
2485     \\hspace #2
2486     italic again
2487   }
2488 }
2489 @end lilypond"
2490   (interpret-markup
2491    layout (prepend-alist-chain 'font-shape 'upright props) arg))
2492
2493 (define-markup-command (medium layout props arg)
2494   (markup?)
2495   #:category font
2496   "Switch to medium font-series (in contrast to bold).
2497
2498 @lilypond[verbatim,quote]
2499 \\markup {
2500   \\bold {
2501     some bold text
2502     \\hspace #2
2503     \\medium {
2504       medium font series
2505     }
2506     \\hspace #2
2507     bold again
2508   }
2509 }
2510 @end lilypond"
2511   (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2512                     arg))
2513
2514 (define-markup-command (normal-text layout props arg)
2515   (markup?)
2516   #:category font
2517   "Set all font related properties (except the size) to get the default
2518 normal text font, no matter what font was used earlier.
2519
2520 @lilypond[verbatim,quote]
2521 \\markup {
2522   \\huge \\bold \\sans \\caps {
2523     huge bold sans caps
2524     \\hspace #2
2525     \\normal-text {
2526       huge normal
2527     }
2528     \\hspace #2
2529     as before
2530   }
2531 }
2532 @end lilypond"
2533   ;; ugh - latin1
2534   (interpret-markup layout
2535                     (cons '((font-family . roman) (font-shape . upright)
2536                             (font-series . medium) (font-encoding . latin1))
2537                           props)
2538                     arg))
2539
2540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2541 ;; symbols.
2542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2543
2544 (define-markup-command (musicglyph layout props glyph-name)
2545   (string?)
2546   #:category music
2547   "@var{glyph-name} is converted to a musical symbol; for example,
2548 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2549 the music font.  See @ruser{The Feta font} for a complete listing of
2550 the possible glyphs.
2551
2552 @lilypond[verbatim,quote]
2553 \\markup {
2554   \\musicglyph #\"f\"
2555   \\musicglyph #\"rests.2\"
2556   \\musicglyph #\"clefs.G_change\"
2557 }
2558 @end lilypond"
2559   (let* ((font (ly:paper-get-font layout
2560                                   (cons '((font-encoding . fetaMusic)
2561                                           (font-name . #f))
2562
2563                                                  props)))
2564          (glyph (ly:font-get-glyph font glyph-name)))
2565     (if (null? (ly:stencil-expr glyph))
2566         (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2567
2568     glyph))
2569
2570 (define-markup-command (doublesharp layout props)
2571   ()
2572   #:category music
2573   "Draw a double sharp symbol.
2574
2575 @lilypond[verbatim,quote]
2576 \\markup {
2577   \\doublesharp
2578 }
2579 @end lilypond"
2580   (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2581
2582 (define-markup-command (sesquisharp layout props)
2583   ()
2584   #:category music
2585   "Draw a 3/2 sharp symbol.
2586
2587 @lilypond[verbatim,quote]
2588 \\markup {
2589   \\sesquisharp
2590 }
2591 @end lilypond"
2592   (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2593
2594 (define-markup-command (sharp layout props)
2595   ()
2596   #:category music
2597   "Draw a sharp symbol.
2598
2599 @lilypond[verbatim,quote]
2600 \\markup {
2601   \\sharp
2602 }
2603 @end lilypond"
2604   (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2605
2606 (define-markup-command (semisharp layout props)
2607   ()
2608   #:category music
2609   "Draw a semisharp symbol.
2610
2611 @lilypond[verbatim,quote]
2612 \\markup {
2613   \\semisharp
2614 }
2615 @end lilypond"
2616   (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2617
2618 (define-markup-command (natural layout props)
2619   ()
2620   #:category music
2621   "Draw a natural symbol.
2622
2623 @lilypond[verbatim,quote]
2624 \\markup {
2625   \\natural
2626 }
2627 @end lilypond"
2628   (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2629
2630 (define-markup-command (semiflat layout props)
2631   ()
2632   #:category music
2633   "Draw a semiflat symbol.
2634
2635 @lilypond[verbatim,quote]
2636 \\markup {
2637   \\semiflat
2638 }
2639 @end lilypond"
2640   (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2641
2642 (define-markup-command (flat layout props)
2643   ()
2644   #:category music
2645   "Draw a flat symbol.
2646
2647 @lilypond[verbatim,quote]
2648 \\markup {
2649   \\flat
2650 }
2651 @end lilypond"
2652   (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2653
2654 (define-markup-command (sesquiflat layout props)
2655   ()
2656   #:category music
2657   "Draw a 3/2 flat symbol.
2658
2659 @lilypond[verbatim,quote]
2660 \\markup {
2661   \\sesquiflat
2662 }
2663 @end lilypond"
2664   (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2665
2666 (define-markup-command (doubleflat layout props)
2667   ()
2668   #:category music
2669   "Draw a double flat symbol.
2670
2671 @lilypond[verbatim,quote]
2672 \\markup {
2673   \\doubleflat
2674 }
2675 @end lilypond"
2676   (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2677
2678 (define-markup-command (with-color layout props color arg)
2679   (color? markup?)
2680   #:category other
2681   "
2682 @cindex coloring text
2683
2684 Draw @var{arg} in color specified by @var{color}.
2685
2686 @lilypond[verbatim,quote]
2687 \\markup {
2688   \\with-color #red
2689   red
2690   \\hspace #2
2691   \\with-color #green
2692   green
2693   \\hspace #2
2694   \\with-color #blue
2695   blue
2696 }
2697 @end lilypond"
2698   (let ((stil (interpret-markup layout props arg)))
2699     (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2700                      (ly:stencil-extent stil X)
2701                      (ly:stencil-extent stil Y))))
2702
2703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2704 ;; glyphs
2705 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2706
2707 (define-markup-command (arrow-head layout props axis dir filled)
2708   (integer? ly:dir? boolean?)
2709   #:category graphic
2710   "Produce an arrow head in specified direction and axis.
2711 Use the filled head if @var{filled} is specified.
2712 @lilypond[verbatim,quote]
2713 \\markup {
2714   \\fontsize #5 {
2715     \\general-align #Y #DOWN {
2716       \\arrow-head #Y #UP ##t
2717       \\arrow-head #Y #DOWN ##f
2718       \\hspace #2
2719       \\arrow-head #X #RIGHT ##f
2720       \\arrow-head #X #LEFT ##f
2721     }
2722   }
2723 }
2724 @end lilypond"
2725   (let*
2726       ((name (format #f "arrowheads.~a.~a~a"
2727                      (if filled
2728                          "close"
2729                          "open")
2730                      axis
2731                      dir)))
2732     (ly:font-get-glyph
2733      (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2734                                      props))
2735      name)))
2736
2737 (define-markup-command (lookup layout props glyph-name)
2738   (string?)
2739   #:category other
2740   "Lookup a glyph by name.
2741
2742 @lilypond[verbatim,quote]
2743 \\markup {
2744   \\override #'(font-encoding . fetaBraces) {
2745     \\lookup #\"brace200\"
2746     \\hspace #2
2747     \\rotate #180
2748     \\lookup #\"brace180\"
2749   }
2750 }
2751 @end lilypond"
2752   (ly:font-get-glyph (ly:paper-get-font layout props)
2753                      glyph-name))
2754
2755 (define-markup-command (char layout props num)
2756   (integer?)
2757   #:category other
2758   "Produce a single character.  Characters encoded in hexadecimal
2759 format require the prefix @code{#x}.
2760
2761 @lilypond[verbatim,quote]
2762 \\markup {
2763   \\char #65 \\char ##x00a9
2764 }
2765 @end lilypond"
2766   (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2767
2768 (define number->mark-letter-vector (make-vector 25 #\A))
2769
2770 (do ((i 0 (1+ i))
2771      (j 0 (1+ j)))
2772     ((>= i 26))
2773   (if (= i (- (char->integer #\I) (char->integer #\A)))
2774       (set! i (1+ i)))
2775   (vector-set! number->mark-letter-vector j
2776                (integer->char (+ i (char->integer #\A)))))
2777
2778 (define number->mark-alphabet-vector (list->vector
2779   (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2780
2781 (define (number->markletter-string vec n)
2782   "Double letters for big marks."
2783   (let* ((lst (vector-length vec)))
2784
2785     (if (>= n lst)
2786         (string-append (number->markletter-string vec (1- (quotient n lst)))
2787                        (number->markletter-string vec (remainder n lst)))
2788         (make-string 1 (vector-ref vec n)))))
2789
2790 (define-markup-command (markletter layout props num)
2791   (integer?)
2792   #:category other
2793   "Make a markup letter for @var{num}.  The letters start with A to@tie{}Z
2794 (skipping letter@tie{}I), and continue with double letters.
2795
2796 @lilypond[verbatim,quote]
2797 \\markup {
2798   \\markletter #8
2799   \\hspace #2
2800   \\markletter #26
2801 }
2802 @end lilypond"
2803   (ly:text-interface::interpret-markup layout props
2804     (number->markletter-string number->mark-letter-vector num)))
2805
2806 (define-markup-command (markalphabet layout props num)
2807   (integer?)
2808   #:category other
2809    "Make a markup letter for @var{num}.  The letters start with A to@tie{}Z
2810 and continue with double letters.
2811
2812 @lilypond[verbatim,quote]
2813 \\markup {
2814   \\markalphabet #8
2815   \\hspace #2
2816   \\markalphabet #26
2817 }
2818 @end lilypond"
2819    (ly:text-interface::interpret-markup layout props
2820      (number->markletter-string number->mark-alphabet-vector num)))
2821
2822 (define-public (horizontal-slash-interval num forward number-interval mag)
2823   (if forward
2824     (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2825           ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2826           (else (interval-widen number-interval (* mag 0.25))))
2827     (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2828           ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2829           (else (interval-widen number-interval (* mag 0.25))))
2830   ))
2831
2832 (define-public (adjust-slash-stencil num forward stencil mag)
2833   (if forward
2834     (cond ((= num 2)
2835               (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2836           ((= num 3)
2837               (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2838           ;((= num 5)
2839               ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2840           ;((= num 7)
2841           ;    (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2842           (else stencil))
2843     (cond ((= num 6)
2844               (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2845           ;((= num 8)
2846           ;    (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2847           (else stencil))
2848   )
2849 )
2850
2851 (define (slashed-digit-internal layout props num forward font-size thickness)
2852   (let* ((mag (magstep font-size))
2853          (thickness (* mag
2854                        (ly:output-def-lookup layout 'line-thickness)
2855                        thickness))
2856          ; backward slashes might use slope and point in the other direction!
2857          (dy (* mag (if forward 0.4 -0.4)))
2858          (number-stencil (interpret-markup layout
2859                                            (prepend-alist-chain 'font-encoding 'fetaText props)
2860                                            (number->string num)))
2861          (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2862          (center (interval-center (ly:stencil-extent number-stencil Y)))
2863          ; Use the real extents of the slash, not the whole number, because we
2864          ; might translate the slash later on!
2865          (num-y (interval-widen (cons center center) (abs dy)))
2866          (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2867          (slash-stencil (if is-sane
2868                             (make-line-stencil thickness
2869                                          (car num-x) (- (interval-center num-y) dy)
2870                                          (cdr num-x) (+ (interval-center num-y) dy))
2871                             #f)))
2872     (if (ly:stencil? slash-stencil)
2873       (begin
2874         ; for some numbers we need to shift the slash/backslash up or down to make
2875         ; the slashed digit look better
2876         (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2877         (set! number-stencil
2878           (ly:stencil-add number-stencil slash-stencil)))
2879       (ly:warning "Unable to create slashed digit ~a" num))
2880     number-stencil))
2881
2882
2883 (define-markup-command (slashed-digit layout props num)
2884   (integer?)
2885   #:category other
2886   #:properties ((font-size 0)
2887                 (thickness 1.6))
2888   "
2889 @cindex slashed digits
2890
2891 A feta number, with slash.  This is for use in the context of
2892 figured bass notation.
2893 @lilypond[verbatim,quote]
2894 \\markup {
2895   \\slashed-digit #5
2896   \\hspace #2
2897   \\override #'(thickness . 3)
2898   \\slashed-digit #7
2899 }
2900 @end lilypond"
2901   (slashed-digit-internal layout props num #t font-size thickness))
2902
2903 (define-markup-command (backslashed-digit layout props num)
2904   (integer?)
2905   #:category other
2906   #:properties ((font-size 0)
2907                 (thickness 1.6))
2908   "
2909 @cindex backslashed digits
2910
2911 A feta number, with backslash.  This is for use in the context of
2912 figured bass notation.
2913 @lilypond[verbatim,quote]
2914 \\markup {
2915   \\backslashed-digit #5
2916   \\hspace #2
2917   \\override #'(thickness . 3)
2918   \\backslashed-digit #7
2919 }
2920 @end lilypond"
2921   (slashed-digit-internal layout props num #f font-size thickness))
2922
2923 ;; eyeglasses
2924 (define eyeglassespath
2925   '((moveto 0.42 0.77)
2926     (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2927     (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2928     (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2929     (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2930     (closepath)
2931     (moveto 2.07 0.77)
2932     (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2933     (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2934     (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2935     (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2936     (closepath)
2937     (moveto 1.025 0.935)
2938     (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2939     (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2940     (moveto -0.68 0.77)
2941     (rlineto 0.66 1.43)
2942     (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2943     (moveto 2.07 0.77)
2944     (rlineto 0.66 1.43)
2945     (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2946
2947 (define-markup-command (eyeglasses layout props)
2948   ()
2949   #:category other
2950   "Prints out eyeglasses, indicating strongly to look at the conductor.
2951 @lilypond[verbatim,quote]
2952 \\markup { \\eyeglasses }
2953 @end lilypond"
2954   (interpret-markup layout props
2955     (make-override-markup '(line-cap-style . butt)
2956       (make-path-markup 0.15 eyeglassespath))))
2957
2958 (define-markup-command (left-brace layout props size)
2959   (number?)
2960   #:category other
2961   "
2962 A feta brace in point size @var{size}.
2963
2964 @lilypond[verbatim,quote]
2965 \\markup {
2966   \\left-brace #35
2967   \\hspace #2
2968   \\left-brace #45
2969 }
2970 @end lilypond"
2971   (let* ((font (ly:paper-get-font layout
2972                                   (cons '((font-encoding . fetaBraces)
2973                                           (font-name . #f))
2974                                         props)))
2975          (glyph-count (1- (ly:otf-glyph-count font)))
2976          (scale (ly:output-def-lookup layout 'output-scale))
2977          (scaled-size (/ (ly:pt size) scale))
2978          (glyph (lambda (n)
2979                   (ly:font-get-glyph font (string-append "brace"
2980                                                          (number->string n)))))
2981          (get-y-from-brace (lambda (brace)
2982                              (interval-length
2983                               (ly:stencil-extent (glyph brace) Y))))
2984          (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2985          (glyph-found (glyph find-brace)))
2986
2987     (if (or (null? (ly:stencil-expr glyph-found))
2988             (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2989             (> scaled-size (interval-length
2990                             (ly:stencil-extent (glyph glyph-count) Y))))
2991         (begin
2992           (ly:warning (_ "no brace found for point size ~S ") size)
2993           (ly:warning (_ "defaulting to ~S pt")
2994                       (/ (* scale (interval-length
2995                                    (ly:stencil-extent glyph-found Y)))
2996                          (ly:pt 1)))))
2997     glyph-found))
2998
2999 (define-markup-command (right-brace layout props size)
3000   (number?)
3001   #:category other
3002   "
3003 A feta brace in point size @var{size}, rotated 180 degrees.
3004
3005 @lilypond[verbatim,quote]
3006 \\markup {
3007   \\right-brace #45
3008   \\hspace #2
3009   \\right-brace #35
3010 }
3011 @end lilypond"
3012   (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3013
3014 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3015 ;; the note command.
3016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3017
3018 ;; TODO: better syntax.
3019
3020 (define-markup-command (note-by-number layout props log dot-count dir)
3021   (number? number? number?)
3022   #:category music
3023   #:properties ((font-size 0)
3024                 (style '()))
3025   "
3026 @cindex notes within text by log and dot-count
3027
3028 Construct a note symbol, with stem.  By using fractional values for
3029 @var{dir}, longer or shorter stems can be obtained.
3030
3031 @lilypond[verbatim,quote]
3032 \\markup {
3033   \\note-by-number #3 #0 #DOWN
3034   \\hspace #2
3035   \\note-by-number #1 #2 #0.8
3036 }
3037 @end lilypond"
3038   (define (get-glyph-name-candidates dir log style)
3039     (map (lambda (dir-name)
3040            (format #f "noteheads.~a~a" dir-name
3041                    (if (and (symbol? style)
3042                             (not (equal? 'default style)))
3043                        (select-head-glyph style (min log 2))
3044                        (min log 2))))
3045          (list (if (= dir UP) "u" "d")
3046                "s")))
3047
3048   (define (get-glyph-name font cands)
3049     (if (null? cands)
3050         ""
3051         (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3052             (get-glyph-name font (cdr cands))
3053             (car cands))))
3054
3055   (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3056                                                props)))
3057          (size-factor (magstep font-size))
3058          (stem-length (* size-factor (max 3 (- log 1))))
3059          (head-glyph-name
3060           (let ((result (get-glyph-name font (get-glyph-name-candidates
3061                                               (sign dir) log style))))
3062             (if (string-null? result)
3063                 ;; If no glyph name can be found, select default heads.  Though
3064                 ;; this usually means an unsupported style has been chosen, it
3065                 ;; also prevents unrelated 'style settings from other grobs
3066                 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3067                 (get-glyph-name font (get-glyph-name-candidates
3068                                       (sign dir) log 'default))
3069                 result)))
3070          (head-glyph (ly:font-get-glyph font head-glyph-name))
3071          (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3072          (stem-thickness (* size-factor 0.13))
3073          (stemy (* dir stem-length))
3074          (attach-off (cons (interval-index
3075                             (ly:stencil-extent head-glyph X)
3076                             (* (sign dir) (car attach-indices)))
3077                            (* (sign dir) ; fixme, this is inconsistent between X & Y.
3078                               (interval-index
3079                                (ly:stencil-extent head-glyph Y)
3080                                (cdr attach-indices)))))
3081          (stem-glyph (and (> log 0)
3082                           (ly:round-filled-box
3083                            (ordered-cons (car attach-off)
3084                                          (+ (car attach-off)
3085                                             (* (- (sign dir)) stem-thickness)))
3086                            (cons (min stemy (cdr attach-off))
3087                                  (max stemy (cdr attach-off)))
3088                            (/ stem-thickness 3))))
3089
3090          (dot (ly:font-get-glyph font "dots.dot"))
3091          (dotwid (interval-length (ly:stencil-extent dot X)))
3092          (dots (and (> dot-count 0)
3093                     (apply ly:stencil-add
3094                            (map (lambda (x)
3095                                   (ly:stencil-translate-axis
3096                                    dot (* 2 x dotwid) X))
3097                                 (iota dot-count)))))
3098          (flaggl (and (> log 2)
3099                       (ly:stencil-translate
3100                        (ly:font-get-glyph font
3101                                           (string-append "flags."
3102                                                          (if (> dir 0) "u" "d")
3103                                                          (number->string log)))
3104                        (cons (+ (car attach-off) (if (< dir 0)
3105                                                      stem-thickness 0))
3106                              stemy)))))
3107
3108     ;; If there is a flag on an upstem and the stem is short, move the dots
3109     ;; to avoid the flag.  16th notes get a special case because their flags
3110     ;; hang lower than any other flags.
3111     (if (and dots (> dir 0) (> log 2)
3112              (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3113         (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3114     (if flaggl
3115         (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3116     (if (ly:stencil? stem-glyph)
3117         (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3118         (set! stem-glyph head-glyph))
3119     (if (ly:stencil? dots)
3120         (set! stem-glyph
3121               (ly:stencil-add
3122                (ly:stencil-translate-axis
3123                 dots
3124                 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3125                 X)
3126                stem-glyph)))
3127     stem-glyph))
3128
3129 (define-public log2
3130   (let ((divisor (log 2)))
3131     (lambda (z) (inexact->exact (/ (log z) divisor)))))
3132
3133 (define (parse-simple-duration duration-string)
3134   "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3135 and return a (log dots) list."
3136   (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3137                             duration-string)))
3138     (if (and match (string=? duration-string (match:substring match 0)))
3139         (let ((len (match:substring match 1))
3140               (dots (match:substring match 2)))
3141           (list (cond ((string=? len "breve") -1)
3142                       ((string=? len "longa") -2)
3143                       ((string=? len "maxima") -3)
3144                       (else (log2 (string->number len))))
3145                 (if dots (string-length dots) 0)))
3146         (ly:error (_ "not a valid duration string: ~a") duration-string))))
3147
3148 (define-markup-command (note layout props duration dir)
3149   (string? number?)
3150   #:category music
3151   #:properties (note-by-number-markup)
3152   "
3153 @cindex notes within text by string
3154
3155 This produces a note with a stem pointing in @var{dir} direction, with
3156 the @var{duration} for the note head type and augmentation dots.  For
3157 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3158 a shortened down stem.
3159
3160 @lilypond[verbatim,quote]
3161 \\markup {
3162   \\override #'(style . cross) {
3163     \\note #\"4..\" #UP
3164   }
3165   \\hspace #2
3166   \\note #\"breve\" #0
3167 }
3168 @end lilypond"
3169   (let ((parsed (parse-simple-duration duration)))
3170     (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3171
3172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3173 ;; translating.
3174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3175
3176 (define-markup-command (lower layout props amount arg)
3177   (number? markup?)
3178   #:category align
3179   "
3180 @cindex lowering text
3181
3182 Lower @var{arg} by the distance @var{amount}.
3183 A negative @var{amount} indicates raising; see also @code{\\raise}.
3184
3185 @lilypond[verbatim,quote]
3186 \\markup {
3187   one
3188   \\lower #3
3189   two
3190   three
3191 }
3192 @end lilypond"
3193   (ly:stencil-translate-axis (interpret-markup layout props arg)
3194                              (- amount) Y))
3195
3196 (define-markup-command (translate-scaled layout props offset arg)
3197   (number-pair? markup?)
3198   #:category align
3199   #:properties ((font-size 0))
3200   "
3201 @cindex translating text
3202 @cindex scaling text
3203
3204 Translate @var{arg} by @var{offset}, scaling the offset by the
3205 @code{font-size}.
3206
3207 @lilypond[verbatim,quote]
3208 \\markup {
3209   \\fontsize #5 {
3210     * \\translate #'(2 . 3) translate
3211     \\hspace #2
3212     * \\translate-scaled #'(2 . 3) translate-scaled
3213   }
3214 }
3215 @end lilypond"
3216   (let* ((factor (magstep font-size))
3217          (scaled (cons (* factor (car offset))
3218                        (* factor (cdr offset)))))
3219     (ly:stencil-translate (interpret-markup layout props arg)
3220                           scaled)))
3221
3222 (define-markup-command (raise layout props amount arg)
3223   (number? markup?)
3224   #:category align
3225   "
3226 @cindex raising text
3227
3228 Raise @var{arg} by the distance @var{amount}.
3229 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3230
3231 The argument to @code{\\raise} is the vertical displacement amount,
3232 measured in (global) staff spaces.  @code{\\raise} and @code{\\super}
3233 raise objects in relation to their surrounding markups.
3234
3235 If the text object itself is positioned above or below the staff, then
3236 @code{\\raise} cannot be used to move it, since the mechanism that
3237 positions it next to the staff cancels any shift made with
3238 @code{\\raise}.  For vertical positioning, use the @code{padding}
3239 and/or @code{extra-offset} properties.
3240
3241 @lilypond[verbatim,quote]
3242 \\markup {
3243   C
3244   \\small
3245   \\bold
3246   \\raise #1.0
3247   9/7+
3248 }
3249 @end lilypond"
3250   (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3251
3252 (define-markup-command (fraction layout props arg1 arg2)
3253   (markup? markup?)
3254   #:category other
3255   #:properties ((font-size 0))
3256   "
3257 @cindex creating text fractions
3258
3259 Make a fraction of two markups.
3260 @lilypond[verbatim,quote]
3261 \\markup {
3262   Ï€ â‰ˆ
3263   \\fraction 355 113
3264 }
3265 @end lilypond"
3266   (let* ((m1 (interpret-markup layout props arg1))
3267          (m2 (interpret-markup layout props arg2))
3268          (factor (magstep font-size))
3269          (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3270          (padding (* factor 0.2))
3271          (baseline (* factor 0.6))
3272          (offset (* factor 0.75)))
3273     (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3274     (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3275     (let* ((x1 (ly:stencil-extent m1 X))
3276            (x2 (ly:stencil-extent m2 X))
3277            (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3278            ;; should stack mols separately, to maintain LINE on baseline
3279            (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3280       (set! stack
3281             (ly:stencil-aligned-to stack Y CENTER))
3282       (set! stack
3283             (ly:stencil-aligned-to stack X LEFT))
3284       ;; should have EX dimension
3285       ;; empirical anyway
3286       (ly:stencil-translate-axis stack offset Y))))
3287
3288 (define-markup-command (normal-size-super layout props arg)
3289   (markup?)
3290   #:category font
3291   #:properties ((baseline-skip))
3292   "
3293 @cindex setting superscript in standard font size
3294
3295 Set @var{arg} in superscript with a normal font size.
3296
3297 @lilypond[verbatim,quote]
3298 \\markup {
3299   default
3300   \\normal-size-super {
3301     superscript in standard size
3302   }
3303 }
3304 @end lilypond"
3305   (ly:stencil-translate-axis
3306    (interpret-markup layout props arg)
3307    (* 0.5 baseline-skip) Y))
3308
3309 (define-markup-command (super layout props arg)
3310   (markup?)
3311   #:category font
3312   #:properties ((font-size 0)
3313                 (baseline-skip))
3314   "
3315 @cindex superscript text
3316
3317 Set @var{arg} in superscript.
3318
3319 @lilypond[verbatim,quote]
3320 \\markup {
3321   E =
3322   \\concat {
3323     mc
3324     \\super
3325     2
3326   }
3327 }
3328 @end lilypond"
3329   (ly:stencil-translate-axis
3330    (interpret-markup
3331     layout
3332     (cons `((font-size . ,(- font-size 3))) props)
3333     arg)
3334    (* 0.5 baseline-skip)
3335    Y))
3336
3337 (define-markup-command (translate layout props offset arg)
3338   (number-pair? markup?)
3339   #:category align
3340   "
3341 @cindex translating text
3342
3343 Translate @var{arg} relative to its surroundings.  @var{offset}
3344 is a pair of numbers representing the displacement in the X and Y axis.
3345
3346 @lilypond[verbatim,quote]
3347 \\markup {
3348   *
3349   \\translate #'(2 . 3)
3350   \\line { translated two spaces right, three up }
3351 }
3352 @end lilypond"
3353   (ly:stencil-translate (interpret-markup layout props arg)
3354                         offset))
3355
3356 (define-markup-command (sub layout props arg)
3357   (markup?)
3358   #:category font
3359   #:properties ((font-size 0)
3360                 (baseline-skip))
3361   "
3362 @cindex subscript text
3363
3364 Set @var{arg} in subscript.
3365
3366 @lilypond[verbatim,quote]
3367 \\markup {
3368   \\concat {
3369     H
3370     \\sub {
3371       2
3372     }
3373     O
3374   }
3375 }
3376 @end lilypond"
3377   (ly:stencil-translate-axis
3378    (interpret-markup
3379     layout
3380     (cons `((font-size . ,(- font-size 3))) props)
3381     arg)
3382    (* -0.5 baseline-skip)
3383    Y))
3384
3385 (define-markup-command (normal-size-sub layout props arg)
3386   (markup?)
3387   #:category font
3388   #:properties ((baseline-skip))
3389   "
3390 @cindex setting subscript in standard font size
3391
3392 Set @var{arg} in subscript with a normal font size.
3393
3394 @lilypond[verbatim,quote]
3395 \\markup {
3396   default
3397   \\normal-size-sub {
3398     subscript in standard size
3399   }
3400 }
3401 @end lilypond"
3402   (ly:stencil-translate-axis
3403    (interpret-markup layout props arg)
3404    (* -0.5 baseline-skip)
3405    Y))
3406
3407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3408 ;; brackets.
3409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3410
3411 (define-markup-command (hbracket layout props arg)
3412   (markup?)
3413   #:category graphic
3414   "
3415 @cindex placing horizontal brackets around text
3416
3417 Draw horizontal brackets around @var{arg}.
3418
3419 @lilypond[verbatim,quote]
3420 \\markup {
3421   \\hbracket {
3422     \\line {
3423       one two three
3424     }
3425   }
3426 }
3427 @end lilypond"
3428   (let ((th 0.1) ;; todo: take from GROB.
3429         (m (interpret-markup layout props arg)))
3430     (bracketify-stencil m X th (* 2.5 th) th)))
3431
3432 (define-markup-command (bracket layout props arg)
3433   (markup?)
3434   #:category graphic
3435   "
3436 @cindex placing vertical brackets around text
3437
3438 Draw vertical brackets around @var{arg}.
3439
3440 @lilypond[verbatim,quote]
3441 \\markup {
3442   \\bracket {
3443     \\note #\"2.\" #UP
3444   }
3445 }
3446 @end lilypond"
3447   (let ((th 0.1) ;; todo: take from GROB.
3448         (m (interpret-markup layout props arg)))
3449     (bracketify-stencil m Y th (* 2.5 th) th)))
3450
3451 (define-markup-command (parenthesize layout props arg)
3452   (markup?)
3453   #:category graphic
3454   #:properties ((angularity 0)
3455                 (padding)
3456                 (size 1)
3457                 (thickness 1)
3458                 (width 0.25))
3459   "
3460 @cindex placing parentheses around text
3461
3462 Draw parentheses around @var{arg}.  This is useful for parenthesizing
3463 a column containing several lines of text.
3464
3465 @lilypond[verbatim,quote]
3466 \\markup {
3467   \\line {
3468     \\parenthesize {
3469       \\column {
3470         foo
3471         bar
3472       }
3473     }
3474     \\override #'(angularity . 2) {
3475       \\parenthesize {
3476         \\column {
3477           bah
3478           baz
3479         }
3480       }
3481     }
3482   }
3483 }
3484 @end lilypond"
3485   (let* ((markup (interpret-markup layout props arg))
3486          (scaled-width (* size width))
3487          (scaled-thickness
3488           (* (chain-assoc-get 'line-thickness props 0.1)
3489              thickness))
3490          (half-thickness
3491           (min (* size 0.5 scaled-thickness)
3492                (* (/ 4 3.0) scaled-width)))
3493          (padding (chain-assoc-get 'padding props half-thickness)))
3494     (parenthesize-stencil
3495      markup half-thickness scaled-width angularity padding)))
3496
3497
3498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3499 ;; Delayed markup evaluation
3500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3501
3502 (define-markup-command (page-ref layout props label gauge default)
3503   (symbol? markup? markup?)
3504   #:category other
3505   "
3506 @cindex referencing page numbers in text
3507
3508 Reference to a page number.  @var{label} is the label set on the referenced
3509 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3510 the maximum width of the page number, and @var{default} the value to display
3511 when @var{label} is not found."
3512   (let* ((gauge-stencil (interpret-markup layout props gauge))
3513          (x-ext (ly:stencil-extent gauge-stencil X))
3514          (y-ext (ly:stencil-extent gauge-stencil Y)))
3515     (ly:make-stencil
3516      `(delay-stencil-evaluation
3517        ,(delay (ly:stencil-expr
3518                 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3519                        (page-number (if (list? table)
3520                                         (assoc-get label table)
3521                                         #f))
3522                        (page-markup (if page-number (format #f "~a" page-number) default))
3523                        (page-stencil (interpret-markup layout props page-markup))
3524                        (gap (- (interval-length x-ext)
3525                                (interval-length (ly:stencil-extent page-stencil X)))))
3526                   (interpret-markup layout props
3527                                     (markup #:concat (#:hspace gap page-markup)))))))
3528      x-ext
3529      y-ext)))
3530
3531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3532 ;; scaling
3533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3534
3535 (define-markup-command (scale layout props factor-pair arg)
3536   (number-pair? markup?)
3537   #:category graphic
3538   "
3539 @cindex scaling markup
3540 @cindex mirroring markup
3541
3542 Scale @var{arg}.  @var{factor-pair} is a pair of numbers
3543 representing the scaling-factor in the X and Y axes.
3544 Negative values may be used to produce mirror images.
3545
3546 @lilypond[verbatim,quote]
3547 \\markup {
3548   \\line {
3549     \\scale #'(2 . 1)
3550     stretched
3551     \\scale #'(1 . -1)
3552     mirrored
3553   }
3554 }
3555 @end lilypond"
3556   (let ((stil (interpret-markup layout props arg))
3557         (sx (car factor-pair))
3558         (sy (cdr factor-pair)))
3559     (ly:stencil-scale stil sx sy)))
3560
3561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3562 ;; Repeating
3563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3564
3565 (define-markup-command (pattern layout props count axis space pattern)
3566   (integer? integer? number? markup?)
3567   #:category other
3568   "
3569 Prints @var{count} times a @var{pattern} markup.
3570 Patterns are spaced apart by @var{space}.
3571 Patterns are distributed on @var{axis}.
3572
3573 @lilypond[verbatim, quote]
3574 \\markup \\column {
3575   \"Horizontally repeated :\"
3576   \\pattern #7 #X #2 \\flat
3577   \\null
3578   \"Vertically repeated :\"
3579   \\pattern #3 #Y #0.5 \\flat
3580 }
3581 @end lilypond"
3582   (let ((pattern-width (interval-length
3583                          (ly:stencil-extent (interpret-markup layout props pattern) X)))
3584         (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3585     (let loop ((i (1- count)) (patterns (markup)))
3586       (if (zero? i)
3587           (interpret-markup
3588             layout
3589             new-props
3590             (if (= axis X)
3591                 (markup patterns pattern)
3592                 (markup #:column (patterns pattern))))
3593           (loop (1- i)
3594             (if (= axis X)
3595                 (markup patterns pattern #:hspace space)
3596                 (markup #:column (patterns pattern #:vspace space))))))))
3597
3598 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3599   (number? ly:dir? markup? markup? markup?)
3600   #:category align
3601   #:properties ((word-space)
3602                 (line-width))
3603   "
3604 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3605 with a line of markups @var{pattern} in between.
3606 Patterns are spaced apart by @var{space}.
3607 Patterns are aligned to the @var{dir} markup.
3608
3609 @lilypond[verbatim, quote]
3610 \\markup \\column {
3611   \"right-aligned :\"
3612   \\fill-with-pattern #1 #RIGHT . first right
3613   \\fill-with-pattern #1 #RIGHT . second right
3614   \\null
3615   \"center-aligned :\"
3616   \\fill-with-pattern #1.5 #CENTER - left right
3617   \\null
3618   \"left-aligned :\"
3619   \\override #'(line-width . 50)
3620   \\fill-with-pattern #2 #LEFT : left first
3621   \\override #'(line-width . 50)
3622   \\fill-with-pattern #2 #LEFT : left second
3623 }
3624 @end lilypond"
3625   (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3626          (pattern-width (interval-length pattern-x-extent))
3627          (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3628          (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3629          (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
3630          (period (+ space pattern-width))
3631          (count (truncate (/ (- middle-width pattern-width) period)))
3632          (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3633     (interpret-markup layout props
3634                       (markup left
3635                               #:with-dimensions (cons 0 middle-width) '(0 . 0)
3636                               #:translate (cons x-offset 0)
3637                               #:pattern (1+ count) X space pattern
3638                               right))))
3639
3640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3641 ;; Markup list commands
3642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3643
3644 (define-public (space-lines baseline stils)
3645   (let space-stil ((stils stils)
3646                    (result (list)))
3647     (if (null? stils)
3648         (reverse! result)
3649         (let* ((stil (car stils))
3650                (dy-top (max (- (/ baseline 1.5)
3651                                (interval-bound (ly:stencil-extent stil Y) UP))
3652                             0.0))
3653                (dy-bottom (max (+ (/ baseline 3.0)
3654                                   (interval-bound (ly:stencil-extent stil Y) DOWN))
3655                                0.0))
3656                (new-stil (ly:make-stencil
3657                           (ly:stencil-expr stil)
3658                           (ly:stencil-extent stil X)
3659                           (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3660                                    dy-bottom)
3661                                 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3662                                    dy-top)))))
3663           (space-stil (cdr stils) (cons new-stil result))))))
3664
3665 (define-markup-list-command (justified-lines layout props args)
3666   (markup-list?)
3667   #:properties ((baseline-skip)
3668                 wordwrap-internal-markup-list)
3669   "
3670 @cindex justifying lines of text
3671
3672 Like @code{\\justify}, but return a list of lines instead of a single markup.
3673 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3674 @var{X}@tie{}is the number of staff spaces."
3675   (space-lines baseline-skip
3676                (interpret-markup-list layout props
3677                                       (make-wordwrap-internal-markup-list #t args))))
3678
3679 (define-markup-list-command (wordwrap-lines layout props args)
3680   (markup-list?)
3681   #:properties ((baseline-skip)
3682                 wordwrap-internal-markup-list)
3683   "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3684 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3685 where @var{X} is the number of staff spaces."
3686   (space-lines baseline-skip
3687                (interpret-markup-list layout props
3688                                       (make-wordwrap-internal-markup-list #f args))))
3689
3690 (define-markup-list-command (column-lines layout props args)
3691   (markup-list?)
3692   #:properties ((baseline-skip))
3693   "Like @code{\\column}, but return a list of lines instead of a single markup.
3694 @code{baseline-skip} determines the space between each markup in @var{args}."
3695   (space-lines baseline-skip
3696                (interpret-markup-list layout props args)))
3697
3698 (define-markup-list-command (override-lines layout props new-prop args)
3699   (pair? markup-list?)
3700   "Like @code{\\override}, for markup lists."
3701   (interpret-markup-list layout (cons (list new-prop) props) args))