1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2014 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-list-command (score-lines layout props score)
1021 "This is the same as the @code{\\score} markup but delivers its
1022 systems as a list of lines. Its @var{score} argument is entered in
1023 braces like it would be for @code{\\score}."
1024 (let ((output (ly:score-embedded-format score layout)))
1026 (if (ly:music-output? output)
1028 (lambda (paper-system)
1029 ;; shift such that the refpoint of the bottom staff of
1030 ;; the first system is the baseline of the score
1031 (ly:stencil-translate-axis
1032 (paper-system-stencil paper-system)
1033 (- (car (paper-system-staff-extents paper-system)))
1035 (vector->list (ly:paper-score-paper-systems output)))
1037 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1040 (define-markup-command (score layout props score)
1043 #:properties ((baseline-skip))
1045 @cindex inserting music into text
1047 Inline an image of music. The reference point (usually the middle
1048 staff line) of the lowest staff in the top system is placed on the
1051 @lilypond[verbatim,quote]
1055 \\new Staff \\relative c' {
1058 \\mark \\markup { Allegro }
1064 \\new Staff \\relative c {
1070 f,( bes d bes d bes)
1078 \\override RehearsalMark
1079 #'break-align-symbols = #'(time-signature key-signature)
1080 \\override RehearsalMark
1081 #'self-alignment-X = #LEFT
1085 \\override TimeSignature
1086 #'break-align-anchor-alignment = #LEFT
1092 (stack-stencils Y DOWN baseline-skip
1093 (score-lines-markup-list layout props score)))
1095 (define-markup-command (null layout props)
1099 @cindex creating empty text objects
1101 An empty markup with extents of a single point.
1103 @lilypond[verbatim,quote]
1110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1111 ;; basic formatting.
1112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1114 (define-markup-command (simple layout props str)
1118 @cindex simple text strings
1120 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1121 @code{\\markup @{ \\simple #\"foo\" @}}.
1123 Note: for creating standard text markup or defining new markup commands,
1124 the use of @code{\\simple} is unnecessary.
1126 @lilypond[verbatim,quote]
1128 \\simple #\"simple\"
1130 \\simple #\"strings\"
1133 (interpret-markup layout props str))
1135 (define-markup-command (tied-lyric layout props str)
1138 #:properties ((word-space))
1140 @cindex simple text strings with tie characters
1142 Like simple-markup, but use tie characters for @q{~} tilde symbols.
1144 @lilypond[verbatim,quote]
1146 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
1147 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
1148 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
1151 (define (replace-ties tie str)
1152 (if (string-contains str "~")
1154 ((half-space (/ word-space 2))
1155 (parts (string-split str #\~))
1156 (tie-str (markup #:hspace half-space
1158 #:hspace half-space))
1159 (joined (list-join parts tie-str)))
1160 (make-concat-markup joined))
1163 (define short-tie-regexp (make-regexp "~[^.]~"))
1164 (define (match-short str) (regexp-exec short-tie-regexp str))
1166 (define (replace-short str mkp)
1167 (let ((match (match-short str)))
1169 (make-concat-markup (list
1171 (replace-ties "ties.lyric.default" str)))
1172 (let ((new-str (match:suffix match))
1173 (new-mkp (make-concat-markup (list
1175 (replace-ties "ties.lyric.default"
1176 (match:prefix match))
1177 (replace-ties "ties.lyric.short"
1178 (match:substring match))))))
1179 (replace-short new-str new-mkp)))))
1181 (interpret-markup layout
1183 (replace-short str (markup))))
1185 (define-public empty-markup
1186 (make-simple-markup ""))
1188 ;; helper for justifying lines.
1189 (define (get-fill-space
1190 word-count line-width word-space text-widths constant-space?)
1191 "Calculate the necessary paddings between adjacent texts in a
1192 single justified line. The lengths of all texts are stored in
1194 When @var{constant-space?} is @code{#t}, the formula for the padding
1196 padding = (line-width - total-text-width)/(word-count - 1)
1197 When @var{constant-space?} is @code{#f}, the formula for the
1198 padding between interior texts a and b is:
1199 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1200 In this case, the first and last padding have to be calculated
1201 specially using the whole length of the first or last text.
1202 All paddings are checked to be at least word-space, to ensure that
1204 Return a list of paddings."
1206 ((null? text-widths) '())
1210 ;; Ensure that space between words cannot be
1211 ;; less than word-space.
1214 (/ (- line-width (apply + text-widths))
1217 ;; special case first padding
1218 ((= (length text-widths) word-count)
1220 (- (- (/ line-width (1- word-count)) (car text-widths))
1221 (/ (cadr text-widths) 2))
1223 word-count line-width word-space (cdr text-widths)
1225 ;; special case last padding
1226 ((= (length text-widths) 2)
1227 (list (- (/ line-width (1- word-count))
1228 (+ (/ (car text-widths) 2) (cadr text-widths)))
1231 (let ((default-padding
1232 (- (/ line-width (1- word-count))
1233 (/ (+ (car text-widths) (cadr text-widths)) 2))))
1235 (if (> word-space default-padding)
1239 word-count line-width word-space (cdr text-widths)
1240 constant-space?))))))
1242 (define (justify-line-helper
1243 layout props args text-direction word-space line-width constant-space?)
1244 "Return a stencil which spreads @var{args} along a line of width
1245 @var{line-width}. If @var{constant-space?} is set to @code{#t}, the
1246 space between words is constant. If @code{#f}, the distance between
1247 words varies according to their relative lengths."
1248 (let* ((orig-stencils (interpret-markup-list layout props args))
1251 (if (ly:stencil-empty? stc X)
1252 (ly:make-stencil (ly:stencil-expr stc)
1253 '(0 . 0) (ly:stencil-extent stc Y))
1258 (if (ly:stencil-empty? stc)
1260 (interval-length (ly:stencil-extent stc X))))
1262 (text-width (apply + text-widths))
1263 (word-count (length stencils))
1264 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1269 (/ (- line-width text-width) 2)
1270 (/ (- line-width text-width) 2)))
1273 (- line-width text-width)))
1276 word-count line-width word-space text-widths
1278 (line-contents (if (= word-count 1)
1285 (if (null? (remove ly:stencil-empty? orig-stencils))
1288 (if (= text-direction LEFT)
1289 (set! line-contents (reverse line-contents)))
1291 (stack-stencils-padding-list
1292 X RIGHT fill-space line-contents))
1293 (if (> word-count 1)
1294 ;; shift s.t. stencils align on the left edge, even if
1295 ;; first stencil had negative X-extent (e.g. center-column)
1296 ;; (if word-count = 1, X-extents are already normalized in
1297 ;; the definition of line-contents)
1299 (ly:stencil-translate-axis
1301 (- (car (ly:stencil-extent (car stencils) X)))
1305 (define-markup-command (fill-line layout props args)
1308 #:properties ((text-direction RIGHT)
1311 "Put @var{markups} in a horizontal line of width @var{line-width}.
1312 The markups are spaced or flushed to fill the entire line.
1313 If there are no arguments, return an empty stencil.
1315 @lilypond[verbatim,quote]
1319 Words evenly spaced across the page
1323 \\line { Text markups }
1325 \\italic { evenly spaced }
1327 \\line { across the page }
1332 (justify-line-helper
1333 layout props args text-direction word-space line-width #f))
1335 (define-markup-command (justify-line layout props args)
1338 #:properties ((text-direction RIGHT)
1341 "Put @var{markups} in a horizontal line of width @var{line-width}.
1342 The markups are spread to fill the entire line and separated by equal
1343 space. If there are no arguments, return an empty stencil.
1345 @lilypond[verbatim,quote]
1348 Space between neighboring words is constant
1352 (justify-line-helper
1353 layout props args text-direction word-space line-width #t))
1355 (define-markup-command (line layout props args)
1358 #:properties ((word-space)
1359 (text-direction RIGHT))
1360 "Put @var{args} in a horizontal line. The property @code{word-space}
1361 determines the space between markups in @var{args}.
1363 @lilypond[verbatim,quote]
1370 (let ((stencils (interpret-markup-list layout props args)))
1371 (if (= text-direction LEFT)
1372 (set! stencils (reverse stencils)))
1373 (stack-stencil-line word-space stencils)))
1375 (define-markup-command (concat layout props args)
1379 @cindex concatenating text
1380 @cindex ligatures in text
1382 Concatenate @var{args} in a horizontal line, without spaces in between.
1383 Strings and simple markups are concatenated on the input level, allowing
1384 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1385 equivalent to @code{\"fi\"}.
1387 @lilypond[verbatim,quote]
1396 (define (concat-string-args arg-list)
1397 (fold-right (lambda (arg result-list)
1398 (let ((result (if (pair? result-list)
1401 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1402 (set! arg (cadr arg)))
1403 (if (and (string? result) (string? arg))
1404 (cons (string-append arg result) (cdr result-list))
1405 (cons arg result-list))))
1409 (interpret-markup layout
1410 (prepend-alist-chain 'word-space 0 props)
1412 (make-override-lines-markup-list
1414 (chain-assoc-get 'word-space props))
1415 (if (markup-command-list? args)
1417 (concat-string-args args))))))
1419 (define (wordwrap-stencils stencils
1420 justify base-space line-width text-dir)
1421 "Perform simple wordwrap, return stencil of each line."
1422 (define space (if justify
1423 ;; justify only stretches lines.
1426 (define (stencil-len s)
1427 (interval-end (ly:stencil-extent s X)))
1428 (define (maybe-shift line)
1429 (if (= text-dir LEFT)
1430 (ly:stencil-translate-axis
1432 (- line-width (stencil-len line))
1435 (if (null? stencils)
1437 (let loop ((lines '())
1440 ((line (first todo))
1442 (word-list (list (first todo))))
1445 (let ((new (if (= text-dir LEFT)
1446 (ly:stencil-stack (car todo) X RIGHT line space)
1447 (ly:stencil-stack line X RIGHT (car todo) space))))
1449 ((<= (stencil-len new) line-width)
1450 (word-loop new (cdr todo)
1451 (cons (car todo) word-list)))
1454 ;; This depends on stencil stacking being
1455 ;; associative so that stacking
1456 ;; left-to-right and right-to-left leads to
1458 (if (= text-dir LEFT)
1460 (reverse! word-list)))
1461 (len (stencil-len line))
1462 (stretch (- line-width len))
1465 (stack-stencils X RIGHT (1+ space) word-list))
1468 ;; Uh oh, nothing to fill.
1469 (loop (cons (maybe-shift line) lines) todo)
1471 (stack-stencils X RIGHT
1472 (+ space (/ stretch spaces))
1476 (else ;; not justify
1477 (loop (cons (maybe-shift line) lines) todo)))))
1480 ;; Now we have the last line assembled with space
1481 ;; which is compressed. We want to use the
1482 ;; uncompressed version instead if it fits, and the
1483 ;; justified version if it doesn't.
1485 ;; This depends on stencil stacking being
1486 ;; associative so that stacking
1487 ;; left-to-right and right-to-left leads to
1489 (if (= text-dir LEFT)
1491 (reverse! word-list)))
1492 (big-line (stack-stencils X RIGHT base-space word-list))
1493 (big-len (stencil-len big-line))
1494 (len (stencil-len line)))
1497 (if (> big-len line-width)
1498 (stack-stencils X RIGHT
1501 (* (- big-len line-width)
1503 (* (- line-width len)
1507 (maybe-shift big-line))))))
1508 (else ;; not justify
1509 (reverse! lines (list (maybe-shift line)))))))))
1512 (define-markup-list-command (wordwrap-internal layout props justify args)
1513 (boolean? markup-list?)
1514 #:properties ((line-width #f)
1516 (text-direction RIGHT))
1517 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1518 (wordwrap-stencils (interpret-markup-list layout props args)
1522 (ly:output-def-lookup layout 'line-width))
1525 (define-markup-command (justify layout props args)
1528 #:properties ((baseline-skip)
1529 wordwrap-internal-markup-list)
1531 @cindex justifying text
1533 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1534 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1535 @var{X}@tie{}is the number of staff spaces.
1537 @lilypond[verbatim,quote]
1540 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1541 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1542 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1543 laboris nisi ut aliquip ex ea commodo consequat.
1547 (stack-lines DOWN 0.0 baseline-skip
1548 (wordwrap-internal-markup-list layout props #t args)))
1550 (define-markup-command (wordwrap layout props args)
1553 #:properties ((baseline-skip)
1554 wordwrap-internal-markup-list)
1555 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1556 the line width, where @var{X} is the number of staff spaces.
1558 @lilypond[verbatim,quote]
1561 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1562 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1563 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1564 laboris nisi ut aliquip ex ea commodo consequat.
1568 (stack-lines DOWN 0.0 baseline-skip
1569 (wordwrap-internal-markup-list layout props #f args)))
1571 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1573 #:properties ((line-width)
1575 (text-direction RIGHT))
1576 "Internal markup list command used to define @code{\\justify-string} and
1577 @code{\\wordwrap-string}."
1578 (let* ((para-strings (regexp-split
1579 (string-regexp-substitute
1581 (string-regexp-substitute "\r\n" "\n" arg))
1582 "\n[ \t\n]*\n[ \t\n]*"))
1583 (list-para-words (map (lambda (str)
1584 (regexp-split str "[ \t\n]+"))
1586 (para-lines (map (lambda (words)
1589 (interpret-markup layout props x))
1591 (wordwrap-stencils stencils
1593 line-width text-direction)))
1595 (concatenate para-lines)))
1597 (define-markup-command (wordwrap-string layout props arg)
1600 #:properties ((baseline-skip)
1601 wordwrap-string-internal-markup-list)
1602 "Wordwrap a string. Paragraphs may be separated with double newlines.
1604 @lilypond[verbatim,quote]
1606 \\override #'(line-width . 40)
1607 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1608 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1609 et dolore magna aliqua.
1612 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1613 laboris nisi ut aliquip ex ea commodo consequat.
1616 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1617 qui officia deserunt mollit anim id est laborum\"
1620 (stack-lines DOWN 0.0 baseline-skip
1621 (wordwrap-string-internal-markup-list layout props #f arg)))
1623 (define-markup-command (justify-string layout props arg)
1626 #:properties ((baseline-skip)
1627 wordwrap-string-internal-markup-list)
1628 "Justify a string. Paragraphs may be separated with double newlines
1630 @lilypond[verbatim,quote]
1632 \\override #'(line-width . 40)
1633 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1634 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1635 et dolore magna aliqua.
1638 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1639 laboris nisi ut aliquip ex ea commodo consequat.
1642 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1643 qui officia deserunt mollit anim id est laborum\"
1646 (stack-lines DOWN 0.0 baseline-skip
1647 (wordwrap-string-internal-markup-list layout props #t arg)))
1649 (define-markup-command (wordwrap-field layout props symbol)
1652 "Wordwrap the data which has been assigned to @var{symbol}.
1654 @lilypond[verbatim,quote]
1656 title = \"My title\"
1657 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1658 elit, sed do eiusmod tempor incididunt ut labore et dolore
1659 magna aliqua. Ut enim ad minim veniam, quis nostrud
1660 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1665 bookTitleMarkup = \\markup {
1667 \\fill-line { \\fromproperty #'header:title }
1669 \\wordwrap-field #'header:myText
1678 (let* ((m (chain-assoc-get symbol props)))
1680 (wordwrap-string-markup layout props m)
1683 (define-markup-command (justify-field layout props symbol)
1686 "Justify the data which has been assigned to @var{symbol}.
1688 @lilypond[verbatim,quote]
1690 title = \"My title\"
1691 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1692 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1693 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1694 laboris nisi ut aliquip ex ea commodo consequat.\"
1698 bookTitleMarkup = \\markup {
1700 \\fill-line { \\fromproperty #'header:title }
1702 \\justify-field #'header:myText
1711 (let* ((m (chain-assoc-get symbol props)))
1713 (justify-string-markup layout props m)
1716 (define-markup-command (combine layout props arg1 arg2)
1720 @cindex merging text
1722 Print two markups on top of each other.
1724 Note: @code{\\combine} cannot take a list of markups enclosed in
1725 curly braces as an argument; the follow example will not compile:
1728 \\combine @{ a list @}
1731 @lilypond[verbatim,quote]
1734 \\override #'(thickness . 2)
1736 \\draw-line #'(0 . 4)
1737 \\arrow-head #Y #DOWN ##f
1740 (let* ((s1 (interpret-markup layout props arg1))
1741 (s2 (interpret-markup layout props arg2)))
1742 (ly:stencil-add s1 s2)))
1745 ;; TODO: should extract baseline-skip from each argument somehow..
1747 (define-markup-command (column layout props args)
1750 #:properties ((baseline-skip))
1752 @cindex stacking text in a column
1754 Stack the markups in @var{args} vertically. The property
1755 @code{baseline-skip} determines the space between markups
1758 @lilypond[verbatim,quote]
1767 (let ((arg-stencils (interpret-markup-list layout props args)))
1768 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1770 (define-markup-command (dir-column layout props args)
1773 #:properties ((direction)
1776 @cindex changing direction of text columns
1778 Make a column of @var{args}, going up or down, depending on the
1779 setting of the @code{direction} layout property.
1781 @lilypond[verbatim,quote]
1783 \\override #`(direction . ,UP) {
1793 \\override #'(direction . 1) {
1800 (stack-lines (if (number? direction) direction -1)
1803 (interpret-markup-list layout props args)))
1805 (define (general-column align-dir baseline mols)
1806 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1808 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1809 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1810 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1811 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1813 (define-markup-command (center-column layout props args)
1816 #:properties ((baseline-skip))
1818 @cindex centering a column of text
1820 Put @code{args} in a centered column.
1822 @lilypond[verbatim,quote]
1831 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1833 (define-markup-command (left-column layout props args)
1836 #:properties ((baseline-skip))
1838 @cindex text columns, left-aligned
1840 Put @code{args} in a left-aligned column.
1842 @lilypond[verbatim,quote]
1851 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1853 (define-markup-command (right-column layout props args)
1856 #:properties ((baseline-skip))
1858 @cindex text columns, right-aligned
1860 Put @code{args} in a right-aligned column.
1862 @lilypond[verbatim,quote]
1871 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1873 (define-markup-command (vcenter layout props arg)
1877 @cindex vertically centering text
1879 Align @code{arg} to its Y@tie{}center.
1881 @lilypond[verbatim,quote]
1889 (let* ((mol (interpret-markup layout props arg)))
1890 (ly:stencil-aligned-to mol Y CENTER)))
1892 (define-markup-command (center-align layout props arg)
1896 @cindex horizontally centering text
1898 Align @code{arg} to its X@tie{}center.
1900 @lilypond[verbatim,quote]
1910 (let* ((mol (interpret-markup layout props arg)))
1911 (ly:stencil-aligned-to mol X CENTER)))
1913 (define-markup-command (right-align layout props arg)
1917 @cindex right aligning text
1919 Align @var{arg} on its right edge.
1921 @lilypond[verbatim,quote]
1931 (let* ((m (interpret-markup layout props arg)))
1932 (ly:stencil-aligned-to m X RIGHT)))
1934 (define-markup-command (left-align layout props arg)
1938 @cindex left aligning text
1940 Align @var{arg} on its left edge.
1942 @lilypond[verbatim,quote]
1952 (let* ((m (interpret-markup layout props arg)))
1953 (ly:stencil-aligned-to m X LEFT)))
1955 (define-markup-command (general-align layout props axis dir arg)
1956 (integer? number? markup?)
1959 @cindex controlling general text alignment
1961 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1963 @lilypond[verbatim,quote]
1967 \\general-align #X #LEFT
1972 \\general-align #X #CENTER
1978 \\general-align #Y #UP
1985 \\general-align #Y #3.2
1992 (let* ((m (interpret-markup layout props arg)))
1993 (ly:stencil-aligned-to m axis dir)))
1995 (define-markup-command (halign layout props dir arg)
1999 @cindex setting horizontal text alignment
2001 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
2002 left-aligned, while @code{+1} is right. Values in between interpolate
2003 alignment accordingly.
2005 @lilypond[verbatim,quote]
2030 (let* ((m (interpret-markup layout props arg)))
2031 (ly:stencil-aligned-to m X dir)))
2033 (define-markup-command (with-dimensions layout props x y arg)
2034 (number-pair? number-pair? markup?)
2037 @cindex setting extent of text objects
2039 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2040 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2042 (make-transparent-box-stencil x y)
2044 `(delay-stencil-evaluation ,(delay expr))
2047 (define-markup-command (pad-around layout props amount arg)
2050 "Add padding @var{amount} all around @var{arg}.
2052 @lilypond[verbatim,quote]
2065 (let* ((m (interpret-markup layout props arg))
2066 (x (interval-widen (ly:stencil-extent m X) amount))
2067 (y (interval-widen (ly:stencil-extent m Y) amount)))
2068 (ly:stencil-add (make-transparent-box-stencil x y)
2071 (define-markup-command (pad-x layout props amount arg)
2075 @cindex padding text horizontally
2077 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2079 @lilypond[verbatim,quote]
2092 (let* ((m (interpret-markup layout props arg))
2093 (x (ly:stencil-extent m X))
2094 (y (ly:stencil-extent m Y)))
2095 (ly:make-stencil (ly:stencil-expr m)
2096 (interval-widen x amount)
2099 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2100 (integer? ly:dir? markup? markup?)
2102 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2103 (let ((m1 (interpret-markup layout props arg1))
2104 (m2 (interpret-markup layout props arg2)))
2105 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2107 (define-markup-command (transparent layout props arg)
2110 "Make @var{arg} transparent.
2112 @lilypond[verbatim,quote]
2119 (let* ((m (interpret-markup layout props arg))
2120 (x (ly:stencil-extent m X))
2121 (y (ly:stencil-extent m Y)))
2122 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2124 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2125 (number-pair? number-pair? markup?)
2127 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2129 @lilypond[verbatim,quote]
2136 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2142 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2143 (interpret-markup layout props arg)))
2145 (define-markup-command (hcenter-in layout props length arg)
2148 "Center @var{arg} horizontally within a box of extending
2149 @var{length}/2 to the left and right.
2151 @lilypond[quote,verbatim]
2154 \\set Staff.instrumentName = \\markup {
2161 \\set Staff.instrumentName = \\markup {
2170 (interpret-markup layout props
2171 (make-pad-to-box-markup
2172 (cons (/ length -2) (/ length 2))
2174 (make-center-align-markup arg))))
2176 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2180 (define-markup-command (property-recursive layout props symbol)
2183 "Print out a warning when a header field markup contains some recursive
2185 (ly:warning "Recursive definition of property ~a detected!" symbol)
2188 (define-markup-command (fromproperty layout props symbol)
2191 "Read the @var{symbol} from property settings, and produce a stencil
2192 from the markup contained within. If @var{symbol} is not defined, it
2193 returns an empty markup.
2195 @lilypond[verbatim,quote]
2197 myTitle = \"myTitle\"
2201 \\fromproperty #'header:myTitle
2208 (let ((m (chain-assoc-get symbol props)))
2210 ;; prevent infinite loops by clearing the interpreted property:
2211 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2214 (define-markup-command (on-the-fly layout props procedure arg)
2215 (procedure? markup?)
2217 "Apply the @var{procedure} markup command to @var{arg}.
2218 @var{procedure} should take a single argument."
2219 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2220 (set-object-property! anonymous-with-signature
2223 (interpret-markup layout props (list anonymous-with-signature arg))))
2225 (define-markup-command (footnote layout props mkup note)
2228 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2230 @lilypond[verbatim,quote]
2233 \\override #'(padding . 0.2)
2237 The footnote will not be annotated automatically."
2238 (ly:stencil-combine-at-edge
2239 (interpret-markup layout props mkup)
2243 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2248 (define-markup-command (auto-footnote layout props mkup note)
2251 #:properties ((raise 0.5)
2253 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2255 @lilypond[verbatim,quote]
2258 \\override #'(padding . 0.2)
2262 The footnote will be annotated automatically."
2263 (let* ((markup-stencil (interpret-markup layout props mkup))
2264 (footnote-hash (gensym "footnote"))
2266 (gauge-stencil (interpret-markup
2269 ((ly:output-def-lookup
2271 'footnote-numbering-function)
2273 (x-ext (ly:stencil-extent gauge-stencil X))
2274 (y-ext (ly:stencil-extent gauge-stencil Y))
2276 `(delay-stencil-evaluation
2280 (ly:output-def-lookup layout
2281 'number-footnote-table))
2282 (footnote-stencil (if (list? table)
2283 (assoc-get footnote-hash
2286 (footnote-stencil (if (ly:stencil? footnote-stencil)
2289 (ly:programming-error
2290 "Cannot find correct footnote for a markup object.")
2292 (gap (- (interval-length x-ext)
2294 (ly:stencil-extent footnote-stencil X))))
2295 (y-trans (- (+ (cdr y-ext)
2297 (cdr (ly:stencil-extent footnote-stencil
2299 (ly:stencil-translate footnote-stencil
2300 (cons gap y-trans)))))))
2301 (main-stencil (ly:stencil-combine-at-edge
2305 (ly:make-stencil footnote-number x-ext y-ext)
2310 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2314 (define-markup-command (override layout props new-prop arg)
2318 @cindex overriding properties within text markup
2320 Add the argument @var{new-prop} to the property list. Properties
2321 may be any property supported by @rinternals{font-interface},
2322 @rinternals{text-interface} and
2323 @rinternals{instrument-specific-markup-interface}.
2325 @lilypond[verbatim,quote]
2333 \\override #'(baseline-skip . 4) {
2342 (interpret-markup layout (cons (list new-prop) props) arg))
2344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2348 (define-markup-command (verbatim-file layout props name)
2351 "Read the contents of file @var{name}, and include it verbatim.
2353 @lilypond[verbatim,quote]
2355 \\verbatim-file #\"simple.ly\"
2358 (interpret-markup layout props
2359 (if (ly:get-option 'safe)
2360 "verbatim-file disabled in safe mode"
2361 (let* ((str (ly:gulp-file name))
2362 (lines (string-split str #\nl)))
2363 (make-typewriter-markup
2364 (make-column-markup lines))))))
2366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2371 (define-markup-command (smaller layout props arg)
2374 "Decrease the font size relative to the current setting.
2376 @lilypond[verbatim,quote]
2389 (interpret-markup layout props
2390 `(,fontsize-markup -1 ,arg)))
2392 (define-markup-command (larger layout props arg)
2395 "Increase the font size relative to the current setting.
2397 @lilypond[verbatim,quote]
2405 (interpret-markup layout props
2406 `(,fontsize-markup 1 ,arg)))
2408 (define-markup-command (finger layout props arg)
2411 "Set @var{arg} as small numbers.
2413 @lilypond[verbatim,quote]
2420 (interpret-markup layout
2421 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2424 (define-markup-command (abs-fontsize layout props size arg)
2427 "Use @var{size} as the absolute font size to display @var{arg}.
2428 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2430 @lilypond[verbatim,quote]
2432 default text font size
2434 \\abs-fontsize #16 { text font size 16 }
2436 \\abs-fontsize #12 { text font size 12 }
2439 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2440 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2441 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2442 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2443 (magnification (/ size ref-size)))
2447 `((baseline-skip . ,(* magnification ref-baseline))
2448 (word-space . ,(* magnification ref-word-space))
2449 (font-size . ,(magnification->font-size magnification)))
2453 (define-markup-command (fontsize layout props increment arg)
2456 #:properties ((font-size 0)
2459 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2462 @lilypond[verbatim,quote]
2473 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2474 (word-space . ,(* word-space (magstep increment)))
2475 (font-size . ,(+ font-size increment)))
2479 (define-markup-command (magnify layout props sz arg)
2483 @cindex magnifying text
2485 Set the font magnification for its argument. In the following
2486 example, the middle@tie{}A is 10% larger:
2489 A \\magnify #1.1 @{ A @} A
2492 Note: Magnification only works if a font name is explicitly selected.
2493 Use @code{\\fontsize} otherwise.
2495 @lilypond[verbatim,quote]
2506 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2509 (define-markup-command (bold layout props arg)
2512 "Switch to bold font-series.
2514 @lilypond[verbatim,quote]
2522 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2524 (define-markup-command (sans layout props arg)
2527 "Switch to the sans serif font family.
2529 @lilypond[verbatim,quote]
2538 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2540 (define-markup-command (number layout props arg)
2543 "Set font family to @code{number}, which yields the font used for
2544 time signatures and fingerings. This font contains numbers and
2545 some punctuation; it has no letters.
2547 @lilypond[verbatim,quote]
2550 0 1 2 3 4 5 6 7 8 9 . ,
2554 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2556 (define-markup-command (roman layout props arg)
2559 "Set font family to @code{roman}.
2561 @lilypond[verbatim,quote]
2567 text in roman font family
2574 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2576 (define-markup-command (huge layout props arg)
2579 "Set font size to +2.
2581 @lilypond[verbatim,quote]
2589 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2591 (define-markup-command (large layout props arg)
2594 "Set font size to +1.
2596 @lilypond[verbatim,quote]
2604 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2606 (define-markup-command (normalsize layout props arg)
2609 "Set font size to default.
2611 @lilypond[verbatim,quote]
2624 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2626 (define-markup-command (small layout props arg)
2629 "Set font size to -1.
2631 @lilypond[verbatim,quote]
2639 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2641 (define-markup-command (tiny layout props arg)
2644 "Set font size to -2.
2646 @lilypond[verbatim,quote]
2654 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2656 (define-markup-command (teeny layout props arg)
2659 "Set font size to -3.
2661 @lilypond[verbatim,quote]
2669 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2671 (define-markup-command (fontCaps layout props arg)
2674 "Set @code{font-shape} to @code{caps}
2676 Note: @code{\\fontCaps} requires the installation and selection of
2677 fonts which support the @code{caps} font shape."
2678 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2681 (define-markup-command (smallCaps layout props arg)
2684 "Emit @var{arg} as small caps.
2686 Note: @code{\\smallCaps} does not support accented characters.
2688 @lilypond[verbatim,quote]
2697 (define (char-list->markup chars lower)
2698 (let ((final-string (string-upcase (reverse-list->string chars))))
2700 (markup #:fontsize -2 final-string)
2702 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2703 (if (null? rest-chars)
2705 (reverse! (cons (char-list->markup currents current-is-lower)
2707 (let* ((ch (car rest-chars))
2708 (is-lower (char-lower-case? ch)))
2709 (if (or (and current-is-lower is-lower)
2710 (and (not current-is-lower) (not is-lower)))
2711 (make-small-caps (cdr rest-chars)
2715 (make-small-caps (cdr rest-chars)
2718 (if (null? currents)
2720 (cons (char-list->markup
2721 currents current-is-lower)
2723 (interpret-markup layout props
2725 (make-small-caps (string->list arg) (list) #f (list))
2728 (define-markup-command (caps layout props arg)
2731 "Copy of the @code{\\smallCaps} command.
2733 @lilypond[verbatim,quote]
2742 (interpret-markup layout props (make-smallCaps-markup arg)))
2744 (define-markup-command (dynamic layout props arg)
2747 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2748 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2749 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2750 done in a different font. The recommended font for this is bold and italic.
2751 @lilypond[verbatim,quote]
2759 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2761 (define-markup-command (text layout props arg)
2764 "Use a text font instead of music symbol or music alphabet font.
2766 @lilypond[verbatim,quote]
2779 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2782 (define-markup-command (italic layout props arg)
2785 "Use italic @code{font-shape} for @var{arg}.
2787 @lilypond[verbatim,quote]
2795 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2797 (define-markup-command (typewriter layout props arg)
2800 "Use @code{font-family} typewriter for @var{arg}.
2802 @lilypond[verbatim,quote]
2811 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2813 (define-markup-command (upright layout props arg)
2816 "Set @code{font-shape} to @code{upright}. This is the opposite
2819 @lilypond[verbatim,quote]
2833 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2835 (define-markup-command (medium layout props arg)
2838 "Switch to medium font-series (in contrast to bold).
2840 @lilypond[verbatim,quote]
2853 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2856 (define-markup-command (normal-text layout props arg)
2859 "Set all font related properties (except the size) to get the default
2860 normal text font, no matter what font was used earlier.
2862 @lilypond[verbatim,quote]
2864 \\huge \\bold \\sans \\caps {
2876 (interpret-markup layout
2877 (cons '((font-family . roman) (font-shape . upright)
2878 (font-series . medium) (font-encoding . latin1))
2882 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2886 (define-markup-command (musicglyph layout props glyph-name)
2889 "@var{glyph-name} is converted to a musical symbol; for example,
2890 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2891 the music font. See @ruser{The Feta font} for a complete listing of
2892 the possible glyphs.
2894 @lilypond[verbatim,quote]
2897 \\musicglyph #\"rests.2\"
2898 \\musicglyph #\"clefs.G_change\"
2901 (let* ((font (ly:paper-get-font layout
2902 (cons '((font-encoding . fetaMusic)
2906 (glyph (ly:font-get-glyph font glyph-name)))
2907 (if (null? (ly:stencil-expr glyph))
2908 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2912 (define-markup-command (doublesharp layout props)
2915 "Draw a double sharp symbol.
2917 @lilypond[verbatim,quote]
2922 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2924 (define-markup-command (sesquisharp layout props)
2927 "Draw a 3/2 sharp symbol.
2929 @lilypond[verbatim,quote]
2934 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2936 (define-markup-command (sharp layout props)
2939 "Draw a sharp symbol.
2941 @lilypond[verbatim,quote]
2946 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2948 (define-markup-command (semisharp layout props)
2951 "Draw a semisharp symbol.
2953 @lilypond[verbatim,quote]
2958 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2960 (define-markup-command (natural layout props)
2963 "Draw a natural symbol.
2965 @lilypond[verbatim,quote]
2970 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2972 (define-markup-command (semiflat layout props)
2975 "Draw a semiflat symbol.
2977 @lilypond[verbatim,quote]
2982 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2984 (define-markup-command (flat layout props)
2987 "Draw a flat symbol.
2989 @lilypond[verbatim,quote]
2994 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2996 (define-markup-command (sesquiflat layout props)
2999 "Draw a 3/2 flat symbol.
3001 @lilypond[verbatim,quote]
3006 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
3008 (define-markup-command (doubleflat layout props)
3011 "Draw a double flat symbol.
3013 @lilypond[verbatim,quote]
3018 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
3020 (define-markup-command (with-color layout props color arg)
3024 @cindex coloring text
3026 Draw @var{arg} in color specified by @var{color}.
3028 @lilypond[verbatim,quote]
3040 (let ((stil (interpret-markup layout props arg)))
3041 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3042 (ly:stencil-extent stil X)
3043 (ly:stencil-extent stil Y))))
3045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3047 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3049 (define-markup-command (arrow-head layout props axis dir filled)
3050 (integer? ly:dir? boolean?)
3052 "Produce an arrow head in specified direction and axis.
3053 Use the filled head if @var{filled} is specified.
3054 @lilypond[verbatim,quote]
3057 \\general-align #Y #DOWN {
3058 \\arrow-head #Y #UP ##t
3059 \\arrow-head #Y #DOWN ##f
3061 \\arrow-head #X #RIGHT ##f
3062 \\arrow-head #X #LEFT ##f
3068 ((name (format #f "arrowheads.~a.~a~a"
3075 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3079 (define-markup-command (lookup layout props glyph-name)
3082 "Lookup a glyph by name.
3084 @lilypond[verbatim,quote]
3086 \\override #'(font-encoding . fetaBraces) {
3087 \\lookup #\"brace200\"
3090 \\lookup #\"brace180\"
3094 (ly:font-get-glyph (ly:paper-get-font layout props)
3097 (define-markup-command (char layout props num)
3100 "Produce a single character. Characters encoded in hexadecimal
3101 format require the prefix @code{#x}.
3103 @lilypond[verbatim,quote]
3105 \\char #65 \\char ##x00a9
3108 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3110 (define number->mark-letter-vector (make-vector 25 #\A))
3115 (if (= i (- (char->integer #\I) (char->integer #\A)))
3117 (vector-set! number->mark-letter-vector j
3118 (integer->char (+ i (char->integer #\A)))))
3120 (define number->mark-alphabet-vector (list->vector
3121 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3123 (define (number->markletter-string vec n)
3124 "Double letters for big marks."
3125 (let* ((lst (vector-length vec)))
3128 (string-append (number->markletter-string vec (1- (quotient n lst)))
3129 (number->markletter-string vec (remainder n lst)))
3130 (make-string 1 (vector-ref vec n)))))
3132 (define-markup-command (markletter layout props num)
3135 "Make a markup letter for @var{num}. The letters start with A
3136 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3138 @lilypond[verbatim,quote]
3145 (ly:text-interface::interpret-markup layout props
3146 (number->markletter-string number->mark-letter-vector num)))
3148 (define-markup-command (markalphabet layout props num)
3151 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3152 and continue with double letters.
3154 @lilypond[verbatim,quote]
3161 (ly:text-interface::interpret-markup layout props
3162 (number->markletter-string number->mark-alphabet-vector num)))
3164 (define-public (horizontal-slash-interval num forward number-interval mag)
3166 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3167 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3168 (else (interval-widen number-interval (* mag 0.25))))
3169 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3170 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3171 (else (interval-widen number-interval (* mag 0.25))))
3174 (define-public (adjust-slash-stencil num forward stencil mag)
3177 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3179 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3181 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3183 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3186 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3188 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3193 (define (slashed-digit-internal layout props num forward font-size thickness)
3194 (let* ((mag (magstep font-size))
3196 (ly:output-def-lookup layout 'line-thickness)
3198 ;; backward slashes might use slope and point in the other direction!
3199 (dy (* mag (if forward 0.4 -0.4)))
3200 (number-stencil (interpret-markup layout
3201 (prepend-alist-chain 'font-encoding 'fetaText props)
3202 (number->string num)))
3203 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3204 (center (interval-center (ly:stencil-extent number-stencil Y)))
3205 ;; Use the real extents of the slash, not the whole number,
3206 ;; because we might translate the slash later on!
3207 (num-y (interval-widen (cons center center) (abs dy)))
3208 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3209 (slash-stencil (if is-sane
3210 (make-line-stencil thickness
3211 (car num-x) (- (interval-center num-y) dy)
3212 (cdr num-x) (+ (interval-center num-y) dy))
3214 (if (ly:stencil? slash-stencil)
3216 ;; for some numbers we need to shift the slash/backslash up or
3217 ;; down to make the slashed digit look better
3218 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3219 (set! number-stencil
3220 (ly:stencil-add number-stencil slash-stencil)))
3221 (ly:warning "Unable to create slashed digit ~a" num))
3225 (define-markup-command (slashed-digit layout props num)
3228 #:properties ((font-size 0)
3231 @cindex slashed digits
3233 A feta number, with slash. This is for use in the context of
3234 figured bass notation.
3235 @lilypond[verbatim,quote]
3239 \\override #'(thickness . 3)
3243 (slashed-digit-internal layout props num #t font-size thickness))
3245 (define-markup-command (backslashed-digit layout props num)
3248 #:properties ((font-size 0)
3251 @cindex backslashed digits
3253 A feta number, with backslash. This is for use in the context of
3254 figured bass notation.
3255 @lilypond[verbatim,quote]
3257 \\backslashed-digit #5
3259 \\override #'(thickness . 3)
3260 \\backslashed-digit #7
3263 (slashed-digit-internal layout props num #f font-size thickness))
3266 (define eyeglassespath
3267 '((moveto 0.42 0.77)
3268 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3269 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3270 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3271 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3274 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3275 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3276 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3277 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3279 (moveto 1.025 0.935)
3280 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3281 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3284 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3287 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3289 (define-markup-command (eyeglasses layout props)
3292 "Prints out eyeglasses, indicating strongly to look at the conductor.
3293 @lilypond[verbatim,quote]
3294 \\markup { \\eyeglasses }
3296 (interpret-markup layout props
3297 (make-override-markup '(line-cap-style . butt)
3298 (make-path-markup 0.15 eyeglassespath))))
3300 (define-markup-command (left-brace layout props size)
3304 A feta brace in point size @var{size}.
3306 @lilypond[verbatim,quote]
3313 (let* ((font (ly:paper-get-font layout
3314 (cons '((font-encoding . fetaBraces)
3317 (glyph-count (1- (ly:otf-glyph-count font)))
3318 (scale (ly:output-def-lookup layout 'output-scale))
3319 (scaled-size (/ (ly:pt size) scale))
3321 (ly:font-get-glyph font (string-append "brace"
3322 (number->string n)))))
3323 (get-y-from-brace (lambda (brace)
3325 (ly:stencil-extent (glyph brace) Y))))
3326 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3327 (glyph-found (glyph find-brace)))
3329 (if (or (null? (ly:stencil-expr glyph-found))
3330 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3331 (> scaled-size (interval-length
3332 (ly:stencil-extent (glyph glyph-count) Y))))
3334 (ly:warning (_ "no brace found for point size ~S ") size)
3335 (ly:warning (_ "defaulting to ~S pt")
3336 (/ (* scale (interval-length
3337 (ly:stencil-extent glyph-found Y)))
3341 (define-markup-command (right-brace layout props size)
3345 A feta brace in point size @var{size}, rotated 180 degrees.
3347 @lilypond[verbatim,quote]
3354 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3356 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3357 ;; the note command.
3358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3360 ;; TODO: better syntax.
3362 (define-markup-command (note-by-number layout props log dot-count dir)
3363 (number? number? number?)
3365 #:properties ((font-size 0)
3369 @cindex notes within text by log and dot-count
3371 Construct a note symbol, with stem and flag. By using fractional values for
3372 @var{dir}, longer or shorter stems can be obtained.
3373 Supports all note-head-styles.
3374 Supported flag-styles are @code{default}, @code{old-straight-flag},
3375 @code{modern-straight-flag} and @code{flat-flag}.
3377 @lilypond[verbatim,quote]
3379 \\note-by-number #3 #0 #DOWN
3381 \\note-by-number #1 #2 #0.8
3384 (define (get-glyph-name-candidates dir log style)
3385 (map (lambda (dir-name)
3386 (format #f "noteheads.~a~a" dir-name
3387 (if (and (symbol? style)
3388 (not (equal? 'default style)))
3389 (select-head-glyph style (min log 2))
3391 (list (if (= dir UP) "u" "d")
3394 (define (get-glyph-name font cands)
3397 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3398 (get-glyph-name font (cdr cands))
3401 (define (buildflags flag-stencil remain curr-stencil spacing)
3402 ;; Function to recursively create a stencil with @code{remain} flags
3403 ;; from the single-flag stencil @code{curr-stencil}, which is already
3404 ;; translated to the position of the previous flag position.
3406 ;; Copy and paste from /scm/flag-styles.scm
3408 (let* ((translated-stencil
3409 (ly:stencil-translate-axis curr-stencil spacing Y))
3410 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3411 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3414 (define (straight-flag-mrkp flag-thickness flag-spacing
3415 upflag-angle upflag-length
3416 downflag-angle downflag-length
3418 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3419 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3420 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3421 ;; @var{downflag-length} are given in staff spaces.
3423 ;; All lengths are scaled according to the font size of the note.
3425 ;; From /scm/flag-styles.scm, modified to fit here.
3427 (let* ((stem-up (> dir 0))
3428 ;; scale with the note size
3429 (factor (magstep font-size))
3430 (stem-thickness (* factor 0.1))
3431 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3432 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3433 (raw-length (if stem-up upflag-length downflag-length))
3434 (angle (if stem-up upflag-angle downflag-angle))
3435 (flag-length (+ (* raw-length factor) half-stem-thickness))
3436 (flag-end (if (= angle 0)
3437 (cons flag-length (* half-stem-thickness dir))
3438 (polar->rectangular flag-length angle)))
3439 (thickness (* flag-thickness factor))
3440 (thickness-offset (cons 0 (* -1 thickness dir)))
3441 (spacing (* -1 flag-spacing factor dir))
3442 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3443 ;; The points of a round-filled-polygon need to be given in
3444 ;; clockwise order, otherwise the polygon will be enlarged by
3449 (offset-add flag-end thickness-offset)
3450 (offset-add start thickness-offset))
3452 (offset-add start thickness-offset)
3453 (offset-add flag-end thickness-offset)
3455 (stencil (ly:round-filled-polygon points half-stem-thickness))
3456 ;; Log for 1/8 is 3, so we need to subtract 3
3457 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3460 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3462 (size-factor (magstep font-size))
3463 (blot (ly:output-def-lookup layout 'blot-diameter))
3465 (let ((result (get-glyph-name font
3466 (get-glyph-name-candidates
3467 (sign dir) log style))))
3468 (if (string-null? result)
3469 ;; If no glyph name can be found, select default heads.
3470 ;; Though this usually means an unsupported style has been
3471 ;; chosen, it also prevents unrelated 'style settings from
3472 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3474 (get-glyph-name font
3475 (get-glyph-name-candidates
3476 (sign dir) log 'default))
3478 (head-glyph (ly:font-get-glyph font head-glyph-name))
3479 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3480 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3481 (stem-length (* size-factor (max 3 (- log 1))))
3482 ;; With ancient-flags we want a tighter stem
3483 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3484 (stemy (* dir stem-length))
3485 (attach-off (cons (interval-index
3486 (ly:stencil-extent head-glyph X)
3487 (* (sign dir) (car attach-indices)))
3488 ;; fixme, this is inconsistent between X & Y.
3491 (ly:stencil-extent head-glyph Y)
3492 (cdr attach-indices)))))
3493 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3495 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3496 (stem-glyph (and (> log 0)
3497 (ly:round-filled-box
3498 (ordered-cons (+ stem-X-corr (car attach-off))
3499 (+ stem-X-corr (car attach-off)
3500 (* (- (sign dir)) stem-thickness)))
3501 (cons (min stemy (cdr attach-off))
3502 (max stemy (cdr attach-off)))
3503 (/ stem-thickness 3))))
3504 (dot (ly:font-get-glyph font "dots.dot"))
3505 (dotwid (interval-length (ly:stencil-extent dot X)))
3506 (dots (and (> dot-count 0)
3507 (apply ly:stencil-add
3509 (ly:stencil-translate-axis
3510 dot (* 2 x dotwid) X))
3511 (iota dot-count)))))
3512 ;; Straight-flags. Values taken from /scm/flag-style.scm
3513 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3514 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3515 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3516 ;; Calculate a corrective to avoid a gap between
3517 ;; straight-flags and the stem.
3518 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3519 (eq? flag-style 'old-straight-flag)
3520 (eq? flag-style 'flat-flag))
3521 (/ blot 10 (* -1 dir))
3523 (flaggl (and (> log 2)
3524 (ly:stencil-translate
3525 (cond ((eq? flag-style 'modern-straight-flag)
3526 modern-straight-flag)
3527 ((eq? flag-style 'old-straight-flag)
3529 ((eq? flag-style 'flat-flag)
3532 (ly:font-get-glyph font
3533 (format #f (if ancient-flags?
3534 "flags.mensural~a2~a"
3536 (if (> dir 0) "u" "d")
3538 (cons (+ (car attach-off)
3539 ;; For tighter stems (with ancient-flags) the
3540 ;; flag has to be adjusted different.
3541 (if (and (not ancient-flags?) (< dir 0))
3544 (+ stemy flag-style-Y-corr))))))
3546 ;; If there is a flag on an upstem and the stem is short, move the dots
3547 ;; to avoid the flag. 16th notes get a special case because their flags
3548 ;; hang lower than any other flags.
3549 ;; Not with ancient flags or straight-flags.
3550 (if (and dots (> dir 0) (> log 2)
3551 (or (eq? flag-style 'default) (null? flag-style))
3552 (not ancient-flags?)
3553 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3554 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3556 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3557 (if (ly:stencil? stem-glyph)
3558 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3559 (set! stem-glyph head-glyph))
3560 (if (ly:stencil? dots)
3563 (ly:stencil-translate-axis
3565 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3571 (let ((divisor (log 2)))
3572 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3574 (define (parse-simple-duration duration-string)
3575 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3576 and return a (log dots) list."
3577 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3579 (if (and match (string=? duration-string (match:substring match 0)))
3580 (let ((len (match:substring match 1))
3581 (dots (match:substring match 2)))
3582 (list (cond ((string=? len "breve") -1)
3583 ((string=? len "longa") -2)
3584 ((string=? len "maxima") -3)
3585 (else (log2 (string->number len))))
3586 (if dots (string-length dots) 0)))
3587 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3589 (define-markup-command (note layout props duration dir)
3592 #:properties (note-by-number-markup)
3594 @cindex notes within text by string
3596 This produces a note with a stem pointing in @var{dir} direction, with
3597 the @var{duration} for the note head type and augmentation dots. For
3598 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3599 a shortened down stem.
3601 @lilypond[verbatim,quote]
3603 \\override #'(style . cross) {
3607 \\note #\"breve\" #0
3610 (let ((parsed (parse-simple-duration duration)))
3611 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3613 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3614 ;; the rest command.
3615 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3617 (define-markup-command (rest-by-number layout props log dot-count)
3620 #:properties ((font-size 0)
3622 (multi-measure-rest #f))
3624 @cindex rests or multi-measure-rests within text by log and dot-count
3626 A rest or multi-measure-rest symbol.
3628 @lilypond[verbatim,quote]
3630 \\rest-by-number #3 #2
3632 \\rest-by-number #0 #1
3634 \\override #'(multi-measure-rest . #t)
3635 \\rest-by-number #0 #0
3639 (define (get-glyph-name-candidates log style)
3640 (let* (;; Choose the style-string to be added.
3641 ;; If no glyph exists, select others for the specified styles
3642 ;; otherwise defaulting.
3645 ;; 'baroque needs to be special-cased, otherwise
3646 ;; `select-head-glyph´ would catch neomensural-glyphs for
3647 ;; this style, if (< log 0).
3648 (eq? style 'baroque)
3649 (string-append (number->string log) ""))
3650 ((eq? style 'petrucci)
3651 (string-append (number->string log) "mensural"))
3652 ;; In other cases `select-head-glyph´ from output-lib.scm
3653 ;; works for rest-glyphs, too.
3654 ((and (symbol? style) (not (eq? style 'default)))
3655 (select-head-glyph style log))
3657 ;; Choose ledgered glyphs for whole and half rest.
3658 ;; Except for the specified styles, logs and MultiMeasureRests.
3660 (if (and (or (list? style)
3662 '(neomensural mensural petrucci))))
3663 (not multi-measure-rest)
3664 (or (= log 0) (= log 1)))
3667 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3669 (define (get-glyph-name font cands)
3670 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3675 (ly:paper-get-font layout
3676 (cons '((font-encoding . fetaMusic)) props)))
3679 (get-glyph-name font
3680 (get-glyph-name-candidates log style))))
3681 (if (string-null? result)
3682 ;; If no glyph name can be found, select default rests. Though
3683 ;; this usually means an unsupported style has been chosen, it
3684 ;; also prevents unrelated 'style settings from other grobs
3685 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3686 (get-glyph-name font (get-glyph-name-candidates log 'default))
3688 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3689 (dot (ly:font-get-glyph font "dots.dot"))
3690 (dot-width (interval-length (ly:stencil-extent dot X)))
3691 (dots (and (> dot-count 0)
3692 (apply ly:stencil-add
3694 (ly:stencil-translate-axis
3695 dot (* 2 x dot-width) X))
3696 (iota dot-count))))))
3698 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3699 ;; glyphs are taken for whole and half rests.
3700 ;; If they are dotted, move the dots in X-direction to avoid collision.
3704 (not (member style '(neomensural mensural petrucci))))
3705 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3707 ;; Add dots to the rest-glyph.
3709 ;; Not sure how to vertical align dots.
3710 ;; For now the dots are centered for half, whole or longer rests.
3711 ;; Otherwise placed near the top of the rest.
3713 ;; Dots for rests with (< log 0) dots are allowed, but not
3714 ;; if multi-measure-rest is set #t.
3715 (if (and (not multi-measure-rest) dots)
3718 (ly:stencil-translate
3721 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3723 (interval-center (ly:stencil-extent rest-glyph Y))
3724 (- (interval-end (ly:stencil-extent rest-glyph Y))
3725 (/ (* 2 dot-width) 3)))))
3729 (define-markup-command (rest layout props duration)
3732 #:properties ((style '())
3733 (multi-measure-rest #f)
3734 (multi-measure-rest-number #t)
3737 @cindex rests or multi-measure-rests within text by string
3739 This produces a rest, with the @var{duration} for the rest type and
3741 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3744 Printing MultiMeasureRests could be enabled with
3745 @code{\\override #'(multi-measure-rest . #t)}
3746 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3747 This is enabled for all styles using default-glyphs.
3748 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3750 @lilypond[verbatim,quote]
3756 \\override #'(multi-measure-rest . #t)
3760 \\override #'(multi-measure-rest-number . #f)
3765 ;; Get the number of mmr-glyphs.
3766 ;; Store them in a list.
3767 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3768 (define (mmr-numbers nmbr)
3769 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3770 (8-remainder (remainder nmbr 8))
3771 (4-bar-glyph (floor (/ 8-remainder 4)))
3772 (4-remainder (remainder nmbr 4))
3773 (2-bar-glyph (floor (/ 4-remainder 2)))
3774 (2-remainder (remainder 4-remainder 2))
3775 (1-bar-glyph (floor (/ 2-remainder 1))))
3776 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3778 ;; Get the correct mmr-glyphs.
3779 ;; Store them in a list.
3781 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3782 ;; -> ("rests.M3" "rests.M1")
3783 (define (get-mmr-glyphs lst1 lst2)
3784 (define (helper l1 l2 l3)
3789 (append (make-list (car l1) (car l2)) l3))))
3790 (helper lst1 lst2 '()))
3792 ;; If duration is not valid, print a warning and return empty-stencil
3793 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3794 (not multi-measure-rest))
3795 (and (= (string-length (car (string-split duration #\. ))) 1)
3796 (= (string->number (car (string-split duration #\. ))) 0)))
3798 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3801 ;; For simple rests:
3802 ;; Get a (log dots) list.
3803 (parsed (parse-simple-duration duration))
3804 ;; Create the rest-stencil
3806 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3807 ;; For MultiMeasureRests:
3808 ;; Get the duration-part of duration
3809 (dur-part-string (car (string-split duration #\. )))
3810 ;; Get the duration of MMR:
3811 ;; If not a number (eg. "maxima") calculate it.
3813 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3814 ;; Get a list of the correct number of each mmr-glyph.
3815 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3816 ;; Create a list of mmr-stencils,
3817 ;; translating the glyph for a whole rest.
3821 (let ((single-mmr-stil
3822 (rest-by-number-markup layout props (* -1 x) 0)))
3824 (ly:stencil-translate-axis
3826 ;; Ugh, hard-coded, why 1?
3830 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3831 ;; Adjust the space between the mmr-glyphs,
3832 ;; if not default-glyphs are used.
3833 (word-space (if (member style
3834 '(neomensural mensural petrucci))
3835 (/ (* word-space 2) 3)
3837 ;; Create the final mmr-stencil
3838 ;; via `stack-stencil-line´ from /scm/markup.scm
3839 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3841 ;; Print the number above a multi-measure-rest
3842 ;; Depends on duration, style and multi-measure-rest-number set #t
3843 (if (and multi-measure-rest
3844 multi-measure-rest-number
3846 (not (member style '(neomensural mensural petrucci))))
3847 (let* ((mmr-stil-x-center
3848 (interval-center (ly:stencil-extent mmr-stil X)))
3852 #:override '(font-encoding . fetaText)
3853 (number->string mmr-duration)))
3855 (interpret-markup layout props duration-markup))
3856 (mmr-number-stil-x-center
3857 (interval-center (ly:stencil-extent mmr-number-stil X))))
3859 (set! mmr-stil (ly:stencil-combine-at-edge
3862 (ly:stencil-translate-axis
3864 (- mmr-stil-x-center mmr-number-stil-x-center)
3868 (if multi-measure-rest
3872 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3874 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3876 (define-markup-command (fermata layout props) ()
3878 #:properties ((direction UP))
3879 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
3880 an inverted glyph. Note that within music, one would usually use the
3881 @code{\\fermata} articulation instead of a markup.
3883 @lilypond[verbatim,quote]
3884 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
3886 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
3889 (interpret-markup layout props
3890 (if (eqv? direction DOWN)
3891 (markup #:musicglyph "scripts.dfermata")
3892 (markup #:musicglyph "scripts.ufermata"))))
3894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3896 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3898 (define-markup-command (lower layout props amount arg)
3902 @cindex lowering text
3904 Lower @var{arg} by the distance @var{amount}.
3905 A negative @var{amount} indicates raising; see also @code{\\raise}.
3907 @lilypond[verbatim,quote]
3915 (ly:stencil-translate-axis (interpret-markup layout props arg)
3918 (define-markup-command (translate-scaled layout props offset arg)
3919 (number-pair? markup?)
3921 #:properties ((font-size 0))
3923 @cindex translating text
3924 @cindex scaling text
3926 Translate @var{arg} by @var{offset}, scaling the offset by the
3929 @lilypond[verbatim,quote]
3932 * \\translate #'(2 . 3) translate
3934 * \\translate-scaled #'(2 . 3) translate-scaled
3938 (let* ((factor (magstep font-size))
3939 (scaled (cons (* factor (car offset))
3940 (* factor (cdr offset)))))
3941 (ly:stencil-translate (interpret-markup layout props arg)
3944 (define-markup-command (raise layout props amount arg)
3948 @cindex raising text
3950 Raise @var{arg} by the distance @var{amount}.
3951 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3953 The argument to @code{\\raise} is the vertical displacement amount,
3954 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3955 raise objects in relation to their surrounding markups.
3957 If the text object itself is positioned above or below the staff, then
3958 @code{\\raise} cannot be used to move it, since the mechanism that
3959 positions it next to the staff cancels any shift made with
3960 @code{\\raise}. For vertical positioning, use the @code{padding}
3961 and/or @code{extra-offset} properties.
3963 @lilypond[verbatim,quote]
3972 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3974 (define-markup-command (fraction layout props arg1 arg2)
3977 #:properties ((font-size 0))
3979 @cindex creating text fractions
3981 Make a fraction of two markups.
3982 @lilypond[verbatim,quote]
3988 (let* ((m1 (interpret-markup layout props arg1))
3989 (m2 (interpret-markup layout props arg2))
3990 (factor (magstep font-size))
3991 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3992 (padding (* factor 0.2))
3993 (baseline (* factor 0.6))
3994 (offset (* factor 0.75)))
3995 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3996 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3997 (let* ((x1 (ly:stencil-extent m1 X))
3998 (x2 (ly:stencil-extent m2 X))
3999 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4000 ;; should stack mols separately, to maintain LINE on baseline
4001 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4003 (ly:stencil-aligned-to stack Y CENTER))
4005 (ly:stencil-aligned-to stack X LEFT))
4006 ;; should have EX dimension
4008 (ly:stencil-translate-axis stack offset Y))))
4010 (define-markup-command (normal-size-super layout props arg)
4013 #:properties ((font-size 0))
4015 @cindex setting superscript in standard font size
4017 Set @var{arg} in superscript with a normal font size.
4019 @lilypond[verbatim,quote]
4022 \\normal-size-super {
4023 superscript in standard size
4027 (ly:stencil-translate-axis
4028 (interpret-markup layout props arg)
4029 (* 1.0 (magstep font-size)) Y))
4031 (define-markup-command (super layout props arg)
4034 #:properties ((font-size 0))
4036 @cindex superscript text
4038 Set @var{arg} in superscript.
4040 @lilypond[verbatim,quote]
4050 (ly:stencil-translate-axis
4053 (cons `((font-size . ,(- font-size 3))) props)
4055 (* 1.0 (magstep font-size)) ; original font-size
4058 (define-markup-command (translate layout props offset arg)
4059 (number-pair? markup?)
4062 @cindex translating text
4064 Translate @var{arg} relative to its surroundings. @var{offset}
4065 is a pair of numbers representing the displacement in the X and Y axis.
4067 @lilypond[verbatim,quote]
4070 \\translate #'(2 . 3)
4071 \\line { translated two spaces right, three up }
4074 (ly:stencil-translate (interpret-markup layout props arg)
4077 (define-markup-command (sub layout props arg)
4080 #:properties ((font-size 0))
4082 @cindex subscript text
4084 Set @var{arg} in subscript.
4086 @lilypond[verbatim,quote]
4097 (ly:stencil-translate-axis
4100 (cons `((font-size . ,(- font-size 3))) props)
4102 (* -0.75 (magstep font-size)) ; original font-size
4105 (define-markup-command (normal-size-sub layout props arg)
4108 #:properties ((font-size 0))
4110 @cindex setting subscript in standard font size
4112 Set @var{arg} in subscript with a normal font size.
4114 @lilypond[verbatim,quote]
4118 subscript in standard size
4122 (ly:stencil-translate-axis
4123 (interpret-markup layout props arg)
4124 (* -0.75 (magstep font-size))
4127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4129 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4131 (define-markup-command (hbracket layout props arg)
4135 @cindex placing horizontal brackets around text
4137 Draw horizontal brackets around @var{arg}.
4139 @lilypond[verbatim,quote]
4148 (let ((th 0.1) ;; todo: take from GROB.
4149 (m (interpret-markup layout props arg)))
4150 (bracketify-stencil m X th (* 2.5 th) th)))
4152 (define-markup-command (bracket layout props arg)
4156 @cindex placing vertical brackets around text
4158 Draw vertical brackets around @var{arg}.
4160 @lilypond[verbatim,quote]
4167 (let ((th 0.1) ;; todo: take from GROB.
4168 (m (interpret-markup layout props arg)))
4169 (bracketify-stencil m Y th (* 2.5 th) th)))
4171 (define-markup-command (parenthesize layout props arg)
4174 #:properties ((angularity 0)
4180 @cindex placing parentheses around text
4182 Draw parentheses around @var{arg}. This is useful for parenthesizing
4183 a column containing several lines of text.
4185 @lilypond[verbatim,quote]
4194 \\override #'(angularity . 2) {
4205 (let* ((markup (interpret-markup layout props arg))
4206 (scaled-width (* size width))
4208 (* (chain-assoc-get 'line-thickness props 0.1)
4211 (min (* size 0.5 scaled-thickness)
4212 (* (/ 4 3.0) scaled-width)))
4213 (padding (chain-assoc-get 'padding props half-thickness)))
4214 (parenthesize-stencil
4215 markup half-thickness scaled-width angularity padding)))
4218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4219 ;; Delayed markup evaluation
4220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4222 (define-markup-command (page-ref layout props label gauge default)
4223 (symbol? markup? markup?)
4226 @cindex referencing page numbers in text
4228 Reference to a page number. @var{label} is the label set on the referenced
4229 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4230 the maximum width of the page number, and @var{default} the value to display
4231 when @var{label} is not found."
4232 (let* ((gauge-stencil (interpret-markup layout props gauge))
4233 (x-ext (ly:stencil-extent gauge-stencil X))
4234 (y-ext (ly:stencil-extent gauge-stencil Y)))
4236 (make-transparent-box-stencil x-ext y-ext))
4238 `(delay-stencil-evaluation
4239 ,(delay (ly:stencil-expr
4240 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4241 (page-number (if (list? table)
4242 (assoc-get label table)
4244 (page-markup (if page-number (format #f "~a" page-number) default))
4245 (page-stencil (interpret-markup layout props page-markup))
4246 (gap (- (interval-length x-ext)
4247 (interval-length (ly:stencil-extent page-stencil X)))))
4248 (interpret-markup layout props
4249 (markup #:hspace gap page-markup))))))
4253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4257 (define-markup-command (scale layout props factor-pair arg)
4258 (number-pair? markup?)
4261 @cindex scaling markup
4262 @cindex mirroring markup
4264 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4265 representing the scaling-factor in the X and Y axes.
4266 Negative values may be used to produce mirror images.
4268 @lilypond[verbatim,quote]
4278 (let ((stil (interpret-markup layout props arg))
4279 (sx (car factor-pair))
4280 (sy (cdr factor-pair)))
4281 (ly:stencil-scale stil sx sy)))
4283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4287 (define-markup-command (pattern layout props count axis space pattern)
4288 (integer? integer? number? markup?)
4291 Prints @var{count} times a @var{pattern} markup.
4292 Patterns are spaced apart by @var{space}.
4293 Patterns are distributed on @var{axis}.
4295 @lilypond[verbatim, quote]
4297 \"Horizontally repeated :\"
4298 \\pattern #7 #X #2 \\flat
4300 \"Vertically repeated :\"
4301 \\pattern #3 #Y #0.5 \\flat
4304 (let ((pattern-width (interval-length
4305 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4306 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4307 (let loop ((i (1- count)) (patterns (markup)))
4313 (markup patterns pattern)
4314 (markup #:column (patterns pattern))))
4317 (markup patterns pattern #:hspace space)
4318 (markup #:column (patterns pattern #:vspace space))))))))
4320 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4321 (number? ly:dir? markup? markup? markup?)
4323 #:properties ((word-space)
4326 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4327 with a line of markups @var{pattern} in between.
4328 Patterns are spaced apart by @var{space}.
4329 Patterns are aligned to the @var{dir} markup.
4331 @lilypond[verbatim, quote]
4334 \\fill-with-pattern #1 #RIGHT . first right
4335 \\fill-with-pattern #1 #RIGHT . second right
4337 \"center-aligned :\"
4338 \\fill-with-pattern #1.5 #CENTER - left right
4341 \\override #'(line-width . 50)
4342 \\fill-with-pattern #2 #LEFT : left first
4343 \\override #'(line-width . 50)
4344 \\fill-with-pattern #2 #LEFT : left second
4347 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4348 (pattern-width (interval-length pattern-x-extent))
4349 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4350 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4351 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4352 (period (+ space pattern-width))
4353 (count (truncate (/ (- middle-width pattern-width) period)))
4354 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4355 (interpret-markup layout props
4357 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4358 #:translate (cons x-offset 0)
4359 #:pattern (1+ count) X space pattern
4362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4364 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4366 (define-markup-command (replace layout props replacements arg)
4370 Used to automatically replace a string by another in the markup @var{arg}.
4371 Each pair of the alist @var{replacements} specifies what should be replaced.
4372 The @code{key} is the string to be replaced by the @code{value} string.
4374 @lilypond[verbatim, quote]
4375 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4379 (internal-add-text-replacements
4384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4385 ;; Markup list commands
4386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4388 (define-public (space-lines baseline stils)
4389 (let space-stil ((stils stils)
4393 (let* ((stil (car stils))
4394 (dy-top (max (- (/ baseline 1.5)
4395 (interval-bound (ly:stencil-extent stil Y) UP))
4397 (dy-bottom (max (+ (/ baseline 3.0)
4398 (interval-bound (ly:stencil-extent stil Y) DOWN))
4400 (new-stil (ly:make-stencil
4401 (ly:stencil-expr stil)
4402 (ly:stencil-extent stil X)
4403 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4405 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4407 (space-stil (cdr stils) (cons new-stil result))))))
4409 (define-markup-list-command (justified-lines layout props args)
4411 #:properties ((baseline-skip)
4412 wordwrap-internal-markup-list)
4414 @cindex justifying lines of text
4416 Like @code{\\justify}, but return a list of lines instead of a single markup.
4417 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4418 @var{X}@tie{}is the number of staff spaces."
4419 (space-lines baseline-skip
4420 (interpret-markup-list layout props
4421 (make-wordwrap-internal-markup-list #t args))))
4423 (define-markup-list-command (wordwrap-lines layout props args)
4425 #:properties ((baseline-skip)
4426 wordwrap-internal-markup-list)
4427 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4428 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4429 where @var{X} is the number of staff spaces."
4430 (space-lines baseline-skip
4431 (interpret-markup-list layout props
4432 (make-wordwrap-internal-markup-list #f args))))
4434 (define-markup-list-command (column-lines layout props args)
4436 #:properties ((baseline-skip))
4437 "Like @code{\\column}, but return a list of lines instead of a single markup.
4438 @code{baseline-skip} determines the space between each markup in @var{args}."
4439 (space-lines baseline-skip
4440 (interpret-markup-list layout props args)))
4442 (define-markup-list-command (override-lines layout props new-prop args)
4443 (pair? markup-list?)
4444 "Like @code{\\override}, for markup lists."
4445 (interpret-markup-list layout (cons (list new-prop) props) args))
4447 (define-markup-list-command (map-markup-commands layout props compose args)
4448 (procedure? markup-list?)
4449 "This applies the function @var{compose} to every markup in
4450 @var{args} (including elements of markup list command calls) in order
4451 to produce a new markup list. Since the return value from a markup
4452 list command call is not a markup list but rather a list of stencils,
4453 this requires passing those stencils off as the results of individual
4454 markup calls. That way, the results should work out as long as no
4455 markups rely on side effects."
4456 (let ((key (make-symbol "key")))
4460 ;; if `compose' does not actually interpret its markup
4461 ;; argument, we still need to return a list of stencils,
4462 ;; created from the single returned stencil
4464 (interpret-markup layout props
4466 (make-on-the-fly-markup
4467 (lambda (layout props m)
4468 ;; here all effects of `compose' on the
4469 ;; properties should be visible, so we
4470 ;; call interpret-markup-list at this
4471 ;; point of time and harvest its
4474 (interpret-markup-list
4475 layout props args)))
4476 (make-null-markup))))))
4477 (lambda (key stencils)
4480 (interpret-markup layout props
4481 (compose (make-stencil-markup sten))))