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-squiggle-line layout props sq-length dest eq-end?)
310 (number? number-pair? boolean?)
312 #:properties ((thickness 0.5)
317 @cindex drawing squiggled lines within text
321 If @code{eq-end?} is set to @code{#t}, it is ensured the squiggled line ends
322 with a bow in same direction as the starting one. @code{sq-length} is the
323 length of the first bow. @code{dest} is the end point of the squiggled line.
324 To match @code{dest} the squiggled line is scaled accordingly.
325 Its appearance may be customized by overrides for @code{thickness},
326 @code{angularity}, @code{height} and @code{orientation}.
327 @lilypond[verbatim,quote]
330 \\draw-squiggle-line #0.5 #'(6 . 0) ##t
331 \\override #'(orientation . -1)
332 \\draw-squiggle-line #0.5 #'(6 . 0) ##t
333 \\draw-squiggle-line #0.5 #'(6 . 0) ##f
334 \\override #'(height . 1)
335 \\draw-squiggle-line #0.5 #'(6 . 0) ##t
336 \\override #'(thickness . 5)
337 \\draw-squiggle-line #0.5 #'(6 . 0) ##t
338 \\override #'(angularity . 2)
339 \\draw-squiggle-line #0.5 #'(6 . 0) ##t
342 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
343 (thick (* thickness line-thickness))
346 (length-to-print (magnitude (make-rectangular x y)))
347 ;; Make a guess how many bows may be needed
348 (guess (max 1 (truncate (/ length-to-print sq-length))))
349 ;; If `eq-end?' is set #t, make sure squiggle-line starts and ends
350 ;; with a bow in same direction
351 (amount (if (and (even? guess) eq-end?) (1+ guess) guess))
352 ;; The lined-up bows needs to fit `length-to-print'
353 ;; Thus scale the length of first bow accordingly
354 ;; Other bows are copies
355 (guessed-squiggle-line-length (* amount sq-length))
356 (line-length-diff (- length-to-print guessed-squiggle-line-length))
357 (line-length-diff-for-each-squiggle
358 (/ line-length-diff amount))
359 (first-bow-length (+ sq-length line-length-diff-for-each-squiggle))
361 ;; TODO two bows are created via `make-bow-stencil'
362 ;; cheaper to use `ly:stencil-scale'?
365 (/ (* first-bow-length x) length-to-print)
366 (/ (* first-bow-length y) length-to-print)))
372 thick angularity height o)))
373 (init-bow-up (init-bow orientation))
374 (init-bow-down (init-bow (- orientation)))
375 ;; Get a list of starting-points for the bows
380 (* n (car first-bow-end-coord))
381 (* n (cdr first-bow-end-coord))))
383 ;; The final stencil: lined-up bows
384 (apply ly:stencil-add
387 (circular-list init-bow-up init-bow-down)
390 (define-markup-command (draw-hline layout props)
393 #:properties ((draw-line-markup)
397 @cindex drawing a line across a page
399 Draws a line across a page, where the property @code{span-factor}
400 controls what fraction of the page is taken up.
401 @lilypond[verbatim,quote]
405 \\override #'(span-factor . 1/3)
410 (interpret-markup layout
412 (markup #:draw-line (cons (* line-width
416 (define-markup-command (draw-circle layout props radius thickness filled)
417 (number? number? boolean?)
420 @cindex drawing circles within text
422 A circle of radius @var{radius} and thickness @var{thickness},
425 @lilypond[verbatim,quote]
427 \\draw-circle #2 #0.5 ##f
429 \\draw-circle #2 #0 ##t
432 (make-circle-stencil radius thickness filled))
434 (define-markup-command (triangle layout props filled)
437 #:properties ((thickness 0.1)
441 @cindex drawing triangles within text
443 A triangle, either filled or empty.
445 @lilypond[verbatim,quote]
452 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
461 (cons 0 (* .86 ex)))))
463 (define-markup-command (circle layout props arg)
466 #:properties ((thickness 1)
468 (circle-padding 0.2))
470 @cindex circling text
472 Draw a circle around @var{arg}. Use @code{thickness},
473 @code{circle-padding} and @code{font-size} properties to determine line
474 thickness and padding around the markup.
476 @lilypond[verbatim,quote]
483 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
485 (pad (* (magstep font-size) circle-padding))
486 (m (interpret-markup layout props arg)))
487 (circle-stencil m th pad)))
489 (define-markup-command (ellipse layout props arg)
492 #:properties ((thickness 1)
497 @cindex drawing ellipse around text
499 Draw an ellipse around @var{arg}. Use @code{thickness},
500 @code{x-padding}, @code{y-padding} and @code{font-size} properties to determine
501 line thickness and padding around the markup.
503 @lilypond[verbatim,quote]
510 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
512 (pad-x (* (magstep font-size) x-padding))
513 (pad-y (* (magstep font-size) y-padding))
514 (m (interpret-markup layout props arg)))
515 (ellipse-stencil m th pad-x pad-y)))
517 (define-markup-command (oval layout props arg)
520 #:properties ((thickness 1)
525 @cindex drawing oval around text
527 Draw an oval around @var{arg}. Use @code{thickness},
528 @code{x-padding}, @code{x-padding} and @code{font-size} properties to determine
529 line thickness and padding around the markup.
531 @lilypond[verbatim,quote]
538 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
540 (pad-x (* (magstep font-size) x-padding))
541 (pad-y (* (magstep font-size) y-padding))
542 (m (interpret-markup layout props arg)))
543 (oval-stencil m th pad-x pad-y)))
545 (define-markup-command (with-url layout props url arg)
549 @cindex inserting URL links into text
551 Add a link to URL @var{url} around @var{arg}. This only works in
554 @lilypond[verbatim,quote]
556 \\with-url #\"http://lilypond.org/\" {
557 LilyPond ... \\italic {
558 music notation for everyone
563 (let* ((stil (interpret-markup layout props arg))
564 (xextent (ly:stencil-extent stil X))
565 (yextent (ly:stencil-extent stil Y))
566 (old-expr (ly:stencil-expr stil))
567 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
569 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
571 (define-markup-command (page-link layout props page-number arg)
575 @cindex referencing page numbers in text
577 Add a link to the page @var{page-number} around @var{arg}. This only works
580 @lilypond[verbatim,quote]
582 \\page-link #2 { \\italic { This links to page 2... } }
585 (let* ((stil (interpret-markup layout props arg))
586 (xextent (ly:stencil-extent stil X))
587 (yextent (ly:stencil-extent stil Y))
588 (old-expr (ly:stencil-expr stil))
589 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
591 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
593 (define-public (book-first-page layout props)
594 "Return the @code{'first-page-number} of the entire book"
595 (define (ancestor layout)
596 "Return the topmost layout ancestor"
597 (let ((parent (ly:output-def-parent layout)))
598 (if (not (ly:output-def? parent))
601 (ly:output-def-lookup (ancestor layout) 'first-page-number))
603 (define-markup-command (with-link layout props label arg)
607 @cindex referencing page labels in text
609 Add a link to the page holding label @var{label} around @var{arg}. This
610 only works in the PDF backend.
612 @lilypond[verbatim,quote]
614 \\with-link #'label {
615 \\italic { This links to the page containing the label... }
619 (let* ((arg-stencil (interpret-markup layout props arg))
620 (x-ext (ly:stencil-extent arg-stencil X))
621 (y-ext (ly:stencil-extent arg-stencil Y)))
624 `(delay-stencil-evaluation
625 ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
628 (assoc-get label table)
630 (first-page-number (book-first-page layout props))
632 (if table-page-number
633 (1+ (- table-page-number first-page-number))
635 (list 'page-link current-page-number
636 `(quote ,x-ext) `(quote ,y-ext)))))
641 (define-markup-command (beam layout props width slope thickness)
642 (number? number? number?)
645 @cindex drawing beams within text
647 Create a beam with the specified parameters.
648 @lilypond[verbatim,quote]
653 (let* ((y (* slope width))
654 (yext (cons (min 0 y) (max 0 y)))
655 (half (/ thickness 2)))
660 width (+ (* width slope) (/ thickness -2))
661 width (+ (* width slope) (/ thickness 2))
663 ,(ly:output-def-lookup layout 'blot-diameter)
666 (cons (+ (- half) (car yext))
667 (+ half (cdr yext))))))
669 (define-markup-command (underline layout props arg)
672 #:properties ((thickness 1) (offset 2))
674 @cindex underlining text
676 Underline @var{arg}. Looks at @code{thickness} to determine line
677 thickness, and @code{offset} to determine line y-offset.
679 @lilypond[verbatim,quote]
680 \\markup \\fill-line {
681 \\underline \"underlined\"
682 \\override #'(offset . 5)
683 \\override #'(thickness . 1)
684 \\underline \"underlined\"
685 \\override #'(offset . 1)
686 \\override #'(thickness . 5)
687 \\underline \"underlined\"
690 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
691 (underline-thick (* thickness thick))
692 (m (interpret-markup layout props arg))
693 (x1 (car (ly:stencil-extent m X)))
694 (x2 (cdr (ly:stencil-extent m X)))
695 (y (* thick (- offset)))
696 (line (make-line-stencil underline-thick x1 y x2 y)))
697 (ly:stencil-add m line)))
699 (define-markup-command (tie layout props arg)
702 #:properties ((thickness 1)
705 (shorten-pair '(0 . 0)))
709 Adds a horizontal bow created with @code{make-tie-stencil} at bottom or top
710 of @var{arg}. Looks at @code{thickness} to determine line thickness, and
711 @code{offset} to determine y-offset. The added bow fits the extent of
712 @var{arg}, @code{shorten-pair} may be used to modify this.
713 @var{direction} may be set using an @code{override} or direction-modifiers or
714 @code{voiceOne}, etc.
716 @lilypond[verbatim,quote]
718 \\override #'(direction . 1)
720 \\override #'(direction . -1)
724 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
725 (thick (* thickness line-thickness))
726 (stil (interpret-markup layout props arg))
727 (x1 (car (ly:stencil-extent stil X)))
728 (x2 (cdr (ly:stencil-extent stil X)))
729 (y-ext (ly:stencil-extent stil Y))
730 (y (+ (* line-thickness offset direction)
731 ;; we put out zero for positive text-direction, to make it
732 ;; consistent with `underline-markup'
733 ;; TODO: this will be problematic for args like "Eng"
734 ;; fix it here _and_ in `underline-markup'
735 (if (negative? direction) 0 (cdr y-ext))))
738 (cons (+ x1 (car shorten-pair) line-thickness) y)
739 (cons (- x2 (cdr shorten-pair) line-thickness) y)
742 (ly:stencil-add stil tie)))
744 (define-markup-command (undertie layout props arg)
747 #:properties (tie-markup)
749 @cindex undertie-ing text
751 @lilypond[verbatim,quote]
753 \\undertie \"undertied\"
754 \\override #'(offset . 5)
755 \\override #'(thickness . 1)
756 \\undertie \"undertied\"
757 \\override #'(offset . 1)
758 \\override #'(thickness . 5)
759 \\undertie \"undertied\"
762 (interpret-markup layout (prepend-alist-chain 'direction DOWN props)
763 (make-tie-markup arg)))
765 (define-markup-command (overtie layout props arg)
768 #:properties (tie-markup)
770 @cindex overtie-ing text
774 @lilypond[verbatim,quote]
776 \\overtie \"overtied\"
777 \\override #'(offset . 5)
778 \\override #'(thickness . 1)
779 \\overtie \"overtied\"
780 \\override #'(offset . 1)
781 \\override #'(thickness . 5)
782 \\overtie \"overtied\"
785 (interpret-markup layout (prepend-alist-chain 'direction UP props)
786 (make-tie-markup arg)))
788 (define-markup-command (box layout props arg)
791 #:properties ((thickness 1)
795 @cindex enclosing text within a box
797 Draw a box round @var{arg}. Looks at @code{thickness},
798 @code{box-padding} and @code{font-size} properties to determine line
799 thickness and padding around the markup.
801 @lilypond[verbatim,quote]
803 \\override #'(box-padding . 0.5)
808 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
810 (pad (* (magstep font-size) box-padding))
811 (m (interpret-markup layout props arg)))
812 (box-stencil m th pad)))
814 (define-markup-command (filled-box layout props xext yext blot)
815 (number-pair? number-pair? number?)
818 @cindex drawing solid boxes within text
819 @cindex drawing boxes with rounded corners
821 Draw a box with rounded corners of dimensions @var{xext} and
822 @var{yext}. For example,
824 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
826 creates a box extending horizontally from -0.3 to 1.8 and
827 vertically from -0.3 up to 1.8, with corners formed from a
828 circle of diameter@tie{}0 (i.e., sharp corners).
830 @lilypond[verbatim,quote]
832 \\filled-box #'(0 . 4) #'(0 . 4) #0
833 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
834 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
836 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
842 (define-markup-command (rounded-box layout props arg)
845 #:properties ((thickness 1)
849 "@cindex enclosing text in a box with rounded corners
850 @cindex drawing boxes with rounded corners around text
851 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
852 @code{box-padding} and @code{font-size} properties to determine line
853 thickness and padding around the markup; the @code{corner-radius} property
854 makes it possible to define another shape for the corners (default is 1).
856 @lilypond[quote,verbatim,relative=2]
864 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
866 (pad (* (magstep font-size) box-padding))
867 (m (interpret-markup layout props arg)))
868 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
871 (define-markup-command (rotate layout props ang arg)
875 @cindex rotating text
877 Rotate object with @var{ang} degrees around its center.
879 @lilypond[verbatim,quote]
889 (let* ((stil (interpret-markup layout props arg)))
890 (ly:stencil-rotate stil ang 0 0)))
892 (define-markup-command (whiteout layout props arg)
895 #:properties ((style 'box)
898 @cindex adding a white background to text
900 Provide a white background for @var{arg}. The shape of the white
901 background is determined by @code{style}. The default
902 is @code{box} which produces a rectangle. @code{rounded-box}
903 produces a rounded rectangle. @code{outline} approximates the
904 outline of the markup.
906 @lilypond[verbatim,quote]
909 \\filled-box #'(-1 . 15) #'(-3 . 4) #1
910 \\override #'(thickness . 1.5)
911 \\whiteout whiteout-box
915 \\filled-box #'(-1 . 24) #'(-3 . 4) #1
916 \\override #'(style . rounded-box)
917 \\override #'(thickness . 3)
918 \\whiteout whiteout-rounded-box
922 \\filled-box #'(-1 . 18) #'(-3 . 4) #1
923 \\override #'(style . outline)
924 \\override #'(thickness . 3)
925 \\whiteout whiteout-outline
929 (interpret-markup layout props arg)
932 (ly:output-def-lookup layout 'line-thickness)))
934 (define-markup-command (pad-markup layout props amount arg)
939 @cindex putting space around text
941 Add space around a markup object.
942 Identical to @code{pad-around}.
944 @lilypond[verbatim,quote]
957 (let* ((m (interpret-markup layout props arg))
958 (x (interval-widen (ly:stencil-extent m X) amount))
959 (y (interval-widen (ly:stencil-extent m Y) amount)))
960 (ly:stencil-add (make-transparent-box-stencil x y)
963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
967 (define-markup-command (strut layout props)
971 @cindex creating vertical spaces in text
973 Create a box of the same height as the space in the current font."
974 (let ((m (ly:text-interface::interpret-markup layout props " ")))
975 (ly:make-stencil (ly:stencil-expr m)
977 (ly:stencil-extent m X)
980 (define-markup-command (hspace layout props amount)
984 @cindex creating horizontal spaces in text
986 Create an invisible object taking up horizontal space @var{amount}.
988 @lilypond[verbatim,quote]
997 (ly:make-stencil "" (cons 0 amount) empty-interval))
999 (define-markup-command (vspace layout props amount)
1003 @cindex creating vertical spaces in text
1005 Create an invisible object taking up vertical space
1006 of @var{amount} multiplied by 3.
1008 @lilypond[verbatim,quote]
1019 (let ((amount (* amount 3.0)))
1020 (ly:make-stencil "" empty-interval (cons 0 amount))))
1023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1024 ;; importing graphics.
1025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1027 (define-markup-command (stencil layout props stil)
1031 @cindex importing stencils into text
1033 Use a stencil as markup.
1035 @lilypond[verbatim,quote]
1037 \\stencil #(make-circle-stencil 2 0 #t)
1043 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
1045 (define (get-postscript-bbox string)
1046 "Extract the bbox from STRING, or return #f if not present."
1048 ((match (regexp-exec bbox-regexp string)))
1052 (string->number (match:substring match x)))
1057 (define-markup-command (epsfile layout props axis size file-name)
1058 (number? number? string?)
1061 @cindex inlining an Encapsulated PostScript image
1063 Inline an EPS image. The image is scaled along @var{axis} to
1066 @lilypond[verbatim,quote]
1068 \\general-align #Y #DOWN {
1069 \\epsfile #X #20 #\"context-example.eps\"
1070 \\epsfile #Y #20 #\"context-example.eps\"
1074 (if (ly:get-option 'safe)
1075 (interpret-markup layout props "not allowed in safe")
1076 (eps-file->stencil axis size file-name)
1079 (define-markup-command (postscript layout props str)
1083 @cindex inserting PostScript directly into text
1084 This inserts @var{str} directly into the output as a PostScript
1087 @lilypond[verbatim,quote]
1091 0.4 0.6 0.5 0 361 arc
1093 1.0 0.6 0.5 0 361 arc
1098 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
1099 \\postscript #ringsps
1111 gsave currentpoint translate
1119 (define-markup-command (path layout props thickness commands) (number? list?)
1121 #:properties ((line-cap-style 'round)
1122 (line-join-style 'round)
1125 @cindex paths, drawing
1126 @cindex drawing paths
1127 Draws a path with line @var{thickness} according to the
1128 directions given in @var{commands}. @var{commands} is a list of
1129 lists where the @code{car} of each sublist is a drawing command and
1130 the @code{cdr} comprises the associated arguments for each command.
1132 There are seven commands available to use in the list
1133 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
1134 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
1135 @code{closepath}. Note that the commands that begin with @emph{r}
1136 are the relative variants of the other three commands.
1138 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
1139 @code{rlineto} take 2 arguments; they are the X and Y coordinates
1140 for the destination point.
1142 The commands @code{curveto} and @code{rcurveto} create cubic
1143 BĆ©zier curves, and take 6 arguments; the first two are the X and Y
1144 coordinates for the first control point, the second two are the X
1145 and Y coordinates for the second control point, and the last two
1146 are the X and Y coordinates for the destination point.
1148 The @code{closepath} command takes zero arguments and closes the
1149 current subpath in the active path.
1151 Note that a sequence of commands @emph{must} begin with a
1152 @code{moveto} or @code{rmoveto} to work with the SVG output.
1154 Line-cap styles and line-join styles may be customized by
1155 overriding the @code{line-cap-style} and @code{line-join-style}
1156 properties, respectively. Available line-cap styles are
1157 @code{'butt}, @code{'round}, and @code{'square}. Available
1158 line-join styles are @code{'miter}, @code{'round}, and
1161 The property @code{filled} specifies whether or not the path is
1164 @lilypond[verbatim,quote]
1170 (curveto -5 -5 -5 5 -1 0)
1174 \\path #0.25 #samplePath
1176 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
1178 \\override #'(filled . #t) \\path #0.25 #samplePath
1181 (let* ((half-thickness (/ thickness 2))
1182 (current-point '(0 . 0))
1183 (set-point (lambda (lst) (set! current-point lst)))
1184 (relative? (lambda (x)
1185 (string-prefix? "r" (symbol->string (car x)))))
1186 ;; For calculating extents, we want to modify the command
1187 ;; list so that all coordinates are absolute.
1188 (new-commands (map (lambda (x)
1190 ;; for rmoveto, rlineto
1191 ((and (relative? x) (= 3 (length x)))
1193 (+ (car current-point)
1195 (+ (cdr current-point)
1201 ((and (relative? x) (= 7 (length x)))
1202 (let* ((old-cp current-point)
1209 (list (+ (car old-cp) (second x))
1210 (+ (cdr old-cp) (third x))
1211 (+ (car old-cp) (fourth x))
1212 (+ (cdr old-cp) (fifth x))
1215 ;; for moveto, lineto
1217 (set-point (cons (second x)
1222 (set-point (cons (sixth x)
1225 ;; keep closepath for filtering;
1226 ;; see `without-closepath'.
1229 ;; path-min-max does not accept 0-arg lists,
1230 ;; and since closepath does not affect extents, filter
1231 ;; out those commands here.
1232 (without-closepath (filter (lambda (x)
1233 (not (equal? 'closepath (car x))))
1235 (extents (path-min-max
1236 ;; set the origin to the first moveto
1237 (list (list-ref (car without-closepath) 0)
1238 (list-ref (car without-closepath) 1))
1240 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1241 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1242 (command-list (fold-right append '() commands)))
1244 ;; account for line thickness
1245 (set! X-extent (interval-widen X-extent half-thickness))
1246 (set! Y-extent (interval-widen Y-extent half-thickness))
1249 `(path ,thickness `(,@',command-list)
1250 ',line-cap-style ',line-join-style ,filled)
1254 (define-markup-list-command (score-lines layout props score)
1256 "This is the same as the @code{\\score} markup but delivers its
1257 systems as a list of lines. Its @var{score} argument is entered in
1258 braces like it would be for @code{\\score}."
1259 (let ((output (ly:score-embedded-format score layout)))
1261 (if (ly:music-output? output)
1263 (lambda (paper-system)
1264 ;; shift such that the refpoint of the bottom staff of
1265 ;; the first system is the baseline of the score
1266 (ly:stencil-translate-axis
1267 (paper-system-stencil paper-system)
1268 (- (car (paper-system-staff-extents paper-system)))
1270 (vector->list (ly:paper-score-paper-systems output)))
1272 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1275 (define-markup-command (score layout props score)
1278 #:properties ((baseline-skip))
1280 @cindex inserting music into text
1282 Inline an image of music. The reference point (usually the middle
1283 staff line) of the lowest staff in the top system is placed on the
1286 @lilypond[verbatim,quote]
1290 \\new Staff \\relative c' {
1293 \\mark \\markup { Allegro }
1299 \\new Staff \\relative c {
1305 f,( bes d bes d bes)
1313 \\override RehearsalMark
1314 #'break-align-symbols = #'(time-signature key-signature)
1315 \\override RehearsalMark
1316 #'self-alignment-X = #LEFT
1320 \\override TimeSignature
1321 #'break-align-anchor-alignment = #LEFT
1327 (stack-stencils Y DOWN baseline-skip
1328 (score-lines-markup-list layout props score)))
1330 (define-markup-command (null layout props)
1334 @cindex creating empty text objects
1336 An empty markup with extents of a single point.
1338 @lilypond[verbatim,quote]
1345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1346 ;; basic formatting.
1347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1349 (define-markup-command (simple layout props str)
1353 @cindex simple text strings
1355 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1356 @code{\\markup @{ \\simple #\"foo\" @}}.
1358 Note: for creating standard text markup or defining new markup commands,
1359 the use of @code{\\simple} is unnecessary.
1361 @lilypond[verbatim,quote]
1363 \\simple #\"simple\"
1365 \\simple #\"strings\"
1368 (interpret-markup layout props str))
1370 (define-markup-command (first-visible layout props args)
1373 "Use the first markup in @var{args} that yields a non-empty stencil
1374 and ignore the rest.
1376 @lilypond[verbatim,quote]
1379 \\fromproperty #'header:composer
1384 (define (false-if-empty stencil)
1385 (if (ly:stencil-empty? stencil) #f stencil))
1390 (false-if-empty (interpret-markup layout props m))
1391 (any false-if-empty (interpret-markup-list layout props (list m)))))
1395 (define-public empty-markup
1396 (make-simple-markup ""))
1398 ;; helper for justifying lines.
1399 (define (get-fill-space
1400 word-count line-width word-space text-widths constant-space?)
1401 "Calculate the necessary paddings between adjacent texts in a
1402 single justified line. The lengths of all texts are stored in
1404 When @var{constant-space?} is @code{#t}, the formula for the padding
1406 padding = (line-width - total-text-width)/(word-count - 1)
1407 When @var{constant-space?} is @code{#f}, the formula for the
1408 padding between interior texts a and b is:
1409 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1410 In this case, the first and last padding have to be calculated
1411 specially using the whole length of the first or last text.
1412 All paddings are checked to be at least word-space, to ensure that
1414 Return a list of paddings."
1416 ((null? text-widths) '())
1420 ;; Ensure that space between words cannot be
1421 ;; less than word-space.
1424 (/ (- line-width (apply + text-widths))
1427 ;; special case first padding
1428 ((= (length text-widths) word-count)
1430 (- (- (/ line-width (1- word-count)) (car text-widths))
1431 (/ (cadr text-widths) 2))
1433 word-count line-width word-space (cdr text-widths)
1435 ;; special case last padding
1436 ((= (length text-widths) 2)
1437 (list (- (/ line-width (1- word-count))
1438 (+ (/ (car text-widths) 2) (cadr text-widths)))
1441 (let ((default-padding
1442 (- (/ line-width (1- word-count))
1443 (/ (+ (car text-widths) (cadr text-widths)) 2))))
1445 (if (> word-space default-padding)
1449 word-count line-width word-space (cdr text-widths)
1450 constant-space?))))))
1452 (define (justify-line-helper
1453 layout props args text-direction word-space line-width constant-space?)
1454 "Return a stencil which spreads @var{args} along a line of width
1455 @var{line-width}. If @var{constant-space?} is set to @code{#t}, the
1456 space between words is constant. If @code{#f}, the distance between
1457 words varies according to their relative lengths."
1458 (let* ((orig-stencils (interpret-markup-list layout props args))
1461 (if (ly:stencil-empty? stc X)
1462 (ly:make-stencil (ly:stencil-expr stc)
1463 '(0 . 0) (ly:stencil-extent stc Y))
1468 (interval-length (ly:stencil-extent stc X)))
1470 (text-width (apply + text-widths))
1471 (word-count (length stencils))
1472 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1477 (/ (- line-width text-width) 2)
1478 (/ (- line-width text-width) 2)))
1481 (- line-width text-width)))
1484 word-count line-width word-space text-widths
1486 (line-contents (if (= word-count 1)
1493 (if (null? (remove ly:stencil-empty? orig-stencils))
1496 (if (= text-direction LEFT)
1497 (set! line-contents (reverse line-contents)))
1499 (stack-stencils-padding-list
1500 X RIGHT fill-space line-contents))
1501 (if (> word-count 1)
1502 ;; shift s.t. stencils align on the left edge, even if
1503 ;; first stencil had negative X-extent (e.g. center-column)
1504 ;; (if word-count = 1, X-extents are already normalized in
1505 ;; the definition of line-contents)
1507 (ly:stencil-translate-axis
1509 (- (car (ly:stencil-extent (car stencils) X)))
1513 (define-markup-command (fill-line layout props args)
1516 #:properties ((text-direction RIGHT)
1519 "Put @var{markups} in a horizontal line of width @var{line-width}.
1520 The markups are spaced or flushed to fill the entire line.
1521 If there are no arguments, return an empty stencil.
1523 @lilypond[verbatim,quote]
1527 Words evenly spaced across the page
1531 \\line { Text markups }
1533 \\italic { evenly spaced }
1535 \\line { across the page }
1540 (justify-line-helper
1541 layout props args text-direction word-space line-width #f))
1543 (define-markup-command (justify-line layout props args)
1546 #:properties ((text-direction RIGHT)
1549 "Put @var{markups} in a horizontal line of width @var{line-width}.
1550 The markups are spread to fill the entire line and separated by equal
1551 space. If there are no arguments, return an empty stencil.
1553 @lilypond[verbatim,quote]
1556 Space between neighboring words is constant
1560 (justify-line-helper
1561 layout props args text-direction word-space line-width #t))
1563 (define-markup-command (concat layout props args)
1567 @cindex concatenating text
1568 @cindex ligatures in text
1570 Concatenate @var{args} in a horizontal line, without spaces in between.
1571 Strings and simple markups are concatenated on the input level, allowing
1572 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1573 equivalent to @code{\"fi\"}.
1575 @lilypond[verbatim,quote]
1584 (define (concat-string-args arg-list)
1585 (fold-right (lambda (arg result-list)
1586 (let ((result (and (pair? result-list)
1587 (car result-list))))
1588 (cond ((not (pair? arg)))
1589 ((eq? (car arg) simple-markup)
1590 (set! arg (cadr arg)))
1591 ((eq? (car arg) char-markup)
1592 (set! arg (ly:wide-char->utf-8 (cadr arg)))))
1593 (if (and (string? result) (string? arg))
1594 (cons (string-append arg result) (cdr result-list))
1595 (cons arg result-list))))
1598 (stack-stencil-line 0
1599 (interpret-markup-list layout props
1600 (if (markup-command-list? args)
1602 (concat-string-args args)))))
1604 (define (wordwrap-stencils stencils
1605 justify base-space line-width text-dir)
1606 "Perform simple wordwrap, return stencil of each line."
1607 (define space (if justify
1608 ;; justify only stretches lines.
1611 (define (stencil-len s)
1612 (interval-end (ly:stencil-extent s X)))
1613 (define (maybe-shift line)
1614 (if (= text-dir LEFT)
1615 (ly:stencil-translate-axis
1617 (- line-width (stencil-len line))
1620 (if (null? stencils)
1622 (let loop ((lines '())
1625 ((line (first todo))
1627 (word-list (list (first todo))))
1630 (let ((new (if (= text-dir LEFT)
1631 (ly:stencil-stack (car todo) X RIGHT line space)
1632 (ly:stencil-stack line X RIGHT (car todo) space))))
1634 ((<= (stencil-len new) line-width)
1635 (word-loop new (cdr todo)
1636 (cons (car todo) word-list)))
1639 ;; This depends on stencil stacking being
1640 ;; associative so that stacking
1641 ;; left-to-right and right-to-left leads to
1643 (if (= text-dir LEFT)
1645 (reverse! word-list)))
1646 (len (stencil-len line))
1647 (stretch (- line-width len))
1650 (stack-stencils X RIGHT (1+ space) word-list))
1653 ;; Uh oh, nothing to fill.
1654 (loop (cons (maybe-shift line) lines) todo)
1656 (stack-stencils X RIGHT
1657 (+ space (/ stretch spaces))
1661 (else ;; not justify
1662 (loop (cons (maybe-shift line) lines) todo)))))
1665 ;; Now we have the last line assembled with space
1666 ;; which is compressed. We want to use the
1667 ;; uncompressed version instead if it fits, and the
1668 ;; justified version if it doesn't.
1670 ;; This depends on stencil stacking being
1671 ;; associative so that stacking
1672 ;; left-to-right and right-to-left leads to
1674 (if (= text-dir LEFT)
1676 (reverse! word-list)))
1677 (big-line (stack-stencils X RIGHT base-space word-list))
1678 (big-len (stencil-len big-line))
1679 (len (stencil-len line)))
1682 (if (> big-len line-width)
1683 (stack-stencils X RIGHT
1686 (* (- big-len line-width)
1688 (* (- line-width len)
1692 (maybe-shift big-line))))))
1693 (else ;; not justify
1694 (reverse! lines (list (maybe-shift line)))))))))
1697 (define-markup-list-command (wordwrap-internal layout props justify args)
1698 (boolean? markup-list?)
1699 #:properties ((line-width #f)
1701 (text-direction RIGHT))
1702 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1703 (wordwrap-stencils (interpret-markup-list layout props args)
1707 (ly:output-def-lookup layout 'line-width))
1710 (define-markup-command (justify layout props args)
1713 #:properties ((baseline-skip)
1714 wordwrap-internal-markup-list)
1716 @cindex justifying text
1718 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1719 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1720 @var{X}@tie{}is the number of staff spaces.
1722 @lilypond[verbatim,quote]
1725 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1726 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1727 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1728 laboris nisi ut aliquip ex ea commodo consequat.
1732 (stack-lines DOWN 0.0 baseline-skip
1733 (wordwrap-internal-markup-list layout props #t args)))
1735 (define-markup-command (wordwrap layout props args)
1738 #:properties ((baseline-skip)
1739 wordwrap-internal-markup-list)
1740 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1741 the line width, where @var{X} is the number of staff spaces.
1743 @lilypond[verbatim,quote]
1746 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1747 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1748 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1749 laboris nisi ut aliquip ex ea commodo consequat.
1753 (stack-lines DOWN 0.0 baseline-skip
1754 (wordwrap-internal-markup-list layout props #f args)))
1756 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1758 #:properties ((line-width)
1760 (text-direction RIGHT))
1761 "Internal markup list command used to define @code{\\justify-string} and
1762 @code{\\wordwrap-string}."
1763 (let* ((para-strings (regexp-split
1764 (string-regexp-substitute
1766 (string-regexp-substitute "\r\n" "\n" arg))
1767 "\n[ \t\n]*\n[ \t\n]*"))
1768 (list-para-words (map (lambda (str)
1769 (regexp-split str "[ \t\n]+"))
1771 (para-lines (map (lambda (words)
1774 (interpret-markup layout props x))
1776 (wordwrap-stencils stencils
1778 line-width text-direction)))
1780 (concatenate para-lines)))
1782 (define-markup-command (wordwrap-string layout props arg)
1785 #:properties ((baseline-skip)
1786 wordwrap-string-internal-markup-list)
1787 "Wordwrap a string. Paragraphs may be separated with double newlines.
1789 @lilypond[verbatim,quote]
1791 \\override #'(line-width . 40)
1792 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1793 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1794 et dolore magna aliqua.
1797 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1798 laboris nisi ut aliquip ex ea commodo consequat.
1801 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1802 qui officia deserunt mollit anim id est laborum\"
1805 (stack-lines DOWN 0.0 baseline-skip
1806 (wordwrap-string-internal-markup-list layout props #f arg)))
1808 (define-markup-command (justify-string layout props arg)
1811 #:properties ((baseline-skip)
1812 wordwrap-string-internal-markup-list)
1813 "Justify a string. Paragraphs may be separated with double newlines
1815 @lilypond[verbatim,quote]
1817 \\override #'(line-width . 40)
1818 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1819 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1820 et dolore magna aliqua.
1823 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1824 laboris nisi ut aliquip ex ea commodo consequat.
1827 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1828 qui officia deserunt mollit anim id est laborum\"
1831 (stack-lines DOWN 0.0 baseline-skip
1832 (wordwrap-string-internal-markup-list layout props #t arg)))
1834 (define-markup-command (wordwrap-field layout props symbol)
1837 "Wordwrap the data which has been assigned to @var{symbol}.
1839 @lilypond[verbatim,quote]
1841 title = \"My title\"
1842 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1843 elit, sed do eiusmod tempor incididunt ut labore et dolore
1844 magna aliqua. Ut enim ad minim veniam, quis nostrud
1845 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1850 bookTitleMarkup = \\markup {
1852 \\fill-line { \\fromproperty #'header:title }
1854 \\wordwrap-field #'header:myText
1863 (let* ((m (chain-assoc-get symbol props)))
1865 (wordwrap-string-markup layout props m)
1868 (define-markup-command (justify-field layout props symbol)
1871 "Justify the data which has been assigned to @var{symbol}.
1873 @lilypond[verbatim,quote]
1875 title = \"My title\"
1876 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1877 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1878 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1879 laboris nisi ut aliquip ex ea commodo consequat.\"
1883 bookTitleMarkup = \\markup {
1885 \\fill-line { \\fromproperty #'header:title }
1887 \\justify-field #'header:myText
1896 (let* ((m (chain-assoc-get symbol props)))
1898 (justify-string-markup layout props m)
1901 (define-markup-command (combine layout props arg1 arg2)
1905 @cindex merging text
1907 Print two markups on top of each other.
1909 Note: @code{\\combine} cannot take a list of markups enclosed in
1910 curly braces as an argument; for this purpose use @code{\\overlay} instead.
1912 @lilypond[verbatim,quote]
1915 \\override #'(thickness . 2)
1917 \\draw-line #'(0 . 4)
1918 \\arrow-head #Y #DOWN ##f
1921 (let* ((s1 (interpret-markup layout props arg1))
1922 (s2 (interpret-markup layout props arg2)))
1923 (ly:stencil-add s1 s2)))
1925 (define-markup-command (overlay layout props args)
1929 @cindex merging text
1931 Takes a list of markups combining them.
1933 @lilypond[verbatim,quote]
1936 \\override #'(thickness . 2)
1938 \\draw-line #'(0 . 4)
1939 \\arrow-head #Y #DOWN ##f
1940 \\translate #'(0 . 4)\\arrow-head #Y #UP ##f
1944 (apply ly:stencil-add (interpret-markup-list layout props args)))
1947 ;; TODO: should extract baseline-skip from each argument somehow..
1949 (define-markup-command (column layout props args)
1952 #:properties ((baseline-skip))
1954 @cindex stacking text in a column
1956 Stack the markups in @var{args} vertically. The property
1957 @code{baseline-skip} determines the space between markups
1960 @lilypond[verbatim,quote]
1969 (let ((arg-stencils (interpret-markup-list layout props args)))
1970 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1972 (define-markup-command (dir-column layout props args)
1975 #:properties ((direction)
1978 @cindex changing direction of text columns
1980 Make a column of @var{args}, going up or down, depending on the
1981 setting of the @code{direction} layout property.
1983 @lilypond[verbatim,quote]
1985 \\override #`(direction . ,UP) {
1995 \\override #'(direction . 1) {
2002 (stack-lines (if (number? direction) direction -1)
2005 (interpret-markup-list layout props args)))
2007 (define (general-column align-dir baseline mols)
2008 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
2010 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
2011 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
2012 (stacked-extent (ly:stencil-extent stacked-stencil X)))
2013 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
2015 (define-markup-command (center-column layout props args)
2018 #:properties ((baseline-skip))
2020 @cindex centering a column of text
2022 Put @code{args} in a centered column.
2024 @lilypond[verbatim,quote]
2033 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
2035 (define-markup-command (left-column layout props args)
2038 #:properties ((baseline-skip))
2040 @cindex text columns, left-aligned
2042 Put @code{args} in a left-aligned column.
2044 @lilypond[verbatim,quote]
2053 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
2055 (define-markup-command (right-column layout props args)
2058 #:properties ((baseline-skip))
2060 @cindex text columns, right-aligned
2062 Put @code{args} in a right-aligned column.
2064 @lilypond[verbatim,quote]
2073 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
2075 (define-markup-command (vcenter layout props arg)
2079 @cindex vertically centering text
2081 Align @code{arg} to its Y@tie{}center.
2083 @lilypond[verbatim,quote]
2091 (let* ((mol (interpret-markup layout props arg)))
2092 (ly:stencil-aligned-to mol Y CENTER)))
2094 (define-markup-command (center-align layout props arg)
2098 @cindex horizontally centering text
2100 Align @code{arg} to its X@tie{}center.
2102 @lilypond[verbatim,quote]
2112 (let* ((mol (interpret-markup layout props arg)))
2113 (ly:stencil-aligned-to mol X CENTER)))
2115 (define-markup-command (right-align layout props arg)
2119 @cindex right aligning text
2121 Align @var{arg} on its right edge.
2123 @lilypond[verbatim,quote]
2133 (let* ((m (interpret-markup layout props arg)))
2134 (ly:stencil-aligned-to m X RIGHT)))
2136 (define-markup-command (left-align layout props arg)
2140 @cindex left aligning text
2142 Align @var{arg} on its left edge.
2144 @lilypond[verbatim,quote]
2154 (let* ((m (interpret-markup layout props arg)))
2155 (ly:stencil-aligned-to m X LEFT)))
2157 (define-markup-command (general-align layout props axis dir arg)
2158 (integer? number? markup?)
2161 @cindex controlling general text alignment
2163 Align @var{arg} in @var{axis} direction to the @var{dir} side.
2165 @lilypond[verbatim,quote]
2169 \\general-align #X #LEFT
2174 \\general-align #X #CENTER
2180 \\general-align #Y #UP
2187 \\general-align #Y #3.2
2194 (let* ((m (interpret-markup layout props arg)))
2195 (ly:stencil-aligned-to m axis dir)))
2197 (define-markup-command (halign layout props dir arg)
2201 @cindex setting horizontal text alignment
2203 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2204 left-aligned, while @code{+1} is right. Values in between interpolate
2205 alignment accordingly.
2207 @lilypond[verbatim,quote]
2232 (let* ((m (interpret-markup layout props arg)))
2233 (ly:stencil-aligned-to m X dir)))
2235 (define-markup-command (with-dimensions layout props x y arg)
2236 (number-pair? number-pair? markup?)
2239 @cindex setting extent of text objects
2241 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2242 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2244 (make-transparent-box-stencil x y)
2246 `(delay-stencil-evaluation ,(delay expr))
2249 (define-markup-command (with-outline layout props outline arg)
2253 Print @var{arg} with the outline and dimensions of @var{outline}."
2254 (ly:stencil-outline (interpret-markup layout props arg)
2255 (interpret-markup layout props outline)))
2257 (define-markup-command (with-dimensions-from layout props arg1 arg2)
2261 Print @var{arg2} with the dimensions of @var{arg1}."
2262 (let* ((stil1 (interpret-markup layout props arg1))
2263 (x (ly:stencil-extent stil1 0))
2264 (y (ly:stencil-extent stil1 1)))
2265 (interpret-markup layout props (markup #:with-dimensions x y arg2))))
2267 (define-markup-command (pad-around layout props amount arg)
2270 "Add padding @var{amount} all around @var{arg}.
2272 @lilypond[verbatim,quote]
2285 (let* ((m (interpret-markup layout props arg))
2286 (x (interval-widen (ly:stencil-extent m X) amount))
2287 (y (interval-widen (ly:stencil-extent m Y) amount)))
2288 (ly:stencil-add (make-transparent-box-stencil x y)
2291 (define-markup-command (pad-x layout props amount arg)
2295 @cindex padding text horizontally
2297 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2299 @lilypond[verbatim,quote]
2312 (let* ((m (interpret-markup layout props arg))
2313 (x (ly:stencil-extent m X))
2314 (y (ly:stencil-extent m Y)))
2315 (ly:make-stencil (ly:stencil-expr m)
2316 (interval-widen x amount)
2319 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2320 (integer? ly:dir? markup? markup?)
2322 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2323 (let ((m1 (interpret-markup layout props arg1))
2324 (m2 (interpret-markup layout props arg2)))
2325 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2327 (define-markup-command (transparent layout props arg)
2330 "Make @var{arg} transparent.
2332 @lilypond[verbatim,quote]
2339 (ly:stencil-outline empty-stencil (interpret-markup layout props arg)))
2341 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2342 (number-pair? number-pair? markup?)
2344 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2346 @lilypond[verbatim,quote]
2353 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2359 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2360 (interpret-markup layout props arg)))
2362 (define-markup-command (hcenter-in layout props length arg)
2365 "Center @var{arg} horizontally within a box of extending
2366 @var{length}/2 to the left and right.
2368 @lilypond[quote,verbatim]
2371 \\set Staff.instrumentName = \\markup {
2378 \\set Staff.instrumentName = \\markup {
2387 (interpret-markup layout props
2388 (make-pad-to-box-markup
2389 (cons (/ length -2) (/ length 2))
2391 (make-center-align-markup arg))))
2393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2397 (define-markup-command (property-recursive layout props symbol)
2400 "Print out a warning when a header field markup contains some recursive
2402 (ly:warning "Recursive definition of property ~a detected!" symbol)
2405 (define-markup-command (fromproperty layout props symbol)
2408 "Read the @var{symbol} from property settings, and produce a stencil
2409 from the markup contained within. If @var{symbol} is not defined, it
2410 returns an empty markup.
2412 @lilypond[verbatim,quote]
2414 myTitle = \"myTitle\"
2418 \\fromproperty #'header:myTitle
2425 (let ((m (chain-assoc-get symbol props)))
2427 ;; prevent infinite loops by clearing the interpreted property:
2428 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2431 (define-markup-command (on-the-fly layout props procedure arg)
2432 (procedure? markup?)
2434 "Apply the @var{procedure} markup command to @var{arg}.
2435 @var{procedure} takes the same arguments as @code{interpret-markup}
2436 and returns a stencil."
2437 (procedure layout props arg))
2439 (define-markup-command (footnote layout props mkup note)
2442 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2444 @lilypond[verbatim,quote]
2447 \\override #'(padding . 0.2)
2451 The footnote will not be annotated automatically."
2452 (ly:stencil-combine-at-edge
2453 (interpret-markup layout props mkup)
2457 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2462 (define-markup-command (auto-footnote layout props mkup note)
2465 #:properties ((raise 0.5)
2467 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2469 @lilypond[verbatim,quote]
2472 \\override #'(padding . 0.2)
2476 The footnote will be annotated automatically."
2477 (let* ((markup-stencil (interpret-markup layout props mkup))
2478 (footnote-hash (gensym "footnote"))
2480 (gauge-stencil (interpret-markup
2483 ((ly:output-def-lookup
2485 'footnote-numbering-function)
2487 (x-ext (ly:stencil-extent gauge-stencil X))
2488 (y-ext (ly:stencil-extent gauge-stencil Y))
2490 `(delay-stencil-evaluation
2494 (ly:output-def-lookup layout
2495 'number-footnote-table))
2496 (footnote-stencil (if (list? table)
2497 (assoc-get footnote-hash
2500 (footnote-stencil (if (ly:stencil? footnote-stencil)
2503 (ly:programming-error
2504 "Cannot find correct footnote for a markup object.")
2506 (gap (- (interval-length x-ext)
2508 (ly:stencil-extent footnote-stencil X))))
2509 (y-trans (- (+ (cdr y-ext)
2511 (cdr (ly:stencil-extent footnote-stencil
2513 (ly:stencil-translate footnote-stencil
2514 (cons gap y-trans)))))))
2515 (main-stencil (ly:stencil-combine-at-edge
2519 (ly:make-stencil footnote-number x-ext y-ext)
2524 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2528 (define-markup-command (override layout props new-prop arg)
2532 @cindex overriding properties within text markup
2534 Add the argument @var{new-prop} to the property list. Properties
2535 may be any property supported by @rinternals{font-interface},
2536 @rinternals{text-interface} and
2537 @rinternals{instrument-specific-markup-interface}.
2539 @lilypond[verbatim,quote]
2547 \\override #'(baseline-skip . 4) {
2556 (interpret-markup layout (cons (list new-prop) props) arg))
2558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2560 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2562 (define-markup-command (verbatim-file layout props name)
2565 "Read the contents of file @var{name}, and include it verbatim.
2567 @lilypond[verbatim,quote]
2569 \\verbatim-file #\"simple.ly\"
2572 (interpret-markup layout props
2573 (if (ly:get-option 'safe)
2574 "verbatim-file disabled in safe mode"
2575 (let* ((str (ly:gulp-file name))
2576 (lines (string-split str #\nl)))
2577 (make-typewriter-markup
2578 (make-column-markup lines))))))
2580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2585 (define-markup-command (smaller layout props arg)
2588 "Decrease the font size relative to the current setting.
2590 @lilypond[verbatim,quote]
2603 (interpret-markup layout props
2604 `(,fontsize-markup -1 ,arg)))
2606 (define-markup-command (larger layout props arg)
2609 "Increase the font size relative to the current setting.
2611 @lilypond[verbatim,quote]
2619 (interpret-markup layout props
2620 `(,fontsize-markup 1 ,arg)))
2622 (define-markup-command (finger layout props arg)
2625 "Set @var{arg} as small numbers.
2627 @lilypond[verbatim,quote]
2634 (interpret-markup layout
2635 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2638 (define-markup-command (abs-fontsize layout props size arg)
2640 #:properties ((word-space 0.6) (baseline-skip 3))
2642 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2643 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2645 @lilypond[verbatim,quote]
2647 default text font size
2649 \\abs-fontsize #16 { text font size 16 }
2651 \\abs-fontsize #12 { text font size 12 }
2654 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2655 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2656 (magnification (/ size ref-size)))
2660 `((baseline-skip . ,(* magnification baseline-skip))
2661 (word-space . ,(* magnification word-space))
2662 (font-size . ,(magnification->font-size magnification)))
2666 (define-markup-command (fontsize layout props increment arg)
2669 #:properties ((font-size 0)
2672 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2675 @lilypond[verbatim,quote]
2686 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2687 (word-space . ,(* word-space (magstep increment)))
2688 (font-size . ,(+ font-size increment)))
2692 (define-markup-command (magnify layout props sz arg)
2696 @cindex magnifying text
2698 Set the font magnification for its argument. In the following
2699 example, the middle@tie{}A is 10% larger:
2702 A \\magnify #1.1 @{ A @} A
2705 Note: Magnification only works if a font name is explicitly selected.
2706 Use @code{\\fontsize} otherwise.
2708 @lilypond[verbatim,quote]
2719 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2722 (define-markup-command (bold layout props arg)
2725 "Switch to bold font-series.
2727 @lilypond[verbatim,quote]
2735 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2737 (define-markup-command (sans layout props arg)
2740 "Switch to the sans serif font family.
2742 @lilypond[verbatim,quote]
2751 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2753 (define-markup-command (number layout props arg)
2756 "Set font family to @code{number}, which yields the font used for
2757 time signatures and fingerings. This font contains numbers and
2758 some punctuation; it has no letters.
2760 @lilypond[verbatim,quote]
2763 0 1 2 3 4 5 6 7 8 9 . ,
2767 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2769 (define-markup-command (roman layout props arg)
2772 "Set font family to @code{roman}.
2774 @lilypond[verbatim,quote]
2780 text in roman font family
2787 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2789 (define-markup-command (huge layout props arg)
2792 "Set font size to +2.
2794 @lilypond[verbatim,quote]
2802 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2804 (define-markup-command (large layout props arg)
2807 "Set font size to +1.
2809 @lilypond[verbatim,quote]
2817 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2819 (define-markup-command (normalsize layout props arg)
2822 "Set font size to default.
2824 @lilypond[verbatim,quote]
2837 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2839 (define-markup-command (small layout props arg)
2842 "Set font size to -1.
2844 @lilypond[verbatim,quote]
2852 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2854 (define-markup-command (tiny layout props arg)
2857 "Set font size to -2.
2859 @lilypond[verbatim,quote]
2867 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2869 (define-markup-command (teeny layout props arg)
2872 "Set font size to -3.
2874 @lilypond[verbatim,quote]
2882 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2884 (define-markup-command (fontCaps layout props arg)
2887 "Set @code{font-shape} to @code{caps}
2889 Note: @code{\\fontCaps} requires the installation and selection of
2890 fonts which support the @code{caps} font shape."
2891 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2894 (define-markup-command (smallCaps layout props arg)
2897 "Emit @var{arg} as small caps.
2899 Note: @code{\\smallCaps} does not support accented characters.
2901 @lilypond[verbatim,quote]
2910 (define (char-list->markup chars lower)
2911 (let ((final-string (string-upcase (reverse-list->string chars))))
2913 (markup #:fontsize -2 final-string)
2915 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2916 (if (null? rest-chars)
2918 (reverse! (cons (char-list->markup currents current-is-lower)
2920 (let* ((ch (car rest-chars))
2921 (is-lower (char-lower-case? ch)))
2922 (if (or (and current-is-lower is-lower)
2923 (and (not current-is-lower) (not is-lower)))
2924 (make-small-caps (cdr rest-chars)
2928 (make-small-caps (cdr rest-chars)
2931 (if (null? currents)
2933 (cons (char-list->markup
2934 currents current-is-lower)
2936 (interpret-markup layout props
2938 (make-small-caps (string->list arg) (list) #f (list))
2941 (define-markup-command (caps layout props arg)
2944 "Copy of the @code{\\smallCaps} command.
2946 @lilypond[verbatim,quote]
2955 (interpret-markup layout props (make-smallCaps-markup arg)))
2957 (define-markup-command (dynamic layout props arg)
2960 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2961 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2962 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2963 done in a different font. The recommended font for this is bold and italic.
2964 @lilypond[verbatim,quote]
2972 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2974 (define-markup-command (text layout props arg)
2977 "Use a text font instead of music symbol or music alphabet font.
2979 @lilypond[verbatim,quote]
2992 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2995 (define-markup-command (italic layout props arg)
2998 "Use italic @code{font-shape} for @var{arg}.
3000 @lilypond[verbatim,quote]
3008 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
3010 (define-markup-command (typewriter layout props arg)
3013 "Use @code{font-family} typewriter for @var{arg}.
3015 @lilypond[verbatim,quote]
3024 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
3026 (define-markup-command (upright layout props arg)
3029 "Set @code{font-shape} to @code{upright}. This is the opposite
3032 @lilypond[verbatim,quote]
3046 layout (prepend-alist-chain 'font-shape 'upright props) arg))
3048 (define-markup-command (medium layout props arg)
3051 "Switch to medium font-series (in contrast to bold).
3053 @lilypond[verbatim,quote]
3066 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
3069 (define-markup-command (normal-text layout props arg)
3072 "Set all font related properties (except the size) to get the default
3073 normal text font, no matter what font was used earlier.
3075 @lilypond[verbatim,quote]
3077 \\huge \\bold \\sans \\caps {
3089 (interpret-markup layout
3090 (cons '((font-family . roman) (font-shape . upright)
3091 (font-series . medium) (font-encoding . latin1))
3095 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3097 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3099 (define-markup-command (musicglyph layout props glyph-name)
3102 "@var{glyph-name} is converted to a musical symbol; for example,
3103 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
3104 the music font. See @ruser{The Emmentaler font} for a complete listing of
3105 the possible glyphs.
3107 @lilypond[verbatim,quote]
3110 \\musicglyph #\"rests.2\"
3111 \\musicglyph #\"clefs.G_change\"
3114 (let* ((font (ly:paper-get-font layout
3115 (cons '((font-encoding . fetaMusic)
3119 (glyph (ly:font-get-glyph font glyph-name)))
3120 (if (null? (ly:stencil-expr glyph))
3121 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
3125 (define-markup-command (doublesharp layout props)
3128 "Draw a double sharp symbol.
3130 @lilypond[verbatim,quote]
3135 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
3137 (define-markup-command (sesquisharp layout props)
3140 "Draw a 3/2 sharp symbol.
3142 @lilypond[verbatim,quote]
3147 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
3149 (define-markup-command (sharp layout props)
3152 "Draw a sharp symbol.
3154 @lilypond[verbatim,quote]
3159 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
3161 (define-markup-command (semisharp layout props)
3164 "Draw a semisharp symbol.
3166 @lilypond[verbatim,quote]
3171 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
3173 (define-markup-command (natural layout props)
3176 "Draw a natural symbol.
3178 @lilypond[verbatim,quote]
3183 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
3185 (define-markup-command (semiflat layout props)
3188 "Draw a semiflat symbol.
3190 @lilypond[verbatim,quote]
3195 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
3197 (define-markup-command (flat layout props)
3200 "Draw a flat symbol.
3202 @lilypond[verbatim,quote]
3207 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
3209 (define-markup-command (sesquiflat layout props)
3212 "Draw a 3/2 flat symbol.
3214 @lilypond[verbatim,quote]
3219 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3221 (define-markup-command (doubleflat layout props)
3224 "Draw a double flat symbol.
3226 @lilypond[verbatim,quote]
3231 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3233 (define-markup-command (with-color layout props color arg)
3237 @cindex coloring text
3239 Draw @var{arg} in color specified by @var{color}.
3241 @lilypond[verbatim,quote]
3253 (let ((stil (interpret-markup layout props arg)))
3254 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3255 (ly:stencil-extent stil X)
3256 (ly:stencil-extent stil Y))))
3258 (define-markup-command (tied-lyric layout props str)
3261 #:properties ((word-space))
3263 @cindex simple text strings with tie characters
3265 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3267 @lilypond[verbatim,quote]
3269 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3270 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3271 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3274 (define (replace-ties tie str)
3275 (if (string-contains str "~")
3277 ((half-space (/ word-space 2))
3278 (parts (string-split str #\~))
3279 (tie-str (markup #:hspace half-space
3281 #:hspace half-space))
3282 (joined (list-join parts tie-str)))
3283 (make-concat-markup joined))
3286 (define short-tie-regexp (make-regexp "~[^.]~"))
3287 (define (match-short str) (regexp-exec short-tie-regexp str))
3289 (define (replace-short str mkp)
3290 (let ((match (match-short str)))
3292 (make-concat-markup (list
3294 (replace-ties "ties.lyric.default" str)))
3295 (let ((new-str (match:suffix match))
3296 (new-mkp (make-concat-markup (list
3298 (replace-ties "ties.lyric.default"
3299 (match:prefix match))
3300 (replace-ties "ties.lyric.short"
3301 (match:substring match))))))
3302 (replace-short new-str new-mkp)))))
3304 (interpret-markup layout
3306 (replace-short str (markup))))
3308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3310 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3312 (define-markup-command (arrow-head layout props axis dir filled)
3313 (integer? ly:dir? boolean?)
3315 "Produce an arrow head in specified direction and axis.
3316 Use the filled head if @var{filled} is specified.
3317 @lilypond[verbatim,quote]
3320 \\general-align #Y #DOWN {
3321 \\arrow-head #Y #UP ##t
3322 \\arrow-head #Y #DOWN ##f
3324 \\arrow-head #X #RIGHT ##f
3325 \\arrow-head #X #LEFT ##f
3331 ((name (format #f "arrowheads.~a.~a~a"
3338 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3342 (define-markup-command (lookup layout props glyph-name)
3345 "Lookup a glyph by name.
3347 @lilypond[verbatim,quote]
3349 \\override #'(font-encoding . fetaBraces) {
3350 \\lookup #\"brace200\"
3353 \\lookup #\"brace180\"
3357 (ly:font-get-glyph (ly:paper-get-font layout props)
3360 (define-markup-command (char layout props num)
3363 "Produce a single character. Characters encoded in hexadecimal
3364 format require the prefix @code{#x}.
3366 @lilypond[verbatim,quote]
3368 \\char #65 \\char ##x00a9
3371 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3373 (define number->mark-letter-vector (make-vector 25 #\A))
3378 (if (= i (- (char->integer #\I) (char->integer #\A)))
3380 (vector-set! number->mark-letter-vector j
3381 (integer->char (+ i (char->integer #\A)))))
3383 (define number->mark-alphabet-vector (list->vector
3384 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3386 (define (number->markletter-string vec n)
3387 "Double letters for big marks."
3388 (let* ((lst (vector-length vec)))
3391 (string-append (number->markletter-string vec (1- (quotient n lst)))
3392 (number->markletter-string vec (remainder n lst)))
3393 (make-string 1 (vector-ref vec n)))))
3395 (define-markup-command (markletter layout props num)
3398 "Make a markup letter for @var{num}. The letters start with A
3399 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3401 @lilypond[verbatim,quote]
3408 (ly:text-interface::interpret-markup layout props
3409 (number->markletter-string number->mark-letter-vector num)))
3411 (define-markup-command (markalphabet layout props num)
3414 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3415 and continue with double letters.
3417 @lilypond[verbatim,quote]
3424 (ly:text-interface::interpret-markup layout props
3425 (number->markletter-string number->mark-alphabet-vector num)))
3427 (define-public (horizontal-slash-interval num forward number-interval mag)
3429 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3430 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3431 (else (interval-widen number-interval (* mag 0.25))))
3432 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3433 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3434 (else (interval-widen number-interval (* mag 0.25))))
3437 (define-public (adjust-slash-stencil num forward stencil mag)
3440 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3442 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3444 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3446 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3449 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3451 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3456 (define (slashed-digit-internal layout props num forward font-size thickness)
3457 (let* ((mag (magstep font-size))
3459 (ly:output-def-lookup layout 'line-thickness)
3461 ;; backward slashes might use slope and point in the other direction!
3462 (dy (* mag (if forward 0.4 -0.4)))
3463 (number-stencil (interpret-markup layout
3464 (prepend-alist-chain 'font-encoding 'fetaText props)
3465 (number->string num)))
3466 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3467 (center (interval-center (ly:stencil-extent number-stencil Y)))
3468 ;; Use the real extents of the slash, not the whole number,
3469 ;; because we might translate the slash later on!
3470 (num-y (interval-widen (cons center center) (abs dy)))
3471 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3472 (slash-stencil (if is-sane
3473 (make-line-stencil thickness
3474 (car num-x) (- (interval-center num-y) dy)
3475 (cdr num-x) (+ (interval-center num-y) dy))
3477 (if (ly:stencil? slash-stencil)
3479 ;; for some numbers we need to shift the slash/backslash up or
3480 ;; down to make the slashed digit look better
3481 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3482 (set! number-stencil
3483 (ly:stencil-add number-stencil slash-stencil)))
3484 (ly:warning "Unable to create slashed digit ~a" num))
3488 (define-markup-command (slashed-digit layout props num)
3491 #:properties ((font-size 0)
3494 @cindex slashed digits
3496 A feta number, with slash. This is for use in the context of
3497 figured bass notation.
3498 @lilypond[verbatim,quote]
3502 \\override #'(thickness . 3)
3506 (slashed-digit-internal layout props num #t font-size thickness))
3508 (define-markup-command (backslashed-digit layout props num)
3511 #:properties ((font-size 0)
3514 @cindex backslashed digits
3516 A feta number, with backslash. This is for use in the context of
3517 figured bass notation.
3518 @lilypond[verbatim,quote]
3520 \\backslashed-digit #5
3522 \\override #'(thickness . 3)
3523 \\backslashed-digit #7
3526 (slashed-digit-internal layout props num #f font-size thickness))
3529 (define eyeglassespath
3530 '((moveto 0.42 0.77)
3531 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3532 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3533 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3534 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3537 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3538 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3539 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3540 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3542 (moveto 1.025 0.935)
3543 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3544 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3547 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3550 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3552 (define-markup-command (eyeglasses layout props)
3555 "Prints out eyeglasses, indicating strongly to look at the conductor.
3556 @lilypond[verbatim,quote]
3557 \\markup { \\eyeglasses }
3559 (interpret-markup layout props
3560 (make-override-markup '(line-cap-style . butt)
3561 (make-path-markup 0.15 eyeglassespath))))
3563 (define-markup-command (left-brace layout props size)
3567 A feta brace in point size @var{size}.
3569 @lilypond[verbatim,quote]
3576 (let* ((font (ly:paper-get-font layout
3577 (cons '((font-encoding . fetaBraces)
3580 (glyph-count (1- (ly:otf-glyph-count font)))
3581 (scale (ly:output-def-lookup layout 'output-scale))
3582 (scaled-size (/ (ly:pt size) scale))
3584 (ly:font-get-glyph font (string-append "brace"
3585 (number->string n)))))
3586 (get-y-from-brace (lambda (brace)
3588 (ly:stencil-extent (glyph brace) Y))))
3589 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3590 (glyph-found (glyph find-brace)))
3592 (if (or (null? (ly:stencil-expr glyph-found))
3593 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3594 (> scaled-size (interval-length
3595 (ly:stencil-extent (glyph glyph-count) Y))))
3597 (ly:warning (_ "no brace found for point size ~S ") size)
3598 (ly:warning (_ "defaulting to ~S pt")
3599 (/ (* scale (interval-length
3600 (ly:stencil-extent glyph-found Y)))
3604 (define-markup-command (right-brace layout props size)
3608 A feta brace in point size @var{size}, rotated 180 degrees.
3610 @lilypond[verbatim,quote]
3617 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3620 ;; the note command.
3621 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3623 ;; TODO: better syntax.
3625 (define-markup-command (note-by-number layout props log dot-count dir)
3626 (number? number? number?)
3628 #:properties ((font-size 0)
3632 @cindex notes within text by log and dot-count
3634 Construct a note symbol, with stem and flag. By using fractional values for
3635 @var{dir}, longer or shorter stems can be obtained.
3636 Supports all note-head-styles. Ancient note-head-styles will get
3637 mensural-style-flags. @code{flag-style} may be overridden independently.
3638 Supported flag-styles are @code{default}, @code{old-straight-flag},
3639 @code{modern-straight-flag}, @code{flat-flag}, @code{mensural} and
3640 @code{neomensural}. The latter two flag-styles will both result in
3641 mensural-flags. Both are supplied for convenience.
3643 @lilypond[verbatim,quote]
3645 \\note-by-number #3 #0 #DOWN
3647 \\note-by-number #1 #2 #0.8
3650 (define (get-glyph-name-candidates dir log style)
3651 (map (lambda (dir-name)
3652 (format #f "noteheads.~a~a"
3654 (if (and (symbol? style)
3655 (not (equal? 'default style)))
3656 (select-head-glyph style (min log 2))
3658 (list (if (= dir UP) "u" "d")
3661 (define (get-glyph-name font cands)
3664 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3665 (get-glyph-name font (cdr cands))
3668 (define (buildflags flag-stencil remain curr-stencil spacing)
3669 ;; Function to recursively create a stencil with @code{remain} flags
3670 ;; from the single-flag stencil @code{curr-stencil}, which is already
3671 ;; translated to the position of the previous flag position.
3673 ;; Copy and paste from /scm/flag-styles.scm
3675 (let* ((translated-stencil
3676 (ly:stencil-translate-axis curr-stencil spacing Y))
3677 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3678 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3681 (define (straight-flag-mrkp flag-thickness flag-spacing
3682 upflag-angle upflag-length
3683 downflag-angle downflag-length
3685 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3686 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3687 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3688 ;; @var{downflag-length} are given in staff spaces.
3690 ;; All lengths are scaled according to the font size of the note.
3692 ;; From /scm/flag-styles.scm, modified to fit here.
3694 (let* ((stem-up (> dir 0))
3695 ;; scale with the note size
3696 (factor (magstep font-size))
3697 (stem-thickness (* factor 0.1))
3698 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3699 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3700 (raw-length (if stem-up upflag-length downflag-length))
3701 (angle (if stem-up upflag-angle downflag-angle))
3702 (flag-length (+ (* raw-length factor) half-stem-thickness))
3703 (flag-end (polar->rectangular flag-length angle))
3704 (thickness (* flag-thickness factor))
3705 (thickness-offset (cons 0 (* -1 thickness dir)))
3706 (spacing (* -1 flag-spacing factor dir))
3707 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3712 (offset-add flag-end thickness-offset)
3714 (points (map (lambda (coord) (offset-add coord start)) raw-points))
3715 (stencil (ly:round-filled-polygon points half-stem-thickness))
3716 ;; Log for 1/8 is 3, so we need to subtract 3
3717 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3720 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)
3723 ;; default for text-font-size is 11
3724 ;; hence we use (/ text-font-size 11) later, to ensure proper scaling
3725 ;; of stem-length and thickness
3726 (text-font-size (ly:output-def-lookup layout 'text-font-size 11))
3727 (size-factor (magstep font-size))
3728 (blot (ly:output-def-lookup layout 'blot-diameter))
3730 (let ((result (get-glyph-name font
3731 (get-glyph-name-candidates
3732 (sign dir) log style))))
3733 (if (string-null? result)
3734 ;; If no glyph name can be found, select default heads.
3735 ;; Though this usually means an unsupported style has been
3736 ;; chosen, it also prevents unrelated 'style settings from
3737 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3739 (get-glyph-name font
3740 (get-glyph-name-candidates
3741 (sign dir) log 'default))
3743 (head-glyph (ly:font-get-glyph font head-glyph-name))
3746 '(mensural neomensural petrucci semipetrucci blackpetrucci)))
3747 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3748 (stem-length (* size-factor (max 3 (- log 1))))
3749 ;; With ancient-flags we want a tighter stem
3751 (* size-factor (/ text-font-size 11) (if ancient-flags? 0.1 0.13)))
3752 (stemy (* dir (/ text-font-size 11) stem-length))
3753 (attach-off (cons (interval-index
3754 (ly:stencil-extent head-glyph X)
3755 (* (sign dir) (car attach-indices)))
3756 ;; fixme, this is inconsistent between X & Y.
3759 (ly:stencil-extent head-glyph Y)
3760 (cdr attach-indices)))))
3761 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3764 (if (or ancient-flags?
3765 (member flag-style '(mensural neomensural)))
3766 (* 0.5 dir stem-thickness) 0))
3767 (stem-glyph (and (> log 0)
3768 (ly:round-filled-box
3769 (ordered-cons (+ stem-X-corr (car attach-off))
3770 (+ stem-X-corr (car attach-off)
3771 (* (- (sign dir)) stem-thickness)))
3772 (cons (min stemy (cdr attach-off))
3773 (max stemy (cdr attach-off)))
3774 (/ stem-thickness 3))))
3775 (dot (ly:font-get-glyph font "dots.dot"))
3776 (dotwid (interval-length (ly:stencil-extent dot X)))
3777 (dots (and (> dot-count 0)
3778 (apply ly:stencil-add
3780 (ly:stencil-translate-axis
3781 dot (* 2 x dotwid) X))
3782 (iota dot-count)))))
3783 ;; Straight-flags. Values taken from /scm/flag-style.scm
3784 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3785 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3786 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3787 ;; Calculate a corrective to avoid a gap between
3788 ;; straight-flags and the stem.
3789 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3790 (eq? flag-style 'old-straight-flag)
3791 (eq? flag-style 'flat-flag))
3792 (/ blot 10 (* -1 dir))
3794 (flaggl (and (> log 2)
3795 (ly:stencil-translate
3796 (cond ((eq? flag-style 'modern-straight-flag)
3797 modern-straight-flag)
3798 ((eq? flag-style 'old-straight-flag)
3800 ((eq? flag-style 'flat-flag)
3803 (ly:font-get-glyph font
3805 (if (or (member flag-style
3806 '(mensural neomensural))
3808 (null? flag-style)))
3809 "flags.mensural~a2~a"
3811 (if (> dir 0) "u" "d")
3813 (cons (+ (car attach-off)
3814 ;; For tighter stems (with ancient-flags) the
3815 ;; flag has to be adjusted different.
3816 (if (and (not ancient-flags?) (< dir 0))
3819 (+ stemy flag-style-Y-corr))))))
3820 ;; If there is a flag on an upstem and the stem is short, move the dots
3821 ;; to avoid the flag. 16th notes get a special case because their flags
3822 ;; hang lower than any other flags.
3823 ;; Not with ancient flags or straight-flags.
3824 (if (and dots (> dir 0) (> log 2)
3825 (or (eq? flag-style 'default) (null? flag-style))
3826 (not ancient-flags?)
3827 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3828 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3830 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3831 (if (ly:stencil? stem-glyph)
3832 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3833 (set! stem-glyph head-glyph))
3834 (if (ly:stencil? dots)
3837 (ly:stencil-translate-axis
3839 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3845 (let ((divisor (log 2)))
3846 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3848 (define (parse-simple-duration duration-string)
3849 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3850 and return a (log dots) list."
3851 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3853 (if (and match (string=? duration-string (match:substring match 0)))
3854 (let ((len (match:substring match 1))
3855 (dots (match:substring match 2)))
3856 (list (cond ((string=? len "breve") -1)
3857 ((string=? len "longa") -2)
3858 ((string=? len "maxima") -3)
3859 (else (log2 (string->number len))))
3860 (if dots (string-length dots) 0)))
3861 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3863 (define-markup-command (note layout props duration dir)
3866 #:properties (note-by-number-markup)
3868 @cindex notes within text by string
3870 This produces a note with a stem pointing in @var{dir} direction, with
3871 the @var{duration} for the note head type and augmentation dots. For
3872 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3873 a shortened down stem.
3875 @lilypond[verbatim,quote]
3877 \\override #'(style . cross) {
3881 \\note #\"breve\" #0
3884 (let ((parsed (parse-simple-duration duration)))
3885 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3888 ;; the rest command.
3889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3891 (define-markup-command (rest-by-number layout props log dot-count)
3894 #:properties ((font-size 0)
3896 (multi-measure-rest #f))
3898 @cindex rests or multi-measure-rests within text by log and dot-count
3900 A rest or multi-measure-rest symbol.
3902 @lilypond[verbatim,quote]
3904 \\rest-by-number #3 #2
3906 \\rest-by-number #0 #1
3908 \\override #'(multi-measure-rest . #t)
3909 \\rest-by-number #0 #0
3913 (define (get-glyph-name-candidates log style)
3914 (let* (;; Choose the style-string to be added.
3915 ;; If no glyph exists, select others for the specified styles
3916 ;; otherwise defaulting.
3919 ;; 'baroque needs to be special-cased, otherwise
3920 ;; `select-head-glyphĀ“ would catch neomensural-glyphs for
3921 ;; this style, if (< log 0).
3922 (eq? style 'baroque)
3923 (string-append (number->string log) ""))
3924 ((eq? style 'petrucci)
3925 (string-append (number->string log) "mensural"))
3926 ;; In other cases `select-head-glyphĀ“ from output-lib.scm
3927 ;; works for rest-glyphs, too.
3928 ((and (symbol? style) (not (eq? style 'default)))
3929 (select-head-glyph style log))
3931 ;; Choose ledgered glyphs for whole and half rest.
3932 ;; Except for the specified styles, logs and MultiMeasureRests.
3934 (if (and (or (list? style)
3936 '(neomensural mensural petrucci))))
3937 (not multi-measure-rest)
3938 (or (= log 0) (= log 1)))
3941 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3943 (define (get-glyph-name font cands)
3944 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3949 (ly:paper-get-font layout
3950 (cons '((font-encoding . fetaMusic)
3955 (get-glyph-name font
3956 (get-glyph-name-candidates log style))))
3957 (if (string-null? result)
3958 ;; If no glyph name can be found, select default rests. Though
3959 ;; this usually means an unsupported style has been chosen, it
3960 ;; also prevents unrelated 'style settings from other grobs
3961 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3962 (get-glyph-name font (get-glyph-name-candidates log 'default))
3964 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3965 (dot (ly:font-get-glyph font "dots.dot"))
3966 (dot-width (interval-length (ly:stencil-extent dot X)))
3967 (dots (and (> dot-count 0)
3968 (apply ly:stencil-add
3970 (ly:stencil-translate-axis
3971 dot (* 2 x dot-width) X))
3972 (iota dot-count))))))
3974 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3975 ;; glyphs are taken for whole and half rests.
3976 ;; If they are dotted, move the dots in X-direction to avoid collision.
3980 (not (member style '(neomensural mensural petrucci))))
3981 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3983 ;; Add dots to the rest-glyph.
3985 ;; Not sure how to vertical align dots.
3986 ;; For now the dots are centered for half, whole or longer rests.
3987 ;; Otherwise placed near the top of the rest.
3989 ;; Dots for rests with (< log 0) dots are allowed, but not
3990 ;; if multi-measure-rest is set #t.
3991 (if (and (not multi-measure-rest) dots)
3994 (ly:stencil-translate
3997 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3999 (interval-center (ly:stencil-extent rest-glyph Y))
4000 (- (interval-end (ly:stencil-extent rest-glyph Y))
4001 (/ (* 2 dot-width) 3)))))
4005 (define-markup-command (rest layout props duration)
4008 #:properties ((style '())
4009 (multi-measure-rest #f)
4010 (multi-measure-rest-number #t)
4013 @cindex rests or multi-measure-rests within text by string
4015 This produces a rest, with the @var{duration} for the rest type and
4017 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
4020 Printing MultiMeasureRests could be enabled with
4021 @code{\\override #'(multi-measure-rest . #t)}
4022 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
4023 This is enabled for all styles using default-glyphs.
4024 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
4026 @lilypond[verbatim,quote]
4032 \\override #'(multi-measure-rest . #t)
4036 \\override #'(multi-measure-rest-number . #f)
4041 ;; Get the number of mmr-glyphs.
4042 ;; Store them in a list.
4043 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
4044 (define (mmr-numbers nmbr)
4045 (let* ((8-bar-glyph (floor (/ nmbr 8)))
4046 (8-remainder (remainder nmbr 8))
4047 (4-bar-glyph (floor (/ 8-remainder 4)))
4048 (4-remainder (remainder nmbr 4))
4049 (2-bar-glyph (floor (/ 4-remainder 2)))
4050 (2-remainder (remainder 4-remainder 2))
4051 (1-bar-glyph (floor (/ 2-remainder 1))))
4052 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
4054 ;; Get the correct mmr-glyphs.
4055 ;; Store them in a list.
4057 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
4058 ;; -> ("rests.M3" "rests.M1")
4059 (define (get-mmr-glyphs lst1 lst2)
4060 (define (helper l1 l2 l3)
4065 (append (make-list (car l1) (car l2)) l3))))
4066 (helper lst1 lst2 '()))
4068 ;; If duration is not valid, print a warning and return empty-stencil
4069 (if (or (and (not (integer? (car (parse-simple-duration duration))))
4070 (not multi-measure-rest))
4071 (and (= (string-length (car (string-split duration #\. ))) 1)
4072 (= (string->number (car (string-split duration #\. ))) 0)))
4074 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
4077 ;; For simple rests:
4078 ;; Get a (log dots) list.
4079 (parsed (parse-simple-duration duration))
4080 ;; Create the rest-stencil
4082 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
4083 ;; For MultiMeasureRests:
4084 ;; Get the duration-part of duration
4085 (dur-part-string (car (string-split duration #\. )))
4086 ;; Get the duration of MMR:
4087 ;; If not a number (eg. "maxima") calculate it.
4089 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
4090 ;; Get a list of the correct number of each mmr-glyph.
4091 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
4092 ;; Create a list of mmr-stencils,
4093 ;; translating the glyph for a whole rest.
4097 (let ((single-mmr-stil
4098 (rest-by-number-markup layout props (* -1 x) 0)))
4100 (ly:stencil-translate-axis
4102 ;; Ugh, hard-coded, why 1?
4106 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
4107 ;; Adjust the space between the mmr-glyphs,
4108 ;; if not default-glyphs are used.
4109 (word-space (if (member style
4110 '(neomensural mensural petrucci))
4111 (/ (* word-space 2) 3)
4113 ;; Create the final mmr-stencil
4114 ;; via `stack-stencil-lineĀ“ from /scm/markup.scm
4115 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
4117 ;; Print the number above a multi-measure-rest
4118 ;; Depends on duration, style and multi-measure-rest-number set #t
4119 (if (and multi-measure-rest
4120 multi-measure-rest-number
4122 (not (member style '(neomensural mensural petrucci))))
4123 (let* ((mmr-stil-x-center
4124 (interval-center (ly:stencil-extent mmr-stil X)))
4128 #:override '(font-encoding . fetaText)
4129 (number->string mmr-duration)))
4131 (interpret-markup layout props duration-markup))
4132 (mmr-number-stil-x-center
4133 (interval-center (ly:stencil-extent mmr-number-stil X))))
4135 (set! mmr-stil (ly:stencil-combine-at-edge
4138 (ly:stencil-translate-axis
4140 (- mmr-stil-x-center mmr-number-stil-x-center)
4144 (if multi-measure-rest
4148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4152 (define-markup-command (fermata layout props) ()
4154 #:properties ((direction UP))
4155 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
4156 an inverted glyph. Note that within music, one would usually use the
4157 @code{\\fermata} articulation instead of a markup.
4159 @lilypond[verbatim,quote]
4160 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
4162 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
4165 (interpret-markup layout props
4166 (if (eqv? direction DOWN)
4167 (markup #:musicglyph "scripts.dfermata")
4168 (markup #:musicglyph "scripts.ufermata"))))
4170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4174 (define-markup-command (lower layout props amount arg)
4178 @cindex lowering text
4180 Lower @var{arg} by the distance @var{amount}.
4181 A negative @var{amount} indicates raising; see also @code{\\raise}.
4183 @lilypond[verbatim,quote]
4191 (ly:stencil-translate-axis (interpret-markup layout props arg)
4194 (define-markup-command (translate-scaled layout props offset arg)
4195 (number-pair? markup?)
4197 #:properties ((font-size 0))
4199 @cindex translating text
4200 @cindex scaling text
4202 Translate @var{arg} by @var{offset}, scaling the offset by the
4205 @lilypond[verbatim,quote]
4208 * \\translate #'(2 . 3) translate
4210 * \\translate-scaled #'(2 . 3) translate-scaled
4214 (let* ((factor (magstep font-size))
4215 (scaled (cons (* factor (car offset))
4216 (* factor (cdr offset)))))
4217 (ly:stencil-translate (interpret-markup layout props arg)
4220 (define-markup-command (raise layout props amount arg)
4224 @cindex raising text
4226 Raise @var{arg} by the distance @var{amount}.
4227 A negative @var{amount} indicates lowering, see also @code{\\lower}.
4229 The argument to @code{\\raise} is the vertical displacement amount,
4230 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
4231 raise objects in relation to their surrounding markups.
4233 If the text object itself is positioned above or below the staff, then
4234 @code{\\raise} cannot be used to move it, since the mechanism that
4235 positions it next to the staff cancels any shift made with
4236 @code{\\raise}. For vertical positioning, use the @code{padding}
4237 and/or @code{extra-offset} properties.
4239 @lilypond[verbatim,quote]
4248 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4250 (define-markup-command (fraction layout props arg1 arg2)
4253 #:properties ((font-size 0))
4255 @cindex creating text fractions
4257 Make a fraction of two markups.
4258 @lilypond[verbatim,quote]
4264 (let* ((m1 (interpret-markup layout props arg1))
4265 (m2 (interpret-markup layout props arg2))
4266 (factor (magstep font-size))
4267 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4268 (padding (* factor 0.2))
4269 (baseline (* factor 0.6))
4270 (offset (* factor 0.75)))
4271 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4272 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4273 (let* ((x1 (ly:stencil-extent m1 X))
4274 (x2 (ly:stencil-extent m2 X))
4275 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4276 ;; should stack mols separately, to maintain LINE on baseline
4277 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4279 (ly:stencil-aligned-to stack Y CENTER))
4281 (ly:stencil-aligned-to stack X LEFT))
4282 ;; should have EX dimension
4284 (ly:stencil-translate-axis stack offset Y))))
4286 (define-markup-command (normal-size-super layout props arg)
4289 #:properties ((font-size 0))
4291 @cindex setting superscript in standard font size
4293 Set @var{arg} in superscript with a normal font size.
4295 @lilypond[verbatim,quote]
4298 \\normal-size-super {
4299 superscript in standard size
4303 (ly:stencil-translate-axis
4304 (interpret-markup layout props arg)
4305 (* 1.0 (magstep font-size)) Y))
4307 (define-markup-command (super layout props arg)
4310 #:properties ((font-size 0))
4312 @cindex superscript text
4314 Set @var{arg} in superscript.
4316 @lilypond[verbatim,quote]
4326 (ly:stencil-translate-axis
4329 (cons `((font-size . ,(- font-size 3))) props)
4331 (* 1.0 (magstep font-size)) ; original font-size
4334 (define-markup-command (translate layout props offset arg)
4335 (number-pair? markup?)
4338 @cindex translating text
4340 Translate @var{arg} relative to its surroundings. @var{offset}
4341 is a pair of numbers representing the displacement in the X and Y axis.
4343 @lilypond[verbatim,quote]
4346 \\translate #'(2 . 3)
4347 \\line { translated two spaces right, three up }
4350 (ly:stencil-translate (interpret-markup layout props arg)
4353 (define-markup-command (sub layout props arg)
4356 #:properties ((font-size 0))
4358 @cindex subscript text
4360 Set @var{arg} in subscript.
4362 @lilypond[verbatim,quote]
4373 (ly:stencil-translate-axis
4376 (cons `((font-size . ,(- font-size 3))) props)
4378 (* -0.75 (magstep font-size)) ; original font-size
4381 (define-markup-command (normal-size-sub layout props arg)
4384 #:properties ((font-size 0))
4386 @cindex setting subscript in standard font size
4388 Set @var{arg} in subscript with a normal font size.
4390 @lilypond[verbatim,quote]
4394 subscript in standard size
4398 (ly:stencil-translate-axis
4399 (interpret-markup layout props arg)
4400 (* -0.75 (magstep font-size))
4403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4407 (define-markup-command (hbracket layout props arg)
4411 @cindex placing horizontal brackets around text
4413 Draw horizontal brackets around @var{arg}.
4415 @lilypond[verbatim,quote]
4424 (let ((th 0.1) ;; todo: take from GROB.
4425 (m (interpret-markup layout props arg)))
4426 (bracketify-stencil m X th (* 2.5 th) th)))
4428 (define-markup-command (bracket layout props arg)
4432 @cindex placing vertical brackets around text
4434 Draw vertical brackets around @var{arg}.
4436 @lilypond[verbatim,quote]
4443 (let ((th 0.1) ;; todo: take from GROB.
4444 (m (interpret-markup layout props arg)))
4445 (bracketify-stencil m Y th (* 2.5 th) th)))
4447 (define-markup-command (parenthesize layout props arg)
4450 #:properties ((angularity 0)
4454 (line-thickness 0.1)
4457 @cindex placing parentheses around text
4459 Draw parentheses around @var{arg}. This is useful for parenthesizing
4460 a column containing several lines of text.
4462 @lilypond[verbatim,quote]
4471 \\override #'(angularity . 2) {
4482 (let* ((m (interpret-markup layout props arg))
4483 (scaled-width (* size width))
4485 (* line-thickness thickness))
4487 (min (* size 0.5 scaled-thickness)
4488 (* (/ 4 3.0) scaled-width)))
4489 (padding (or padding half-thickness)))
4490 (parenthesize-stencil
4491 m half-thickness scaled-width angularity padding)))
4494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4495 ;; Delayed markup evaluation
4496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4498 (define-markup-command (page-ref layout props label gauge default)
4499 (symbol? markup? markup?)
4502 @cindex referencing page numbers in text
4504 Reference to a page number. @var{label} is the label set on the referenced
4505 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4506 the maximum width of the page number, and @var{default} the value to display
4507 when @var{label} is not found.
4509 (If the current book or bookpart is set to use roman numerals for page numbers,
4510 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4511 width may require additional tweaking.)"
4512 (let* ((gauge-stencil (interpret-markup layout props gauge))
4513 (x-ext (ly:stencil-extent gauge-stencil X))
4514 (y-ext (ly:stencil-extent gauge-stencil Y)))
4516 (make-transparent-box-stencil x-ext y-ext))
4518 `(delay-stencil-evaluation
4519 ,(delay (ly:stencil-expr
4520 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4521 (page-number (if (list? table)
4522 (assoc-get label table)
4524 (number-type (ly:output-def-lookup layout 'page-number-type))
4525 (page-markup (if page-number
4526 (number-format number-type page-number)
4528 (page-stencil (interpret-markup layout props page-markup))
4529 (gap (- (interval-length x-ext)
4530 (interval-length (ly:stencil-extent page-stencil X)))))
4531 (interpret-markup layout props
4532 (markup #:hspace gap page-markup))))))
4536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4540 (define-markup-command (scale layout props factor-pair arg)
4541 (number-pair? markup?)
4544 @cindex scaling markup
4545 @cindex mirroring markup
4547 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4548 representing the scaling-factor in the X and Y axes.
4549 Negative values may be used to produce mirror images.
4551 @lilypond[verbatim,quote]
4561 (let ((stil (interpret-markup layout props arg))
4562 (sx (car factor-pair))
4563 (sy (cdr factor-pair)))
4564 (ly:stencil-scale stil sx sy)))
4566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4570 (define-markup-command (pattern layout props count axis space pattern)
4571 (integer? integer? number? markup?)
4574 Prints @var{count} times a @var{pattern} markup.
4575 Patterns are spaced apart by @var{space}.
4576 Patterns are distributed on @var{axis}.
4578 @lilypond[verbatim, quote]
4580 \"Horizontally repeated :\"
4581 \\pattern #7 #X #2 \\flat
4583 \"Vertically repeated :\"
4584 \\pattern #3 #Y #0.5 \\flat
4587 (let ((pattern-width (interval-length
4588 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4589 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4590 (let loop ((i (1- count)) (patterns (markup)))
4596 (markup patterns pattern)
4597 (markup #:column (patterns pattern))))
4600 (markup patterns pattern #:hspace space)
4601 (markup #:column (patterns pattern #:vspace space))))))))
4603 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4604 (number? ly:dir? markup? markup? markup?)
4606 #:properties ((word-space)
4609 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4610 with a line of markups @var{pattern} in between.
4611 Patterns are spaced apart by @var{space}.
4612 Patterns are aligned to the @var{dir} markup.
4614 @lilypond[verbatim, quote]
4617 \\fill-with-pattern #1 #RIGHT . first right
4618 \\fill-with-pattern #1 #RIGHT . second right
4620 \"center-aligned :\"
4621 \\fill-with-pattern #1.5 #CENTER - left right
4624 \\override #'(line-width . 50)
4625 \\fill-with-pattern #2 #LEFT : left first
4626 \\override #'(line-width . 50)
4627 \\fill-with-pattern #2 #LEFT : left second
4630 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4631 (pattern-width (interval-length pattern-x-extent))
4632 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4633 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4634 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4635 (period (+ space pattern-width))
4636 (count (truncate (/ (- middle-width pattern-width) period)))
4637 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4638 (interpret-markup layout props
4640 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4641 #:translate (cons x-offset 0)
4642 #:pattern (1+ count) X space pattern
4645 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4649 (define-markup-command (replace layout props replacements arg)
4653 Used to automatically replace a string by another in the markup @var{arg}.
4654 Each pair of the alist @var{replacements} specifies what should be replaced.
4655 The @code{key} is the string to be replaced by the @code{value} string.
4657 @lilypond[verbatim, quote]
4658 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4662 (internal-add-text-replacements
4667 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4668 ;; Markup list commands
4669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4671 (define-public (space-lines baseline stils)
4672 (let space-stil ((stils stils)
4676 (let* ((stil (car stils))
4677 (dy-top (max (- (/ baseline 1.5)
4678 (interval-bound (ly:stencil-extent stil Y) UP))
4680 (dy-bottom (max (+ (/ baseline 3.0)
4681 (interval-bound (ly:stencil-extent stil Y) DOWN))
4683 (new-stil (ly:make-stencil
4684 (ly:stencil-expr stil)
4685 (ly:stencil-extent stil X)
4686 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4688 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4690 (space-stil (cdr stils) (cons new-stil result))))))
4692 (define-markup-list-command (justified-lines layout props args)
4694 #:properties ((baseline-skip)
4695 wordwrap-internal-markup-list)
4697 @cindex justifying lines of text
4699 Like @code{\\justify}, but return a list of lines instead of a single markup.
4700 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4701 @var{X}@tie{}is the number of staff spaces."
4702 (space-lines baseline-skip
4703 (interpret-markup-list layout props
4704 (make-wordwrap-internal-markup-list #t args))))
4706 (define-markup-list-command (wordwrap-lines layout props args)
4708 #:properties ((baseline-skip)
4709 wordwrap-internal-markup-list)
4710 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4711 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4712 where @var{X} is the number of staff spaces."
4713 (space-lines baseline-skip
4714 (interpret-markup-list layout props
4715 (make-wordwrap-internal-markup-list #f args))))
4717 (define-markup-list-command (column-lines layout props args)
4719 #:properties ((baseline-skip))
4720 "Like @code{\\column}, but return a list of lines instead of a single markup.
4721 @code{baseline-skip} determines the space between each markup in @var{args}."
4722 (space-lines baseline-skip
4723 (interpret-markup-list layout props args)))
4725 (define-markup-list-command (override-lines layout props new-prop args)
4726 (pair? markup-list?)
4727 "Like @code{\\override}, for markup lists."
4728 (interpret-markup-list layout (cons (list new-prop) props) args))
4730 (define-markup-list-command (table layout props column-align lst)
4731 (number-list? markup-list?)
4732 #:properties ((padding 0)
4734 "@cindex creating a table.
4738 @var{column-align} specifies how each column is aligned, possible values are
4739 -1, 0, 1. The number of elements in @var{column-align} determines how many
4740 columns will be printed.
4741 The entries to print are given by @var{lst}, a markup-list. If needed, the last
4742 row is filled up with @code{point-stencil}s.
4743 Overriding @code{padding} may be used to increase columns horizontal distance.
4744 Overriding @code{baseline-skip} to increase rows vertical distance.
4745 @lilypond[verbatim,quote]
4747 \\override #'(padding . 2)
4751 \\underline { center-aligned right-aligned center-aligned left-aligned }
4752 one \\number 1 thousandth \\number 0.001
4753 eleven \\number 11 hundredth \\number 0.01
4754 twenty \\number 20 tenth \\number 0.1
4755 thousand \\number 1000 one \\number 1.0
4761 (define (split-lst initial-lst lngth result-lst)
4762 ;; split a list into a list of sublists of length lngth
4763 ;; eg. (split-lst '(1 2 3 4 5 6) 2 '())
4764 ;; -> ((1 2) (3 4) (5 6))
4765 (cond ((not (integer? (/ (length initial-lst) lngth)))
4767 "Can't split list of length ~a into ~a parts, returning empty list"
4768 (length initial-lst) lngth)
4770 ((null? initial-lst)
4771 (reverse result-lst))
4774 (drop initial-lst lngth)
4776 (cons (take initial-lst lngth) result-lst)))))
4778 (define (dists-list init padding lst)
4779 ;; Returns a list, where each element of `lst' is
4780 ;; added to the sum of the previous elements of `lst' plus padding.
4781 ;; `init' will be the first element of the resulting list. The addition
4782 ;; starts with the values of `init', `padding' and `(car lst)'.
4783 ;; eg. (dists-list 0.01 0.1 '(1 2 3 4)))
4784 ;; -> (0.01 1.11 3.21 6.31 10.41)
4785 (if (or (not (number? init))
4786 (not (number? padding))
4787 (not (number-list? lst)))
4790 "not fitting argument for `dists-list', return empty lst ")
4793 (fold (lambda (elem rl) (cons (+ elem padding (car rl)) rl))
4797 (let* (;; get the number of columns
4798 (columns (length column-align))
4799 (init-stils (interpret-markup-list layout props lst))
4800 ;; If the given markup-list is the result of a markup-list call, their
4801 ;; length may not be easily predictable, thus we add point-stencils
4802 ;; to fill last row of the table.
4803 (rem (remainder (length init-stils) columns))
4807 (append init-stils (make-list (- columns rem) point-stencil))))
4808 ;; get the stencils in sublists of length `columns'
4810 (split-lst filled-stils columns '()))
4811 ;; procedure to return stencil-length
4812 ;; If it is nan, return 0
4815 (let ((lngth (interval-length (ly:stencil-extent m X))))
4816 (if (nan? lngth) 0 lngth))))
4817 ;; get the max width of each column in a list
4818 (columns-max-x-lengths
4824 (map (lambda (l) (list-ref l x)) stils))))
4826 ;; create a list of (basic) distances, which each column should
4827 ;; moved, using `dists-list'. Some padding may be added.
4829 (dists-list 0 padding columns-max-x-lengths))
4830 ;; Get all stencils of a row, moved accurately to build columns.
4831 ;; If the items of a column are aligned other than left, we need to
4832 ;; move them to avoid collisions:
4833 ;; center aligned: move all items half the width of the widest item
4834 ;; right aligned: move all items the full width of the widest item.
4835 ;; Added to the default-offset calculated in `dist-sequence'.
4836 ;; `stencils-for-row-proc' needs four arguments:
4838 ;; dist - a numerical value as basic offset in X direction
4839 ;; column - a numerical value for the column we're in
4840 ;; x-align - a numerical value how current column should be
4841 ;; aligned, where (-1, 0, 1) means (LEFT, CENTER, RIGHT)
4842 (stencils-for-row-proc
4843 (lambda (stil dist column x-align)
4844 (ly:stencil-translate-axis
4845 (ly:stencil-aligned-to stil X x-align)
4846 (cond ((member x-align '(0 1))
4847 (let* (;; get the stuff for relevant column
4850 (lambda (s) (list-ref s column))
4852 ;; get length of every column-item
4854 (map lengths-proc stuff-for-column))
4856 (apply max 0 lengths-for-column)))
4857 (+ dist (/ widest (if (= x-align 0) 2 1)))))
4860 ;; get a list of rows using `ly:stencil-add' on a list of stencils
4864 (apply ly:stencil-add
4866 ;; the procedure creating the stencils:
4867 stencils-for-row-proc
4868 ;; the procedure's args:
4874 (space-lines baseline-skip rows)))
4876 (define-markup-list-command (map-markup-commands layout props compose args)
4877 (procedure? markup-list?)
4878 "This applies the function @var{compose} to every markup in
4879 @var{args} (including elements of markup list command calls) in order
4880 to produce a new markup list. Since the return value from a markup
4881 list command call is not a markup list but rather a list of stencils,
4882 this requires passing those stencils off as the results of individual
4883 markup calls. That way, the results should work out as long as no
4884 markups rely on side effects."
4885 (let ((key (make-symbol "key")))
4889 ;; if `compose' does not actually interpret its markup
4890 ;; argument, we still need to return a list of stencils,
4891 ;; created from the single returned stencil
4893 (interpret-markup layout props
4895 (make-on-the-fly-markup
4896 (lambda (layout props m)
4897 ;; here all effects of `compose' on the
4898 ;; properties should be visible, so we
4899 ;; call interpret-markup-list at this
4900 ;; point of time and harvest its
4903 (interpret-markup-list
4904 layout props args)))
4905 (make-null-markup))))))
4906 (lambda (key stencils)
4909 (interpret-markup layout props
4910 (compose (make-stencil-markup sten))))