1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Markup commands and markup-list commands definitions.
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-markup-command' macro.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
42 ;;; `layout' is an output def, which properties can be accessed
43 ;;; using `ly:output-def-lookup'.
44 ;;; `props' is a list of property settings which can be accessed
45 ;;; using `chain-assoc-get' (more on that below)
48 ;;; the command arguments.
49 ;;; There is no limitation on the order of command arguments.
50 ;;; However, markup functions taking a markup as their last
51 ;;; argument are somewhat special as you can apply them to a
52 ;;; markup list, and the result is a markup list where the
53 ;;; markup function (with the specified leading arguments) has
54 ;;; been applied to every element of the original markup list.
56 ;;; Since replicating the leading arguments for applying a
57 ;;; markup function to a markup list is cheap mostly for
58 ;;; Scheme arguments, you avoid performance pitfalls by just
59 ;;; using Scheme arguments for the leading arguments of markup
60 ;;; functions that take a markup as their last argument.
63 ;;; the arguments signature, i.e., a list of type predicates which
64 ;;; are used to type check the arguments, and also to define the general
65 ;;; argument types (markup, markup-list, scheme) that the command is
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
71 ;;; for documentation purpose, builtin markup commands are grouped by
72 ;;; category. This can be any symbol. When documentation is generated,
73 ;;; the symbol is converted to a capitalized string, where hyphens are
74 ;;; replaced by spaces.
77 ;;; this is used both for documentation generation, and to ease
78 ;;; programming the command itself. It is list of
79 ;;; (property-name default-value)
80 ;;; or (property-name)
81 ;;; elements. Each property is looked-up in the `props' argument, and
82 ;;; the symbol naming the property is bound to its value.
83 ;;; When the property is not found in `props', then the symbol is bound
84 ;;; to the given default value. When no default value is given, #f is
86 ;;; Thus, using the following property bindings:
89 ;;; is equivalent to writing:
90 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;; (font-size (chain-assoc-get 'font-size props 0)))
93 ;;; When a command `B' internally calls an other command `A', it may
94 ;;; desirable to see in `B' documentation all the properties and
95 ;;; default values used by `A'. In that case, add `A-markup' to the
96 ;;; property-bindings of B. (This is used when generating
97 ;;; documentation, but won't create bindings.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '()
115 empty-interval empty-interval))
116 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;; line has to come early since it is often used implicitly from the
120 ;; markup macro since \markup { a b c } -> \markup \line { a b c }
121 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
123 (define-markup-command (line layout props args)
126 #:properties ((word-space)
127 (text-direction RIGHT))
128 "Put @var{args} in a horizontal line. The property @code{word-space}
129 determines the space between markups in @var{args}.
131 @lilypond[verbatim,quote]
138 (let ((stencils (interpret-markup-list layout props args)))
139 (if (= text-direction LEFT)
140 (set! stencils (reverse stencils)))
141 (stack-stencil-line word-space stencils)))
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 (define-markup-command (draw-line layout props dest)
150 #:properties ((thickness 1))
152 @cindex drawing lines within text
155 @lilypond[verbatim,quote]
157 \\draw-line #'(4 . 4)
158 \\override #'(thickness . 5)
159 \\draw-line #'(-3 . 0)
162 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
166 (make-line-stencil th 0 0 x y)))
168 (define-markup-command (draw-dashed-line layout props dest)
171 #:properties ((thickness 1)
177 @cindex drawing dashed lines within text
181 If @code{full-length} is set to #t (default) the dashed-line extends to the
182 whole length given by @var{dest}, without white space at beginning or end.
183 @code{off} will then be altered to fit.
184 To insist on the given (or default) values of @code{on}, @code{off} use
185 @code{\\override #'(full-length . #f)}
186 Manual settings for @code{on},@code{off} and @code{phase} are possible.
187 @lilypond[verbatim,quote]
189 \\draw-dashed-line #'(5.1 . 2.3)
190 \\override #'(on . 0.3)
191 \\override #'(off . 0.5)
192 \\draw-dashed-line #'(5.1 . 2.3)
195 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
196 ;; Calculate the thickness to be used.
197 (th (* line-thickness thickness))
198 (half-thick (/ th 2))
199 ;; Get the extensions in x- and y-direction.
202 ;; Calculate the length of the dashed line.
203 (line-length (sqrt (+ (expt x 2) (expt y 2)))))
205 (if (and full-length (not (= (+ on off) 0)))
207 ;; Add double-thickness to avoid overlapping.
208 (set! off (+ (* 2 th) off))
209 (let* (;; Make a guess how often the off/on-pair should be printed
210 ;; after the initial `onĀ“.
211 ;; Assume a minimum of 1 to avoid division by zero.
212 (guess (max 1 (round (/ (- line-length on) (+ off on)))))
213 ;; Not sure about the value or why corr is necessary at all,
214 ;; but it seems to be necessary.
216 (/ line-thickness 10)
218 ;; Calculate a new value for off to fit the
220 (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
224 ;; Settings for (= on 0). Resulting in a dotted line.
226 ;; If line-length isn't shorter than `thĀ“, change the given
227 ;; value for `offĀ“ to fit the line-length.
228 ((and (= on 0) (< th line-length))
231 ;; If the line-length is shorter than `thĀ“, it makes no
232 ;; sense to adjust `offĀ“. The rounded edges of the lines
233 ;; would prevent any nice output.
235 ;; This will result in a single dot for very short lines.
236 ((and (= on 0) (>= th line-length))
239 ;; Settings for (not (= on 0)). Resulting in a dashed line.
241 ;; If line-length isn't shorter than one go of on-off-on,
242 ;; change the given value for `offĀ“ to fit the line-length.
243 ((< (+ (* 2 on) off) line-length)
245 ;; If the line-length is too short, but greater than
246 ;; (* 4 th) set on/off to (/ line-length 3)
247 ((< (* 4 th) line-length)
248 (set! on (/ line-length 3))
249 (set! off (/ line-length 3)))
250 ;; If the line-length is shorter than (* 4 th), it makes
251 ;; no sense trying to adjust on/off. The rounded edges of
252 ;; the lines would prevent any nice output.
253 ;; Simply set `onĀ“ to line-length.
255 (set! on line-length))))))
257 ;; If `onĀ“ or `offĀ“ is negative, or the sum of `on' and `off' equals zero a
258 ;; ghostscript-error occurs while calling
259 ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
260 ;; Better be paranoid.
261 (if (or (= (+ on off) 0)
265 (ly:warning "Can't print a line - setting on/off to default")
269 ;; To give the lines produced by \draw-line and \draw-dashed-line the same
270 ;; length, half-thick has to be added to the stencil-extensions.
272 (list 'dashed-line th on off x y phase)
273 (interval-widen (ordered-cons 0 x) half-thick)
274 (interval-widen (ordered-cons 0 y) half-thick))))
276 (define-markup-command (draw-dotted-line layout props dest)
279 #:properties ((thickness 1)
283 @cindex drawing dotted lines within text
287 The dotted-line always extends to the whole length given by @var{dest}, without
288 white space at beginning or end.
289 Manual settings for @code{off} are possible to get larger or smaller space
291 The given (or default) value of @code{off} will be altered to fit the
293 @lilypond[verbatim,quote]
295 \\draw-dotted-line #'(5.1 . 2.3)
296 \\override #'(thickness . 2)
297 \\override #'(off . 0.2)
298 \\draw-dotted-line #'(5.1 . 2.3)
302 (let ((new-props (prepend-alist-chain 'on 0
303 (prepend-alist-chain 'full-length #t props))))
305 (interpret-markup layout
307 (markup #:draw-dashed-line dest))))
309 (define-markup-command (draw-hline layout props)
312 #:properties ((draw-line-markup)
316 @cindex drawing a line across a page
318 Draws a line across a page, where the property @code{span-factor}
319 controls what fraction of the page is taken up.
320 @lilypond[verbatim,quote]
324 \\override #'(span-factor . 1/3)
329 (interpret-markup layout
331 (markup #:draw-line (cons (* line-width
335 (define-markup-command (draw-circle layout props radius thickness filled)
336 (number? number? boolean?)
339 @cindex drawing circles within text
341 A circle of radius @var{radius} and thickness @var{thickness},
344 @lilypond[verbatim,quote]
346 \\draw-circle #2 #0.5 ##f
348 \\draw-circle #2 #0 ##t
351 (make-circle-stencil radius thickness filled))
353 (define-markup-command (triangle layout props filled)
356 #:properties ((thickness 0.1)
360 @cindex drawing triangles within text
362 A triangle, either filled or empty.
364 @lilypond[verbatim,quote]
371 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
380 (cons 0 (* .86 ex)))))
382 (define-markup-command (circle layout props arg)
385 #:properties ((thickness 1)
387 (circle-padding 0.2))
389 @cindex circling text
391 Draw a circle around @var{arg}. Use @code{thickness},
392 @code{circle-padding} and @code{font-size} properties to determine line
393 thickness and padding around the markup.
395 @lilypond[verbatim,quote]
402 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
404 (pad (* (magstep font-size) circle-padding))
405 (m (interpret-markup layout props arg)))
406 (circle-stencil m th pad)))
408 (define-markup-command (ellipse layout props arg)
411 #:properties ((thickness 1)
416 @cindex drawing ellipse around text
418 Draw an ellipse around @var{arg}. Use @code{thickness},
419 @code{x-padding}, @code{y-padding} and @code{font-size} properties to determine
420 line thickness and padding around the markup.
422 @lilypond[verbatim,quote]
429 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
431 (pad-x (* (magstep font-size) x-padding))
432 (pad-y (* (magstep font-size) y-padding))
433 (m (interpret-markup layout props arg)))
434 (ellipse-stencil m th pad-x pad-y)))
436 (define-markup-command (oval layout props arg)
439 #:properties ((thickness 1)
444 @cindex drawing oval around text
446 Draw an oval around @var{arg}. Use @code{thickness},
447 @code{x-padding}, @code{x-padding} and @code{font-size} properties to determine
448 line thickness and padding around the markup.
450 @lilypond[verbatim,quote]
457 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
459 (pad-x (* (magstep font-size) x-padding))
460 (pad-y (* (magstep font-size) y-padding))
461 (m (interpret-markup layout props arg)))
462 (oval-stencil m th pad-x pad-y)))
464 (define-markup-command (with-url layout props url arg)
468 @cindex inserting URL links into text
470 Add a link to URL @var{url} around @var{arg}. This only works in
473 @lilypond[verbatim,quote]
475 \\with-url #\"http://lilypond.org/\" {
476 LilyPond ... \\italic {
477 music notation for everyone
482 (let* ((stil (interpret-markup layout props arg))
483 (xextent (ly:stencil-extent stil X))
484 (yextent (ly:stencil-extent stil Y))
485 (old-expr (ly:stencil-expr stil))
486 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
488 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
490 (define-markup-command (page-link layout props page-number arg)
494 @cindex referencing page numbers in text
496 Add a link to the page @var{page-number} around @var{arg}. This only works
499 @lilypond[verbatim,quote]
501 \\page-link #2 { \\italic { This links to page 2... } }
504 (let* ((stil (interpret-markup layout props arg))
505 (xextent (ly:stencil-extent stil X))
506 (yextent (ly:stencil-extent stil Y))
507 (old-expr (ly:stencil-expr stil))
508 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
510 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
512 (define-markup-command (with-link layout props label arg)
516 @cindex referencing page labels in text
518 Add a link to the page holding label @var{label} around @var{arg}. This
519 only works in the PDF backend.
521 @lilypond[verbatim,quote]
523 \\with-link #'label {
524 \\italic { This links to the page containing the label... }
528 (let* ((arg-stencil (interpret-markup layout props arg))
529 (x-ext (ly:stencil-extent arg-stencil X))
530 (y-ext (ly:stencil-extent arg-stencil Y)))
533 `(delay-stencil-evaluation
534 ,(delay (let* ((table (ly:output-def-lookup layout 'label-page-table))
535 (page-number (if (list? table)
536 (assoc-get label table)
538 (list 'page-link page-number
539 `(quote ,x-ext) `(quote ,y-ext)))))
545 (define-markup-command (beam layout props width slope thickness)
546 (number? number? number?)
549 @cindex drawing beams within text
551 Create a beam with the specified parameters.
552 @lilypond[verbatim,quote]
557 (let* ((y (* slope width))
558 (yext (cons (min 0 y) (max 0 y)))
559 (half (/ thickness 2)))
564 width (+ (* width slope) (/ thickness -2))
565 width (+ (* width slope) (/ thickness 2))
567 ,(ly:output-def-lookup layout 'blot-diameter)
570 (cons (+ (- half) (car yext))
571 (+ half (cdr yext))))))
573 (define-markup-command (underline layout props arg)
576 #:properties ((thickness 1) (offset 2))
578 @cindex underlining text
580 Underline @var{arg}. Looks at @code{thickness} to determine line
581 thickness, and @code{offset} to determine line y-offset.
583 @lilypond[verbatim,quote]
584 \\markup \\fill-line {
585 \\underline \"underlined\"
586 \\override #'(offset . 5)
587 \\override #'(thickness . 1)
588 \\underline \"underlined\"
589 \\override #'(offset . 1)
590 \\override #'(thickness . 5)
591 \\underline \"underlined\"
594 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
595 (underline-thick (* thickness thick))
596 (m (interpret-markup layout props arg))
597 (x1 (car (ly:stencil-extent m X)))
598 (x2 (cdr (ly:stencil-extent m X)))
599 (y (* thick (- offset)))
600 (line (make-line-stencil underline-thick x1 y x2 y)))
601 (ly:stencil-add m line)))
603 (define-markup-command (box layout props arg)
606 #:properties ((thickness 1)
610 @cindex enclosing text within a box
612 Draw a box round @var{arg}. Looks at @code{thickness},
613 @code{box-padding} and @code{font-size} properties to determine line
614 thickness and padding around the markup.
616 @lilypond[verbatim,quote]
618 \\override #'(box-padding . 0.5)
623 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
625 (pad (* (magstep font-size) box-padding))
626 (m (interpret-markup layout props arg)))
627 (box-stencil m th pad)))
629 (define-markup-command (filled-box layout props xext yext blot)
630 (number-pair? number-pair? number?)
633 @cindex drawing solid boxes within text
634 @cindex drawing boxes with rounded corners
636 Draw a box with rounded corners of dimensions @var{xext} and
637 @var{yext}. For example,
639 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
641 creates a box extending horizontally from -0.3 to 1.8 and
642 vertically from -0.3 up to 1.8, with corners formed from a
643 circle of diameter@tie{}0 (i.e., sharp corners).
645 @lilypond[verbatim,quote]
647 \\filled-box #'(0 . 4) #'(0 . 4) #0
648 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
649 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
651 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
657 (define-markup-command (rounded-box layout props arg)
660 #:properties ((thickness 1)
664 "@cindex enclosing text in a box with rounded corners
665 @cindex drawing boxes with rounded corners around text
666 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
667 @code{box-padding} and @code{font-size} properties to determine line
668 thickness and padding around the markup; the @code{corner-radius} property
669 makes it possible to define another shape for the corners (default is 1).
671 @lilypond[quote,verbatim,relative=2]
679 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
681 (pad (* (magstep font-size) box-padding))
682 (m (interpret-markup layout props arg)))
683 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
686 (define-markup-command (rotate layout props ang arg)
690 @cindex rotating text
692 Rotate object with @var{ang} degrees around its center.
694 @lilypond[verbatim,quote]
704 (let* ((stil (interpret-markup layout props arg)))
705 (ly:stencil-rotate stil ang 0 0)))
707 (define-markup-command (whiteout layout props arg)
711 @cindex adding a white background to text
713 Provide a white background for @var{arg}.
715 @lilypond[verbatim,quote]
718 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
722 (stencil-whiteout (interpret-markup layout props arg)))
724 (define-markup-command (pad-markup layout props amount arg)
729 @cindex putting space around text
731 Add space around a markup object.
732 Identical to @code{pad-around}.
734 @lilypond[verbatim,quote]
747 (let* ((m (interpret-markup layout props arg))
748 (x (interval-widen (ly:stencil-extent m X) amount))
749 (y (interval-widen (ly:stencil-extent m Y) amount)))
750 (ly:stencil-add (make-transparent-box-stencil x y)
753 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
755 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
757 (define-markup-command (strut layout props)
761 @cindex creating vertical spaces in text
763 Create a box of the same height as the space in the current font."
764 (let ((m (ly:text-interface::interpret-markup layout props " ")))
765 (ly:make-stencil (ly:stencil-expr m)
767 (ly:stencil-extent m X)
770 (define-markup-command (hspace layout props amount)
774 @cindex creating horizontal spaces in text
776 Create an invisible object taking up horizontal space @var{amount}.
778 @lilypond[verbatim,quote]
787 (ly:make-stencil "" (cons 0 amount) empty-interval))
789 (define-markup-command (vspace layout props amount)
793 @cindex creating vertical spaces in text
795 Create an invisible object taking up vertical space
796 of @var{amount} multiplied by 3.
798 @lilypond[verbatim,quote]
809 (let ((amount (* amount 3.0)))
810 (ly:make-stencil "" empty-interval (cons 0 amount))))
813 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
814 ;; importing graphics.
815 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
817 (define-markup-command (stencil layout props stil)
821 @cindex importing stencils into text
823 Use a stencil as markup.
825 @lilypond[verbatim,quote]
827 \\stencil #(make-circle-stencil 2 0 #t)
833 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
835 (define (get-postscript-bbox string)
836 "Extract the bbox from STRING, or return #f if not present."
838 ((match (regexp-exec bbox-regexp string)))
842 (string->number (match:substring match x)))
847 (define-markup-command (epsfile layout props axis size file-name)
848 (number? number? string?)
851 @cindex inlining an Encapsulated PostScript image
853 Inline an EPS image. The image is scaled along @var{axis} to
856 @lilypond[verbatim,quote]
858 \\general-align #Y #DOWN {
859 \\epsfile #X #20 #\"context-example.eps\"
860 \\epsfile #Y #20 #\"context-example.eps\"
864 (if (ly:get-option 'safe)
865 (interpret-markup layout props "not allowed in safe")
866 (eps-file->stencil axis size file-name)
869 (define-markup-command (postscript layout props str)
873 @cindex inserting PostScript directly into text
874 This inserts @var{str} directly into the output as a PostScript
877 @lilypond[verbatim,quote]
881 0.4 0.6 0.5 0 361 arc
883 1.0 0.6 0.5 0 361 arc
888 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
889 \\postscript #ringsps
901 gsave currentpoint translate
909 (define-markup-command (path layout props thickness commands) (number? list?)
911 #:properties ((line-cap-style 'round)
912 (line-join-style 'round)
915 @cindex paths, drawing
916 @cindex drawing paths
917 Draws a path with line @var{thickness} according to the
918 directions given in @var{commands}. @var{commands} is a list of
919 lists where the @code{car} of each sublist is a drawing command and
920 the @code{cdr} comprises the associated arguments for each command.
922 There are seven commands available to use in the list
923 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
924 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
925 @code{closepath}. Note that the commands that begin with @emph{r}
926 are the relative variants of the other three commands.
928 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
929 @code{rlineto} take 2 arguments; they are the X and Y coordinates
930 for the destination point.
932 The commands @code{curveto} and @code{rcurveto} create cubic
933 BĆ©zier curves, and take 6 arguments; the first two are the X and Y
934 coordinates for the first control point, the second two are the X
935 and Y coordinates for the second control point, and the last two
936 are the X and Y coordinates for the destination point.
938 The @code{closepath} command takes zero arguments and closes the
939 current subpath in the active path.
941 Note that a sequence of commands @emph{must} begin with a
942 @code{moveto} or @code{rmoveto} to work with the SVG output.
944 Line-cap styles and line-join styles may be customized by
945 overriding the @code{line-cap-style} and @code{line-join-style}
946 properties, respectively. Available line-cap styles are
947 @code{'butt}, @code{'round}, and @code{'square}. Available
948 line-join styles are @code{'miter}, @code{'round}, and
951 The property @code{filled} specifies whether or not the path is
954 @lilypond[verbatim,quote]
960 (curveto -5 -5 -5 5 -1 0)
964 \\path #0.25 #samplePath
966 \\override #'(line-join-style . miter) \\path #0.25 #samplePath
968 \\override #'(filled . #t) \\path #0.25 #samplePath
971 (let* ((half-thickness (/ thickness 2))
972 (current-point '(0 . 0))
973 (set-point (lambda (lst) (set! current-point lst)))
974 (relative? (lambda (x)
975 (string-prefix? "r" (symbol->string (car x)))))
976 ;; For calculating extents, we want to modify the command
977 ;; list so that all coordinates are absolute.
978 (new-commands (map (lambda (x)
980 ;; for rmoveto, rlineto
981 ((and (relative? x) (= 3 (length x)))
983 (+ (car current-point)
985 (+ (cdr current-point)
991 ((and (relative? x) (= 7 (length x)))
992 (let* ((old-cp current-point)
999 (list (+ (car old-cp) (second x))
1000 (+ (cdr old-cp) (third x))
1001 (+ (car old-cp) (fourth x))
1002 (+ (cdr old-cp) (fifth x))
1005 ;; for moveto, lineto
1007 (set-point (cons (second x)
1012 (set-point (cons (sixth x)
1015 ;; keep closepath for filtering;
1016 ;; see `without-closepath'.
1019 ;; path-min-max does not accept 0-arg lists,
1020 ;; and since closepath does not affect extents, filter
1021 ;; out those commands here.
1022 (without-closepath (filter (lambda (x)
1023 (not (equal? 'closepath (car x))))
1025 (extents (path-min-max
1026 ;; set the origin to the first moveto
1027 (list (list-ref (car without-closepath) 0)
1028 (list-ref (car without-closepath) 1))
1030 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
1031 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
1032 (command-list (fold-right append '() commands)))
1034 ;; account for line thickness
1035 (set! X-extent (interval-widen X-extent half-thickness))
1036 (set! Y-extent (interval-widen Y-extent half-thickness))
1039 `(path ,thickness `(,@',command-list)
1040 ',line-cap-style ',line-join-style ,filled)
1044 (define-markup-list-command (score-lines layout props score)
1046 "This is the same as the @code{\\score} markup but delivers its
1047 systems as a list of lines. Its @var{score} argument is entered in
1048 braces like it would be for @code{\\score}."
1049 (let ((output (ly:score-embedded-format score layout)))
1051 (if (ly:music-output? output)
1053 (lambda (paper-system)
1054 ;; shift such that the refpoint of the bottom staff of
1055 ;; the first system is the baseline of the score
1056 (ly:stencil-translate-axis
1057 (paper-system-stencil paper-system)
1058 (- (car (paper-system-staff-extents paper-system)))
1060 (vector->list (ly:paper-score-paper-systems output)))
1062 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
1065 (define-markup-command (score layout props score)
1068 #:properties ((baseline-skip))
1070 @cindex inserting music into text
1072 Inline an image of music. The reference point (usually the middle
1073 staff line) of the lowest staff in the top system is placed on the
1076 @lilypond[verbatim,quote]
1080 \\new Staff \\relative c' {
1083 \\mark \\markup { Allegro }
1089 \\new Staff \\relative c {
1095 f,( bes d bes d bes)
1103 \\override RehearsalMark
1104 #'break-align-symbols = #'(time-signature key-signature)
1105 \\override RehearsalMark
1106 #'self-alignment-X = #LEFT
1110 \\override TimeSignature
1111 #'break-align-anchor-alignment = #LEFT
1117 (stack-stencils Y DOWN baseline-skip
1118 (score-lines-markup-list layout props score)))
1120 (define-markup-command (null layout props)
1124 @cindex creating empty text objects
1126 An empty markup with extents of a single point.
1128 @lilypond[verbatim,quote]
1135 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1136 ;; basic formatting.
1137 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1139 (define-markup-command (simple layout props str)
1143 @cindex simple text strings
1145 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1146 @code{\\markup @{ \\simple #\"foo\" @}}.
1148 Note: for creating standard text markup or defining new markup commands,
1149 the use of @code{\\simple} is unnecessary.
1151 @lilypond[verbatim,quote]
1153 \\simple #\"simple\"
1155 \\simple #\"strings\"
1158 (interpret-markup layout props str))
1160 (define-markup-command (first-visible layout props args)
1163 "Use the first markup in @var{args} that yields a non-empty stencil
1164 and ignore the rest.
1166 @lilypond[verbatim,quote]
1169 \\fromproperty #'header:composer
1174 (define (false-if-empty stencil)
1175 (if (ly:stencil-empty? stencil) #f stencil))
1180 (false-if-empty (interpret-markup layout props m))
1181 (any false-if-empty (interpret-markup-list layout props (list m)))))
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 (interval-length (ly:stencil-extent stc X)))
1260 (text-width (apply + text-widths))
1261 (word-count (length stencils))
1262 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1267 (/ (- line-width text-width) 2)
1268 (/ (- line-width text-width) 2)))
1271 (- line-width text-width)))
1274 word-count line-width word-space text-widths
1276 (line-contents (if (= word-count 1)
1283 (if (null? (remove ly:stencil-empty? orig-stencils))
1286 (if (= text-direction LEFT)
1287 (set! line-contents (reverse line-contents)))
1289 (stack-stencils-padding-list
1290 X RIGHT fill-space line-contents))
1291 (if (> word-count 1)
1292 ;; shift s.t. stencils align on the left edge, even if
1293 ;; first stencil had negative X-extent (e.g. center-column)
1294 ;; (if word-count = 1, X-extents are already normalized in
1295 ;; the definition of line-contents)
1297 (ly:stencil-translate-axis
1299 (- (car (ly:stencil-extent (car stencils) X)))
1303 (define-markup-command (fill-line layout props args)
1306 #:properties ((text-direction RIGHT)
1309 "Put @var{markups} in a horizontal line of width @var{line-width}.
1310 The markups are spaced or flushed to fill the entire line.
1311 If there are no arguments, return an empty stencil.
1313 @lilypond[verbatim,quote]
1317 Words evenly spaced across the page
1321 \\line { Text markups }
1323 \\italic { evenly spaced }
1325 \\line { across the page }
1330 (justify-line-helper
1331 layout props args text-direction word-space line-width #f))
1333 (define-markup-command (justify-line layout props args)
1336 #:properties ((text-direction RIGHT)
1339 "Put @var{markups} in a horizontal line of width @var{line-width}.
1340 The markups are spread to fill the entire line and separated by equal
1341 space. If there are no arguments, return an empty stencil.
1343 @lilypond[verbatim,quote]
1346 Space between neighboring words is constant
1350 (justify-line-helper
1351 layout props args text-direction word-space line-width #t))
1353 (define-markup-command (concat layout props args)
1357 @cindex concatenating text
1358 @cindex ligatures in text
1360 Concatenate @var{args} in a horizontal line, without spaces in between.
1361 Strings and simple markups are concatenated on the input level, allowing
1362 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1363 equivalent to @code{\"fi\"}.
1365 @lilypond[verbatim,quote]
1374 (define (concat-string-args arg-list)
1375 (fold-right (lambda (arg result-list)
1376 (let ((result (if (pair? result-list)
1379 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1380 (set! arg (cadr arg)))
1381 (if (and (string? result) (string? arg))
1382 (cons (string-append arg result) (cdr result-list))
1383 (cons arg result-list))))
1387 (interpret-markup layout
1388 (prepend-alist-chain 'word-space 0 props)
1390 (make-override-lines-markup-list
1392 (chain-assoc-get 'word-space props))
1393 (if (markup-command-list? args)
1395 (concat-string-args args))))))
1397 (define (wordwrap-stencils stencils
1398 justify base-space line-width text-dir)
1399 "Perform simple wordwrap, return stencil of each line."
1400 (define space (if justify
1401 ;; justify only stretches lines.
1404 (define (stencil-len s)
1405 (interval-end (ly:stencil-extent s X)))
1406 (define (maybe-shift line)
1407 (if (= text-dir LEFT)
1408 (ly:stencil-translate-axis
1410 (- line-width (stencil-len line))
1413 (if (null? stencils)
1415 (let loop ((lines '())
1418 ((line (first todo))
1420 (word-list (list (first todo))))
1423 (let ((new (if (= text-dir LEFT)
1424 (ly:stencil-stack (car todo) X RIGHT line space)
1425 (ly:stencil-stack line X RIGHT (car todo) space))))
1427 ((<= (stencil-len new) line-width)
1428 (word-loop new (cdr todo)
1429 (cons (car todo) word-list)))
1432 ;; This depends on stencil stacking being
1433 ;; associative so that stacking
1434 ;; left-to-right and right-to-left leads to
1436 (if (= text-dir LEFT)
1438 (reverse! word-list)))
1439 (len (stencil-len line))
1440 (stretch (- line-width len))
1443 (stack-stencils X RIGHT (1+ space) word-list))
1446 ;; Uh oh, nothing to fill.
1447 (loop (cons (maybe-shift line) lines) todo)
1449 (stack-stencils X RIGHT
1450 (+ space (/ stretch spaces))
1454 (else ;; not justify
1455 (loop (cons (maybe-shift line) lines) todo)))))
1458 ;; Now we have the last line assembled with space
1459 ;; which is compressed. We want to use the
1460 ;; uncompressed version instead if it fits, and the
1461 ;; justified version if it doesn't.
1463 ;; This depends on stencil stacking being
1464 ;; associative so that stacking
1465 ;; left-to-right and right-to-left leads to
1467 (if (= text-dir LEFT)
1469 (reverse! word-list)))
1470 (big-line (stack-stencils X RIGHT base-space word-list))
1471 (big-len (stencil-len big-line))
1472 (len (stencil-len line)))
1475 (if (> big-len line-width)
1476 (stack-stencils X RIGHT
1479 (* (- big-len line-width)
1481 (* (- line-width len)
1485 (maybe-shift big-line))))))
1486 (else ;; not justify
1487 (reverse! lines (list (maybe-shift line)))))))))
1490 (define-markup-list-command (wordwrap-internal layout props justify args)
1491 (boolean? markup-list?)
1492 #:properties ((line-width #f)
1494 (text-direction RIGHT))
1495 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1496 (wordwrap-stencils (interpret-markup-list layout props args)
1500 (ly:output-def-lookup layout 'line-width))
1503 (define-markup-command (justify layout props args)
1506 #:properties ((baseline-skip)
1507 wordwrap-internal-markup-list)
1509 @cindex justifying text
1511 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1512 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1513 @var{X}@tie{}is the number of staff spaces.
1515 @lilypond[verbatim,quote]
1518 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1519 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1520 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1521 laboris nisi ut aliquip ex ea commodo consequat.
1525 (stack-lines DOWN 0.0 baseline-skip
1526 (wordwrap-internal-markup-list layout props #t args)))
1528 (define-markup-command (wordwrap layout props args)
1531 #:properties ((baseline-skip)
1532 wordwrap-internal-markup-list)
1533 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1534 the line width, where @var{X} is the number of staff spaces.
1536 @lilypond[verbatim,quote]
1539 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1540 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1541 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1542 laboris nisi ut aliquip ex ea commodo consequat.
1546 (stack-lines DOWN 0.0 baseline-skip
1547 (wordwrap-internal-markup-list layout props #f args)))
1549 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1551 #:properties ((line-width)
1553 (text-direction RIGHT))
1554 "Internal markup list command used to define @code{\\justify-string} and
1555 @code{\\wordwrap-string}."
1556 (let* ((para-strings (regexp-split
1557 (string-regexp-substitute
1559 (string-regexp-substitute "\r\n" "\n" arg))
1560 "\n[ \t\n]*\n[ \t\n]*"))
1561 (list-para-words (map (lambda (str)
1562 (regexp-split str "[ \t\n]+"))
1564 (para-lines (map (lambda (words)
1567 (interpret-markup layout props x))
1569 (wordwrap-stencils stencils
1571 line-width text-direction)))
1573 (concatenate para-lines)))
1575 (define-markup-command (wordwrap-string layout props arg)
1578 #:properties ((baseline-skip)
1579 wordwrap-string-internal-markup-list)
1580 "Wordwrap a string. Paragraphs may be separated with double newlines.
1582 @lilypond[verbatim,quote]
1584 \\override #'(line-width . 40)
1585 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1586 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1587 et dolore magna aliqua.
1590 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1591 laboris nisi ut aliquip ex ea commodo consequat.
1594 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1595 qui officia deserunt mollit anim id est laborum\"
1598 (stack-lines DOWN 0.0 baseline-skip
1599 (wordwrap-string-internal-markup-list layout props #f arg)))
1601 (define-markup-command (justify-string layout props arg)
1604 #:properties ((baseline-skip)
1605 wordwrap-string-internal-markup-list)
1606 "Justify a string. Paragraphs may be separated with double newlines
1608 @lilypond[verbatim,quote]
1610 \\override #'(line-width . 40)
1611 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1612 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1613 et dolore magna aliqua.
1616 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1617 laboris nisi ut aliquip ex ea commodo consequat.
1620 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1621 qui officia deserunt mollit anim id est laborum\"
1624 (stack-lines DOWN 0.0 baseline-skip
1625 (wordwrap-string-internal-markup-list layout props #t arg)))
1627 (define-markup-command (wordwrap-field layout props symbol)
1630 "Wordwrap the data which has been assigned to @var{symbol}.
1632 @lilypond[verbatim,quote]
1634 title = \"My title\"
1635 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1636 elit, sed do eiusmod tempor incididunt ut labore et dolore
1637 magna aliqua. Ut enim ad minim veniam, quis nostrud
1638 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1643 bookTitleMarkup = \\markup {
1645 \\fill-line { \\fromproperty #'header:title }
1647 \\wordwrap-field #'header:myText
1656 (let* ((m (chain-assoc-get symbol props)))
1658 (wordwrap-string-markup layout props m)
1661 (define-markup-command (justify-field layout props symbol)
1664 "Justify the data which has been assigned to @var{symbol}.
1666 @lilypond[verbatim,quote]
1668 title = \"My title\"
1669 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1670 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1671 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1672 laboris nisi ut aliquip ex ea commodo consequat.\"
1676 bookTitleMarkup = \\markup {
1678 \\fill-line { \\fromproperty #'header:title }
1680 \\justify-field #'header:myText
1689 (let* ((m (chain-assoc-get symbol props)))
1691 (justify-string-markup layout props m)
1694 (define-markup-command (combine layout props arg1 arg2)
1698 @cindex merging text
1700 Print two markups on top of each other.
1702 Note: @code{\\combine} cannot take a list of markups enclosed in
1703 curly braces as an argument; the follow example will not compile:
1706 \\combine @{ a list @}
1709 @lilypond[verbatim,quote]
1712 \\override #'(thickness . 2)
1714 \\draw-line #'(0 . 4)
1715 \\arrow-head #Y #DOWN ##f
1718 (let* ((s1 (interpret-markup layout props arg1))
1719 (s2 (interpret-markup layout props arg2)))
1720 (ly:stencil-add s1 s2)))
1723 ;; TODO: should extract baseline-skip from each argument somehow..
1725 (define-markup-command (column layout props args)
1728 #:properties ((baseline-skip))
1730 @cindex stacking text in a column
1732 Stack the markups in @var{args} vertically. The property
1733 @code{baseline-skip} determines the space between markups
1736 @lilypond[verbatim,quote]
1745 (let ((arg-stencils (interpret-markup-list layout props args)))
1746 (stack-lines -1 0.0 baseline-skip arg-stencils)))
1748 (define-markup-command (dir-column layout props args)
1751 #:properties ((direction)
1754 @cindex changing direction of text columns
1756 Make a column of @var{args}, going up or down, depending on the
1757 setting of the @code{direction} layout property.
1759 @lilypond[verbatim,quote]
1761 \\override #`(direction . ,UP) {
1771 \\override #'(direction . 1) {
1778 (stack-lines (if (number? direction) direction -1)
1781 (interpret-markup-list layout props args)))
1783 (define (general-column align-dir baseline mols)
1784 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1786 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1787 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1788 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1789 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1791 (define-markup-command (center-column layout props args)
1794 #:properties ((baseline-skip))
1796 @cindex centering a column of text
1798 Put @code{args} in a centered column.
1800 @lilypond[verbatim,quote]
1809 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1811 (define-markup-command (left-column layout props args)
1814 #:properties ((baseline-skip))
1816 @cindex text columns, left-aligned
1818 Put @code{args} in a left-aligned column.
1820 @lilypond[verbatim,quote]
1829 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1831 (define-markup-command (right-column layout props args)
1834 #:properties ((baseline-skip))
1836 @cindex text columns, right-aligned
1838 Put @code{args} in a right-aligned column.
1840 @lilypond[verbatim,quote]
1849 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1851 (define-markup-command (vcenter layout props arg)
1855 @cindex vertically centering text
1857 Align @code{arg} to its Y@tie{}center.
1859 @lilypond[verbatim,quote]
1867 (let* ((mol (interpret-markup layout props arg)))
1868 (ly:stencil-aligned-to mol Y CENTER)))
1870 (define-markup-command (center-align layout props arg)
1874 @cindex horizontally centering text
1876 Align @code{arg} to its X@tie{}center.
1878 @lilypond[verbatim,quote]
1888 (let* ((mol (interpret-markup layout props arg)))
1889 (ly:stencil-aligned-to mol X CENTER)))
1891 (define-markup-command (right-align layout props arg)
1895 @cindex right aligning text
1897 Align @var{arg} on its right edge.
1899 @lilypond[verbatim,quote]
1909 (let* ((m (interpret-markup layout props arg)))
1910 (ly:stencil-aligned-to m X RIGHT)))
1912 (define-markup-command (left-align layout props arg)
1916 @cindex left aligning text
1918 Align @var{arg} on its left edge.
1920 @lilypond[verbatim,quote]
1930 (let* ((m (interpret-markup layout props arg)))
1931 (ly:stencil-aligned-to m X LEFT)))
1933 (define-markup-command (general-align layout props axis dir arg)
1934 (integer? number? markup?)
1937 @cindex controlling general text alignment
1939 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1941 @lilypond[verbatim,quote]
1945 \\general-align #X #LEFT
1950 \\general-align #X #CENTER
1956 \\general-align #Y #UP
1963 \\general-align #Y #3.2
1970 (let* ((m (interpret-markup layout props arg)))
1971 (ly:stencil-aligned-to m axis dir)))
1973 (define-markup-command (halign layout props dir arg)
1977 @cindex setting horizontal text alignment
1979 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1980 left-aligned, while @code{+1} is right. Values in between interpolate
1981 alignment accordingly.
1983 @lilypond[verbatim,quote]
2008 (let* ((m (interpret-markup layout props arg)))
2009 (ly:stencil-aligned-to m X dir)))
2011 (define-markup-command (with-dimensions layout props x y arg)
2012 (number-pair? number-pair? markup?)
2015 @cindex setting extent of text objects
2017 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
2018 (let* ((expr (ly:stencil-expr (interpret-markup layout props arg))))
2020 (make-transparent-box-stencil x y)
2022 `(delay-stencil-evaluation ,(delay expr))
2025 (define-markup-command (pad-around layout props amount arg)
2028 "Add padding @var{amount} all around @var{arg}.
2030 @lilypond[verbatim,quote]
2043 (let* ((m (interpret-markup layout props arg))
2044 (x (interval-widen (ly:stencil-extent m X) amount))
2045 (y (interval-widen (ly:stencil-extent m Y) amount)))
2046 (ly:stencil-add (make-transparent-box-stencil x y)
2049 (define-markup-command (pad-x layout props amount arg)
2053 @cindex padding text horizontally
2055 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
2057 @lilypond[verbatim,quote]
2070 (let* ((m (interpret-markup layout props arg))
2071 (x (ly:stencil-extent m X))
2072 (y (ly:stencil-extent m Y)))
2073 (ly:make-stencil (ly:stencil-expr m)
2074 (interval-widen x amount)
2077 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
2078 (integer? ly:dir? markup? markup?)
2080 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
2081 (let ((m1 (interpret-markup layout props arg1))
2082 (m2 (interpret-markup layout props arg2)))
2083 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
2085 (define-markup-command (transparent layout props arg)
2088 "Make @var{arg} transparent.
2090 @lilypond[verbatim,quote]
2097 (let* ((m (interpret-markup layout props arg))
2098 (x (ly:stencil-extent m X))
2099 (y (ly:stencil-extent m Y)))
2100 (ly:make-stencil (list 'transparent-stencil (ly:stencil-expr m)) x y)))
2102 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
2103 (number-pair? number-pair? markup?)
2105 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
2107 @lilypond[verbatim,quote]
2114 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2120 (ly:stencil-add (make-transparent-box-stencil x-ext y-ext)
2121 (interpret-markup layout props arg)))
2123 (define-markup-command (hcenter-in layout props length arg)
2126 "Center @var{arg} horizontally within a box of extending
2127 @var{length}/2 to the left and right.
2129 @lilypond[quote,verbatim]
2132 \\set Staff.instrumentName = \\markup {
2139 \\set Staff.instrumentName = \\markup {
2148 (interpret-markup layout props
2149 (make-pad-to-box-markup
2150 (cons (/ length -2) (/ length 2))
2152 (make-center-align-markup arg))))
2154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2158 (define-markup-command (property-recursive layout props symbol)
2161 "Print out a warning when a header field markup contains some recursive
2163 (ly:warning "Recursive definition of property ~a detected!" symbol)
2166 (define-markup-command (fromproperty layout props symbol)
2169 "Read the @var{symbol} from property settings, and produce a stencil
2170 from the markup contained within. If @var{symbol} is not defined, it
2171 returns an empty markup.
2173 @lilypond[verbatim,quote]
2175 myTitle = \"myTitle\"
2179 \\fromproperty #'header:myTitle
2186 (let ((m (chain-assoc-get symbol props)))
2188 ;; prevent infinite loops by clearing the interpreted property:
2189 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2192 (define-markup-command (on-the-fly layout props procedure arg)
2193 (procedure? markup?)
2195 "Apply the @var{procedure} markup command to @var{arg}.
2196 @var{procedure} should take a single argument."
2197 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2198 (set-object-property! anonymous-with-signature
2201 (interpret-markup layout props (list anonymous-with-signature arg))))
2203 (define-markup-command (footnote layout props mkup note)
2206 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2208 @lilypond[verbatim,quote]
2211 \\override #'(padding . 0.2)
2215 The footnote will not be annotated automatically."
2216 (ly:stencil-combine-at-edge
2217 (interpret-markup layout props mkup)
2221 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2226 (define-markup-command (auto-footnote layout props mkup note)
2229 #:properties ((raise 0.5)
2231 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2233 @lilypond[verbatim,quote]
2236 \\override #'(padding . 0.2)
2240 The footnote will be annotated automatically."
2241 (let* ((markup-stencil (interpret-markup layout props mkup))
2242 (footnote-hash (gensym "footnote"))
2244 (gauge-stencil (interpret-markup
2247 ((ly:output-def-lookup
2249 'footnote-numbering-function)
2251 (x-ext (ly:stencil-extent gauge-stencil X))
2252 (y-ext (ly:stencil-extent gauge-stencil Y))
2254 `(delay-stencil-evaluation
2258 (ly:output-def-lookup layout
2259 'number-footnote-table))
2260 (footnote-stencil (if (list? table)
2261 (assoc-get footnote-hash
2264 (footnote-stencil (if (ly:stencil? footnote-stencil)
2267 (ly:programming-error
2268 "Cannot find correct footnote for a markup object.")
2270 (gap (- (interval-length x-ext)
2272 (ly:stencil-extent footnote-stencil X))))
2273 (y-trans (- (+ (cdr y-ext)
2275 (cdr (ly:stencil-extent footnote-stencil
2277 (ly:stencil-translate footnote-stencil
2278 (cons gap y-trans)))))))
2279 (main-stencil (ly:stencil-combine-at-edge
2283 (ly:make-stencil footnote-number x-ext y-ext)
2288 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2292 (define-markup-command (override layout props new-prop arg)
2296 @cindex overriding properties within text markup
2298 Add the argument @var{new-prop} to the property list. Properties
2299 may be any property supported by @rinternals{font-interface},
2300 @rinternals{text-interface} and
2301 @rinternals{instrument-specific-markup-interface}.
2303 @lilypond[verbatim,quote]
2311 \\override #'(baseline-skip . 4) {
2320 (interpret-markup layout (cons (list new-prop) props) arg))
2322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2326 (define-markup-command (verbatim-file layout props name)
2329 "Read the contents of file @var{name}, and include it verbatim.
2331 @lilypond[verbatim,quote]
2333 \\verbatim-file #\"simple.ly\"
2336 (interpret-markup layout props
2337 (if (ly:get-option 'safe)
2338 "verbatim-file disabled in safe mode"
2339 (let* ((str (ly:gulp-file name))
2340 (lines (string-split str #\nl)))
2341 (make-typewriter-markup
2342 (make-column-markup lines))))))
2344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2349 (define-markup-command (smaller layout props arg)
2352 "Decrease the font size relative to the current setting.
2354 @lilypond[verbatim,quote]
2367 (interpret-markup layout props
2368 `(,fontsize-markup -1 ,arg)))
2370 (define-markup-command (larger layout props arg)
2373 "Increase the font size relative to the current setting.
2375 @lilypond[verbatim,quote]
2383 (interpret-markup layout props
2384 `(,fontsize-markup 1 ,arg)))
2386 (define-markup-command (finger layout props arg)
2389 "Set @var{arg} as small numbers.
2391 @lilypond[verbatim,quote]
2398 (interpret-markup layout
2399 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2402 (define-markup-command (abs-fontsize layout props size arg)
2405 "Use @var{size} as the absolute font size (in points) to display @var{arg}.
2406 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2408 @lilypond[verbatim,quote]
2410 default text font size
2412 \\abs-fontsize #16 { text font size 16 }
2414 \\abs-fontsize #12 { text font size 12 }
2417 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2418 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2419 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2420 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2421 (magnification (/ size ref-size)))
2425 `((baseline-skip . ,(* magnification ref-baseline))
2426 (word-space . ,(* magnification ref-word-space))
2427 (font-size . ,(magnification->font-size magnification)))
2431 (define-markup-command (fontsize layout props increment arg)
2434 #:properties ((font-size 0)
2437 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2440 @lilypond[verbatim,quote]
2451 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2452 (word-space . ,(* word-space (magstep increment)))
2453 (font-size . ,(+ font-size increment)))
2457 (define-markup-command (magnify layout props sz arg)
2461 @cindex magnifying text
2463 Set the font magnification for its argument. In the following
2464 example, the middle@tie{}A is 10% larger:
2467 A \\magnify #1.1 @{ A @} A
2470 Note: Magnification only works if a font name is explicitly selected.
2471 Use @code{\\fontsize} otherwise.
2473 @lilypond[verbatim,quote]
2484 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2487 (define-markup-command (bold layout props arg)
2490 "Switch to bold font-series.
2492 @lilypond[verbatim,quote]
2500 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2502 (define-markup-command (sans layout props arg)
2505 "Switch to the sans serif font family.
2507 @lilypond[verbatim,quote]
2516 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2518 (define-markup-command (number layout props arg)
2521 "Set font family to @code{number}, which yields the font used for
2522 time signatures and fingerings. This font contains numbers and
2523 some punctuation; it has no letters.
2525 @lilypond[verbatim,quote]
2528 0 1 2 3 4 5 6 7 8 9 . ,
2532 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2534 (define-markup-command (roman layout props arg)
2537 "Set font family to @code{roman}.
2539 @lilypond[verbatim,quote]
2545 text in roman font family
2552 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2554 (define-markup-command (huge layout props arg)
2557 "Set font size to +2.
2559 @lilypond[verbatim,quote]
2567 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2569 (define-markup-command (large layout props arg)
2572 "Set font size to +1.
2574 @lilypond[verbatim,quote]
2582 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2584 (define-markup-command (normalsize layout props arg)
2587 "Set font size to default.
2589 @lilypond[verbatim,quote]
2602 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2604 (define-markup-command (small layout props arg)
2607 "Set font size to -1.
2609 @lilypond[verbatim,quote]
2617 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2619 (define-markup-command (tiny layout props arg)
2622 "Set font size to -2.
2624 @lilypond[verbatim,quote]
2632 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2634 (define-markup-command (teeny layout props arg)
2637 "Set font size to -3.
2639 @lilypond[verbatim,quote]
2647 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2649 (define-markup-command (fontCaps layout props arg)
2652 "Set @code{font-shape} to @code{caps}
2654 Note: @code{\\fontCaps} requires the installation and selection of
2655 fonts which support the @code{caps} font shape."
2656 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2659 (define-markup-command (smallCaps layout props arg)
2662 "Emit @var{arg} as small caps.
2664 Note: @code{\\smallCaps} does not support accented characters.
2666 @lilypond[verbatim,quote]
2675 (define (char-list->markup chars lower)
2676 (let ((final-string (string-upcase (reverse-list->string chars))))
2678 (markup #:fontsize -2 final-string)
2680 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2681 (if (null? rest-chars)
2683 (reverse! (cons (char-list->markup currents current-is-lower)
2685 (let* ((ch (car rest-chars))
2686 (is-lower (char-lower-case? ch)))
2687 (if (or (and current-is-lower is-lower)
2688 (and (not current-is-lower) (not is-lower)))
2689 (make-small-caps (cdr rest-chars)
2693 (make-small-caps (cdr rest-chars)
2696 (if (null? currents)
2698 (cons (char-list->markup
2699 currents current-is-lower)
2701 (interpret-markup layout props
2703 (make-small-caps (string->list arg) (list) #f (list))
2706 (define-markup-command (caps layout props arg)
2709 "Copy of the @code{\\smallCaps} command.
2711 @lilypond[verbatim,quote]
2720 (interpret-markup layout props (make-smallCaps-markup arg)))
2722 (define-markup-command (dynamic layout props arg)
2725 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2726 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2727 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2728 done in a different font. The recommended font for this is bold and italic.
2729 @lilypond[verbatim,quote]
2737 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2739 (define-markup-command (text layout props arg)
2742 "Use a text font instead of music symbol or music alphabet font.
2744 @lilypond[verbatim,quote]
2757 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2760 (define-markup-command (italic layout props arg)
2763 "Use italic @code{font-shape} for @var{arg}.
2765 @lilypond[verbatim,quote]
2773 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2775 (define-markup-command (typewriter layout props arg)
2778 "Use @code{font-family} typewriter for @var{arg}.
2780 @lilypond[verbatim,quote]
2789 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2791 (define-markup-command (upright layout props arg)
2794 "Set @code{font-shape} to @code{upright}. This is the opposite
2797 @lilypond[verbatim,quote]
2811 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2813 (define-markup-command (medium layout props arg)
2816 "Switch to medium font-series (in contrast to bold).
2818 @lilypond[verbatim,quote]
2831 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2834 (define-markup-command (normal-text layout props arg)
2837 "Set all font related properties (except the size) to get the default
2838 normal text font, no matter what font was used earlier.
2840 @lilypond[verbatim,quote]
2842 \\huge \\bold \\sans \\caps {
2854 (interpret-markup layout
2855 (cons '((font-family . roman) (font-shape . upright)
2856 (font-series . medium) (font-encoding . latin1))
2860 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2864 (define-markup-command (musicglyph layout props glyph-name)
2867 "@var{glyph-name} is converted to a musical symbol; for example,
2868 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2869 the music font. See @ruser{The Feta font} for a complete listing of
2870 the possible glyphs.
2872 @lilypond[verbatim,quote]
2875 \\musicglyph #\"rests.2\"
2876 \\musicglyph #\"clefs.G_change\"
2879 (let* ((font (ly:paper-get-font layout
2880 (cons '((font-encoding . fetaMusic)
2884 (glyph (ly:font-get-glyph font glyph-name)))
2885 (if (null? (ly:stencil-expr glyph))
2886 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2890 (define-markup-command (doublesharp layout props)
2893 "Draw a double sharp symbol.
2895 @lilypond[verbatim,quote]
2900 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2902 (define-markup-command (sesquisharp layout props)
2905 "Draw a 3/2 sharp symbol.
2907 @lilypond[verbatim,quote]
2912 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2914 (define-markup-command (sharp layout props)
2917 "Draw a sharp symbol.
2919 @lilypond[verbatim,quote]
2924 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2926 (define-markup-command (semisharp layout props)
2929 "Draw a semisharp symbol.
2931 @lilypond[verbatim,quote]
2936 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2938 (define-markup-command (natural layout props)
2941 "Draw a natural symbol.
2943 @lilypond[verbatim,quote]
2948 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2950 (define-markup-command (semiflat layout props)
2953 "Draw a semiflat symbol.
2955 @lilypond[verbatim,quote]
2960 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2962 (define-markup-command (flat layout props)
2965 "Draw a flat symbol.
2967 @lilypond[verbatim,quote]
2972 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2974 (define-markup-command (sesquiflat layout props)
2977 "Draw a 3/2 flat symbol.
2979 @lilypond[verbatim,quote]
2984 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2986 (define-markup-command (doubleflat layout props)
2989 "Draw a double flat symbol.
2991 @lilypond[verbatim,quote]
2996 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2998 (define-markup-command (with-color layout props color arg)
3002 @cindex coloring text
3004 Draw @var{arg} in color specified by @var{color}.
3006 @lilypond[verbatim,quote]
3018 (let ((stil (interpret-markup layout props arg)))
3019 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
3020 (ly:stencil-extent stil X)
3021 (ly:stencil-extent stil Y))))
3023 (define-markup-command (tied-lyric layout props str)
3026 #:properties ((word-space))
3028 @cindex simple text strings with tie characters
3030 Like simple-markup, but use tie characters for @q{~} tilde symbols.
3032 @lilypond[verbatim,quote]
3034 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
3035 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
3036 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
3039 (define (replace-ties tie str)
3040 (if (string-contains str "~")
3042 ((half-space (/ word-space 2))
3043 (parts (string-split str #\~))
3044 (tie-str (markup #:hspace half-space
3046 #:hspace half-space))
3047 (joined (list-join parts tie-str)))
3048 (make-concat-markup joined))
3051 (define short-tie-regexp (make-regexp "~[^.]~"))
3052 (define (match-short str) (regexp-exec short-tie-regexp str))
3054 (define (replace-short str mkp)
3055 (let ((match (match-short str)))
3057 (make-concat-markup (list
3059 (replace-ties "ties.lyric.default" str)))
3060 (let ((new-str (match:suffix match))
3061 (new-mkp (make-concat-markup (list
3063 (replace-ties "ties.lyric.default"
3064 (match:prefix match))
3065 (replace-ties "ties.lyric.short"
3066 (match:substring match))))))
3067 (replace-short new-str new-mkp)))))
3069 (interpret-markup layout
3071 (replace-short str (markup))))
3073 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3075 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3077 (define-markup-command (arrow-head layout props axis dir filled)
3078 (integer? ly:dir? boolean?)
3080 "Produce an arrow head in specified direction and axis.
3081 Use the filled head if @var{filled} is specified.
3082 @lilypond[verbatim,quote]
3085 \\general-align #Y #DOWN {
3086 \\arrow-head #Y #UP ##t
3087 \\arrow-head #Y #DOWN ##f
3089 \\arrow-head #X #RIGHT ##f
3090 \\arrow-head #X #LEFT ##f
3096 ((name (format #f "arrowheads.~a.~a~a"
3103 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3107 (define-markup-command (lookup layout props glyph-name)
3110 "Lookup a glyph by name.
3112 @lilypond[verbatim,quote]
3114 \\override #'(font-encoding . fetaBraces) {
3115 \\lookup #\"brace200\"
3118 \\lookup #\"brace180\"
3122 (ly:font-get-glyph (ly:paper-get-font layout props)
3125 (define-markup-command (char layout props num)
3128 "Produce a single character. Characters encoded in hexadecimal
3129 format require the prefix @code{#x}.
3131 @lilypond[verbatim,quote]
3133 \\char #65 \\char ##x00a9
3136 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
3138 (define number->mark-letter-vector (make-vector 25 #\A))
3143 (if (= i (- (char->integer #\I) (char->integer #\A)))
3145 (vector-set! number->mark-letter-vector j
3146 (integer->char (+ i (char->integer #\A)))))
3148 (define number->mark-alphabet-vector (list->vector
3149 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
3151 (define (number->markletter-string vec n)
3152 "Double letters for big marks."
3153 (let* ((lst (vector-length vec)))
3156 (string-append (number->markletter-string vec (1- (quotient n lst)))
3157 (number->markletter-string vec (remainder n lst)))
3158 (make-string 1 (vector-ref vec n)))))
3160 (define-markup-command (markletter layout props num)
3163 "Make a markup letter for @var{num}. The letters start with A
3164 to@tie{}Z (skipping letter@tie{}I), and continue with double letters.
3166 @lilypond[verbatim,quote]
3173 (ly:text-interface::interpret-markup layout props
3174 (number->markletter-string number->mark-letter-vector num)))
3176 (define-markup-command (markalphabet layout props num)
3179 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3180 and continue with double letters.
3182 @lilypond[verbatim,quote]
3189 (ly:text-interface::interpret-markup layout props
3190 (number->markletter-string number->mark-alphabet-vector num)))
3192 (define-public (horizontal-slash-interval num forward number-interval mag)
3194 (cond ;; ((= num 6) (interval-widen number-interval (* mag 0.5)))
3195 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3196 (else (interval-widen number-interval (* mag 0.25))))
3197 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3198 ;; ((= num 5) (interval-widen number-interval (* mag 0.5)))
3199 (else (interval-widen number-interval (* mag 0.25))))
3202 (define-public (adjust-slash-stencil num forward stencil mag)
3205 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3207 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3209 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3211 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3214 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3216 ;; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3221 (define (slashed-digit-internal layout props num forward font-size thickness)
3222 (let* ((mag (magstep font-size))
3224 (ly:output-def-lookup layout 'line-thickness)
3226 ;; backward slashes might use slope and point in the other direction!
3227 (dy (* mag (if forward 0.4 -0.4)))
3228 (number-stencil (interpret-markup layout
3229 (prepend-alist-chain 'font-encoding 'fetaText props)
3230 (number->string num)))
3231 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3232 (center (interval-center (ly:stencil-extent number-stencil Y)))
3233 ;; Use the real extents of the slash, not the whole number,
3234 ;; because we might translate the slash later on!
3235 (num-y (interval-widen (cons center center) (abs dy)))
3236 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3237 (slash-stencil (if is-sane
3238 (make-line-stencil thickness
3239 (car num-x) (- (interval-center num-y) dy)
3240 (cdr num-x) (+ (interval-center num-y) dy))
3242 (if (ly:stencil? slash-stencil)
3244 ;; for some numbers we need to shift the slash/backslash up or
3245 ;; down to make the slashed digit look better
3246 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3247 (set! number-stencil
3248 (ly:stencil-add number-stencil slash-stencil)))
3249 (ly:warning "Unable to create slashed digit ~a" num))
3253 (define-markup-command (slashed-digit layout props num)
3256 #:properties ((font-size 0)
3259 @cindex slashed digits
3261 A feta number, with slash. This is for use in the context of
3262 figured bass notation.
3263 @lilypond[verbatim,quote]
3267 \\override #'(thickness . 3)
3271 (slashed-digit-internal layout props num #t font-size thickness))
3273 (define-markup-command (backslashed-digit layout props num)
3276 #:properties ((font-size 0)
3279 @cindex backslashed digits
3281 A feta number, with backslash. This is for use in the context of
3282 figured bass notation.
3283 @lilypond[verbatim,quote]
3285 \\backslashed-digit #5
3287 \\override #'(thickness . 3)
3288 \\backslashed-digit #7
3291 (slashed-digit-internal layout props num #f font-size thickness))
3294 (define eyeglassespath
3295 '((moveto 0.42 0.77)
3296 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3297 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3298 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3299 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3302 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3303 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3304 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3305 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3307 (moveto 1.025 0.935)
3308 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3309 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3312 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3315 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3317 (define-markup-command (eyeglasses layout props)
3320 "Prints out eyeglasses, indicating strongly to look at the conductor.
3321 @lilypond[verbatim,quote]
3322 \\markup { \\eyeglasses }
3324 (interpret-markup layout props
3325 (make-override-markup '(line-cap-style . butt)
3326 (make-path-markup 0.15 eyeglassespath))))
3328 (define-markup-command (left-brace layout props size)
3332 A feta brace in point size @var{size}.
3334 @lilypond[verbatim,quote]
3341 (let* ((font (ly:paper-get-font layout
3342 (cons '((font-encoding . fetaBraces)
3345 (glyph-count (1- (ly:otf-glyph-count font)))
3346 (scale (ly:output-def-lookup layout 'output-scale))
3347 (scaled-size (/ (ly:pt size) scale))
3349 (ly:font-get-glyph font (string-append "brace"
3350 (number->string n)))))
3351 (get-y-from-brace (lambda (brace)
3353 (ly:stencil-extent (glyph brace) Y))))
3354 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3355 (glyph-found (glyph find-brace)))
3357 (if (or (null? (ly:stencil-expr glyph-found))
3358 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3359 (> scaled-size (interval-length
3360 (ly:stencil-extent (glyph glyph-count) Y))))
3362 (ly:warning (_ "no brace found for point size ~S ") size)
3363 (ly:warning (_ "defaulting to ~S pt")
3364 (/ (* scale (interval-length
3365 (ly:stencil-extent glyph-found Y)))
3369 (define-markup-command (right-brace layout props size)
3373 A feta brace in point size @var{size}, rotated 180 degrees.
3375 @lilypond[verbatim,quote]
3382 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3385 ;; the note command.
3386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3388 ;; TODO: better syntax.
3390 (define-markup-command (note-by-number layout props log dot-count dir)
3391 (number? number? number?)
3393 #:properties ((font-size 0)
3397 @cindex notes within text by log and dot-count
3399 Construct a note symbol, with stem and flag. By using fractional values for
3400 @var{dir}, longer or shorter stems can be obtained.
3401 Supports all note-head-styles.
3402 Supported flag-styles are @code{default}, @code{old-straight-flag},
3403 @code{modern-straight-flag} and @code{flat-flag}.
3405 @lilypond[verbatim,quote]
3407 \\note-by-number #3 #0 #DOWN
3409 \\note-by-number #1 #2 #0.8
3412 (define (get-glyph-name-candidates dir log style)
3413 (map (lambda (dir-name)
3414 (format #f "noteheads.~a~a" dir-name
3415 (if (and (symbol? style)
3416 (not (equal? 'default style)))
3417 (select-head-glyph style (min log 2))
3419 (list (if (= dir UP) "u" "d")
3422 (define (get-glyph-name font cands)
3425 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3426 (get-glyph-name font (cdr cands))
3429 (define (buildflags flag-stencil remain curr-stencil spacing)
3430 ;; Function to recursively create a stencil with @code{remain} flags
3431 ;; from the single-flag stencil @code{curr-stencil}, which is already
3432 ;; translated to the position of the previous flag position.
3434 ;; Copy and paste from /scm/flag-styles.scm
3436 (let* ((translated-stencil
3437 (ly:stencil-translate-axis curr-stencil spacing Y))
3438 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3439 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3442 (define (straight-flag-mrkp flag-thickness flag-spacing
3443 upflag-angle upflag-length
3444 downflag-angle downflag-length
3446 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3447 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3448 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3449 ;; @var{downflag-length} are given in staff spaces.
3451 ;; All lengths are scaled according to the font size of the note.
3453 ;; From /scm/flag-styles.scm, modified to fit here.
3455 (let* ((stem-up (> dir 0))
3456 ;; scale with the note size
3457 (factor (magstep font-size))
3458 (stem-thickness (* factor 0.1))
3459 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3460 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3461 (raw-length (if stem-up upflag-length downflag-length))
3462 (angle (if stem-up upflag-angle downflag-angle))
3463 (flag-length (+ (* raw-length factor) half-stem-thickness))
3464 (flag-end (if (= angle 0)
3465 (cons flag-length (* half-stem-thickness dir))
3466 (polar->rectangular flag-length angle)))
3467 (thickness (* flag-thickness factor))
3468 (thickness-offset (cons 0 (* -1 thickness dir)))
3469 (spacing (* -1 flag-spacing factor dir))
3470 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3471 ;; The points of a round-filled-polygon need to be given in
3472 ;; clockwise order, otherwise the polygon will be enlarged by
3477 (offset-add flag-end thickness-offset)
3478 (offset-add start thickness-offset))
3480 (offset-add start thickness-offset)
3481 (offset-add flag-end thickness-offset)
3483 (stencil (ly:round-filled-polygon points half-stem-thickness))
3484 ;; Log for 1/8 is 3, so we need to subtract 3
3485 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3488 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3490 (size-factor (magstep font-size))
3491 (blot (ly:output-def-lookup layout 'blot-diameter))
3493 (let ((result (get-glyph-name font
3494 (get-glyph-name-candidates
3495 (sign dir) log style))))
3496 (if (string-null? result)
3497 ;; If no glyph name can be found, select default heads.
3498 ;; Though this usually means an unsupported style has been
3499 ;; chosen, it also prevents unrelated 'style settings from
3500 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3502 (get-glyph-name font
3503 (get-glyph-name-candidates
3504 (sign dir) log 'default))
3506 (head-glyph (ly:font-get-glyph font head-glyph-name))
3507 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3508 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3509 (stem-length (* size-factor (max 3 (- log 1))))
3510 ;; With ancient-flags we want a tighter stem
3511 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3512 (stemy (* dir stem-length))
3513 (attach-off (cons (interval-index
3514 (ly:stencil-extent head-glyph X)
3515 (* (sign dir) (car attach-indices)))
3516 ;; fixme, this is inconsistent between X & Y.
3519 (ly:stencil-extent head-glyph Y)
3520 (cdr attach-indices)))))
3521 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3523 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3524 (stem-glyph (and (> log 0)
3525 (ly:round-filled-box
3526 (ordered-cons (+ stem-X-corr (car attach-off))
3527 (+ stem-X-corr (car attach-off)
3528 (* (- (sign dir)) stem-thickness)))
3529 (cons (min stemy (cdr attach-off))
3530 (max stemy (cdr attach-off)))
3531 (/ stem-thickness 3))))
3532 (dot (ly:font-get-glyph font "dots.dot"))
3533 (dotwid (interval-length (ly:stencil-extent dot X)))
3534 (dots (and (> dot-count 0)
3535 (apply ly:stencil-add
3537 (ly:stencil-translate-axis
3538 dot (* 2 x dotwid) X))
3539 (iota dot-count)))))
3540 ;; Straight-flags. Values taken from /scm/flag-style.scm
3541 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3542 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3543 (flat-flag (straight-flag-mrkp 0.55 1.0 0 1.0 0 1.0 dir))
3544 ;; Calculate a corrective to avoid a gap between
3545 ;; straight-flags and the stem.
3546 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3547 (eq? flag-style 'old-straight-flag)
3548 (eq? flag-style 'flat-flag))
3549 (/ blot 10 (* -1 dir))
3551 (flaggl (and (> log 2)
3552 (ly:stencil-translate
3553 (cond ((eq? flag-style 'modern-straight-flag)
3554 modern-straight-flag)
3555 ((eq? flag-style 'old-straight-flag)
3557 ((eq? flag-style 'flat-flag)
3560 (ly:font-get-glyph font
3561 (format #f (if ancient-flags?
3562 "flags.mensural~a2~a"
3564 (if (> dir 0) "u" "d")
3566 (cons (+ (car attach-off)
3567 ;; For tighter stems (with ancient-flags) the
3568 ;; flag has to be adjusted different.
3569 (if (and (not ancient-flags?) (< dir 0))
3572 (+ stemy flag-style-Y-corr))))))
3574 ;; If there is a flag on an upstem and the stem is short, move the dots
3575 ;; to avoid the flag. 16th notes get a special case because their flags
3576 ;; hang lower than any other flags.
3577 ;; Not with ancient flags or straight-flags.
3578 (if (and dots (> dir 0) (> log 2)
3579 (or (eq? flag-style 'default) (null? flag-style))
3580 (not ancient-flags?)
3581 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3582 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3584 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3585 (if (ly:stencil? stem-glyph)
3586 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3587 (set! stem-glyph head-glyph))
3588 (if (ly:stencil? dots)
3591 (ly:stencil-translate-axis
3593 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3599 (let ((divisor (log 2)))
3600 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3602 (define (parse-simple-duration duration-string)
3603 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3604 and return a (log dots) list."
3605 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3607 (if (and match (string=? duration-string (match:substring match 0)))
3608 (let ((len (match:substring match 1))
3609 (dots (match:substring match 2)))
3610 (list (cond ((string=? len "breve") -1)
3611 ((string=? len "longa") -2)
3612 ((string=? len "maxima") -3)
3613 (else (log2 (string->number len))))
3614 (if dots (string-length dots) 0)))
3615 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3617 (define-markup-command (note layout props duration dir)
3620 #:properties (note-by-number-markup)
3622 @cindex notes within text by string
3624 This produces a note with a stem pointing in @var{dir} direction, with
3625 the @var{duration} for the note head type and augmentation dots. For
3626 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3627 a shortened down stem.
3629 @lilypond[verbatim,quote]
3631 \\override #'(style . cross) {
3635 \\note #\"breve\" #0
3638 (let ((parsed (parse-simple-duration duration)))
3639 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3642 ;; the rest command.
3643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3645 (define-markup-command (rest-by-number layout props log dot-count)
3648 #:properties ((font-size 0)
3650 (multi-measure-rest #f))
3652 @cindex rests or multi-measure-rests within text by log and dot-count
3654 A rest or multi-measure-rest symbol.
3656 @lilypond[verbatim,quote]
3658 \\rest-by-number #3 #2
3660 \\rest-by-number #0 #1
3662 \\override #'(multi-measure-rest . #t)
3663 \\rest-by-number #0 #0
3667 (define (get-glyph-name-candidates log style)
3668 (let* (;; Choose the style-string to be added.
3669 ;; If no glyph exists, select others for the specified styles
3670 ;; otherwise defaulting.
3673 ;; 'baroque needs to be special-cased, otherwise
3674 ;; `select-head-glyphĀ“ would catch neomensural-glyphs for
3675 ;; this style, if (< log 0).
3676 (eq? style 'baroque)
3677 (string-append (number->string log) ""))
3678 ((eq? style 'petrucci)
3679 (string-append (number->string log) "mensural"))
3680 ;; In other cases `select-head-glyphĀ“ from output-lib.scm
3681 ;; works for rest-glyphs, too.
3682 ((and (symbol? style) (not (eq? style 'default)))
3683 (select-head-glyph style log))
3685 ;; Choose ledgered glyphs for whole and half rest.
3686 ;; Except for the specified styles, logs and MultiMeasureRests.
3688 (if (and (or (list? style)
3690 '(neomensural mensural petrucci))))
3691 (not multi-measure-rest)
3692 (or (= log 0) (= log 1)))
3695 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3697 (define (get-glyph-name font cands)
3698 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3703 (ly:paper-get-font layout
3704 (cons '((font-encoding . fetaMusic)) props)))
3707 (get-glyph-name font
3708 (get-glyph-name-candidates log style))))
3709 (if (string-null? result)
3710 ;; If no glyph name can be found, select default rests. Though
3711 ;; this usually means an unsupported style has been chosen, it
3712 ;; also prevents unrelated 'style settings from other grobs
3713 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3714 (get-glyph-name font (get-glyph-name-candidates log 'default))
3716 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3717 (dot (ly:font-get-glyph font "dots.dot"))
3718 (dot-width (interval-length (ly:stencil-extent dot X)))
3719 (dots (and (> dot-count 0)
3720 (apply ly:stencil-add
3722 (ly:stencil-translate-axis
3723 dot (* 2 x dot-width) X))
3724 (iota dot-count))))))
3726 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3727 ;; glyphs are taken for whole and half rests.
3728 ;; If they are dotted, move the dots in X-direction to avoid collision.
3732 (not (member style '(neomensural mensural petrucci))))
3733 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3735 ;; Add dots to the rest-glyph.
3737 ;; Not sure how to vertical align dots.
3738 ;; For now the dots are centered for half, whole or longer rests.
3739 ;; Otherwise placed near the top of the rest.
3741 ;; Dots for rests with (< log 0) dots are allowed, but not
3742 ;; if multi-measure-rest is set #t.
3743 (if (and (not multi-measure-rest) dots)
3746 (ly:stencil-translate
3749 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3751 (interval-center (ly:stencil-extent rest-glyph Y))
3752 (- (interval-end (ly:stencil-extent rest-glyph Y))
3753 (/ (* 2 dot-width) 3)))))
3757 (define-markup-command (rest layout props duration)
3760 #:properties ((style '())
3761 (multi-measure-rest #f)
3762 (multi-measure-rest-number #t)
3765 @cindex rests or multi-measure-rests within text by string
3767 This produces a rest, with the @var{duration} for the rest type and
3769 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3772 Printing MultiMeasureRests could be enabled with
3773 @code{\\override #'(multi-measure-rest . #t)}
3774 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3775 This is enabled for all styles using default-glyphs.
3776 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3778 @lilypond[verbatim,quote]
3784 \\override #'(multi-measure-rest . #t)
3788 \\override #'(multi-measure-rest-number . #f)
3793 ;; Get the number of mmr-glyphs.
3794 ;; Store them in a list.
3795 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3796 (define (mmr-numbers nmbr)
3797 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3798 (8-remainder (remainder nmbr 8))
3799 (4-bar-glyph (floor (/ 8-remainder 4)))
3800 (4-remainder (remainder nmbr 4))
3801 (2-bar-glyph (floor (/ 4-remainder 2)))
3802 (2-remainder (remainder 4-remainder 2))
3803 (1-bar-glyph (floor (/ 2-remainder 1))))
3804 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3806 ;; Get the correct mmr-glyphs.
3807 ;; Store them in a list.
3809 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3810 ;; -> ("rests.M3" "rests.M1")
3811 (define (get-mmr-glyphs lst1 lst2)
3812 (define (helper l1 l2 l3)
3817 (append (make-list (car l1) (car l2)) l3))))
3818 (helper lst1 lst2 '()))
3820 ;; If duration is not valid, print a warning and return empty-stencil
3821 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3822 (not multi-measure-rest))
3823 (and (= (string-length (car (string-split duration #\. ))) 1)
3824 (= (string->number (car (string-split duration #\. ))) 0)))
3826 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3829 ;; For simple rests:
3830 ;; Get a (log dots) list.
3831 (parsed (parse-simple-duration duration))
3832 ;; Create the rest-stencil
3834 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3835 ;; For MultiMeasureRests:
3836 ;; Get the duration-part of duration
3837 (dur-part-string (car (string-split duration #\. )))
3838 ;; Get the duration of MMR:
3839 ;; If not a number (eg. "maxima") calculate it.
3841 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3842 ;; Get a list of the correct number of each mmr-glyph.
3843 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3844 ;; Create a list of mmr-stencils,
3845 ;; translating the glyph for a whole rest.
3849 (let ((single-mmr-stil
3850 (rest-by-number-markup layout props (* -1 x) 0)))
3852 (ly:stencil-translate-axis
3854 ;; Ugh, hard-coded, why 1?
3858 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3859 ;; Adjust the space between the mmr-glyphs,
3860 ;; if not default-glyphs are used.
3861 (word-space (if (member style
3862 '(neomensural mensural petrucci))
3863 (/ (* word-space 2) 3)
3865 ;; Create the final mmr-stencil
3866 ;; via `stack-stencil-lineĀ“ from /scm/markup.scm
3867 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3869 ;; Print the number above a multi-measure-rest
3870 ;; Depends on duration, style and multi-measure-rest-number set #t
3871 (if (and multi-measure-rest
3872 multi-measure-rest-number
3874 (not (member style '(neomensural mensural petrucci))))
3875 (let* ((mmr-stil-x-center
3876 (interval-center (ly:stencil-extent mmr-stil X)))
3880 #:override '(font-encoding . fetaText)
3881 (number->string mmr-duration)))
3883 (interpret-markup layout props duration-markup))
3884 (mmr-number-stil-x-center
3885 (interval-center (ly:stencil-extent mmr-number-stil X))))
3887 (set! mmr-stil (ly:stencil-combine-at-edge
3890 (ly:stencil-translate-axis
3892 (- mmr-stil-x-center mmr-number-stil-x-center)
3896 (if multi-measure-rest
3900 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3902 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3904 (define-markup-command (fermata layout props) ()
3906 #:properties ((direction UP))
3907 "Create a fermata glyph. When @var{direction} is @code{DOWN}, use
3908 an inverted glyph. Note that within music, one would usually use the
3909 @code{\\fermata} articulation instead of a markup.
3911 @lilypond[verbatim,quote]
3912 { c''1^\\markup \\fermata d''1_\\markup \\fermata }
3914 \\markup { \\fermata \\override #`(direction . ,DOWN) \\fermata }
3917 (interpret-markup layout props
3918 (if (eqv? direction DOWN)
3919 (markup #:musicglyph "scripts.dfermata")
3920 (markup #:musicglyph "scripts.ufermata"))))
3922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3924 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3926 (define-markup-command (lower layout props amount arg)
3930 @cindex lowering text
3932 Lower @var{arg} by the distance @var{amount}.
3933 A negative @var{amount} indicates raising; see also @code{\\raise}.
3935 @lilypond[verbatim,quote]
3943 (ly:stencil-translate-axis (interpret-markup layout props arg)
3946 (define-markup-command (translate-scaled layout props offset arg)
3947 (number-pair? markup?)
3949 #:properties ((font-size 0))
3951 @cindex translating text
3952 @cindex scaling text
3954 Translate @var{arg} by @var{offset}, scaling the offset by the
3957 @lilypond[verbatim,quote]
3960 * \\translate #'(2 . 3) translate
3962 * \\translate-scaled #'(2 . 3) translate-scaled
3966 (let* ((factor (magstep font-size))
3967 (scaled (cons (* factor (car offset))
3968 (* factor (cdr offset)))))
3969 (ly:stencil-translate (interpret-markup layout props arg)
3972 (define-markup-command (raise layout props amount arg)
3976 @cindex raising text
3978 Raise @var{arg} by the distance @var{amount}.
3979 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3981 The argument to @code{\\raise} is the vertical displacement amount,
3982 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3983 raise objects in relation to their surrounding markups.
3985 If the text object itself is positioned above or below the staff, then
3986 @code{\\raise} cannot be used to move it, since the mechanism that
3987 positions it next to the staff cancels any shift made with
3988 @code{\\raise}. For vertical positioning, use the @code{padding}
3989 and/or @code{extra-offset} properties.
3991 @lilypond[verbatim,quote]
4000 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
4002 (define-markup-command (fraction layout props arg1 arg2)
4005 #:properties ((font-size 0))
4007 @cindex creating text fractions
4009 Make a fraction of two markups.
4010 @lilypond[verbatim,quote]
4016 (let* ((m1 (interpret-markup layout props arg1))
4017 (m2 (interpret-markup layout props arg2))
4018 (factor (magstep font-size))
4019 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
4020 (padding (* factor 0.2))
4021 (baseline (* factor 0.6))
4022 (offset (* factor 0.75)))
4023 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
4024 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
4025 (let* ((x1 (ly:stencil-extent m1 X))
4026 (x2 (ly:stencil-extent m2 X))
4027 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
4028 ;; should stack mols separately, to maintain LINE on baseline
4029 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
4031 (ly:stencil-aligned-to stack Y CENTER))
4033 (ly:stencil-aligned-to stack X LEFT))
4034 ;; should have EX dimension
4036 (ly:stencil-translate-axis stack offset Y))))
4038 (define-markup-command (normal-size-super layout props arg)
4041 #:properties ((font-size 0))
4043 @cindex setting superscript in standard font size
4045 Set @var{arg} in superscript with a normal font size.
4047 @lilypond[verbatim,quote]
4050 \\normal-size-super {
4051 superscript in standard size
4055 (ly:stencil-translate-axis
4056 (interpret-markup layout props arg)
4057 (* 1.0 (magstep font-size)) Y))
4059 (define-markup-command (super layout props arg)
4062 #:properties ((font-size 0))
4064 @cindex superscript text
4066 Set @var{arg} in superscript.
4068 @lilypond[verbatim,quote]
4078 (ly:stencil-translate-axis
4081 (cons `((font-size . ,(- font-size 3))) props)
4083 (* 1.0 (magstep font-size)) ; original font-size
4086 (define-markup-command (translate layout props offset arg)
4087 (number-pair? markup?)
4090 @cindex translating text
4092 Translate @var{arg} relative to its surroundings. @var{offset}
4093 is a pair of numbers representing the displacement in the X and Y axis.
4095 @lilypond[verbatim,quote]
4098 \\translate #'(2 . 3)
4099 \\line { translated two spaces right, three up }
4102 (ly:stencil-translate (interpret-markup layout props arg)
4105 (define-markup-command (sub layout props arg)
4108 #:properties ((font-size 0))
4110 @cindex subscript text
4112 Set @var{arg} in subscript.
4114 @lilypond[verbatim,quote]
4125 (ly:stencil-translate-axis
4128 (cons `((font-size . ,(- font-size 3))) props)
4130 (* -0.75 (magstep font-size)) ; original font-size
4133 (define-markup-command (normal-size-sub layout props arg)
4136 #:properties ((font-size 0))
4138 @cindex setting subscript in standard font size
4140 Set @var{arg} in subscript with a normal font size.
4142 @lilypond[verbatim,quote]
4146 subscript in standard size
4150 (ly:stencil-translate-axis
4151 (interpret-markup layout props arg)
4152 (* -0.75 (magstep font-size))
4155 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4157 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4159 (define-markup-command (hbracket layout props arg)
4163 @cindex placing horizontal brackets around text
4165 Draw horizontal brackets around @var{arg}.
4167 @lilypond[verbatim,quote]
4176 (let ((th 0.1) ;; todo: take from GROB.
4177 (m (interpret-markup layout props arg)))
4178 (bracketify-stencil m X th (* 2.5 th) th)))
4180 (define-markup-command (bracket layout props arg)
4184 @cindex placing vertical brackets around text
4186 Draw vertical brackets around @var{arg}.
4188 @lilypond[verbatim,quote]
4195 (let ((th 0.1) ;; todo: take from GROB.
4196 (m (interpret-markup layout props arg)))
4197 (bracketify-stencil m Y th (* 2.5 th) th)))
4199 (define-markup-command (parenthesize layout props arg)
4202 #:properties ((angularity 0)
4208 @cindex placing parentheses around text
4210 Draw parentheses around @var{arg}. This is useful for parenthesizing
4211 a column containing several lines of text.
4213 @lilypond[verbatim,quote]
4222 \\override #'(angularity . 2) {
4233 (let* ((m (interpret-markup layout props arg))
4234 (scaled-width (* size width))
4236 (* (chain-assoc-get 'line-thickness props 0.1)
4239 (min (* size 0.5 scaled-thickness)
4240 (* (/ 4 3.0) scaled-width)))
4241 (padding (chain-assoc-get 'padding props half-thickness)))
4242 (parenthesize-stencil
4243 m half-thickness scaled-width angularity padding)))
4246 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4247 ;; Delayed markup evaluation
4248 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4250 (define-markup-command (page-ref layout props label gauge default)
4251 (symbol? markup? markup?)
4254 @cindex referencing page numbers in text
4256 Reference to a page number. @var{label} is the label set on the referenced
4257 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4258 the maximum width of the page number, and @var{default} the value to display
4259 when @var{label} is not found.
4261 (If the current book or bookpart is set to use roman numerals for page numbers,
4262 the reference will be formatted accordingly -- in which case the @var{gauge}'s
4263 width may require additional tweaking.)"
4264 (let* ((gauge-stencil (interpret-markup layout props gauge))
4265 (x-ext (ly:stencil-extent gauge-stencil X))
4266 (y-ext (ly:stencil-extent gauge-stencil Y)))
4268 (make-transparent-box-stencil x-ext y-ext))
4270 `(delay-stencil-evaluation
4271 ,(delay (ly:stencil-expr
4272 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4273 (page-number (if (list? table)
4274 (assoc-get label table)
4276 (number-type (ly:output-def-lookup layout 'page-number-type))
4277 (page-markup (if page-number
4278 (number-format number-type page-number)
4280 (page-stencil (interpret-markup layout props page-markup))
4281 (gap (- (interval-length x-ext)
4282 (interval-length (ly:stencil-extent page-stencil X)))))
4283 (interpret-markup layout props
4284 (markup #:hspace gap page-markup))))))
4288 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4290 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4292 (define-markup-command (scale layout props factor-pair arg)
4293 (number-pair? markup?)
4296 @cindex scaling markup
4297 @cindex mirroring markup
4299 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4300 representing the scaling-factor in the X and Y axes.
4301 Negative values may be used to produce mirror images.
4303 @lilypond[verbatim,quote]
4313 (let ((stil (interpret-markup layout props arg))
4314 (sx (car factor-pair))
4315 (sy (cdr factor-pair)))
4316 (ly:stencil-scale stil sx sy)))
4318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4322 (define-markup-command (pattern layout props count axis space pattern)
4323 (integer? integer? number? markup?)
4326 Prints @var{count} times a @var{pattern} markup.
4327 Patterns are spaced apart by @var{space}.
4328 Patterns are distributed on @var{axis}.
4330 @lilypond[verbatim, quote]
4332 \"Horizontally repeated :\"
4333 \\pattern #7 #X #2 \\flat
4335 \"Vertically repeated :\"
4336 \\pattern #3 #Y #0.5 \\flat
4339 (let ((pattern-width (interval-length
4340 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4341 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4342 (let loop ((i (1- count)) (patterns (markup)))
4348 (markup patterns pattern)
4349 (markup #:column (patterns pattern))))
4352 (markup patterns pattern #:hspace space)
4353 (markup #:column (patterns pattern #:vspace space))))))))
4355 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4356 (number? ly:dir? markup? markup? markup?)
4358 #:properties ((word-space)
4361 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4362 with a line of markups @var{pattern} in between.
4363 Patterns are spaced apart by @var{space}.
4364 Patterns are aligned to the @var{dir} markup.
4366 @lilypond[verbatim, quote]
4369 \\fill-with-pattern #1 #RIGHT . first right
4370 \\fill-with-pattern #1 #RIGHT . second right
4372 \"center-aligned :\"
4373 \\fill-with-pattern #1.5 #CENTER - left right
4376 \\override #'(line-width . 50)
4377 \\fill-with-pattern #2 #LEFT : left first
4378 \\override #'(line-width . 50)
4379 \\fill-with-pattern #2 #LEFT : left second
4382 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4383 (pattern-width (interval-length pattern-x-extent))
4384 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4385 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4386 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4387 (period (+ space pattern-width))
4388 (count (truncate (/ (- middle-width pattern-width) period)))
4389 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4390 (interpret-markup layout props
4392 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4393 #:translate (cons x-offset 0)
4394 #:pattern (1+ count) X space pattern
4397 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4401 (define-markup-command (replace layout props replacements arg)
4405 Used to automatically replace a string by another in the markup @var{arg}.
4406 Each pair of the alist @var{replacements} specifies what should be replaced.
4407 The @code{key} is the string to be replaced by the @code{value} string.
4409 @lilypond[verbatim, quote]
4410 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4414 (internal-add-text-replacements
4419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4420 ;; Markup list commands
4421 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4423 (define-public (space-lines baseline stils)
4424 (let space-stil ((stils stils)
4428 (let* ((stil (car stils))
4429 (dy-top (max (- (/ baseline 1.5)
4430 (interval-bound (ly:stencil-extent stil Y) UP))
4432 (dy-bottom (max (+ (/ baseline 3.0)
4433 (interval-bound (ly:stencil-extent stil Y) DOWN))
4435 (new-stil (ly:make-stencil
4436 (ly:stencil-expr stil)
4437 (ly:stencil-extent stil X)
4438 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4440 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4442 (space-stil (cdr stils) (cons new-stil result))))))
4444 (define-markup-list-command (justified-lines layout props args)
4446 #:properties ((baseline-skip)
4447 wordwrap-internal-markup-list)
4449 @cindex justifying lines of text
4451 Like @code{\\justify}, but return a list of lines instead of a single markup.
4452 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4453 @var{X}@tie{}is the number of staff spaces."
4454 (space-lines baseline-skip
4455 (interpret-markup-list layout props
4456 (make-wordwrap-internal-markup-list #t args))))
4458 (define-markup-list-command (wordwrap-lines layout props args)
4460 #:properties ((baseline-skip)
4461 wordwrap-internal-markup-list)
4462 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4463 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4464 where @var{X} is the number of staff spaces."
4465 (space-lines baseline-skip
4466 (interpret-markup-list layout props
4467 (make-wordwrap-internal-markup-list #f args))))
4469 (define-markup-list-command (column-lines layout props args)
4471 #:properties ((baseline-skip))
4472 "Like @code{\\column}, but return a list of lines instead of a single markup.
4473 @code{baseline-skip} determines the space between each markup in @var{args}."
4474 (space-lines baseline-skip
4475 (interpret-markup-list layout props args)))
4477 (define-markup-list-command (override-lines layout props new-prop args)
4478 (pair? markup-list?)
4479 "Like @code{\\override}, for markup lists."
4480 (interpret-markup-list layout (cons (list new-prop) props) args))
4482 (define-markup-list-command (map-markup-commands layout props compose args)
4483 (procedure? markup-list?)
4484 "This applies the function @var{compose} to every markup in
4485 @var{args} (including elements of markup list command calls) in order
4486 to produce a new markup list. Since the return value from a markup
4487 list command call is not a markup list but rather a list of stencils,
4488 this requires passing those stencils off as the results of individual
4489 markup calls. That way, the results should work out as long as no
4490 markups rely on side effects."
4491 (let ((key (make-symbol "key")))
4495 ;; if `compose' does not actually interpret its markup
4496 ;; argument, we still need to return a list of stencils,
4497 ;; created from the single returned stencil
4499 (interpret-markup layout props
4501 (make-on-the-fly-markup
4502 (lambda (layout props m)
4503 ;; here all effects of `compose' on the
4504 ;; properties should be visible, so we
4505 ;; call interpret-markup-list at this
4506 ;; point of time and harvest its
4509 (interpret-markup-list
4510 layout props args)))
4511 (make-null-markup))))))
4512 (lambda (key stencils)
4515 (interpret-markup layout props
4516 (compose (make-stencil-markup sten))))