1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Markup commands and markup-list commands definitions.
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-markup-command' macro.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
42 ;;; `layout' is an output def, which properties can be accessed
43 ;;; using `ly:output-def-lookup'.
44 ;;; `props' is a list of property settings which can be accessed
45 ;;; using `chain-assoc-get' (more on that below)
48 ;;; the command arguments.
49 ;;; There is no limitation on the order of command arguments.
50 ;;; However, markup functions taking a markup as their last
51 ;;; argument are somewhat special as you can apply them to a
52 ;;; markup list, and the result is a markup list where the
53 ;;; markup function (with the specified leading arguments) has
54 ;;; been applied to every element of the original markup list.
56 ;;; Since replicating the leading arguments for applying a
57 ;;; markup function to a markup list is cheap mostly for
58 ;;; Scheme arguments, you avoid performance pitfalls by just
59 ;;; using Scheme arguments for the leading arguments of markup
60 ;;; functions that take a markup as their last argument.
63 ;;; the arguments signature, i.e., a list of type predicates which
64 ;;; are used to type check the arguments, and also to define the general
65 ;;; argument types (markup, markup-list, scheme) that the command is
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
71 ;;; for documentation purpose, builtin markup commands are grouped by
72 ;;; category. This can be any symbol. When documentation is generated,
73 ;;; the symbol is converted to a capitalized string, where hyphens are
74 ;;; replaced by spaces.
77 ;;; this is used both for documentation generation, and to ease
78 ;;; programming the command itself. It is list of
79 ;;; (property-name default-value)
80 ;;; or (property-name)
81 ;;; elements. Each property is looked-up in the `props' argument, and
82 ;;; the symbol naming the property is bound to its value.
83 ;;; When the property is not found in `props', then the symbol is bound
84 ;;; to the given default value. When no default value is given, #f is
86 ;;; Thus, using the following property bindings:
89 ;;; is equivalent to writing:
90 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;; (font-size (chain-assoc-get 'font-size props 0)))
93 ;;; When a command `B' internally calls an other command `A', it may
94 ;;; desirable to see in `B' documentation all the properties and
95 ;;; default values used by `A'. In that case, add `A-markup' to the
96 ;;; property-bindings of B. (This is used when generating
97 ;;; documentation, but won't create bindings.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '()
115 empty-interval empty-interval))
116 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;; line has to come early since it is often used implicitly from the
120 ;; markup macro since \markup { a b c } -> \markup \line { a b c }
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 (define-markup-command (line layout props args)
126 #:properties ((word-space)
127 (text-direction RIGHT))
128 "Put @var{args} in a horizontal line. The property @code{word-space}
129 determines the space between markups in @var{args}.
131 @lilypond[verbatim,quote]
138 (let ((stencils (interpret-markup-list layout props args)))
139 (if (= text-direction LEFT)
140 (set! stencils (reverse stencils)))
141 (stack-stencil-line word-space stencils)))
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 (define-markup-command (draw-line layout props dest)
150 #:properties ((thickness 1))
152 @cindex drawing lines within text
155 @lilypond[verbatim,quote]
157 \\draw-line #'(4 . 4)
158 \\override #'(thickness . 5)
159 \\draw-line #'(-3 . 0)
162 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
166 (make-line-stencil th 0 0 x y)))
168 (define-markup-command (draw-dashed-line layout props dest)
171 #:properties ((thickness 1)
177 @cindex drawing dashed lines within text
181 If @code{full-length} is set to #t (default) the dashed-line extends to the
182 whole length given by @var{dest}, without white space at beginning or end.
183 @code{off} will then be altered to fit.
184 To insist on the given (or default) values of @code{on}, @code{off} use
185 @code{\\override #'(full-length . #f)}
186 Manual settings for @code{on},@code{off} and @code{phase} are possible.
187 @lilypond[verbatim,quote]
189 \\draw-dashed-line #'(5.1 . 2.3)
190 \\override #'(on . 0.3)
191 \\override #'(off . 0.5)
192 \\draw-dashed-line #'(5.1 . 2.3)
195 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
196 ;; Calculate the thickness to be used.
197 (th (* line-thickness thickness))
198 (half-thick (/ th 2))
199 ;; Get the extensions in x- and y-direction.
202 ;; Calculate the length of the dashed line.
203 (line-length (sqrt (+ (expt x 2) (expt y 2)))))
205 (if (and full-length (not (= (+ on off) 0)))
207 ;; Add double-thickness to avoid overlapping.
208 (set! off (+ (* 2 th) off))
209 (let* (;; Make a guess how often the off/on-pair should be printed
210 ;; after the initial `onĀ“.
211 ;; Assume a minimum of 1 to avoid division by zero.
212 (guess (max 1 (round (/ (- line-length on) (+ off on)))))
213 ;; Not sure about the value or why corr is necessary at all,
214 ;; but it seems to be necessary.
216 (/ line-thickness 10)
218 ;; Calculate a new value for off to fit the
220 (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
224 ;; Settings for (= on 0). Resulting in a dotted line.
226 ;; If line-length isn't shorter than `thĀ“, change the given
227 ;; value for `offĀ“ to fit the line-length.
228 ((and (= on 0) (< th line-length))
231 ;; If the line-length is shorter than `thĀ“, it makes no
232 ;; sense to adjust `offĀ“. The rounded edges of the lines
233 ;; would prevent any nice output.
235 ;; This will result in a single dot for very short lines.
236 ((and (= on 0) (>= th line-length))
239 ;; Settings for (not (= on 0)). Resulting in a dashed line.
241 ;; If line-length isn't shorter than one go of on-off-on,
242 ;; change the given value for `offĀ“ to fit the line-length.
243 ((< (+ (* 2 on) off) line-length)
245 ;; If the line-length is too short, but greater than
246 ;; (* 4 th) set on/off to (/ line-length 3)
247 ((< (* 4 th) line-length)
248 (set! on (/ line-length 3))
249 (set! off (/ line-length 3)))
250 ;; If the line-length is shorter than (* 4 th), it makes
251 ;; no sense trying to adjust on/off. The rounded edges of
252 ;; the lines would prevent any nice output.
253 ;; Simply set `onĀ“ to line-length.
255 (set! on line-length))))))
257 ;; If `onĀ“ or `offĀ“ is negative, or the sum of `on' and `off' equals zero a
258 ;; ghostscript-error occurs while calling
259 ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
260 ;; Better be paranoid.
261 (if (or (= (+ on off) 0)
265 (ly:warning "Can't print a line - setting on/off to default")
269 ;; To give the lines produced by \draw-line and \draw-dashed-line the same
270 ;; length, half-thick has to be added to the stencil-extensions.
272 (list 'dashed-line th on off x y phase)
273 (interval-widen (ordered-cons 0 x) half-thick)
274 (interval-widen (ordered-cons 0 y) half-thick))))
276 (define-markup-command (draw-dotted-line layout props dest)
279 #:properties ((thickness 1)
283 @cindex drawing dotted lines within text
287 The dotted-line always extends to the whole length given by @var{dest}, without
288 white space at beginning or end.
289 Manual settings for @code{off} are possible to get larger or smaller space
291 The given (or default) value of @code{off} will be altered to fit the
293 @lilypond[verbatim,quote]
295 \\draw-dotted-line #'(5.1 . 2.3)
296 \\override #'(thickness . 2)
297 \\override #'(off . 0.2)
298 \\draw-dotted-line #'(5.1 . 2.3)
302 (let ((new-props (prepend-alist-chain 'on 0
303 (prepend-alist-chain 'full-length #t props))))
305 (interpret-markup layout
307 (markup #:draw-dashed-line dest))))
309 (define-markup-command (draw-hline layout props)
312 #:properties ((draw-line-markup)
316 @cindex drawing a line across a page
318 Draws a line across a page, where the property @code{span-factor}
319 controls what fraction of the page is taken up.
320 @lilypond[verbatim,quote]
324 \\override #'(span-factor . 1/3)
329 (interpret-markup layout
331 (markup #:draw-line (cons (* line-width
335 (define-markup-command (draw-circle layout props radius thickness filled)
336 (number? number? boolean?)
339 @cindex drawing circles within text
341 A circle of radius @var{radius} and thickness @var{thickness},
344 @lilypond[verbatim,quote]
346 \\draw-circle #2 #0.5 ##f
348 \\draw-circle #2 #0 ##t
351 (make-circle-stencil radius thickness filled))
353 (define-markup-command (triangle layout props filled)
356 #:properties ((thickness 0.1)
360 @cindex drawing triangles within text
362 A triangle, either filled or empty.
364 @lilypond[verbatim,quote]
371 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
380 (cons 0 (* .86 ex)))))
382 (define-markup-command (circle layout props arg)
385 #:properties ((thickness 1)
387 (circle-padding 0.2))
389 @cindex circling text
391 Draw a circle around @var{arg}. Use @code{thickness},
392 @code{circle-padding} and @code{font-size} properties to determine line
393 thickness and padding around the markup.
395 @lilypond[verbatim,quote]
402 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
404 (pad (* (magstep font-size) circle-padding))
405 (m (interpret-markup layout props arg)))
406 (circle-stencil m th pad)))
408 (define-markup-command (ellipse layout props arg)
411 #:properties ((thickness 1)
416 @cindex drawing ellipse around text
418 Draw an ellipse around @var{arg}. Use @code{thickness},
419 @code{x-padding}, @code{y-padding} and @code{font-size} properties to determine
420 line thickness and padding around the markup.
422 @lilypond[verbatim,quote]
429 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
431 (pad-x (* (magstep font-size) x-padding))
432 (pad-y (* (magstep font-size) y-padding))
433 (m (interpret-markup layout props arg)))
434 (ellipse-stencil m th pad-x pad-y)))
436 (define-markup-command (oval layout props arg)
439 #:properties ((thickness 1)
444 @cindex drawing oval around text
446 Draw an oval around @var{arg}. Use @code{thickness},
447 @code{x-padding}, @code{x-padding} and @code{font-size} properties to determine
448 line thickness and padding around the markup.
450 @lilypond[verbatim,quote]
457 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
459 (pad-x (* (magstep font-size) x-padding))
460 (pad-y (* (magstep font-size) y-padding))
461 (m (interpret-markup layout props arg)))
462 (oval-stencil m th pad-x pad-y)))
464 (define-markup-command (with-url layout props url arg)
468 @cindex inserting URL links into text
470 Add a link to URL @var{url} around @var{arg}. This only works in
473 @lilypond[verbatim,quote]
475 \\with-url #\"http://lilypond.org/\" {
476 LilyPond ... \\italic {
477 music notation for everyone
482 (let* ((stil (interpret-markup layout props arg))
483 (xextent (ly:stencil-extent stil X))
484 (yextent (ly:stencil-extent stil Y))
485 (old-expr (ly:stencil-expr stil))
486 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
488 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
490 (define-markup-command (page-link layout props page-number arg)
494 @cindex referencing page numbers in text
496 Add a link to the page @var{page-number} around @var{arg}. This only works
499 @lilypond[verbatim,quote]
501 \\page-link #2 { \\italic { This links to page 2... } }
504 (let* ((stil (interpret-markup layout props arg))
505 (xextent (ly:stencil-extent stil X))
506 (yextent (ly:stencil-extent stil Y))
507 (old-expr (ly:stencil-expr stil))
508 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
510 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
512 (define-markup-command (with-link layout props label arg)
516 @cindex referencing page labels in text
518 Add a link to the page holding label @var{label} around @var{arg}. This
519 only works in the PDF backend.
521 @lilypond[verbatim,quote]
523 \\with-link #'label {
524 \\italic { This links to the page containing the label... }
528 (let* ((arg-stencil (interpret-markup layout props arg))
529 (x-ext (ly:stencil-extent arg-stencil X))
530 (y-ext (ly:stencil-extent arg-stencil Y)))
533 `(delay-stencil-evaluation
534 ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
537 (assoc-get label table)
540 (ly:output-def-lookup layout 'first-page-number))
542 (if table-page-number
543 (1+ (- table-page-number first-page-number))
545 (list 'page-link current-page-number
546 `(quote ,x-ext) `(quote ,y-ext)))))
551 (define-markup-command (beam layout props width slope thickness)
552 (number? number? number?)
555 @cindex drawing beams within text
557 Create a beam with the specified parameters.
558 @lilypond[verbatim,quote]
563 (let* ((y (* slope width))
564 (yext (cons (min 0 y) (max 0 y)))
565 (half (/ thickness 2)))
570 width (+ (* width slope) (/ thickness -2))
571 width (+ (* width slope) (/ thickness 2))
573 ,(ly:output-def-lookup layout 'blot-diameter)
576 (cons (+ (- half) (car yext))
577 (+ half (cdr yext))))))
579 (define-markup-command (underline layout props arg)
582 #:properties ((thickness 1) (offset 2))
584 @cindex underlining text
586 Underline @var{arg}. Looks at @code{thickness} to determine line
587 thickness, and @code{offset} to determine line y-offset.
589 @lilypond[verbatim,quote]
590 \\markup \\fill-line {
591 \\underline \"underlined\"
592 \\override #'(offset . 5)
593 \\override #'(thickness . 1)
594 \\underline \"underlined\"
595 \\override #'(offset . 1)
596 \\override #'(thickness . 5)
597 \\underline \"underlined\"
600 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
601 (underline-thick (* thickness thick))
602 (m (interpret-markup layout props arg))
603 (x1 (car (ly:stencil-extent m X)))
604 (x2 (cdr (ly:stencil-extent m X)))
605 (y (* thick (- offset)))
606 (line (make-line-stencil underline-thick x1 y x2 y)))
607 (ly:stencil-add m line)))
609 (define-markup-command (box layout props arg)
612 #:properties ((thickness 1)
616 @cindex enclosing text within a box
618 Draw a box round @var{arg}. Looks at @code{thickness},
619 @code{box-padding} and @code{font-size} properties to determine line
620 thickness and padding around the markup.
622 @lilypond[verbatim,quote]
624 \\override #'(box-padding . 0.5)
629 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
631 (pad (* (magstep font-size) box-padding))
632 (m (interpret-markup layout props arg)))
633 (box-stencil m th pad)))
635 (define-markup-command (filled-box layout props xext yext blot)
636 (number-pair? number-pair? number?)
639 @cindex drawing solid boxes within text
640 @cindex drawing boxes with rounded corners
642 Draw a box with rounded corners of dimensions @var{xext} and
643 @var{yext}. For example,
645 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
647 creates a box extending horizontally from -0.3 to 1.8 and
648 vertically from -0.3 up to 1.8, with corners formed from a
649 circle of diameter@tie{}0 (i.e., sharp corners).
651 @lilypond[verbatim,quote]
653 \\filled-box #'(0 . 4) #'(0 . 4) #0
654 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
655 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
657 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
663 (define-markup-command (rounded-box layout props arg)
666 #:properties ((thickness 1)
670 "@cindex enclosing text in a box with rounded corners
671 @cindex drawing boxes with rounded corners around text
672 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
673 @code{box-padding} and @code{font-size} properties to determine line
674 thickness and padding around the markup; the @code{corner-radius} property
675 makes it possible to define another shape for the corners (default is 1).
677 @lilypond[quote,verbatim,relative=2]
685 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
687 (pad (* (magstep font-size) box-padding))
688 (m (interpret-markup layout props arg)))
689 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
692 (define-markup-command (rotate layout props ang arg)
696 @cindex rotating text
698 Rotate object with @var{ang} degrees around its center.
700 @lilypond[verbatim,quote]
710 (let* ((stil (interpret-markup layout props arg)))
711 (ly:stencil-rotate stil ang 0 0)))
713 (define-markup-command (whiteout layout props arg)
716 #:properties ((thickness 3))
718 @cindex adding a white background to text
720 Provide a white background for @var{arg}.
722 @lilypond[verbatim,quote]
725 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
726 \\override #'(thickness . 1.5) \\whiteout whiteout
730 (interpret-markup layout props arg)
732 (ly:output-def-lookup layout 'line-thickness))))
734 (define-markup-command (whiteout-box layout props arg)
738 @cindex adding a rounded rectangular white background to text
740 Provide a rounded rectangular white background for @var{arg}.
742 @lilypond[verbatim,quote]
745 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
746 \\whiteout-box whiteout-box
749 (stencil-whiteout-box (interpret-markup layout props arg)))
751 (define-markup-command (pad-markup layout props amount arg)
756 @cindex putting space around text
758 Add space around a markup object.
759 Identical to @code{pad-around}.
761 @lilypond[verbatim,quote]
774 (let* ((m (interpret-markup layout props arg))
775 (x (interval-widen (ly:stencil-extent m X) amount))
776 (y (interval-widen (ly:stencil-extent m Y) amount)))
777 (ly:stencil-add (make-transparent-box-stencil x y)
780 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
784 (define-markup-command (strut layout props)
788 @cindex creating vertical spaces in text
790 Create a box of the same height as the space in the current font."
791 (let ((m (ly:text-interface::interpret-markup layout props " ")))
792 (ly:make-stencil (ly:stencil-expr m)
794 (ly:stencil-extent m X)
797 (define-markup-command (hspace layout props amount)
801 @cindex creating horizontal spaces in text
803 Create an invisible object taking up horizontal space @var{amount}.
805 @lilypond[verbatim,quote]
814 (ly:make-stencil "" (cons 0 amount) empty-interval))
816 (define-markup-command (vspace layout props amount)
820 @cindex creating vertical spaces in text
822 Create an invisible object taking up vertical space
823 of @var{amount} multiplied by 3.
825 @lilypond[verbatim,quote]
836 (let ((amount (* amount 3.0)))
837 (ly:make-stencil "" empty-interval (cons 0 amount))))
840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841 ;; importing graphics.
842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
844 (define-markup-command (stencil layout props stil)
848 @cindex importing stencils into text
850 Use a stencil as markup.
852 @lilypond[verbatim,quote]
854 \\stencil #(make-circle-stencil 2 0 #t)
860 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
862 (define (get-postscript-bbox string)
863 "Extract the bbox from STRING, or return #f if not present."
865 ((match (regexp-exec bbox-regexp string)))
869 (string->number (match:substring match x)))
874 (define-markup-command (epsfile layout props axis size file-name)
875 (number? number? string?)
878 @cindex inlining an Encapsulated PostScript image
880 Inline an EPS image. The image is scaled along @var{axis} to
883 @lilypond[verbatim,quote]
885 \\general-align #Y #DOWN {
886 \\epsfile #X #20 #\"context-example.eps\"
887 \\epsfile #Y #20 #\"context-example.eps\"
891 (if (ly:get-option 'safe)
892 (interpret-markup layout props "not allowed in safe")
893 (eps-file->stencil axis size file-name)
896 (define-markup-command (postscript layout props str)
900 @cindex inserting PostScript directly into text
901 This inserts @var{str} directly into the output as a PostScript
904 @lilypond[verbatim,quote]
908 0.4 0.6 0.5 0 361 arc
910 1.0 0.6 0.5 0 361 arc
915 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
916 \\postscript #ringsps
928 gsave currentpoint translate
936 (define-markup-command (path layout props thickness commands) (number? list?)
938 #:properties ((line-cap-style 'round)
939 (line-join-style 'round)
942 @cindex paths, drawing
943 @cindex drawing paths
944 Draws a path with line @var{thickness} according to the
945 directions given in @var{commands}. @var{commands} is a list of
946 lists where the @code{car} of each sublist is a drawing command and
947 the @code{cdr} comprises the associated arguments for each command.
949 There are seven commands available to use in the list
950 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
951 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
952 @code{closepath}. Note that the commands that begin with @emph{r}
953 are the relative variants of the other three commands.
955 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
956 @code{rlineto} take 2 arguments; they are the X and Y coordinates
957 for the destination point.
959 The commands @code{curveto} and @code{rcurveto} create cubic
960 BĆ©zier curves, and take 6 arguments; the first two are the X and Y
961 coordinates for the first control point, the second two are the X
962 and Y coordinates for the second control point, and the last two
963 are the X and Y coordinates for the destination point.
965 The @code{closepath} command takes zero arguments and closes the
966 current subpath in the active path.
968 Note that a sequence of commands @emph{must} begin with a
969 @code{moveto} or @code{rmoveto} to work with the SVG output.
971 Line-cap styles and line-join styles may be customized by
972 overriding the @code{line-cap-style} and @code{line-join-style}
973 properties, respectively. Available line-cap styles are
974 @code{'butt}, @code{'round}, and @code{'square}. Available
975 line-join styles are @code{'miter}, @code{'round}, and
978 The property @code{filled} specifies whether or not the path is
981 @lilypond[verbatim,quote]
987 (curveto -5 -5 -5 5 -1 0)
991 \\path #0.25 #samplePath
993 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
995 \\override #'(filled . #t) \\path #0.25 #samplePath
998 (let* ((half-thickness (/ thickness 2))
999 (current-point '(0 . 0))
1000 (set-point (lambda (lst) (set! current-point lst)))
1001 (relative? (lambda (x)
1002 (string-prefix? "r" (symbol->string (car x)))))
1003 ;; For calculating extents, we want to modify the command
1004 ;; list so that all coordinates are absolute.
1005 (new-commands (map (lambda (x)
1007 ;; for rmoveto, rlineto
1008 ((and (relative? x) (= 3 (length x)))
1010 (+ (car current-point)
1012 (+ (cdr current-point)
1018 ((and (relative? x) (= 7 (length x)))
1019 (let* ((old-cp current-point)
1026 (list (+ (car old-cp) (second x))
1027 (+ (cdr old-cp) (third x))
1028 (+ (car old-cp) (fourth x))
1029 (+ (cdr old-cp) (fifth x))
1032 ;; for moveto, lineto
1034 (set-point (cons (second x)
1039 (set-point (cons (sixth x)
1042 ;; keep closepath for filtering;
1043 ;; see `without-closepath'.
1046 ;; path-min-max does not accept 0-arg lists,
1047 ;; and since closepath does not affect extents, filter
1048 ;; out those commands here.
1049 (without-closepath (filter (lambda (x)
1050 (not (equal? 'closepath (car x))))
1052 (extents (path-min-max
1053 ;; set the origin to the first moveto
1054 (list (list-ref (car without-closepath) 0)
1055 (list-ref (car without-closepath) 1))
1057 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1058 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1059 (command-list (fold-right append '() commands)))
1061 ;; account for line thickness
1062 (set! X-extent (interval-widen X-extent half-thickness))
1063 (set! Y-extent (interval-widen Y-extent half-thickness))
1066 `(path ,thickness `(,@',command-list)
1067 ',line-cap-style ',line-join-style ,filled)
1071 (define-markup-list-command (score-lines layout props score)
1073 "This is the same as the @code{\\score} markup but delivers its
1074 systems as a list of lines. Its @var{score} argument is entered in
1075 braces like it would be for @code{\\score}."
1076 (let ((output (ly:score-embedded-format score layout)))
1078 (if (ly:music-output? output)
1080 (lambda (paper-system)
1081 ;; shift such that the refpoint of the bottom staff of
1082 ;; the first system is the baseline of the score
1083 (ly:stencil-translate-axis
1084 (paper-system-stencil paper-system)
1085 (- (car (paper-system-staff-extents paper-system)))
1087 (vector->list (ly:paper-score-paper-systems output)))
1089 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1092 (define-markup-command (score layout props score)
1095 #:properties ((baseline-skip))
1097 @cindex inserting music into text
1099 Inline an image of music. The reference point (usually the middle
1100 staff line) of the lowest staff in the top system is placed on the
1103 @lilypond[verbatim,quote]
1107 \\new Staff \\relative c' {
1110 \\mark \\markup { Allegro }
1116 \\new Staff \\relative c {
1122 f,( bes d bes d bes)
1130 \\override RehearsalMark
1131 #'break-align-symbols = #'(time-signature key-signature)
1132 \\override RehearsalMark
1133 #'self-alignment-X = #LEFT
1137 \\override TimeSignature
1138 #'break-align-anchor-alignment = #LEFT
1144 (stack-stencils Y DOWN baseline-skip
1145 (score-lines-markup-list layout props score)))
1147 (define-markup-command (null layout props)
1151 @cindex creating empty text objects
1153 An empty markup with extents of a single point.
1155 @lilypond[verbatim,quote]
1162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1163 ;; basic formatting.
1164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1166 (define-markup-command (simple layout props str)
1170 @cindex simple text strings
1172 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1173 @code{\\markup @{ \\simple #\"foo\" @}}.
1175 Note: for creating standard text markup or defining new markup commands,
1176 the use of @code{\\simple} is unnecessary.
1178 @lilypond[verbatim,quote]
1180 \\simple #\"simple\"
1182 \\simple #\"strings\"
1185 (interpret-markup layout props str))
1187 (define-markup-command (first-visible layout props args)
1190 "Use the first markup in @var{args} that yields a non-empty stencil
1191 and ignore the rest.
1193 @lilypond[verbatim,quote]
1196 \\fromproperty #'header:composer
1201 (define (false-if-empty stencil)
1202 (if (ly:stencil-empty? stencil) #f stencil))
1207 (false-if-empty (interpret-markup layout props m))
1208 (any false-if-empty (interpret-markup-list layout props (list m)))))
1212 (define-public empty-markup
1213 (make-simple-markup ""))
1215 ;; helper for justifying lines.
1216 (define (get-fill-space
1217 word-count line-width word-space text-widths constant-space?)
1218 "Calculate the necessary paddings between adjacent texts in a
1219 single justified line. The lengths of all texts are stored in
1221 When @var{constant-space?} is @code{#t}, the formula for the padding
1223 padding = (line-width - total-text-width)/(word-count - 1)
1224 When @var{constant-space?} is @code{#f}, the formula for the
1225 padding between interior texts a and b is:
1226 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1227 In this case, the first and last padding have to be calculated
1228 specially using the whole length of the first or last text.
1229 All paddings are checked to be at least word-space, to ensure that
1231 Return a list of paddings."
1233 ((null? text-widths) '())
1237 ;; Ensure that space between words cannot be
1238 ;; less than word-space.
1241 (/ (- line-width (apply + text-widths))
1244 ;; special case first padding
1245 ((= (length text-widths) word-count)
1247 (- (- (/ line-width (1- word-count)) (car text-widths))
1248 (/ (cadr text-widths) 2))
1250 word-count line-width word-space (cdr text-widths)
1252 ;; special case last padding
1253 ((= (length text-widths) 2)
1254 (list (- (/ line-width (1- word-count))
1255 (+ (/ (car text-widths) 2) (cadr text-widths)))
1258 (let ((default-padding
1259 (- (/ line-width (1- word-count))
1260 (/ (+ (car text-widths) (cadr text-widths)) 2))))
1262 (if (> word-space default-padding)
1266 word-count line-width word-space (cdr text-widths)
1267 constant-space?))))))
1269 (define (justify-line-helper
1270 layout props args text-direction word-space line-width constant-space?)
1271 "Return a stencil which spreads @var{args} along a line of width
1272 @var{line-width}. If @var{constant-space?} is set to @code{#t}, the
1273 space between words is constant. If @code{#f}, the distance between
1274 words varies according to their relative lengths."
1275 (let* ((orig-stencils (interpret-markup-list layout props args))
1278 (if (ly:stencil-empty? stc X)
1279 (ly:make-stencil (ly:stencil-expr stc)
1280 '(0 . 0) (ly:stencil-extent stc Y))
1285 (interval-length (ly:stencil-extent stc X)))
1287 (text-width (apply + text-widths))
1288 (word-count (length stencils))
1289 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1294 (/ (- line-width text-width) 2)
1295 (/ (- line-width text-width) 2)))
1298 (- line-width text-width)))
1301 word-count line-width word-space text-widths
1303 (line-contents (if (= word-count 1)
1310 (if (null? (remove ly:stencil-empty? orig-stencils))
1313 (if (= text-direction LEFT)
1314 (set! line-contents (reverse line-contents)))
1316 (stack-stencils-padding-list
1317 X RIGHT fill-space line-contents))
1318 (if (> word-count 1)
1319 ;; shift s.t. stencils align on the left edge, even if
1320 ;; first stencil had negative X-extent (e.g. center-column)
1321 ;; (if word-count = 1, X-extents are already normalized in
1322 ;; the definition of line-contents)
1324 (ly:stencil-translate-axis
1326 (- (car (ly:stencil-extent (car stencils) X)))
1330 (define-markup-command (fill-line layout props args)
1333 #:properties ((text-direction RIGHT)
1336 "Put @var{markups} in a horizontal line of width @var{line-width}.
1337 The markups are spaced or flushed to fill the entire line.
1338 If there are no arguments, return an empty stencil.
1340 @lilypond[verbatim,quote]
1344 Words evenly spaced across the page
1348 \\line { Text markups }
1350 \\italic { evenly spaced }
1352 \\line { across the page }
1357 (justify-line-helper
1358 layout props args text-direction word-space line-width #f))
1360 (define-markup-command (justify-line layout props args)
1363 #:properties ((text-direction RIGHT)
1366 "Put @var{markups} in a horizontal line of width @var{line-width}.
1367 The markups are spread to fill the entire line and separated by equal
1368 space. If there are no arguments, return an empty stencil.
1370 @lilypond[verbatim,quote]
1373 Space between neighboring words is constant
1377 (justify-line-helper
1378 layout props args text-direction word-space line-width #t))
1380 (define-markup-command (concat layout props args)
1384 @cindex concatenating text
1385 @cindex ligatures in text
1387 Concatenate @var{args} in a horizontal line, without spaces in between.
1388 Strings and simple markups are concatenated on the input level, allowing
1389 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1390 equivalent to @code{\"fi\"}.
1392 @lilypond[verbatim,quote]
1401 (define (concat-string-args arg-list)
1402 (fold-right (lambda (arg result-list)
1403 (let ((result (if (pair? result-list)
1406 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1407 (set! arg (cadr arg)))
1408 (if (and (string? result) (string? arg))
1409 (cons (string-append arg result) (cdr result-list))
1410 (cons arg result-list))))
1414 (interpret-markup layout
1415 (prepend-alist-chain 'word-space 0 props)
1417 (make-override-lines-markup-list
1419 (chain-assoc-get 'word-space props))
1420 (if (markup-command-list? args)
1422 (concat-string-args args))))))
1424 (define (wordwrap-stencils stencils
1425 justify base-space line-width text-dir)
1426 "Perform simple wordwrap, return stencil of each line."
1427 (define space (if justify
1428 ;; justify only stretches lines.
1431 (define (stencil-len s)
1432 (interval-end (ly:stencil-extent s X)))
1433 (define (maybe-shift line)
1434 (if (= text-dir LEFT)
1435 (ly:stencil-translate-axis
1437 (- line-width (stencil-len line))
1440 (if (null? stencils)
1442 (let loop ((lines '())
1445 ((line (first todo))
1447 (word-list (list (first todo))))
1450 (let ((new (if (= text-dir LEFT)
1451 (ly:stencil-stack (car todo) X RIGHT line space)
1452 (ly:stencil-stack line X RIGHT (car todo) space))))
1454 ((<= (stencil-len new) line-width)
1455 (word-loop new (cdr todo)
1456 (cons (car todo) word-list)))
1459 ;; This depends on stencil stacking being
1460 ;; associative so that stacking
1461 ;; left-to-right and right-to-left leads to
1463 (if (= text-dir LEFT)
1465 (reverse! word-list)))
1466 (len (stencil-len line))
1467 (stretch (- line-width len))
1470 (stack-stencils X RIGHT (1+ space) word-list))
1473 ;; Uh oh, nothing to fill.
1474 (loop (cons (maybe-shift line) lines) todo)
1476 (stack-stencils X RIGHT
1477 (+ space (/ stretch spaces))
1481 (else ;; not justify
1482 (loop (cons (maybe-shift line) lines) todo)))))
1485 ;; Now we have the last line assembled with space
1486 ;; which is compressed. We want to use the
1487 ;; uncompressed version instead if it fits, and the
1488 ;; justified version if it doesn't.
1490 ;; This depends on stencil stacking being
1491 ;; associative so that stacking
1492 ;; left-to-right and right-to-left leads to
1494 (if (= text-dir LEFT)
1496 (reverse! word-list)))
1497 (big-line (stack-stencils X RIGHT base-space word-list))
1498 (big-len (stencil-len big-line))
1499 (len (stencil-len line)))
1502 (if (> big-len line-width)
1503 (stack-stencils X RIGHT
1506 (* (- big-len line-width)
1508 (* (- line-width len)
1512 (maybe-shift big-line))))))
1513 (else ;; not justify
1514 (reverse! lines (list (maybe-shift line)))))))))
1517 (define-markup-list-command (wordwrap-internal layout props justify args)
1518 (boolean? markup-list?)
1519 #:properties ((line-width #f)
1521 (text-direction RIGHT))
1522 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1523 (wordwrap-stencils (interpret-markup-list layout props args)
1527 (ly:output-def-lookup layout 'line-width))
1530 (define-markup-command (justify layout props args)
1533 #:properties ((baseline-skip)
1534 wordwrap-internal-markup-list)
1536 @cindex justifying text
1538 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1539 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1540 @var{X}@tie{}is the number of staff spaces.
1542 @lilypond[verbatim,quote]
1545 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1546 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1547 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1548 laboris nisi ut aliquip ex ea commodo consequat.
1552 (stack-lines DOWN 0.0 baseline-skip
1553 (wordwrap-internal-markup-list layout props #t args)))
1555 (define-markup-command (wordwrap layout props args)
1558 #:properties ((baseline-skip)
1559 wordwrap-internal-markup-list)
1560 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1561 the line width, where @var{X} is the number of staff spaces.
1563 @lilypond[verbatim,quote]
1566 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1567 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1568 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1569 laboris nisi ut aliquip ex ea commodo consequat.
1573 (stack-lines DOWN 0.0 baseline-skip
1574 (wordwrap-internal-markup-list layout props #f args)))
1576 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1578 #:properties ((line-width)
1580 (text-direction RIGHT))
1581 "Internal markup list command used to define @code{\\justify-string} and
1582 @code{\\wordwrap-string}."
1583 (let* ((para-strings (regexp-split
1584 (string-regexp-substitute
1586 (string-regexp-substitute "\r\n" "\n" arg))
1587 "\n[ \t\n]*\n[ \t\n]*"))
1588 (list-para-words (map (lambda (str)
1589 (regexp-split str "[ \t\n]+"))
1591 (para-lines (map (lambda (words)
1594 (interpret-markup layout props x))
1596 (wordwrap-stencils stencils
1598 line-width text-direction)))
1600 (concatenate para-lines)))
1602 (define-markup-command (wordwrap-string layout props arg)
1605 #:properties ((baseline-skip)
1606 wordwrap-string-internal-markup-list)
1607 "Wordwrap a string. Paragraphs may be separated with double newlines.
1609 @lilypond[verbatim,quote]
1611 \\override #'(line-width . 40)
1612 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1613 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1614 et dolore magna aliqua.
1617 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1618 laboris nisi ut aliquip ex ea commodo consequat.
1621 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1622 qui officia deserunt mollit anim id est laborum\"
1625 (stack-lines DOWN 0.0 baseline-skip
1626 (wordwrap-string-internal-markup-list layout props #f arg)))
1628 (define-markup-command (justify-string layout props arg)
1631 #:properties ((baseline-skip)
1632 wordwrap-string-internal-markup-list)
1633 "Justify a string. Paragraphs may be separated with double newlines
1635 @lilypond[verbatim,quote]
1637 \\override #'(line-width . 40)
1638 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1639 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1640 et dolore magna aliqua.
1643 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1644 laboris nisi ut aliquip ex ea commodo consequat.
1647 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1648 qui officia deserunt mollit anim id est laborum\"
1651 (stack-lines DOWN 0.0 baseline-skip
1652 (wordwrap-string-internal-markup-list layout props #t arg)))
1654 (define-markup-command (wordwrap-field layout props symbol)
1657 "Wordwrap the data which has been assigned to @var{symbol}.
1659 @lilypond[verbatim,quote]
1661 title = \"My title\"
1662 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1663 elit, sed do eiusmod tempor incididunt ut labore et dolore
1664 magna aliqua. Ut enim ad minim veniam, quis nostrud
1665 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1670 bookTitleMarkup = \\markup {
1672 \\fill-line { \\fromproperty #'header:title }
1674 \\wordwrap-field #'header:myText
1683 (let* ((m (chain-assoc-get symbol props)))
1685 (wordwrap-string-markup layout props m)
1688 (define-markup-command (justify-field layout props symbol)
1691 "Justify the data which has been assigned to @var{symbol}.
1693 @lilypond[verbatim,quote]
1695 title = \"My title\"
1696 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1697 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1698 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1699 laboris nisi ut aliquip ex ea commodo consequat.\"
1703 bookTitleMarkup = \\markup {
1705 \\fill-line { \\fromproperty #'header:title }
1707 \\justify-field #'header:myText
1716 (let* ((m (chain-assoc-get symbol props)))
1718 (justify-string-markup layout props m)
1721 (define-markup-command (combine layout props arg1 arg2)
1725 @cindex merging text
1727 Print two markups on top of each other.
1729 Note: @code{\\combine} cannot take a list of markups enclosed in
1730 curly braces as an argument; the follow example will not compile:
1733 \\combine @{ a list @}
1736 @lilypond[verbatim,quote]
1739 \\override #'(thickness . 2)
1741 \\draw-line #'(0 . 4)
1742 \\arrow-head #Y #DOWN ##f
1745 (let* ((s1 (interpret-markup layout props arg1))
1746 (s2 (interpret-markup layout props arg2)))
1747 (ly:stencil-add s1 s2)))
1750 ;; TODO: should extract baseline-skip from each argument somehow..
1752 (define-markup-command (column layout props args)
1755 #:properties ((baseline-skip))
1757 @cindex stacking text in a column
1759 Stack the markups in @var{args} vertically. The property
1760 @code{baseline-skip} determines the space between markups
1763 @lilypond[verbatim,quote]
1772 (let ((arg-stencils (interpret-markup-list layout props args)))
1773 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1775 (define-markup-command (dir-column layout props args)
1778 #:properties ((direction)
1781 @cindex changing direction of text columns
1783 Make a column of @var{args}, going up or down, depending on the
1784 setting of the @code{direction} layout property.
1786 @lilypond[verbatim,quote]
1788 \\override #`(direction . ,UP) {
1798 \\override #'(direction . 1) {
1805 (stack-lines (if (number? direction) direction -1)
1808 (interpret-markup-list layout props args)))
1810 (define (general-column align-dir baseline mols)
1811 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1813 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1814 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1815 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1816 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1818 (define-markup-command (center-column layout props args)
1821 #:properties ((baseline-skip))
1823 @cindex centering a column of text
1825 Put @code{args} in a centered column.
1827 @lilypond[verbatim,quote]
1836 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1838 (define-markup-command (left-column layout props args)
1841 #:properties ((baseline-skip))
1843 @cindex text columns, left-aligned
1845 Put @code{args} in a left-aligned column.
1847 @lilypond[verbatim,quote]
1856 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1858 (define-markup-command (right-column layout props args)
1861 #:properties ((baseline-skip))
1863 @cindex text columns, right-aligned
1865 Put @code{args} in a right-aligned column.
1867 @lilypond[verbatim,quote]
1876 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1878 (define-markup-command (vcenter layout props arg)
1882 @cindex vertically centering text
1884 Align @code{arg} to its Y@tie{}center.
1886 @lilypond[verbatim,quote]
1894 (let* ((mol (interpret-markup layout props arg)))
1895 (ly:stencil-aligned-to mol Y CENTER)))
1897 (define-markup-command (center-align layout props arg)
1901 @cindex horizontally centering text
1903 Align @code{arg} to its X@tie{}center.
1905 @lilypond[verbatim,quote]
1915 (let* ((mol (interpret-markup layout props arg)))
1916 (ly:stencil-aligned-to mol X CENTER)))
1918 (define-markup-command (right-align layout props arg)
1922 @cindex right aligning text
1924 Align @var{arg} on its right edge.
1926 @lilypond[verbatim,quote]
1936 (let* ((m (interpret-markup layout props arg)))
1937 (ly:stencil-aligned-to m X RIGHT)))
1939 (define-markup-command (left-align layout props arg)
1943 @cindex left aligning text
1945 Align @var{arg} on its left edge.
1947 @lilypond[verbatim,quote]
1957 (let* ((m (interpret-markup layout props arg)))
1958 (ly:stencil-aligned-to m X LEFT)))
1960 (define-markup-command (general-align layout props axis dir arg)
1961 (integer? number? markup?)
1964 @cindex controlling general text alignment
1966 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1968 @lilypond[verbatim,quote]
1972 \\general-align #X #LEFT
1977 \\general-align #X #CENTER
1983 \\general-align #Y #UP
1990 \\general-align #Y #3.2
1997 (let* ((m (interpret-markup layout props arg)))
1998 (ly:stencil-aligned-to m axis dir)))
2000 (define-markup-command (halign layout props dir arg)
2004 @cindex setting horizontal text alignment
2006 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2007 left-aligned, while @code{+1} is right. Values in between interpolate
2008 alignment accordingly.
2010 @lilypond[verbatim,quote]
2035 (let* ((m (interpret-markup layout props arg)))
2036 (ly:stencil-aligned-to m X dir)))
2038 (define-markup-command (with-dimensions layout props x y arg)
2039 (number-pair? number-pair? markup?)
2042 @cindex setting extent of text objects
2044 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2045 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2047 (make-transparent-box-stencil x y)
2049 `(delay-stencil-evaluation ,(delay expr))
2052 (define-markup-command (pad-around layout props amount arg)
2055 "Add padding @var{amount} all around @var{arg}.
2057 @lilypond[verbatim,quote]
2070 (let* ((m (interpret-markup layout props arg))
2071 (x (interval-widen (ly:stencil-extent m X) amount))
2072 (y (interval-widen (ly:stencil-extent m Y) amount)))
2073 (ly:stencil-add (make-transparent-box-stencil x y)
2076 (define-markup-command (pad-x layout props amount arg)
2080 @cindex padding text horizontally
2082 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2084 @lilypond[verbatim,quote]
2097 (let* ((m (interpret-markup layout props arg))
2098 (x (ly:stencil-extent m X))
2099 (y (ly:stencil-extent m Y)))
2100 (ly:make-stencil (ly:stencil-expr m)
2101 (interval-widen x amount)
2104 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2105 (integer? ly:dir? markup? markup?)
2107 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2108 (let ((m1 (interpret-markup layout props arg1))
2109 (m2 (interpret-markup layout props arg2)))
2110 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2112 (define-markup-command (transparent layout props arg)
2115 "Make @var{arg} transparent.
2117 @lilypond[verbatim,quote]
2124 (let* ((m (interpret-markup layout props arg))
2125 (x (ly:stencil-extent m X))
2126 (y (ly:stencil-extent m Y)))
2127 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2129 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2130 (number-pair? number-pair? markup?)
2132 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2134 @lilypond[verbatim,quote]
2141 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2147 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2148 (interpret-markup layout props arg)))
2150 (define-markup-command (hcenter-in layout props length arg)
2153 "Center @var{arg} horizontally within a box of extending
2154 @var{length}/2 to the left and right.
2156 @lilypond[quote,verbatim]
2159 \\set Staff.instrumentName = \\markup {
2166 \\set Staff.instrumentName = \\markup {
2175 (interpret-markup layout props
2176 (make-pad-to-box-markup
2177 (cons (/ length -2) (/ length 2))
2179 (make-center-align-markup arg))))
2181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2185 (define-markup-command (property-recursive layout props symbol)
2188 "Print out a warning when a header field markup contains some recursive
2190 (ly:warning "Recursive definition of property ~a detected!" symbol)
2193 (define-markup-command (fromproperty layout props symbol)
2196 "Read the @var{symbol} from property settings, and produce a stencil
2197 from the markup contained within. If @var{symbol} is not defined, it
2198 returns an empty markup.
2200 @lilypond[verbatim,quote]
2202 myTitle = \"myTitle\"
2206 \\fromproperty #'header:myTitle
2213 (let ((m (chain-assoc-get symbol props)))
2215 ;; prevent infinite loops by clearing the interpreted property:
2216 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2219 (define-markup-command (on-the-fly layout props procedure arg)
2220 (procedure? markup?)
2222 "Apply the @var{procedure} markup command to @var{arg}.
2223 @var{procedure} should take a single argument."
2224 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2225 (set-object-property! anonymous-with-signature
2228 (interpret-markup layout props (list anonymous-with-signature arg))))
2230 (define-markup-command (footnote layout props mkup note)
2233 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2235 @lilypond[verbatim,quote]
2238 \\override #'(padding . 0.2)
2242 The footnote will not be annotated automatically."
2243 (ly:stencil-combine-at-edge
2244 (interpret-markup layout props mkup)
2248 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2253 (define-markup-command (auto-footnote layout props mkup note)
2256 #:properties ((raise 0.5)
2258 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2260 @lilypond[verbatim,quote]
2263 \\override #'(padding . 0.2)
2267 The footnote will be annotated automatically."
2268 (let* ((markup-stencil (interpret-markup layout props mkup))
2269 (footnote-hash (gensym "footnote"))
2271 (gauge-stencil (interpret-markup
2274 ((ly:output-def-lookup
2276 'footnote-numbering-function)
2278 (x-ext (ly:stencil-extent gauge-stencil X))
2279 (y-ext (ly:stencil-extent gauge-stencil Y))
2281 `(delay-stencil-evaluation
2285 (ly:output-def-lookup layout
2286 'number-footnote-table))
2287 (footnote-stencil (if (list? table)
2288 (assoc-get footnote-hash
2291 (footnote-stencil (if (ly:stencil? footnote-stencil)
2294 (ly:programming-error
2295 "Cannot find correct footnote for a markup object.")
2297 (gap (- (interval-length x-ext)
2299 (ly:stencil-extent footnote-stencil X))))
2300 (y-trans (- (+ (cdr y-ext)
2302 (cdr (ly:stencil-extent footnote-stencil
2304 (ly:stencil-translate footnote-stencil
2305 (cons gap y-trans)))))))
2306 (main-stencil (ly:stencil-combine-at-edge
2310 (ly:make-stencil footnote-number x-ext y-ext)
2315 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2319 (define-markup-command (override layout props new-prop arg)
2323 @cindex overriding properties within text markup
2325 Add the argument @var{new-prop} to the property list. Properties
2326 may be any property supported by @rinternals{font-interface},
2327 @rinternals{text-interface} and
2328 @rinternals{instrument-specific-markup-interface}.
2330 @lilypond[verbatim,quote]
2338 \\override #'(baseline-skip . 4) {
2347 (interpret-markup layout (cons (list new-prop) props) arg))
2349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2353 (define-markup-command (verbatim-file layout props name)
2356 "Read the contents of file @var{name}, and include it verbatim.
2358 @lilypond[verbatim,quote]
2360 \\verbatim-file #\"simple.ly\"
2363 (interpret-markup layout props
2364 (if (ly:get-option 'safe)
2365 "verbatim-file disabled in safe mode"
2366 (let* ((str (ly:gulp-file name))
2367 (lines (string-split str #\nl)))
2368 (make-typewriter-markup
2369 (make-column-markup lines))))))
2371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2373 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2376 (define-markup-command (smaller layout props arg)
2379 "Decrease the font size relative to the current setting.
2381 @lilypond[verbatim,quote]
2394 (interpret-markup layout props
2395 `(,fontsize-markup -1 ,arg)))
2397 (define-markup-command (larger layout props arg)
2400 "Increase the font size relative to the current setting.
2402 @lilypond[verbatim,quote]
2410 (interpret-markup layout props
2411 `(,fontsize-markup 1 ,arg)))
2413 (define-markup-command (finger layout props arg)
2416 "Set @var{arg} as small numbers.
2418 @lilypond[verbatim,quote]
2425 (interpret-markup layout
2426 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2429 (define-markup-command (abs-fontsize layout props size arg)
2432 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2433 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2435 @lilypond[verbatim,quote]
2437 default text font size
2439 \\abs-fontsize #16 { text font size 16 }
2441 \\abs-fontsize #12 { text font size 12 }
2444 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2445 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2446 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2447 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2448 (magnification (/ size ref-size)))
2452 `((baseline-skip . ,(* magnification ref-baseline))
2453 (word-space . ,(* magnification ref-word-space))
2454 (font-size . ,(magnification->font-size magnification)))
2458 (define-markup-command (fontsize layout props increment arg)
2461 #:properties ((font-size 0)
2464 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2467 @lilypond[verbatim,quote]
2478 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2479 (word-space . ,(* word-space (magstep increment)))
2480 (font-size . ,(+ font-size increment)))
2484 (define-markup-command (magnify layout props sz arg)
2488 @cindex magnifying text
2490 Set the font magnification for its argument. In the following
2491 example, the middle@tie{}A is 10% larger:
2494 A \\magnify #1.1 @{ A @} A
2497 Note: Magnification only works if a font name is explicitly selected.
2498 Use @code{\\fontsize} otherwise.
2500 @lilypond[verbatim,quote]
2511 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2514 (define-markup-command (bold layout props arg)
2517 "Switch to bold font-series.
2519 @lilypond[verbatim,quote]
2527 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2529 (define-markup-command (sans layout props arg)
2532 "Switch to the sans serif font family.
2534 @lilypond[verbatim,quote]
2543 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2545 (define-markup-command (number layout props arg)
2548 "Set font family to @code{number}, which yields the font used for
2549 time signatures and fingerings. This font contains numbers and
2550 some punctuation; it has no letters.
2552 @lilypond[verbatim,quote]
2555 0 1 2 3 4 5 6 7 8 9 . ,
2559 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2561 (define-markup-command (roman layout props arg)
2564 "Set font family to @code{roman}.
2566 @lilypond[verbatim,quote]
2572 text in roman font family
2579 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2581 (define-markup-command (huge layout props arg)
2584 "Set font size to +2.
2586 @lilypond[verbatim,quote]
2594 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2596 (define-markup-command (large layout props arg)
2599 "Set font size to +1.
2601 @lilypond[verbatim,quote]
2609 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2611 (define-markup-command (normalsize layout props arg)
2614 "Set font size to default.
2616 @lilypond[verbatim,quote]
2629 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2631 (define-markup-command (small layout props arg)
2634 "Set font size to -1.
2636 @lilypond[verbatim,quote]
2644 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2646 (define-markup-command (tiny layout props arg)
2649 "Set font size to -2.
2651 @lilypond[verbatim,quote]
2659 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2661 (define-markup-command (teeny layout props arg)
2664 "Set font size to -3.
2666 @lilypond[verbatim,quote]
2674 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2676 (define-markup-command (fontCaps layout props arg)
2679 "Set @code{font-shape} to @code{caps}
2681 Note: @code{\\fontCaps} requires the installation and selection of
2682 fonts which support the @code{caps} font shape."
2683 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2686 (define-markup-command (smallCaps layout props arg)
2689 "Emit @var{arg} as small caps.
2691 Note: @code{\\smallCaps} does not support accented characters.
2693 @lilypond[verbatim,quote]
2702 (define (char-list->markup chars lower)
2703 (let ((final-string (string-upcase (reverse-list->string chars))))
2705 (markup #:fontsize -2 final-string)
2707 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2708 (if (null? rest-chars)
2710 (reverse! (cons (char-list->markup currents current-is-lower)
2712 (let* ((ch (car rest-chars))
2713 (is-lower (char-lower-case? ch)))
2714 (if (or (and current-is-lower is-lower)
2715 (and (not current-is-lower) (not is-lower)))
2716 (make-small-caps (cdr rest-chars)
2720 (make-small-caps (cdr rest-chars)
2723 (if (null? currents)
2725 (cons (char-list->markup
2726 currents current-is-lower)
2728 (interpret-markup layout props
2730 (make-small-caps (string->list arg) (list) #f (list))
2733 (define-markup-command (caps layout props arg)
2736 "Copy of the @code{\\smallCaps} command.
2738 @lilypond[verbatim,quote]
2747 (interpret-markup layout props (make-smallCaps-markup arg)))
2749 (define-markup-command (dynamic layout props arg)
2752 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2753 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2754 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2755 done in a different font. The recommended font for this is bold and italic.
2756 @lilypond[verbatim,quote]
2764 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2766 (define-markup-command (text layout props arg)
2769 "Use a text font instead of music symbol or music alphabet font.
2771 @lilypond[verbatim,quote]
2784 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2787 (define-markup-command (italic layout props arg)
2790 "Use italic @code{font-shape} for @var{arg}.
2792 @lilypond[verbatim,quote]
2800 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2802 (define-markup-command (typewriter layout props arg)
2805 "Use @code{font-family} typewriter for @var{arg}.
2807 @lilypond[verbatim,quote]
2816 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2818 (define-markup-command (upright layout props arg)
2821 "Set @code{font-shape} to @code{upright}. This is the opposite
2824 @lilypond[verbatim,quote]
2838 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2840 (define-markup-command (medium layout props arg)
2843 "Switch to medium font-series (in contrast to bold).
2845 @lilypond[verbatim,quote]
2858 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2861 (define-markup-command (normal-text layout props arg)
2864 "Set all font related properties (except the size) to get the default
2865 normal text font, no matter what font was used earlier.
2867 @lilypond[verbatim,quote]
2869 \\huge \\bold \\sans \\caps {
2881 (interpret-markup layout
2882 (cons '((font-family . roman) (font-shape . upright)
2883 (font-series . medium) (font-encoding . latin1))
2887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2891 (define-markup-command (musicglyph layout props glyph-name)
2894 "@var{glyph-name} is converted to a musical symbol; for example,
2895 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2896 the music font. See @ruser{The Feta font} for a complete listing of
2897 the possible glyphs.
2899 @lilypond[verbatim,quote]
2902 \\musicglyph #\"rests.2\"
2903 \\musicglyph #\"clefs.G_change\"
2906 (let* ((font (ly:paper-get-font layout
2907 (cons '((font-encoding . fetaMusic)
2911 (glyph (ly:font-get-glyph font glyph-name)))
2912 (if (null? (ly:stencil-expr glyph))
2913 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2917 (define-markup-command (doublesharp layout props)
2920 "Draw a double sharp symbol.
2922 @lilypond[verbatim,quote]
2927 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2929 (define-markup-command (sesquisharp layout props)
2932 "Draw a 3/2 sharp symbol.
2934 @lilypond[verbatim,quote]
2939 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2941 (define-markup-command (sharp layout props)
2944 "Draw a sharp symbol.
2946 @lilypond[verbatim,quote]
2951 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2953 (define-markup-command (semisharp layout props)
2956 "Draw a semisharp symbol.
2958 @lilypond[verbatim,quote]
2963 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2965 (define-markup-command (natural layout props)
2968 "Draw a natural symbol.
2970 @lilypond[verbatim,quote]
2975 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2977 (define-markup-command (semiflat layout props)
2980 "Draw a semiflat symbol.
2982 @lilypond[verbatim,quote]
2987 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2989 (define-markup-command (flat layout props)
2992 "Draw a flat symbol.
2994 @lilypond[verbatim,quote]
2999 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
3001 (define-markup-command (sesquiflat layout props)
3004 "Draw a 3/2 flat symbol.
3006 @lilypond[verbatim,quote]
3011 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3013 (define-markup-command (doubleflat layout props)
3016 "Draw a double flat symbol.
3018 @lilypond[verbatim,quote]
3023 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3025 (define-markup-command (with-color layout props color arg)
3029 @cindex coloring text
3031 Draw @var{arg} in color specified by @var{color}.
3033 @lilypond[verbatim,quote]
3045 (let ((stil (interpret-markup layout props arg)))
3046 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3047 (ly:stencil-extent stil X)
3048 (ly:stencil-extent stil Y))))
3050 (define-markup-command (tied-lyric layout props str)
3053 #:properties ((word-space))
3055 @cindex simple text strings with tie characters
3057 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3059 @lilypond[verbatim,quote]
3061 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3062 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3063 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3066 (define (replace-ties tie str)
3067 (if (string-contains str "~")
3069 ((half-space (/ word-space 2))
3070 (parts (string-split str #\~))
3071 (tie-str (markup #:hspace half-space
3073 #:hspace half-space))
3074 (joined (list-join parts tie-str)))
3075 (make-concat-markup joined))
3078 (define short-tie-regexp (make-regexp "~[^.]~"))
3079 (define (match-short str) (regexp-exec short-tie-regexp str))
3081 (define (replace-short str mkp)
3082 (let ((match (match-short str)))
3084 (make-concat-markup (list
3086 (replace-ties "ties.lyric.default" str)))
3087 (let ((new-str (match:suffix match))
3088 (new-mkp (make-concat-markup (list
3090 (replace-ties "ties.lyric.default"
3091 (match:prefix match))
3092 (replace-ties "ties.lyric.short"
3093 (match:substring match))))))
3094 (replace-short new-str new-mkp)))))
3096 (interpret-markup layout
3098 (replace-short str (markup))))
3100 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3104 (define-markup-command (arrow-head layout props axis dir filled)
3105 (integer? ly:dir? boolean?)
3107 "Produce an arrow head in specified direction and axis.
3108 Use the filled head if @var{filled} is specified.
3109 @lilypond[verbatim,quote]
3112 \\general-align #Y #DOWN {
3113 \\arrow-head #Y #UP ##t
3114 \\arrow-head #Y #DOWN ##f
3116 \\arrow-head #X #RIGHT ##f
3117 \\arrow-head #X #LEFT ##f
3123 ((name (format #f "arrowheads.~a.~a~a"
3130 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3134 (define-markup-command (lookup layout props glyph-name)
3137 "Lookup a glyph by name.
3139 @lilypond[verbatim,quote]
3141 \\override #'(font-encoding . fetaBraces) {
3142 \\lookup #\"brace200\"
3145 \\lookup #\"brace180\"
3149 (ly:font-get-glyph (ly:paper-get-font layout props)
3152 (define-markup-command (char layout props num)
3155 "Produce a single character. Characters encoded in hexadecimal
3156 format require the prefix @code{#x}.
3158 @lilypond[verbatim,quote]
3160 \\char #65 \\char ##x00a9
3163 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3165 (define number->mark-letter-vector (make-vector 25 #\A))
3170 (if (= i (- (char->integer #\I) (char->integer #\A)))
3172 (vector-set! number->mark-letter-vector j
3173 (integer->char (+ i (char->integer #\A)))))
3175 (define number->mark-alphabet-vector (list->vector
3176 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3178 (define (number->markletter-string vec n)
3179 "Double letters for big marks."
3180 (let* ((lst (vector-length vec)))
3183 (string-append (number->markletter-string vec (1- (quotient n lst)))
3184 (number->markletter-string vec (remainder n lst)))
3185 (make-string 1 (vector-ref vec n)))))
3187 (define-markup-command (markletter layout props num)
3190 "Make a markup letter for @var{num}. The letters start with A
3191 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3193 @lilypond[verbatim,quote]
3200 (ly:text-interface::interpret-markup layout props
3201 (number->markletter-string number->mark-letter-vector num)))
3203 (define-markup-command (markalphabet layout props num)
3206 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3207 and continue with double letters.
3209 @lilypond[verbatim,quote]
3216 (ly:text-interface::interpret-markup layout props
3217 (number->markletter-string number->mark-alphabet-vector num)))
3219 (define-public (horizontal-slash-interval num forward number-interval mag)
3221 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3222 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3223 (else (interval-widen number-interval (* mag 0.25))))
3224 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3225 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3226 (else (interval-widen number-interval (* mag 0.25))))
3229 (define-public (adjust-slash-stencil num forward stencil mag)
3232 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3234 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3236 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3238 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3241 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3243 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3248 (define (slashed-digit-internal layout props num forward font-size thickness)
3249 (let* ((mag (magstep font-size))
3251 (ly:output-def-lookup layout 'line-thickness)
3253 ;; backward slashes might use slope and point in the other direction!
3254 (dy (* mag (if forward 0.4 -0.4)))
3255 (number-stencil (interpret-markup layout
3256 (prepend-alist-chain 'font-encoding 'fetaText props)
3257 (number->string num)))
3258 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3259 (center (interval-center (ly:stencil-extent number-stencil Y)))
3260 ;; Use the real extents of the slash, not the whole number,
3261 ;; because we might translate the slash later on!
3262 (num-y (interval-widen (cons center center) (abs dy)))
3263 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3264 (slash-stencil (if is-sane
3265 (make-line-stencil thickness
3266 (car num-x) (- (interval-center num-y) dy)
3267 (cdr num-x) (+ (interval-center num-y) dy))
3269 (if (ly:stencil? slash-stencil)
3271 ;; for some numbers we need to shift the slash/backslash up or
3272 ;; down to make the slashed digit look better
3273 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3274 (set! number-stencil
3275 (ly:stencil-add number-stencil slash-stencil)))
3276 (ly:warning "Unable to create slashed digit ~a" num))
3280 (define-markup-command (slashed-digit layout props num)
3283 #:properties ((font-size 0)
3286 @cindex slashed digits
3288 A feta number, with slash. This is for use in the context of
3289 figured bass notation.
3290 @lilypond[verbatim,quote]
3294 \\override #'(thickness . 3)
3298 (slashed-digit-internal layout props num #t font-size thickness))
3300 (define-markup-command (backslashed-digit layout props num)
3303 #:properties ((font-size 0)
3306 @cindex backslashed digits
3308 A feta number, with backslash. This is for use in the context of
3309 figured bass notation.
3310 @lilypond[verbatim,quote]
3312 \\backslashed-digit #5
3314 \\override #'(thickness . 3)
3315 \\backslashed-digit #7
3318 (slashed-digit-internal layout props num #f font-size thickness))
3321 (define eyeglassespath
3322 '((moveto 0.42 0.77)
3323 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3324 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3325 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3326 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3329 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3330 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3331 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3332 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3334 (moveto 1.025 0.935)
3335 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3336 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3339 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3342 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3344 (define-markup-command (eyeglasses layout props)
3347 "Prints out eyeglasses, indicating strongly to look at the conductor.
3348 @lilypond[verbatim,quote]
3349 \\markup { \\eyeglasses }
3351 (interpret-markup layout props
3352 (make-override-markup '(line-cap-style . butt)
3353 (make-path-markup 0.15 eyeglassespath))))
3355 (define-markup-command (left-brace layout props size)
3359 A feta brace in point size @var{size}.
3361 @lilypond[verbatim,quote]
3368 (let* ((font (ly:paper-get-font layout
3369 (cons '((font-encoding . fetaBraces)
3372 (glyph-count (1- (ly:otf-glyph-count font)))
3373 (scale (ly:output-def-lookup layout 'output-scale))
3374 (scaled-size (/ (ly:pt size) scale))
3376 (ly:font-get-glyph font (string-append "brace"
3377 (number->string n)))))
3378 (get-y-from-brace (lambda (brace)
3380 (ly:stencil-extent (glyph brace) Y))))
3381 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3382 (glyph-found (glyph find-brace)))
3384 (if (or (null? (ly:stencil-expr glyph-found))
3385 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3386 (> scaled-size (interval-length
3387 (ly:stencil-extent (glyph glyph-count) Y))))
3389 (ly:warning (_ "no brace found for point size ~S ") size)
3390 (ly:warning (_ "defaulting to ~S pt")
3391 (/ (* scale (interval-length
3392 (ly:stencil-extent glyph-found Y)))
3396 (define-markup-command (right-brace layout props size)
3400 A feta brace in point size @var{size}, rotated 180 degrees.
3402 @lilypond[verbatim,quote]
3409 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3412 ;; the note command.
3413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3415 ;; TODO: better syntax.
3417 (define-markup-command (note-by-number layout props log dot-count dir)
3418 (number? number? number?)
3420 #:properties ((font-size 0)
3424 @cindex notes within text by log and dot-count
3426 Construct a note symbol, with stem and flag. By using fractional values for
3427 @var{dir}, longer or shorter stems can be obtained.
3428 Supports all note-head-styles.
3429 Supported flag-styles are @code{default}, @code{old-straight-flag},
3430 @code{modern-straight-flag} and @code{flat-flag}.
3432 @lilypond[verbatim,quote]
3434 \\note-by-number #3 #0 #DOWN
3436 \\note-by-number #1 #2 #0.8
3439 (define (get-glyph-name-candidates dir log style)
3440 (map (lambda (dir-name)
3441 (format #f "noteheads.~a~a" dir-name
3442 (if (and (symbol? style)
3443 (not (equal? 'default style)))
3444 (select-head-glyph style (min log 2))
3446 (list (if (= dir UP) "u" "d")
3449 (define (get-glyph-name font cands)
3452 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3453 (get-glyph-name font (cdr cands))
3456 (define (buildflags flag-stencil remain curr-stencil spacing)
3457 ;; Function to recursively create a stencil with @code{remain} flags
3458 ;; from the single-flag stencil @code{curr-stencil}, which is already
3459 ;; translated to the position of the previous flag position.
3461 ;; Copy and paste from /scm/flag-styles.scm
3463 (let* ((translated-stencil
3464 (ly:stencil-translate-axis curr-stencil spacing Y))
3465 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3466 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3469 (define (straight-flag-mrkp flag-thickness flag-spacing
3470 upflag-angle upflag-length
3471 downflag-angle downflag-length
3473 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3474 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3475 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3476 ;; @var{downflag-length} are given in staff spaces.
3478 ;; All lengths are scaled according to the font size of the note.
3480 ;; From /scm/flag-styles.scm, modified to fit here.
3482 (let* ((stem-up (> dir 0))
3483 ;; scale with the note size
3484 (factor (magstep font-size))
3485 (stem-thickness (* factor 0.1))
3486 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3487 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3488 (raw-length (if stem-up upflag-length downflag-length))
3489 (angle (if stem-up upflag-angle downflag-angle))
3490 (flag-length (+ (* raw-length factor) half-stem-thickness))
3491 (flag-end (if (= angle 0)
3492 (cons flag-length (* half-stem-thickness dir))
3493 (polar->rectangular flag-length angle)))
3494 (thickness (* flag-thickness factor))
3495 (thickness-offset (cons 0 (* -1 thickness dir)))
3496 (spacing (* -1 flag-spacing factor dir))
3497 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3500 (offset-add flag-end thickness-offset)
3501 (offset-add start thickness-offset)))
3502 (stencil (ly:round-filled-polygon points half-stem-thickness))
3503 ;; Log for 1/8 is 3, so we need to subtract 3
3504 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3507 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3509 (size-factor (magstep font-size))
3510 (blot (ly:output-def-lookup layout 'blot-diameter))
3512 (let ((result (get-glyph-name font
3513 (get-glyph-name-candidates
3514 (sign dir) log style))))
3515 (if (string-null? result)
3516 ;; If no glyph name can be found, select default heads.
3517 ;; Though this usually means an unsupported style has been
3518 ;; chosen, it also prevents unrelated 'style settings from
3519 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3521 (get-glyph-name font
3522 (get-glyph-name-candidates
3523 (sign dir) log 'default))
3525 (head-glyph (ly:font-get-glyph font head-glyph-name))
3526 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3527 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3528 (stem-length (* size-factor (max 3 (- log 1))))
3529 ;; With ancient-flags we want a tighter stem
3530 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3531 (stemy (* dir stem-length))
3532 (attach-off (cons (interval-index
3533 (ly:stencil-extent head-glyph X)
3534 (* (sign dir) (car attach-indices)))
3535 ;; fixme, this is inconsistent between X & Y.
3538 (ly:stencil-extent head-glyph Y)
3539 (cdr attach-indices)))))
3540 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3542 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3543 (stem-glyph (and (> log 0)
3544 (ly:round-filled-box
3545 (ordered-cons (+ stem-X-corr (car attach-off))
3546 (+ stem-X-corr (car attach-off)
3547 (* (- (sign dir)) stem-thickness)))
3548 (cons (min stemy (cdr attach-off))
3549 (max stemy (cdr attach-off)))
3550 (/ stem-thickness 3))))
3551 (dot (ly:font-get-glyph font "dots.dot"))
3552 (dotwid (interval-length (ly:stencil-extent dot X)))
3553 (dots (and (> dot-count 0)
3554 (apply ly:stencil-add
3556 (ly:stencil-translate-axis
3557 dot (* 2 x dotwid) X))
3558 (iota dot-count)))))
3559 ;; Straight-flags. Values taken from /scm/flag-style.scm
3560 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3561 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3562 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3563 ;; Calculate a corrective to avoid a gap between
3564 ;; straight-flags and the stem.
3565 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3566 (eq? flag-style 'old-straight-flag)
3567 (eq? flag-style 'flat-flag))
3568 (/ blot 10 (* -1 dir))
3570 (flaggl (and (> log 2)
3571 (ly:stencil-translate
3572 (cond ((eq? flag-style 'modern-straight-flag)
3573 modern-straight-flag)
3574 ((eq? flag-style 'old-straight-flag)
3576 ((eq? flag-style 'flat-flag)
3579 (ly:font-get-glyph font
3580 (format #f (if ancient-flags?
3581 "flags.mensural~a2~a"
3583 (if (> dir 0) "u" "d")
3585 (cons (+ (car attach-off)
3586 ;; For tighter stems (with ancient-flags) the
3587 ;; flag has to be adjusted different.
3588 (if (and (not ancient-flags?) (< dir 0))
3591 (+ stemy flag-style-Y-corr))))))
3593 ;; If there is a flag on an upstem and the stem is short, move the dots
3594 ;; to avoid the flag. 16th notes get a special case because their flags
3595 ;; hang lower than any other flags.
3596 ;; Not with ancient flags or straight-flags.
3597 (if (and dots (> dir 0) (> log 2)
3598 (or (eq? flag-style 'default) (null? flag-style))
3599 (not ancient-flags?)
3600 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3601 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3603 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3604 (if (ly:stencil? stem-glyph)
3605 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3606 (set! stem-glyph head-glyph))
3607 (if (ly:stencil? dots)
3610 (ly:stencil-translate-axis
3612 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3618 (let ((divisor (log 2)))
3619 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3621 (define (parse-simple-duration duration-string)
3622 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3623 and return a (log dots) list."
3624 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3626 (if (and match (string=? duration-string (match:substring match 0)))
3627 (let ((len (match:substring match 1))
3628 (dots (match:substring match 2)))
3629 (list (cond ((string=? len "breve") -1)
3630 ((string=? len "longa") -2)
3631 ((string=? len "maxima") -3)
3632 (else (log2 (string->number len))))
3633 (if dots (string-length dots) 0)))
3634 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3636 (define-markup-command (note layout props duration dir)
3639 #:properties (note-by-number-markup)
3641 @cindex notes within text by string
3643 This produces a note with a stem pointing in @var{dir} direction, with
3644 the @var{duration} for the note head type and augmentation dots. For
3645 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3646 a shortened down stem.
3648 @lilypond[verbatim,quote]
3650 \\override #'(style . cross) {
3654 \\note #\"breve\" #0
3657 (let ((parsed (parse-simple-duration duration)))
3658 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3660 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3661 ;; the rest command.
3662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3664 (define-markup-command (rest-by-number layout props log dot-count)
3667 #:properties ((font-size 0)
3669 (multi-measure-rest #f))
3671 @cindex rests or multi-measure-rests within text by log and dot-count
3673 A rest or multi-measure-rest symbol.
3675 @lilypond[verbatim,quote]
3677 \\rest-by-number #3 #2
3679 \\rest-by-number #0 #1
3681 \\override #'(multi-measure-rest . #t)
3682 \\rest-by-number #0 #0
3686 (define (get-glyph-name-candidates log style)
3687 (let* (;; Choose the style-string to be added.
3688 ;; If no glyph exists, select others for the specified styles
3689 ;; otherwise defaulting.
3692 ;; 'baroque needs to be special-cased, otherwise
3693 ;; `select-head-glyphĀ“ would catch neomensural-glyphs for
3694 ;; this style, if (< log 0).
3695 (eq? style 'baroque)
3696 (string-append (number->string log) ""))
3697 ((eq? style 'petrucci)
3698 (string-append (number->string log) "mensural"))
3699 ;; In other cases `select-head-glyphĀ“ from output-lib.scm
3700 ;; works for rest-glyphs, too.
3701 ((and (symbol? style) (not (eq? style 'default)))
3702 (select-head-glyph style log))
3704 ;; Choose ledgered glyphs for whole and half rest.
3705 ;; Except for the specified styles, logs and MultiMeasureRests.
3707 (if (and (or (list? style)
3709 '(neomensural mensural petrucci))))
3710 (not multi-measure-rest)
3711 (or (= log 0) (= log 1)))
3714 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3716 (define (get-glyph-name font cands)
3717 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3722 (ly:paper-get-font layout
3723 (cons '((font-encoding . fetaMusic)) props)))
3726 (get-glyph-name font
3727 (get-glyph-name-candidates log style))))
3728 (if (string-null? result)
3729 ;; If no glyph name can be found, select default rests. Though
3730 ;; this usually means an unsupported style has been chosen, it
3731 ;; also prevents unrelated 'style settings from other grobs
3732 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3733 (get-glyph-name font (get-glyph-name-candidates log 'default))
3735 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3736 (dot (ly:font-get-glyph font "dots.dot"))
3737 (dot-width (interval-length (ly:stencil-extent dot X)))
3738 (dots (and (> dot-count 0)
3739 (apply ly:stencil-add
3741 (ly:stencil-translate-axis
3742 dot (* 2 x dot-width) X))
3743 (iota dot-count))))))
3745 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3746 ;; glyphs are taken for whole and half rests.
3747 ;; If they are dotted, move the dots in X-direction to avoid collision.
3751 (not (member style '(neomensural mensural petrucci))))
3752 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3754 ;; Add dots to the rest-glyph.
3756 ;; Not sure how to vertical align dots.
3757 ;; For now the dots are centered for half, whole or longer rests.
3758 ;; Otherwise placed near the top of the rest.
3760 ;; Dots for rests with (< log 0) dots are allowed, but not
3761 ;; if multi-measure-rest is set #t.
3762 (if (and (not multi-measure-rest) dots)
3765 (ly:stencil-translate
3768 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3770 (interval-center (ly:stencil-extent rest-glyph Y))
3771 (- (interval-end (ly:stencil-extent rest-glyph Y))
3772 (/ (* 2 dot-width) 3)))))
3776 (define-markup-command (rest layout props duration)
3779 #:properties ((style '())
3780 (multi-measure-rest #f)
3781 (multi-measure-rest-number #t)
3784 @cindex rests or multi-measure-rests within text by string
3786 This produces a rest, with the @var{duration} for the rest type and
3788 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3791 Printing MultiMeasureRests could be enabled with
3792 @code{\\override #'(multi-measure-rest . #t)}
3793 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3794 This is enabled for all styles using default-glyphs.
3795 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3797 @lilypond[verbatim,quote]
3803 \\override #'(multi-measure-rest . #t)
3807 \\override #'(multi-measure-rest-number . #f)
3812 ;; Get the number of mmr-glyphs.
3813 ;; Store them in a list.
3814 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3815 (define (mmr-numbers nmbr)
3816 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3817 (8-remainder (remainder nmbr 8))
3818 (4-bar-glyph (floor (/ 8-remainder 4)))
3819 (4-remainder (remainder nmbr 4))
3820 (2-bar-glyph (floor (/ 4-remainder 2)))
3821 (2-remainder (remainder 4-remainder 2))
3822 (1-bar-glyph (floor (/ 2-remainder 1))))
3823 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3825 ;; Get the correct mmr-glyphs.
3826 ;; Store them in a list.
3828 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3829 ;; -> ("rests.M3" "rests.M1")
3830 (define (get-mmr-glyphs lst1 lst2)
3831 (define (helper l1 l2 l3)
3836 (append (make-list (car l1) (car l2)) l3))))
3837 (helper lst1 lst2 '()))
3839 ;; If duration is not valid, print a warning and return empty-stencil
3840 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3841 (not multi-measure-rest))
3842 (and (= (string-length (car (string-split duration #\. ))) 1)
3843 (= (string->number (car (string-split duration #\. ))) 0)))
3845 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3848 ;; For simple rests:
3849 ;; Get a (log dots) list.
3850 (parsed (parse-simple-duration duration))
3851 ;; Create the rest-stencil
3853 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3854 ;; For MultiMeasureRests:
3855 ;; Get the duration-part of duration
3856 (dur-part-string (car (string-split duration #\. )))
3857 ;; Get the duration of MMR:
3858 ;; If not a number (eg. "maxima") calculate it.
3860 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3861 ;; Get a list of the correct number of each mmr-glyph.
3862 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3863 ;; Create a list of mmr-stencils,
3864 ;; translating the glyph for a whole rest.
3868 (let ((single-mmr-stil
3869 (rest-by-number-markup layout props (* -1 x) 0)))
3871 (ly:stencil-translate-axis
3873 ;; Ugh, hard-coded, why 1?
3877 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3878 ;; Adjust the space between the mmr-glyphs,
3879 ;; if not default-glyphs are used.
3880 (word-space (if (member style
3881 '(neomensural mensural petrucci))
3882 (/ (* word-space 2) 3)
3884 ;; Create the final mmr-stencil
3885 ;; via `stack-stencil-lineĀ“ from /scm/markup.scm
3886 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3888 ;; Print the number above a multi-measure-rest
3889 ;; Depends on duration, style and multi-measure-rest-number set #t
3890 (if (and multi-measure-rest
3891 multi-measure-rest-number
3893 (not (member style '(neomensural mensural petrucci))))
3894 (let* ((mmr-stil-x-center
3895 (interval-center (ly:stencil-extent mmr-stil X)))
3899 #:override '(font-encoding . fetaText)
3900 (number->string mmr-duration)))
3902 (interpret-markup layout props duration-markup))
3903 (mmr-number-stil-x-center
3904 (interval-center (ly:stencil-extent mmr-number-stil X))))
3906 (set! mmr-stil (ly:stencil-combine-at-edge
3909 (ly:stencil-translate-axis
3911 (- mmr-stil-x-center mmr-number-stil-x-center)
3915 (if multi-measure-rest
3919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3921 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3923 (define-markup-command (fermata layout props) ()
3925 #:properties ((direction UP))
3926 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
3927 an inverted glyph. Note that within music, one would usually use the
3928 @code{\\fermata} articulation instead of a markup.
3930 @lilypond[verbatim,quote]
3931 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
3933 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
3936 (interpret-markup layout props
3937 (if (eqv? direction DOWN)
3938 (markup #:musicglyph "scripts.dfermata")
3939 (markup #:musicglyph "scripts.ufermata"))))
3941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3945 (define-markup-command (lower layout props amount arg)
3949 @cindex lowering text
3951 Lower @var{arg} by the distance @var{amount}.
3952 A negative @var{amount} indicates raising; see also @code{\\raise}.
3954 @lilypond[verbatim,quote]
3962 (ly:stencil-translate-axis (interpret-markup layout props arg)
3965 (define-markup-command (translate-scaled layout props offset arg)
3966 (number-pair? markup?)
3968 #:properties ((font-size 0))
3970 @cindex translating text
3971 @cindex scaling text
3973 Translate @var{arg} by @var{offset}, scaling the offset by the
3976 @lilypond[verbatim,quote]
3979 * \\translate #'(2 . 3) translate
3981 * \\translate-scaled #'(2 . 3) translate-scaled
3985 (let* ((factor (magstep font-size))
3986 (scaled (cons (* factor (car offset))
3987 (* factor (cdr offset)))))
3988 (ly:stencil-translate (interpret-markup layout props arg)
3991 (define-markup-command (raise layout props amount arg)
3995 @cindex raising text
3997 Raise @var{arg} by the distance @var{amount}.
3998 A negative @var{amount} indicates lowering, see also @code{\\lower}.
4000 The argument to @code{\\raise} is the vertical displacement amount,
4001 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
4002 raise objects in relation to their surrounding markups.
4004 If the text object itself is positioned above or below the staff, then
4005 @code{\\raise} cannot be used to move it, since the mechanism that
4006 positions it next to the staff cancels any shift made with
4007 @code{\\raise}. For vertical positioning, use the @code{padding}
4008 and/or @code{extra-offset} properties.
4010 @lilypond[verbatim,quote]
4019 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4021 (define-markup-command (fraction layout props arg1 arg2)
4024 #:properties ((font-size 0))
4026 @cindex creating text fractions
4028 Make a fraction of two markups.
4029 @lilypond[verbatim,quote]
4035 (let* ((m1 (interpret-markup layout props arg1))
4036 (m2 (interpret-markup layout props arg2))
4037 (factor (magstep font-size))
4038 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4039 (padding (* factor 0.2))
4040 (baseline (* factor 0.6))
4041 (offset (* factor 0.75)))
4042 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4043 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4044 (let* ((x1 (ly:stencil-extent m1 X))
4045 (x2 (ly:stencil-extent m2 X))
4046 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4047 ;; should stack mols separately, to maintain LINE on baseline
4048 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4050 (ly:stencil-aligned-to stack Y CENTER))
4052 (ly:stencil-aligned-to stack X LEFT))
4053 ;; should have EX dimension
4055 (ly:stencil-translate-axis stack offset Y))))
4057 (define-markup-command (normal-size-super layout props arg)
4060 #:properties ((font-size 0))
4062 @cindex setting superscript in standard font size
4064 Set @var{arg} in superscript with a normal font size.
4066 @lilypond[verbatim,quote]
4069 \\normal-size-super {
4070 superscript in standard size
4074 (ly:stencil-translate-axis
4075 (interpret-markup layout props arg)
4076 (* 1.0 (magstep font-size)) Y))
4078 (define-markup-command (super layout props arg)
4081 #:properties ((font-size 0))
4083 @cindex superscript text
4085 Set @var{arg} in superscript.
4087 @lilypond[verbatim,quote]
4097 (ly:stencil-translate-axis
4100 (cons `((font-size . ,(- font-size 3))) props)
4102 (* 1.0 (magstep font-size)) ; original font-size
4105 (define-markup-command (translate layout props offset arg)
4106 (number-pair? markup?)
4109 @cindex translating text
4111 Translate @var{arg} relative to its surroundings. @var{offset}
4112 is a pair of numbers representing the displacement in the X and Y axis.
4114 @lilypond[verbatim,quote]
4117 \\translate #'(2 . 3)
4118 \\line { translated two spaces right, three up }
4121 (ly:stencil-translate (interpret-markup layout props arg)
4124 (define-markup-command (sub layout props arg)
4127 #:properties ((font-size 0))
4129 @cindex subscript text
4131 Set @var{arg} in subscript.
4133 @lilypond[verbatim,quote]
4144 (ly:stencil-translate-axis
4147 (cons `((font-size . ,(- font-size 3))) props)
4149 (* -0.75 (magstep font-size)) ; original font-size
4152 (define-markup-command (normal-size-sub layout props arg)
4155 #:properties ((font-size 0))
4157 @cindex setting subscript in standard font size
4159 Set @var{arg} in subscript with a normal font size.
4161 @lilypond[verbatim,quote]
4165 subscript in standard size
4169 (ly:stencil-translate-axis
4170 (interpret-markup layout props arg)
4171 (* -0.75 (magstep font-size))
4174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4178 (define-markup-command (hbracket layout props arg)
4182 @cindex placing horizontal brackets around text
4184 Draw horizontal brackets around @var{arg}.
4186 @lilypond[verbatim,quote]
4195 (let ((th 0.1) ;; todo: take from GROB.
4196 (m (interpret-markup layout props arg)))
4197 (bracketify-stencil m X th (* 2.5 th) th)))
4199 (define-markup-command (bracket layout props arg)
4203 @cindex placing vertical brackets around text
4205 Draw vertical brackets around @var{arg}.
4207 @lilypond[verbatim,quote]
4214 (let ((th 0.1) ;; todo: take from GROB.
4215 (m (interpret-markup layout props arg)))
4216 (bracketify-stencil m Y th (* 2.5 th) th)))
4218 (define-markup-command (parenthesize layout props arg)
4221 #:properties ((angularity 0)
4227 @cindex placing parentheses around text
4229 Draw parentheses around @var{arg}. This is useful for parenthesizing
4230 a column containing several lines of text.
4232 @lilypond[verbatim,quote]
4241 \\override #'(angularity . 2) {
4252 (let* ((m (interpret-markup layout props arg))
4253 (scaled-width (* size width))
4255 (* (chain-assoc-get 'line-thickness props 0.1)
4258 (min (* size 0.5 scaled-thickness)
4259 (* (/ 4 3.0) scaled-width)))
4260 (padding (chain-assoc-get 'padding props half-thickness)))
4261 (parenthesize-stencil
4262 m half-thickness scaled-width angularity padding)))
4265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4266 ;; Delayed markup evaluation
4267 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4269 (define-markup-command (page-ref layout props label gauge default)
4270 (symbol? markup? markup?)
4273 @cindex referencing page numbers in text
4275 Reference to a page number. @var{label} is the label set on the referenced
4276 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4277 the maximum width of the page number, and @var{default} the value to display
4278 when @var{label} is not found.
4280 (If the current book or bookpart is set to use roman numerals for page numbers,
4281 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4282 width may require additional tweaking.)"
4283 (let* ((gauge-stencil (interpret-markup layout props gauge))
4284 (x-ext (ly:stencil-extent gauge-stencil X))
4285 (y-ext (ly:stencil-extent gauge-stencil Y)))
4287 (make-transparent-box-stencil x-ext y-ext))
4289 `(delay-stencil-evaluation
4290 ,(delay (ly:stencil-expr
4291 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4292 (page-number (if (list? table)
4293 (assoc-get label table)
4295 (number-type (ly:output-def-lookup layout 'page-number-type))
4296 (page-markup (if page-number
4297 (number-format number-type page-number)
4299 (page-stencil (interpret-markup layout props page-markup))
4300 (gap (- (interval-length x-ext)
4301 (interval-length (ly:stencil-extent page-stencil X)))))
4302 (interpret-markup layout props
4303 (markup #:hspace gap page-markup))))))
4307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4311 (define-markup-command (scale layout props factor-pair arg)
4312 (number-pair? markup?)
4315 @cindex scaling markup
4316 @cindex mirroring markup
4318 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4319 representing the scaling-factor in the X and Y axes.
4320 Negative values may be used to produce mirror images.
4322 @lilypond[verbatim,quote]
4332 (let ((stil (interpret-markup layout props arg))
4333 (sx (car factor-pair))
4334 (sy (cdr factor-pair)))
4335 (ly:stencil-scale stil sx sy)))
4337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4341 (define-markup-command (pattern layout props count axis space pattern)
4342 (integer? integer? number? markup?)
4345 Prints @var{count} times a @var{pattern} markup.
4346 Patterns are spaced apart by @var{space}.
4347 Patterns are distributed on @var{axis}.
4349 @lilypond[verbatim, quote]
4351 \"Horizontally repeated :\"
4352 \\pattern #7 #X #2 \\flat
4354 \"Vertically repeated :\"
4355 \\pattern #3 #Y #0.5 \\flat
4358 (let ((pattern-width (interval-length
4359 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4360 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4361 (let loop ((i (1- count)) (patterns (markup)))
4367 (markup patterns pattern)
4368 (markup #:column (patterns pattern))))
4371 (markup patterns pattern #:hspace space)
4372 (markup #:column (patterns pattern #:vspace space))))))))
4374 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4375 (number? ly:dir? markup? markup? markup?)
4377 #:properties ((word-space)
4380 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4381 with a line of markups @var{pattern} in between.
4382 Patterns are spaced apart by @var{space}.
4383 Patterns are aligned to the @var{dir} markup.
4385 @lilypond[verbatim, quote]
4388 \\fill-with-pattern #1 #RIGHT . first right
4389 \\fill-with-pattern #1 #RIGHT . second right
4391 \"center-aligned :\"
4392 \\fill-with-pattern #1.5 #CENTER - left right
4395 \\override #'(line-width . 50)
4396 \\fill-with-pattern #2 #LEFT : left first
4397 \\override #'(line-width . 50)
4398 \\fill-with-pattern #2 #LEFT : left second
4401 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4402 (pattern-width (interval-length pattern-x-extent))
4403 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4404 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4405 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4406 (period (+ space pattern-width))
4407 (count (truncate (/ (- middle-width pattern-width) period)))
4408 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4409 (interpret-markup layout props
4411 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4412 #:translate (cons x-offset 0)
4413 #:pattern (1+ count) X space pattern
4416 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4420 (define-markup-command (replace layout props replacements arg)
4424 Used to automatically replace a string by another in the markup @var{arg}.
4425 Each pair of the alist @var{replacements} specifies what should be replaced.
4426 The @code{key} is the string to be replaced by the @code{value} string.
4428 @lilypond[verbatim, quote]
4429 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4433 (internal-add-text-replacements
4438 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4439 ;; Markup list commands
4440 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4442 (define-public (space-lines baseline stils)
4443 (let space-stil ((stils stils)
4447 (let* ((stil (car stils))
4448 (dy-top (max (- (/ baseline 1.5)
4449 (interval-bound (ly:stencil-extent stil Y) UP))
4451 (dy-bottom (max (+ (/ baseline 3.0)
4452 (interval-bound (ly:stencil-extent stil Y) DOWN))
4454 (new-stil (ly:make-stencil
4455 (ly:stencil-expr stil)
4456 (ly:stencil-extent stil X)
4457 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4459 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4461 (space-stil (cdr stils) (cons new-stil result))))))
4463 (define-markup-list-command (justified-lines layout props args)
4465 #:properties ((baseline-skip)
4466 wordwrap-internal-markup-list)
4468 @cindex justifying lines of text
4470 Like @code{\\justify}, but return a list of lines instead of a single markup.
4471 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4472 @var{X}@tie{}is the number of staff spaces."
4473 (space-lines baseline-skip
4474 (interpret-markup-list layout props
4475 (make-wordwrap-internal-markup-list #t args))))
4477 (define-markup-list-command (wordwrap-lines layout props args)
4479 #:properties ((baseline-skip)
4480 wordwrap-internal-markup-list)
4481 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4482 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4483 where @var{X} is the number of staff spaces."
4484 (space-lines baseline-skip
4485 (interpret-markup-list layout props
4486 (make-wordwrap-internal-markup-list #f args))))
4488 (define-markup-list-command (column-lines layout props args)
4490 #:properties ((baseline-skip))
4491 "Like @code{\\column}, but return a list of lines instead of a single markup.
4492 @code{baseline-skip} determines the space between each markup in @var{args}."
4493 (space-lines baseline-skip
4494 (interpret-markup-list layout props args)))
4496 (define-markup-list-command (override-lines layout props new-prop args)
4497 (pair? markup-list?)
4498 "Like @code{\\override}, for markup lists."
4499 (interpret-markup-list layout (cons (list new-prop) props) args))
4501 (define-markup-list-command (map-markup-commands layout props compose args)
4502 (procedure? markup-list?)
4503 "This applies the function @var{compose} to every markup in
4504 @var{args} (including elements of markup list command calls) in order
4505 to produce a new markup list. Since the return value from a markup
4506 list command call is not a markup list but rather a list of stencils,
4507 this requires passing those stencils off as the results of individual
4508 markup calls. That way, the results should work out as long as no
4509 markups rely on side effects."
4510 (let ((key (make-symbol "key")))
4514 ;; if `compose' does not actually interpret its markup
4515 ;; argument, we still need to return a list of stencils,
4516 ;; created from the single returned stencil
4518 (interpret-markup layout props
4520 (make-on-the-fly-markup
4521 (lambda (layout props m)
4522 ;; here all effects of `compose' on the
4523 ;; properties should be visible, so we
4524 ;; call interpret-markup-list at this
4525 ;; point of time and harvest its
4528 (interpret-markup-list
4529 layout props args)))
4530 (make-null-markup))))))
4531 (lambda (key stencils)
4534 (interpret-markup layout props
4535 (compose (make-stencil-markup sten))))