1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2012 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 (define-markup-command (draw-line layout props dest)
125 #:properties ((thickness 1))
127 @cindex drawing lines within text
130 @lilypond[verbatim,quote]
132 \\draw-line #'(4 . 4)
133 \\override #'(thickness . 5)
134 \\draw-line #'(-3 . 0)
137 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
141 (make-line-stencil th 0 0 x y)))
143 (define-markup-command (draw-dashed-line layout props dest)
146 #:properties ((thickness 1)
152 @cindex drawing dashed lines within text
156 If @code{full-length} is set to #t (default) the dashed-line extends to the
157 whole length given by @var{dest}, without white space at beginning or end.
158 @code{off} will then be altered to fit.
159 To insist on the given (or default) values of @code{on}, @code{off} use
160 @code{\\override #'(full-length . #f)}
161 Manual settings for @code{on},@code{off} and @code{phase} are possible.
162 @lilypond[verbatim,quote]
164 \\draw-dashed-line #'(5.1 . 2.3)
165 \\override #'(on . 0.3)
166 \\override #'(off . 0.5)
167 \\draw-dashed-line #'(5.1 . 2.3)
170 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
171 ;; Calculate the thickness to be used.
172 (th (* line-thickness thickness))
173 (half-thick (/ th 2))
174 ;; Get the extensions in x- and y-direction.
177 ;; Calculate the length of the dashed line.
178 (line-length (sqrt (+ (expt x 2) (expt y 2)))))
180 (if (and full-length (not (= (+ on off) 0)))
182 ;; Add double-thickness to avoid overlapping.
183 (set! off (+ (* 2 th) off))
184 (let* (;; Make a guess how often the off/on-pair should be printed
185 ;; after the initial `on´.
186 ;; Assume a minimum of 1 to avoid division by zero.
187 (guess (max 1 (round (/ (- line-length on) (+ off on)))))
188 ;; Not sure about the value or why corr is necessary at all,
189 ;; but it seems to be necessary.
191 (/ line-thickness 10)
193 ;; Calculate a new value for off to fit the
195 (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
199 ;; Settings for (= on 0). Resulting in a dotted line.
201 ;; If line-length isn't shorter than `th´, change the given
202 ;; value for `off´ to fit the line-length.
203 ((and (= on 0) (< th line-length))
206 ;; If the line-length is shorter than `th´, it makes no
207 ;; sense to adjust `off´. The rounded edges of the lines
208 ;; would prevent any nice output.
210 ;; This will result in a single dot for very short lines.
211 ((and (= on 0) (>= th line-length))
214 ;; Settings for (not (= on 0)). Resulting in a dashed line.
216 ;; If line-length isn't shorter than one go of on-off-on,
217 ;; change the given value for `off´ to fit the line-length.
218 ((< (+ (* 2 on) off) line-length)
220 ;; If the line-length is too short, but greater than
221 ;; (* 4 th) set on/off to (/ line-length 3)
222 ((< (* 4 th) line-length)
223 (set! on (/ line-length 3))
224 (set! off (/ line-length 3)))
225 ;; If the line-length is shorter than (* 4 th), it makes
226 ;; no sense trying to adjust on/off. The rounded edges of
227 ;; the lines would prevent any nice output.
228 ;; Simply set `on´ to line-length.
230 (set! on line-length))))))
232 ;; If `on´ or `off´ is negative, or the sum of `on' and `off' equals zero a
233 ;; ghostscript-error occurs while calling
234 ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
235 ;; Better be paranoid.
236 (if (or (= (+ on off) 0)
240 (ly:warning "Can't print a line - setting on/off to default")
244 ;; To give the lines produced by \draw-line and \draw-dashed-line the same
245 ;; length, half-thick has to be added to the stencil-extensions.
247 (list 'dashed-line th on off x y phase)
248 (interval-widen (ordered-cons 0 x) half-thick)
249 (interval-widen (ordered-cons 0 y) half-thick))))
251 (define-markup-command (draw-dotted-line layout props dest)
254 #:properties ((thickness 1)
258 @cindex drawing dotted lines within text
262 The dotted-line always extends to the whole length given by @var{dest}, without
263 white space at beginning or end.
264 Manual settings for @code{off} are possible to get larger or smaller space
266 The given (or default) value of @code{off} will be altered to fit the
268 @lilypond[verbatim,quote]
270 \\draw-dotted-line #'(5.1 . 2.3)
271 \\override #'(thickness . 2)
272 \\override #'(off . 0.2)
273 \\draw-dotted-line #'(5.1 . 2.3)
277 (let ((new-props (prepend-alist-chain 'on 0
278 (prepend-alist-chain 'full-length #t props))))
280 (interpret-markup layout
282 (markup #:draw-dashed-line dest))))
284 (define-markup-command (draw-hline layout props)
287 #:properties ((draw-line-markup)
291 @cindex drawing a line across a page
293 Draws a line across a page, where the property @code{span-factor}
294 controls what fraction of the page is taken up.
295 @lilypond[verbatim,quote]
299 \\override #'(span-factor . 1/3)
304 (interpret-markup layout
306 (markup #:draw-line (cons (* line-width
310 (define-markup-command (draw-circle layout props radius thickness filled)
311 (number? number? boolean?)
314 @cindex drawing circles within text
316 A circle of radius @var{radius} and thickness @var{thickness},
319 @lilypond[verbatim,quote]
321 \\draw-circle #2 #0.5 ##f
323 \\draw-circle #2 #0 ##t
326 (make-circle-stencil radius thickness filled))
328 (define-markup-command (triangle layout props filled)
331 #:properties ((thickness 0.1)
335 @cindex drawing triangles within text
337 A triangle, either filled or empty.
339 @lilypond[verbatim,quote]
346 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
355 (cons 0 (* .86 ex)))))
357 (define-markup-command (circle layout props arg)
360 #:properties ((thickness 1)
362 (circle-padding 0.2))
364 @cindex circling text
366 Draw a circle around @var{arg}. Use @code{thickness},
367 @code{circle-padding} and @code{font-size} properties to determine line
368 thickness and padding around the markup.
370 @lilypond[verbatim,quote]
377 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
379 (pad (* (magstep font-size) circle-padding))
380 (m (interpret-markup layout props arg)))
381 (circle-stencil m th pad)))
383 (define-markup-command (ellipse layout props arg)
386 #:properties ((thickness 1)
391 @cindex drawing ellipse around text
393 Draw an ellipse around @var{arg}. Use @code{thickness},
394 @code{x-padding}, @code{y-padding} and @code{font-size} properties to determine
395 line thickness and padding around the markup.
397 @lilypond[verbatim,quote]
404 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
406 (pad-x (* (magstep font-size) x-padding))
407 (pad-y (* (magstep font-size) y-padding))
408 (m (interpret-markup layout props arg)))
409 (ellipse-stencil m th pad-x pad-y)))
411 (define-markup-command (oval layout props arg)
414 #:properties ((thickness 1)
419 @cindex drawing oval around text
421 Draw an oval around @var{arg}. Use @code{thickness},
422 @code{x-padding}, @code{x-padding} and @code{font-size} properties to determine
423 line thickness and padding around the markup.
425 @lilypond[verbatim,quote]
432 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
434 (pad-x (* (magstep font-size) x-padding))
435 (pad-y (* (magstep font-size) y-padding))
436 (m (interpret-markup layout props arg)))
437 (oval-stencil m th pad-x pad-y)))
439 (define-markup-command (with-url layout props url arg)
443 @cindex inserting URL links into text
445 Add a link to URL @var{url} around @var{arg}. This only works in
448 @lilypond[verbatim,quote]
450 \\with-url #\"http://lilypond.org/\" {
451 LilyPond ... \\italic {
452 music notation for everyone
457 (let* ((stil (interpret-markup layout props arg))
458 (xextent (ly:stencil-extent stil X))
459 (yextent (ly:stencil-extent stil Y))
460 (old-expr (ly:stencil-expr stil))
461 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
463 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
465 (define-markup-command (page-link layout props page-number arg)
469 @cindex referencing page numbers in text
471 Add a link to the page @var{page-number} around @var{arg}. This only works
474 @lilypond[verbatim,quote]
476 \\page-link #2 { \\italic { This links to page 2... } }
479 (let* ((stil (interpret-markup layout props arg))
480 (xextent (ly:stencil-extent stil X))
481 (yextent (ly:stencil-extent stil Y))
482 (old-expr (ly:stencil-expr stil))
483 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
485 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
487 (define-markup-command (with-link layout props label arg)
491 @cindex referencing page labels in text
493 Add a link to the page holding label @var{label} around @var{arg}. This
494 only works in the PDF backend.
496 @lilypond[verbatim,quote]
498 \\with-link #'label {
499 \\italic { This links to the page containing the label... }
503 (let* ((arg-stencil (interpret-markup layout props arg))
504 (x-ext (ly:stencil-extent arg-stencil X))
505 (y-ext (ly:stencil-extent arg-stencil Y)))
508 `(delay-stencil-evaluation
509 ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
510 (page-number (if (list? table)
511 (assoc-get label table)
513 (list 'page-link page-number
514 `(quote ,x-ext) `(quote ,y-ext)))))
520 (define-markup-command (beam layout props width slope thickness)
521 (number? number? number?)
524 @cindex drawing beams within text
526 Create a beam with the specified parameters.
527 @lilypond[verbatim,quote]
532 (let* ((y (* slope width))
533 (yext (cons (min 0 y) (max 0 y)))
534 (half (/ thickness 2)))
539 width (+ (* width slope) (/ thickness -2))
540 width (+ (* width slope) (/ thickness 2))
542 ,(ly:output-def-lookup layout 'blot-diameter)
545 (cons (+ (- half) (car yext))
546 (+ half (cdr yext))))))
548 (define-markup-command (underline layout props arg)
551 #:properties ((thickness 1) (offset 2))
553 @cindex underlining text
555 Underline @var{arg}. Looks at @code{thickness} to determine line
556 thickness, and @code{offset} to determine line y-offset.
558 @lilypond[verbatim,quote]
559 \\markup \\fill-line {
560 \\underline \"underlined\"
561 \\override #'(offset . 5)
562 \\override #'(thickness . 1)
563 \\underline \"underlined\"
564 \\override #'(offset . 1)
565 \\override #'(thickness . 5)
566 \\underline \"underlined\"
569 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
570 (underline-thick (* thickness thick))
571 (markup (interpret-markup layout props arg))
572 (x1 (car (ly:stencil-extent markup X)))
573 (x2 (cdr (ly:stencil-extent markup X)))
574 (y (* thick (- offset)))
575 (line (make-line-stencil underline-thick x1 y x2 y)))
576 (ly:stencil-add markup line)))
578 (define-markup-command (box layout props arg)
581 #:properties ((thickness 1)
585 @cindex enclosing text within a box
587 Draw a box round @var{arg}. Looks at @code{thickness},
588 @code{box-padding} and @code{font-size} properties to determine line
589 thickness and padding around the markup.
591 @lilypond[verbatim,quote]
593 \\override #'(box-padding . 0.5)
598 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
600 (pad (* (magstep font-size) box-padding))
601 (m (interpret-markup layout props arg)))
602 (box-stencil m th pad)))
604 (define-markup-command (filled-box layout props xext yext blot)
605 (number-pair? number-pair? number?)
608 @cindex drawing solid boxes within text
609 @cindex drawing boxes with rounded corners
611 Draw a box with rounded corners of dimensions @var{xext} and
612 @var{yext}. For example,
614 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
616 creates a box extending horizontally from -0.3 to 1.8 and
617 vertically from -0.3 up to 1.8, with corners formed from a
618 circle of diameter@tie{}0 (i.e., sharp corners).
620 @lilypond[verbatim,quote]
622 \\filled-box #'(0 . 4) #'(0 . 4) #0
623 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
624 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
626 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
632 (define-markup-command (rounded-box layout props arg)
635 #:properties ((thickness 1)
639 "@cindex enclosing text in a box with rounded corners
640 @cindex drawing boxes with rounded corners around text
641 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
642 @code{box-padding} and @code{font-size} properties to determine line
643 thickness and padding around the markup; the @code{corner-radius} property
644 makes it possible to define another shape for the corners (default is 1).
646 @lilypond[quote,verbatim,relative=2]
654 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
656 (pad (* (magstep font-size) box-padding))
657 (m (interpret-markup layout props arg)))
658 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
661 (define-markup-command (rotate layout props ang arg)
665 @cindex rotating text
667 Rotate object with @var{ang} degrees around its center.
669 @lilypond[verbatim,quote]
679 (let* ((stil (interpret-markup layout props arg)))
680 (ly:stencil-rotate stil ang 0 0)))
682 (define-markup-command (whiteout layout props arg)
686 @cindex adding a white background to text
688 Provide a white background for @var{arg}.
690 @lilypond[verbatim,quote]
693 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
697 (stencil-whiteout (interpret-markup layout props arg)))
699 (define-markup-command (pad-markup layout props amount arg)
704 @cindex putting space around text
706 Add space around a markup object.
707 Identical to @code{pad-around}.
709 @lilypond[verbatim,quote]
722 (let* ((m (interpret-markup layout props arg))
723 (x (interval-widen (ly:stencil-extent m X) amount))
724 (y (interval-widen (ly:stencil-extent m Y) amount)))
725 (ly:stencil-add (make-transparent-box-stencil x y)
728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732 (define-markup-command (strut layout props)
736 @cindex creating vertical spaces in text
738 Create a box of the same height as the space in the current font."
739 (let ((m (ly:text-interface::interpret-markup layout props " ")))
740 (ly:make-stencil (ly:stencil-expr m)
742 (ly:stencil-extent m X)
745 (define-markup-command (hspace layout props amount)
749 @cindex creating horizontal spaces in text
751 Create an invisible object taking up horizontal space @var{amount}.
753 @lilypond[verbatim,quote]
762 (ly:make-stencil "" (cons 0 amount) empty-interval))
764 (define-markup-command (vspace layout props amount)
768 @cindex creating vertical spaces in text
770 Create an invisible object taking up vertical space
771 of @var{amount} multiplied by 3.
773 @lilypond[verbatim,quote]
784 (let ((amount (* amount 3.0)))
785 (ly:make-stencil "" empty-interval (cons 0 amount))))
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
789 ;; importing graphics.
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792 (define-markup-command (stencil layout props stil)
796 @cindex importing stencils into text
798 Use a stencil as markup.
800 @lilypond[verbatim,quote]
802 \\stencil #(make-circle-stencil 2 0 #t)
808 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
810 (define (get-postscript-bbox string)
811 "Extract the bbox from STRING, or return #f if not present."
813 ((match (regexp-exec bbox-regexp string)))
817 (string->number (match:substring match x)))
822 (define-markup-command (epsfile layout props axis size file-name)
823 (number? number? string?)
826 @cindex inlining an Encapsulated PostScript image
828 Inline an EPS image. The image is scaled along @var{axis} to
831 @lilypond[verbatim,quote]
833 \\general-align #Y #DOWN {
834 \\epsfile #X #20 #\"context-example.eps\"
835 \\epsfile #Y #20 #\"context-example.eps\"
839 (if (ly:get-option 'safe)
840 (interpret-markup layout props "not allowed in safe")
841 (eps-file->stencil axis size file-name)
844 (define-markup-command (postscript layout props str)
848 @cindex inserting PostScript directly into text
849 This inserts @var{str} directly into the output as a PostScript
852 @lilypond[verbatim,quote]
856 0.4 0.6 0.5 0 361 arc
858 1.0 0.6 0.5 0 361 arc
863 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
864 \\postscript #ringsps
876 gsave currentpoint translate
884 (define-markup-command (path layout props thickness commands) (number? list?)
886 #:properties ((line-cap-style 'round)
887 (line-join-style 'round)
890 @cindex paths, drawing
891 @cindex drawing paths
892 Draws a path with line @var{thickness} according to the
893 directions given in @var{commands}. @var{commands} is a list of
894 lists where the @code{car} of each sublist is a drawing command and
895 the @code{cdr} comprises the associated arguments for each command.
897 There are seven commands available to use in the list
898 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
899 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
900 @code{closepath}. Note that the commands that begin with @emph{r}
901 are the relative variants of the other three commands.
903 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
904 @code{rlineto} take 2 arguments; they are the X and Y coordinates
905 for the destination point.
907 The commands @code{curveto} and @code{rcurveto} create cubic
908 Bézier curves, and take 6 arguments; the first two are the X and Y
909 coordinates for the first control point, the second two are the X
910 and Y coordinates for the second control point, and the last two
911 are the X and Y coordinates for the destination point.
913 The @code{closepath} command takes zero arguments and closes the
914 current subpath in the active path.
916 Note that a sequence of commands @emph{must} begin with a
917 @code{moveto} or @code{rmoveto} to work with the SVG output.
919 Line-cap styles and line-join styles may be customized by
920 overriding the @code{line-cap-style} and @code{line-join-style}
921 properties, respectively. Available line-cap styles are
922 @code{'butt}, @code{'round}, and @code{'square}. Available
923 line-join styles are @code{'miter}, @code{'round}, and
926 The property @code{filled} specifies whether or not the path is
929 @lilypond[verbatim,quote]
935 (curveto -5 -5 -5 5 -1 0)
939 \\path #0.25 #samplePath
941 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
943 \\override #'(filled . #t) \\path #0.25 #samplePath
946 (let* ((half-thickness (/ thickness 2))
947 (current-point '(0 . 0))
948 (set-point (lambda (lst) (set! current-point lst)))
949 (relative? (lambda (x)
950 (string-prefix? "r" (symbol->string (car x)))))
951 ;; For calculating extents, we want to modify the command
952 ;; list so that all coordinates are absolute.
953 (new-commands (map (lambda (x)
955 ;; for rmoveto, rlineto
956 ((and (relative? x) (= 3 (length x)))
958 (+ (car current-point)
960 (+ (cdr current-point)
966 ((and (relative? x) (= 7 (length x)))
967 (let* ((old-cp current-point)
974 (list (+ (car old-cp) (second x))
975 (+ (cdr old-cp) (third x))
976 (+ (car old-cp) (fourth x))
977 (+ (cdr old-cp) (fifth x))
980 ;; for moveto, lineto
982 (set-point (cons (second x)
987 (set-point (cons (sixth x)
990 ;; keep closepath for filtering;
991 ;; see `without-closepath'.
994 ;; path-min-max does not accept 0-arg lists,
995 ;; and since closepath does not affect extents, filter
996 ;; out those commands here.
997 (without-closepath (filter (lambda (x)
998 (not (equal? 'closepath (car x))))
1000 (extents (path-min-max
1001 ;; set the origin to the first moveto
1002 (list (list-ref (car without-closepath) 0)
1003 (list-ref (car without-closepath) 1))
1005 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1006 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1007 (command-list (fold-right append '() commands)))
1009 ;; account for line thickness
1010 (set! X-extent (interval-widen X-extent half-thickness))
1011 (set! Y-extent (interval-widen Y-extent half-thickness))
1014 `(path ,thickness `(,@',command-list)
1015 ',line-cap-style ',line-join-style ,filled)
1019 (define-markup-command (score layout props score)
1022 #:properties ((baseline-skip))
1024 @cindex inserting music into text
1026 Inline an image of music. The reference point (usually the middle
1027 staff line) of the lowest staff in the top system is placed on the
1030 @lilypond[verbatim,quote]
1034 \\new Staff \\relative c' {
1037 \\mark \\markup { Allegro }
1043 \\new Staff \\relative c {
1049 f,( bes d bes d bes)
1057 \\override RehearsalMark
1058 #'break-align-symbols = #'(time-signature key-signature)
1059 \\override RehearsalMark
1060 #'self-alignment-X = #LEFT
1064 \\override TimeSignature
1065 #'break-align-anchor-alignment = #LEFT
1071 (let ((output (ly:score-embedded-format score layout)))
1073 (if (ly:music-output? output)
1074 (let ((paper-systems
1076 (ly:paper-score-paper-systems output))))
1077 (if (pair? paper-systems)
1078 ;; shift such that the refpoint of the bottom staff of
1079 ;; the first system is the baseline of the score
1080 (ly:stencil-translate-axis
1081 (stack-stencils Y DOWN baseline-skip
1082 (map paper-system-stencil paper-systems))
1083 (- (car (paper-system-staff-extents (car paper-systems))))
1087 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1090 (define-markup-command (null layout props)
1094 @cindex creating empty text objects
1096 An empty markup with extents of a single point.
1098 @lilypond[verbatim,quote]
1105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1106 ;; basic formatting.
1107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1109 (define-markup-command (simple layout props str)
1113 @cindex simple text strings
1115 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1116 @code{\\markup @{ \\simple #\"foo\" @}}.
1118 Note: for creating standard text markup or defining new markup commands,
1119 the use of @code{\\simple} is unnecessary.
1121 @lilypond[verbatim,quote]
1123 \\simple #\"simple\"
1125 \\simple #\"strings\"
1128 (interpret-markup layout props str))
1130 (define-markup-command (tied-lyric layout props str)
1133 #:properties ((word-space))
1135 @cindex simple text strings with tie characters
1137 Like simple-markup, but use tie characters for @q{~} tilde symbols.
1139 @lilypond[verbatim,quote]
1141 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
1142 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
1143 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
1146 (define (replace-ties tie str)
1147 (if (string-contains str "~")
1149 ((half-space (/ word-space 2))
1150 (parts (string-split str #\~))
1151 (tie-str (markup #:hspace half-space
1153 #:hspace half-space))
1154 (joined (list-join parts tie-str)))
1155 (make-concat-markup joined))
1158 (define short-tie-regexp (make-regexp "~[^.]~"))
1159 (define (match-short str) (regexp-exec short-tie-regexp str))
1161 (define (replace-short str mkp)
1162 (let ((match (match-short str)))
1164 (make-concat-markup (list
1166 (replace-ties "ties.lyric.default" str)))
1167 (let ((new-str (match:suffix match))
1168 (new-mkp (make-concat-markup (list
1170 (replace-ties "ties.lyric.default"
1171 (match:prefix match))
1172 (replace-ties "ties.lyric.short"
1173 (match:substring match))))))
1174 (replace-short new-str new-mkp)))))
1176 (interpret-markup layout
1178 (replace-short str (markup))))
1180 (define-public empty-markup
1181 (make-simple-markup ""))
1183 ;; helper for justifying lines.
1184 (define (get-fill-space word-count line-width word-space text-widths)
1185 "Calculate the necessary paddings between each two adjacent texts.
1186 The lengths of all texts are stored in @var{text-widths}.
1187 The normal formula for the padding between texts a and b is:
1188 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1189 The first and last padding have to be calculated specially using the
1190 whole length of the first or last text.
1191 All paddings are checked to be at least word-space, to ensure that
1193 Return a list of paddings."
1195 ((null? text-widths) '())
1197 ;; special case first padding
1198 ((= (length text-widths) word-count)
1200 (- (- (/ line-width (1- word-count)) (car text-widths))
1201 (/ (car (cdr text-widths)) 2))
1202 (get-fill-space word-count line-width word-space (cdr text-widths))))
1203 ;; special case last padding
1204 ((= (length text-widths) 2)
1205 (list (- (/ line-width (1- word-count))
1206 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
1208 (let ((default-padding
1209 (- (/ line-width (1- word-count))
1210 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
1212 (if (> word-space default-padding)
1215 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
1217 (define-markup-command (fill-line layout props args)
1220 #:properties ((text-direction RIGHT)
1223 "Put @var{markups} in a horizontal line of width @var{line-width}.
1224 The markups are spaced or flushed to fill the entire line.
1225 If there are no arguments, return an empty stencil.
1227 @lilypond[verbatim,quote]
1231 Words evenly spaced across the page
1235 \\line { Text markups }
1237 \\italic { evenly spaced }
1239 \\line { across the page }
1244 (let* ((orig-stencils (interpret-markup-list layout props args))
1247 (if (ly:stencil-empty? stc)
1249 stc)) orig-stencils))
1252 (if (ly:stencil-empty? stc)
1254 (interval-length (ly:stencil-extent stc X))))
1256 (text-width (apply + text-widths))
1257 (word-count (length stencils))
1258 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1263 (/ (- line-width text-width) 2)
1264 (/ (- line-width text-width) 2)))
1267 (- line-width text-width)))
1269 (get-fill-space word-count line-width word-space text-widths))))
1271 (line-contents (if (= word-count 1)
1278 (if (null? (remove ly:stencil-empty? orig-stencils))
1281 (if (= text-direction LEFT)
1282 (set! line-contents (reverse line-contents)))
1284 (stack-stencils-padding-list
1285 X RIGHT fill-space line-contents))
1286 (if (> word-count 1)
1287 ;; shift s.t. stencils align on the left edge, even if
1288 ;; first stencil had negative X-extent (e.g. center-column)
1289 ;; (if word-count = 1, X-extents are already normalized in
1290 ;; the definition of line-contents)
1292 (ly:stencil-translate-axis
1294 (- (car (ly:stencil-extent (car stencils) X)))
1298 (define-markup-command (line layout props args)
1301 #:properties ((word-space)
1302 (text-direction RIGHT))
1303 "Put @var{args} in a horizontal line. The property @code{word-space}
1304 determines the space between markups in @var{args}.
1306 @lilypond[verbatim,quote]
1313 (let ((stencils (interpret-markup-list layout props args)))
1314 (if (= text-direction LEFT)
1315 (set! stencils (reverse stencils)))
1316 (stack-stencil-line word-space stencils)))
1318 (define-markup-command (concat layout props args)
1322 @cindex concatenating text
1323 @cindex ligatures in text
1325 Concatenate @var{args} in a horizontal line, without spaces in between.
1326 Strings and simple markups are concatenated on the input level, allowing
1327 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1328 equivalent to @code{\"fi\"}.
1330 @lilypond[verbatim,quote]
1339 (define (concat-string-args arg-list)
1340 (fold-right (lambda (arg result-list)
1341 (let ((result (if (pair? result-list)
1344 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1345 (set! arg (cadr arg)))
1346 (if (and (string? result) (string? arg))
1347 (cons (string-append arg result) (cdr result-list))
1348 (cons arg result-list))))
1352 (interpret-markup layout
1353 (prepend-alist-chain 'word-space 0 props)
1355 (make-override-lines-markup-list
1357 (chain-assoc-get 'word-space props))
1358 (if (markup-command-list? args)
1360 (concat-string-args args))))))
1362 (define (wordwrap-stencils stencils
1363 justify base-space line-width text-dir)
1364 "Perform simple wordwrap, return stencil of each line."
1365 (define space (if justify
1366 ;; justify only stretches lines.
1369 (define (stencil-len s)
1370 (interval-end (ly:stencil-extent s X)))
1371 (define (maybe-shift line)
1372 (if (= text-dir LEFT)
1373 (ly:stencil-translate-axis
1375 (- line-width (stencil-len line))
1378 (if (null? stencils)
1380 (let loop ((lines '())
1383 ((line (first todo))
1385 (word-list (list (first todo))))
1388 (let ((new (if (= text-dir LEFT)
1389 (ly:stencil-stack (car todo) X RIGHT line space)
1390 (ly:stencil-stack line X RIGHT (car todo) space))))
1392 ((<= (stencil-len new) line-width)
1393 (word-loop new (cdr todo)
1394 (cons (car todo) word-list)))
1397 ;; This depends on stencil stacking being
1398 ;; associative so that stacking
1399 ;; left-to-right and right-to-left leads to
1401 (if (= text-dir LEFT)
1403 (reverse! word-list)))
1404 (len (stencil-len line))
1405 (stretch (- line-width len))
1408 (stack-stencils X RIGHT (1+ space) word-list))
1411 ;; Uh oh, nothing to fill.
1412 (loop (cons (maybe-shift line) lines) todo)
1414 (stack-stencils X RIGHT
1415 (+ space (/ stretch spaces))
1419 (else ;; not justify
1420 (loop (cons (maybe-shift line) lines) todo)))))
1423 ;; Now we have the last line assembled with space
1424 ;; which is compressed. We want to use the
1425 ;; uncompressed version instead if it fits, and the
1426 ;; justified version if it doesn't.
1428 ;; This depends on stencil stacking being
1429 ;; associative so that stacking
1430 ;; left-to-right and right-to-left leads to
1432 (if (= text-dir LEFT)
1434 (reverse! word-list)))
1435 (big-line (stack-stencils X RIGHT base-space word-list))
1436 (big-len (stencil-len big-line))
1437 (len (stencil-len line)))
1440 (if (> big-len line-width)
1441 (stack-stencils X RIGHT
1444 (* (- big-len line-width)
1446 (* (- line-width len)
1450 (maybe-shift big-line))))))
1451 (else ;; not justify
1452 (reverse! lines (list (maybe-shift line)))))))))
1455 (define-markup-list-command (wordwrap-internal layout props justify args)
1456 (boolean? markup-list?)
1457 #:properties ((line-width #f)
1459 (text-direction RIGHT))
1460 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1461 (wordwrap-stencils (interpret-markup-list layout props args)
1465 (ly:output-def-lookup layout 'line-width))
1468 (define-markup-command (justify layout props args)
1471 #:properties ((baseline-skip)
1472 wordwrap-internal-markup-list)
1474 @cindex justifying text
1476 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1477 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1478 @var{X}@tie{}is the number of staff spaces.
1480 @lilypond[verbatim,quote]
1483 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1484 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1485 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1486 laboris nisi ut aliquip ex ea commodo consequat.
1490 (stack-lines DOWN 0.0 baseline-skip
1491 (wordwrap-internal-markup-list layout props #t args)))
1493 (define-markup-command (wordwrap layout props args)
1496 #:properties ((baseline-skip)
1497 wordwrap-internal-markup-list)
1498 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1499 the line width, where @var{X} is the number of staff spaces.
1501 @lilypond[verbatim,quote]
1504 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1505 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1506 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1507 laboris nisi ut aliquip ex ea commodo consequat.
1511 (stack-lines DOWN 0.0 baseline-skip
1512 (wordwrap-internal-markup-list layout props #f args)))
1514 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1516 #:properties ((line-width)
1518 (text-direction RIGHT))
1519 "Internal markup list command used to define @code{\\justify-string} and
1520 @code{\\wordwrap-string}."
1521 (let* ((para-strings (regexp-split
1522 (string-regexp-substitute
1524 (string-regexp-substitute "\r\n" "\n" arg))
1525 "\n[ \t\n]*\n[ \t\n]*"))
1526 (list-para-words (map (lambda (str)
1527 (regexp-split str "[ \t\n]+"))
1529 (para-lines (map (lambda (words)
1532 (interpret-markup layout props x))
1534 (wordwrap-stencils stencils
1536 line-width text-direction)))
1538 (concatenate para-lines)))
1540 (define-markup-command (wordwrap-string layout props arg)
1543 #:properties ((baseline-skip)
1544 wordwrap-string-internal-markup-list)
1545 "Wordwrap a string. Paragraphs may be separated with double newlines.
1547 @lilypond[verbatim,quote]
1549 \\override #'(line-width . 40)
1550 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1551 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1552 et dolore magna aliqua.
1555 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1556 laboris nisi ut aliquip ex ea commodo consequat.
1559 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1560 qui officia deserunt mollit anim id est laborum\"
1563 (stack-lines DOWN 0.0 baseline-skip
1564 (wordwrap-string-internal-markup-list layout props #f arg)))
1566 (define-markup-command (justify-string layout props arg)
1569 #:properties ((baseline-skip)
1570 wordwrap-string-internal-markup-list)
1571 "Justify a string. Paragraphs may be separated with double newlines
1573 @lilypond[verbatim,quote]
1575 \\override #'(line-width . 40)
1576 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1577 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1578 et dolore magna aliqua.
1581 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1582 laboris nisi ut aliquip ex ea commodo consequat.
1585 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1586 qui officia deserunt mollit anim id est laborum\"
1589 (stack-lines DOWN 0.0 baseline-skip
1590 (wordwrap-string-internal-markup-list layout props #t arg)))
1592 (define-markup-command (wordwrap-field layout props symbol)
1595 "Wordwrap the data which has been assigned to @var{symbol}.
1597 @lilypond[verbatim,quote]
1599 title = \"My title\"
1600 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1601 elit, sed do eiusmod tempor incididunt ut labore et dolore
1602 magna aliqua. Ut enim ad minim veniam, quis nostrud
1603 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1608 bookTitleMarkup = \\markup {
1610 \\fill-line { \\fromproperty #'header:title }
1612 \\wordwrap-field #'header:myText
1621 (let* ((m (chain-assoc-get symbol props)))
1623 (wordwrap-string-markup layout props m)
1626 (define-markup-command (justify-field layout props symbol)
1629 "Justify the data which has been assigned to @var{symbol}.
1631 @lilypond[verbatim,quote]
1633 title = \"My title\"
1634 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1635 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1636 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1637 laboris nisi ut aliquip ex ea commodo consequat.\"
1641 bookTitleMarkup = \\markup {
1643 \\fill-line { \\fromproperty #'header:title }
1645 \\justify-field #'header:myText
1654 (let* ((m (chain-assoc-get symbol props)))
1656 (justify-string-markup layout props m)
1659 (define-markup-command (combine layout props arg1 arg2)
1663 @cindex merging text
1665 Print two markups on top of each other.
1667 Note: @code{\\combine} cannot take a list of markups enclosed in
1668 curly braces as an argument; the follow example will not compile:
1671 \\combine @{ a list @}
1674 @lilypond[verbatim,quote]
1677 \\override #'(thickness . 2)
1679 \\draw-line #'(0 . 4)
1680 \\arrow-head #Y #DOWN ##f
1683 (let* ((s1 (interpret-markup layout props arg1))
1684 (s2 (interpret-markup layout props arg2)))
1685 (ly:stencil-add s1 s2)))
1688 ;; TODO: should extract baseline-skip from each argument somehow..
1690 (define-markup-command (column layout props args)
1693 #:properties ((baseline-skip))
1695 @cindex stacking text in a column
1697 Stack the markups in @var{args} vertically. The property
1698 @code{baseline-skip} determines the space between markups
1701 @lilypond[verbatim,quote]
1710 (let ((arg-stencils (interpret-markup-list layout props args)))
1711 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1713 (define-markup-command (dir-column layout props args)
1716 #:properties ((direction)
1719 @cindex changing direction of text columns
1721 Make a column of @var{args}, going up or down, depending on the
1722 setting of the @code{direction} layout property.
1724 @lilypond[verbatim,quote]
1726 \\override #`(direction . ,UP) {
1736 \\override #'(direction . 1) {
1743 (stack-lines (if (number? direction) direction -1)
1746 (interpret-markup-list layout props args)))
1748 (define (general-column align-dir baseline mols)
1749 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1751 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1752 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1753 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1754 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1756 (define-markup-command (center-column layout props args)
1759 #:properties ((baseline-skip))
1761 @cindex centering a column of text
1763 Put @code{args} in a centered column.
1765 @lilypond[verbatim,quote]
1774 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1776 (define-markup-command (left-column layout props args)
1779 #:properties ((baseline-skip))
1781 @cindex text columns, left-aligned
1783 Put @code{args} in a left-aligned column.
1785 @lilypond[verbatim,quote]
1794 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1796 (define-markup-command (right-column layout props args)
1799 #:properties ((baseline-skip))
1801 @cindex text columns, right-aligned
1803 Put @code{args} in a right-aligned column.
1805 @lilypond[verbatim,quote]
1814 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1816 (define-markup-command (vcenter layout props arg)
1820 @cindex vertically centering text
1822 Align @code{arg} to its Y@tie{}center.
1824 @lilypond[verbatim,quote]
1832 (let* ((mol (interpret-markup layout props arg)))
1833 (ly:stencil-aligned-to mol Y CENTER)))
1835 (define-markup-command (center-align layout props arg)
1839 @cindex horizontally centering text
1841 Align @code{arg} to its X@tie{}center.
1843 @lilypond[verbatim,quote]
1853 (let* ((mol (interpret-markup layout props arg)))
1854 (ly:stencil-aligned-to mol X CENTER)))
1856 (define-markup-command (right-align layout props arg)
1860 @cindex right aligning text
1862 Align @var{arg} on its right edge.
1864 @lilypond[verbatim,quote]
1874 (let* ((m (interpret-markup layout props arg)))
1875 (ly:stencil-aligned-to m X RIGHT)))
1877 (define-markup-command (left-align layout props arg)
1881 @cindex left aligning text
1883 Align @var{arg} on its left edge.
1885 @lilypond[verbatim,quote]
1895 (let* ((m (interpret-markup layout props arg)))
1896 (ly:stencil-aligned-to m X LEFT)))
1898 (define-markup-command (general-align layout props axis dir arg)
1899 (integer? number? markup?)
1902 @cindex controlling general text alignment
1904 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1906 @lilypond[verbatim,quote]
1910 \\general-align #X #LEFT
1915 \\general-align #X #CENTER
1921 \\general-align #Y #UP
1928 \\general-align #Y #3.2
1935 (let* ((m (interpret-markup layout props arg)))
1936 (ly:stencil-aligned-to m axis dir)))
1938 (define-markup-command (halign layout props dir arg)
1942 @cindex setting horizontal text alignment
1944 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1945 left-aligned, while @code{+1} is right. Values in between interpolate
1946 alignment accordingly.
1948 @lilypond[verbatim,quote]
1973 (let* ((m (interpret-markup layout props arg)))
1974 (ly:stencil-aligned-to m X dir)))
1976 (define-markup-command (with-dimensions layout props x y arg)
1977 (number-pair? number-pair? markup?)
1980 @cindex setting extent of text objects
1982 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1983 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
1985 (make-transparent-box-stencil x y)
1987 `(delay-stencil-evaluation ,(delay expr))
1990 (define-markup-command (pad-around layout props amount arg)
1993 "Add padding @var{amount} all around @var{arg}.
1995 @lilypond[verbatim,quote]
2008 (let* ((m (interpret-markup layout props arg))
2009 (x (interval-widen (ly:stencil-extent m X) amount))
2010 (y (interval-widen (ly:stencil-extent m Y) amount)))
2011 (ly:stencil-add (make-transparent-box-stencil x y)
2014 (define-markup-command (pad-x layout props amount arg)
2018 @cindex padding text horizontally
2020 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2022 @lilypond[verbatim,quote]
2035 (let* ((m (interpret-markup layout props arg))
2036 (x (ly:stencil-extent m X))
2037 (y (ly:stencil-extent m Y)))
2038 (ly:make-stencil (ly:stencil-expr m)
2039 (interval-widen x amount)
2042 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2043 (integer? ly:dir? markup? markup?)
2045 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2046 (let ((m1 (interpret-markup layout props arg1))
2047 (m2 (interpret-markup layout props arg2)))
2048 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2050 (define-markup-command (transparent layout props arg)
2053 "Make @var{arg} transparent.
2055 @lilypond[verbatim,quote]
2062 (let* ((m (interpret-markup layout props arg))
2063 (x (ly:stencil-extent m X))
2064 (y (ly:stencil-extent m Y)))
2065 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2067 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2068 (number-pair? number-pair? markup?)
2070 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2072 @lilypond[verbatim,quote]
2079 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2085 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2086 (interpret-markup layout props arg)))
2088 (define-markup-command (hcenter-in layout props length arg)
2091 "Center @var{arg} horizontally within a box of extending
2092 @var{length}/2 to the left and right.
2094 @lilypond[quote,verbatim]
2097 \\set Staff.instrumentName = \\markup {
2104 \\set Staff.instrumentName = \\markup {
2113 (interpret-markup layout props
2114 (make-pad-to-box-markup
2115 (cons (/ length -2) (/ length 2))
2117 (make-center-align-markup arg))))
2119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2123 (define-markup-command (property-recursive layout props symbol)
2126 "Print out a warning when a header field markup contains some recursive
2128 (ly:warning "Recursive definition of property ~a detected!" symbol)
2131 (define-markup-command (fromproperty layout props symbol)
2134 "Read the @var{symbol} from property settings, and produce a stencil
2135 from the markup contained within. If @var{symbol} is not defined, it
2136 returns an empty markup.
2138 @lilypond[verbatim,quote]
2140 myTitle = \"myTitle\"
2144 \\fromproperty #'header:myTitle
2151 (let ((m (chain-assoc-get symbol props)))
2153 ;; prevent infinite loops by clearing the interpreted property:
2154 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2157 (define-markup-command (on-the-fly layout props procedure arg)
2158 (procedure? markup?)
2160 "Apply the @var{procedure} markup command to @var{arg}.
2161 @var{procedure} should take a single argument."
2162 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2163 (set-object-property! anonymous-with-signature
2166 (interpret-markup layout props (list anonymous-with-signature arg))))
2168 (define-markup-command (footnote layout props mkup note)
2171 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2173 @lilypond[verbatim,quote]
2176 \\override #'(padding . 0.2)
2180 The footnote will not be annotated automatically."
2181 (ly:stencil-combine-at-edge
2182 (interpret-markup layout props mkup)
2186 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2191 (define-markup-command (auto-footnote layout props mkup note)
2194 #:properties ((raise 0.5)
2196 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2198 @lilypond[verbatim,quote]
2201 \\override #'(padding . 0.2)
2205 The footnote will be annotated automatically."
2206 (let* ((markup-stencil (interpret-markup layout props mkup))
2207 (footnote-hash (gensym "footnote"))
2209 (gauge-stencil (interpret-markup
2212 ((ly:output-def-lookup
2214 'footnote-numbering-function)
2216 (x-ext (ly:stencil-extent gauge-stencil X))
2217 (y-ext (ly:stencil-extent gauge-stencil Y))
2219 `(delay-stencil-evaluation
2223 (ly:output-def-lookup layout
2224 'number-footnote-table))
2225 (footnote-stencil (if (list? table)
2226 (assoc-get footnote-hash
2229 (footnote-stencil (if (ly:stencil? footnote-stencil)
2232 (ly:programming-error
2233 "Cannot find correct footnote for a markup object.")
2235 (gap (- (interval-length x-ext)
2237 (ly:stencil-extent footnote-stencil X))))
2238 (y-trans (- (+ (cdr y-ext)
2240 (cdr (ly:stencil-extent footnote-stencil
2242 (ly:stencil-translate footnote-stencil
2243 (cons gap y-trans)))))))
2244 (main-stencil (ly:stencil-combine-at-edge
2248 (ly:make-stencil footnote-number x-ext y-ext)
2253 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2257 (define-markup-command (override layout props new-prop arg)
2261 @cindex overriding properties within text markup
2263 Add the argument @var{new-prop} to the property list. Properties
2264 may be any property supported by @rinternals{font-interface},
2265 @rinternals{text-interface} and
2266 @rinternals{instrument-specific-markup-interface}.
2268 @lilypond[verbatim,quote]
2276 \\override #'(baseline-skip . 4) {
2285 (interpret-markup layout (cons (list new-prop) props) arg))
2287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2291 (define-markup-command (verbatim-file layout props name)
2294 "Read the contents of file @var{name}, and include it verbatim.
2296 @lilypond[verbatim,quote]
2298 \\verbatim-file #\"simple.ly\"
2301 (interpret-markup layout props
2302 (if (ly:get-option 'safe)
2303 "verbatim-file disabled in safe mode"
2304 (let* ((str (ly:gulp-file name))
2305 (lines (string-split str #\nl)))
2306 (make-typewriter-markup
2307 (make-column-markup lines))))))
2309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2311 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2314 (define-markup-command (smaller layout props arg)
2317 "Decrease the font size relative to the current setting.
2319 @lilypond[verbatim,quote]
2332 (interpret-markup layout props
2333 `(,fontsize-markup -1 ,arg)))
2335 (define-markup-command (larger layout props arg)
2338 "Increase the font size relative to the current setting.
2340 @lilypond[verbatim,quote]
2348 (interpret-markup layout props
2349 `(,fontsize-markup 1 ,arg)))
2351 (define-markup-command (finger layout props arg)
2354 "Set @var{arg} as small numbers.
2356 @lilypond[verbatim,quote]
2363 (interpret-markup layout
2364 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2367 (define-markup-command (abs-fontsize layout props size arg)
2370 "Use @var{size} as the absolute font size to display @var{arg}.
2371 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2373 @lilypond[verbatim,quote]
2375 default text font size
2377 \\abs-fontsize #16 { text font size 16 }
2379 \\abs-fontsize #12 { text font size 12 }
2382 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2383 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2384 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2385 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2386 (magnification (/ size ref-size)))
2390 `((baseline-skip . ,(* magnification ref-baseline))
2391 (word-space . ,(* magnification ref-word-space))
2392 (font-size . ,(magnification->font-size magnification)))
2396 (define-markup-command (fontsize layout props increment arg)
2399 #:properties ((font-size 0)
2402 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2405 @lilypond[verbatim,quote]
2416 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2417 (word-space . ,(* word-space (magstep increment)))
2418 (font-size . ,(+ font-size increment)))
2422 (define-markup-command (magnify layout props sz arg)
2426 @cindex magnifying text
2428 Set the font magnification for its argument. In the following
2429 example, the middle@tie{}A is 10% larger:
2432 A \\magnify #1.1 @{ A @} A
2435 Note: Magnification only works if a font name is explicitly selected.
2436 Use @code{\\fontsize} otherwise.
2438 @lilypond[verbatim,quote]
2449 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2452 (define-markup-command (bold layout props arg)
2455 "Switch to bold font-series.
2457 @lilypond[verbatim,quote]
2465 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2467 (define-markup-command (sans layout props arg)
2470 "Switch to the sans serif font family.
2472 @lilypond[verbatim,quote]
2481 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2483 (define-markup-command (number layout props arg)
2486 "Set font family to @code{number}, which yields the font used for
2487 time signatures and fingerings. This font contains numbers and
2488 some punctuation; it has no letters.
2490 @lilypond[verbatim,quote]
2493 0 1 2 3 4 5 6 7 8 9 . ,
2497 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2499 (define-markup-command (roman layout props arg)
2502 "Set font family to @code{roman}.
2504 @lilypond[verbatim,quote]
2510 text in roman font family
2517 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2519 (define-markup-command (huge layout props arg)
2522 "Set font size to +2.
2524 @lilypond[verbatim,quote]
2532 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2534 (define-markup-command (large layout props arg)
2537 "Set font size to +1.
2539 @lilypond[verbatim,quote]
2547 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2549 (define-markup-command (normalsize layout props arg)
2552 "Set font size to default.
2554 @lilypond[verbatim,quote]
2567 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2569 (define-markup-command (small layout props arg)
2572 "Set font size to -1.
2574 @lilypond[verbatim,quote]
2582 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2584 (define-markup-command (tiny layout props arg)
2587 "Set font size to -2.
2589 @lilypond[verbatim,quote]
2597 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2599 (define-markup-command (teeny layout props arg)
2602 "Set font size to -3.
2604 @lilypond[verbatim,quote]
2612 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2614 (define-markup-command (fontCaps layout props arg)
2617 "Set @code{font-shape} to @code{caps}
2619 Note: @code{\\fontCaps} requires the installation and selection of
2620 fonts which support the @code{caps} font shape."
2621 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2624 (define-markup-command (smallCaps layout props arg)
2627 "Emit @var{arg} as small caps.
2629 Note: @code{\\smallCaps} does not support accented characters.
2631 @lilypond[verbatim,quote]
2640 (define (char-list->markup chars lower)
2641 (let ((final-string (string-upcase (reverse-list->string chars))))
2643 (markup #:fontsize -2 final-string)
2645 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2646 (if (null? rest-chars)
2648 (reverse! (cons (char-list->markup currents current-is-lower)
2650 (let* ((ch (car rest-chars))
2651 (is-lower (char-lower-case? ch)))
2652 (if (or (and current-is-lower is-lower)
2653 (and (not current-is-lower) (not is-lower)))
2654 (make-small-caps (cdr rest-chars)
2658 (make-small-caps (cdr rest-chars)
2661 (if (null? currents)
2663 (cons (char-list->markup
2664 currents current-is-lower)
2666 (interpret-markup layout props
2668 (make-small-caps (string->list arg) (list) #f (list))
2671 (define-markup-command (caps layout props arg)
2674 "Copy of the @code{\\smallCaps} command.
2676 @lilypond[verbatim,quote]
2685 (interpret-markup layout props (make-smallCaps-markup arg)))
2687 (define-markup-command (dynamic layout props arg)
2690 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2691 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2692 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2693 done in a different font. The recommended font for this is bold and italic.
2694 @lilypond[verbatim,quote]
2702 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2704 (define-markup-command (text layout props arg)
2707 "Use a text font instead of music symbol or music alphabet font.
2709 @lilypond[verbatim,quote]
2722 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2725 (define-markup-command (italic layout props arg)
2728 "Use italic @code{font-shape} for @var{arg}.
2730 @lilypond[verbatim,quote]
2738 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2740 (define-markup-command (typewriter layout props arg)
2743 "Use @code{font-family} typewriter for @var{arg}.
2745 @lilypond[verbatim,quote]
2754 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2756 (define-markup-command (upright layout props arg)
2759 "Set @code{font-shape} to @code{upright}. This is the opposite
2762 @lilypond[verbatim,quote]
2776 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2778 (define-markup-command (medium layout props arg)
2781 "Switch to medium font-series (in contrast to bold).
2783 @lilypond[verbatim,quote]
2796 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2799 (define-markup-command (normal-text layout props arg)
2802 "Set all font related properties (except the size) to get the default
2803 normal text font, no matter what font was used earlier.
2805 @lilypond[verbatim,quote]
2807 \\huge \\bold \\sans \\caps {
2819 (interpret-markup layout
2820 (cons '((font-family . roman) (font-shape . upright)
2821 (font-series . medium) (font-encoding . latin1))
2825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2829 (define-markup-command (musicglyph layout props glyph-name)
2832 "@var{glyph-name} is converted to a musical symbol; for example,
2833 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2834 the music font. See @ruser{The Feta font} for a complete listing of
2835 the possible glyphs.
2837 @lilypond[verbatim,quote]
2840 \\musicglyph #\"rests.2\"
2841 \\musicglyph #\"clefs.G_change\"
2844 (let* ((font (ly:paper-get-font layout
2845 (cons '((font-encoding . fetaMusic)
2849 (glyph (ly:font-get-glyph font glyph-name)))
2850 (if (null? (ly:stencil-expr glyph))
2851 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2855 (define-markup-command (doublesharp layout props)
2858 "Draw a double sharp symbol.
2860 @lilypond[verbatim,quote]
2865 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2867 (define-markup-command (sesquisharp layout props)
2870 "Draw a 3/2 sharp symbol.
2872 @lilypond[verbatim,quote]
2877 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2879 (define-markup-command (sharp layout props)
2882 "Draw a sharp symbol.
2884 @lilypond[verbatim,quote]
2889 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2891 (define-markup-command (semisharp layout props)
2894 "Draw a semisharp symbol.
2896 @lilypond[verbatim,quote]
2901 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2903 (define-markup-command (natural layout props)
2906 "Draw a natural symbol.
2908 @lilypond[verbatim,quote]
2913 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2915 (define-markup-command (semiflat layout props)
2918 "Draw a semiflat symbol.
2920 @lilypond[verbatim,quote]
2925 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2927 (define-markup-command (flat layout props)
2930 "Draw a flat symbol.
2932 @lilypond[verbatim,quote]
2937 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2939 (define-markup-command (sesquiflat layout props)
2942 "Draw a 3/2 flat symbol.
2944 @lilypond[verbatim,quote]
2949 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2951 (define-markup-command (doubleflat layout props)
2954 "Draw a double flat symbol.
2956 @lilypond[verbatim,quote]
2961 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2963 (define-markup-command (with-color layout props color arg)
2967 @cindex coloring text
2969 Draw @var{arg} in color specified by @var{color}.
2971 @lilypond[verbatim,quote]
2983 (let ((stil (interpret-markup layout props arg)))
2984 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2985 (ly:stencil-extent stil X)
2986 (ly:stencil-extent stil Y))))
2988 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2992 (define-markup-command (arrow-head layout props axis dir filled)
2993 (integer? ly:dir? boolean?)
2995 "Produce an arrow head in specified direction and axis.
2996 Use the filled head if @var{filled} is specified.
2997 @lilypond[verbatim,quote]
3000 \\general-align #Y #DOWN {
3001 \\arrow-head #Y #UP ##t
3002 \\arrow-head #Y #DOWN ##f
3004 \\arrow-head #X #RIGHT ##f
3005 \\arrow-head #X #LEFT ##f
3011 ((name (format #f "arrowheads.~a.~a~a"
3018 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3022 (define-markup-command (lookup layout props glyph-name)
3025 "Lookup a glyph by name.
3027 @lilypond[verbatim,quote]
3029 \\override #'(font-encoding . fetaBraces) {
3030 \\lookup #\"brace200\"
3033 \\lookup #\"brace180\"
3037 (ly:font-get-glyph (ly:paper-get-font layout props)
3040 (define-markup-command (char layout props num)
3043 "Produce a single character. Characters encoded in hexadecimal
3044 format require the prefix @code{#x}.
3046 @lilypond[verbatim,quote]
3048 \\char #65 \\char ##x00a9
3051 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3053 (define number->mark-letter-vector (make-vector 25 #\A))
3058 (if (= i (- (char->integer #\I) (char->integer #\A)))
3060 (vector-set! number->mark-letter-vector j
3061 (integer->char (+ i (char->integer #\A)))))
3063 (define number->mark-alphabet-vector (list->vector
3064 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3066 (define (number->markletter-string vec n)
3067 "Double letters for big marks."
3068 (let* ((lst (vector-length vec)))
3071 (string-append (number->markletter-string vec (1- (quotient n lst)))
3072 (number->markletter-string vec (remainder n lst)))
3073 (make-string 1 (vector-ref vec n)))))
3075 (define-markup-command (markletter layout props num)
3078 "Make a markup letter for @var{num}. The letters start with A
3079 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3081 @lilypond[verbatim,quote]
3088 (ly:text-interface::interpret-markup layout props
3089 (number->markletter-string number->mark-letter-vector num)))
3091 (define-markup-command (markalphabet layout props num)
3094 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3095 and continue with double letters.
3097 @lilypond[verbatim,quote]
3104 (ly:text-interface::interpret-markup layout props
3105 (number->markletter-string number->mark-alphabet-vector num)))
3107 (define-public (horizontal-slash-interval num forward number-interval mag)
3109 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3110 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3111 (else (interval-widen number-interval (* mag 0.25))))
3112 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3113 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3114 (else (interval-widen number-interval (* mag 0.25))))
3117 (define-public (adjust-slash-stencil num forward stencil mag)
3120 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3122 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3124 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3126 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3129 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3131 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3136 (define (slashed-digit-internal layout props num forward font-size thickness)
3137 (let* ((mag (magstep font-size))
3139 (ly:output-def-lookup layout 'line-thickness)
3141 ;; backward slashes might use slope and point in the other direction!
3142 (dy (* mag (if forward 0.4 -0.4)))
3143 (number-stencil (interpret-markup layout
3144 (prepend-alist-chain 'font-encoding 'fetaText props)
3145 (number->string num)))
3146 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3147 (center (interval-center (ly:stencil-extent number-stencil Y)))
3148 ;; Use the real extents of the slash, not the whole number,
3149 ;; because we might translate the slash later on!
3150 (num-y (interval-widen (cons center center) (abs dy)))
3151 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3152 (slash-stencil (if is-sane
3153 (make-line-stencil thickness
3154 (car num-x) (- (interval-center num-y) dy)
3155 (cdr num-x) (+ (interval-center num-y) dy))
3157 (if (ly:stencil? slash-stencil)
3159 ;; for some numbers we need to shift the slash/backslash up or
3160 ;; down to make the slashed digit look better
3161 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3162 (set! number-stencil
3163 (ly:stencil-add number-stencil slash-stencil)))
3164 (ly:warning "Unable to create slashed digit ~a" num))
3168 (define-markup-command (slashed-digit layout props num)
3171 #:properties ((font-size 0)
3174 @cindex slashed digits
3176 A feta number, with slash. This is for use in the context of
3177 figured bass notation.
3178 @lilypond[verbatim,quote]
3182 \\override #'(thickness . 3)
3186 (slashed-digit-internal layout props num #t font-size thickness))
3188 (define-markup-command (backslashed-digit layout props num)
3191 #:properties ((font-size 0)
3194 @cindex backslashed digits
3196 A feta number, with backslash. This is for use in the context of
3197 figured bass notation.
3198 @lilypond[verbatim,quote]
3200 \\backslashed-digit #5
3202 \\override #'(thickness . 3)
3203 \\backslashed-digit #7
3206 (slashed-digit-internal layout props num #f font-size thickness))
3209 (define eyeglassespath
3210 '((moveto 0.42 0.77)
3211 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3212 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3213 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3214 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3217 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3218 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3219 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3220 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3222 (moveto 1.025 0.935)
3223 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3224 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3227 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3230 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3232 (define-markup-command (eyeglasses layout props)
3235 "Prints out eyeglasses, indicating strongly to look at the conductor.
3236 @lilypond[verbatim,quote]
3237 \\markup { \\eyeglasses }
3239 (interpret-markup layout props
3240 (make-override-markup '(line-cap-style . butt)
3241 (make-path-markup 0.15 eyeglassespath))))
3243 (define-markup-command (left-brace layout props size)
3247 A feta brace in point size @var{size}.
3249 @lilypond[verbatim,quote]
3256 (let* ((font (ly:paper-get-font layout
3257 (cons '((font-encoding . fetaBraces)
3260 (glyph-count (1- (ly:otf-glyph-count font)))
3261 (scale (ly:output-def-lookup layout 'output-scale))
3262 (scaled-size (/ (ly:pt size) scale))
3264 (ly:font-get-glyph font (string-append "brace"
3265 (number->string n)))))
3266 (get-y-from-brace (lambda (brace)
3268 (ly:stencil-extent (glyph brace) Y))))
3269 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3270 (glyph-found (glyph find-brace)))
3272 (if (or (null? (ly:stencil-expr glyph-found))
3273 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3274 (> scaled-size (interval-length
3275 (ly:stencil-extent (glyph glyph-count) Y))))
3277 (ly:warning (_ "no brace found for point size ~S ") size)
3278 (ly:warning (_ "defaulting to ~S pt")
3279 (/ (* scale (interval-length
3280 (ly:stencil-extent glyph-found Y)))
3284 (define-markup-command (right-brace layout props size)
3288 A feta brace in point size @var{size}, rotated 180 degrees.
3290 @lilypond[verbatim,quote]
3297 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3300 ;; the note command.
3301 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3303 ;; TODO: better syntax.
3305 (define-markup-command (note-by-number layout props log dot-count dir)
3306 (number? number? number?)
3308 #:properties ((font-size 0)
3312 @cindex notes within text by log and dot-count
3314 Construct a note symbol, with stem and flag. By using fractional values for
3315 @var{dir}, longer or shorter stems can be obtained.
3316 Supports all note-head-styles.
3317 Supported flag-styles are @code{default}, @code{old-straight-flag},
3318 @code{modern-straight-flag} and @code{flat-flag}.
3320 @lilypond[verbatim,quote]
3322 \\note-by-number #3 #0 #DOWN
3324 \\note-by-number #1 #2 #0.8
3327 (define (get-glyph-name-candidates dir log style)
3328 (map (lambda (dir-name)
3329 (format #f "noteheads.~a~a" dir-name
3330 (if (and (symbol? style)
3331 (not (equal? 'default style)))
3332 (select-head-glyph style (min log 2))
3334 (list (if (= dir UP) "u" "d")
3337 (define (get-glyph-name font cands)
3340 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3341 (get-glyph-name font (cdr cands))
3344 (define (buildflags flag-stencil remain curr-stencil spacing)
3345 ;; Function to recursively create a stencil with @code{remain} flags
3346 ;; from the single-flag stencil @code{curr-stencil}, which is already
3347 ;; translated to the position of the previous flag position.
3349 ;; Copy and paste from /scm/flag-styles.scm
3351 (let* ((translated-stencil
3352 (ly:stencil-translate-axis curr-stencil spacing Y))
3353 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3354 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3357 (define (straight-flag-mrkp flag-thickness flag-spacing
3358 upflag-angle upflag-length
3359 downflag-angle downflag-length
3361 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3362 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3363 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3364 ;; @var{downflag-length} are given in staff spaces.
3366 ;; All lengths are scaled according to the font size of the note.
3368 ;; From /scm/flag-styles.scm, modified to fit here.
3370 (let* ((stem-up (> dir 0))
3371 ;; scale with the note size
3372 (factor (magstep font-size))
3373 (stem-thickness (* factor 0.1))
3374 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3375 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3376 (raw-length (if stem-up upflag-length downflag-length))
3377 (angle (if stem-up upflag-angle downflag-angle))
3378 (flag-length (+ (* raw-length factor) half-stem-thickness))
3379 (flag-end (if (= angle 0)
3380 (cons flag-length (* half-stem-thickness dir))
3381 (polar->rectangular flag-length angle)))
3382 (thickness (* flag-thickness factor))
3383 (thickness-offset (cons 0 (* -1 thickness dir)))
3384 (spacing (* -1 flag-spacing factor dir))
3385 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3386 ;; The points of a round-filled-polygon need to be given in
3387 ;; clockwise order, otherwise the polygon will be enlarged by
3392 (offset-add flag-end thickness-offset)
3393 (offset-add start thickness-offset))
3395 (offset-add start thickness-offset)
3396 (offset-add flag-end thickness-offset)
3398 (stencil (ly:round-filled-polygon points half-stem-thickness))
3399 ;; Log for 1/8 is 3, so we need to subtract 3
3400 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3403 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3405 (size-factor (magstep font-size))
3406 (blot (ly:output-def-lookup layout 'blot-diameter))
3408 (let ((result (get-glyph-name font
3409 (get-glyph-name-candidates
3410 (sign dir) log style))))
3411 (if (string-null? result)
3412 ;; If no glyph name can be found, select default heads.
3413 ;; Though this usually means an unsupported style has been
3414 ;; chosen, it also prevents unrelated 'style settings from
3415 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3417 (get-glyph-name font
3418 (get-glyph-name-candidates
3419 (sign dir) log 'default))
3421 (head-glyph (ly:font-get-glyph font head-glyph-name))
3422 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3423 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3424 (stem-length (* size-factor (max 3 (- log 1))))
3425 ;; With ancient-flags we want a tighter stem
3426 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3427 (stemy (* dir stem-length))
3428 (attach-off (cons (interval-index
3429 (ly:stencil-extent head-glyph X)
3430 (* (sign dir) (car attach-indices)))
3431 ;; fixme, this is inconsistent between X & Y.
3434 (ly:stencil-extent head-glyph Y)
3435 (cdr attach-indices)))))
3436 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3438 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3439 (stem-glyph (and (> log 0)
3440 (ly:round-filled-box
3441 (ordered-cons (+ stem-X-corr (car attach-off))
3442 (+ stem-X-corr (car attach-off)
3443 (* (- (sign dir)) stem-thickness)))
3444 (cons (min stemy (cdr attach-off))
3445 (max stemy (cdr attach-off)))
3446 (/ stem-thickness 3))))
3447 (dot (ly:font-get-glyph font "dots.dot"))
3448 (dotwid (interval-length (ly:stencil-extent dot X)))
3449 (dots (and (> dot-count 0)
3450 (apply ly:stencil-add
3452 (ly:stencil-translate-axis
3453 dot (* 2 x dotwid) X))
3454 (iota dot-count)))))
3455 ;; Straight-flags. Values taken from /scm/flag-style.scm
3456 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3457 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3458 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3459 ;; Calculate a corrective to avoid a gap between
3460 ;; straight-flags and the stem.
3461 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3462 (eq? flag-style 'old-straight-flag)
3463 (eq? flag-style 'flat-flag))
3464 (/ blot 10 (* -1 dir))
3466 (flaggl (and (> log 2)
3467 (ly:stencil-translate
3468 (cond ((eq? flag-style 'modern-straight-flag)
3469 modern-straight-flag)
3470 ((eq? flag-style 'old-straight-flag)
3472 ((eq? flag-style 'flat-flag)
3475 (ly:font-get-glyph font
3476 (format #f (if ancient-flags?
3477 "flags.mensural~a2~a"
3479 (if (> dir 0) "u" "d")
3481 (cons (+ (car attach-off)
3482 ;; For tighter stems (with ancient-flags) the
3483 ;; flag has to be adjusted different.
3484 (if (and (not ancient-flags?) (< dir 0))
3487 (+ stemy flag-style-Y-corr))))))
3489 ;; If there is a flag on an upstem and the stem is short, move the dots
3490 ;; to avoid the flag. 16th notes get a special case because their flags
3491 ;; hang lower than any other flags.
3492 ;; Not with ancient flags or straight-flags.
3493 (if (and dots (> dir 0) (> log 2)
3494 (or (eq? flag-style 'default) (null? flag-style))
3495 (not ancient-flags?)
3496 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3497 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3499 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3500 (if (ly:stencil? stem-glyph)
3501 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3502 (set! stem-glyph head-glyph))
3503 (if (ly:stencil? dots)
3506 (ly:stencil-translate-axis
3508 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3514 (let ((divisor (log 2)))
3515 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3517 (define (parse-simple-duration duration-string)
3518 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3519 and return a (log dots) list."
3520 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3522 (if (and match (string=? duration-string (match:substring match 0)))
3523 (let ((len (match:substring match 1))
3524 (dots (match:substring match 2)))
3525 (list (cond ((string=? len "breve") -1)
3526 ((string=? len "longa") -2)
3527 ((string=? len "maxima") -3)
3528 (else (log2 (string->number len))))
3529 (if dots (string-length dots) 0)))
3530 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3532 (define-markup-command (note layout props duration dir)
3535 #:properties (note-by-number-markup)
3537 @cindex notes within text by string
3539 This produces a note with a stem pointing in @var{dir} direction, with
3540 the @var{duration} for the note head type and augmentation dots. For
3541 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3542 a shortened down stem.
3544 @lilypond[verbatim,quote]
3546 \\override #'(style . cross) {
3550 \\note #\"breve\" #0
3553 (let ((parsed (parse-simple-duration duration)))
3554 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3557 ;; the rest command.
3558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3560 (define-markup-command (rest-by-number layout props log dot-count)
3563 #:properties ((font-size 0)
3565 (multi-measure-rest #f))
3567 @cindex rests or multi-measure-rests within text by log and dot-count
3569 A rest or multi-measure-rest symbol.
3571 @lilypond[verbatim,quote]
3573 \\rest-by-number #3 #2
3575 \\rest-by-number #0 #1
3577 \\override #'(multi-measure-rest . #t)
3578 \\rest-by-number #0 #0
3582 (define (get-glyph-name-candidates log style)
3583 (let* (;; Choose the style-string to be added.
3584 ;; If no glyph exists, select others for the specified styles
3585 ;; otherwise defaulting.
3588 ;; 'baroque needs to be special-cased, otherwise
3589 ;; `select-head-glyph´ would catch neomensural-glyphs for
3590 ;; this style, if (< log 0).
3591 (eq? style 'baroque)
3592 (string-append (number->string log) ""))
3593 ((eq? style 'petrucci)
3594 (string-append (number->string log) "mensural"))
3595 ;; In other cases `select-head-glyph´ from output-lib.scm
3596 ;; works for rest-glyphs, too.
3597 ((and (symbol? style) (not (eq? style 'default)))
3598 (select-head-glyph style log))
3600 ;; Choose ledgered glyphs for whole and half rest.
3601 ;; Except for the specified styles, logs and MultiMeasureRests.
3603 (if (and (or (list? style)
3605 '(neomensural mensural petrucci))))
3606 (not multi-measure-rest)
3607 (or (= log 0) (= log 1)))
3610 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3612 (define (get-glyph-name font cands)
3613 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3618 (ly:paper-get-font layout
3619 (cons '((font-encoding . fetaMusic)) props)))
3622 (get-glyph-name font
3623 (get-glyph-name-candidates log style))))
3624 (if (string-null? result)
3625 ;; If no glyph name can be found, select default rests. Though
3626 ;; this usually means an unsupported style has been chosen, it
3627 ;; also prevents unrelated 'style settings from other grobs
3628 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3629 (get-glyph-name font (get-glyph-name-candidates log 'default))
3631 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3632 (dot (ly:font-get-glyph font "dots.dot"))
3633 (dot-width (interval-length (ly:stencil-extent dot X)))
3634 (dots (and (> dot-count 0)
3635 (apply ly:stencil-add
3637 (ly:stencil-translate-axis
3638 dot (* 2 x dot-width) X))
3639 (iota dot-count))))))
3641 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3642 ;; glyphs are taken for whole and half rests.
3643 ;; If they are dotted, move the dots in X-direction to avoid collision.
3647 (not (member style '(neomensural mensural petrucci))))
3648 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3650 ;; Add dots to the rest-glyph.
3652 ;; Not sure how to vertical align dots.
3653 ;; For now the dots are centered for half, whole or longer rests.
3654 ;; Otherwise placed near the top of the rest.
3656 ;; Dots for rests with (< log 0) dots are allowed, but not
3657 ;; if multi-measure-rest is set #t.
3658 (if (and (not multi-measure-rest) dots)
3661 (ly:stencil-translate
3664 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3666 (interval-center (ly:stencil-extent rest-glyph Y))
3667 (- (interval-end (ly:stencil-extent rest-glyph Y))
3668 (/ (* 2 dot-width) 3)))))
3672 (define-markup-command (rest layout props duration)
3675 #:properties ((style '())
3676 (multi-measure-rest #f)
3677 (multi-measure-rest-number #t)
3680 @cindex rests or multi-measure-rests within text by string
3682 This produces a rest, with the @var{duration} for the rest type and
3684 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3687 Printing MultiMeasureRests could be enabled with
3688 @code{\\override #'(multi-measure-rest . #t)}
3689 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3690 This is enabled for all styles using default-glyphs.
3691 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3693 @lilypond[verbatim,quote]
3699 \\override #'(multi-measure-rest . #t)
3703 \\override #'(multi-measure-rest-number . #f)
3708 ;; Get the number of mmr-glyphs.
3709 ;; Store them in a list.
3710 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3711 (define (mmr-numbers nmbr)
3712 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3713 (8-remainder (remainder nmbr 8))
3714 (4-bar-glyph (floor (/ 8-remainder 4)))
3715 (4-remainder (remainder nmbr 4))
3716 (2-bar-glyph (floor (/ 4-remainder 2)))
3717 (2-remainder (remainder 4-remainder 2))
3718 (1-bar-glyph (floor (/ 2-remainder 1))))
3719 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3721 ;; Get the correct mmr-glyphs.
3722 ;; Store them in a list.
3724 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3725 ;; -> ("rests.M3" "rests.M1")
3726 (define (get-mmr-glyphs lst1 lst2)
3727 (define (helper l1 l2 l3)
3732 (append (make-list (car l1) (car l2)) l3))))
3733 (helper lst1 lst2 '()))
3735 ;; If duration is not valid, print a warning and return empty-stencil
3736 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3737 (not multi-measure-rest))
3738 (and (= (string-length (car (string-split duration #\. ))) 1)
3739 (= (string->number (car (string-split duration #\. ))) 0)))
3741 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3744 ;; For simple rests:
3745 ;; Get a (log dots) list.
3746 (parsed (parse-simple-duration duration))
3747 ;; Create the rest-stencil
3749 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3750 ;; For MultiMeasureRests:
3751 ;; Get the duration-part of duration
3752 (dur-part-string (car (string-split duration #\. )))
3753 ;; Get the duration of MMR:
3754 ;; If not a number (eg. "maxima") calculate it.
3756 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3757 ;; Get a list of the correct number of each mmr-glyph.
3758 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3759 ;; Create a list of mmr-stencils,
3760 ;; translating the glyph for a whole rest.
3764 (let ((single-mmr-stil
3765 (rest-by-number-markup layout props (* -1 x) 0)))
3767 (ly:stencil-translate-axis
3769 ;; Ugh, hard-coded, why 1?
3773 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3774 ;; Adjust the space between the mmr-glyphs,
3775 ;; if not default-glyphs are used.
3776 (word-space (if (member style
3777 '(neomensural mensural petrucci))
3778 (/ (* word-space 2) 3)
3780 ;; Create the final mmr-stencil
3781 ;; via `stack-stencil-line´ from /scm/markup.scm
3782 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3784 ;; Print the number above a multi-measure-rest
3785 ;; Depends on duration, style and multi-measure-rest-number set #t
3786 (if (and multi-measure-rest
3787 multi-measure-rest-number
3789 (not (member style '(neomensural mensural petrucci))))
3790 (let* ((mmr-stil-x-center
3791 (interval-center (ly:stencil-extent mmr-stil X)))
3795 #:override '(font-encoding . fetaText)
3796 (number->string mmr-duration)))
3798 (interpret-markup layout props duration-markup))
3799 (mmr-number-stil-x-center
3800 (interval-center (ly:stencil-extent mmr-number-stil X))))
3802 (set! mmr-stil (ly:stencil-combine-at-edge
3805 (ly:stencil-translate-axis
3807 (- mmr-stil-x-center mmr-number-stil-x-center)
3811 (if multi-measure-rest
3815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3817 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3819 (define-markup-command (fermata layout props) ()
3821 #:properties ((direction UP))
3822 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
3823 an inverted glyph. Note that within music, one would usually use the
3824 @code{\\fermata} articulation instead of a markup.
3826 @lilypond[verbatim,quote]
3827 { c1^\\markup \\fermata d1_\\markup \\fermata }
3829 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
3832 (interpret-markup layout props
3833 (if (eqv? direction DOWN)
3834 (markup #:musicglyph "scripts.dfermata")
3835 (markup #:musicglyph "scripts.ufermata"))))
3837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3841 (define-markup-command (lower layout props amount arg)
3845 @cindex lowering text
3847 Lower @var{arg} by the distance @var{amount}.
3848 A negative @var{amount} indicates raising; see also @code{\\raise}.
3850 @lilypond[verbatim,quote]
3858 (ly:stencil-translate-axis (interpret-markup layout props arg)
3861 (define-markup-command (translate-scaled layout props offset arg)
3862 (number-pair? markup?)
3864 #:properties ((font-size 0))
3866 @cindex translating text
3867 @cindex scaling text
3869 Translate @var{arg} by @var{offset}, scaling the offset by the
3872 @lilypond[verbatim,quote]
3875 * \\translate #'(2 . 3) translate
3877 * \\translate-scaled #'(2 . 3) translate-scaled
3881 (let* ((factor (magstep font-size))
3882 (scaled (cons (* factor (car offset))
3883 (* factor (cdr offset)))))
3884 (ly:stencil-translate (interpret-markup layout props arg)
3887 (define-markup-command (raise layout props amount arg)
3891 @cindex raising text
3893 Raise @var{arg} by the distance @var{amount}.
3894 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3896 The argument to @code{\\raise} is the vertical displacement amount,
3897 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3898 raise objects in relation to their surrounding markups.
3900 If the text object itself is positioned above or below the staff, then
3901 @code{\\raise} cannot be used to move it, since the mechanism that
3902 positions it next to the staff cancels any shift made with
3903 @code{\\raise}. For vertical positioning, use the @code{padding}
3904 and/or @code{extra-offset} properties.
3906 @lilypond[verbatim,quote]
3915 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3917 (define-markup-command (fraction layout props arg1 arg2)
3920 #:properties ((font-size 0))
3922 @cindex creating text fractions
3924 Make a fraction of two markups.
3925 @lilypond[verbatim,quote]
3931 (let* ((m1 (interpret-markup layout props arg1))
3932 (m2 (interpret-markup layout props arg2))
3933 (factor (magstep font-size))
3934 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3935 (padding (* factor 0.2))
3936 (baseline (* factor 0.6))
3937 (offset (* factor 0.75)))
3938 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3939 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3940 (let* ((x1 (ly:stencil-extent m1 X))
3941 (x2 (ly:stencil-extent m2 X))
3942 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3943 ;; should stack mols separately, to maintain LINE on baseline
3944 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3946 (ly:stencil-aligned-to stack Y CENTER))
3948 (ly:stencil-aligned-to stack X LEFT))
3949 ;; should have EX dimension
3951 (ly:stencil-translate-axis stack offset Y))))
3953 (define-markup-command (normal-size-super layout props arg)
3956 #:properties ((baseline-skip))
3958 @cindex setting superscript in standard font size
3960 Set @var{arg} in superscript with a normal font size.
3962 @lilypond[verbatim,quote]
3965 \\normal-size-super {
3966 superscript in standard size
3970 (ly:stencil-translate-axis
3971 (interpret-markup layout props arg)
3972 (* 0.5 baseline-skip) Y))
3974 (define-markup-command (super layout props arg)
3977 #:properties ((font-size 0)
3980 @cindex superscript text
3982 Set @var{arg} in superscript.
3984 @lilypond[verbatim,quote]
3994 (ly:stencil-translate-axis
3997 (cons `((font-size . ,(- font-size 3))) props)
3999 (* 0.5 baseline-skip)
4002 (define-markup-command (translate layout props offset arg)
4003 (number-pair? markup?)
4006 @cindex translating text
4008 Translate @var{arg} relative to its surroundings. @var{offset}
4009 is a pair of numbers representing the displacement in the X and Y axis.
4011 @lilypond[verbatim,quote]
4014 \\translate #'(2 . 3)
4015 \\line { translated two spaces right, three up }
4018 (ly:stencil-translate (interpret-markup layout props arg)
4021 (define-markup-command (sub layout props arg)
4024 #:properties ((font-size 0)
4027 @cindex subscript text
4029 Set @var{arg} in subscript.
4031 @lilypond[verbatim,quote]
4042 (ly:stencil-translate-axis
4045 (cons `((font-size . ,(- font-size 3))) props)
4047 (* -0.5 baseline-skip)
4050 (define-markup-command (normal-size-sub layout props arg)
4053 #:properties ((baseline-skip))
4055 @cindex setting subscript in standard font size
4057 Set @var{arg} in subscript with a normal font size.
4059 @lilypond[verbatim,quote]
4063 subscript in standard size
4067 (ly:stencil-translate-axis
4068 (interpret-markup layout props arg)
4069 (* -0.5 baseline-skip)
4072 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4074 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4076 (define-markup-command (hbracket layout props arg)
4080 @cindex placing horizontal brackets around text
4082 Draw horizontal brackets around @var{arg}.
4084 @lilypond[verbatim,quote]
4093 (let ((th 0.1) ;; todo: take from GROB.
4094 (m (interpret-markup layout props arg)))
4095 (bracketify-stencil m X th (* 2.5 th) th)))
4097 (define-markup-command (bracket layout props arg)
4101 @cindex placing vertical brackets around text
4103 Draw vertical brackets around @var{arg}.
4105 @lilypond[verbatim,quote]
4112 (let ((th 0.1) ;; todo: take from GROB.
4113 (m (interpret-markup layout props arg)))
4114 (bracketify-stencil m Y th (* 2.5 th) th)))
4116 (define-markup-command (parenthesize layout props arg)
4119 #:properties ((angularity 0)
4125 @cindex placing parentheses around text
4127 Draw parentheses around @var{arg}. This is useful for parenthesizing
4128 a column containing several lines of text.
4130 @lilypond[verbatim,quote]
4139 \\override #'(angularity . 2) {
4150 (let* ((markup (interpret-markup layout props arg))
4151 (scaled-width (* size width))
4153 (* (chain-assoc-get 'line-thickness props 0.1)
4156 (min (* size 0.5 scaled-thickness)
4157 (* (/ 4 3.0) scaled-width)))
4158 (padding (chain-assoc-get 'padding props half-thickness)))
4159 (parenthesize-stencil
4160 markup half-thickness scaled-width angularity padding)))
4163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4164 ;; Delayed markup evaluation
4165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4167 (define-markup-command (page-ref layout props label gauge default)
4168 (symbol? markup? markup?)
4171 @cindex referencing page numbers in text
4173 Reference to a page number. @var{label} is the label set on the referenced
4174 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4175 the maximum width of the page number, and @var{default} the value to display
4176 when @var{label} is not found."
4177 (let* ((gauge-stencil (interpret-markup layout props gauge))
4178 (x-ext (ly:stencil-extent gauge-stencil X))
4179 (y-ext (ly:stencil-extent gauge-stencil Y)))
4181 (make-transparent-box-stencil x-ext y-ext))
4183 `(delay-stencil-evaluation
4184 ,(delay (ly:stencil-expr
4185 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4186 (page-number (if (list? table)
4187 (assoc-get label table)
4189 (page-markup (if page-number (format #f "~a" page-number) default))
4190 (page-stencil (interpret-markup layout props page-markup))
4191 (gap (- (interval-length x-ext)
4192 (interval-length (ly:stencil-extent page-stencil X)))))
4193 (interpret-markup layout props
4194 (markup #:hspace gap page-markup))))))
4198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4202 (define-markup-command (scale layout props factor-pair arg)
4203 (number-pair? markup?)
4206 @cindex scaling markup
4207 @cindex mirroring markup
4209 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4210 representing the scaling-factor in the X and Y axes.
4211 Negative values may be used to produce mirror images.
4213 @lilypond[verbatim,quote]
4223 (let ((stil (interpret-markup layout props arg))
4224 (sx (car factor-pair))
4225 (sy (cdr factor-pair)))
4226 (ly:stencil-scale stil sx sy)))
4228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4232 (define-markup-command (pattern layout props count axis space pattern)
4233 (integer? integer? number? markup?)
4236 Prints @var{count} times a @var{pattern} markup.
4237 Patterns are spaced apart by @var{space}.
4238 Patterns are distributed on @var{axis}.
4240 @lilypond[verbatim, quote]
4242 \"Horizontally repeated :\"
4243 \\pattern #7 #X #2 \\flat
4245 \"Vertically repeated :\"
4246 \\pattern #3 #Y #0.5 \\flat
4249 (let ((pattern-width (interval-length
4250 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4251 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4252 (let loop ((i (1- count)) (patterns (markup)))
4258 (markup patterns pattern)
4259 (markup #:column (patterns pattern))))
4262 (markup patterns pattern #:hspace space)
4263 (markup #:column (patterns pattern #:vspace space))))))))
4265 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4266 (number? ly:dir? markup? markup? markup?)
4268 #:properties ((word-space)
4271 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4272 with a line of markups @var{pattern} in between.
4273 Patterns are spaced apart by @var{space}.
4274 Patterns are aligned to the @var{dir} markup.
4276 @lilypond[verbatim, quote]
4279 \\fill-with-pattern #1 #RIGHT . first right
4280 \\fill-with-pattern #1 #RIGHT . second right
4282 \"center-aligned :\"
4283 \\fill-with-pattern #1.5 #CENTER - left right
4286 \\override #'(line-width . 50)
4287 \\fill-with-pattern #2 #LEFT : left first
4288 \\override #'(line-width . 50)
4289 \\fill-with-pattern #2 #LEFT : left second
4292 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4293 (pattern-width (interval-length pattern-x-extent))
4294 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4295 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4296 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4297 (period (+ space pattern-width))
4298 (count (truncate (/ (- middle-width pattern-width) period)))
4299 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4300 (interpret-markup layout props
4302 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4303 #:translate (cons x-offset 0)
4304 #:pattern (1+ count) X space pattern
4307 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4311 (define-markup-command (replace layout props replacements arg)
4315 Used to automatically replace a string by another in the markup @var{arg}.
4316 Each pair of the alist @var{replacements} specifies what should be replaced.
4317 The @code{key} is the string to be replaced by the @code{value} string.
4319 @lilypond[verbatim, quote]
4320 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4324 (internal-add-text-replacements
4329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4330 ;; Markup list commands
4331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4333 (define-public (space-lines baseline stils)
4334 (let space-stil ((stils stils)
4338 (let* ((stil (car stils))
4339 (dy-top (max (- (/ baseline 1.5)
4340 (interval-bound (ly:stencil-extent stil Y) UP))
4342 (dy-bottom (max (+ (/ baseline 3.0)
4343 (interval-bound (ly:stencil-extent stil Y) DOWN))
4345 (new-stil (ly:make-stencil
4346 (ly:stencil-expr stil)
4347 (ly:stencil-extent stil X)
4348 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4350 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4352 (space-stil (cdr stils) (cons new-stil result))))))
4354 (define-markup-list-command (justified-lines layout props args)
4356 #:properties ((baseline-skip)
4357 wordwrap-internal-markup-list)
4359 @cindex justifying lines of text
4361 Like @code{\\justify}, but return a list of lines instead of a single markup.
4362 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4363 @var{X}@tie{}is the number of staff spaces."
4364 (space-lines baseline-skip
4365 (interpret-markup-list layout props
4366 (make-wordwrap-internal-markup-list #t args))))
4368 (define-markup-list-command (wordwrap-lines layout props args)
4370 #:properties ((baseline-skip)
4371 wordwrap-internal-markup-list)
4372 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4373 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4374 where @var{X} is the number of staff spaces."
4375 (space-lines baseline-skip
4376 (interpret-markup-list layout props
4377 (make-wordwrap-internal-markup-list #f args))))
4379 (define-markup-list-command (column-lines layout props args)
4381 #:properties ((baseline-skip))
4382 "Like @code{\\column}, but return a list of lines instead of a single markup.
4383 @code{baseline-skip} determines the space between each markup in @var{args}."
4384 (space-lines baseline-skip
4385 (interpret-markup-list layout props args)))
4387 (define-markup-list-command (override-lines layout props new-prop args)
4388 (pair? markup-list?)
4389 "Like @code{\\override}, for markup lists."
4390 (interpret-markup-list layout (cons (list new-prop) props) args))
4392 (define-markup-list-command (map-markup-commands layout props compose args)
4393 (procedure? markup-list?)
4394 "This applies the function @var{compose} to every markup in
4395 @var{args} (including elements of markup list command calls) in order
4396 to produce a new markup list. Since the return value from a markup
4397 list command call is not a markup list but rather a list of stencils,
4398 this requires passing those stencils off as the results of individual
4399 markup calls. That way, the results should work out as long as no
4400 markups rely on side effects."
4401 (let ((key (make-symbol "key")))
4405 ;; if `compose' does not actually interpret its markup
4406 ;; argument, we still need to return a list of stencils,
4407 ;; created from the single returned stencil
4409 (interpret-markup layout props
4411 (make-on-the-fly-markup
4412 (lambda (layout props m)
4413 ;; here all effects of `compose' on the
4414 ;; properties should be visible, so we
4415 ;; call interpret-markup-list at this
4416 ;; point of time and harvest its
4419 (interpret-markup-list
4420 layout props args)))
4421 (make-null-markup))))))
4422 (lambda (key stencils)
4425 (interpret-markup layout props
4426 (compose (make-stencil-markup sten))))