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 rectangle. @code{rounded-box}
822 produces a rounded rectangle. @code{outline} approximates the
823 outline of the markup.
825 @lilypond[verbatim,quote]
828 \\filled-box #'(-1 . 15) #'(-3 . 4) #1
829 \\override #'(thickness . 1.5)
830 \\whiteout whiteout-box
834 \\filled-box #'(-1 . 24) #'(-3 . 4) #1
835 \\override #'(style . rounded-box)
836 \\override #'(thickness . 3)
837 \\whiteout whiteout-rounded-box
841 \\filled-box #'(-1 . 18) #'(-3 . 4) #1
842 \\override #'(style . outline)
843 \\override #'(thickness . 3)
844 \\whiteout whiteout-outline
848 (interpret-markup layout props arg)
851 (ly:output-def-lookup layout 'line-thickness)))
853 (define-markup-command (pad-markup layout props amount arg)
858 @cindex putting space around text
860 Add space around a markup object.
861 Identical to @code{pad-around}.
863 @lilypond[verbatim,quote]
876 (let* ((m (interpret-markup layout props arg))
877 (x (interval-widen (ly:stencil-extent m X) amount))
878 (y (interval-widen (ly:stencil-extent m Y) amount)))
879 (ly:stencil-add (make-transparent-box-stencil x y)
882 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
886 (define-markup-command (strut layout props)
890 @cindex creating vertical spaces in text
892 Create a box of the same height as the space in the current font."
893 (let ((m (ly:text-interface::interpret-markup layout props " ")))
894 (ly:make-stencil (ly:stencil-expr m)
896 (ly:stencil-extent m X)
899 (define-markup-command (hspace layout props amount)
903 @cindex creating horizontal spaces in text
905 Create an invisible object taking up horizontal space @var{amount}.
907 @lilypond[verbatim,quote]
916 (ly:make-stencil "" (cons 0 amount) empty-interval))
918 (define-markup-command (vspace layout props amount)
922 @cindex creating vertical spaces in text
924 Create an invisible object taking up vertical space
925 of @var{amount} multiplied by 3.
927 @lilypond[verbatim,quote]
938 (let ((amount (* amount 3.0)))
939 (ly:make-stencil "" empty-interval (cons 0 amount))))
942 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
943 ;; importing graphics.
944 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
946 (define-markup-command (stencil layout props stil)
950 @cindex importing stencils into text
952 Use a stencil as markup.
954 @lilypond[verbatim,quote]
956 \\stencil #(make-circle-stencil 2 0 #t)
962 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
964 (define (get-postscript-bbox string)
965 "Extract the bbox from STRING, or return #f if not present."
967 ((match (regexp-exec bbox-regexp string)))
971 (string->number (match:substring match x)))
976 (define-markup-command (epsfile layout props axis size file-name)
977 (number? number? string?)
980 @cindex inlining an Encapsulated PostScript image
982 Inline an EPS image. The image is scaled along @var{axis} to
985 @lilypond[verbatim,quote]
987 \\general-align #Y #DOWN {
988 \\epsfile #X #20 #\"context-example.eps\"
989 \\epsfile #Y #20 #\"context-example.eps\"
993 (if (ly:get-option 'safe)
994 (interpret-markup layout props "not allowed in safe")
995 (eps-file->stencil axis size file-name)
998 (define-markup-command (postscript layout props str)
1002 @cindex inserting PostScript directly into text
1003 This inserts @var{str} directly into the output as a PostScript
1006 @lilypond[verbatim,quote]
1010 0.4 0.6 0.5 0 361 arc
1012 1.0 0.6 0.5 0 361 arc
1017 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
1018 \\postscript #ringsps
1030 gsave currentpoint translate
1038 (define-markup-command (path layout props thickness commands) (number? list?)
1040 #:properties ((line-cap-style 'round)
1041 (line-join-style 'round)
1044 @cindex paths, drawing
1045 @cindex drawing paths
1046 Draws a path with line @var{thickness} according to the
1047 directions given in @var{commands}. @var{commands} is a list of
1048 lists where the @code{car} of each sublist is a drawing command and
1049 the @code{cdr} comprises the associated arguments for each command.
1051 There are seven commands available to use in the list
1052 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
1053 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
1054 @code{closepath}. Note that the commands that begin with @emph{r}
1055 are the relative variants of the other three commands.
1057 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
1058 @code{rlineto} take 2 arguments; they are the X and Y coordinates
1059 for the destination point.
1061 The commands @code{curveto} and @code{rcurveto} create cubic
1062 BĆ©zier curves, and take 6 arguments; the first two are the X and Y
1063 coordinates for the first control point, the second two are the X
1064 and Y coordinates for the second control point, and the last two
1065 are the X and Y coordinates for the destination point.
1067 The @code{closepath} command takes zero arguments and closes the
1068 current subpath in the active path.
1070 Note that a sequence of commands @emph{must} begin with a
1071 @code{moveto} or @code{rmoveto} to work with the SVG output.
1073 Line-cap styles and line-join styles may be customized by
1074 overriding the @code{line-cap-style} and @code{line-join-style}
1075 properties, respectively. Available line-cap styles are
1076 @code{'butt}, @code{'round}, and @code{'square}. Available
1077 line-join styles are @code{'miter}, @code{'round}, and
1080 The property @code{filled} specifies whether or not the path is
1083 @lilypond[verbatim,quote]
1089 (curveto -5 -5 -5 5 -1 0)
1093 \\path #0.25 #samplePath
1095 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
1097 \\override #'(filled . #t) \\path #0.25 #samplePath
1100 (let* ((half-thickness (/ thickness 2))
1101 (current-point '(0 . 0))
1102 (set-point (lambda (lst) (set! current-point lst)))
1103 (relative? (lambda (x)
1104 (string-prefix? "r" (symbol->string (car x)))))
1105 ;; For calculating extents, we want to modify the command
1106 ;; list so that all coordinates are absolute.
1107 (new-commands (map (lambda (x)
1109 ;; for rmoveto, rlineto
1110 ((and (relative? x) (= 3 (length x)))
1112 (+ (car current-point)
1114 (+ (cdr current-point)
1120 ((and (relative? x) (= 7 (length x)))
1121 (let* ((old-cp current-point)
1128 (list (+ (car old-cp) (second x))
1129 (+ (cdr old-cp) (third x))
1130 (+ (car old-cp) (fourth x))
1131 (+ (cdr old-cp) (fifth x))
1134 ;; for moveto, lineto
1136 (set-point (cons (second x)
1141 (set-point (cons (sixth x)
1144 ;; keep closepath for filtering;
1145 ;; see `without-closepath'.
1148 ;; path-min-max does not accept 0-arg lists,
1149 ;; and since closepath does not affect extents, filter
1150 ;; out those commands here.
1151 (without-closepath (filter (lambda (x)
1152 (not (equal? 'closepath (car x))))
1154 (extents (path-min-max
1155 ;; set the origin to the first moveto
1156 (list (list-ref (car without-closepath) 0)
1157 (list-ref (car without-closepath) 1))
1159 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1160 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1161 (command-list (fold-right append '() commands)))
1163 ;; account for line thickness
1164 (set! X-extent (interval-widen X-extent half-thickness))
1165 (set! Y-extent (interval-widen Y-extent half-thickness))
1168 `(path ,thickness `(,@',command-list)
1169 ',line-cap-style ',line-join-style ,filled)
1173 (define-markup-list-command (score-lines layout props score)
1175 "This is the same as the @code{\\score} markup but delivers its
1176 systems as a list of lines. Its @var{score} argument is entered in
1177 braces like it would be for @code{\\score}."
1178 (let ((output (ly:score-embedded-format score layout)))
1180 (if (ly:music-output? output)
1182 (lambda (paper-system)
1183 ;; shift such that the refpoint of the bottom staff of
1184 ;; the first system is the baseline of the score
1185 (ly:stencil-translate-axis
1186 (paper-system-stencil paper-system)
1187 (- (car (paper-system-staff-extents paper-system)))
1189 (vector->list (ly:paper-score-paper-systems output)))
1191 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1194 (define-markup-command (score layout props score)
1197 #:properties ((baseline-skip))
1199 @cindex inserting music into text
1201 Inline an image of music. The reference point (usually the middle
1202 staff line) of the lowest staff in the top system is placed on the
1205 @lilypond[verbatim,quote]
1209 \\new Staff \\relative c' {
1212 \\mark \\markup { Allegro }
1218 \\new Staff \\relative c {
1224 f,( bes d bes d bes)
1232 \\override RehearsalMark
1233 #'break-align-symbols = #'(time-signature key-signature)
1234 \\override RehearsalMark
1235 #'self-alignment-X = #LEFT
1239 \\override TimeSignature
1240 #'break-align-anchor-alignment = #LEFT
1246 (stack-stencils Y DOWN baseline-skip
1247 (score-lines-markup-list layout props score)))
1249 (define-markup-command (null layout props)
1253 @cindex creating empty text objects
1255 An empty markup with extents of a single point.
1257 @lilypond[verbatim,quote]
1264 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1265 ;; basic formatting.
1266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1268 (define-markup-command (simple layout props str)
1272 @cindex simple text strings
1274 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1275 @code{\\markup @{ \\simple #\"foo\" @}}.
1277 Note: for creating standard text markup or defining new markup commands,
1278 the use of @code{\\simple} is unnecessary.
1280 @lilypond[verbatim,quote]
1282 \\simple #\"simple\"
1284 \\simple #\"strings\"
1287 (interpret-markup layout props str))
1289 (define-markup-command (first-visible layout props args)
1292 "Use the first markup in @var{args} that yields a non-empty stencil
1293 and ignore the rest.
1295 @lilypond[verbatim,quote]
1298 \\fromproperty #'header:composer
1303 (define (false-if-empty stencil)
1304 (if (ly:stencil-empty? stencil) #f stencil))
1309 (false-if-empty (interpret-markup layout props m))
1310 (any false-if-empty (interpret-markup-list layout props (list m)))))
1314 (define-public empty-markup
1315 (make-simple-markup ""))
1317 ;; helper for justifying lines.
1318 (define (get-fill-space
1319 word-count line-width word-space text-widths constant-space?)
1320 "Calculate the necessary paddings between adjacent texts in a
1321 single justified line. The lengths of all texts are stored in
1323 When @var{constant-space?} is @code{#t}, the formula for the padding
1325 padding = (line-width - total-text-width)/(word-count - 1)
1326 When @var{constant-space?} is @code{#f}, the formula for the
1327 padding between interior texts a and b is:
1328 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1329 In this case, the first and last padding have to be calculated
1330 specially using the whole length of the first or last text.
1331 All paddings are checked to be at least word-space, to ensure that
1333 Return a list of paddings."
1335 ((null? text-widths) '())
1339 ;; Ensure that space between words cannot be
1340 ;; less than word-space.
1343 (/ (- line-width (apply + text-widths))
1346 ;; special case first padding
1347 ((= (length text-widths) word-count)
1349 (- (- (/ line-width (1- word-count)) (car text-widths))
1350 (/ (cadr text-widths) 2))
1352 word-count line-width word-space (cdr text-widths)
1354 ;; special case last padding
1355 ((= (length text-widths) 2)
1356 (list (- (/ line-width (1- word-count))
1357 (+ (/ (car text-widths) 2) (cadr text-widths)))
1360 (let ((default-padding
1361 (- (/ line-width (1- word-count))
1362 (/ (+ (car text-widths) (cadr text-widths)) 2))))
1364 (if (> word-space default-padding)
1368 word-count line-width word-space (cdr text-widths)
1369 constant-space?))))))
1371 (define (justify-line-helper
1372 layout props args text-direction word-space line-width constant-space?)
1373 "Return a stencil which spreads @var{args} along a line of width
1374 @var{line-width}. If @var{constant-space?} is set to @code{#t}, the
1375 space between words is constant. If @code{#f}, the distance between
1376 words varies according to their relative lengths."
1377 (let* ((orig-stencils (interpret-markup-list layout props args))
1380 (if (ly:stencil-empty? stc X)
1381 (ly:make-stencil (ly:stencil-expr stc)
1382 '(0 . 0) (ly:stencil-extent stc Y))
1387 (interval-length (ly:stencil-extent stc X)))
1389 (text-width (apply + text-widths))
1390 (word-count (length stencils))
1391 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1396 (/ (- line-width text-width) 2)
1397 (/ (- line-width text-width) 2)))
1400 (- line-width text-width)))
1403 word-count line-width word-space text-widths
1405 (line-contents (if (= word-count 1)
1412 (if (null? (remove ly:stencil-empty? orig-stencils))
1415 (if (= text-direction LEFT)
1416 (set! line-contents (reverse line-contents)))
1418 (stack-stencils-padding-list
1419 X RIGHT fill-space line-contents))
1420 (if (> word-count 1)
1421 ;; shift s.t. stencils align on the left edge, even if
1422 ;; first stencil had negative X-extent (e.g. center-column)
1423 ;; (if word-count = 1, X-extents are already normalized in
1424 ;; the definition of line-contents)
1426 (ly:stencil-translate-axis
1428 (- (car (ly:stencil-extent (car stencils) X)))
1432 (define-markup-command (fill-line layout props args)
1435 #:properties ((text-direction RIGHT)
1438 "Put @var{markups} in a horizontal line of width @var{line-width}.
1439 The markups are spaced or flushed to fill the entire line.
1440 If there are no arguments, return an empty stencil.
1442 @lilypond[verbatim,quote]
1446 Words evenly spaced across the page
1450 \\line { Text markups }
1452 \\italic { evenly spaced }
1454 \\line { across the page }
1459 (justify-line-helper
1460 layout props args text-direction word-space line-width #f))
1462 (define-markup-command (justify-line layout props args)
1465 #:properties ((text-direction RIGHT)
1468 "Put @var{markups} in a horizontal line of width @var{line-width}.
1469 The markups are spread to fill the entire line and separated by equal
1470 space. If there are no arguments, return an empty stencil.
1472 @lilypond[verbatim,quote]
1475 Space between neighboring words is constant
1479 (justify-line-helper
1480 layout props args text-direction word-space line-width #t))
1482 (define-markup-command (concat layout props args)
1486 @cindex concatenating text
1487 @cindex ligatures in text
1489 Concatenate @var{args} in a horizontal line, without spaces in between.
1490 Strings and simple markups are concatenated on the input level, allowing
1491 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1492 equivalent to @code{\"fi\"}.
1494 @lilypond[verbatim,quote]
1503 (define (concat-string-args arg-list)
1504 (fold-right (lambda (arg result-list)
1505 (let ((result (and (pair? result-list)
1506 (car result-list))))
1507 (cond ((not (pair? arg)))
1508 ((eq? (car arg) simple-markup)
1509 (set! arg (cadr arg)))
1510 ((eq? (car arg) char-markup)
1511 (set! arg (ly:wide-char->utf-8 (cadr arg)))))
1512 (if (and (string? result) (string? arg))
1513 (cons (string-append arg result) (cdr result-list))
1514 (cons arg result-list))))
1518 (interpret-markup layout
1519 (prepend-alist-chain 'word-space 0 props)
1521 (make-override-lines-markup-list
1523 (chain-assoc-get 'word-space props))
1524 (if (markup-command-list? args)
1526 (concat-string-args args))))))
1528 (define (wordwrap-stencils stencils
1529 justify base-space line-width text-dir)
1530 "Perform simple wordwrap, return stencil of each line."
1531 (define space (if justify
1532 ;; justify only stretches lines.
1535 (define (stencil-len s)
1536 (interval-end (ly:stencil-extent s X)))
1537 (define (maybe-shift line)
1538 (if (= text-dir LEFT)
1539 (ly:stencil-translate-axis
1541 (- line-width (stencil-len line))
1544 (if (null? stencils)
1546 (let loop ((lines '())
1549 ((line (first todo))
1551 (word-list (list (first todo))))
1554 (let ((new (if (= text-dir LEFT)
1555 (ly:stencil-stack (car todo) X RIGHT line space)
1556 (ly:stencil-stack line X RIGHT (car todo) space))))
1558 ((<= (stencil-len new) line-width)
1559 (word-loop new (cdr todo)
1560 (cons (car todo) word-list)))
1563 ;; This depends on stencil stacking being
1564 ;; associative so that stacking
1565 ;; left-to-right and right-to-left leads to
1567 (if (= text-dir LEFT)
1569 (reverse! word-list)))
1570 (len (stencil-len line))
1571 (stretch (- line-width len))
1574 (stack-stencils X RIGHT (1+ space) word-list))
1577 ;; Uh oh, nothing to fill.
1578 (loop (cons (maybe-shift line) lines) todo)
1580 (stack-stencils X RIGHT
1581 (+ space (/ stretch spaces))
1585 (else ;; not justify
1586 (loop (cons (maybe-shift line) lines) todo)))))
1589 ;; Now we have the last line assembled with space
1590 ;; which is compressed. We want to use the
1591 ;; uncompressed version instead if it fits, and the
1592 ;; justified version if it doesn't.
1594 ;; This depends on stencil stacking being
1595 ;; associative so that stacking
1596 ;; left-to-right and right-to-left leads to
1598 (if (= text-dir LEFT)
1600 (reverse! word-list)))
1601 (big-line (stack-stencils X RIGHT base-space word-list))
1602 (big-len (stencil-len big-line))
1603 (len (stencil-len line)))
1606 (if (> big-len line-width)
1607 (stack-stencils X RIGHT
1610 (* (- big-len line-width)
1612 (* (- line-width len)
1616 (maybe-shift big-line))))))
1617 (else ;; not justify
1618 (reverse! lines (list (maybe-shift line)))))))))
1621 (define-markup-list-command (wordwrap-internal layout props justify args)
1622 (boolean? markup-list?)
1623 #:properties ((line-width #f)
1625 (text-direction RIGHT))
1626 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1627 (wordwrap-stencils (interpret-markup-list layout props args)
1631 (ly:output-def-lookup layout 'line-width))
1634 (define-markup-command (justify layout props args)
1637 #:properties ((baseline-skip)
1638 wordwrap-internal-markup-list)
1640 @cindex justifying text
1642 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1643 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1644 @var{X}@tie{}is the number of staff spaces.
1646 @lilypond[verbatim,quote]
1649 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1650 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1651 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1652 laboris nisi ut aliquip ex ea commodo consequat.
1656 (stack-lines DOWN 0.0 baseline-skip
1657 (wordwrap-internal-markup-list layout props #t args)))
1659 (define-markup-command (wordwrap layout props args)
1662 #:properties ((baseline-skip)
1663 wordwrap-internal-markup-list)
1664 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1665 the line width, where @var{X} is the number of staff spaces.
1667 @lilypond[verbatim,quote]
1670 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1671 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1672 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1673 laboris nisi ut aliquip ex ea commodo consequat.
1677 (stack-lines DOWN 0.0 baseline-skip
1678 (wordwrap-internal-markup-list layout props #f args)))
1680 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1682 #:properties ((line-width)
1684 (text-direction RIGHT))
1685 "Internal markup list command used to define @code{\\justify-string} and
1686 @code{\\wordwrap-string}."
1687 (let* ((para-strings (regexp-split
1688 (string-regexp-substitute
1690 (string-regexp-substitute "\r\n" "\n" arg))
1691 "\n[ \t\n]*\n[ \t\n]*"))
1692 (list-para-words (map (lambda (str)
1693 (regexp-split str "[ \t\n]+"))
1695 (para-lines (map (lambda (words)
1698 (interpret-markup layout props x))
1700 (wordwrap-stencils stencils
1702 line-width text-direction)))
1704 (concatenate para-lines)))
1706 (define-markup-command (wordwrap-string layout props arg)
1709 #:properties ((baseline-skip)
1710 wordwrap-string-internal-markup-list)
1711 "Wordwrap a string. Paragraphs may be separated with double newlines.
1713 @lilypond[verbatim,quote]
1715 \\override #'(line-width . 40)
1716 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1717 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1718 et dolore magna aliqua.
1721 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1722 laboris nisi ut aliquip ex ea commodo consequat.
1725 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1726 qui officia deserunt mollit anim id est laborum\"
1729 (stack-lines DOWN 0.0 baseline-skip
1730 (wordwrap-string-internal-markup-list layout props #f arg)))
1732 (define-markup-command (justify-string layout props arg)
1735 #:properties ((baseline-skip)
1736 wordwrap-string-internal-markup-list)
1737 "Justify a string. Paragraphs may be separated with double newlines
1739 @lilypond[verbatim,quote]
1741 \\override #'(line-width . 40)
1742 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1743 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1744 et dolore magna aliqua.
1747 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1748 laboris nisi ut aliquip ex ea commodo consequat.
1751 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1752 qui officia deserunt mollit anim id est laborum\"
1755 (stack-lines DOWN 0.0 baseline-skip
1756 (wordwrap-string-internal-markup-list layout props #t arg)))
1758 (define-markup-command (wordwrap-field layout props symbol)
1761 "Wordwrap the data which has been assigned to @var{symbol}.
1763 @lilypond[verbatim,quote]
1765 title = \"My title\"
1766 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1767 elit, sed do eiusmod tempor incididunt ut labore et dolore
1768 magna aliqua. Ut enim ad minim veniam, quis nostrud
1769 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1774 bookTitleMarkup = \\markup {
1776 \\fill-line { \\fromproperty #'header:title }
1778 \\wordwrap-field #'header:myText
1787 (let* ((m (chain-assoc-get symbol props)))
1789 (wordwrap-string-markup layout props m)
1792 (define-markup-command (justify-field layout props symbol)
1795 "Justify the data which has been assigned to @var{symbol}.
1797 @lilypond[verbatim,quote]
1799 title = \"My title\"
1800 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1801 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1802 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1803 laboris nisi ut aliquip ex ea commodo consequat.\"
1807 bookTitleMarkup = \\markup {
1809 \\fill-line { \\fromproperty #'header:title }
1811 \\justify-field #'header:myText
1820 (let* ((m (chain-assoc-get symbol props)))
1822 (justify-string-markup layout props m)
1825 (define-markup-command (combine layout props arg1 arg2)
1829 @cindex merging text
1831 Print two markups on top of each other.
1833 Note: @code{\\combine} cannot take a list of markups enclosed in
1834 curly braces as an argument; for this purpose use @code{\\overlay} instead.
1836 @lilypond[verbatim,quote]
1839 \\override #'(thickness . 2)
1841 \\draw-line #'(0 . 4)
1842 \\arrow-head #Y #DOWN ##f
1845 (let* ((s1 (interpret-markup layout props arg1))
1846 (s2 (interpret-markup layout props arg2)))
1847 (ly:stencil-add s1 s2)))
1849 (define-markup-command (overlay layout props args)
1853 @cindex merging text
1855 Takes a list of markups combining them.
1857 @lilypond[verbatim,quote]
1860 \\override #'(thickness . 2)
1862 \\draw-line #'(0 . 4)
1863 \\arrow-head #Y #DOWN ##f
1864 \\translate #'(0 . 4)\\arrow-head #Y #UP ##f
1868 (apply ly:stencil-add (interpret-markup-list layout props args)))
1871 ;; TODO: should extract baseline-skip from each argument somehow..
1873 (define-markup-command (column layout props args)
1876 #:properties ((baseline-skip))
1878 @cindex stacking text in a column
1880 Stack the markups in @var{args} vertically. The property
1881 @code{baseline-skip} determines the space between markups
1884 @lilypond[verbatim,quote]
1893 (let ((arg-stencils (interpret-markup-list layout props args)))
1894 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1896 (define-markup-command (dir-column layout props args)
1899 #:properties ((direction)
1902 @cindex changing direction of text columns
1904 Make a column of @var{args}, going up or down, depending on the
1905 setting of the @code{direction} layout property.
1907 @lilypond[verbatim,quote]
1909 \\override #`(direction . ,UP) {
1919 \\override #'(direction . 1) {
1926 (stack-lines (if (number? direction) direction -1)
1929 (interpret-markup-list layout props args)))
1931 (define (general-column align-dir baseline mols)
1932 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1934 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1935 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1936 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1937 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1939 (define-markup-command (center-column layout props args)
1942 #:properties ((baseline-skip))
1944 @cindex centering a column of text
1946 Put @code{args} in a centered column.
1948 @lilypond[verbatim,quote]
1957 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1959 (define-markup-command (left-column layout props args)
1962 #:properties ((baseline-skip))
1964 @cindex text columns, left-aligned
1966 Put @code{args} in a left-aligned column.
1968 @lilypond[verbatim,quote]
1977 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1979 (define-markup-command (right-column layout props args)
1982 #:properties ((baseline-skip))
1984 @cindex text columns, right-aligned
1986 Put @code{args} in a right-aligned column.
1988 @lilypond[verbatim,quote]
1997 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1999 (define-markup-command (vcenter layout props arg)
2003 @cindex vertically centering text
2005 Align @code{arg} to its Y@tie{}center.
2007 @lilypond[verbatim,quote]
2015 (let* ((mol (interpret-markup layout props arg)))
2016 (ly:stencil-aligned-to mol Y CENTER)))
2018 (define-markup-command (center-align layout props arg)
2022 @cindex horizontally centering text
2024 Align @code{arg} to its X@tie{}center.
2026 @lilypond[verbatim,quote]
2036 (let* ((mol (interpret-markup layout props arg)))
2037 (ly:stencil-aligned-to mol X CENTER)))
2039 (define-markup-command (right-align layout props arg)
2043 @cindex right aligning text
2045 Align @var{arg} on its right edge.
2047 @lilypond[verbatim,quote]
2057 (let* ((m (interpret-markup layout props arg)))
2058 (ly:stencil-aligned-to m X RIGHT)))
2060 (define-markup-command (left-align layout props arg)
2064 @cindex left aligning text
2066 Align @var{arg} on its left edge.
2068 @lilypond[verbatim,quote]
2078 (let* ((m (interpret-markup layout props arg)))
2079 (ly:stencil-aligned-to m X LEFT)))
2081 (define-markup-command (general-align layout props axis dir arg)
2082 (integer? number? markup?)
2085 @cindex controlling general text alignment
2087 Align @var{arg} in @var{axis} direction to the @var{dir} side.
2089 @lilypond[verbatim,quote]
2093 \\general-align #X #LEFT
2098 \\general-align #X #CENTER
2104 \\general-align #Y #UP
2111 \\general-align #Y #3.2
2118 (let* ((m (interpret-markup layout props arg)))
2119 (ly:stencil-aligned-to m axis dir)))
2121 (define-markup-command (halign layout props dir arg)
2125 @cindex setting horizontal text alignment
2127 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2128 left-aligned, while @code{+1} is right. Values in between interpolate
2129 alignment accordingly.
2131 @lilypond[verbatim,quote]
2156 (let* ((m (interpret-markup layout props arg)))
2157 (ly:stencil-aligned-to m X dir)))
2159 (define-markup-command (with-dimensions layout props x y arg)
2160 (number-pair? number-pair? markup?)
2163 @cindex setting extent of text objects
2165 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2166 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2168 (make-transparent-box-stencil x y)
2170 `(delay-stencil-evaluation ,(delay expr))
2173 (define-markup-command (pad-around layout props amount arg)
2176 "Add padding @var{amount} all around @var{arg}.
2178 @lilypond[verbatim,quote]
2191 (let* ((m (interpret-markup layout props arg))
2192 (x (interval-widen (ly:stencil-extent m X) amount))
2193 (y (interval-widen (ly:stencil-extent m Y) amount)))
2194 (ly:stencil-add (make-transparent-box-stencil x y)
2197 (define-markup-command (pad-x layout props amount arg)
2201 @cindex padding text horizontally
2203 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2205 @lilypond[verbatim,quote]
2218 (let* ((m (interpret-markup layout props arg))
2219 (x (ly:stencil-extent m X))
2220 (y (ly:stencil-extent m Y)))
2221 (ly:make-stencil (ly:stencil-expr m)
2222 (interval-widen x amount)
2225 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2226 (integer? ly:dir? markup? markup?)
2228 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2229 (let ((m1 (interpret-markup layout props arg1))
2230 (m2 (interpret-markup layout props arg2)))
2231 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2233 (define-markup-command (transparent layout props arg)
2236 "Make @var{arg} transparent.
2238 @lilypond[verbatim,quote]
2245 (let* ((m (interpret-markup layout props arg))
2246 (x (ly:stencil-extent m X))
2247 (y (ly:stencil-extent m Y)))
2248 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2250 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2251 (number-pair? number-pair? markup?)
2253 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2255 @lilypond[verbatim,quote]
2262 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2268 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2269 (interpret-markup layout props arg)))
2271 (define-markup-command (hcenter-in layout props length arg)
2274 "Center @var{arg} horizontally within a box of extending
2275 @var{length}/2 to the left and right.
2277 @lilypond[quote,verbatim]
2280 \\set Staff.instrumentName = \\markup {
2287 \\set Staff.instrumentName = \\markup {
2296 (interpret-markup layout props
2297 (make-pad-to-box-markup
2298 (cons (/ length -2) (/ length 2))
2300 (make-center-align-markup arg))))
2302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2306 (define-markup-command (property-recursive layout props symbol)
2309 "Print out a warning when a header field markup contains some recursive
2311 (ly:warning "Recursive definition of property ~a detected!" symbol)
2314 (define-markup-command (fromproperty layout props symbol)
2317 "Read the @var{symbol} from property settings, and produce a stencil
2318 from the markup contained within. If @var{symbol} is not defined, it
2319 returns an empty markup.
2321 @lilypond[verbatim,quote]
2323 myTitle = \"myTitle\"
2327 \\fromproperty #'header:myTitle
2334 (let ((m (chain-assoc-get symbol props)))
2336 ;; prevent infinite loops by clearing the interpreted property:
2337 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2340 (define-markup-command (on-the-fly layout props procedure arg)
2341 (procedure? markup?)
2343 "Apply the @var{procedure} markup command to @var{arg}.
2344 @var{procedure} takes the same arguments as @code{interpret-markup}
2345 and returns a stencil."
2346 (procedure layout props arg))
2348 (define-markup-command (footnote layout props mkup note)
2351 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2353 @lilypond[verbatim,quote]
2356 \\override #'(padding . 0.2)
2360 The footnote will not be annotated automatically."
2361 (ly:stencil-combine-at-edge
2362 (interpret-markup layout props mkup)
2366 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2371 (define-markup-command (auto-footnote layout props mkup note)
2374 #:properties ((raise 0.5)
2376 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2378 @lilypond[verbatim,quote]
2381 \\override #'(padding . 0.2)
2385 The footnote will be annotated automatically."
2386 (let* ((markup-stencil (interpret-markup layout props mkup))
2387 (footnote-hash (gensym "footnote"))
2389 (gauge-stencil (interpret-markup
2392 ((ly:output-def-lookup
2394 'footnote-numbering-function)
2396 (x-ext (ly:stencil-extent gauge-stencil X))
2397 (y-ext (ly:stencil-extent gauge-stencil Y))
2399 `(delay-stencil-evaluation
2403 (ly:output-def-lookup layout
2404 'number-footnote-table))
2405 (footnote-stencil (if (list? table)
2406 (assoc-get footnote-hash
2409 (footnote-stencil (if (ly:stencil? footnote-stencil)
2412 (ly:programming-error
2413 "Cannot find correct footnote for a markup object.")
2415 (gap (- (interval-length x-ext)
2417 (ly:stencil-extent footnote-stencil X))))
2418 (y-trans (- (+ (cdr y-ext)
2420 (cdr (ly:stencil-extent footnote-stencil
2422 (ly:stencil-translate footnote-stencil
2423 (cons gap y-trans)))))))
2424 (main-stencil (ly:stencil-combine-at-edge
2428 (ly:make-stencil footnote-number x-ext y-ext)
2433 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2437 (define-markup-command (override layout props new-prop arg)
2441 @cindex overriding properties within text markup
2443 Add the argument @var{new-prop} to the property list. Properties
2444 may be any property supported by @rinternals{font-interface},
2445 @rinternals{text-interface} and
2446 @rinternals{instrument-specific-markup-interface}.
2448 @lilypond[verbatim,quote]
2456 \\override #'(baseline-skip . 4) {
2465 (interpret-markup layout (cons (list new-prop) props) arg))
2467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2469 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2471 (define-markup-command (verbatim-file layout props name)
2474 "Read the contents of file @var{name}, and include it verbatim.
2476 @lilypond[verbatim,quote]
2478 \\verbatim-file #\"simple.ly\"
2481 (interpret-markup layout props
2482 (if (ly:get-option 'safe)
2483 "verbatim-file disabled in safe mode"
2484 (let* ((str (ly:gulp-file name))
2485 (lines (string-split str #\nl)))
2486 (make-typewriter-markup
2487 (make-column-markup lines))))))
2489 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2491 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2494 (define-markup-command (smaller layout props arg)
2497 "Decrease the font size relative to the current setting.
2499 @lilypond[verbatim,quote]
2512 (interpret-markup layout props
2513 `(,fontsize-markup -1 ,arg)))
2515 (define-markup-command (larger layout props arg)
2518 "Increase the font size relative to the current setting.
2520 @lilypond[verbatim,quote]
2528 (interpret-markup layout props
2529 `(,fontsize-markup 1 ,arg)))
2531 (define-markup-command (finger layout props arg)
2534 "Set @var{arg} as small numbers.
2536 @lilypond[verbatim,quote]
2543 (interpret-markup layout
2544 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2547 (define-markup-command (abs-fontsize layout props size arg)
2550 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2551 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2553 @lilypond[verbatim,quote]
2555 default text font size
2557 \\abs-fontsize #16 { text font size 16 }
2559 \\abs-fontsize #12 { text font size 12 }
2562 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2563 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2564 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2565 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2566 (magnification (/ size ref-size)))
2570 `((baseline-skip . ,(* magnification ref-baseline))
2571 (word-space . ,(* magnification ref-word-space))
2572 (font-size . ,(magnification->font-size magnification)))
2576 (define-markup-command (fontsize layout props increment arg)
2579 #:properties ((font-size 0)
2582 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2585 @lilypond[verbatim,quote]
2596 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2597 (word-space . ,(* word-space (magstep increment)))
2598 (font-size . ,(+ font-size increment)))
2602 (define-markup-command (magnify layout props sz arg)
2606 @cindex magnifying text
2608 Set the font magnification for its argument. In the following
2609 example, the middle@tie{}A is 10% larger:
2612 A \\magnify #1.1 @{ A @} A
2615 Note: Magnification only works if a font name is explicitly selected.
2616 Use @code{\\fontsize} otherwise.
2618 @lilypond[verbatim,quote]
2629 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2632 (define-markup-command (bold layout props arg)
2635 "Switch to bold font-series.
2637 @lilypond[verbatim,quote]
2645 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2647 (define-markup-command (sans layout props arg)
2650 "Switch to the sans serif font family.
2652 @lilypond[verbatim,quote]
2661 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2663 (define-markup-command (number layout props arg)
2666 "Set font family to @code{number}, which yields the font used for
2667 time signatures and fingerings. This font contains numbers and
2668 some punctuation; it has no letters.
2670 @lilypond[verbatim,quote]
2673 0 1 2 3 4 5 6 7 8 9 . ,
2677 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2679 (define-markup-command (roman layout props arg)
2682 "Set font family to @code{roman}.
2684 @lilypond[verbatim,quote]
2690 text in roman font family
2697 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2699 (define-markup-command (huge layout props arg)
2702 "Set font size to +2.
2704 @lilypond[verbatim,quote]
2712 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2714 (define-markup-command (large layout props arg)
2717 "Set font size to +1.
2719 @lilypond[verbatim,quote]
2727 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2729 (define-markup-command (normalsize layout props arg)
2732 "Set font size to default.
2734 @lilypond[verbatim,quote]
2747 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2749 (define-markup-command (small layout props arg)
2752 "Set font size to -1.
2754 @lilypond[verbatim,quote]
2762 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2764 (define-markup-command (tiny layout props arg)
2767 "Set font size to -2.
2769 @lilypond[verbatim,quote]
2777 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2779 (define-markup-command (teeny layout props arg)
2782 "Set font size to -3.
2784 @lilypond[verbatim,quote]
2792 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2794 (define-markup-command (fontCaps layout props arg)
2797 "Set @code{font-shape} to @code{caps}
2799 Note: @code{\\fontCaps} requires the installation and selection of
2800 fonts which support the @code{caps} font shape."
2801 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2804 (define-markup-command (smallCaps layout props arg)
2807 "Emit @var{arg} as small caps.
2809 Note: @code{\\smallCaps} does not support accented characters.
2811 @lilypond[verbatim,quote]
2820 (define (char-list->markup chars lower)
2821 (let ((final-string (string-upcase (reverse-list->string chars))))
2823 (markup #:fontsize -2 final-string)
2825 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2826 (if (null? rest-chars)
2828 (reverse! (cons (char-list->markup currents current-is-lower)
2830 (let* ((ch (car rest-chars))
2831 (is-lower (char-lower-case? ch)))
2832 (if (or (and current-is-lower is-lower)
2833 (and (not current-is-lower) (not is-lower)))
2834 (make-small-caps (cdr rest-chars)
2838 (make-small-caps (cdr rest-chars)
2841 (if (null? currents)
2843 (cons (char-list->markup
2844 currents current-is-lower)
2846 (interpret-markup layout props
2848 (make-small-caps (string->list arg) (list) #f (list))
2851 (define-markup-command (caps layout props arg)
2854 "Copy of the @code{\\smallCaps} command.
2856 @lilypond[verbatim,quote]
2865 (interpret-markup layout props (make-smallCaps-markup arg)))
2867 (define-markup-command (dynamic layout props arg)
2870 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2871 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2872 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2873 done in a different font. The recommended font for this is bold and italic.
2874 @lilypond[verbatim,quote]
2882 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2884 (define-markup-command (text layout props arg)
2887 "Use a text font instead of music symbol or music alphabet font.
2889 @lilypond[verbatim,quote]
2902 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2905 (define-markup-command (italic layout props arg)
2908 "Use italic @code{font-shape} for @var{arg}.
2910 @lilypond[verbatim,quote]
2918 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2920 (define-markup-command (typewriter layout props arg)
2923 "Use @code{font-family} typewriter for @var{arg}.
2925 @lilypond[verbatim,quote]
2934 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2936 (define-markup-command (upright layout props arg)
2939 "Set @code{font-shape} to @code{upright}. This is the opposite
2942 @lilypond[verbatim,quote]
2956 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2958 (define-markup-command (medium layout props arg)
2961 "Switch to medium font-series (in contrast to bold).
2963 @lilypond[verbatim,quote]
2976 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2979 (define-markup-command (normal-text layout props arg)
2982 "Set all font related properties (except the size) to get the default
2983 normal text font, no matter what font was used earlier.
2985 @lilypond[verbatim,quote]
2987 \\huge \\bold \\sans \\caps {
2999 (interpret-markup layout
3000 (cons '((font-family . roman) (font-shape . upright)
3001 (font-series . medium) (font-encoding . latin1))
3005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3009 (define-markup-command (musicglyph layout props glyph-name)
3012 "@var{glyph-name} is converted to a musical symbol; for example,
3013 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
3014 the music font. See @ruser{The Feta font} for a complete listing of
3015 the possible glyphs.
3017 @lilypond[verbatim,quote]
3020 \\musicglyph #\"rests.2\"
3021 \\musicglyph #\"clefs.G_change\"
3024 (let* ((font (ly:paper-get-font layout
3025 (cons '((font-encoding . fetaMusic)
3029 (glyph (ly:font-get-glyph font glyph-name)))
3030 (if (null? (ly:stencil-expr glyph))
3031 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
3035 (define-markup-command (doublesharp layout props)
3038 "Draw a double sharp symbol.
3040 @lilypond[verbatim,quote]
3045 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
3047 (define-markup-command (sesquisharp layout props)
3050 "Draw a 3/2 sharp symbol.
3052 @lilypond[verbatim,quote]
3057 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
3059 (define-markup-command (sharp layout props)
3062 "Draw a sharp symbol.
3064 @lilypond[verbatim,quote]
3069 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
3071 (define-markup-command (semisharp layout props)
3074 "Draw a semisharp symbol.
3076 @lilypond[verbatim,quote]
3081 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
3083 (define-markup-command (natural layout props)
3086 "Draw a natural symbol.
3088 @lilypond[verbatim,quote]
3093 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
3095 (define-markup-command (semiflat layout props)
3098 "Draw a semiflat symbol.
3100 @lilypond[verbatim,quote]
3105 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
3107 (define-markup-command (flat layout props)
3110 "Draw a flat symbol.
3112 @lilypond[verbatim,quote]
3117 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
3119 (define-markup-command (sesquiflat layout props)
3122 "Draw a 3/2 flat symbol.
3124 @lilypond[verbatim,quote]
3129 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3131 (define-markup-command (doubleflat layout props)
3134 "Draw a double flat symbol.
3136 @lilypond[verbatim,quote]
3141 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3143 (define-markup-command (with-color layout props color arg)
3147 @cindex coloring text
3149 Draw @var{arg} in color specified by @var{color}.
3151 @lilypond[verbatim,quote]
3163 (let ((stil (interpret-markup layout props arg)))
3164 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3165 (ly:stencil-extent stil X)
3166 (ly:stencil-extent stil Y))))
3168 (define-markup-command (tied-lyric layout props str)
3171 #:properties ((word-space))
3173 @cindex simple text strings with tie characters
3175 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3177 @lilypond[verbatim,quote]
3179 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3180 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3181 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3184 (define (replace-ties tie str)
3185 (if (string-contains str "~")
3187 ((half-space (/ word-space 2))
3188 (parts (string-split str #\~))
3189 (tie-str (markup #:hspace half-space
3191 #:hspace half-space))
3192 (joined (list-join parts tie-str)))
3193 (make-concat-markup joined))
3196 (define short-tie-regexp (make-regexp "~[^.]~"))
3197 (define (match-short str) (regexp-exec short-tie-regexp str))
3199 (define (replace-short str mkp)
3200 (let ((match (match-short str)))
3202 (make-concat-markup (list
3204 (replace-ties "ties.lyric.default" str)))
3205 (let ((new-str (match:suffix match))
3206 (new-mkp (make-concat-markup (list
3208 (replace-ties "ties.lyric.default"
3209 (match:prefix match))
3210 (replace-ties "ties.lyric.short"
3211 (match:substring match))))))
3212 (replace-short new-str new-mkp)))))
3214 (interpret-markup layout
3216 (replace-short str (markup))))
3218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3222 (define-markup-command (arrow-head layout props axis dir filled)
3223 (integer? ly:dir? boolean?)
3225 "Produce an arrow head in specified direction and axis.
3226 Use the filled head if @var{filled} is specified.
3227 @lilypond[verbatim,quote]
3230 \\general-align #Y #DOWN {
3231 \\arrow-head #Y #UP ##t
3232 \\arrow-head #Y #DOWN ##f
3234 \\arrow-head #X #RIGHT ##f
3235 \\arrow-head #X #LEFT ##f
3241 ((name (format #f "arrowheads.~a.~a~a"
3248 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3252 (define-markup-command (lookup layout props glyph-name)
3255 "Lookup a glyph by name.
3257 @lilypond[verbatim,quote]
3259 \\override #'(font-encoding . fetaBraces) {
3260 \\lookup #\"brace200\"
3263 \\lookup #\"brace180\"
3267 (ly:font-get-glyph (ly:paper-get-font layout props)
3270 (define-markup-command (char layout props num)
3273 "Produce a single character. Characters encoded in hexadecimal
3274 format require the prefix @code{#x}.
3276 @lilypond[verbatim,quote]
3278 \\char #65 \\char ##x00a9
3281 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3283 (define number->mark-letter-vector (make-vector 25 #\A))
3288 (if (= i (- (char->integer #\I) (char->integer #\A)))
3290 (vector-set! number->mark-letter-vector j
3291 (integer->char (+ i (char->integer #\A)))))
3293 (define number->mark-alphabet-vector (list->vector
3294 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3296 (define (number->markletter-string vec n)
3297 "Double letters for big marks."
3298 (let* ((lst (vector-length vec)))
3301 (string-append (number->markletter-string vec (1- (quotient n lst)))
3302 (number->markletter-string vec (remainder n lst)))
3303 (make-string 1 (vector-ref vec n)))))
3305 (define-markup-command (markletter layout props num)
3308 "Make a markup letter for @var{num}. The letters start with A
3309 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3311 @lilypond[verbatim,quote]
3318 (ly:text-interface::interpret-markup layout props
3319 (number->markletter-string number->mark-letter-vector num)))
3321 (define-markup-command (markalphabet layout props num)
3324 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3325 and continue with double letters.
3327 @lilypond[verbatim,quote]
3334 (ly:text-interface::interpret-markup layout props
3335 (number->markletter-string number->mark-alphabet-vector num)))
3337 (define-public (horizontal-slash-interval num forward number-interval mag)
3339 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3340 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3341 (else (interval-widen number-interval (* mag 0.25))))
3342 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3343 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3344 (else (interval-widen number-interval (* mag 0.25))))
3347 (define-public (adjust-slash-stencil num forward stencil mag)
3350 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3352 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3354 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3356 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3359 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3361 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3366 (define (slashed-digit-internal layout props num forward font-size thickness)
3367 (let* ((mag (magstep font-size))
3369 (ly:output-def-lookup layout 'line-thickness)
3371 ;; backward slashes might use slope and point in the other direction!
3372 (dy (* mag (if forward 0.4 -0.4)))
3373 (number-stencil (interpret-markup layout
3374 (prepend-alist-chain 'font-encoding 'fetaText props)
3375 (number->string num)))
3376 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3377 (center (interval-center (ly:stencil-extent number-stencil Y)))
3378 ;; Use the real extents of the slash, not the whole number,
3379 ;; because we might translate the slash later on!
3380 (num-y (interval-widen (cons center center) (abs dy)))
3381 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3382 (slash-stencil (if is-sane
3383 (make-line-stencil thickness
3384 (car num-x) (- (interval-center num-y) dy)
3385 (cdr num-x) (+ (interval-center num-y) dy))
3387 (if (ly:stencil? slash-stencil)
3389 ;; for some numbers we need to shift the slash/backslash up or
3390 ;; down to make the slashed digit look better
3391 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3392 (set! number-stencil
3393 (ly:stencil-add number-stencil slash-stencil)))
3394 (ly:warning "Unable to create slashed digit ~a" num))
3398 (define-markup-command (slashed-digit layout props num)
3401 #:properties ((font-size 0)
3404 @cindex slashed digits
3406 A feta number, with slash. This is for use in the context of
3407 figured bass notation.
3408 @lilypond[verbatim,quote]
3412 \\override #'(thickness . 3)
3416 (slashed-digit-internal layout props num #t font-size thickness))
3418 (define-markup-command (backslashed-digit layout props num)
3421 #:properties ((font-size 0)
3424 @cindex backslashed digits
3426 A feta number, with backslash. This is for use in the context of
3427 figured bass notation.
3428 @lilypond[verbatim,quote]
3430 \\backslashed-digit #5
3432 \\override #'(thickness . 3)
3433 \\backslashed-digit #7
3436 (slashed-digit-internal layout props num #f font-size thickness))
3439 (define eyeglassespath
3440 '((moveto 0.42 0.77)
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)
3443 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3444 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3447 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3448 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3449 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3450 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3452 (moveto 1.025 0.935)
3453 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3454 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3457 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3460 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3462 (define-markup-command (eyeglasses layout props)
3465 "Prints out eyeglasses, indicating strongly to look at the conductor.
3466 @lilypond[verbatim,quote]
3467 \\markup { \\eyeglasses }
3469 (interpret-markup layout props
3470 (make-override-markup '(line-cap-style . butt)
3471 (make-path-markup 0.15 eyeglassespath))))
3473 (define-markup-command (left-brace layout props size)
3477 A feta brace in point size @var{size}.
3479 @lilypond[verbatim,quote]
3486 (let* ((font (ly:paper-get-font layout
3487 (cons '((font-encoding . fetaBraces)
3490 (glyph-count (1- (ly:otf-glyph-count font)))
3491 (scale (ly:output-def-lookup layout 'output-scale))
3492 (scaled-size (/ (ly:pt size) scale))
3494 (ly:font-get-glyph font (string-append "brace"
3495 (number->string n)))))
3496 (get-y-from-brace (lambda (brace)
3498 (ly:stencil-extent (glyph brace) Y))))
3499 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3500 (glyph-found (glyph find-brace)))
3502 (if (or (null? (ly:stencil-expr glyph-found))
3503 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3504 (> scaled-size (interval-length
3505 (ly:stencil-extent (glyph glyph-count) Y))))
3507 (ly:warning (_ "no brace found for point size ~S ") size)
3508 (ly:warning (_ "defaulting to ~S pt")
3509 (/ (* scale (interval-length
3510 (ly:stencil-extent glyph-found Y)))
3514 (define-markup-command (right-brace layout props size)
3518 A feta brace in point size @var{size}, rotated 180 degrees.
3520 @lilypond[verbatim,quote]
3527 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3530 ;; the note command.
3531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3533 ;; TODO: better syntax.
3535 (define-markup-command (note-by-number layout props log dot-count dir)
3536 (number? number? number?)
3538 #:properties ((font-size 0)
3542 @cindex notes within text by log and dot-count
3544 Construct a note symbol, with stem and flag. By using fractional values for
3545 @var{dir}, longer or shorter stems can be obtained.
3546 Supports all note-head-styles.
3547 Supported flag-styles are @code{default}, @code{old-straight-flag},
3548 @code{modern-straight-flag} and @code{flat-flag}.
3550 @lilypond[verbatim,quote]
3552 \\note-by-number #3 #0 #DOWN
3554 \\note-by-number #1 #2 #0.8
3557 (define (get-glyph-name-candidates dir log style)
3558 (map (lambda (dir-name)
3559 (format #f "noteheads.~a~a" dir-name
3560 (if (and (symbol? style)
3561 (not (equal? 'default style)))
3562 (select-head-glyph style (min log 2))
3564 (list (if (= dir UP) "u" "d")
3567 (define (get-glyph-name font cands)
3570 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3571 (get-glyph-name font (cdr cands))
3574 (define (buildflags flag-stencil remain curr-stencil spacing)
3575 ;; Function to recursively create a stencil with @code{remain} flags
3576 ;; from the single-flag stencil @code{curr-stencil}, which is already
3577 ;; translated to the position of the previous flag position.
3579 ;; Copy and paste from /scm/flag-styles.scm
3581 (let* ((translated-stencil
3582 (ly:stencil-translate-axis curr-stencil spacing Y))
3583 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3584 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3587 (define (straight-flag-mrkp flag-thickness flag-spacing
3588 upflag-angle upflag-length
3589 downflag-angle downflag-length
3591 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3592 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3593 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3594 ;; @var{downflag-length} are given in staff spaces.
3596 ;; All lengths are scaled according to the font size of the note.
3598 ;; From /scm/flag-styles.scm, modified to fit here.
3600 (let* ((stem-up (> dir 0))
3601 ;; scale with the note size
3602 (factor (magstep font-size))
3603 (stem-thickness (* factor 0.1))
3604 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3605 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3606 (raw-length (if stem-up upflag-length downflag-length))
3607 (angle (if stem-up upflag-angle downflag-angle))
3608 (flag-length (+ (* raw-length factor) half-stem-thickness))
3609 (flag-end (if (= angle 0)
3610 (cons flag-length (* half-stem-thickness dir))
3611 (polar->rectangular flag-length angle)))
3612 (thickness (* flag-thickness factor))
3613 (thickness-offset (cons 0 (* -1 thickness dir)))
3614 (spacing (* -1 flag-spacing factor dir))
3615 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3618 (offset-add flag-end thickness-offset)
3619 (offset-add start thickness-offset)))
3620 (stencil (ly:round-filled-polygon points half-stem-thickness))
3621 ;; Log for 1/8 is 3, so we need to subtract 3
3622 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3625 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)
3628 (size-factor (magstep font-size))
3629 (blot (ly:output-def-lookup layout 'blot-diameter))
3631 (let ((result (get-glyph-name font
3632 (get-glyph-name-candidates
3633 (sign dir) log style))))
3634 (if (string-null? result)
3635 ;; If no glyph name can be found, select default heads.
3636 ;; Though this usually means an unsupported style has been
3637 ;; chosen, it also prevents unrelated 'style settings from
3638 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3640 (get-glyph-name font
3641 (get-glyph-name-candidates
3642 (sign dir) log 'default))
3644 (head-glyph (ly:font-get-glyph font head-glyph-name))
3645 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3646 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3647 (stem-length (* size-factor (max 3 (- log 1))))
3648 ;; With ancient-flags we want a tighter stem
3649 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3650 (stemy (* dir stem-length))
3651 (attach-off (cons (interval-index
3652 (ly:stencil-extent head-glyph X)
3653 (* (sign dir) (car attach-indices)))
3654 ;; fixme, this is inconsistent between X & Y.
3657 (ly:stencil-extent head-glyph Y)
3658 (cdr attach-indices)))))
3659 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3661 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3662 (stem-glyph (and (> log 0)
3663 (ly:round-filled-box
3664 (ordered-cons (+ stem-X-corr (car attach-off))
3665 (+ stem-X-corr (car attach-off)
3666 (* (- (sign dir)) stem-thickness)))
3667 (cons (min stemy (cdr attach-off))
3668 (max stemy (cdr attach-off)))
3669 (/ stem-thickness 3))))
3670 (dot (ly:font-get-glyph font "dots.dot"))
3671 (dotwid (interval-length (ly:stencil-extent dot X)))
3672 (dots (and (> dot-count 0)
3673 (apply ly:stencil-add
3675 (ly:stencil-translate-axis
3676 dot (* 2 x dotwid) X))
3677 (iota dot-count)))))
3678 ;; Straight-flags. Values taken from /scm/flag-style.scm
3679 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3680 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3681 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3682 ;; Calculate a corrective to avoid a gap between
3683 ;; straight-flags and the stem.
3684 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3685 (eq? flag-style 'old-straight-flag)
3686 (eq? flag-style 'flat-flag))
3687 (/ blot 10 (* -1 dir))
3689 (flaggl (and (> log 2)
3690 (ly:stencil-translate
3691 (cond ((eq? flag-style 'modern-straight-flag)
3692 modern-straight-flag)
3693 ((eq? flag-style 'old-straight-flag)
3695 ((eq? flag-style 'flat-flag)
3698 (ly:font-get-glyph font
3699 (format #f (if ancient-flags?
3700 "flags.mensural~a2~a"
3702 (if (> dir 0) "u" "d")
3704 (cons (+ (car attach-off)
3705 ;; For tighter stems (with ancient-flags) the
3706 ;; flag has to be adjusted different.
3707 (if (and (not ancient-flags?) (< dir 0))
3710 (+ stemy flag-style-Y-corr))))))
3712 ;; If there is a flag on an upstem and the stem is short, move the dots
3713 ;; to avoid the flag. 16th notes get a special case because their flags
3714 ;; hang lower than any other flags.
3715 ;; Not with ancient flags or straight-flags.
3716 (if (and dots (> dir 0) (> log 2)
3717 (or (eq? flag-style 'default) (null? flag-style))
3718 (not ancient-flags?)
3719 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3720 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3722 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3723 (if (ly:stencil? stem-glyph)
3724 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3725 (set! stem-glyph head-glyph))
3726 (if (ly:stencil? dots)
3729 (ly:stencil-translate-axis
3731 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3737 (let ((divisor (log 2)))
3738 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3740 (define (parse-simple-duration duration-string)
3741 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3742 and return a (log dots) list."
3743 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3745 (if (and match (string=? duration-string (match:substring match 0)))
3746 (let ((len (match:substring match 1))
3747 (dots (match:substring match 2)))
3748 (list (cond ((string=? len "breve") -1)
3749 ((string=? len "longa") -2)
3750 ((string=? len "maxima") -3)
3751 (else (log2 (string->number len))))
3752 (if dots (string-length dots) 0)))
3753 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3755 (define-markup-command (note layout props duration dir)
3758 #:properties (note-by-number-markup)
3760 @cindex notes within text by string
3762 This produces a note with a stem pointing in @var{dir} direction, with
3763 the @var{duration} for the note head type and augmentation dots. For
3764 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3765 a shortened down stem.
3767 @lilypond[verbatim,quote]
3769 \\override #'(style . cross) {
3773 \\note #\"breve\" #0
3776 (let ((parsed (parse-simple-duration duration)))
3777 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3780 ;; the rest command.
3781 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3783 (define-markup-command (rest-by-number layout props log dot-count)
3786 #:properties ((font-size 0)
3788 (multi-measure-rest #f))
3790 @cindex rests or multi-measure-rests within text by log and dot-count
3792 A rest or multi-measure-rest symbol.
3794 @lilypond[verbatim,quote]
3796 \\rest-by-number #3 #2
3798 \\rest-by-number #0 #1
3800 \\override #'(multi-measure-rest . #t)
3801 \\rest-by-number #0 #0
3805 (define (get-glyph-name-candidates log style)
3806 (let* (;; Choose the style-string to be added.
3807 ;; If no glyph exists, select others for the specified styles
3808 ;; otherwise defaulting.
3811 ;; 'baroque needs to be special-cased, otherwise
3812 ;; `select-head-glyphĀ“ would catch neomensural-glyphs for
3813 ;; this style, if (< log 0).
3814 (eq? style 'baroque)
3815 (string-append (number->string log) ""))
3816 ((eq? style 'petrucci)
3817 (string-append (number->string log) "mensural"))
3818 ;; In other cases `select-head-glyphĀ“ from output-lib.scm
3819 ;; works for rest-glyphs, too.
3820 ((and (symbol? style) (not (eq? style 'default)))
3821 (select-head-glyph style log))
3823 ;; Choose ledgered glyphs for whole and half rest.
3824 ;; Except for the specified styles, logs and MultiMeasureRests.
3826 (if (and (or (list? style)
3828 '(neomensural mensural petrucci))))
3829 (not multi-measure-rest)
3830 (or (= log 0) (= log 1)))
3833 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3835 (define (get-glyph-name font cands)
3836 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3841 (ly:paper-get-font layout
3842 (cons '((font-encoding . fetaMusic)
3847 (get-glyph-name font
3848 (get-glyph-name-candidates log style))))
3849 (if (string-null? result)
3850 ;; If no glyph name can be found, select default rests. Though
3851 ;; this usually means an unsupported style has been chosen, it
3852 ;; also prevents unrelated 'style settings from other grobs
3853 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3854 (get-glyph-name font (get-glyph-name-candidates log 'default))
3856 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3857 (dot (ly:font-get-glyph font "dots.dot"))
3858 (dot-width (interval-length (ly:stencil-extent dot X)))
3859 (dots (and (> dot-count 0)
3860 (apply ly:stencil-add
3862 (ly:stencil-translate-axis
3863 dot (* 2 x dot-width) X))
3864 (iota dot-count))))))
3866 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3867 ;; glyphs are taken for whole and half rests.
3868 ;; If they are dotted, move the dots in X-direction to avoid collision.
3872 (not (member style '(neomensural mensural petrucci))))
3873 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3875 ;; Add dots to the rest-glyph.
3877 ;; Not sure how to vertical align dots.
3878 ;; For now the dots are centered for half, whole or longer rests.
3879 ;; Otherwise placed near the top of the rest.
3881 ;; Dots for rests with (< log 0) dots are allowed, but not
3882 ;; if multi-measure-rest is set #t.
3883 (if (and (not multi-measure-rest) dots)
3886 (ly:stencil-translate
3889 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3891 (interval-center (ly:stencil-extent rest-glyph Y))
3892 (- (interval-end (ly:stencil-extent rest-glyph Y))
3893 (/ (* 2 dot-width) 3)))))
3897 (define-markup-command (rest layout props duration)
3900 #:properties ((style '())
3901 (multi-measure-rest #f)
3902 (multi-measure-rest-number #t)
3905 @cindex rests or multi-measure-rests within text by string
3907 This produces a rest, with the @var{duration} for the rest type and
3909 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3912 Printing MultiMeasureRests could be enabled with
3913 @code{\\override #'(multi-measure-rest . #t)}
3914 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3915 This is enabled for all styles using default-glyphs.
3916 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3918 @lilypond[verbatim,quote]
3924 \\override #'(multi-measure-rest . #t)
3928 \\override #'(multi-measure-rest-number . #f)
3933 ;; Get the number of mmr-glyphs.
3934 ;; Store them in a list.
3935 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3936 (define (mmr-numbers nmbr)
3937 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3938 (8-remainder (remainder nmbr 8))
3939 (4-bar-glyph (floor (/ 8-remainder 4)))
3940 (4-remainder (remainder nmbr 4))
3941 (2-bar-glyph (floor (/ 4-remainder 2)))
3942 (2-remainder (remainder 4-remainder 2))
3943 (1-bar-glyph (floor (/ 2-remainder 1))))
3944 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3946 ;; Get the correct mmr-glyphs.
3947 ;; Store them in a list.
3949 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3950 ;; -> ("rests.M3" "rests.M1")
3951 (define (get-mmr-glyphs lst1 lst2)
3952 (define (helper l1 l2 l3)
3957 (append (make-list (car l1) (car l2)) l3))))
3958 (helper lst1 lst2 '()))
3960 ;; If duration is not valid, print a warning and return empty-stencil
3961 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3962 (not multi-measure-rest))
3963 (and (= (string-length (car (string-split duration #\. ))) 1)
3964 (= (string->number (car (string-split duration #\. ))) 0)))
3966 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3969 ;; For simple rests:
3970 ;; Get a (log dots) list.
3971 (parsed (parse-simple-duration duration))
3972 ;; Create the rest-stencil
3974 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3975 ;; For MultiMeasureRests:
3976 ;; Get the duration-part of duration
3977 (dur-part-string (car (string-split duration #\. )))
3978 ;; Get the duration of MMR:
3979 ;; If not a number (eg. "maxima") calculate it.
3981 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3982 ;; Get a list of the correct number of each mmr-glyph.
3983 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3984 ;; Create a list of mmr-stencils,
3985 ;; translating the glyph for a whole rest.
3989 (let ((single-mmr-stil
3990 (rest-by-number-markup layout props (* -1 x) 0)))
3992 (ly:stencil-translate-axis
3994 ;; Ugh, hard-coded, why 1?
3998 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3999 ;; Adjust the space between the mmr-glyphs,
4000 ;; if not default-glyphs are used.
4001 (word-space (if (member style
4002 '(neomensural mensural petrucci))
4003 (/ (* word-space 2) 3)
4005 ;; Create the final mmr-stencil
4006 ;; via `stack-stencil-lineĀ“ from /scm/markup.scm
4007 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
4009 ;; Print the number above a multi-measure-rest
4010 ;; Depends on duration, style and multi-measure-rest-number set #t
4011 (if (and multi-measure-rest
4012 multi-measure-rest-number
4014 (not (member style '(neomensural mensural petrucci))))
4015 (let* ((mmr-stil-x-center
4016 (interval-center (ly:stencil-extent mmr-stil X)))
4020 #:override '(font-encoding . fetaText)
4021 (number->string mmr-duration)))
4023 (interpret-markup layout props duration-markup))
4024 (mmr-number-stil-x-center
4025 (interval-center (ly:stencil-extent mmr-number-stil X))))
4027 (set! mmr-stil (ly:stencil-combine-at-edge
4030 (ly:stencil-translate-axis
4032 (- mmr-stil-x-center mmr-number-stil-x-center)
4036 (if multi-measure-rest
4040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4044 (define-markup-command (fermata layout props) ()
4046 #:properties ((direction UP))
4047 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
4048 an inverted glyph. Note that within music, one would usually use the
4049 @code{\\fermata} articulation instead of a markup.
4051 @lilypond[verbatim,quote]
4052 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
4054 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
4057 (interpret-markup layout props
4058 (if (eqv? direction DOWN)
4059 (markup #:musicglyph "scripts.dfermata")
4060 (markup #:musicglyph "scripts.ufermata"))))
4062 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4066 (define-markup-command (lower layout props amount arg)
4070 @cindex lowering text
4072 Lower @var{arg} by the distance @var{amount}.
4073 A negative @var{amount} indicates raising; see also @code{\\raise}.
4075 @lilypond[verbatim,quote]
4083 (ly:stencil-translate-axis (interpret-markup layout props arg)
4086 (define-markup-command (translate-scaled layout props offset arg)
4087 (number-pair? markup?)
4089 #:properties ((font-size 0))
4091 @cindex translating text
4092 @cindex scaling text
4094 Translate @var{arg} by @var{offset}, scaling the offset by the
4097 @lilypond[verbatim,quote]
4100 * \\translate #'(2 . 3) translate
4102 * \\translate-scaled #'(2 . 3) translate-scaled
4106 (let* ((factor (magstep font-size))
4107 (scaled (cons (* factor (car offset))
4108 (* factor (cdr offset)))))
4109 (ly:stencil-translate (interpret-markup layout props arg)
4112 (define-markup-command (raise layout props amount arg)
4116 @cindex raising text
4118 Raise @var{arg} by the distance @var{amount}.
4119 A negative @var{amount} indicates lowering, see also @code{\\lower}.
4121 The argument to @code{\\raise} is the vertical displacement amount,
4122 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
4123 raise objects in relation to their surrounding markups.
4125 If the text object itself is positioned above or below the staff, then
4126 @code{\\raise} cannot be used to move it, since the mechanism that
4127 positions it next to the staff cancels any shift made with
4128 @code{\\raise}. For vertical positioning, use the @code{padding}
4129 and/or @code{extra-offset} properties.
4131 @lilypond[verbatim,quote]
4140 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4142 (define-markup-command (fraction layout props arg1 arg2)
4145 #:properties ((font-size 0))
4147 @cindex creating text fractions
4149 Make a fraction of two markups.
4150 @lilypond[verbatim,quote]
4156 (let* ((m1 (interpret-markup layout props arg1))
4157 (m2 (interpret-markup layout props arg2))
4158 (factor (magstep font-size))
4159 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4160 (padding (* factor 0.2))
4161 (baseline (* factor 0.6))
4162 (offset (* factor 0.75)))
4163 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4164 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4165 (let* ((x1 (ly:stencil-extent m1 X))
4166 (x2 (ly:stencil-extent m2 X))
4167 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4168 ;; should stack mols separately, to maintain LINE on baseline
4169 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4171 (ly:stencil-aligned-to stack Y CENTER))
4173 (ly:stencil-aligned-to stack X LEFT))
4174 ;; should have EX dimension
4176 (ly:stencil-translate-axis stack offset Y))))
4178 (define-markup-command (normal-size-super layout props arg)
4181 #:properties ((font-size 0))
4183 @cindex setting superscript in standard font size
4185 Set @var{arg} in superscript with a normal font size.
4187 @lilypond[verbatim,quote]
4190 \\normal-size-super {
4191 superscript in standard size
4195 (ly:stencil-translate-axis
4196 (interpret-markup layout props arg)
4197 (* 1.0 (magstep font-size)) Y))
4199 (define-markup-command (super layout props arg)
4202 #:properties ((font-size 0))
4204 @cindex superscript text
4206 Set @var{arg} in superscript.
4208 @lilypond[verbatim,quote]
4218 (ly:stencil-translate-axis
4221 (cons `((font-size . ,(- font-size 3))) props)
4223 (* 1.0 (magstep font-size)) ; original font-size
4226 (define-markup-command (translate layout props offset arg)
4227 (number-pair? markup?)
4230 @cindex translating text
4232 Translate @var{arg} relative to its surroundings. @var{offset}
4233 is a pair of numbers representing the displacement in the X and Y axis.
4235 @lilypond[verbatim,quote]
4238 \\translate #'(2 . 3)
4239 \\line { translated two spaces right, three up }
4242 (ly:stencil-translate (interpret-markup layout props arg)
4245 (define-markup-command (sub layout props arg)
4248 #:properties ((font-size 0))
4250 @cindex subscript text
4252 Set @var{arg} in subscript.
4254 @lilypond[verbatim,quote]
4265 (ly:stencil-translate-axis
4268 (cons `((font-size . ,(- font-size 3))) props)
4270 (* -0.75 (magstep font-size)) ; original font-size
4273 (define-markup-command (normal-size-sub layout props arg)
4276 #:properties ((font-size 0))
4278 @cindex setting subscript in standard font size
4280 Set @var{arg} in subscript with a normal font size.
4282 @lilypond[verbatim,quote]
4286 subscript in standard size
4290 (ly:stencil-translate-axis
4291 (interpret-markup layout props arg)
4292 (* -0.75 (magstep font-size))
4295 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4299 (define-markup-command (hbracket layout props arg)
4303 @cindex placing horizontal brackets around text
4305 Draw horizontal brackets around @var{arg}.
4307 @lilypond[verbatim,quote]
4316 (let ((th 0.1) ;; todo: take from GROB.
4317 (m (interpret-markup layout props arg)))
4318 (bracketify-stencil m X th (* 2.5 th) th)))
4320 (define-markup-command (bracket layout props arg)
4324 @cindex placing vertical brackets around text
4326 Draw vertical brackets around @var{arg}.
4328 @lilypond[verbatim,quote]
4335 (let ((th 0.1) ;; todo: take from GROB.
4336 (m (interpret-markup layout props arg)))
4337 (bracketify-stencil m Y th (* 2.5 th) th)))
4339 (define-markup-command (parenthesize layout props arg)
4342 #:properties ((angularity 0)
4348 @cindex placing parentheses around text
4350 Draw parentheses around @var{arg}. This is useful for parenthesizing
4351 a column containing several lines of text.
4353 @lilypond[verbatim,quote]
4362 \\override #'(angularity . 2) {
4373 (let* ((m (interpret-markup layout props arg))
4374 (scaled-width (* size width))
4376 (* (chain-assoc-get 'line-thickness props 0.1)
4379 (min (* size 0.5 scaled-thickness)
4380 (* (/ 4 3.0) scaled-width)))
4381 (padding (chain-assoc-get 'padding props half-thickness)))
4382 (parenthesize-stencil
4383 m half-thickness scaled-width angularity padding)))
4386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4387 ;; Delayed markup evaluation
4388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4390 (define-markup-command (page-ref layout props label gauge default)
4391 (symbol? markup? markup?)
4394 @cindex referencing page numbers in text
4396 Reference to a page number. @var{label} is the label set on the referenced
4397 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4398 the maximum width of the page number, and @var{default} the value to display
4399 when @var{label} is not found.
4401 (If the current book or bookpart is set to use roman numerals for page numbers,
4402 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4403 width may require additional tweaking.)"
4404 (let* ((gauge-stencil (interpret-markup layout props gauge))
4405 (x-ext (ly:stencil-extent gauge-stencil X))
4406 (y-ext (ly:stencil-extent gauge-stencil Y)))
4408 (make-transparent-box-stencil x-ext y-ext))
4410 `(delay-stencil-evaluation
4411 ,(delay (ly:stencil-expr
4412 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4413 (page-number (if (list? table)
4414 (assoc-get label table)
4416 (number-type (ly:output-def-lookup layout 'page-number-type))
4417 (page-markup (if page-number
4418 (number-format number-type page-number)
4420 (page-stencil (interpret-markup layout props page-markup))
4421 (gap (- (interval-length x-ext)
4422 (interval-length (ly:stencil-extent page-stencil X)))))
4423 (interpret-markup layout props
4424 (markup #:hspace gap page-markup))))))
4428 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4430 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4432 (define-markup-command (scale layout props factor-pair arg)
4433 (number-pair? markup?)
4436 @cindex scaling markup
4437 @cindex mirroring markup
4439 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4440 representing the scaling-factor in the X and Y axes.
4441 Negative values may be used to produce mirror images.
4443 @lilypond[verbatim,quote]
4453 (let ((stil (interpret-markup layout props arg))
4454 (sx (car factor-pair))
4455 (sy (cdr factor-pair)))
4456 (ly:stencil-scale stil sx sy)))
4458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4462 (define-markup-command (pattern layout props count axis space pattern)
4463 (integer? integer? number? markup?)
4466 Prints @var{count} times a @var{pattern} markup.
4467 Patterns are spaced apart by @var{space}.
4468 Patterns are distributed on @var{axis}.
4470 @lilypond[verbatim, quote]
4472 \"Horizontally repeated :\"
4473 \\pattern #7 #X #2 \\flat
4475 \"Vertically repeated :\"
4476 \\pattern #3 #Y #0.5 \\flat
4479 (let ((pattern-width (interval-length
4480 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4481 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4482 (let loop ((i (1- count)) (patterns (markup)))
4488 (markup patterns pattern)
4489 (markup #:column (patterns pattern))))
4492 (markup patterns pattern #:hspace space)
4493 (markup #:column (patterns pattern #:vspace space))))))))
4495 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4496 (number? ly:dir? markup? markup? markup?)
4498 #:properties ((word-space)
4501 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4502 with a line of markups @var{pattern} in between.
4503 Patterns are spaced apart by @var{space}.
4504 Patterns are aligned to the @var{dir} markup.
4506 @lilypond[verbatim, quote]
4509 \\fill-with-pattern #1 #RIGHT . first right
4510 \\fill-with-pattern #1 #RIGHT . second right
4512 \"center-aligned :\"
4513 \\fill-with-pattern #1.5 #CENTER - left right
4516 \\override #'(line-width . 50)
4517 \\fill-with-pattern #2 #LEFT : left first
4518 \\override #'(line-width . 50)
4519 \\fill-with-pattern #2 #LEFT : left second
4522 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4523 (pattern-width (interval-length pattern-x-extent))
4524 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4525 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4526 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4527 (period (+ space pattern-width))
4528 (count (truncate (/ (- middle-width pattern-width) period)))
4529 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4530 (interpret-markup layout props
4532 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4533 #:translate (cons x-offset 0)
4534 #:pattern (1+ count) X space pattern
4537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4541 (define-markup-command (replace layout props replacements arg)
4545 Used to automatically replace a string by another in the markup @var{arg}.
4546 Each pair of the alist @var{replacements} specifies what should be replaced.
4547 The @code{key} is the string to be replaced by the @code{value} string.
4549 @lilypond[verbatim, quote]
4550 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4554 (internal-add-text-replacements
4559 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4560 ;; Markup list commands
4561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4563 (define-public (space-lines baseline stils)
4564 (let space-stil ((stils stils)
4568 (let* ((stil (car stils))
4569 (dy-top (max (- (/ baseline 1.5)
4570 (interval-bound (ly:stencil-extent stil Y) UP))
4572 (dy-bottom (max (+ (/ baseline 3.0)
4573 (interval-bound (ly:stencil-extent stil Y) DOWN))
4575 (new-stil (ly:make-stencil
4576 (ly:stencil-expr stil)
4577 (ly:stencil-extent stil X)
4578 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4580 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4582 (space-stil (cdr stils) (cons new-stil result))))))
4584 (define-markup-list-command (justified-lines layout props args)
4586 #:properties ((baseline-skip)
4587 wordwrap-internal-markup-list)
4589 @cindex justifying lines of text
4591 Like @code{\\justify}, but return a list of lines instead of a single markup.
4592 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4593 @var{X}@tie{}is the number of staff spaces."
4594 (space-lines baseline-skip
4595 (interpret-markup-list layout props
4596 (make-wordwrap-internal-markup-list #t args))))
4598 (define-markup-list-command (wordwrap-lines layout props args)
4600 #:properties ((baseline-skip)
4601 wordwrap-internal-markup-list)
4602 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4603 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4604 where @var{X} is the number of staff spaces."
4605 (space-lines baseline-skip
4606 (interpret-markup-list layout props
4607 (make-wordwrap-internal-markup-list #f args))))
4609 (define-markup-list-command (column-lines layout props args)
4611 #:properties ((baseline-skip))
4612 "Like @code{\\column}, but return a list of lines instead of a single markup.
4613 @code{baseline-skip} determines the space between each markup in @var{args}."
4614 (space-lines baseline-skip
4615 (interpret-markup-list layout props args)))
4617 (define-markup-list-command (override-lines layout props new-prop args)
4618 (pair? markup-list?)
4619 "Like @code{\\override}, for markup lists."
4620 (interpret-markup-list layout (cons (list new-prop) props) args))
4622 (define-markup-list-command (map-markup-commands layout props compose args)
4623 (procedure? markup-list?)
4624 "This applies the function @var{compose} to every markup in
4625 @var{args} (including elements of markup list command calls) in order
4626 to produce a new markup list. Since the return value from a markup
4627 list command call is not a markup list but rather a list of stencils,
4628 this requires passing those stencils off as the results of individual
4629 markup calls. That way, the results should work out as long as no
4630 markups rely on side effects."
4631 (let ((key (make-symbol "key")))
4635 ;; if `compose' does not actually interpret its markup
4636 ;; argument, we still need to return a list of stencils,
4637 ;; created from the single returned stencil
4639 (interpret-markup layout props
4641 (make-on-the-fly-markup
4642 (lambda (layout props m)
4643 ;; here all effects of `compose' on the
4644 ;; properties should be visible, so we
4645 ;; call interpret-markup-list at this
4646 ;; point of time and harvest its
4649 (interpret-markup-list
4650 layout props args)))
4651 (make-null-markup))))))
4652 (lambda (key stencils)
4655 (interpret-markup layout props
4656 (compose (make-stencil-markup sten))))