1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
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.
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.
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/>.
20 ;;; Markup commands and markup-list commands definitions.
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.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
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)
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.
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.
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
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
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.
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
86 ;;; Thus, using the following property bindings:
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)))
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.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '()
115 empty-interval empty-interval))
116 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;; line has to come early since it is often used implicitly from the
120 ;; markup macro since \markup { a b c } -> \markup \line { a b c }
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 (define-markup-command (line layout props args)
126 #:properties ((word-space)
127 (text-direction RIGHT))
128 "Put @var{args} in a horizontal line. The property @code{word-space}
129 determines the space between markups in @var{args}.
131 @lilypond[verbatim,quote]
138 (let ((stencils (interpret-markup-list layout props args)))
139 (if (= text-direction LEFT)
140 (set! stencils (reverse stencils)))
141 (stack-stencil-line word-space stencils)))
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 (define-markup-command (draw-line layout props dest)
150 #:properties ((thickness 1))
152 @cindex drawing lines within text
155 @lilypond[verbatim,quote]
157 \\draw-line #'(4 . 4)
158 \\override #'(thickness . 5)
159 \\draw-line #'(-3 . 0)
162 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
166 (make-line-stencil th 0 0 x y)))
168 (define-markup-command (draw-dashed-line layout props dest)
171 #:properties ((thickness 1)
177 @cindex drawing dashed lines within text
181 If @code{full-length} is set to #t (default) the dashed-line extends to the
182 whole length given by @var{dest}, without white space at beginning or end.
183 @code{off} will then be altered to fit.
184 To insist on the given (or default) values of @code{on}, @code{off} use
185 @code{\\override #'(full-length . #f)}
186 Manual settings for @code{on},@code{off} and @code{phase} are possible.
187 @lilypond[verbatim,quote]
189 \\draw-dashed-line #'(5.1 . 2.3)
190 \\override #'(on . 0.3)
191 \\override #'(off . 0.5)
192 \\draw-dashed-line #'(5.1 . 2.3)
195 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
196 ;; Calculate the thickness to be used.
197 (th (* line-thickness thickness))
198 (half-thick (/ th 2))
199 ;; Get the extensions in x- and y-direction.
202 ;; Calculate the length of the dashed line.
203 (line-length (sqrt (+ (expt x 2) (expt y 2)))))
205 (if (and full-length (not (= (+ on off) 0)))
207 ;; Add double-thickness to avoid overlapping.
208 (set! off (+ (* 2 th) off))
209 (let* (;; Make a guess how often the off/on-pair should be printed
210 ;; after the initial `on´.
211 ;; Assume a minimum of 1 to avoid division by zero.
212 (guess (max 1 (round (/ (- line-length on) (+ off on)))))
213 ;; Not sure about the value or why corr is necessary at all,
214 ;; but it seems to be necessary.
216 (/ line-thickness 10)
218 ;; Calculate a new value for off to fit the
220 (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
224 ;; Settings for (= on 0). Resulting in a dotted line.
226 ;; If line-length isn't shorter than `th´, change the given
227 ;; value for `off´ to fit the line-length.
228 ((and (= on 0) (< th line-length))
231 ;; If the line-length is shorter than `th´, it makes no
232 ;; sense to adjust `off´. The rounded edges of the lines
233 ;; would prevent any nice output.
235 ;; This will result in a single dot for very short lines.
236 ((and (= on 0) (>= th line-length))
239 ;; Settings for (not (= on 0)). Resulting in a dashed line.
241 ;; If line-length isn't shorter than one go of on-off-on,
242 ;; change the given value for `off´ to fit the line-length.
243 ((< (+ (* 2 on) off) line-length)
245 ;; If the line-length is too short, but greater than
246 ;; (* 4 th) set on/off to (/ line-length 3)
247 ((< (* 4 th) line-length)
248 (set! on (/ line-length 3))
249 (set! off (/ line-length 3)))
250 ;; If the line-length is shorter than (* 4 th), it makes
251 ;; no sense trying to adjust on/off. The rounded edges of
252 ;; the lines would prevent any nice output.
253 ;; Simply set `on´ to line-length.
255 (set! on line-length))))))
257 ;; If `on´ or `off´ is negative, or the sum of `on' and `off' equals zero a
258 ;; ghostscript-error occurs while calling
259 ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
260 ;; Better be paranoid.
261 (if (or (= (+ on off) 0)
265 (ly:warning "Can't print a line - setting on/off to default")
269 ;; To give the lines produced by \draw-line and \draw-dashed-line the same
270 ;; length, half-thick has to be added to the stencil-extensions.
272 (list 'dashed-line th on off x y phase)
273 (interval-widen (ordered-cons 0 x) half-thick)
274 (interval-widen (ordered-cons 0 y) half-thick))))
276 (define-markup-command (draw-dotted-line layout props dest)
279 #:properties ((thickness 1)
283 @cindex drawing dotted lines within text
287 The dotted-line always extends to the whole length given by @var{dest}, without
288 white space at beginning or end.
289 Manual settings for @code{off} are possible to get larger or smaller space
291 The given (or default) value of @code{off} will be altered to fit the
293 @lilypond[verbatim,quote]
295 \\draw-dotted-line #'(5.1 . 2.3)
296 \\override #'(thickness . 2)
297 \\override #'(off . 0.2)
298 \\draw-dotted-line #'(5.1 . 2.3)
302 (let ((new-props (prepend-alist-chain 'on 0
303 (prepend-alist-chain 'full-length #t props))))
305 (interpret-markup layout
307 (markup #:draw-dashed-line dest))))
309 (define-markup-command (draw-hline layout props)
312 #:properties ((draw-line-markup)
316 @cindex drawing a line across a page
318 Draws a line across a page, where the property @code{span-factor}
319 controls what fraction of the page is taken up.
320 @lilypond[verbatim,quote]
324 \\override #'(span-factor . 1/3)
329 (interpret-markup layout
331 (markup #:draw-line (cons (* line-width
335 (define-markup-command (draw-circle layout props radius thickness filled)
336 (number? number? boolean?)
339 @cindex drawing circles within text
341 A circle of radius @var{radius} and thickness @var{thickness},
344 @lilypond[verbatim,quote]
346 \\draw-circle #2 #0.5 ##f
348 \\draw-circle #2 #0 ##t
351 (make-circle-stencil radius thickness filled))
353 (define-markup-command (triangle layout props filled)
356 #:properties ((thickness 0.1)
360 @cindex drawing triangles within text
362 A triangle, either filled or empty.
364 @lilypond[verbatim,quote]
371 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
380 (cons 0 (* .86 ex)))))
382 (define-markup-command (circle layout props arg)
385 #:properties ((thickness 1)
387 (circle-padding 0.2))
389 @cindex circling text
391 Draw a circle around @var{arg}. Use @code{thickness},
392 @code{circle-padding} and @code{font-size} properties to determine line
393 thickness and padding around the markup.
395 @lilypond[verbatim,quote]
402 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
404 (pad (* (magstep font-size) circle-padding))
405 (m (interpret-markup layout props arg)))
406 (circle-stencil m th pad)))
408 (define-markup-command (ellipse layout props arg)
411 #:properties ((thickness 1)
416 @cindex drawing ellipse around text
418 Draw an ellipse around @var{arg}. Use @code{thickness},
419 @code{x-padding}, @code{y-padding} and @code{font-size} properties to determine
420 line thickness and padding around the markup.
422 @lilypond[verbatim,quote]
429 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
431 (pad-x (* (magstep font-size) x-padding))
432 (pad-y (* (magstep font-size) y-padding))
433 (m (interpret-markup layout props arg)))
434 (ellipse-stencil m th pad-x pad-y)))
436 (define-markup-command (oval layout props arg)
439 #:properties ((thickness 1)
444 @cindex drawing oval around text
446 Draw an oval around @var{arg}. Use @code{thickness},
447 @code{x-padding}, @code{x-padding} and @code{font-size} properties to determine
448 line thickness and padding around the markup.
450 @lilypond[verbatim,quote]
457 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
459 (pad-x (* (magstep font-size) x-padding))
460 (pad-y (* (magstep font-size) y-padding))
461 (m (interpret-markup layout props arg)))
462 (oval-stencil m th pad-x pad-y)))
464 (define-markup-command (with-url layout props url arg)
468 @cindex inserting URL links into text
470 Add a link to URL @var{url} around @var{arg}. This only works in
473 @lilypond[verbatim,quote]
475 \\with-url #\"http://lilypond.org/\" {
476 LilyPond ... \\italic {
477 music notation for everyone
482 (let* ((stil (interpret-markup layout props arg))
483 (xextent (ly:stencil-extent stil X))
484 (yextent (ly:stencil-extent stil Y))
485 (old-expr (ly:stencil-expr stil))
486 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
488 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
490 (define-markup-command (page-link layout props page-number arg)
494 @cindex referencing page numbers in text
496 Add a link to the page @var{page-number} around @var{arg}. This only works
499 @lilypond[verbatim,quote]
501 \\page-link #2 { \\italic { This links to page 2... } }
504 (let* ((stil (interpret-markup layout props arg))
505 (xextent (ly:stencil-extent stil X))
506 (yextent (ly:stencil-extent stil Y))
507 (old-expr (ly:stencil-expr stil))
508 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
510 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
512 (define-public (book-first-page layout props)
513 "Return the @code{'first-page-number} of the entire book"
514 (define (ancestor layout)
515 "Return the topmost layout ancestor"
516 (let ((parent (ly:output-def-parent layout)))
517 (if (not (ly:output-def? parent))
520 (ly:output-def-lookup (ancestor layout) 'first-page-number))
522 (define-markup-command (with-link layout props label arg)
526 @cindex referencing page labels in text
528 Add a link to the page holding label @var{label} around @var{arg}. This
529 only works in the PDF backend.
531 @lilypond[verbatim,quote]
533 \\with-link #'label {
534 \\italic { This links to the page containing the label... }
538 (let* ((arg-stencil (interpret-markup layout props arg))
539 (x-ext (ly:stencil-extent arg-stencil X))
540 (y-ext (ly:stencil-extent arg-stencil Y)))
543 `(delay-stencil-evaluation
544 ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
547 (assoc-get label table)
549 (first-page-number (book-first-page layout props))
551 (if table-page-number
552 (1+ (- table-page-number first-page-number))
554 (list 'page-link current-page-number
555 `(quote ,x-ext) `(quote ,y-ext)))))
560 (define-markup-command (beam layout props width slope thickness)
561 (number? number? number?)
564 @cindex drawing beams within text
566 Create a beam with the specified parameters.
567 @lilypond[verbatim,quote]
572 (let* ((y (* slope width))
573 (yext (cons (min 0 y) (max 0 y)))
574 (half (/ thickness 2)))
579 width (+ (* width slope) (/ thickness -2))
580 width (+ (* width slope) (/ thickness 2))
582 ,(ly:output-def-lookup layout 'blot-diameter)
585 (cons (+ (- half) (car yext))
586 (+ half (cdr yext))))))
588 (define-markup-command (underline layout props arg)
591 #:properties ((thickness 1) (offset 2))
593 @cindex underlining text
595 Underline @var{arg}. Looks at @code{thickness} to determine line
596 thickness, and @code{offset} to determine line y-offset.
598 @lilypond[verbatim,quote]
599 \\markup \\fill-line {
600 \\underline \"underlined\"
601 \\override #'(offset . 5)
602 \\override #'(thickness . 1)
603 \\underline \"underlined\"
604 \\override #'(offset . 1)
605 \\override #'(thickness . 5)
606 \\underline \"underlined\"
609 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
610 (underline-thick (* thickness thick))
611 (m (interpret-markup layout props arg))
612 (x1 (car (ly:stencil-extent m X)))
613 (x2 (cdr (ly:stencil-extent m X)))
614 (y (* thick (- offset)))
615 (line (make-line-stencil underline-thick x1 y x2 y)))
616 (ly:stencil-add m line)))
618 (define-markup-command (tie layout props arg)
621 #:properties ((thickness 1)
624 (shorten-pair '(0 . 0)))
628 Adds a horizontal bow created with @code{make-tie-stencil} at bottom or top
629 of @var{arg}. Looks at @code{thickness} to determine line thickness, and
630 @code{offset} to determine y-offset. The added bow fits the extent of
631 @var{arg}, @code{shorten-pair} may be used to modify this.
632 @var{direction} may be set using an @code{override} or direction-modifiers or
633 @code{voiceOne}, etc.
635 @lilypond[verbatim,quote]
637 \\override #'(direction . 1)
639 \\override #'(direction . -1)
643 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
644 (thick (* thickness line-thickness))
645 (stil (interpret-markup layout props arg))
646 (x1 (car (ly:stencil-extent stil X)))
647 (x2 (cdr (ly:stencil-extent stil X)))
648 (y-ext (ly:stencil-extent stil Y))
649 (y (+ (* line-thickness offset direction)
650 ;; we put out zero for positive text-direction, to make it
651 ;; consistent with `underline-markup'
652 ;; TODO: this will be problematic for args like "Eng"
653 ;; fix it here _and_ in `underline-markup'
654 (if (negative? direction) 0 (cdr y-ext))))
657 (cons (+ x1 (car shorten-pair) line-thickness) y)
658 (cons (- x2 (cdr shorten-pair) line-thickness) y)
661 (ly:stencil-add stil tie)))
663 (define-markup-command (undertie layout props arg)
666 #:properties (tie-markup)
668 @cindex undertie-ing text
670 @lilypond[verbatim,quote]
672 \\undertie \"undertied\"
673 \\override #'(offset . 5)
674 \\override #'(thickness . 1)
675 \\undertie \"undertied\"
676 \\override #'(offset . 1)
677 \\override #'(thickness . 5)
678 \\undertie \"undertied\"
681 (interpret-markup layout (prepend-alist-chain 'direction DOWN props)
682 (make-tie-markup arg)))
684 (define-markup-command (overtie layout props arg)
687 #:properties (tie-markup)
689 @cindex overtie-ing text
693 @lilypond[verbatim,quote]
695 \\overtie \"overtied\"
696 \\override #'(offset . 5)
697 \\override #'(thickness . 1)
698 \\overtie \"overtied\"
699 \\override #'(offset . 1)
700 \\override #'(thickness . 5)
701 \\overtie \"overtied\"
704 (interpret-markup layout (prepend-alist-chain 'direction UP props)
705 (make-tie-markup arg)))
707 (define-markup-command (box layout props arg)
710 #:properties ((thickness 1)
714 @cindex enclosing text within a box
716 Draw a box round @var{arg}. Looks at @code{thickness},
717 @code{box-padding} and @code{font-size} properties to determine line
718 thickness and padding around the markup.
720 @lilypond[verbatim,quote]
722 \\override #'(box-padding . 0.5)
727 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
729 (pad (* (magstep font-size) box-padding))
730 (m (interpret-markup layout props arg)))
731 (box-stencil m th pad)))
733 (define-markup-command (filled-box layout props xext yext blot)
734 (number-pair? number-pair? number?)
737 @cindex drawing solid boxes within text
738 @cindex drawing boxes with rounded corners
740 Draw a box with rounded corners of dimensions @var{xext} and
741 @var{yext}. For example,
743 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
745 creates a box extending horizontally from -0.3 to 1.8 and
746 vertically from -0.3 up to 1.8, with corners formed from a
747 circle of diameter@tie{}0 (i.e., sharp corners).
749 @lilypond[verbatim,quote]
751 \\filled-box #'(0 . 4) #'(0 . 4) #0
752 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
753 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
755 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
761 (define-markup-command (rounded-box layout props arg)
764 #:properties ((thickness 1)
768 "@cindex enclosing text in a box with rounded corners
769 @cindex drawing boxes with rounded corners around text
770 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
771 @code{box-padding} and @code{font-size} properties to determine line
772 thickness and padding around the markup; the @code{corner-radius} property
773 makes it possible to define another shape for the corners (default is 1).
775 @lilypond[quote,verbatim,relative=2]
783 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
785 (pad (* (magstep font-size) box-padding))
786 (m (interpret-markup layout props arg)))
787 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
790 (define-markup-command (rotate layout props ang arg)
794 @cindex rotating text
796 Rotate object with @var{ang} degrees around its center.
798 @lilypond[verbatim,quote]
808 (let* ((stil (interpret-markup layout props arg)))
809 (ly:stencil-rotate stil ang 0 0)))
811 (define-markup-command (whiteout layout props arg)
814 #:properties ((style 'box)
817 @cindex adding a white background to text
819 Provide a white background for @var{arg}. The shape of the white
820 background is determined by @code{style}. The default
821 is @code{box} which produces a white rectangle. @code{outline}
822 approximates the outline of the markup.
824 @lilypond[verbatim,quote]
827 \\filled-box #'(-1 . 15) #'(-3 . 4) #1
828 \\override #'(thickness . 1.5)
829 \\whiteout whiteout-box
833 \\filled-box #'(-1 . 18) #'(-3 . 4) #1
834 \\override #'(style . outline)
835 \\override #'(thickness . 3)
836 \\whiteout whiteout-outline
840 (interpret-markup layout props arg)
843 (ly:output-def-lookup layout 'line-thickness)))
845 (define-markup-command (pad-markup layout props amount arg)
850 @cindex putting space around text
852 Add space around a markup object.
853 Identical to @code{pad-around}.
855 @lilypond[verbatim,quote]
868 (let* ((m (interpret-markup layout props arg))
869 (x (interval-widen (ly:stencil-extent m X) amount))
870 (y (interval-widen (ly:stencil-extent m Y) amount)))
871 (ly:stencil-add (make-transparent-box-stencil x y)
874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
878 (define-markup-command (strut layout props)
882 @cindex creating vertical spaces in text
884 Create a box of the same height as the space in the current font."
885 (let ((m (ly:text-interface::interpret-markup layout props " ")))
886 (ly:make-stencil (ly:stencil-expr m)
888 (ly:stencil-extent m X)
891 (define-markup-command (hspace layout props amount)
895 @cindex creating horizontal spaces in text
897 Create an invisible object taking up horizontal space @var{amount}.
899 @lilypond[verbatim,quote]
908 (ly:make-stencil "" (cons 0 amount) empty-interval))
910 (define-markup-command (vspace layout props amount)
914 @cindex creating vertical spaces in text
916 Create an invisible object taking up vertical space
917 of @var{amount} multiplied by 3.
919 @lilypond[verbatim,quote]
930 (let ((amount (* amount 3.0)))
931 (ly:make-stencil "" empty-interval (cons 0 amount))))
934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
935 ;; importing graphics.
936 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
938 (define-markup-command (stencil layout props stil)
942 @cindex importing stencils into text
944 Use a stencil as markup.
946 @lilypond[verbatim,quote]
948 \\stencil #(make-circle-stencil 2 0 #t)
954 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
956 (define (get-postscript-bbox string)
957 "Extract the bbox from STRING, or return #f if not present."
959 ((match (regexp-exec bbox-regexp string)))
963 (string->number (match:substring match x)))
968 (define-markup-command (epsfile layout props axis size file-name)
969 (number? number? string?)
972 @cindex inlining an Encapsulated PostScript image
974 Inline an EPS image. The image is scaled along @var{axis} to
977 @lilypond[verbatim,quote]
979 \\general-align #Y #DOWN {
980 \\epsfile #X #20 #\"context-example.eps\"
981 \\epsfile #Y #20 #\"context-example.eps\"
985 (if (ly:get-option 'safe)
986 (interpret-markup layout props "not allowed in safe")
987 (eps-file->stencil axis size file-name)
990 (define-markup-command (postscript layout props str)
994 @cindex inserting PostScript directly into text
995 This inserts @var{str} directly into the output as a PostScript
998 @lilypond[verbatim,quote]
1002 0.4 0.6 0.5 0 361 arc
1004 1.0 0.6 0.5 0 361 arc
1009 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
1010 \\postscript #ringsps
1022 gsave currentpoint translate
1030 (define-markup-command (path layout props thickness commands) (number? list?)
1032 #:properties ((line-cap-style 'round)
1033 (line-join-style 'round)
1036 @cindex paths, drawing
1037 @cindex drawing paths
1038 Draws a path with line @var{thickness} according to the
1039 directions given in @var{commands}. @var{commands} is a list of
1040 lists where the @code{car} of each sublist is a drawing command and
1041 the @code{cdr} comprises the associated arguments for each command.
1043 There are seven commands available to use in the list
1044 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
1045 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
1046 @code{closepath}. Note that the commands that begin with @emph{r}
1047 are the relative variants of the other three commands.
1049 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
1050 @code{rlineto} take 2 arguments; they are the X and Y coordinates
1051 for the destination point.
1053 The commands @code{curveto} and @code{rcurveto} create cubic
1054 Bézier curves, and take 6 arguments; the first two are the X and Y
1055 coordinates for the first control point, the second two are the X
1056 and Y coordinates for the second control point, and the last two
1057 are the X and Y coordinates for the destination point.
1059 The @code{closepath} command takes zero arguments and closes the
1060 current subpath in the active path.
1062 Note that a sequence of commands @emph{must} begin with a
1063 @code{moveto} or @code{rmoveto} to work with the SVG output.
1065 Line-cap styles and line-join styles may be customized by
1066 overriding the @code{line-cap-style} and @code{line-join-style}
1067 properties, respectively. Available line-cap styles are
1068 @code{'butt}, @code{'round}, and @code{'square}. Available
1069 line-join styles are @code{'miter}, @code{'round}, and
1072 The property @code{filled} specifies whether or not the path is
1075 @lilypond[verbatim,quote]
1081 (curveto -5 -5 -5 5 -1 0)
1085 \\path #0.25 #samplePath
1087 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
1089 \\override #'(filled . #t) \\path #0.25 #samplePath
1092 (let* ((half-thickness (/ thickness 2))
1093 (current-point '(0 . 0))
1094 (set-point (lambda (lst) (set! current-point lst)))
1095 (relative? (lambda (x)
1096 (string-prefix? "r" (symbol->string (car x)))))
1097 ;; For calculating extents, we want to modify the command
1098 ;; list so that all coordinates are absolute.
1099 (new-commands (map (lambda (x)
1101 ;; for rmoveto, rlineto
1102 ((and (relative? x) (= 3 (length x)))
1104 (+ (car current-point)
1106 (+ (cdr current-point)
1112 ((and (relative? x) (= 7 (length x)))
1113 (let* ((old-cp current-point)
1120 (list (+ (car old-cp) (second x))
1121 (+ (cdr old-cp) (third x))
1122 (+ (car old-cp) (fourth x))
1123 (+ (cdr old-cp) (fifth x))
1126 ;; for moveto, lineto
1128 (set-point (cons (second x)
1133 (set-point (cons (sixth x)
1136 ;; keep closepath for filtering;
1137 ;; see `without-closepath'.
1140 ;; path-min-max does not accept 0-arg lists,
1141 ;; and since closepath does not affect extents, filter
1142 ;; out those commands here.
1143 (without-closepath (filter (lambda (x)
1144 (not (equal? 'closepath (car x))))
1146 (extents (path-min-max
1147 ;; set the origin to the first moveto
1148 (list (list-ref (car without-closepath) 0)
1149 (list-ref (car without-closepath) 1))
1151 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1152 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1153 (command-list (fold-right append '() commands)))
1155 ;; account for line thickness
1156 (set! X-extent (interval-widen X-extent half-thickness))
1157 (set! Y-extent (interval-widen Y-extent half-thickness))
1160 `(path ,thickness `(,@',command-list)
1161 ',line-cap-style ',line-join-style ,filled)
1165 (define-markup-list-command (score-lines layout props score)
1167 "This is the same as the @code{\\score} markup but delivers its
1168 systems as a list of lines. Its @var{score} argument is entered in
1169 braces like it would be for @code{\\score}."
1170 (let ((output (ly:score-embedded-format score layout)))
1172 (if (ly:music-output? output)
1174 (lambda (paper-system)
1175 ;; shift such that the refpoint of the bottom staff of
1176 ;; the first system is the baseline of the score
1177 (ly:stencil-translate-axis
1178 (paper-system-stencil paper-system)
1179 (- (car (paper-system-staff-extents paper-system)))
1181 (vector->list (ly:paper-score-paper-systems output)))
1183 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1186 (define-markup-command (score layout props score)
1189 #:properties ((baseline-skip))
1191 @cindex inserting music into text
1193 Inline an image of music. The reference point (usually the middle
1194 staff line) of the lowest staff in the top system is placed on the
1197 @lilypond[verbatim,quote]
1201 \\new Staff \\relative c' {
1204 \\mark \\markup { Allegro }
1210 \\new Staff \\relative c {
1216 f,( bes d bes d bes)
1224 \\override RehearsalMark
1225 #'break-align-symbols = #'(time-signature key-signature)
1226 \\override RehearsalMark
1227 #'self-alignment-X = #LEFT
1231 \\override TimeSignature
1232 #'break-align-anchor-alignment = #LEFT
1238 (stack-stencils Y DOWN baseline-skip
1239 (score-lines-markup-list layout props score)))
1241 (define-markup-command (null layout props)
1245 @cindex creating empty text objects
1247 An empty markup with extents of a single point.
1249 @lilypond[verbatim,quote]
1256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1257 ;; basic formatting.
1258 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1260 (define-markup-command (simple layout props str)
1264 @cindex simple text strings
1266 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1267 @code{\\markup @{ \\simple #\"foo\" @}}.
1269 Note: for creating standard text markup or defining new markup commands,
1270 the use of @code{\\simple} is unnecessary.
1272 @lilypond[verbatim,quote]
1274 \\simple #\"simple\"
1276 \\simple #\"strings\"
1279 (interpret-markup layout props str))
1281 (define-markup-command (first-visible layout props args)
1284 "Use the first markup in @var{args} that yields a non-empty stencil
1285 and ignore the rest.
1287 @lilypond[verbatim,quote]
1290 \\fromproperty #'header:composer
1295 (define (false-if-empty stencil)
1296 (if (ly:stencil-empty? stencil) #f stencil))
1301 (false-if-empty (interpret-markup layout props m))
1302 (any false-if-empty (interpret-markup-list layout props (list m)))))
1306 (define-public empty-markup
1307 (make-simple-markup ""))
1309 ;; helper for justifying lines.
1310 (define (get-fill-space
1311 word-count line-width word-space text-widths constant-space?)
1312 "Calculate the necessary paddings between adjacent texts in a
1313 single justified line. The lengths of all texts are stored in
1315 When @var{constant-space?} is @code{#t}, the formula for the padding
1317 padding = (line-width - total-text-width)/(word-count - 1)
1318 When @var{constant-space?} is @code{#f}, the formula for the
1319 padding between interior texts a and b is:
1320 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1321 In this case, the first and last padding have to be calculated
1322 specially using the whole length of the first or last text.
1323 All paddings are checked to be at least word-space, to ensure that
1325 Return a list of paddings."
1327 ((null? text-widths) '())
1331 ;; Ensure that space between words cannot be
1332 ;; less than word-space.
1335 (/ (- line-width (apply + text-widths))
1338 ;; special case first padding
1339 ((= (length text-widths) word-count)
1341 (- (- (/ line-width (1- word-count)) (car text-widths))
1342 (/ (cadr text-widths) 2))
1344 word-count line-width word-space (cdr text-widths)
1346 ;; special case last padding
1347 ((= (length text-widths) 2)
1348 (list (- (/ line-width (1- word-count))
1349 (+ (/ (car text-widths) 2) (cadr text-widths)))
1352 (let ((default-padding
1353 (- (/ line-width (1- word-count))
1354 (/ (+ (car text-widths) (cadr text-widths)) 2))))
1356 (if (> word-space default-padding)
1360 word-count line-width word-space (cdr text-widths)
1361 constant-space?))))))
1363 (define (justify-line-helper
1364 layout props args text-direction word-space line-width constant-space?)
1365 "Return a stencil which spreads @var{args} along a line of width
1366 @var{line-width}. If @var{constant-space?} is set to @code{#t}, the
1367 space between words is constant. If @code{#f}, the distance between
1368 words varies according to their relative lengths."
1369 (let* ((orig-stencils (interpret-markup-list layout props args))
1372 (if (ly:stencil-empty? stc X)
1373 (ly:make-stencil (ly:stencil-expr stc)
1374 '(0 . 0) (ly:stencil-extent stc Y))
1379 (interval-length (ly:stencil-extent stc X)))
1381 (text-width (apply + text-widths))
1382 (word-count (length stencils))
1383 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1388 (/ (- line-width text-width) 2)
1389 (/ (- line-width text-width) 2)))
1392 (- line-width text-width)))
1395 word-count line-width word-space text-widths
1397 (line-contents (if (= word-count 1)
1404 (if (null? (remove ly:stencil-empty? orig-stencils))
1407 (if (= text-direction LEFT)
1408 (set! line-contents (reverse line-contents)))
1410 (stack-stencils-padding-list
1411 X RIGHT fill-space line-contents))
1412 (if (> word-count 1)
1413 ;; shift s.t. stencils align on the left edge, even if
1414 ;; first stencil had negative X-extent (e.g. center-column)
1415 ;; (if word-count = 1, X-extents are already normalized in
1416 ;; the definition of line-contents)
1418 (ly:stencil-translate-axis
1420 (- (car (ly:stencil-extent (car stencils) X)))
1424 (define-markup-command (fill-line layout props args)
1427 #:properties ((text-direction RIGHT)
1430 "Put @var{markups} in a horizontal line of width @var{line-width}.
1431 The markups are spaced or flushed to fill the entire line.
1432 If there are no arguments, return an empty stencil.
1434 @lilypond[verbatim,quote]
1438 Words evenly spaced across the page
1442 \\line { Text markups }
1444 \\italic { evenly spaced }
1446 \\line { across the page }
1451 (justify-line-helper
1452 layout props args text-direction word-space line-width #f))
1454 (define-markup-command (justify-line layout props args)
1457 #:properties ((text-direction RIGHT)
1460 "Put @var{markups} in a horizontal line of width @var{line-width}.
1461 The markups are spread to fill the entire line and separated by equal
1462 space. If there are no arguments, return an empty stencil.
1464 @lilypond[verbatim,quote]
1467 Space between neighboring words is constant
1471 (justify-line-helper
1472 layout props args text-direction word-space line-width #t))
1474 (define-markup-command (concat layout props args)
1478 @cindex concatenating text
1479 @cindex ligatures in text
1481 Concatenate @var{args} in a horizontal line, without spaces in between.
1482 Strings and simple markups are concatenated on the input level, allowing
1483 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1484 equivalent to @code{\"fi\"}.
1486 @lilypond[verbatim,quote]
1495 (define (concat-string-args arg-list)
1496 (fold-right (lambda (arg result-list)
1497 (let ((result (and (pair? result-list)
1498 (car result-list))))
1499 (cond ((not (pair? arg)))
1500 ((eq? (car arg) simple-markup)
1501 (set! arg (cadr arg)))
1502 ((eq? (car arg) char-markup)
1503 (set! arg (ly:wide-char->utf-8 (cadr arg)))))
1504 (if (and (string? result) (string? arg))
1505 (cons (string-append arg result) (cdr result-list))
1506 (cons arg result-list))))
1510 (interpret-markup layout
1511 (prepend-alist-chain 'word-space 0 props)
1513 (make-override-lines-markup-list
1515 (chain-assoc-get 'word-space props))
1516 (if (markup-command-list? args)
1518 (concat-string-args args))))))
1520 (define (wordwrap-stencils stencils
1521 justify base-space line-width text-dir)
1522 "Perform simple wordwrap, return stencil of each line."
1523 (define space (if justify
1524 ;; justify only stretches lines.
1527 (define (stencil-len s)
1528 (interval-end (ly:stencil-extent s X)))
1529 (define (maybe-shift line)
1530 (if (= text-dir LEFT)
1531 (ly:stencil-translate-axis
1533 (- line-width (stencil-len line))
1536 (if (null? stencils)
1538 (let loop ((lines '())
1541 ((line (first todo))
1543 (word-list (list (first todo))))
1546 (let ((new (if (= text-dir LEFT)
1547 (ly:stencil-stack (car todo) X RIGHT line space)
1548 (ly:stencil-stack line X RIGHT (car todo) space))))
1550 ((<= (stencil-len new) line-width)
1551 (word-loop new (cdr todo)
1552 (cons (car todo) word-list)))
1555 ;; This depends on stencil stacking being
1556 ;; associative so that stacking
1557 ;; left-to-right and right-to-left leads to
1559 (if (= text-dir LEFT)
1561 (reverse! word-list)))
1562 (len (stencil-len line))
1563 (stretch (- line-width len))
1566 (stack-stencils X RIGHT (1+ space) word-list))
1569 ;; Uh oh, nothing to fill.
1570 (loop (cons (maybe-shift line) lines) todo)
1572 (stack-stencils X RIGHT
1573 (+ space (/ stretch spaces))
1577 (else ;; not justify
1578 (loop (cons (maybe-shift line) lines) todo)))))
1581 ;; Now we have the last line assembled with space
1582 ;; which is compressed. We want to use the
1583 ;; uncompressed version instead if it fits, and the
1584 ;; justified version if it doesn't.
1586 ;; This depends on stencil stacking being
1587 ;; associative so that stacking
1588 ;; left-to-right and right-to-left leads to
1590 (if (= text-dir LEFT)
1592 (reverse! word-list)))
1593 (big-line (stack-stencils X RIGHT base-space word-list))
1594 (big-len (stencil-len big-line))
1595 (len (stencil-len line)))
1598 (if (> big-len line-width)
1599 (stack-stencils X RIGHT
1602 (* (- big-len line-width)
1604 (* (- line-width len)
1608 (maybe-shift big-line))))))
1609 (else ;; not justify
1610 (reverse! lines (list (maybe-shift line)))))))))
1613 (define-markup-list-command (wordwrap-internal layout props justify args)
1614 (boolean? markup-list?)
1615 #:properties ((line-width #f)
1617 (text-direction RIGHT))
1618 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1619 (wordwrap-stencils (interpret-markup-list layout props args)
1623 (ly:output-def-lookup layout 'line-width))
1626 (define-markup-command (justify layout props args)
1629 #:properties ((baseline-skip)
1630 wordwrap-internal-markup-list)
1632 @cindex justifying text
1634 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1635 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1636 @var{X}@tie{}is the number of staff spaces.
1638 @lilypond[verbatim,quote]
1641 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1642 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1643 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1644 laboris nisi ut aliquip ex ea commodo consequat.
1648 (stack-lines DOWN 0.0 baseline-skip
1649 (wordwrap-internal-markup-list layout props #t args)))
1651 (define-markup-command (wordwrap layout props args)
1654 #:properties ((baseline-skip)
1655 wordwrap-internal-markup-list)
1656 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1657 the line width, where @var{X} is the number of staff spaces.
1659 @lilypond[verbatim,quote]
1662 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1663 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1664 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1665 laboris nisi ut aliquip ex ea commodo consequat.
1669 (stack-lines DOWN 0.0 baseline-skip
1670 (wordwrap-internal-markup-list layout props #f args)))
1672 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1674 #:properties ((line-width)
1676 (text-direction RIGHT))
1677 "Internal markup list command used to define @code{\\justify-string} and
1678 @code{\\wordwrap-string}."
1679 (let* ((para-strings (regexp-split
1680 (string-regexp-substitute
1682 (string-regexp-substitute "\r\n" "\n" arg))
1683 "\n[ \t\n]*\n[ \t\n]*"))
1684 (list-para-words (map (lambda (str)
1685 (regexp-split str "[ \t\n]+"))
1687 (para-lines (map (lambda (words)
1690 (interpret-markup layout props x))
1692 (wordwrap-stencils stencils
1694 line-width text-direction)))
1696 (concatenate para-lines)))
1698 (define-markup-command (wordwrap-string layout props arg)
1701 #:properties ((baseline-skip)
1702 wordwrap-string-internal-markup-list)
1703 "Wordwrap a string. Paragraphs may be separated with double newlines.
1705 @lilypond[verbatim,quote]
1707 \\override #'(line-width . 40)
1708 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1709 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1710 et dolore magna aliqua.
1713 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1714 laboris nisi ut aliquip ex ea commodo consequat.
1717 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1718 qui officia deserunt mollit anim id est laborum\"
1721 (stack-lines DOWN 0.0 baseline-skip
1722 (wordwrap-string-internal-markup-list layout props #f arg)))
1724 (define-markup-command (justify-string layout props arg)
1727 #:properties ((baseline-skip)
1728 wordwrap-string-internal-markup-list)
1729 "Justify a string. Paragraphs may be separated with double newlines
1731 @lilypond[verbatim,quote]
1733 \\override #'(line-width . 40)
1734 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1735 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1736 et dolore magna aliqua.
1739 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1740 laboris nisi ut aliquip ex ea commodo consequat.
1743 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1744 qui officia deserunt mollit anim id est laborum\"
1747 (stack-lines DOWN 0.0 baseline-skip
1748 (wordwrap-string-internal-markup-list layout props #t arg)))
1750 (define-markup-command (wordwrap-field layout props symbol)
1753 "Wordwrap the data which has been assigned to @var{symbol}.
1755 @lilypond[verbatim,quote]
1757 title = \"My title\"
1758 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1759 elit, sed do eiusmod tempor incididunt ut labore et dolore
1760 magna aliqua. Ut enim ad minim veniam, quis nostrud
1761 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1766 bookTitleMarkup = \\markup {
1768 \\fill-line { \\fromproperty #'header:title }
1770 \\wordwrap-field #'header:myText
1779 (let* ((m (chain-assoc-get symbol props)))
1781 (wordwrap-string-markup layout props m)
1784 (define-markup-command (justify-field layout props symbol)
1787 "Justify the data which has been assigned to @var{symbol}.
1789 @lilypond[verbatim,quote]
1791 title = \"My title\"
1792 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1793 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1794 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1795 laboris nisi ut aliquip ex ea commodo consequat.\"
1799 bookTitleMarkup = \\markup {
1801 \\fill-line { \\fromproperty #'header:title }
1803 \\justify-field #'header:myText
1812 (let* ((m (chain-assoc-get symbol props)))
1814 (justify-string-markup layout props m)
1817 (define-markup-command (combine layout props arg1 arg2)
1821 @cindex merging text
1823 Print two markups on top of each other.
1825 Note: @code{\\combine} cannot take a list of markups enclosed in
1826 curly braces as an argument; for this purpose use @code{\\overlay} instead.
1828 @lilypond[verbatim,quote]
1831 \\override #'(thickness . 2)
1833 \\draw-line #'(0 . 4)
1834 \\arrow-head #Y #DOWN ##f
1837 (let* ((s1 (interpret-markup layout props arg1))
1838 (s2 (interpret-markup layout props arg2)))
1839 (ly:stencil-add s1 s2)))
1841 (define-markup-command (overlay layout props args)
1845 @cindex merging text
1847 Takes a list of markups combining them.
1849 @lilypond[verbatim,quote]
1852 \\override #'(thickness . 2)
1854 \\draw-line #'(0 . 4)
1855 \\arrow-head #Y #DOWN ##f
1856 \\translate #'(0 . 4)\\arrow-head #Y #UP ##f
1860 (apply ly:stencil-add (interpret-markup-list layout props args)))
1863 ;; TODO: should extract baseline-skip from each argument somehow..
1865 (define-markup-command (column layout props args)
1868 #:properties ((baseline-skip))
1870 @cindex stacking text in a column
1872 Stack the markups in @var{args} vertically. The property
1873 @code{baseline-skip} determines the space between markups
1876 @lilypond[verbatim,quote]
1885 (let ((arg-stencils (interpret-markup-list layout props args)))
1886 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1888 (define-markup-command (dir-column layout props args)
1891 #:properties ((direction)
1894 @cindex changing direction of text columns
1896 Make a column of @var{args}, going up or down, depending on the
1897 setting of the @code{direction} layout property.
1899 @lilypond[verbatim,quote]
1901 \\override #`(direction . ,UP) {
1911 \\override #'(direction . 1) {
1918 (stack-lines (if (number? direction) direction -1)
1921 (interpret-markup-list layout props args)))
1923 (define (general-column align-dir baseline mols)
1924 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1926 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1927 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1928 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1929 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1931 (define-markup-command (center-column layout props args)
1934 #:properties ((baseline-skip))
1936 @cindex centering a column of text
1938 Put @code{args} in a centered column.
1940 @lilypond[verbatim,quote]
1949 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1951 (define-markup-command (left-column layout props args)
1954 #:properties ((baseline-skip))
1956 @cindex text columns, left-aligned
1958 Put @code{args} in a left-aligned column.
1960 @lilypond[verbatim,quote]
1969 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1971 (define-markup-command (right-column layout props args)
1974 #:properties ((baseline-skip))
1976 @cindex text columns, right-aligned
1978 Put @code{args} in a right-aligned column.
1980 @lilypond[verbatim,quote]
1989 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1991 (define-markup-command (vcenter layout props arg)
1995 @cindex vertically centering text
1997 Align @code{arg} to its Y@tie{}center.
1999 @lilypond[verbatim,quote]
2007 (let* ((mol (interpret-markup layout props arg)))
2008 (ly:stencil-aligned-to mol Y CENTER)))
2010 (define-markup-command (center-align layout props arg)
2014 @cindex horizontally centering text
2016 Align @code{arg} to its X@tie{}center.
2018 @lilypond[verbatim,quote]
2028 (let* ((mol (interpret-markup layout props arg)))
2029 (ly:stencil-aligned-to mol X CENTER)))
2031 (define-markup-command (right-align layout props arg)
2035 @cindex right aligning text
2037 Align @var{arg} on its right edge.
2039 @lilypond[verbatim,quote]
2049 (let* ((m (interpret-markup layout props arg)))
2050 (ly:stencil-aligned-to m X RIGHT)))
2052 (define-markup-command (left-align layout props arg)
2056 @cindex left aligning text
2058 Align @var{arg} on its left edge.
2060 @lilypond[verbatim,quote]
2070 (let* ((m (interpret-markup layout props arg)))
2071 (ly:stencil-aligned-to m X LEFT)))
2073 (define-markup-command (general-align layout props axis dir arg)
2074 (integer? number? markup?)
2077 @cindex controlling general text alignment
2079 Align @var{arg} in @var{axis} direction to the @var{dir} side.
2081 @lilypond[verbatim,quote]
2085 \\general-align #X #LEFT
2090 \\general-align #X #CENTER
2096 \\general-align #Y #UP
2103 \\general-align #Y #3.2
2110 (let* ((m (interpret-markup layout props arg)))
2111 (ly:stencil-aligned-to m axis dir)))
2113 (define-markup-command (halign layout props dir arg)
2117 @cindex setting horizontal text alignment
2119 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2120 left-aligned, while @code{+1} is right. Values in between interpolate
2121 alignment accordingly.
2123 @lilypond[verbatim,quote]
2148 (let* ((m (interpret-markup layout props arg)))
2149 (ly:stencil-aligned-to m X dir)))
2151 (define-markup-command (with-dimensions layout props x y arg)
2152 (number-pair? number-pair? markup?)
2155 @cindex setting extent of text objects
2157 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2158 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2160 (make-transparent-box-stencil x y)
2162 `(delay-stencil-evaluation ,(delay expr))
2165 (define-markup-command (pad-around layout props amount arg)
2168 "Add padding @var{amount} all around @var{arg}.
2170 @lilypond[verbatim,quote]
2183 (let* ((m (interpret-markup layout props arg))
2184 (x (interval-widen (ly:stencil-extent m X) amount))
2185 (y (interval-widen (ly:stencil-extent m Y) amount)))
2186 (ly:stencil-add (make-transparent-box-stencil x y)
2189 (define-markup-command (pad-x layout props amount arg)
2193 @cindex padding text horizontally
2195 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2197 @lilypond[verbatim,quote]
2210 (let* ((m (interpret-markup layout props arg))
2211 (x (ly:stencil-extent m X))
2212 (y (ly:stencil-extent m Y)))
2213 (ly:make-stencil (ly:stencil-expr m)
2214 (interval-widen x amount)
2217 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2218 (integer? ly:dir? markup? markup?)
2220 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2221 (let ((m1 (interpret-markup layout props arg1))
2222 (m2 (interpret-markup layout props arg2)))
2223 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2225 (define-markup-command (transparent layout props arg)
2228 "Make @var{arg} transparent.
2230 @lilypond[verbatim,quote]
2237 (let* ((m (interpret-markup layout props arg))
2238 (x (ly:stencil-extent m X))
2239 (y (ly:stencil-extent m Y)))
2240 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2242 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2243 (number-pair? number-pair? markup?)
2245 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2247 @lilypond[verbatim,quote]
2254 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2260 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2261 (interpret-markup layout props arg)))
2263 (define-markup-command (hcenter-in layout props length arg)
2266 "Center @var{arg} horizontally within a box of extending
2267 @var{length}/2 to the left and right.
2269 @lilypond[quote,verbatim]
2272 \\set Staff.instrumentName = \\markup {
2279 \\set Staff.instrumentName = \\markup {
2288 (interpret-markup layout props
2289 (make-pad-to-box-markup
2290 (cons (/ length -2) (/ length 2))
2292 (make-center-align-markup arg))))
2294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2298 (define-markup-command (property-recursive layout props symbol)
2301 "Print out a warning when a header field markup contains some recursive
2303 (ly:warning "Recursive definition of property ~a detected!" symbol)
2306 (define-markup-command (fromproperty layout props symbol)
2309 "Read the @var{symbol} from property settings, and produce a stencil
2310 from the markup contained within. If @var{symbol} is not defined, it
2311 returns an empty markup.
2313 @lilypond[verbatim,quote]
2315 myTitle = \"myTitle\"
2319 \\fromproperty #'header:myTitle
2326 (let ((m (chain-assoc-get symbol props)))
2328 ;; prevent infinite loops by clearing the interpreted property:
2329 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2332 (define-markup-command (on-the-fly layout props procedure arg)
2333 (procedure? markup?)
2335 "Apply the @var{procedure} markup command to @var{arg}.
2336 @var{procedure} takes the same arguments as @code{interpret-markup}
2337 and returns a stencil."
2338 (procedure layout props arg))
2340 (define-markup-command (footnote layout props mkup note)
2343 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2345 @lilypond[verbatim,quote]
2348 \\override #'(padding . 0.2)
2352 The footnote will not be annotated automatically."
2353 (ly:stencil-combine-at-edge
2354 (interpret-markup layout props mkup)
2358 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2363 (define-markup-command (auto-footnote layout props mkup note)
2366 #:properties ((raise 0.5)
2368 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2370 @lilypond[verbatim,quote]
2373 \\override #'(padding . 0.2)
2377 The footnote will be annotated automatically."
2378 (let* ((markup-stencil (interpret-markup layout props mkup))
2379 (footnote-hash (gensym "footnote"))
2381 (gauge-stencil (interpret-markup
2384 ((ly:output-def-lookup
2386 'footnote-numbering-function)
2388 (x-ext (ly:stencil-extent gauge-stencil X))
2389 (y-ext (ly:stencil-extent gauge-stencil Y))
2391 `(delay-stencil-evaluation
2395 (ly:output-def-lookup layout
2396 'number-footnote-table))
2397 (footnote-stencil (if (list? table)
2398 (assoc-get footnote-hash
2401 (footnote-stencil (if (ly:stencil? footnote-stencil)
2404 (ly:programming-error
2405 "Cannot find correct footnote for a markup object.")
2407 (gap (- (interval-length x-ext)
2409 (ly:stencil-extent footnote-stencil X))))
2410 (y-trans (- (+ (cdr y-ext)
2412 (cdr (ly:stencil-extent footnote-stencil
2414 (ly:stencil-translate footnote-stencil
2415 (cons gap y-trans)))))))
2416 (main-stencil (ly:stencil-combine-at-edge
2420 (ly:make-stencil footnote-number x-ext y-ext)
2425 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2429 (define-markup-command (override layout props new-prop arg)
2433 @cindex overriding properties within text markup
2435 Add the argument @var{new-prop} to the property list. Properties
2436 may be any property supported by @rinternals{font-interface},
2437 @rinternals{text-interface} and
2438 @rinternals{instrument-specific-markup-interface}.
2440 @lilypond[verbatim,quote]
2448 \\override #'(baseline-skip . 4) {
2457 (interpret-markup layout (cons (list new-prop) props) arg))
2459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2463 (define-markup-command (verbatim-file layout props name)
2466 "Read the contents of file @var{name}, and include it verbatim.
2468 @lilypond[verbatim,quote]
2470 \\verbatim-file #\"simple.ly\"
2473 (interpret-markup layout props
2474 (if (ly:get-option 'safe)
2475 "verbatim-file disabled in safe mode"
2476 (let* ((str (ly:gulp-file name))
2477 (lines (string-split str #\nl)))
2478 (make-typewriter-markup
2479 (make-column-markup lines))))))
2481 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2483 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2486 (define-markup-command (smaller layout props arg)
2489 "Decrease the font size relative to the current setting.
2491 @lilypond[verbatim,quote]
2504 (interpret-markup layout props
2505 `(,fontsize-markup -1 ,arg)))
2507 (define-markup-command (larger layout props arg)
2510 "Increase the font size relative to the current setting.
2512 @lilypond[verbatim,quote]
2520 (interpret-markup layout props
2521 `(,fontsize-markup 1 ,arg)))
2523 (define-markup-command (finger layout props arg)
2526 "Set @var{arg} as small numbers.
2528 @lilypond[verbatim,quote]
2535 (interpret-markup layout
2536 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2539 (define-markup-command (abs-fontsize layout props size arg)
2542 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2543 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2545 @lilypond[verbatim,quote]
2547 default text font size
2549 \\abs-fontsize #16 { text font size 16 }
2551 \\abs-fontsize #12 { text font size 12 }
2554 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2555 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2556 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2557 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2558 (magnification (/ size ref-size)))
2562 `((baseline-skip . ,(* magnification ref-baseline))
2563 (word-space . ,(* magnification ref-word-space))
2564 (font-size . ,(magnification->font-size magnification)))
2568 (define-markup-command (fontsize layout props increment arg)
2571 #:properties ((font-size 0)
2574 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2577 @lilypond[verbatim,quote]
2588 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2589 (word-space . ,(* word-space (magstep increment)))
2590 (font-size . ,(+ font-size increment)))
2594 (define-markup-command (magnify layout props sz arg)
2598 @cindex magnifying text
2600 Set the font magnification for its argument. In the following
2601 example, the middle@tie{}A is 10% larger:
2604 A \\magnify #1.1 @{ A @} A
2607 Note: Magnification only works if a font name is explicitly selected.
2608 Use @code{\\fontsize} otherwise.
2610 @lilypond[verbatim,quote]
2621 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2624 (define-markup-command (bold layout props arg)
2627 "Switch to bold font-series.
2629 @lilypond[verbatim,quote]
2637 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2639 (define-markup-command (sans layout props arg)
2642 "Switch to the sans serif font family.
2644 @lilypond[verbatim,quote]
2653 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2655 (define-markup-command (number layout props arg)
2658 "Set font family to @code{number}, which yields the font used for
2659 time signatures and fingerings. This font contains numbers and
2660 some punctuation; it has no letters.
2662 @lilypond[verbatim,quote]
2665 0 1 2 3 4 5 6 7 8 9 . ,
2669 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2671 (define-markup-command (roman layout props arg)
2674 "Set font family to @code{roman}.
2676 @lilypond[verbatim,quote]
2682 text in roman font family
2689 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2691 (define-markup-command (huge layout props arg)
2694 "Set font size to +2.
2696 @lilypond[verbatim,quote]
2704 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2706 (define-markup-command (large layout props arg)
2709 "Set font size to +1.
2711 @lilypond[verbatim,quote]
2719 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2721 (define-markup-command (normalsize layout props arg)
2724 "Set font size to default.
2726 @lilypond[verbatim,quote]
2739 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2741 (define-markup-command (small layout props arg)
2744 "Set font size to -1.
2746 @lilypond[verbatim,quote]
2754 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2756 (define-markup-command (tiny layout props arg)
2759 "Set font size to -2.
2761 @lilypond[verbatim,quote]
2769 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2771 (define-markup-command (teeny layout props arg)
2774 "Set font size to -3.
2776 @lilypond[verbatim,quote]
2784 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2786 (define-markup-command (fontCaps layout props arg)
2789 "Set @code{font-shape} to @code{caps}
2791 Note: @code{\\fontCaps} requires the installation and selection of
2792 fonts which support the @code{caps} font shape."
2793 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2796 (define-markup-command (smallCaps layout props arg)
2799 "Emit @var{arg} as small caps.
2801 Note: @code{\\smallCaps} does not support accented characters.
2803 @lilypond[verbatim,quote]
2812 (define (char-list->markup chars lower)
2813 (let ((final-string (string-upcase (reverse-list->string chars))))
2815 (markup #:fontsize -2 final-string)
2817 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2818 (if (null? rest-chars)
2820 (reverse! (cons (char-list->markup currents current-is-lower)
2822 (let* ((ch (car rest-chars))
2823 (is-lower (char-lower-case? ch)))
2824 (if (or (and current-is-lower is-lower)
2825 (and (not current-is-lower) (not is-lower)))
2826 (make-small-caps (cdr rest-chars)
2830 (make-small-caps (cdr rest-chars)
2833 (if (null? currents)
2835 (cons (char-list->markup
2836 currents current-is-lower)
2838 (interpret-markup layout props
2840 (make-small-caps (string->list arg) (list) #f (list))
2843 (define-markup-command (caps layout props arg)
2846 "Copy of the @code{\\smallCaps} command.
2848 @lilypond[verbatim,quote]
2857 (interpret-markup layout props (make-smallCaps-markup arg)))
2859 (define-markup-command (dynamic layout props arg)
2862 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2863 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2864 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2865 done in a different font. The recommended font for this is bold and italic.
2866 @lilypond[verbatim,quote]
2874 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2876 (define-markup-command (text layout props arg)
2879 "Use a text font instead of music symbol or music alphabet font.
2881 @lilypond[verbatim,quote]
2894 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2897 (define-markup-command (italic layout props arg)
2900 "Use italic @code{font-shape} for @var{arg}.
2902 @lilypond[verbatim,quote]
2910 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2912 (define-markup-command (typewriter layout props arg)
2915 "Use @code{font-family} typewriter for @var{arg}.
2917 @lilypond[verbatim,quote]
2926 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2928 (define-markup-command (upright layout props arg)
2931 "Set @code{font-shape} to @code{upright}. This is the opposite
2934 @lilypond[verbatim,quote]
2948 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2950 (define-markup-command (medium layout props arg)
2953 "Switch to medium font-series (in contrast to bold).
2955 @lilypond[verbatim,quote]
2968 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2971 (define-markup-command (normal-text layout props arg)
2974 "Set all font related properties (except the size) to get the default
2975 normal text font, no matter what font was used earlier.
2977 @lilypond[verbatim,quote]
2979 \\huge \\bold \\sans \\caps {
2991 (interpret-markup layout
2992 (cons '((font-family . roman) (font-shape . upright)
2993 (font-series . medium) (font-encoding . latin1))
2997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2999 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3001 (define-markup-command (musicglyph layout props glyph-name)
3004 "@var{glyph-name} is converted to a musical symbol; for example,
3005 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
3006 the music font. See @ruser{The Feta font} for a complete listing of
3007 the possible glyphs.
3009 @lilypond[verbatim,quote]
3012 \\musicglyph #\"rests.2\"
3013 \\musicglyph #\"clefs.G_change\"
3016 (let* ((font (ly:paper-get-font layout
3017 (cons '((font-encoding . fetaMusic)
3021 (glyph (ly:font-get-glyph font glyph-name)))
3022 (if (null? (ly:stencil-expr glyph))
3023 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
3027 (define-markup-command (doublesharp layout props)
3030 "Draw a double sharp symbol.
3032 @lilypond[verbatim,quote]
3037 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
3039 (define-markup-command (sesquisharp layout props)
3042 "Draw a 3/2 sharp symbol.
3044 @lilypond[verbatim,quote]
3049 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
3051 (define-markup-command (sharp layout props)
3054 "Draw a sharp symbol.
3056 @lilypond[verbatim,quote]
3061 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
3063 (define-markup-command (semisharp layout props)
3066 "Draw a semisharp symbol.
3068 @lilypond[verbatim,quote]
3073 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
3075 (define-markup-command (natural layout props)
3078 "Draw a natural symbol.
3080 @lilypond[verbatim,quote]
3085 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
3087 (define-markup-command (semiflat layout props)
3090 "Draw a semiflat symbol.
3092 @lilypond[verbatim,quote]
3097 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
3099 (define-markup-command (flat layout props)
3102 "Draw a flat symbol.
3104 @lilypond[verbatim,quote]
3109 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
3111 (define-markup-command (sesquiflat layout props)
3114 "Draw a 3/2 flat symbol.
3116 @lilypond[verbatim,quote]
3121 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3123 (define-markup-command (doubleflat layout props)
3126 "Draw a double flat symbol.
3128 @lilypond[verbatim,quote]
3133 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3135 (define-markup-command (with-color layout props color arg)
3139 @cindex coloring text
3141 Draw @var{arg} in color specified by @var{color}.
3143 @lilypond[verbatim,quote]
3155 (let ((stil (interpret-markup layout props arg)))
3156 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3157 (ly:stencil-extent stil X)
3158 (ly:stencil-extent stil Y))))
3160 (define-markup-command (tied-lyric layout props str)
3163 #:properties ((word-space))
3165 @cindex simple text strings with tie characters
3167 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3169 @lilypond[verbatim,quote]
3171 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3172 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3173 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3176 (define (replace-ties tie str)
3177 (if (string-contains str "~")
3179 ((half-space (/ word-space 2))
3180 (parts (string-split str #\~))
3181 (tie-str (markup #:hspace half-space
3183 #:hspace half-space))
3184 (joined (list-join parts tie-str)))
3185 (make-concat-markup joined))
3188 (define short-tie-regexp (make-regexp "~[^.]~"))
3189 (define (match-short str) (regexp-exec short-tie-regexp str))
3191 (define (replace-short str mkp)
3192 (let ((match (match-short str)))
3194 (make-concat-markup (list
3196 (replace-ties "ties.lyric.default" str)))
3197 (let ((new-str (match:suffix match))
3198 (new-mkp (make-concat-markup (list
3200 (replace-ties "ties.lyric.default"
3201 (match:prefix match))
3202 (replace-ties "ties.lyric.short"
3203 (match:substring match))))))
3204 (replace-short new-str new-mkp)))))
3206 (interpret-markup layout
3208 (replace-short str (markup))))
3210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3214 (define-markup-command (arrow-head layout props axis dir filled)
3215 (integer? ly:dir? boolean?)
3217 "Produce an arrow head in specified direction and axis.
3218 Use the filled head if @var{filled} is specified.
3219 @lilypond[verbatim,quote]
3222 \\general-align #Y #DOWN {
3223 \\arrow-head #Y #UP ##t
3224 \\arrow-head #Y #DOWN ##f
3226 \\arrow-head #X #RIGHT ##f
3227 \\arrow-head #X #LEFT ##f
3233 ((name (format #f "arrowheads.~a.~a~a"
3240 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3244 (define-markup-command (lookup layout props glyph-name)
3247 "Lookup a glyph by name.
3249 @lilypond[verbatim,quote]
3251 \\override #'(font-encoding . fetaBraces) {
3252 \\lookup #\"brace200\"
3255 \\lookup #\"brace180\"
3259 (ly:font-get-glyph (ly:paper-get-font layout props)
3262 (define-markup-command (char layout props num)
3265 "Produce a single character. Characters encoded in hexadecimal
3266 format require the prefix @code{#x}.
3268 @lilypond[verbatim,quote]
3270 \\char #65 \\char ##x00a9
3273 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3275 (define number->mark-letter-vector (make-vector 25 #\A))
3280 (if (= i (- (char->integer #\I) (char->integer #\A)))
3282 (vector-set! number->mark-letter-vector j
3283 (integer->char (+ i (char->integer #\A)))))
3285 (define number->mark-alphabet-vector (list->vector
3286 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3288 (define (number->markletter-string vec n)
3289 "Double letters for big marks."
3290 (let* ((lst (vector-length vec)))
3293 (string-append (number->markletter-string vec (1- (quotient n lst)))
3294 (number->markletter-string vec (remainder n lst)))
3295 (make-string 1 (vector-ref vec n)))))
3297 (define-markup-command (markletter layout props num)
3300 "Make a markup letter for @var{num}. The letters start with A
3301 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3303 @lilypond[verbatim,quote]
3310 (ly:text-interface::interpret-markup layout props
3311 (number->markletter-string number->mark-letter-vector num)))
3313 (define-markup-command (markalphabet layout props num)
3316 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3317 and continue with double letters.
3319 @lilypond[verbatim,quote]
3326 (ly:text-interface::interpret-markup layout props
3327 (number->markletter-string number->mark-alphabet-vector num)))
3329 (define-public (horizontal-slash-interval num forward number-interval mag)
3331 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3332 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3333 (else (interval-widen number-interval (* mag 0.25))))
3334 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3335 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3336 (else (interval-widen number-interval (* mag 0.25))))
3339 (define-public (adjust-slash-stencil num forward stencil mag)
3342 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3344 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3346 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3348 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3351 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3353 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3358 (define (slashed-digit-internal layout props num forward font-size thickness)
3359 (let* ((mag (magstep font-size))
3361 (ly:output-def-lookup layout 'line-thickness)
3363 ;; backward slashes might use slope and point in the other direction!
3364 (dy (* mag (if forward 0.4 -0.4)))
3365 (number-stencil (interpret-markup layout
3366 (prepend-alist-chain 'font-encoding 'fetaText props)
3367 (number->string num)))
3368 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3369 (center (interval-center (ly:stencil-extent number-stencil Y)))
3370 ;; Use the real extents of the slash, not the whole number,
3371 ;; because we might translate the slash later on!
3372 (num-y (interval-widen (cons center center) (abs dy)))
3373 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3374 (slash-stencil (if is-sane
3375 (make-line-stencil thickness
3376 (car num-x) (- (interval-center num-y) dy)
3377 (cdr num-x) (+ (interval-center num-y) dy))
3379 (if (ly:stencil? slash-stencil)
3381 ;; for some numbers we need to shift the slash/backslash up or
3382 ;; down to make the slashed digit look better
3383 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3384 (set! number-stencil
3385 (ly:stencil-add number-stencil slash-stencil)))
3386 (ly:warning "Unable to create slashed digit ~a" num))
3390 (define-markup-command (slashed-digit layout props num)
3393 #:properties ((font-size 0)
3396 @cindex slashed digits
3398 A feta number, with slash. This is for use in the context of
3399 figured bass notation.
3400 @lilypond[verbatim,quote]
3404 \\override #'(thickness . 3)
3408 (slashed-digit-internal layout props num #t font-size thickness))
3410 (define-markup-command (backslashed-digit layout props num)
3413 #:properties ((font-size 0)
3416 @cindex backslashed digits
3418 A feta number, with backslash. This is for use in the context of
3419 figured bass notation.
3420 @lilypond[verbatim,quote]
3422 \\backslashed-digit #5
3424 \\override #'(thickness . 3)
3425 \\backslashed-digit #7
3428 (slashed-digit-internal layout props num #f font-size thickness))
3431 (define eyeglassespath
3432 '((moveto 0.42 0.77)
3433 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3434 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3435 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3436 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3439 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3440 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3441 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3442 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3444 (moveto 1.025 0.935)
3445 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3446 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3449 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3452 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3454 (define-markup-command (eyeglasses layout props)
3457 "Prints out eyeglasses, indicating strongly to look at the conductor.
3458 @lilypond[verbatim,quote]
3459 \\markup { \\eyeglasses }
3461 (interpret-markup layout props
3462 (make-override-markup '(line-cap-style . butt)
3463 (make-path-markup 0.15 eyeglassespath))))
3465 (define-markup-command (left-brace layout props size)
3469 A feta brace in point size @var{size}.
3471 @lilypond[verbatim,quote]
3478 (let* ((font (ly:paper-get-font layout
3479 (cons '((font-encoding . fetaBraces)
3482 (glyph-count (1- (ly:otf-glyph-count font)))
3483 (scale (ly:output-def-lookup layout 'output-scale))
3484 (scaled-size (/ (ly:pt size) scale))
3486 (ly:font-get-glyph font (string-append "brace"
3487 (number->string n)))))
3488 (get-y-from-brace (lambda (brace)
3490 (ly:stencil-extent (glyph brace) Y))))
3491 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3492 (glyph-found (glyph find-brace)))
3494 (if (or (null? (ly:stencil-expr glyph-found))
3495 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3496 (> scaled-size (interval-length
3497 (ly:stencil-extent (glyph glyph-count) Y))))
3499 (ly:warning (_ "no brace found for point size ~S ") size)
3500 (ly:warning (_ "defaulting to ~S pt")
3501 (/ (* scale (interval-length
3502 (ly:stencil-extent glyph-found Y)))
3506 (define-markup-command (right-brace layout props size)
3510 A feta brace in point size @var{size}, rotated 180 degrees.
3512 @lilypond[verbatim,quote]
3519 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3521 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3522 ;; the note command.
3523 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3525 ;; TODO: better syntax.
3527 (define-markup-command (note-by-number layout props log dot-count dir)
3528 (number? number? number?)
3530 #:properties ((font-size 0)
3534 @cindex notes within text by log and dot-count
3536 Construct a note symbol, with stem and flag. By using fractional values for
3537 @var{dir}, longer or shorter stems can be obtained.
3538 Supports all note-head-styles.
3539 Supported flag-styles are @code{default}, @code{old-straight-flag},
3540 @code{modern-straight-flag} and @code{flat-flag}.
3542 @lilypond[verbatim,quote]
3544 \\note-by-number #3 #0 #DOWN
3546 \\note-by-number #1 #2 #0.8
3549 (define (get-glyph-name-candidates dir log style)
3550 (map (lambda (dir-name)
3551 (format #f "noteheads.~a~a" dir-name
3552 (if (and (symbol? style)
3553 (not (equal? 'default style)))
3554 (select-head-glyph style (min log 2))
3556 (list (if (= dir UP) "u" "d")
3559 (define (get-glyph-name font cands)
3562 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3563 (get-glyph-name font (cdr cands))
3566 (define (buildflags flag-stencil remain curr-stencil spacing)
3567 ;; Function to recursively create a stencil with @code{remain} flags
3568 ;; from the single-flag stencil @code{curr-stencil}, which is already
3569 ;; translated to the position of the previous flag position.
3571 ;; Copy and paste from /scm/flag-styles.scm
3573 (let* ((translated-stencil
3574 (ly:stencil-translate-axis curr-stencil spacing Y))
3575 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3576 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3579 (define (straight-flag-mrkp flag-thickness flag-spacing
3580 upflag-angle upflag-length
3581 downflag-angle downflag-length
3583 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3584 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3585 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3586 ;; @var{downflag-length} are given in staff spaces.
3588 ;; All lengths are scaled according to the font size of the note.
3590 ;; From /scm/flag-styles.scm, modified to fit here.
3592 (let* ((stem-up (> dir 0))
3593 ;; scale with the note size
3594 (factor (magstep font-size))
3595 (stem-thickness (* factor 0.1))
3596 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3597 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3598 (raw-length (if stem-up upflag-length downflag-length))
3599 (angle (if stem-up upflag-angle downflag-angle))
3600 (flag-length (+ (* raw-length factor) half-stem-thickness))
3601 (flag-end (if (= angle 0)
3602 (cons flag-length (* half-stem-thickness dir))
3603 (polar->rectangular flag-length angle)))
3604 (thickness (* flag-thickness factor))
3605 (thickness-offset (cons 0 (* -1 thickness dir)))
3606 (spacing (* -1 flag-spacing factor dir))
3607 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3610 (offset-add flag-end thickness-offset)
3611 (offset-add start thickness-offset)))
3612 (stencil (ly:round-filled-polygon points half-stem-thickness))
3613 ;; Log for 1/8 is 3, so we need to subtract 3
3614 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3617 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)
3620 (size-factor (magstep font-size))
3621 (blot (ly:output-def-lookup layout 'blot-diameter))
3623 (let ((result (get-glyph-name font
3624 (get-glyph-name-candidates
3625 (sign dir) log style))))
3626 (if (string-null? result)
3627 ;; If no glyph name can be found, select default heads.
3628 ;; Though this usually means an unsupported style has been
3629 ;; chosen, it also prevents unrelated 'style settings from
3630 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3632 (get-glyph-name font
3633 (get-glyph-name-candidates
3634 (sign dir) log 'default))
3636 (head-glyph (ly:font-get-glyph font head-glyph-name))
3637 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3638 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3639 (stem-length (* size-factor (max 3 (- log 1))))
3640 ;; With ancient-flags we want a tighter stem
3641 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3642 (stemy (* dir stem-length))
3643 (attach-off (cons (interval-index
3644 (ly:stencil-extent head-glyph X)
3645 (* (sign dir) (car attach-indices)))
3646 ;; fixme, this is inconsistent between X & Y.
3649 (ly:stencil-extent head-glyph Y)
3650 (cdr attach-indices)))))
3651 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3653 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3654 (stem-glyph (and (> log 0)
3655 (ly:round-filled-box
3656 (ordered-cons (+ stem-X-corr (car attach-off))
3657 (+ stem-X-corr (car attach-off)
3658 (* (- (sign dir)) stem-thickness)))
3659 (cons (min stemy (cdr attach-off))
3660 (max stemy (cdr attach-off)))
3661 (/ stem-thickness 3))))
3662 (dot (ly:font-get-glyph font "dots.dot"))
3663 (dotwid (interval-length (ly:stencil-extent dot X)))
3664 (dots (and (> dot-count 0)
3665 (apply ly:stencil-add
3667 (ly:stencil-translate-axis
3668 dot (* 2 x dotwid) X))
3669 (iota dot-count)))))
3670 ;; Straight-flags. Values taken from /scm/flag-style.scm
3671 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3672 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3673 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3674 ;; Calculate a corrective to avoid a gap between
3675 ;; straight-flags and the stem.
3676 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3677 (eq? flag-style 'old-straight-flag)
3678 (eq? flag-style 'flat-flag))
3679 (/ blot 10 (* -1 dir))
3681 (flaggl (and (> log 2)
3682 (ly:stencil-translate
3683 (cond ((eq? flag-style 'modern-straight-flag)
3684 modern-straight-flag)
3685 ((eq? flag-style 'old-straight-flag)
3687 ((eq? flag-style 'flat-flag)
3690 (ly:font-get-glyph font
3691 (format #f (if ancient-flags?
3692 "flags.mensural~a2~a"
3694 (if (> dir 0) "u" "d")
3696 (cons (+ (car attach-off)
3697 ;; For tighter stems (with ancient-flags) the
3698 ;; flag has to be adjusted different.
3699 (if (and (not ancient-flags?) (< dir 0))
3702 (+ stemy flag-style-Y-corr))))))
3704 ;; If there is a flag on an upstem and the stem is short, move the dots
3705 ;; to avoid the flag. 16th notes get a special case because their flags
3706 ;; hang lower than any other flags.
3707 ;; Not with ancient flags or straight-flags.
3708 (if (and dots (> dir 0) (> log 2)
3709 (or (eq? flag-style 'default) (null? flag-style))
3710 (not ancient-flags?)
3711 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3712 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3714 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3715 (if (ly:stencil? stem-glyph)
3716 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3717 (set! stem-glyph head-glyph))
3718 (if (ly:stencil? dots)
3721 (ly:stencil-translate-axis
3723 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3729 (let ((divisor (log 2)))
3730 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3732 (define (parse-simple-duration duration-string)
3733 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3734 and return a (log dots) list."
3735 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3737 (if (and match (string=? duration-string (match:substring match 0)))
3738 (let ((len (match:substring match 1))
3739 (dots (match:substring match 2)))
3740 (list (cond ((string=? len "breve") -1)
3741 ((string=? len "longa") -2)
3742 ((string=? len "maxima") -3)
3743 (else (log2 (string->number len))))
3744 (if dots (string-length dots) 0)))
3745 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3747 (define-markup-command (note layout props duration dir)
3750 #:properties (note-by-number-markup)
3752 @cindex notes within text by string
3754 This produces a note with a stem pointing in @var{dir} direction, with
3755 the @var{duration} for the note head type and augmentation dots. For
3756 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3757 a shortened down stem.
3759 @lilypond[verbatim,quote]
3761 \\override #'(style . cross) {
3765 \\note #\"breve\" #0
3768 (let ((parsed (parse-simple-duration duration)))
3769 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3771 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3772 ;; the rest command.
3773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3775 (define-markup-command (rest-by-number layout props log dot-count)
3778 #:properties ((font-size 0)
3780 (multi-measure-rest #f))
3782 @cindex rests or multi-measure-rests within text by log and dot-count
3784 A rest or multi-measure-rest symbol.
3786 @lilypond[verbatim,quote]
3788 \\rest-by-number #3 #2
3790 \\rest-by-number #0 #1
3792 \\override #'(multi-measure-rest . #t)
3793 \\rest-by-number #0 #0
3797 (define (get-glyph-name-candidates log style)
3798 (let* (;; Choose the style-string to be added.
3799 ;; If no glyph exists, select others for the specified styles
3800 ;; otherwise defaulting.
3803 ;; 'baroque needs to be special-cased, otherwise
3804 ;; `select-head-glyph´ would catch neomensural-glyphs for
3805 ;; this style, if (< log 0).
3806 (eq? style 'baroque)
3807 (string-append (number->string log) ""))
3808 ((eq? style 'petrucci)
3809 (string-append (number->string log) "mensural"))
3810 ;; In other cases `select-head-glyph´ from output-lib.scm
3811 ;; works for rest-glyphs, too.
3812 ((and (symbol? style) (not (eq? style 'default)))
3813 (select-head-glyph style log))
3815 ;; Choose ledgered glyphs for whole and half rest.
3816 ;; Except for the specified styles, logs and MultiMeasureRests.
3818 (if (and (or (list? style)
3820 '(neomensural mensural petrucci))))
3821 (not multi-measure-rest)
3822 (or (= log 0) (= log 1)))
3825 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3827 (define (get-glyph-name font cands)
3828 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3833 (ly:paper-get-font layout
3834 (cons '((font-encoding . fetaMusic)
3839 (get-glyph-name font
3840 (get-glyph-name-candidates log style))))
3841 (if (string-null? result)
3842 ;; If no glyph name can be found, select default rests. Though
3843 ;; this usually means an unsupported style has been chosen, it
3844 ;; also prevents unrelated 'style settings from other grobs
3845 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3846 (get-glyph-name font (get-glyph-name-candidates log 'default))
3848 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3849 (dot (ly:font-get-glyph font "dots.dot"))
3850 (dot-width (interval-length (ly:stencil-extent dot X)))
3851 (dots (and (> dot-count 0)
3852 (apply ly:stencil-add
3854 (ly:stencil-translate-axis
3855 dot (* 2 x dot-width) X))
3856 (iota dot-count))))))
3858 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3859 ;; glyphs are taken for whole and half rests.
3860 ;; If they are dotted, move the dots in X-direction to avoid collision.
3864 (not (member style '(neomensural mensural petrucci))))
3865 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3867 ;; Add dots to the rest-glyph.
3869 ;; Not sure how to vertical align dots.
3870 ;; For now the dots are centered for half, whole or longer rests.
3871 ;; Otherwise placed near the top of the rest.
3873 ;; Dots for rests with (< log 0) dots are allowed, but not
3874 ;; if multi-measure-rest is set #t.
3875 (if (and (not multi-measure-rest) dots)
3878 (ly:stencil-translate
3881 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3883 (interval-center (ly:stencil-extent rest-glyph Y))
3884 (- (interval-end (ly:stencil-extent rest-glyph Y))
3885 (/ (* 2 dot-width) 3)))))
3889 (define-markup-command (rest layout props duration)
3892 #:properties ((style '())
3893 (multi-measure-rest #f)
3894 (multi-measure-rest-number #t)
3897 @cindex rests or multi-measure-rests within text by string
3899 This produces a rest, with the @var{duration} for the rest type and
3901 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3904 Printing MultiMeasureRests could be enabled with
3905 @code{\\override #'(multi-measure-rest . #t)}
3906 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3907 This is enabled for all styles using default-glyphs.
3908 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3910 @lilypond[verbatim,quote]
3916 \\override #'(multi-measure-rest . #t)
3920 \\override #'(multi-measure-rest-number . #f)
3925 ;; Get the number of mmr-glyphs.
3926 ;; Store them in a list.
3927 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3928 (define (mmr-numbers nmbr)
3929 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3930 (8-remainder (remainder nmbr 8))
3931 (4-bar-glyph (floor (/ 8-remainder 4)))
3932 (4-remainder (remainder nmbr 4))
3933 (2-bar-glyph (floor (/ 4-remainder 2)))
3934 (2-remainder (remainder 4-remainder 2))
3935 (1-bar-glyph (floor (/ 2-remainder 1))))
3936 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3938 ;; Get the correct mmr-glyphs.
3939 ;; Store them in a list.
3941 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3942 ;; -> ("rests.M3" "rests.M1")
3943 (define (get-mmr-glyphs lst1 lst2)
3944 (define (helper l1 l2 l3)
3949 (append (make-list (car l1) (car l2)) l3))))
3950 (helper lst1 lst2 '()))
3952 ;; If duration is not valid, print a warning and return empty-stencil
3953 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3954 (not multi-measure-rest))
3955 (and (= (string-length (car (string-split duration #\. ))) 1)
3956 (= (string->number (car (string-split duration #\. ))) 0)))
3958 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3961 ;; For simple rests:
3962 ;; Get a (log dots) list.
3963 (parsed (parse-simple-duration duration))
3964 ;; Create the rest-stencil
3966 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3967 ;; For MultiMeasureRests:
3968 ;; Get the duration-part of duration
3969 (dur-part-string (car (string-split duration #\. )))
3970 ;; Get the duration of MMR:
3971 ;; If not a number (eg. "maxima") calculate it.
3973 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3974 ;; Get a list of the correct number of each mmr-glyph.
3975 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3976 ;; Create a list of mmr-stencils,
3977 ;; translating the glyph for a whole rest.
3981 (let ((single-mmr-stil
3982 (rest-by-number-markup layout props (* -1 x) 0)))
3984 (ly:stencil-translate-axis
3986 ;; Ugh, hard-coded, why 1?
3990 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3991 ;; Adjust the space between the mmr-glyphs,
3992 ;; if not default-glyphs are used.
3993 (word-space (if (member style
3994 '(neomensural mensural petrucci))
3995 (/ (* word-space 2) 3)
3997 ;; Create the final mmr-stencil
3998 ;; via `stack-stencil-line´ from /scm/markup.scm
3999 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
4001 ;; Print the number above a multi-measure-rest
4002 ;; Depends on duration, style and multi-measure-rest-number set #t
4003 (if (and multi-measure-rest
4004 multi-measure-rest-number
4006 (not (member style '(neomensural mensural petrucci))))
4007 (let* ((mmr-stil-x-center
4008 (interval-center (ly:stencil-extent mmr-stil X)))
4012 #:override '(font-encoding . fetaText)
4013 (number->string mmr-duration)))
4015 (interpret-markup layout props duration-markup))
4016 (mmr-number-stil-x-center
4017 (interval-center (ly:stencil-extent mmr-number-stil X))))
4019 (set! mmr-stil (ly:stencil-combine-at-edge
4022 (ly:stencil-translate-axis
4024 (- mmr-stil-x-center mmr-number-stil-x-center)
4028 (if multi-measure-rest
4032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4036 (define-markup-command (fermata layout props) ()
4038 #:properties ((direction UP))
4039 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
4040 an inverted glyph. Note that within music, one would usually use the
4041 @code{\\fermata} articulation instead of a markup.
4043 @lilypond[verbatim,quote]
4044 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
4046 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
4049 (interpret-markup layout props
4050 (if (eqv? direction DOWN)
4051 (markup #:musicglyph "scripts.dfermata")
4052 (markup #:musicglyph "scripts.ufermata"))))
4054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4058 (define-markup-command (lower layout props amount arg)
4062 @cindex lowering text
4064 Lower @var{arg} by the distance @var{amount}.
4065 A negative @var{amount} indicates raising; see also @code{\\raise}.
4067 @lilypond[verbatim,quote]
4075 (ly:stencil-translate-axis (interpret-markup layout props arg)
4078 (define-markup-command (translate-scaled layout props offset arg)
4079 (number-pair? markup?)
4081 #:properties ((font-size 0))
4083 @cindex translating text
4084 @cindex scaling text
4086 Translate @var{arg} by @var{offset}, scaling the offset by the
4089 @lilypond[verbatim,quote]
4092 * \\translate #'(2 . 3) translate
4094 * \\translate-scaled #'(2 . 3) translate-scaled
4098 (let* ((factor (magstep font-size))
4099 (scaled (cons (* factor (car offset))
4100 (* factor (cdr offset)))))
4101 (ly:stencil-translate (interpret-markup layout props arg)
4104 (define-markup-command (raise layout props amount arg)
4108 @cindex raising text
4110 Raise @var{arg} by the distance @var{amount}.
4111 A negative @var{amount} indicates lowering, see also @code{\\lower}.
4113 The argument to @code{\\raise} is the vertical displacement amount,
4114 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
4115 raise objects in relation to their surrounding markups.
4117 If the text object itself is positioned above or below the staff, then
4118 @code{\\raise} cannot be used to move it, since the mechanism that
4119 positions it next to the staff cancels any shift made with
4120 @code{\\raise}. For vertical positioning, use the @code{padding}
4121 and/or @code{extra-offset} properties.
4123 @lilypond[verbatim,quote]
4132 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4134 (define-markup-command (fraction layout props arg1 arg2)
4137 #:properties ((font-size 0))
4139 @cindex creating text fractions
4141 Make a fraction of two markups.
4142 @lilypond[verbatim,quote]
4148 (let* ((m1 (interpret-markup layout props arg1))
4149 (m2 (interpret-markup layout props arg2))
4150 (factor (magstep font-size))
4151 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4152 (padding (* factor 0.2))
4153 (baseline (* factor 0.6))
4154 (offset (* factor 0.75)))
4155 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4156 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4157 (let* ((x1 (ly:stencil-extent m1 X))
4158 (x2 (ly:stencil-extent m2 X))
4159 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4160 ;; should stack mols separately, to maintain LINE on baseline
4161 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4163 (ly:stencil-aligned-to stack Y CENTER))
4165 (ly:stencil-aligned-to stack X LEFT))
4166 ;; should have EX dimension
4168 (ly:stencil-translate-axis stack offset Y))))
4170 (define-markup-command (normal-size-super layout props arg)
4173 #:properties ((font-size 0))
4175 @cindex setting superscript in standard font size
4177 Set @var{arg} in superscript with a normal font size.
4179 @lilypond[verbatim,quote]
4182 \\normal-size-super {
4183 superscript in standard size
4187 (ly:stencil-translate-axis
4188 (interpret-markup layout props arg)
4189 (* 1.0 (magstep font-size)) Y))
4191 (define-markup-command (super layout props arg)
4194 #:properties ((font-size 0))
4196 @cindex superscript text
4198 Set @var{arg} in superscript.
4200 @lilypond[verbatim,quote]
4210 (ly:stencil-translate-axis
4213 (cons `((font-size . ,(- font-size 3))) props)
4215 (* 1.0 (magstep font-size)) ; original font-size
4218 (define-markup-command (translate layout props offset arg)
4219 (number-pair? markup?)
4222 @cindex translating text
4224 Translate @var{arg} relative to its surroundings. @var{offset}
4225 is a pair of numbers representing the displacement in the X and Y axis.
4227 @lilypond[verbatim,quote]
4230 \\translate #'(2 . 3)
4231 \\line { translated two spaces right, three up }
4234 (ly:stencil-translate (interpret-markup layout props arg)
4237 (define-markup-command (sub layout props arg)
4240 #:properties ((font-size 0))
4242 @cindex subscript text
4244 Set @var{arg} in subscript.
4246 @lilypond[verbatim,quote]
4257 (ly:stencil-translate-axis
4260 (cons `((font-size . ,(- font-size 3))) props)
4262 (* -0.75 (magstep font-size)) ; original font-size
4265 (define-markup-command (normal-size-sub layout props arg)
4268 #:properties ((font-size 0))
4270 @cindex setting subscript in standard font size
4272 Set @var{arg} in subscript with a normal font size.
4274 @lilypond[verbatim,quote]
4278 subscript in standard size
4282 (ly:stencil-translate-axis
4283 (interpret-markup layout props arg)
4284 (* -0.75 (magstep font-size))
4287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4291 (define-markup-command (hbracket layout props arg)
4295 @cindex placing horizontal brackets around text
4297 Draw horizontal brackets around @var{arg}.
4299 @lilypond[verbatim,quote]
4308 (let ((th 0.1) ;; todo: take from GROB.
4309 (m (interpret-markup layout props arg)))
4310 (bracketify-stencil m X th (* 2.5 th) th)))
4312 (define-markup-command (bracket layout props arg)
4316 @cindex placing vertical brackets around text
4318 Draw vertical brackets around @var{arg}.
4320 @lilypond[verbatim,quote]
4327 (let ((th 0.1) ;; todo: take from GROB.
4328 (m (interpret-markup layout props arg)))
4329 (bracketify-stencil m Y th (* 2.5 th) th)))
4331 (define-markup-command (parenthesize layout props arg)
4334 #:properties ((angularity 0)
4340 @cindex placing parentheses around text
4342 Draw parentheses around @var{arg}. This is useful for parenthesizing
4343 a column containing several lines of text.
4345 @lilypond[verbatim,quote]
4354 \\override #'(angularity . 2) {
4365 (let* ((m (interpret-markup layout props arg))
4366 (scaled-width (* size width))
4368 (* (chain-assoc-get 'line-thickness props 0.1)
4371 (min (* size 0.5 scaled-thickness)
4372 (* (/ 4 3.0) scaled-width)))
4373 (padding (chain-assoc-get 'padding props half-thickness)))
4374 (parenthesize-stencil
4375 m half-thickness scaled-width angularity padding)))
4378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4379 ;; Delayed markup evaluation
4380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4382 (define-markup-command (page-ref layout props label gauge default)
4383 (symbol? markup? markup?)
4386 @cindex referencing page numbers in text
4388 Reference to a page number. @var{label} is the label set on the referenced
4389 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4390 the maximum width of the page number, and @var{default} the value to display
4391 when @var{label} is not found.
4393 (If the current book or bookpart is set to use roman numerals for page numbers,
4394 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4395 width may require additional tweaking.)"
4396 (let* ((gauge-stencil (interpret-markup layout props gauge))
4397 (x-ext (ly:stencil-extent gauge-stencil X))
4398 (y-ext (ly:stencil-extent gauge-stencil Y)))
4400 (make-transparent-box-stencil x-ext y-ext))
4402 `(delay-stencil-evaluation
4403 ,(delay (ly:stencil-expr
4404 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4405 (page-number (if (list? table)
4406 (assoc-get label table)
4408 (number-type (ly:output-def-lookup layout 'page-number-type))
4409 (page-markup (if page-number
4410 (number-format number-type page-number)
4412 (page-stencil (interpret-markup layout props page-markup))
4413 (gap (- (interval-length x-ext)
4414 (interval-length (ly:stencil-extent page-stencil X)))))
4415 (interpret-markup layout props
4416 (markup #:hspace gap page-markup))))))
4420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4424 (define-markup-command (scale layout props factor-pair arg)
4425 (number-pair? markup?)
4428 @cindex scaling markup
4429 @cindex mirroring markup
4431 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4432 representing the scaling-factor in the X and Y axes.
4433 Negative values may be used to produce mirror images.
4435 @lilypond[verbatim,quote]
4445 (let ((stil (interpret-markup layout props arg))
4446 (sx (car factor-pair))
4447 (sy (cdr factor-pair)))
4448 (ly:stencil-scale stil sx sy)))
4450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4454 (define-markup-command (pattern layout props count axis space pattern)
4455 (integer? integer? number? markup?)
4458 Prints @var{count} times a @var{pattern} markup.
4459 Patterns are spaced apart by @var{space}.
4460 Patterns are distributed on @var{axis}.
4462 @lilypond[verbatim, quote]
4464 \"Horizontally repeated :\"
4465 \\pattern #7 #X #2 \\flat
4467 \"Vertically repeated :\"
4468 \\pattern #3 #Y #0.5 \\flat
4471 (let ((pattern-width (interval-length
4472 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4473 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4474 (let loop ((i (1- count)) (patterns (markup)))
4480 (markup patterns pattern)
4481 (markup #:column (patterns pattern))))
4484 (markup patterns pattern #:hspace space)
4485 (markup #:column (patterns pattern #:vspace space))))))))
4487 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4488 (number? ly:dir? markup? markup? markup?)
4490 #:properties ((word-space)
4493 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4494 with a line of markups @var{pattern} in between.
4495 Patterns are spaced apart by @var{space}.
4496 Patterns are aligned to the @var{dir} markup.
4498 @lilypond[verbatim, quote]
4501 \\fill-with-pattern #1 #RIGHT . first right
4502 \\fill-with-pattern #1 #RIGHT . second right
4504 \"center-aligned :\"
4505 \\fill-with-pattern #1.5 #CENTER - left right
4508 \\override #'(line-width . 50)
4509 \\fill-with-pattern #2 #LEFT : left first
4510 \\override #'(line-width . 50)
4511 \\fill-with-pattern #2 #LEFT : left second
4514 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4515 (pattern-width (interval-length pattern-x-extent))
4516 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4517 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4518 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4519 (period (+ space pattern-width))
4520 (count (truncate (/ (- middle-width pattern-width) period)))
4521 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4522 (interpret-markup layout props
4524 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4525 #:translate (cons x-offset 0)
4526 #:pattern (1+ count) X space pattern
4529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4533 (define-markup-command (replace layout props replacements arg)
4537 Used to automatically replace a string by another in the markup @var{arg}.
4538 Each pair of the alist @var{replacements} specifies what should be replaced.
4539 The @code{key} is the string to be replaced by the @code{value} string.
4541 @lilypond[verbatim, quote]
4542 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4546 (internal-add-text-replacements
4551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4552 ;; Markup list commands
4553 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4555 (define-public (space-lines baseline stils)
4556 (let space-stil ((stils stils)
4560 (let* ((stil (car stils))
4561 (dy-top (max (- (/ baseline 1.5)
4562 (interval-bound (ly:stencil-extent stil Y) UP))
4564 (dy-bottom (max (+ (/ baseline 3.0)
4565 (interval-bound (ly:stencil-extent stil Y) DOWN))
4567 (new-stil (ly:make-stencil
4568 (ly:stencil-expr stil)
4569 (ly:stencil-extent stil X)
4570 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4572 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4574 (space-stil (cdr stils) (cons new-stil result))))))
4576 (define-markup-list-command (justified-lines layout props args)
4578 #:properties ((baseline-skip)
4579 wordwrap-internal-markup-list)
4581 @cindex justifying lines of text
4583 Like @code{\\justify}, but return a list of lines instead of a single markup.
4584 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4585 @var{X}@tie{}is the number of staff spaces."
4586 (space-lines baseline-skip
4587 (interpret-markup-list layout props
4588 (make-wordwrap-internal-markup-list #t args))))
4590 (define-markup-list-command (wordwrap-lines layout props args)
4592 #:properties ((baseline-skip)
4593 wordwrap-internal-markup-list)
4594 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4595 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4596 where @var{X} is the number of staff spaces."
4597 (space-lines baseline-skip
4598 (interpret-markup-list layout props
4599 (make-wordwrap-internal-markup-list #f args))))
4601 (define-markup-list-command (column-lines layout props args)
4603 #:properties ((baseline-skip))
4604 "Like @code{\\column}, but return a list of lines instead of a single markup.
4605 @code{baseline-skip} determines the space between each markup in @var{args}."
4606 (space-lines baseline-skip
4607 (interpret-markup-list layout props args)))
4609 (define-markup-list-command (override-lines layout props new-prop args)
4610 (pair? markup-list?)
4611 "Like @code{\\override}, for markup lists."
4612 (interpret-markup-list layout (cons (list new-prop) props) args))
4614 (define-markup-list-command (map-markup-commands layout props compose args)
4615 (procedure? markup-list?)
4616 "This applies the function @var{compose} to every markup in
4617 @var{args} (including elements of markup list command calls) in order
4618 to produce a new markup list. Since the return value from a markup
4619 list command call is not a markup list but rather a list of stencils,
4620 this requires passing those stencils off as the results of individual
4621 markup calls. That way, the results should work out as long as no
4622 markups rely on side effects."
4623 (let ((key (make-symbol "key")))
4627 ;; if `compose' does not actually interpret its markup
4628 ;; argument, we still need to return a list of stencils,
4629 ;; created from the single returned stencil
4631 (interpret-markup layout props
4633 (make-on-the-fly-markup
4634 (lambda (layout props m)
4635 ;; here all effects of `compose' on the
4636 ;; properties should be visible, so we
4637 ;; call interpret-markup-list at this
4638 ;; point of time and harvest its
4641 (interpret-markup-list
4642 layout props args)))
4643 (make-null-markup))))))
4644 (lambda (key stencils)
4647 (interpret-markup layout props
4648 (compose (make-stencil-markup sten))))