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))))
1599 (interpret-markup layout
1600 (prepend-alist-chain 'word-space 0 props)
1602 (make-override-lines-markup-list
1604 (chain-assoc-get 'word-space props))
1605 (if (markup-command-list? args)
1607 (concat-string-args args))))))
1609 (define (wordwrap-stencils stencils
1610 justify base-space line-width text-dir)
1611 "Perform simple wordwrap, return stencil of each line."
1612 (define space (if justify
1613 ;; justify only stretches lines.
1616 (define (stencil-len s)
1617 (interval-end (ly:stencil-extent s X)))
1618 (define (maybe-shift line)
1619 (if (= text-dir LEFT)
1620 (ly:stencil-translate-axis
1622 (- line-width (stencil-len line))
1625 (if (null? stencils)
1627 (let loop ((lines '())
1630 ((line (first todo))
1632 (word-list (list (first todo))))
1635 (let ((new (if (= text-dir LEFT)
1636 (ly:stencil-stack (car todo) X RIGHT line space)
1637 (ly:stencil-stack line X RIGHT (car todo) space))))
1639 ((<= (stencil-len new) line-width)
1640 (word-loop new (cdr todo)
1641 (cons (car todo) word-list)))
1644 ;; This depends on stencil stacking being
1645 ;; associative so that stacking
1646 ;; left-to-right and right-to-left leads to
1648 (if (= text-dir LEFT)
1650 (reverse! word-list)))
1651 (len (stencil-len line))
1652 (stretch (- line-width len))
1655 (stack-stencils X RIGHT (1+ space) word-list))
1658 ;; Uh oh, nothing to fill.
1659 (loop (cons (maybe-shift line) lines) todo)
1661 (stack-stencils X RIGHT
1662 (+ space (/ stretch spaces))
1666 (else ;; not justify
1667 (loop (cons (maybe-shift line) lines) todo)))))
1670 ;; Now we have the last line assembled with space
1671 ;; which is compressed. We want to use the
1672 ;; uncompressed version instead if it fits, and the
1673 ;; justified version if it doesn't.
1675 ;; This depends on stencil stacking being
1676 ;; associative so that stacking
1677 ;; left-to-right and right-to-left leads to
1679 (if (= text-dir LEFT)
1681 (reverse! word-list)))
1682 (big-line (stack-stencils X RIGHT base-space word-list))
1683 (big-len (stencil-len big-line))
1684 (len (stencil-len line)))
1687 (if (> big-len line-width)
1688 (stack-stencils X RIGHT
1691 (* (- big-len line-width)
1693 (* (- line-width len)
1697 (maybe-shift big-line))))))
1698 (else ;; not justify
1699 (reverse! lines (list (maybe-shift line)))))))))
1702 (define-markup-list-command (wordwrap-internal layout props justify args)
1703 (boolean? markup-list?)
1704 #:properties ((line-width #f)
1706 (text-direction RIGHT))
1707 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1708 (wordwrap-stencils (interpret-markup-list layout props args)
1712 (ly:output-def-lookup layout 'line-width))
1715 (define-markup-command (justify layout props args)
1718 #:properties ((baseline-skip)
1719 wordwrap-internal-markup-list)
1721 @cindex justifying text
1723 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1724 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1725 @var{X}@tie{}is the number of staff spaces.
1727 @lilypond[verbatim,quote]
1730 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1731 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1732 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1733 laboris nisi ut aliquip ex ea commodo consequat.
1737 (stack-lines DOWN 0.0 baseline-skip
1738 (wordwrap-internal-markup-list layout props #t args)))
1740 (define-markup-command (wordwrap layout props args)
1743 #:properties ((baseline-skip)
1744 wordwrap-internal-markup-list)
1745 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1746 the line width, where @var{X} is the number of staff spaces.
1748 @lilypond[verbatim,quote]
1751 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1752 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1753 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1754 laboris nisi ut aliquip ex ea commodo consequat.
1758 (stack-lines DOWN 0.0 baseline-skip
1759 (wordwrap-internal-markup-list layout props #f args)))
1761 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1763 #:properties ((line-width)
1765 (text-direction RIGHT))
1766 "Internal markup list command used to define @code{\\justify-string} and
1767 @code{\\wordwrap-string}."
1768 (let* ((para-strings (regexp-split
1769 (string-regexp-substitute
1771 (string-regexp-substitute "\r\n" "\n" arg))
1772 "\n[ \t\n]*\n[ \t\n]*"))
1773 (list-para-words (map (lambda (str)
1774 (regexp-split str "[ \t\n]+"))
1776 (para-lines (map (lambda (words)
1779 (interpret-markup layout props x))
1781 (wordwrap-stencils stencils
1783 line-width text-direction)))
1785 (concatenate para-lines)))
1787 (define-markup-command (wordwrap-string layout props arg)
1790 #:properties ((baseline-skip)
1791 wordwrap-string-internal-markup-list)
1792 "Wordwrap a string. Paragraphs may be separated with double newlines.
1794 @lilypond[verbatim,quote]
1796 \\override #'(line-width . 40)
1797 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1798 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1799 et dolore magna aliqua.
1802 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1803 laboris nisi ut aliquip ex ea commodo consequat.
1806 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1807 qui officia deserunt mollit anim id est laborum\"
1810 (stack-lines DOWN 0.0 baseline-skip
1811 (wordwrap-string-internal-markup-list layout props #f arg)))
1813 (define-markup-command (justify-string layout props arg)
1816 #:properties ((baseline-skip)
1817 wordwrap-string-internal-markup-list)
1818 "Justify a string. Paragraphs may be separated with double newlines
1820 @lilypond[verbatim,quote]
1822 \\override #'(line-width . 40)
1823 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1824 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1825 et dolore magna aliqua.
1828 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1829 laboris nisi ut aliquip ex ea commodo consequat.
1832 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1833 qui officia deserunt mollit anim id est laborum\"
1836 (stack-lines DOWN 0.0 baseline-skip
1837 (wordwrap-string-internal-markup-list layout props #t arg)))
1839 (define-markup-command (wordwrap-field layout props symbol)
1842 "Wordwrap the data which has been assigned to @var{symbol}.
1844 @lilypond[verbatim,quote]
1846 title = \"My title\"
1847 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1848 elit, sed do eiusmod tempor incididunt ut labore et dolore
1849 magna aliqua. Ut enim ad minim veniam, quis nostrud
1850 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1855 bookTitleMarkup = \\markup {
1857 \\fill-line { \\fromproperty #'header:title }
1859 \\wordwrap-field #'header:myText
1868 (let* ((m (chain-assoc-get symbol props)))
1870 (wordwrap-string-markup layout props m)
1873 (define-markup-command (justify-field layout props symbol)
1876 "Justify the data which has been assigned to @var{symbol}.
1878 @lilypond[verbatim,quote]
1880 title = \"My title\"
1881 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1882 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1883 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1884 laboris nisi ut aliquip ex ea commodo consequat.\"
1888 bookTitleMarkup = \\markup {
1890 \\fill-line { \\fromproperty #'header:title }
1892 \\justify-field #'header:myText
1901 (let* ((m (chain-assoc-get symbol props)))
1903 (justify-string-markup layout props m)
1906 (define-markup-command (combine layout props arg1 arg2)
1910 @cindex merging text
1912 Print two markups on top of each other.
1914 Note: @code{\\combine} cannot take a list of markups enclosed in
1915 curly braces as an argument; for this purpose use @code{\\overlay} instead.
1917 @lilypond[verbatim,quote]
1920 \\override #'(thickness . 2)
1922 \\draw-line #'(0 . 4)
1923 \\arrow-head #Y #DOWN ##f
1926 (let* ((s1 (interpret-markup layout props arg1))
1927 (s2 (interpret-markup layout props arg2)))
1928 (ly:stencil-add s1 s2)))
1930 (define-markup-command (overlay layout props args)
1934 @cindex merging text
1936 Takes a list of markups combining them.
1938 @lilypond[verbatim,quote]
1941 \\override #'(thickness . 2)
1943 \\draw-line #'(0 . 4)
1944 \\arrow-head #Y #DOWN ##f
1945 \\translate #'(0 . 4)\\arrow-head #Y #UP ##f
1949 (apply ly:stencil-add (interpret-markup-list layout props args)))
1952 ;; TODO: should extract baseline-skip from each argument somehow..
1954 (define-markup-command (column layout props args)
1957 #:properties ((baseline-skip))
1959 @cindex stacking text in a column
1961 Stack the markups in @var{args} vertically. The property
1962 @code{baseline-skip} determines the space between markups
1965 @lilypond[verbatim,quote]
1974 (let ((arg-stencils (interpret-markup-list layout props args)))
1975 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1977 (define-markup-command (dir-column layout props args)
1980 #:properties ((direction)
1983 @cindex changing direction of text columns
1985 Make a column of @var{args}, going up or down, depending on the
1986 setting of the @code{direction} layout property.
1988 @lilypond[verbatim,quote]
1990 \\override #`(direction . ,UP) {
2000 \\override #'(direction . 1) {
2007 (stack-lines (if (number? direction) direction -1)
2010 (interpret-markup-list layout props args)))
2012 (define (general-column align-dir baseline mols)
2013 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
2015 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
2016 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
2017 (stacked-extent (ly:stencil-extent stacked-stencil X)))
2018 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
2020 (define-markup-command (center-column layout props args)
2023 #:properties ((baseline-skip))
2025 @cindex centering a column of text
2027 Put @code{args} in a centered column.
2029 @lilypond[verbatim,quote]
2038 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
2040 (define-markup-command (left-column layout props args)
2043 #:properties ((baseline-skip))
2045 @cindex text columns, left-aligned
2047 Put @code{args} in a left-aligned column.
2049 @lilypond[verbatim,quote]
2058 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
2060 (define-markup-command (right-column layout props args)
2063 #:properties ((baseline-skip))
2065 @cindex text columns, right-aligned
2067 Put @code{args} in a right-aligned column.
2069 @lilypond[verbatim,quote]
2078 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
2080 (define-markup-command (vcenter layout props arg)
2084 @cindex vertically centering text
2086 Align @code{arg} to its Y@tie{}center.
2088 @lilypond[verbatim,quote]
2096 (let* ((mol (interpret-markup layout props arg)))
2097 (ly:stencil-aligned-to mol Y CENTER)))
2099 (define-markup-command (center-align layout props arg)
2103 @cindex horizontally centering text
2105 Align @code{arg} to its X@tie{}center.
2107 @lilypond[verbatim,quote]
2117 (let* ((mol (interpret-markup layout props arg)))
2118 (ly:stencil-aligned-to mol X CENTER)))
2120 (define-markup-command (right-align layout props arg)
2124 @cindex right aligning text
2126 Align @var{arg} on its right edge.
2128 @lilypond[verbatim,quote]
2138 (let* ((m (interpret-markup layout props arg)))
2139 (ly:stencil-aligned-to m X RIGHT)))
2141 (define-markup-command (left-align layout props arg)
2145 @cindex left aligning text
2147 Align @var{arg} on its left edge.
2149 @lilypond[verbatim,quote]
2159 (let* ((m (interpret-markup layout props arg)))
2160 (ly:stencil-aligned-to m X LEFT)))
2162 (define-markup-command (general-align layout props axis dir arg)
2163 (integer? number? markup?)
2166 @cindex controlling general text alignment
2168 Align @var{arg} in @var{axis} direction to the @var{dir} side.
2170 @lilypond[verbatim,quote]
2174 \\general-align #X #LEFT
2179 \\general-align #X #CENTER
2185 \\general-align #Y #UP
2192 \\general-align #Y #3.2
2199 (let* ((m (interpret-markup layout props arg)))
2200 (ly:stencil-aligned-to m axis dir)))
2202 (define-markup-command (halign layout props dir arg)
2206 @cindex setting horizontal text alignment
2208 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2209 left-aligned, while @code{+1} is right. Values in between interpolate
2210 alignment accordingly.
2212 @lilypond[verbatim,quote]
2237 (let* ((m (interpret-markup layout props arg)))
2238 (ly:stencil-aligned-to m X dir)))
2240 (define-markup-command (with-dimensions layout props x y arg)
2241 (number-pair? number-pair? markup?)
2244 @cindex setting extent of text objects
2246 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2247 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2249 (make-transparent-box-stencil x y)
2251 `(delay-stencil-evaluation ,(delay expr))
2254 (define-markup-command (with-outline layout props outline arg)
2258 Print @var{arg} with the outline and dimensions of @var{outline}."
2259 (ly:stencil-outline (interpret-markup layout props arg)
2260 (interpret-markup layout props outline)))
2262 (define-markup-command (with-dimensions-from layout props arg1 arg2)
2266 Print @var{arg2} with the dimensions of @var{arg1}."
2267 (let* ((stil1 (interpret-markup layout props arg1))
2268 (x (ly:stencil-extent stil1 0))
2269 (y (ly:stencil-extent stil1 1)))
2270 (interpret-markup layout props (markup #:with-dimensions x y arg2))))
2272 (define-markup-command (pad-around layout props amount arg)
2275 "Add padding @var{amount} all around @var{arg}.
2277 @lilypond[verbatim,quote]
2290 (let* ((m (interpret-markup layout props arg))
2291 (x (interval-widen (ly:stencil-extent m X) amount))
2292 (y (interval-widen (ly:stencil-extent m Y) amount)))
2293 (ly:stencil-add (make-transparent-box-stencil x y)
2296 (define-markup-command (pad-x layout props amount arg)
2300 @cindex padding text horizontally
2302 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2304 @lilypond[verbatim,quote]
2317 (let* ((m (interpret-markup layout props arg))
2318 (x (ly:stencil-extent m X))
2319 (y (ly:stencil-extent m Y)))
2320 (ly:make-stencil (ly:stencil-expr m)
2321 (interval-widen x amount)
2324 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2325 (integer? ly:dir? markup? markup?)
2327 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2328 (let ((m1 (interpret-markup layout props arg1))
2329 (m2 (interpret-markup layout props arg2)))
2330 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2332 (define-markup-command (transparent layout props arg)
2335 "Make @var{arg} transparent.
2337 @lilypond[verbatim,quote]
2344 (ly:stencil-outline empty-stencil (interpret-markup layout props arg)))
2346 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2347 (number-pair? number-pair? markup?)
2349 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2351 @lilypond[verbatim,quote]
2358 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2364 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2365 (interpret-markup layout props arg)))
2367 (define-markup-command (hcenter-in layout props length arg)
2370 "Center @var{arg} horizontally within a box of extending
2371 @var{length}/2 to the left and right.
2373 @lilypond[quote,verbatim]
2376 \\set Staff.instrumentName = \\markup {
2383 \\set Staff.instrumentName = \\markup {
2392 (interpret-markup layout props
2393 (make-pad-to-box-markup
2394 (cons (/ length -2) (/ length 2))
2396 (make-center-align-markup arg))))
2398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2402 (define-markup-command (property-recursive layout props symbol)
2405 "Print out a warning when a header field markup contains some recursive
2407 (ly:warning "Recursive definition of property ~a detected!" symbol)
2410 (define-markup-command (fromproperty layout props symbol)
2413 "Read the @var{symbol} from property settings, and produce a stencil
2414 from the markup contained within. If @var{symbol} is not defined, it
2415 returns an empty markup.
2417 @lilypond[verbatim,quote]
2419 myTitle = \"myTitle\"
2423 \\fromproperty #'header:myTitle
2430 (let ((m (chain-assoc-get symbol props)))
2432 ;; prevent infinite loops by clearing the interpreted property:
2433 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2436 (define-markup-command (on-the-fly layout props procedure arg)
2437 (procedure? markup?)
2439 "Apply the @var{procedure} markup command to @var{arg}.
2440 @var{procedure} takes the same arguments as @code{interpret-markup}
2441 and returns a stencil."
2442 (procedure layout props arg))
2444 (define-markup-command (footnote layout props mkup note)
2447 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2449 @lilypond[verbatim,quote]
2452 \\override #'(padding . 0.2)
2456 The footnote will not be annotated automatically."
2457 (ly:stencil-combine-at-edge
2458 (interpret-markup layout props mkup)
2462 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2467 (define-markup-command (auto-footnote layout props mkup note)
2470 #:properties ((raise 0.5)
2472 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2474 @lilypond[verbatim,quote]
2477 \\override #'(padding . 0.2)
2481 The footnote will be annotated automatically."
2482 (let* ((markup-stencil (interpret-markup layout props mkup))
2483 (footnote-hash (gensym "footnote"))
2485 (gauge-stencil (interpret-markup
2488 ((ly:output-def-lookup
2490 'footnote-numbering-function)
2492 (x-ext (ly:stencil-extent gauge-stencil X))
2493 (y-ext (ly:stencil-extent gauge-stencil Y))
2495 `(delay-stencil-evaluation
2499 (ly:output-def-lookup layout
2500 'number-footnote-table))
2501 (footnote-stencil (if (list? table)
2502 (assoc-get footnote-hash
2505 (footnote-stencil (if (ly:stencil? footnote-stencil)
2508 (ly:programming-error
2509 "Cannot find correct footnote for a markup object.")
2511 (gap (- (interval-length x-ext)
2513 (ly:stencil-extent footnote-stencil X))))
2514 (y-trans (- (+ (cdr y-ext)
2516 (cdr (ly:stencil-extent footnote-stencil
2518 (ly:stencil-translate footnote-stencil
2519 (cons gap y-trans)))))))
2520 (main-stencil (ly:stencil-combine-at-edge
2524 (ly:make-stencil footnote-number x-ext y-ext)
2529 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2533 (define-markup-command (override layout props new-prop arg)
2537 @cindex overriding properties within text markup
2539 Add the argument @var{new-prop} to the property list. Properties
2540 may be any property supported by @rinternals{font-interface},
2541 @rinternals{text-interface} and
2542 @rinternals{instrument-specific-markup-interface}.
2544 @lilypond[verbatim,quote]
2552 \\override #'(baseline-skip . 4) {
2561 (interpret-markup layout (cons (list new-prop) props) arg))
2563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2565 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2567 (define-markup-command (verbatim-file layout props name)
2570 "Read the contents of file @var{name}, and include it verbatim.
2572 @lilypond[verbatim,quote]
2574 \\verbatim-file #\"simple.ly\"
2577 (interpret-markup layout props
2578 (if (ly:get-option 'safe)
2579 "verbatim-file disabled in safe mode"
2580 (let* ((str (ly:gulp-file name))
2581 (lines (string-split str #\nl)))
2582 (make-typewriter-markup
2583 (make-column-markup lines))))))
2585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2587 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2590 (define-markup-command (smaller layout props arg)
2593 "Decrease the font size relative to the current setting.
2595 @lilypond[verbatim,quote]
2608 (interpret-markup layout props
2609 `(,fontsize-markup -1 ,arg)))
2611 (define-markup-command (larger layout props arg)
2614 "Increase the font size relative to the current setting.
2616 @lilypond[verbatim,quote]
2624 (interpret-markup layout props
2625 `(,fontsize-markup 1 ,arg)))
2627 (define-markup-command (finger layout props arg)
2630 "Set @var{arg} as small numbers.
2632 @lilypond[verbatim,quote]
2639 (interpret-markup layout
2640 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2643 (define-markup-command (abs-fontsize layout props size arg)
2646 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2647 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2649 @lilypond[verbatim,quote]
2651 default text font size
2653 \\abs-fontsize #16 { text font size 16 }
2655 \\abs-fontsize #12 { text font size 12 }
2658 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2659 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2660 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2661 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2662 (magnification (/ size ref-size)))
2666 `((baseline-skip . ,(* magnification ref-baseline))
2667 (word-space . ,(* magnification ref-word-space))
2668 (font-size . ,(magnification->font-size magnification)))
2672 (define-markup-command (fontsize layout props increment arg)
2675 #:properties ((font-size 0)
2678 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2681 @lilypond[verbatim,quote]
2692 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2693 (word-space . ,(* word-space (magstep increment)))
2694 (font-size . ,(+ font-size increment)))
2698 (define-markup-command (magnify layout props sz arg)
2702 @cindex magnifying text
2704 Set the font magnification for its argument. In the following
2705 example, the middle@tie{}A is 10% larger:
2708 A \\magnify #1.1 @{ A @} A
2711 Note: Magnification only works if a font name is explicitly selected.
2712 Use @code{\\fontsize} otherwise.
2714 @lilypond[verbatim,quote]
2725 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2728 (define-markup-command (bold layout props arg)
2731 "Switch to bold font-series.
2733 @lilypond[verbatim,quote]
2741 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2743 (define-markup-command (sans layout props arg)
2746 "Switch to the sans serif font family.
2748 @lilypond[verbatim,quote]
2757 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2759 (define-markup-command (number layout props arg)
2762 "Set font family to @code{number}, which yields the font used for
2763 time signatures and fingerings. This font contains numbers and
2764 some punctuation; it has no letters.
2766 @lilypond[verbatim,quote]
2769 0 1 2 3 4 5 6 7 8 9 . ,
2773 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2775 (define-markup-command (roman layout props arg)
2778 "Set font family to @code{roman}.
2780 @lilypond[verbatim,quote]
2786 text in roman font family
2793 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2795 (define-markup-command (huge layout props arg)
2798 "Set font size to +2.
2800 @lilypond[verbatim,quote]
2808 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2810 (define-markup-command (large layout props arg)
2813 "Set font size to +1.
2815 @lilypond[verbatim,quote]
2823 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2825 (define-markup-command (normalsize layout props arg)
2828 "Set font size to default.
2830 @lilypond[verbatim,quote]
2843 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2845 (define-markup-command (small layout props arg)
2848 "Set font size to -1.
2850 @lilypond[verbatim,quote]
2858 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2860 (define-markup-command (tiny layout props arg)
2863 "Set font size to -2.
2865 @lilypond[verbatim,quote]
2873 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2875 (define-markup-command (teeny layout props arg)
2878 "Set font size to -3.
2880 @lilypond[verbatim,quote]
2888 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2890 (define-markup-command (fontCaps layout props arg)
2893 "Set @code{font-shape} to @code{caps}
2895 Note: @code{\\fontCaps} requires the installation and selection of
2896 fonts which support the @code{caps} font shape."
2897 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2900 (define-markup-command (smallCaps layout props arg)
2903 "Emit @var{arg} as small caps.
2905 Note: @code{\\smallCaps} does not support accented characters.
2907 @lilypond[verbatim,quote]
2916 (define (char-list->markup chars lower)
2917 (let ((final-string (string-upcase (reverse-list->string chars))))
2919 (markup #:fontsize -2 final-string)
2921 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2922 (if (null? rest-chars)
2924 (reverse! (cons (char-list->markup currents current-is-lower)
2926 (let* ((ch (car rest-chars))
2927 (is-lower (char-lower-case? ch)))
2928 (if (or (and current-is-lower is-lower)
2929 (and (not current-is-lower) (not is-lower)))
2930 (make-small-caps (cdr rest-chars)
2934 (make-small-caps (cdr rest-chars)
2937 (if (null? currents)
2939 (cons (char-list->markup
2940 currents current-is-lower)
2942 (interpret-markup layout props
2944 (make-small-caps (string->list arg) (list) #f (list))
2947 (define-markup-command (caps layout props arg)
2950 "Copy of the @code{\\smallCaps} command.
2952 @lilypond[verbatim,quote]
2961 (interpret-markup layout props (make-smallCaps-markup arg)))
2963 (define-markup-command (dynamic layout props arg)
2966 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2967 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2968 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2969 done in a different font. The recommended font for this is bold and italic.
2970 @lilypond[verbatim,quote]
2978 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2980 (define-markup-command (text layout props arg)
2983 "Use a text font instead of music symbol or music alphabet font.
2985 @lilypond[verbatim,quote]
2998 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
3001 (define-markup-command (italic layout props arg)
3004 "Use italic @code{font-shape} for @var{arg}.
3006 @lilypond[verbatim,quote]
3014 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
3016 (define-markup-command (typewriter layout props arg)
3019 "Use @code{font-family} typewriter for @var{arg}.
3021 @lilypond[verbatim,quote]
3030 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
3032 (define-markup-command (upright layout props arg)
3035 "Set @code{font-shape} to @code{upright}. This is the opposite
3038 @lilypond[verbatim,quote]
3052 layout (prepend-alist-chain 'font-shape 'upright props) arg))
3054 (define-markup-command (medium layout props arg)
3057 "Switch to medium font-series (in contrast to bold).
3059 @lilypond[verbatim,quote]
3072 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
3075 (define-markup-command (normal-text layout props arg)
3078 "Set all font related properties (except the size) to get the default
3079 normal text font, no matter what font was used earlier.
3081 @lilypond[verbatim,quote]
3083 \\huge \\bold \\sans \\caps {
3095 (interpret-markup layout
3096 (cons '((font-family . roman) (font-shape . upright)
3097 (font-series . medium) (font-encoding . latin1))
3101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3105 (define-markup-command (musicglyph layout props glyph-name)
3108 "@var{glyph-name} is converted to a musical symbol; for example,
3109 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
3110 the music font. See @ruser{The Feta font} for a complete listing of
3111 the possible glyphs.
3113 @lilypond[verbatim,quote]
3116 \\musicglyph #\"rests.2\"
3117 \\musicglyph #\"clefs.G_change\"
3120 (let* ((font (ly:paper-get-font layout
3121 (cons '((font-encoding . fetaMusic)
3125 (glyph (ly:font-get-glyph font glyph-name)))
3126 (if (null? (ly:stencil-expr glyph))
3127 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
3131 (define-markup-command (doublesharp layout props)
3134 "Draw a double sharp symbol.
3136 @lilypond[verbatim,quote]
3141 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
3143 (define-markup-command (sesquisharp layout props)
3146 "Draw a 3/2 sharp symbol.
3148 @lilypond[verbatim,quote]
3153 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
3155 (define-markup-command (sharp layout props)
3158 "Draw a sharp symbol.
3160 @lilypond[verbatim,quote]
3165 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
3167 (define-markup-command (semisharp layout props)
3170 "Draw a semisharp symbol.
3172 @lilypond[verbatim,quote]
3177 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
3179 (define-markup-command (natural layout props)
3182 "Draw a natural symbol.
3184 @lilypond[verbatim,quote]
3189 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
3191 (define-markup-command (semiflat layout props)
3194 "Draw a semiflat symbol.
3196 @lilypond[verbatim,quote]
3201 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
3203 (define-markup-command (flat layout props)
3206 "Draw a flat symbol.
3208 @lilypond[verbatim,quote]
3213 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
3215 (define-markup-command (sesquiflat layout props)
3218 "Draw a 3/2 flat symbol.
3220 @lilypond[verbatim,quote]
3225 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3227 (define-markup-command (doubleflat layout props)
3230 "Draw a double flat symbol.
3232 @lilypond[verbatim,quote]
3237 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3239 (define-markup-command (with-color layout props color arg)
3243 @cindex coloring text
3245 Draw @var{arg} in color specified by @var{color}.
3247 @lilypond[verbatim,quote]
3259 (let ((stil (interpret-markup layout props arg)))
3260 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3261 (ly:stencil-extent stil X)
3262 (ly:stencil-extent stil Y))))
3264 (define-markup-command (tied-lyric layout props str)
3267 #:properties ((word-space))
3269 @cindex simple text strings with tie characters
3271 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3273 @lilypond[verbatim,quote]
3275 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3276 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3277 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3280 (define (replace-ties tie str)
3281 (if (string-contains str "~")
3283 ((half-space (/ word-space 2))
3284 (parts (string-split str #\~))
3285 (tie-str (markup #:hspace half-space
3287 #:hspace half-space))
3288 (joined (list-join parts tie-str)))
3289 (make-concat-markup joined))
3292 (define short-tie-regexp (make-regexp "~[^.]~"))
3293 (define (match-short str) (regexp-exec short-tie-regexp str))
3295 (define (replace-short str mkp)
3296 (let ((match (match-short str)))
3298 (make-concat-markup (list
3300 (replace-ties "ties.lyric.default" str)))
3301 (let ((new-str (match:suffix match))
3302 (new-mkp (make-concat-markup (list
3304 (replace-ties "ties.lyric.default"
3305 (match:prefix match))
3306 (replace-ties "ties.lyric.short"
3307 (match:substring match))))))
3308 (replace-short new-str new-mkp)))))
3310 (interpret-markup layout
3312 (replace-short str (markup))))
3314 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3316 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3318 (define-markup-command (arrow-head layout props axis dir filled)
3319 (integer? ly:dir? boolean?)
3321 "Produce an arrow head in specified direction and axis.
3322 Use the filled head if @var{filled} is specified.
3323 @lilypond[verbatim,quote]
3326 \\general-align #Y #DOWN {
3327 \\arrow-head #Y #UP ##t
3328 \\arrow-head #Y #DOWN ##f
3330 \\arrow-head #X #RIGHT ##f
3331 \\arrow-head #X #LEFT ##f
3337 ((name (format #f "arrowheads.~a.~a~a"
3344 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3348 (define-markup-command (lookup layout props glyph-name)
3351 "Lookup a glyph by name.
3353 @lilypond[verbatim,quote]
3355 \\override #'(font-encoding . fetaBraces) {
3356 \\lookup #\"brace200\"
3359 \\lookup #\"brace180\"
3363 (ly:font-get-glyph (ly:paper-get-font layout props)
3366 (define-markup-command (char layout props num)
3369 "Produce a single character. Characters encoded in hexadecimal
3370 format require the prefix @code{#x}.
3372 @lilypond[verbatim,quote]
3374 \\char #65 \\char ##x00a9
3377 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3379 (define number->mark-letter-vector (make-vector 25 #\A))
3384 (if (= i (- (char->integer #\I) (char->integer #\A)))
3386 (vector-set! number->mark-letter-vector j
3387 (integer->char (+ i (char->integer #\A)))))
3389 (define number->mark-alphabet-vector (list->vector
3390 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3392 (define (number->markletter-string vec n)
3393 "Double letters for big marks."
3394 (let* ((lst (vector-length vec)))
3397 (string-append (number->markletter-string vec (1- (quotient n lst)))
3398 (number->markletter-string vec (remainder n lst)))
3399 (make-string 1 (vector-ref vec n)))))
3401 (define-markup-command (markletter layout props num)
3404 "Make a markup letter for @var{num}. The letters start with A
3405 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3407 @lilypond[verbatim,quote]
3414 (ly:text-interface::interpret-markup layout props
3415 (number->markletter-string number->mark-letter-vector num)))
3417 (define-markup-command (markalphabet layout props num)
3420 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3421 and continue with double letters.
3423 @lilypond[verbatim,quote]
3430 (ly:text-interface::interpret-markup layout props
3431 (number->markletter-string number->mark-alphabet-vector num)))
3433 (define-public (horizontal-slash-interval num forward number-interval mag)
3435 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3436 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3437 (else (interval-widen number-interval (* mag 0.25))))
3438 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3439 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3440 (else (interval-widen number-interval (* mag 0.25))))
3443 (define-public (adjust-slash-stencil num forward stencil mag)
3446 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3448 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3450 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3452 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3455 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3457 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3462 (define (slashed-digit-internal layout props num forward font-size thickness)
3463 (let* ((mag (magstep font-size))
3465 (ly:output-def-lookup layout 'line-thickness)
3467 ;; backward slashes might use slope and point in the other direction!
3468 (dy (* mag (if forward 0.4 -0.4)))
3469 (number-stencil (interpret-markup layout
3470 (prepend-alist-chain 'font-encoding 'fetaText props)
3471 (number->string num)))
3472 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3473 (center (interval-center (ly:stencil-extent number-stencil Y)))
3474 ;; Use the real extents of the slash, not the whole number,
3475 ;; because we might translate the slash later on!
3476 (num-y (interval-widen (cons center center) (abs dy)))
3477 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3478 (slash-stencil (if is-sane
3479 (make-line-stencil thickness
3480 (car num-x) (- (interval-center num-y) dy)
3481 (cdr num-x) (+ (interval-center num-y) dy))
3483 (if (ly:stencil? slash-stencil)
3485 ;; for some numbers we need to shift the slash/backslash up or
3486 ;; down to make the slashed digit look better
3487 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3488 (set! number-stencil
3489 (ly:stencil-add number-stencil slash-stencil)))
3490 (ly:warning "Unable to create slashed digit ~a" num))
3494 (define-markup-command (slashed-digit layout props num)
3497 #:properties ((font-size 0)
3500 @cindex slashed digits
3502 A feta number, with slash. This is for use in the context of
3503 figured bass notation.
3504 @lilypond[verbatim,quote]
3508 \\override #'(thickness . 3)
3512 (slashed-digit-internal layout props num #t font-size thickness))
3514 (define-markup-command (backslashed-digit layout props num)
3517 #:properties ((font-size 0)
3520 @cindex backslashed digits
3522 A feta number, with backslash. This is for use in the context of
3523 figured bass notation.
3524 @lilypond[verbatim,quote]
3526 \\backslashed-digit #5
3528 \\override #'(thickness . 3)
3529 \\backslashed-digit #7
3532 (slashed-digit-internal layout props num #f font-size thickness))
3535 (define eyeglassespath
3536 '((moveto 0.42 0.77)
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)
3543 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3544 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3545 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3546 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3548 (moveto 1.025 0.935)
3549 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3550 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3553 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3556 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3558 (define-markup-command (eyeglasses layout props)
3561 "Prints out eyeglasses, indicating strongly to look at the conductor.
3562 @lilypond[verbatim,quote]
3563 \\markup { \\eyeglasses }
3565 (interpret-markup layout props
3566 (make-override-markup '(line-cap-style . butt)
3567 (make-path-markup 0.15 eyeglassespath))))
3569 (define-markup-command (left-brace layout props size)
3573 A feta brace in point size @var{size}.
3575 @lilypond[verbatim,quote]
3582 (let* ((font (ly:paper-get-font layout
3583 (cons '((font-encoding . fetaBraces)
3586 (glyph-count (1- (ly:otf-glyph-count font)))
3587 (scale (ly:output-def-lookup layout 'output-scale))
3588 (scaled-size (/ (ly:pt size) scale))
3590 (ly:font-get-glyph font (string-append "brace"
3591 (number->string n)))))
3592 (get-y-from-brace (lambda (brace)
3594 (ly:stencil-extent (glyph brace) Y))))
3595 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3596 (glyph-found (glyph find-brace)))
3598 (if (or (null? (ly:stencil-expr glyph-found))
3599 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3600 (> scaled-size (interval-length
3601 (ly:stencil-extent (glyph glyph-count) Y))))
3603 (ly:warning (_ "no brace found for point size ~S ") size)
3604 (ly:warning (_ "defaulting to ~S pt")
3605 (/ (* scale (interval-length
3606 (ly:stencil-extent glyph-found Y)))
3610 (define-markup-command (right-brace layout props size)
3614 A feta brace in point size @var{size}, rotated 180 degrees.
3616 @lilypond[verbatim,quote]
3623 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3626 ;; the note command.
3627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3629 ;; TODO: better syntax.
3631 (define-markup-command (note-by-number layout props log dot-count dir)
3632 (number? number? number?)
3634 #:properties ((font-size 0)
3638 @cindex notes within text by log and dot-count
3640 Construct a note symbol, with stem and flag. By using fractional values for
3641 @var{dir}, longer or shorter stems can be obtained.
3642 Supports all note-head-styles. Ancient note-head-styles will get
3643 mensural-style-flags. @code{flag-style} may be overridden independently.
3644 Supported flag-styles are @code{default}, @code{old-straight-flag},
3645 @code{modern-straight-flag}, @code{flat-flag}, @code{mensural} and
3646 @code{neomensural}. The latter two flag-styles will both result in
3647 mensural-flags. Both are supplied for convenience.
3649 @lilypond[verbatim,quote]
3651 \\note-by-number #3 #0 #DOWN
3653 \\note-by-number #1 #2 #0.8
3656 (define (get-glyph-name-candidates dir log style)
3657 (map (lambda (dir-name)
3658 (format #f "noteheads.~a~a"
3660 (if (and (symbol? style)
3661 (not (equal? 'default style)))
3662 (select-head-glyph style (min log 2))
3664 (list (if (= dir UP) "u" "d")
3667 (define (get-glyph-name font cands)
3670 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3671 (get-glyph-name font (cdr cands))
3674 (define (buildflags flag-stencil remain curr-stencil spacing)
3675 ;; Function to recursively create a stencil with @code{remain} flags
3676 ;; from the single-flag stencil @code{curr-stencil}, which is already
3677 ;; translated to the position of the previous flag position.
3679 ;; Copy and paste from /scm/flag-styles.scm
3681 (let* ((translated-stencil
3682 (ly:stencil-translate-axis curr-stencil spacing Y))
3683 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3684 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3687 (define (straight-flag-mrkp flag-thickness flag-spacing
3688 upflag-angle upflag-length
3689 downflag-angle downflag-length
3691 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3692 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3693 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3694 ;; @var{downflag-length} are given in staff spaces.
3696 ;; All lengths are scaled according to the font size of the note.
3698 ;; From /scm/flag-styles.scm, modified to fit here.
3700 (let* ((stem-up (> dir 0))
3701 ;; scale with the note size
3702 (factor (magstep font-size))
3703 (stem-thickness (* factor 0.1))
3704 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3705 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3706 (raw-length (if stem-up upflag-length downflag-length))
3707 (angle (if stem-up upflag-angle downflag-angle))
3708 (flag-length (+ (* raw-length factor) half-stem-thickness))
3709 (flag-end (polar->rectangular flag-length angle))
3710 (thickness (* flag-thickness factor))
3711 (thickness-offset (cons 0 (* -1 thickness dir)))
3712 (spacing (* -1 flag-spacing factor dir))
3713 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3718 (offset-add flag-end thickness-offset)
3720 (points (map (lambda (coord) (offset-add coord start)) raw-points))
3721 (stencil (ly:round-filled-polygon points half-stem-thickness))
3722 ;; Log for 1/8 is 3, so we need to subtract 3
3723 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3726 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)
3729 (size-factor (magstep font-size))
3730 (blot (ly:output-def-lookup layout 'blot-diameter))
3732 (let ((result (get-glyph-name font
3733 (get-glyph-name-candidates
3734 (sign dir) log style))))
3735 (if (string-null? result)
3736 ;; If no glyph name can be found, select default heads.
3737 ;; Though this usually means an unsupported style has been
3738 ;; chosen, it also prevents unrelated 'style settings from
3739 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3741 (get-glyph-name font
3742 (get-glyph-name-candidates
3743 (sign dir) log 'default))
3745 (head-glyph (ly:font-get-glyph font head-glyph-name))
3748 '(mensural neomensural petrucci semipetrucci blackpetrucci)))
3749 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3750 (stem-length (* size-factor (max 3 (- log 1))))
3751 ;; With ancient-flags we want a tighter stem
3752 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3753 (stemy (* dir stem-length))
3754 (attach-off (cons (interval-index
3755 (ly:stencil-extent head-glyph X)
3756 (* (sign dir) (car attach-indices)))
3757 ;; fixme, this is inconsistent between X & Y.
3760 (ly:stencil-extent head-glyph Y)
3761 (cdr attach-indices)))))
3762 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3765 (if (or ancient-flags?
3766 (member flag-style '(mensural neomensural)))
3767 (* 0.5 dir stem-thickness) 0))
3768 (stem-glyph (and (> log 0)
3769 (ly:round-filled-box
3770 (ordered-cons (+ stem-X-corr (car attach-off))
3771 (+ stem-X-corr (car attach-off)
3772 (* (- (sign dir)) stem-thickness)))
3773 (cons (min stemy (cdr attach-off))
3774 (max stemy (cdr attach-off)))
3775 (/ stem-thickness 3))))
3776 (dot (ly:font-get-glyph font "dots.dot"))
3777 (dotwid (interval-length (ly:stencil-extent dot X)))
3778 (dots (and (> dot-count 0)
3779 (apply ly:stencil-add
3781 (ly:stencil-translate-axis
3782 dot (* 2 x dotwid) X))
3783 (iota dot-count)))))
3784 ;; Straight-flags. Values taken from /scm/flag-style.scm
3785 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3786 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3787 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3788 ;; Calculate a corrective to avoid a gap between
3789 ;; straight-flags and the stem.
3790 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3791 (eq? flag-style 'old-straight-flag)
3792 (eq? flag-style 'flat-flag))
3793 (/ blot 10 (* -1 dir))
3795 (flaggl (and (> log 2)
3796 (ly:stencil-translate
3797 (cond ((eq? flag-style 'modern-straight-flag)
3798 modern-straight-flag)
3799 ((eq? flag-style 'old-straight-flag)
3801 ((eq? flag-style 'flat-flag)
3804 (ly:font-get-glyph font
3806 (if (or (member flag-style
3807 '(mensural neomensural))
3809 (null? flag-style)))
3810 "flags.mensural~a2~a"
3812 (if (> dir 0) "u" "d")
3814 (cons (+ (car attach-off)
3815 ;; For tighter stems (with ancient-flags) the
3816 ;; flag has to be adjusted different.
3817 (if (and (not ancient-flags?) (< dir 0))
3820 (+ stemy flag-style-Y-corr))))))
3822 ;; If there is a flag on an upstem and the stem is short, move the dots
3823 ;; to avoid the flag. 16th notes get a special case because their flags
3824 ;; hang lower than any other flags.
3825 ;; Not with ancient flags or straight-flags.
3826 (if (and dots (> dir 0) (> log 2)
3827 (or (eq? flag-style 'default) (null? flag-style))
3828 (not ancient-flags?)
3829 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3830 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3832 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3833 (if (ly:stencil? stem-glyph)
3834 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3835 (set! stem-glyph head-glyph))
3836 (if (ly:stencil? dots)
3839 (ly:stencil-translate-axis
3841 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3847 (let ((divisor (log 2)))
3848 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3850 (define (parse-simple-duration duration-string)
3851 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3852 and return a (log dots) list."
3853 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3855 (if (and match (string=? duration-string (match:substring match 0)))
3856 (let ((len (match:substring match 1))
3857 (dots (match:substring match 2)))
3858 (list (cond ((string=? len "breve") -1)
3859 ((string=? len "longa") -2)
3860 ((string=? len "maxima") -3)
3861 (else (log2 (string->number len))))
3862 (if dots (string-length dots) 0)))
3863 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3865 (define-markup-command (note layout props duration dir)
3868 #:properties (note-by-number-markup)
3870 @cindex notes within text by string
3872 This produces a note with a stem pointing in @var{dir} direction, with
3873 the @var{duration} for the note head type and augmentation dots. For
3874 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3875 a shortened down stem.
3877 @lilypond[verbatim,quote]
3879 \\override #'(style . cross) {
3883 \\note #\"breve\" #0
3886 (let ((parsed (parse-simple-duration duration)))
3887 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3890 ;; the rest command.
3891 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3893 (define-markup-command (rest-by-number layout props log dot-count)
3896 #:properties ((font-size 0)
3898 (multi-measure-rest #f))
3900 @cindex rests or multi-measure-rests within text by log and dot-count
3902 A rest or multi-measure-rest symbol.
3904 @lilypond[verbatim,quote]
3906 \\rest-by-number #3 #2
3908 \\rest-by-number #0 #1
3910 \\override #'(multi-measure-rest . #t)
3911 \\rest-by-number #0 #0
3915 (define (get-glyph-name-candidates log style)
3916 (let* (;; Choose the style-string to be added.
3917 ;; If no glyph exists, select others for the specified styles
3918 ;; otherwise defaulting.
3921 ;; 'baroque needs to be special-cased, otherwise
3922 ;; `select-head-glyphĀ“ would catch neomensural-glyphs for
3923 ;; this style, if (< log 0).
3924 (eq? style 'baroque)
3925 (string-append (number->string log) ""))
3926 ((eq? style 'petrucci)
3927 (string-append (number->string log) "mensural"))
3928 ;; In other cases `select-head-glyphĀ“ from output-lib.scm
3929 ;; works for rest-glyphs, too.
3930 ((and (symbol? style) (not (eq? style 'default)))
3931 (select-head-glyph style log))
3933 ;; Choose ledgered glyphs for whole and half rest.
3934 ;; Except for the specified styles, logs and MultiMeasureRests.
3936 (if (and (or (list? style)
3938 '(neomensural mensural petrucci))))
3939 (not multi-measure-rest)
3940 (or (= log 0) (= log 1)))
3943 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3945 (define (get-glyph-name font cands)
3946 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3951 (ly:paper-get-font layout
3952 (cons '((font-encoding . fetaMusic)
3957 (get-glyph-name font
3958 (get-glyph-name-candidates log style))))
3959 (if (string-null? result)
3960 ;; If no glyph name can be found, select default rests. Though
3961 ;; this usually means an unsupported style has been chosen, it
3962 ;; also prevents unrelated 'style settings from other grobs
3963 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3964 (get-glyph-name font (get-glyph-name-candidates log 'default))
3966 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3967 (dot (ly:font-get-glyph font "dots.dot"))
3968 (dot-width (interval-length (ly:stencil-extent dot X)))
3969 (dots (and (> dot-count 0)
3970 (apply ly:stencil-add
3972 (ly:stencil-translate-axis
3973 dot (* 2 x dot-width) X))
3974 (iota dot-count))))))
3976 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3977 ;; glyphs are taken for whole and half rests.
3978 ;; If they are dotted, move the dots in X-direction to avoid collision.
3982 (not (member style '(neomensural mensural petrucci))))
3983 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3985 ;; Add dots to the rest-glyph.
3987 ;; Not sure how to vertical align dots.
3988 ;; For now the dots are centered for half, whole or longer rests.
3989 ;; Otherwise placed near the top of the rest.
3991 ;; Dots for rests with (< log 0) dots are allowed, but not
3992 ;; if multi-measure-rest is set #t.
3993 (if (and (not multi-measure-rest) dots)
3996 (ly:stencil-translate
3999 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
4001 (interval-center (ly:stencil-extent rest-glyph Y))
4002 (- (interval-end (ly:stencil-extent rest-glyph Y))
4003 (/ (* 2 dot-width) 3)))))
4007 (define-markup-command (rest layout props duration)
4010 #:properties ((style '())
4011 (multi-measure-rest #f)
4012 (multi-measure-rest-number #t)
4015 @cindex rests or multi-measure-rests within text by string
4017 This produces a rest, with the @var{duration} for the rest type and
4019 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
4022 Printing MultiMeasureRests could be enabled with
4023 @code{\\override #'(multi-measure-rest . #t)}
4024 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
4025 This is enabled for all styles using default-glyphs.
4026 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
4028 @lilypond[verbatim,quote]
4034 \\override #'(multi-measure-rest . #t)
4038 \\override #'(multi-measure-rest-number . #f)
4043 ;; Get the number of mmr-glyphs.
4044 ;; Store them in a list.
4045 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
4046 (define (mmr-numbers nmbr)
4047 (let* ((8-bar-glyph (floor (/ nmbr 8)))
4048 (8-remainder (remainder nmbr 8))
4049 (4-bar-glyph (floor (/ 8-remainder 4)))
4050 (4-remainder (remainder nmbr 4))
4051 (2-bar-glyph (floor (/ 4-remainder 2)))
4052 (2-remainder (remainder 4-remainder 2))
4053 (1-bar-glyph (floor (/ 2-remainder 1))))
4054 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
4056 ;; Get the correct mmr-glyphs.
4057 ;; Store them in a list.
4059 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
4060 ;; -> ("rests.M3" "rests.M1")
4061 (define (get-mmr-glyphs lst1 lst2)
4062 (define (helper l1 l2 l3)
4067 (append (make-list (car l1) (car l2)) l3))))
4068 (helper lst1 lst2 '()))
4070 ;; If duration is not valid, print a warning and return empty-stencil
4071 (if (or (and (not (integer? (car (parse-simple-duration duration))))
4072 (not multi-measure-rest))
4073 (and (= (string-length (car (string-split duration #\. ))) 1)
4074 (= (string->number (car (string-split duration #\. ))) 0)))
4076 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
4079 ;; For simple rests:
4080 ;; Get a (log dots) list.
4081 (parsed (parse-simple-duration duration))
4082 ;; Create the rest-stencil
4084 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
4085 ;; For MultiMeasureRests:
4086 ;; Get the duration-part of duration
4087 (dur-part-string (car (string-split duration #\. )))
4088 ;; Get the duration of MMR:
4089 ;; If not a number (eg. "maxima") calculate it.
4091 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
4092 ;; Get a list of the correct number of each mmr-glyph.
4093 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
4094 ;; Create a list of mmr-stencils,
4095 ;; translating the glyph for a whole rest.
4099 (let ((single-mmr-stil
4100 (rest-by-number-markup layout props (* -1 x) 0)))
4102 (ly:stencil-translate-axis
4104 ;; Ugh, hard-coded, why 1?
4108 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
4109 ;; Adjust the space between the mmr-glyphs,
4110 ;; if not default-glyphs are used.
4111 (word-space (if (member style
4112 '(neomensural mensural petrucci))
4113 (/ (* word-space 2) 3)
4115 ;; Create the final mmr-stencil
4116 ;; via `stack-stencil-lineĀ“ from /scm/markup.scm
4117 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
4119 ;; Print the number above a multi-measure-rest
4120 ;; Depends on duration, style and multi-measure-rest-number set #t
4121 (if (and multi-measure-rest
4122 multi-measure-rest-number
4124 (not (member style '(neomensural mensural petrucci))))
4125 (let* ((mmr-stil-x-center
4126 (interval-center (ly:stencil-extent mmr-stil X)))
4130 #:override '(font-encoding . fetaText)
4131 (number->string mmr-duration)))
4133 (interpret-markup layout props duration-markup))
4134 (mmr-number-stil-x-center
4135 (interval-center (ly:stencil-extent mmr-number-stil X))))
4137 (set! mmr-stil (ly:stencil-combine-at-edge
4140 (ly:stencil-translate-axis
4142 (- mmr-stil-x-center mmr-number-stil-x-center)
4146 (if multi-measure-rest
4150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4154 (define-markup-command (fermata layout props) ()
4156 #:properties ((direction UP))
4157 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
4158 an inverted glyph. Note that within music, one would usually use the
4159 @code{\\fermata} articulation instead of a markup.
4161 @lilypond[verbatim,quote]
4162 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
4164 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
4167 (interpret-markup layout props
4168 (if (eqv? direction DOWN)
4169 (markup #:musicglyph "scripts.dfermata")
4170 (markup #:musicglyph "scripts.ufermata"))))
4172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4176 (define-markup-command (lower layout props amount arg)
4180 @cindex lowering text
4182 Lower @var{arg} by the distance @var{amount}.
4183 A negative @var{amount} indicates raising; see also @code{\\raise}.
4185 @lilypond[verbatim,quote]
4193 (ly:stencil-translate-axis (interpret-markup layout props arg)
4196 (define-markup-command (translate-scaled layout props offset arg)
4197 (number-pair? markup?)
4199 #:properties ((font-size 0))
4201 @cindex translating text
4202 @cindex scaling text
4204 Translate @var{arg} by @var{offset}, scaling the offset by the
4207 @lilypond[verbatim,quote]
4210 * \\translate #'(2 . 3) translate
4212 * \\translate-scaled #'(2 . 3) translate-scaled
4216 (let* ((factor (magstep font-size))
4217 (scaled (cons (* factor (car offset))
4218 (* factor (cdr offset)))))
4219 (ly:stencil-translate (interpret-markup layout props arg)
4222 (define-markup-command (raise layout props amount arg)
4226 @cindex raising text
4228 Raise @var{arg} by the distance @var{amount}.
4229 A negative @var{amount} indicates lowering, see also @code{\\lower}.
4231 The argument to @code{\\raise} is the vertical displacement amount,
4232 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
4233 raise objects in relation to their surrounding markups.
4235 If the text object itself is positioned above or below the staff, then
4236 @code{\\raise} cannot be used to move it, since the mechanism that
4237 positions it next to the staff cancels any shift made with
4238 @code{\\raise}. For vertical positioning, use the @code{padding}
4239 and/or @code{extra-offset} properties.
4241 @lilypond[verbatim,quote]
4250 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4252 (define-markup-command (fraction layout props arg1 arg2)
4255 #:properties ((font-size 0))
4257 @cindex creating text fractions
4259 Make a fraction of two markups.
4260 @lilypond[verbatim,quote]
4266 (let* ((m1 (interpret-markup layout props arg1))
4267 (m2 (interpret-markup layout props arg2))
4268 (factor (magstep font-size))
4269 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4270 (padding (* factor 0.2))
4271 (baseline (* factor 0.6))
4272 (offset (* factor 0.75)))
4273 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4274 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4275 (let* ((x1 (ly:stencil-extent m1 X))
4276 (x2 (ly:stencil-extent m2 X))
4277 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4278 ;; should stack mols separately, to maintain LINE on baseline
4279 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4281 (ly:stencil-aligned-to stack Y CENTER))
4283 (ly:stencil-aligned-to stack X LEFT))
4284 ;; should have EX dimension
4286 (ly:stencil-translate-axis stack offset Y))))
4288 (define-markup-command (normal-size-super layout props arg)
4291 #:properties ((font-size 0))
4293 @cindex setting superscript in standard font size
4295 Set @var{arg} in superscript with a normal font size.
4297 @lilypond[verbatim,quote]
4300 \\normal-size-super {
4301 superscript in standard size
4305 (ly:stencil-translate-axis
4306 (interpret-markup layout props arg)
4307 (* 1.0 (magstep font-size)) Y))
4309 (define-markup-command (super layout props arg)
4312 #:properties ((font-size 0))
4314 @cindex superscript text
4316 Set @var{arg} in superscript.
4318 @lilypond[verbatim,quote]
4328 (ly:stencil-translate-axis
4331 (cons `((font-size . ,(- font-size 3))) props)
4333 (* 1.0 (magstep font-size)) ; original font-size
4336 (define-markup-command (translate layout props offset arg)
4337 (number-pair? markup?)
4340 @cindex translating text
4342 Translate @var{arg} relative to its surroundings. @var{offset}
4343 is a pair of numbers representing the displacement in the X and Y axis.
4345 @lilypond[verbatim,quote]
4348 \\translate #'(2 . 3)
4349 \\line { translated two spaces right, three up }
4352 (ly:stencil-translate (interpret-markup layout props arg)
4355 (define-markup-command (sub layout props arg)
4358 #:properties ((font-size 0))
4360 @cindex subscript text
4362 Set @var{arg} in subscript.
4364 @lilypond[verbatim,quote]
4375 (ly:stencil-translate-axis
4378 (cons `((font-size . ,(- font-size 3))) props)
4380 (* -0.75 (magstep font-size)) ; original font-size
4383 (define-markup-command (normal-size-sub layout props arg)
4386 #:properties ((font-size 0))
4388 @cindex setting subscript in standard font size
4390 Set @var{arg} in subscript with a normal font size.
4392 @lilypond[verbatim,quote]
4396 subscript in standard size
4400 (ly:stencil-translate-axis
4401 (interpret-markup layout props arg)
4402 (* -0.75 (magstep font-size))
4405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4409 (define-markup-command (hbracket layout props arg)
4413 @cindex placing horizontal brackets around text
4415 Draw horizontal brackets around @var{arg}.
4417 @lilypond[verbatim,quote]
4426 (let ((th 0.1) ;; todo: take from GROB.
4427 (m (interpret-markup layout props arg)))
4428 (bracketify-stencil m X th (* 2.5 th) th)))
4430 (define-markup-command (bracket layout props arg)
4434 @cindex placing vertical brackets around text
4436 Draw vertical brackets around @var{arg}.
4438 @lilypond[verbatim,quote]
4445 (let ((th 0.1) ;; todo: take from GROB.
4446 (m (interpret-markup layout props arg)))
4447 (bracketify-stencil m Y th (* 2.5 th) th)))
4449 (define-markup-command (parenthesize layout props arg)
4452 #:properties ((angularity 0)
4458 @cindex placing parentheses around text
4460 Draw parentheses around @var{arg}. This is useful for parenthesizing
4461 a column containing several lines of text.
4463 @lilypond[verbatim,quote]
4472 \\override #'(angularity . 2) {
4483 (let* ((m (interpret-markup layout props arg))
4484 (scaled-width (* size width))
4486 (* (chain-assoc-get 'line-thickness props 0.1)
4489 (min (* size 0.5 scaled-thickness)
4490 (* (/ 4 3.0) scaled-width)))
4491 (padding (chain-assoc-get 'padding props half-thickness)))
4492 (parenthesize-stencil
4493 m half-thickness scaled-width angularity padding)))
4496 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4497 ;; Delayed markup evaluation
4498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4500 (define-markup-command (page-ref layout props label gauge default)
4501 (symbol? markup? markup?)
4504 @cindex referencing page numbers in text
4506 Reference to a page number. @var{label} is the label set on the referenced
4507 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4508 the maximum width of the page number, and @var{default} the value to display
4509 when @var{label} is not found.
4511 (If the current book or bookpart is set to use roman numerals for page numbers,
4512 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4513 width may require additional tweaking.)"
4514 (let* ((gauge-stencil (interpret-markup layout props gauge))
4515 (x-ext (ly:stencil-extent gauge-stencil X))
4516 (y-ext (ly:stencil-extent gauge-stencil Y)))
4518 (make-transparent-box-stencil x-ext y-ext))
4520 `(delay-stencil-evaluation
4521 ,(delay (ly:stencil-expr
4522 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4523 (page-number (if (list? table)
4524 (assoc-get label table)
4526 (number-type (ly:output-def-lookup layout 'page-number-type))
4527 (page-markup (if page-number
4528 (number-format number-type page-number)
4530 (page-stencil (interpret-markup layout props page-markup))
4531 (gap (- (interval-length x-ext)
4532 (interval-length (ly:stencil-extent page-stencil X)))))
4533 (interpret-markup layout props
4534 (markup #:hspace gap page-markup))))))
4538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4542 (define-markup-command (scale layout props factor-pair arg)
4543 (number-pair? markup?)
4546 @cindex scaling markup
4547 @cindex mirroring markup
4549 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4550 representing the scaling-factor in the X and Y axes.
4551 Negative values may be used to produce mirror images.
4553 @lilypond[verbatim,quote]
4563 (let ((stil (interpret-markup layout props arg))
4564 (sx (car factor-pair))
4565 (sy (cdr factor-pair)))
4566 (ly:stencil-scale stil sx sy)))
4568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4572 (define-markup-command (pattern layout props count axis space pattern)
4573 (integer? integer? number? markup?)
4576 Prints @var{count} times a @var{pattern} markup.
4577 Patterns are spaced apart by @var{space}.
4578 Patterns are distributed on @var{axis}.
4580 @lilypond[verbatim, quote]
4582 \"Horizontally repeated :\"
4583 \\pattern #7 #X #2 \\flat
4585 \"Vertically repeated :\"
4586 \\pattern #3 #Y #0.5 \\flat
4589 (let ((pattern-width (interval-length
4590 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4591 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4592 (let loop ((i (1- count)) (patterns (markup)))
4598 (markup patterns pattern)
4599 (markup #:column (patterns pattern))))
4602 (markup patterns pattern #:hspace space)
4603 (markup #:column (patterns pattern #:vspace space))))))))
4605 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4606 (number? ly:dir? markup? markup? markup?)
4608 #:properties ((word-space)
4611 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4612 with a line of markups @var{pattern} in between.
4613 Patterns are spaced apart by @var{space}.
4614 Patterns are aligned to the @var{dir} markup.
4616 @lilypond[verbatim, quote]
4619 \\fill-with-pattern #1 #RIGHT . first right
4620 \\fill-with-pattern #1 #RIGHT . second right
4622 \"center-aligned :\"
4623 \\fill-with-pattern #1.5 #CENTER - left right
4626 \\override #'(line-width . 50)
4627 \\fill-with-pattern #2 #LEFT : left first
4628 \\override #'(line-width . 50)
4629 \\fill-with-pattern #2 #LEFT : left second
4632 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4633 (pattern-width (interval-length pattern-x-extent))
4634 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4635 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4636 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4637 (period (+ space pattern-width))
4638 (count (truncate (/ (- middle-width pattern-width) period)))
4639 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4640 (interpret-markup layout props
4642 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4643 #:translate (cons x-offset 0)
4644 #:pattern (1+ count) X space pattern
4647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4651 (define-markup-command (replace layout props replacements arg)
4655 Used to automatically replace a string by another in the markup @var{arg}.
4656 Each pair of the alist @var{replacements} specifies what should be replaced.
4657 The @code{key} is the string to be replaced by the @code{value} string.
4659 @lilypond[verbatim, quote]
4660 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4664 (internal-add-text-replacements
4669 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4670 ;; Markup list commands
4671 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4673 (define-public (space-lines baseline stils)
4674 (let space-stil ((stils stils)
4678 (let* ((stil (car stils))
4679 (dy-top (max (- (/ baseline 1.5)
4680 (interval-bound (ly:stencil-extent stil Y) UP))
4682 (dy-bottom (max (+ (/ baseline 3.0)
4683 (interval-bound (ly:stencil-extent stil Y) DOWN))
4685 (new-stil (ly:make-stencil
4686 (ly:stencil-expr stil)
4687 (ly:stencil-extent stil X)
4688 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4690 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4692 (space-stil (cdr stils) (cons new-stil result))))))
4694 (define-markup-list-command (justified-lines layout props args)
4696 #:properties ((baseline-skip)
4697 wordwrap-internal-markup-list)
4699 @cindex justifying lines of text
4701 Like @code{\\justify}, but return a list of lines instead of a single markup.
4702 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4703 @var{X}@tie{}is the number of staff spaces."
4704 (space-lines baseline-skip
4705 (interpret-markup-list layout props
4706 (make-wordwrap-internal-markup-list #t args))))
4708 (define-markup-list-command (wordwrap-lines layout props args)
4710 #:properties ((baseline-skip)
4711 wordwrap-internal-markup-list)
4712 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4713 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4714 where @var{X} is the number of staff spaces."
4715 (space-lines baseline-skip
4716 (interpret-markup-list layout props
4717 (make-wordwrap-internal-markup-list #f args))))
4719 (define-markup-list-command (column-lines layout props args)
4721 #:properties ((baseline-skip))
4722 "Like @code{\\column}, but return a list of lines instead of a single markup.
4723 @code{baseline-skip} determines the space between each markup in @var{args}."
4724 (space-lines baseline-skip
4725 (interpret-markup-list layout props args)))
4727 (define-markup-list-command (override-lines layout props new-prop args)
4728 (pair? markup-list?)
4729 "Like @code{\\override}, for markup lists."
4730 (interpret-markup-list layout (cons (list new-prop) props) args))
4732 (define-markup-list-command (table layout props column-align lst)
4733 (number-list? markup-list?)
4734 #:properties ((padding 0)
4736 "@cindex creating a table.
4740 @var{column-align} specifies how each column is aligned, possible values are
4741 -1, 0, 1. The number of elements in @var{column-align} determines how many
4742 columns will be printed.
4743 The entries to print are given by @var{lst}, a markup-list. If needed, the last
4744 row is filled up with @code{point-stencil}s.
4745 Overriding @code{padding} may be used to increase columns horizontal distance.
4746 Overriding @code{baseline-skip} to increase rows vertical distance.
4747 @lilypond[verbatim,quote]
4749 \\override #'(padding . 2)
4753 \\underline { center-aligned right-aligned center-aligned left-aligned }
4754 one \\number 1 thousandth \\number 0.001
4755 eleven \\number 11 hundredth \\number 0.01
4756 twenty \\number 20 tenth \\number 0.1
4757 thousand \\number 1000 one \\number 1.0
4763 (define (split-lst initial-lst lngth result-lst)
4764 ;; split a list into a list of sublists of length lngth
4765 ;; eg. (split-lst '(1 2 3 4 5 6) 2 '())
4766 ;; -> ((1 2) (3 4) (5 6))
4767 (cond ((not (integer? (/ (length initial-lst) lngth)))
4769 "Can't split list of length ~a into ~a parts, returning empty list"
4770 (length initial-lst) lngth)
4772 ((null? initial-lst)
4773 (reverse result-lst))
4776 (drop initial-lst lngth)
4778 (cons (take initial-lst lngth) result-lst)))))
4780 (define (dists-list init padding lst)
4781 ;; Returns a list, where each element of `lst' is
4782 ;; added to the sum of the previous elements of `lst' plus padding.
4783 ;; `init' will be the first element of the resulting list. The addition
4784 ;; starts with the values of `init', `padding' and `(car lst)'.
4785 ;; eg. (dists-list 0.01 0.1 '(1 2 3 4)))
4786 ;; -> (0.01 1.11 3.21 6.31 10.41)
4787 (if (or (not (number? init))
4788 (not (number? padding))
4789 (not (number-list? lst)))
4792 "not fitting argument for `dists-list', return empty lst ")
4795 (fold (lambda (elem rl) (cons (+ elem padding (car rl)) rl))
4799 (let* (;; get the number of columns
4800 (columns (length column-align))
4801 (init-stils (interpret-markup-list layout props lst))
4802 ;; If the given markup-list is the result of a markup-list call, their
4803 ;; length may not be easily predictable, thus we add point-stencils
4804 ;; to fill last row of the table.
4805 (rem (remainder (length init-stils) columns))
4809 (append init-stils (make-list (- columns rem) point-stencil))))
4810 ;; get the stencils in sublists of length `columns'
4812 (split-lst filled-stils columns '()))
4813 ;; procedure to return stencil-length
4814 ;; If it is nan, return 0
4817 (let ((lngth (interval-length (ly:stencil-extent m X))))
4818 (if (nan? lngth) 0 lngth))))
4819 ;; get the max width of each column in a list
4820 (columns-max-x-lengths
4826 (map (lambda (l) (list-ref l x)) stils))))
4828 ;; create a list of (basic) distances, which each column should
4829 ;; moved, using `dists-list'. Some padding may be added.
4831 (dists-list 0 padding columns-max-x-lengths))
4832 ;; Get all stencils of a row, moved accurately to build columns.
4833 ;; If the items of a column are aligned other than left, we need to
4834 ;; move them to avoid collisions:
4835 ;; center aligned: move all items half the width of the widest item
4836 ;; right aligned: move all items the full width of the widest item.
4837 ;; Added to the default-offset calculated in `dist-sequence'.
4838 ;; `stencils-for-row-proc' needs four arguments:
4840 ;; dist - a numerical value as basic offset in X direction
4841 ;; column - a numerical value for the column we're in
4842 ;; x-align - a numerical value how current column should be
4843 ;; aligned, where (-1, 0, 1) means (LEFT, CENTER, RIGHT)
4844 (stencils-for-row-proc
4845 (lambda (stil dist column x-align)
4846 (ly:stencil-translate-axis
4847 (ly:stencil-aligned-to stil X x-align)
4848 (cond ((member x-align '(0 1))
4849 (let* (;; get the stuff for relevant column
4852 (lambda (s) (list-ref s column))
4854 ;; get length of every column-item
4856 (map lengths-proc stuff-for-column))
4858 (apply max 0 lengths-for-column)))
4859 (+ dist (/ widest (if (= x-align 0) 2 1)))))
4862 ;; get a list of rows using `ly:stencil-add' on a list of stencils
4866 (apply ly:stencil-add
4868 ;; the procedure creating the stencils:
4869 stencils-for-row-proc
4870 ;; the procedure's args:
4876 (space-lines baseline-skip rows)))
4878 (define-markup-list-command (map-markup-commands layout props compose args)
4879 (procedure? markup-list?)
4880 "This applies the function @var{compose} to every markup in
4881 @var{args} (including elements of markup list command calls) in order
4882 to produce a new markup list. Since the return value from a markup
4883 list command call is not a markup list but rather a list of stencils,
4884 this requires passing those stencils off as the results of individual
4885 markup calls. That way, the results should work out as long as no
4886 markups rely on side effects."
4887 (let ((key (make-symbol "key")))
4891 ;; if `compose' does not actually interpret its markup
4892 ;; argument, we still need to return a list of stencils,
4893 ;; created from the single returned stencil
4895 (interpret-markup layout props
4897 (make-on-the-fly-markup
4898 (lambda (layout props m)
4899 ;; here all effects of `compose' on the
4900 ;; properties should be visible, so we
4901 ;; call interpret-markup-list at this
4902 ;; point of time and harvest its
4905 (interpret-markup-list
4906 layout props args)))
4907 (make-null-markup))))))
4908 (lambda (key stencils)
4911 (interpret-markup layout props
4912 (compose (make-stencil-markup sten))))