1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Markup commands and markup-list commands definitions.
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-markup-command' macro.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
42 ;;; `layout' is an output def, which properties can be accessed
43 ;;; using `ly:output-def-lookup'.
44 ;;; `props' is a list of property settings which can be accessed
45 ;;; using `chain-assoc-get' (more on that below)
48 ;;; the command arguments.
49 ;;; There is no limitation on the order of command arguments.
50 ;;; However, markup functions taking a markup as their last
51 ;;; argument are somewhat special as you can apply them to a
52 ;;; markup list, and the result is a markup list where the
53 ;;; markup function (with the specified leading arguments) has
54 ;;; been applied to every element of the original markup list.
56 ;;; Since replicating the leading arguments for applying a
57 ;;; markup function to a markup list is cheap mostly for
58 ;;; Scheme arguments, you avoid performance pitfalls by just
59 ;;; using Scheme arguments for the leading arguments of markup
60 ;;; functions that take a markup as their last argument.
63 ;;; the arguments signature, i.e., a list of type predicates which
64 ;;; are used to type check the arguments, and also to define the general
65 ;;; argument types (markup, markup-list, scheme) that the command is
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
71 ;;; for documentation purpose, builtin markup commands are grouped by
72 ;;; category. This can be any symbol. When documentation is generated,
73 ;;; the symbol is converted to a capitalized string, where hyphens are
74 ;;; replaced by spaces.
77 ;;; this is used both for documentation generation, and to ease
78 ;;; programming the command itself. It is list of
79 ;;; (property-name default-value)
80 ;;; or (property-name)
81 ;;; elements. Each property is looked-up in the `props' argument, and
82 ;;; the symbol naming the property is bound to its value.
83 ;;; When the property is not found in `props', then the symbol is bound
84 ;;; to the given default value. When no default value is given, #f is
86 ;;; Thus, using the following property bindings:
89 ;;; is equivalent to writing:
90 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;; (font-size (chain-assoc-get 'font-size props 0)))
93 ;;; When a command `B' internally calls an other command `A', it may
94 ;;; desirable to see in `B' documentation all the properties and
95 ;;; default values used by `A'. In that case, add `A-markup' to the
96 ;;; property-bindings of B. (This is used when generating
97 ;;; documentation, but won't create bindings.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
115 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 (define-markup-command (draw-line layout props dest)
124 #:properties ((thickness 1))
126 @cindex drawing lines within text
129 @lilypond[verbatim,quote]
131 \\draw-line #'(4 . 4)
132 \\override #'(thickness . 5)
133 \\draw-line #'(-3 . 0)
136 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
140 (make-line-stencil th 0 0 x y)))
142 (define-markup-command (draw-dashed-line layout props dest)
145 #:properties ((thickness 1)
151 @cindex drawing dashed lines within text
155 If @code{full-length} is set to #t (default) the dashed-line extends to the
156 whole length given by @var{dest}, without white space at beginning or end.
157 @code{off} will then be altered to fit.
158 To insist on the given (or default) values of @code{on}, @code{off} use
159 @code{\\override #'(full-length . #f)}
160 Manual settings for @code{on},@code{off} and @code{phase} are possible.
161 @lilypond[verbatim,quote]
163 \\draw-dashed-line #'(5.1 . 2.3)
164 \\override #'(on . 0.3)
165 \\override #'(off . 0.5)
166 \\draw-dashed-line #'(5.1 . 2.3)
169 (let* ((line-thickness (ly:output-def-lookup layout 'line-thickness))
170 ;; Calculate the thickness to be used.
171 (th (* line-thickness thickness))
172 (half-thick (/ th 2))
173 ;; Get the extensions in x- and y-direction.
176 ;; Calculate the length of the dashed line.
177 (line-length (sqrt (+ (expt x 2) (expt y 2)))))
179 (if (and full-length (not (= (+ on off) 0)))
181 ;; Add double-thickness to avoid overlapping.
182 (set! off (+ (* 2 th) off))
183 (let* (;; Make a guess how often the off/on-pair should be printed
184 ;; after the initial `on´.
185 ;; Assume a minimum of 1 to avoid division by zero.
186 (guess (max 1 (round (/ (- line-length on) (+ off on)))))
187 ;; Not sure about the value or why corr is necessary at all,
188 ;; but it seems to be necessary.
190 (/ line-thickness 10)
192 ;; Calculate a new value for off to fit the
194 (new-off (/ (- line-length corr (* (1+ guess) on)) guess))
198 ;; Settings for (= on 0). Resulting in a dotted line.
200 ;; If line-length isn't shorter than `th´, change the given
201 ;; value for `off´ to fit the line-length.
202 ((and (= on 0) (< th line-length))
205 ;; If the line-length is shorter than `th´, it makes no
206 ;; sense to adjust `off´. The rounded edges of the lines
207 ;; would prevent any nice output.
209 ;; This will result in a single dot for very short lines.
210 ((and (= on 0) (>= th line-length))
213 ;; Settings for (not (= on 0)). Resulting in a dashed line.
215 ;; If line-length isn't shorter than one go of on-off-on,
216 ;; change the given value for `off´ to fit the line-length.
217 ((< (+ (* 2 on) off) line-length)
219 ;; If the line-length is too short, but greater than
220 ;; (* 4 th) set on/off to (/ line-length 3)
221 ((< (* 4 th) line-length)
222 (set! on (/ line-length 3))
223 (set! off (/ line-length 3)))
224 ;; If the line-length is shorter than (* 4 th), it makes
225 ;; no sense trying to adjust on/off. The rounded edges of
226 ;; the lines would prevent any nice output.
227 ;; Simply set `on´ to line-length.
229 (set! on line-length))))))
231 ;; If `on´ or `off´ is negative, or the sum of `on' and `off' equals zero a
232 ;; ghostscript-error occurs while calling
233 ;; (ly:make-stencil (list 'dashed-line th on off x y phase) x-ext y-ext)
234 ;; Better be paranoid.
235 (if (or (= (+ on off) 0)
239 (ly:warning "Can't print a line - setting on/off to default")
243 ;; To give the lines produced by \draw-line and \draw-dashed-line the same
244 ;; length, half-thick has to be added to the stencil-extensions.
246 (list 'dashed-line th on off x y phase)
247 (interval-widen (ordered-cons 0 x) half-thick)
248 (interval-widen (ordered-cons 0 y) half-thick))))
250 (define-markup-command (draw-dotted-line layout props dest)
253 #:properties ((thickness 1)
257 @cindex drawing dotted lines within text
261 The dotted-line always extends to the whole length given by @var{dest}, without
262 white space at beginning or end.
263 Manual settings for @code{off} are possible to get larger or smaller space
265 The given (or default) value of @code{off} will be altered to fit the
267 @lilypond[verbatim,quote]
269 \\draw-dotted-line #'(5.1 . 2.3)
270 \\override #'(thickness . 2)
271 \\override #'(off . 0.2)
272 \\draw-dotted-line #'(5.1 . 2.3)
276 (let ((new-props (prepend-alist-chain 'on 0
277 (prepend-alist-chain 'full-length #t props))))
279 (interpret-markup layout
281 (markup #:draw-dashed-line dest))))
283 (define-markup-command (draw-hline layout props)
286 #:properties ((draw-line-markup)
290 @cindex drawing a line across a page
292 Draws a line across a page, where the property @code{span-factor}
293 controls what fraction of the page is taken up.
294 @lilypond[verbatim,quote]
298 \\override #'(span-factor . 1/3)
303 (interpret-markup layout
305 (markup #:draw-line (cons (* line-width
309 (define-markup-command (draw-circle layout props radius thickness filled)
310 (number? number? boolean?)
313 @cindex drawing circles within text
315 A circle of radius @var{radius} and thickness @var{thickness},
318 @lilypond[verbatim,quote]
320 \\draw-circle #2 #0.5 ##f
322 \\draw-circle #2 #0 ##t
325 (make-circle-stencil radius thickness filled))
327 (define-markup-command (triangle layout props filled)
330 #:properties ((thickness 0.1)
334 @cindex drawing triangles within text
336 A triangle, either filled or empty.
338 @lilypond[verbatim,quote]
345 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
354 (cons 0 (* .86 ex)))))
356 (define-markup-command (circle layout props arg)
359 #:properties ((thickness 1)
361 (circle-padding 0.2))
363 @cindex circling text
365 Draw a circle around @var{arg}. Use @code{thickness},
366 @code{circle-padding} and @code{font-size} properties to determine line
367 thickness and padding around the markup.
369 @lilypond[verbatim,quote]
376 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
378 (pad (* (magstep font-size) circle-padding))
379 (m (interpret-markup layout props arg)))
380 (circle-stencil m th pad)))
382 (define-markup-command (with-url layout props url arg)
386 @cindex inserting URL links into text
388 Add a link to URL @var{url} around @var{arg}. This only works in
391 @lilypond[verbatim,quote]
393 \\with-url #\"http://lilypond.org/\" {
394 LilyPond ... \\italic {
395 music notation for everyone
400 (let* ((stil (interpret-markup layout props arg))
401 (xextent (ly:stencil-extent stil X))
402 (yextent (ly:stencil-extent stil Y))
403 (old-expr (ly:stencil-expr stil))
404 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
406 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
408 (define-markup-command (page-link layout props page-number arg)
412 @cindex referencing page numbers in text
414 Add a link to the page @var{page-number} around @var{arg}. This only works
417 @lilypond[verbatim,quote]
419 \\page-link #2 { \\italic { This links to page 2... } }
422 (let* ((stil (interpret-markup layout props arg))
423 (xextent (ly:stencil-extent stil X))
424 (yextent (ly:stencil-extent stil Y))
425 (old-expr (ly:stencil-expr stil))
426 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
428 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
430 (define-markup-command (with-link layout props label arg)
434 @cindex referencing page labels in text
436 Add a link to the page holding label @var{label} around @var{arg}. This
437 only works in the PDF backend.
439 @lilypond[verbatim,quote]
441 \\with-link #'label {
442 \\italic { This links to the page containing the label... }
446 (let* ((arg-stencil (interpret-markup layout props arg))
447 (x-ext (ly:stencil-extent arg-stencil X))
448 (y-ext (ly:stencil-extent arg-stencil Y)))
450 `(delay-stencil-evaluation
451 ,(delay (ly:stencil-expr
452 (let* ((table (ly:output-def-lookup layout 'label-page-table))
453 (page-number (if (list? table)
454 (assoc-get label table)
456 (link-expr (list 'page-link page-number
457 `(quote ,x-ext) `(quote ,y-ext))))
458 (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
464 (define-markup-command (beam layout props width slope thickness)
465 (number? number? number?)
468 @cindex drawing beams within text
470 Create a beam with the specified parameters.
471 @lilypond[verbatim,quote]
476 (let* ((y (* slope width))
477 (yext (cons (min 0 y) (max 0 y)))
478 (half (/ thickness 2)))
483 width (+ (* width slope) (/ thickness -2))
484 width (+ (* width slope) (/ thickness 2))
486 ,(ly:output-def-lookup layout 'blot-diameter)
489 (cons (+ (- half) (car yext))
490 (+ half (cdr yext))))))
492 (define-markup-command (underline layout props arg)
495 #:properties ((thickness 1) (offset 2))
497 @cindex underlining text
499 Underline @var{arg}. Looks at @code{thickness} to determine line
500 thickness, and @code{offset} to determine line y-offset.
502 @lilypond[verbatim,quote]
503 \\markup \\fill-line {
504 \\underline \"underlined\"
505 \\override #'(offset . 5)
506 \\override #'(thickness . 1)
507 \\underline \"underlined\"
508 \\override #'(offset . 1)
509 \\override #'(thickness . 5)
510 \\underline \"underlined\"
513 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
514 (underline-thick (* thickness thick))
515 (markup (interpret-markup layout props arg))
516 (x1 (car (ly:stencil-extent markup X)))
517 (x2 (cdr (ly:stencil-extent markup X)))
518 (y (* thick (- offset)))
519 (line (make-line-stencil underline-thick x1 y x2 y)))
520 (ly:stencil-add markup line)))
522 (define-markup-command (box layout props arg)
525 #:properties ((thickness 1)
529 @cindex enclosing text within a box
531 Draw a box round @var{arg}. Looks at @code{thickness},
532 @code{box-padding} and @code{font-size} properties to determine line
533 thickness and padding around the markup.
535 @lilypond[verbatim,quote]
537 \\override #'(box-padding . 0.5)
542 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
544 (pad (* (magstep font-size) box-padding))
545 (m (interpret-markup layout props arg)))
546 (box-stencil m th pad)))
548 (define-markup-command (filled-box layout props xext yext blot)
549 (number-pair? number-pair? number?)
552 @cindex drawing solid boxes within text
553 @cindex drawing boxes with rounded corners
555 Draw a box with rounded corners of dimensions @var{xext} and
556 @var{yext}. For example,
558 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
560 creates a box extending horizontally from -0.3 to 1.8 and
561 vertically from -0.3 up to 1.8, with corners formed from a
562 circle of diameter@tie{}0 (i.e., sharp corners).
564 @lilypond[verbatim,quote]
566 \\filled-box #'(0 . 4) #'(0 . 4) #0
567 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
568 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
570 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
576 (define-markup-command (rounded-box layout props arg)
579 #:properties ((thickness 1)
583 "@cindex enclosing text in a box with rounded corners
584 @cindex drawing boxes with rounded corners around text
585 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
586 @code{box-padding} and @code{font-size} properties to determine line
587 thickness and padding around the markup; the @code{corner-radius} property
588 makes it possible to define another shape for the corners (default is 1).
590 @lilypond[quote,verbatim,relative=2]
598 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
600 (pad (* (magstep font-size) box-padding))
601 (m (interpret-markup layout props arg)))
602 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
605 (define-markup-command (rotate layout props ang arg)
609 @cindex rotating text
611 Rotate object with @var{ang} degrees around its center.
613 @lilypond[verbatim,quote]
623 (let* ((stil (interpret-markup layout props arg)))
624 (ly:stencil-rotate stil ang 0 0)))
626 (define-markup-command (whiteout layout props arg)
630 @cindex adding a white background to text
632 Provide a white background for @var{arg}.
634 @lilypond[verbatim,quote]
637 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
641 (stencil-whiteout (interpret-markup layout props arg)))
643 (define-markup-command (pad-markup layout props amount arg)
648 @cindex putting space around text
650 Add space around a markup object.
652 @lilypond[verbatim,quote]
666 ((stil (interpret-markup layout props arg))
667 (xext (ly:stencil-extent stil X))
668 (yext (ly:stencil-extent stil Y)))
671 (ly:stencil-expr stil)
672 (interval-widen xext amount)
673 (interval-widen yext amount))))
675 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
677 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
679 (define-markup-command (strut layout props)
683 @cindex creating vertical spaces in text
685 Create a box of the same height as the space in the current font."
686 (let ((m (ly:text-interface::interpret-markup layout props " ")))
687 (ly:make-stencil (ly:stencil-expr m)
689 (ly:stencil-extent m X)
692 (define-markup-command (hspace layout props amount)
695 #:properties ((word-space))
697 @cindex creating horizontal spaces in text
699 Create an invisible object taking up horizontal space @var{amount}.
701 @lilypond[verbatim,quote]
710 (let ((corrected-space (- amount word-space)))
711 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))))
713 (define-markup-command (vspace layout props amount)
717 @cindex creating vertical spaces in text
719 Create an invisible object taking up vertical space
720 of @var{amount} multiplied by 3.
722 @lilypond[verbatim,quote]
733 (let ((amount (* amount 3.0)))
734 (ly:make-stencil "" (cons 0 0) (cons 0 amount))))
737 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
738 ;; importing graphics.
739 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
741 (define-markup-command (stencil layout props stil)
745 @cindex importing stencils into text
747 Use a stencil as markup.
749 @lilypond[verbatim,quote]
751 \\stencil #(make-circle-stencil 2 0 #t)
757 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
759 (define (get-postscript-bbox string)
760 "Extract the bbox from STRING, or return #f if not present."
762 ((match (regexp-exec bbox-regexp string)))
766 (string->number (match:substring match x)))
771 (define-markup-command (epsfile layout props axis size file-name)
772 (number? number? string?)
775 @cindex inlining an Encapsulated PostScript image
777 Inline an EPS image. The image is scaled along @var{axis} to
780 @lilypond[verbatim,quote]
782 \\general-align #Y #DOWN {
783 \\epsfile #X #20 #\"context-example.eps\"
784 \\epsfile #Y #20 #\"context-example.eps\"
788 (if (ly:get-option 'safe)
789 (interpret-markup layout props "not allowed in safe")
790 (eps-file->stencil axis size file-name)
793 (define-markup-command (postscript layout props str)
797 @cindex inserting PostScript directly into text
798 This inserts @var{str} directly into the output as a PostScript
801 @lilypond[verbatim,quote]
805 0.4 0.6 0.5 0 361 arc
807 1.0 0.6 0.5 0 361 arc
812 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
813 \\postscript #ringsps
825 gsave currentpoint translate
833 (define-markup-command (path layout props thickness commands) (number? list?)
835 #:properties ((line-cap-style 'round)
836 (line-join-style 'round)
839 @cindex paths, drawing
840 @cindex drawing paths
841 Draws a path with line thickness @var{thickness} according to the
842 directions given in @var{commands}. @var{commands} is a list of
843 lists where the @code{car} of each sublist is a drawing command and
844 the @code{cdr} comprises the associated arguments for each command.
846 Line-cap styles and line-join styles may be customized by
847 overriding the @code{line-cap-style} and @code{line-join-style}
848 properties, respectively. Available line-cap styles are
849 @code{'butt}, @code{'round}, and @code{'square}. Available
850 line-join styles are @code{'miter}, @code{'round}, and
853 The property @code{filled} specifies whether or not the path is
856 There are seven commands available to use in the list
857 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
858 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
859 @code{closepath}. Note that the commands that begin with @emph{r}
860 are the relative variants of the other three commands.
862 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
863 @code{rlineto} take 2 arguments; they are the X and Y coordinates
864 for the destination point.
866 The commands @code{curveto} and @code{rcurveto} create cubic
867 Bézier curves, and take 6 arguments; the first two are the X and Y
868 coordinates for the first control point, the second two are the X
869 and Y coordinates for the second control point, and the last two
870 are the X and Y coordinates for the destination point.
872 The @code{closepath} command takes zero arguments and closes the
873 current subpath in the active path.
875 Note that a sequence of commands @emph{must} begin with a
876 @code{moveto} or @code{rmoveto} to work with the SVG output.
878 @lilypond[verbatim,quote]
884 (curveto -5 -5 -5 5 -1 0)
888 \\path #0.25 #samplePath
891 (let* ((half-thickness (/ thickness 2))
892 (current-point '(0 . 0))
893 (set-point (lambda (lst) (set! current-point lst)))
894 (relative? (lambda (x)
895 (string-prefix? "r" (symbol->string (car x)))))
896 ;; For calculating extents, we want to modify the command
897 ;; list so that all coordinates are absolute.
898 (new-commands (map (lambda (x)
900 ;; for rmoveto, rlineto
901 ((and (relative? x) (= 3 (length x)))
903 (+ (car current-point)
905 (+ (cdr current-point)
911 ((and (relative? x) (= 7 (length x)))
912 (let* ((old-cp current-point)
919 (list (+ (car old-cp) (second x))
920 (+ (cdr old-cp) (third x))
921 (+ (car old-cp) (fourth x))
922 (+ (cdr old-cp) (fifth x))
925 ;; for moveto, lineto
927 (set-point (cons (second x)
932 (set-point (cons (sixth x)
935 ;; keep closepath for filtering;
936 ;; see `without-closepath'.
939 ;; path-min-max does not accept 0-arg lists,
940 ;; and since closepath does not affect extents, filter
941 ;; out those commands here.
942 (without-closepath (filter (lambda (x)
943 (not (equal? 'closepath (car x))))
945 (extents (path-min-max
946 ;; set the origin to the first moveto
947 (list (list-ref (car without-closepath) 0)
948 (list-ref (car without-closepath) 1))
950 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
951 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
952 (command-list (fold-right append '() commands)))
954 ;; account for line thickness
955 (set! X-extent (interval-widen X-extent half-thickness))
956 (set! Y-extent (interval-widen Y-extent half-thickness))
959 `(path ,thickness `(,@',command-list)
960 ',line-cap-style ',line-join-style ,filled)
964 (define-markup-list-command (score-lines layout props score)
967 This is the same as the @code{\\score} markup but delivers its
968 systems as a list of lines. This is not usually called directly by
969 the user. Instead, it is called when the parser encounters
970 @code{\\score} in a context where only markup lists are allowed. When
971 used as the argument of a toplevel @code{\\markuplist}, the result can
972 be split across pages."
973 (let ((output (ly:score-embedded-format score layout)))
975 (if (ly:music-output? output)
977 (lambda (paper-system)
978 ;; shift such that the refpoint of the bottom staff of
979 ;; the first system is the baseline of the score
980 (ly:stencil-translate-axis
981 (paper-system-stencil paper-system)
982 (- (car (paper-system-staff-extents paper-system)))
984 (vector->list (ly:paper-score-paper-systems output)))
986 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
989 (define-markup-command (score layout props score)
992 #:properties ((baseline-skip))
994 @cindex inserting music into text
996 Inline an image of music. The reference point (usually the middle
997 staff line) of the lowest staff in the top system is placed on the
1000 @lilypond[verbatim,quote]
1004 \\new Staff \\relative c' {
1007 \\mark \\markup { Allegro }
1013 \\new Staff \\relative c {
1019 f,( bes d bes d bes)
1027 \\override RehearsalMark
1028 #'break-align-symbols = #'(time-signature key-signature)
1029 \\override RehearsalMark
1030 #'self-alignment-X = #LEFT
1034 \\override TimeSignature
1035 #'break-align-anchor-alignment = #LEFT
1041 (stack-stencils Y DOWN baseline-skip
1042 (score-lines-markup-list layout props score)))
1044 (define-markup-command (null layout props)
1048 @cindex creating empty text objects
1050 An empty markup with extents of a single point.
1052 @lilypond[verbatim,quote]
1059 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1060 ;; basic formatting.
1061 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1063 (define-markup-command (simple layout props str)
1067 @cindex simple text strings
1069 A simple text string; @code{\\markup @{ foo @}} is equivalent with
1070 @code{\\markup @{ \\simple #\"foo\" @}}.
1072 Note: for creating standard text markup or defining new markup commands,
1073 the use of @code{\\simple} is unnecessary.
1075 @lilypond[verbatim,quote]
1077 \\simple #\"simple\"
1079 \\simple #\"strings\"
1082 (interpret-markup layout props str))
1084 (define-markup-command (tied-lyric layout props str)
1087 #:properties ((word-space))
1089 @cindex simple text strings with tie characters
1091 Like simple-markup, but use tie characters for @q{~} tilde symbols.
1093 @lilypond[verbatim,quote]
1095 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
1096 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
1097 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
1100 (define (replace-ties tie str)
1101 (if (string-contains str "~")
1103 ((half-space (/ word-space 2))
1104 (parts (string-split str #\~))
1105 (tie-str (markup #:hspace half-space
1107 #:hspace half-space))
1108 (joined (list-join parts tie-str)))
1109 (make-concat-markup joined))
1112 (define short-tie-regexp (make-regexp "~[^.]~"))
1113 (define (match-short str) (regexp-exec short-tie-regexp str))
1115 (define (replace-short str mkp)
1116 (let ((match (match-short str)))
1118 (make-concat-markup (list
1120 (replace-ties "ties.lyric.default" str)))
1121 (let ((new-str (match:suffix match))
1122 (new-mkp (make-concat-markup (list
1124 (replace-ties "ties.lyric.default"
1125 (match:prefix match))
1126 (replace-ties "ties.lyric.short"
1127 (match:substring match))))))
1128 (replace-short new-str new-mkp)))))
1130 (interpret-markup layout
1132 (replace-short str (markup))))
1134 (define-public empty-markup
1135 (make-simple-markup ""))
1137 ;; helper for justifying lines.
1138 (define (get-fill-space word-count line-width word-space text-widths)
1139 "Calculate the necessary paddings between each two adjacent texts.
1140 The lengths of all texts are stored in @var{text-widths}.
1141 The normal formula for the padding between texts a and b is:
1142 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
1143 The first and last padding have to be calculated specially using the
1144 whole length of the first or last text.
1145 All paddings are checked to be at least word-space, to ensure that
1147 Return a list of paddings."
1149 ((null? text-widths) '())
1151 ;; special case first padding
1152 ((= (length text-widths) word-count)
1154 (- (- (/ line-width (1- word-count)) (car text-widths))
1155 (/ (car (cdr text-widths)) 2))
1156 (get-fill-space word-count line-width word-space (cdr text-widths))))
1157 ;; special case last padding
1158 ((= (length text-widths) 2)
1159 (list (- (/ line-width (1- word-count))
1160 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
1162 (let ((default-padding
1163 (- (/ line-width (1- word-count))
1164 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
1166 (if (> word-space default-padding)
1169 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
1171 (define-markup-command (fill-line layout props args)
1174 #:properties ((text-direction RIGHT)
1177 "Put @var{markups} in a horizontal line of width @var{line-width}.
1178 The markups are spaced or flushed to fill the entire line.
1179 If there are no arguments, return an empty stencil.
1181 @lilypond[verbatim,quote]
1185 Words evenly spaced across the page
1189 \\line { Text markups }
1191 \\italic { evenly spaced }
1193 \\line { across the page }
1198 (let* ((orig-stencils (interpret-markup-list layout props args))
1201 (if (ly:stencil-empty? stc)
1203 stc)) orig-stencils))
1206 (if (ly:stencil-empty? stc)
1208 (interval-length (ly:stencil-extent stc X))))
1210 (text-width (apply + text-widths))
1211 (word-count (length stencils))
1212 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1217 (/ (- line-width text-width) 2)
1218 (/ (- line-width text-width) 2)))
1221 (- line-width text-width)))
1223 (get-fill-space word-count line-width word-space text-widths))))
1225 (line-contents (if (= word-count 1)
1232 (if (null? (remove ly:stencil-empty? orig-stencils))
1235 (if (= text-direction LEFT)
1236 (set! line-contents (reverse line-contents)))
1238 (stack-stencils-padding-list
1239 X RIGHT fill-space line-contents))
1240 (if (> word-count 1)
1241 ;; shift s.t. stencils align on the left edge, even if
1242 ;; first stencil had negative X-extent (e.g. center-column)
1243 ;; (if word-count = 1, X-extents are already normalized in
1244 ;; the definition of line-contents)
1246 (ly:stencil-translate-axis
1248 (- (car (ly:stencil-extent (car stencils) X)))
1252 (define-markup-command (line layout props args)
1255 #:properties ((word-space)
1256 (text-direction RIGHT))
1257 "Put @var{args} in a horizontal line. The property @code{word-space}
1258 determines the space between markups in @var{args}.
1260 @lilypond[verbatim,quote]
1267 (let ((stencils (interpret-markup-list layout props args)))
1268 (if (= text-direction LEFT)
1269 (set! stencils (reverse stencils)))
1272 (remove ly:stencil-empty? stencils))))
1274 (define-markup-command (concat layout props args)
1278 @cindex concatenating text
1279 @cindex ligatures in text
1281 Concatenate @var{args} in a horizontal line, without spaces in between.
1282 Strings and simple markups are concatenated on the input level, allowing
1283 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1284 equivalent to @code{\"fi\"}.
1286 @lilypond[verbatim,quote]
1295 (define (concat-string-args arg-list)
1296 (fold-right (lambda (arg result-list)
1297 (let ((result (if (pair? result-list)
1300 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1301 (set! arg (cadr arg)))
1302 (if (and (string? result) (string? arg))
1303 (cons (string-append arg result) (cdr result-list))
1304 (cons arg result-list))))
1308 (interpret-markup layout
1309 (prepend-alist-chain 'word-space 0 props)
1310 (make-line-markup (if (markup-command-list? args)
1312 (concat-string-args args)))))
1314 (define (wordwrap-stencils stencils
1315 justify base-space line-width text-dir)
1316 "Perform simple wordwrap, return stencil of each line."
1317 (define space (if justify
1318 ;; justify only stretches lines.
1321 (define (take-list width space stencils
1322 accumulator accumulated-width)
1323 "Return (head-list . tail) pair, with head-list fitting into width"
1324 (if (null? stencils)
1325 (cons accumulator stencils)
1326 (let* ((first (car stencils))
1327 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1328 (newwid (+ space first-wid accumulated-width)))
1329 (if (or (null? accumulator)
1331 (take-list width space
1333 (cons first accumulator)
1335 (cons accumulator stencils)))))
1336 (let loop ((lines '())
1338 (let* ((line-break (take-list line-width space todo
1340 (line-stencils (car line-break))
1341 (space-left (- line-width
1342 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1344 (line-word-space (cond ((not justify) space)
1345 ;; don't stretch last line of paragraph.
1346 ;; hmmm . bug - will overstretch the last line in some case.
1347 ((null? (cdr line-break))
1349 ((null? line-stencils) 0.0)
1350 ((null? (cdr line-stencils)) 0.0)
1351 (else (/ space-left (1- (length line-stencils))))))
1352 (line (stack-stencil-line line-word-space
1353 (if (= text-dir RIGHT)
1354 (reverse line-stencils)
1356 (if (pair? (cdr line-break))
1357 (loop (cons line lines)
1360 (if (= text-dir LEFT)
1362 (ly:stencil-translate-axis
1364 (- line-width (interval-end (ly:stencil-extent line X)))
1366 (reverse (cons line lines)))))))
1368 (define-markup-list-command (wordwrap-internal layout props justify args)
1369 (boolean? markup-list?)
1370 #:properties ((line-width #f)
1372 (text-direction RIGHT))
1373 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1374 (wordwrap-stencils (remove ly:stencil-empty?
1375 (interpret-markup-list layout props args))
1379 (ly:output-def-lookup layout 'line-width))
1382 (define-markup-command (justify layout props args)
1385 #:properties ((baseline-skip)
1386 wordwrap-internal-markup-list)
1388 @cindex justifying text
1390 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1391 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1392 @var{X}@tie{}is the number of staff spaces.
1394 @lilypond[verbatim,quote]
1397 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1398 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1399 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1400 laboris nisi ut aliquip ex ea commodo consequat.
1404 (stack-lines DOWN 0.0 baseline-skip
1405 (wordwrap-internal-markup-list layout props #t args)))
1407 (define-markup-command (wordwrap layout props args)
1410 #:properties ((baseline-skip)
1411 wordwrap-internal-markup-list)
1412 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1413 the line width, where @var{X} is the number of staff spaces.
1415 @lilypond[verbatim,quote]
1418 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1419 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1420 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1421 laboris nisi ut aliquip ex ea commodo consequat.
1425 (stack-lines DOWN 0.0 baseline-skip
1426 (wordwrap-internal-markup-list layout props #f args)))
1428 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1430 #:properties ((line-width)
1432 (text-direction RIGHT))
1433 "Internal markup list command used to define @code{\\justify-string} and
1434 @code{\\wordwrap-string}."
1435 (let* ((para-strings (regexp-split
1436 (string-regexp-substitute
1438 (string-regexp-substitute "\r\n" "\n" arg))
1439 "\n[ \t\n]*\n[ \t\n]*"))
1440 (list-para-words (map (lambda (str)
1441 (regexp-split str "[ \t\n]+"))
1443 (para-lines (map (lambda (words)
1445 (remove ly:stencil-empty?
1447 (interpret-markup layout props x))
1449 (wordwrap-stencils stencils
1451 line-width text-direction)))
1453 (apply append para-lines)))
1455 (define-markup-command (wordwrap-string layout props arg)
1458 #:properties ((baseline-skip)
1459 wordwrap-string-internal-markup-list)
1460 "Wordwrap a string. Paragraphs may be separated with double newlines.
1462 @lilypond[verbatim,quote]
1464 \\override #'(line-width . 40)
1465 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1466 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1467 et dolore magna aliqua.
1470 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1471 laboris nisi ut aliquip ex ea commodo consequat.
1474 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1475 qui officia deserunt mollit anim id est laborum\"
1478 (stack-lines DOWN 0.0 baseline-skip
1479 (wordwrap-string-internal-markup-list layout props #f arg)))
1481 (define-markup-command (justify-string layout props arg)
1484 #:properties ((baseline-skip)
1485 wordwrap-string-internal-markup-list)
1486 "Justify a string. Paragraphs may be separated with double newlines
1488 @lilypond[verbatim,quote]
1490 \\override #'(line-width . 40)
1491 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1492 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1493 et dolore magna aliqua.
1496 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1497 laboris nisi ut aliquip ex ea commodo consequat.
1500 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1501 qui officia deserunt mollit anim id est laborum\"
1504 (stack-lines DOWN 0.0 baseline-skip
1505 (wordwrap-string-internal-markup-list layout props #t arg)))
1507 (define-markup-command (wordwrap-field layout props symbol)
1510 "Wordwrap the data which has been assigned to @var{symbol}.
1512 @lilypond[verbatim,quote]
1514 title = \"My title\"
1515 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1516 elit, sed do eiusmod tempor incididunt ut labore et dolore
1517 magna aliqua. Ut enim ad minim veniam, quis nostrud
1518 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1523 bookTitleMarkup = \\markup {
1525 \\fill-line { \\fromproperty #'header:title }
1527 \\wordwrap-field #'header:myText
1536 (let* ((m (chain-assoc-get symbol props)))
1538 (wordwrap-string-markup layout props m)
1541 (define-markup-command (justify-field layout props symbol)
1544 "Justify the data which has been assigned to @var{symbol}.
1546 @lilypond[verbatim,quote]
1548 title = \"My title\"
1549 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1550 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1551 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1552 laboris nisi ut aliquip ex ea commodo consequat.\"
1556 bookTitleMarkup = \\markup {
1558 \\fill-line { \\fromproperty #'header:title }
1560 \\justify-field #'header:myText
1569 (let* ((m (chain-assoc-get symbol props)))
1571 (justify-string-markup layout props m)
1574 (define-markup-command (combine layout props arg1 arg2)
1578 @cindex merging text
1580 Print two markups on top of each other.
1582 Note: @code{\\combine} cannot take a list of markups enclosed in
1583 curly braces as an argument; the follow example will not compile:
1586 \\combine @{ a list @}
1589 @lilypond[verbatim,quote]
1592 \\override #'(thickness . 2)
1594 \\draw-line #'(0 . 4)
1595 \\arrow-head #Y #DOWN ##f
1598 (let* ((s1 (interpret-markup layout props arg1))
1599 (s2 (interpret-markup layout props arg2)))
1600 (ly:stencil-add s1 s2)))
1603 ;; TODO: should extract baseline-skip from each argument somehow..
1605 (define-markup-command (column layout props args)
1608 #:properties ((baseline-skip))
1610 @cindex stacking text in a column
1612 Stack the markups in @var{args} vertically. The property
1613 @code{baseline-skip} determines the space between markups
1616 @lilypond[verbatim,quote]
1625 (let ((arg-stencils (interpret-markup-list layout props args)))
1626 (stack-lines -1 0.0 baseline-skip
1627 (remove ly:stencil-empty? arg-stencils))))
1629 (define-markup-command (dir-column layout props args)
1632 #:properties ((direction)
1635 @cindex changing direction of text columns
1637 Make a column of @var{args}, going up or down, depending on the
1638 setting of the @code{direction} layout property.
1640 @lilypond[verbatim,quote]
1642 \\override #`(direction . ,UP) {
1652 \\override #'(direction . 1) {
1659 (stack-lines (if (number? direction) direction -1)
1662 (interpret-markup-list layout props args)))
1664 (define (general-column align-dir baseline mols)
1665 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1667 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1668 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1669 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1670 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1672 (define-markup-command (center-column layout props args)
1675 #:properties ((baseline-skip))
1677 @cindex centering a column of text
1679 Put @code{args} in a centered column.
1681 @lilypond[verbatim,quote]
1690 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1692 (define-markup-command (left-column layout props args)
1695 #:properties ((baseline-skip))
1697 @cindex text columns, left-aligned
1699 Put @code{args} in a left-aligned column.
1701 @lilypond[verbatim,quote]
1710 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1712 (define-markup-command (right-column layout props args)
1715 #:properties ((baseline-skip))
1717 @cindex text columns, right-aligned
1719 Put @code{args} in a right-aligned column.
1721 @lilypond[verbatim,quote]
1730 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1732 (define-markup-command (vcenter layout props arg)
1736 @cindex vertically centering text
1738 Align @code{arg} to its Y@tie{}center.
1740 @lilypond[verbatim,quote]
1748 (let* ((mol (interpret-markup layout props arg)))
1749 (ly:stencil-aligned-to mol Y CENTER)))
1751 (define-markup-command (center-align layout props arg)
1755 @cindex horizontally centering text
1757 Align @code{arg} to its X@tie{}center.
1759 @lilypond[verbatim,quote]
1769 (let* ((mol (interpret-markup layout props arg)))
1770 (ly:stencil-aligned-to mol X CENTER)))
1772 (define-markup-command (right-align layout props arg)
1776 @cindex right aligning text
1778 Align @var{arg} on its right edge.
1780 @lilypond[verbatim,quote]
1790 (let* ((m (interpret-markup layout props arg)))
1791 (ly:stencil-aligned-to m X RIGHT)))
1793 (define-markup-command (left-align layout props arg)
1797 @cindex left aligning text
1799 Align @var{arg} on its left edge.
1801 @lilypond[verbatim,quote]
1811 (let* ((m (interpret-markup layout props arg)))
1812 (ly:stencil-aligned-to m X LEFT)))
1814 (define-markup-command (general-align layout props axis dir arg)
1815 (integer? number? markup?)
1818 @cindex controlling general text alignment
1820 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1822 @lilypond[verbatim,quote]
1826 \\general-align #X #LEFT
1831 \\general-align #X #CENTER
1837 \\general-align #Y #UP
1844 \\general-align #Y #3.2
1851 (let* ((m (interpret-markup layout props arg)))
1852 (ly:stencil-aligned-to m axis dir)))
1854 (define-markup-command (halign layout props dir arg)
1858 @cindex setting horizontal text alignment
1860 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1861 left-aligned, while @code{+1} is right. Values in between interpolate
1862 alignment accordingly.
1864 @lilypond[verbatim,quote]
1889 (let* ((m (interpret-markup layout props arg)))
1890 (ly:stencil-aligned-to m X dir)))
1892 (define-markup-command (with-dimensions layout props x y arg)
1893 (number-pair? number-pair? markup?)
1896 @cindex setting extent of text objects
1898 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1899 (let* ((m (interpret-markup layout props arg)))
1900 (ly:make-stencil (ly:stencil-expr m) x y)))
1902 (define-markup-command (pad-around layout props amount arg)
1905 "Add padding @var{amount} all around @var{arg}.
1907 @lilypond[verbatim,quote]
1920 (let* ((m (interpret-markup layout props arg))
1921 (x (ly:stencil-extent m X))
1922 (y (ly:stencil-extent m Y)))
1923 (ly:make-stencil (ly:stencil-expr m)
1924 (interval-widen x amount)
1925 (interval-widen y amount))))
1927 (define-markup-command (pad-x layout props amount arg)
1931 @cindex padding text horizontally
1933 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1935 @lilypond[verbatim,quote]
1948 (let* ((m (interpret-markup layout props arg))
1949 (x (ly:stencil-extent m X))
1950 (y (ly:stencil-extent m Y)))
1951 (ly:make-stencil (ly:stencil-expr m)
1952 (interval-widen x amount)
1955 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1956 (integer? ly:dir? markup? markup?)
1958 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1959 (let ((m1 (interpret-markup layout props arg1))
1960 (m2 (interpret-markup layout props arg2)))
1961 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1963 (define-markup-command (transparent layout props arg)
1966 "Make @var{arg} transparent.
1968 @lilypond[verbatim,quote]
1975 (let* ((m (interpret-markup layout props arg))
1976 (x (ly:stencil-extent m X))
1977 (y (ly:stencil-extent m Y)))
1978 (ly:make-stencil "" x y)))
1980 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1981 (number-pair? number-pair? markup?)
1983 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1985 @lilypond[verbatim,quote]
1992 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1998 (let* ((m (interpret-markup layout props arg))
1999 (x (ly:stencil-extent m X))
2000 (y (ly:stencil-extent m Y)))
2001 (ly:make-stencil (ly:stencil-expr m)
2002 (interval-union x-ext x)
2003 (interval-union y-ext y))))
2005 (define-markup-command (hcenter-in layout props length arg)
2008 "Center @var{arg} horizontally within a box of extending
2009 @var{length}/2 to the left and right.
2011 @lilypond[quote,verbatim]
2014 \\set Staff.instrumentName = \\markup {
2021 \\set Staff.instrumentName = \\markup {
2030 (interpret-markup layout props
2031 (make-pad-to-box-markup
2032 (cons (/ length -2) (/ length 2))
2034 (make-center-align-markup arg))))
2036 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2038 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2040 (define-markup-command (property-recursive layout props symbol)
2043 "Print out a warning when a header field markup contains some recursive
2045 (ly:warning "Recursive definition of property ~a detected!" symbol)
2048 (define-markup-command (fromproperty layout props symbol)
2051 "Read the @var{symbol} from property settings, and produce a stencil
2052 from the markup contained within. If @var{symbol} is not defined, it
2053 returns an empty markup.
2055 @lilypond[verbatim,quote]
2057 myTitle = \"myTitle\"
2061 \\fromproperty #'header:myTitle
2068 (let ((m (chain-assoc-get symbol props)))
2070 ;; prevent infinite loops by clearing the interpreted property:
2071 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2074 (define-markup-command (on-the-fly layout props procedure arg)
2075 (procedure? markup?)
2077 "Apply the @var{procedure} markup command to @var{arg}.
2078 @var{procedure} should take a single argument."
2079 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2080 (set-object-property! anonymous-with-signature
2083 (interpret-markup layout props (list anonymous-with-signature arg))))
2085 (define-markup-command (footnote layout props mkup note)
2088 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2090 @lilypond[verbatim,quote]
2093 \\override #'(padding . 0.2)
2097 The footnote will not be annotated automatically."
2098 (ly:stencil-combine-at-edge
2099 (interpret-markup layout props mkup)
2103 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2108 (define-markup-command (auto-footnote layout props mkup note)
2111 #:properties ((raise 0.5)
2113 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2115 @lilypond[verbatim,quote]
2118 \\override #'(padding . 0.2)
2122 The footnote will be annotated automatically."
2123 (let* ((markup-stencil (interpret-markup layout props mkup))
2124 (footnote-hash (gensym "footnote"))
2126 (gauge-stencil (interpret-markup
2129 ((ly:output-def-lookup
2131 'footnote-numbering-function)
2133 (x-ext (ly:stencil-extent gauge-stencil X))
2134 (y-ext (ly:stencil-extent gauge-stencil Y))
2136 `(delay-stencil-evaluation
2140 (ly:output-def-lookup layout
2141 'number-footnote-table))
2142 (footnote-stencil (if (list? table)
2143 (assoc-get footnote-hash
2146 (footnote-stencil (if (ly:stencil? footnote-stencil)
2149 (ly:programming-error
2150 "Cannot find correct footnote for a markup object.")
2152 (gap (- (interval-length x-ext)
2154 (ly:stencil-extent footnote-stencil X))))
2155 (y-trans (- (+ (cdr y-ext)
2157 (cdr (ly:stencil-extent footnote-stencil
2159 (ly:stencil-translate footnote-stencil
2160 (cons gap y-trans)))))))
2161 (main-stencil (ly:stencil-combine-at-edge
2165 (ly:make-stencil footnote-number x-ext y-ext)
2170 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2174 (define-markup-command (override layout props new-prop arg)
2178 @cindex overriding properties within text markup
2180 Add the argument @var{new-prop} to the property list. Properties
2181 may be any property supported by @rinternals{font-interface},
2182 @rinternals{text-interface} and
2183 @rinternals{instrument-specific-markup-interface}.
2185 @lilypond[verbatim,quote]
2193 \\override #'(baseline-skip . 4) {
2202 (interpret-markup layout (cons (list new-prop) props) arg))
2204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2208 (define-markup-command (verbatim-file layout props name)
2211 "Read the contents of file @var{name}, and include it verbatim.
2213 @lilypond[verbatim,quote]
2215 \\verbatim-file #\"simple.ly\"
2218 (interpret-markup layout props
2219 (if (ly:get-option 'safe)
2220 "verbatim-file disabled in safe mode"
2221 (let* ((str (ly:gulp-file name))
2222 (lines (string-split str #\nl)))
2223 (make-typewriter-markup
2224 (make-column-markup lines))))))
2226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2231 (define-markup-command (smaller layout props arg)
2234 "Decrease the font size relative to the current setting.
2236 @lilypond[verbatim,quote]
2249 (interpret-markup layout props
2250 `(,fontsize-markup -1 ,arg)))
2252 (define-markup-command (larger layout props arg)
2255 "Increase the font size relative to the current setting.
2257 @lilypond[verbatim,quote]
2265 (interpret-markup layout props
2266 `(,fontsize-markup 1 ,arg)))
2268 (define-markup-command (finger layout props arg)
2271 "Set @var{arg} as small numbers.
2273 @lilypond[verbatim,quote]
2280 (interpret-markup layout
2281 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2284 (define-markup-command (abs-fontsize layout props size arg)
2287 "Use @var{size} as the absolute font size to display @var{arg}.
2288 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2290 @lilypond[verbatim,quote]
2292 default text font size
2294 \\abs-fontsize #16 { text font size 16 }
2296 \\abs-fontsize #12 { text font size 12 }
2299 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2300 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2301 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2302 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2303 (magnification (/ size ref-size)))
2307 `((baseline-skip . ,(* magnification ref-baseline))
2308 (word-space . ,(* magnification ref-word-space))
2309 (font-size . ,(magnification->font-size magnification)))
2313 (define-markup-command (fontsize layout props increment arg)
2316 #:properties ((font-size 0)
2319 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2322 @lilypond[verbatim,quote]
2333 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2334 (word-space . ,(* word-space (magstep increment)))
2335 (font-size . ,(+ font-size increment)))
2339 (define-markup-command (magnify layout props sz arg)
2343 @cindex magnifying text
2345 Set the font magnification for its argument. In the following
2346 example, the middle@tie{}A is 10% larger:
2349 A \\magnify #1.1 @{ A @} A
2352 Note: Magnification only works if a font name is explicitly selected.
2353 Use @code{\\fontsize} otherwise.
2355 @lilypond[verbatim,quote]
2366 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2369 (define-markup-command (bold layout props arg)
2372 "Switch to bold font-series.
2374 @lilypond[verbatim,quote]
2382 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2384 (define-markup-command (sans layout props arg)
2387 "Switch to the sans serif font family.
2389 @lilypond[verbatim,quote]
2398 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2400 (define-markup-command (number layout props arg)
2403 "Set font family to @code{number}, which yields the font used for
2404 time signatures and fingerings. This font contains numbers and
2405 some punctuation; it has no letters.
2407 @lilypond[verbatim,quote]
2410 0 1 2 3 4 5 6 7 8 9 . ,
2414 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2416 (define-markup-command (roman layout props arg)
2419 "Set font family to @code{roman}.
2421 @lilypond[verbatim,quote]
2427 text in roman font family
2434 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2436 (define-markup-command (huge layout props arg)
2439 "Set font size to +2.
2441 @lilypond[verbatim,quote]
2449 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2451 (define-markup-command (large layout props arg)
2454 "Set font size to +1.
2456 @lilypond[verbatim,quote]
2464 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2466 (define-markup-command (normalsize layout props arg)
2469 "Set font size to default.
2471 @lilypond[verbatim,quote]
2484 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2486 (define-markup-command (small layout props arg)
2489 "Set font size to -1.
2491 @lilypond[verbatim,quote]
2499 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2501 (define-markup-command (tiny layout props arg)
2504 "Set font size to -2.
2506 @lilypond[verbatim,quote]
2514 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2516 (define-markup-command (teeny layout props arg)
2519 "Set font size to -3.
2521 @lilypond[verbatim,quote]
2529 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2531 (define-markup-command (fontCaps layout props arg)
2534 "Set @code{font-shape} to @code{caps}
2536 Note: @code{\\fontCaps} requires the installation and selection of
2537 fonts which support the @code{caps} font shape."
2538 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2541 (define-markup-command (smallCaps layout props arg)
2544 "Emit @var{arg} as small caps.
2546 Note: @code{\\smallCaps} does not support accented characters.
2548 @lilypond[verbatim,quote]
2557 (define (char-list->markup chars lower)
2558 (let ((final-string (string-upcase (reverse-list->string chars))))
2560 (markup #:fontsize -2 final-string)
2562 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2563 (if (null? rest-chars)
2565 (reverse! (cons (char-list->markup currents current-is-lower)
2567 (let* ((ch (car rest-chars))
2568 (is-lower (char-lower-case? ch)))
2569 (if (or (and current-is-lower is-lower)
2570 (and (not current-is-lower) (not is-lower)))
2571 (make-small-caps (cdr rest-chars)
2575 (make-small-caps (cdr rest-chars)
2578 (if (null? currents)
2580 (cons (char-list->markup
2581 currents current-is-lower)
2583 (interpret-markup layout props
2585 (make-small-caps (string->list arg) (list) #f (list))
2588 (define-markup-command (caps layout props arg)
2591 "Copy of the @code{\\smallCaps} command.
2593 @lilypond[verbatim,quote]
2602 (interpret-markup layout props (make-smallCaps-markup arg)))
2604 (define-markup-command (dynamic layout props arg)
2607 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2608 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2609 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2610 done in a different font. The recommended font for this is bold and italic.
2611 @lilypond[verbatim,quote]
2619 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2621 (define-markup-command (text layout props arg)
2624 "Use a text font instead of music symbol or music alphabet font.
2626 @lilypond[verbatim,quote]
2639 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2642 (define-markup-command (italic layout props arg)
2645 "Use italic @code{font-shape} for @var{arg}.
2647 @lilypond[verbatim,quote]
2655 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2657 (define-markup-command (typewriter layout props arg)
2660 "Use @code{font-family} typewriter for @var{arg}.
2662 @lilypond[verbatim,quote]
2671 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2673 (define-markup-command (upright layout props arg)
2676 "Set @code{font-shape} to @code{upright}. This is the opposite
2679 @lilypond[verbatim,quote]
2693 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2695 (define-markup-command (medium layout props arg)
2698 "Switch to medium font-series (in contrast to bold).
2700 @lilypond[verbatim,quote]
2713 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2716 (define-markup-command (normal-text layout props arg)
2719 "Set all font related properties (except the size) to get the default
2720 normal text font, no matter what font was used earlier.
2722 @lilypond[verbatim,quote]
2724 \\huge \\bold \\sans \\caps {
2736 (interpret-markup layout
2737 (cons '((font-family . roman) (font-shape . upright)
2738 (font-series . medium) (font-encoding . latin1))
2742 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2744 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2746 (define-markup-command (musicglyph layout props glyph-name)
2749 "@var{glyph-name} is converted to a musical symbol; for example,
2750 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2751 the music font. See @ruser{The Feta font} for a complete listing of
2752 the possible glyphs.
2754 @lilypond[verbatim,quote]
2757 \\musicglyph #\"rests.2\"
2758 \\musicglyph #\"clefs.G_change\"
2761 (let* ((font (ly:paper-get-font layout
2762 (cons '((font-encoding . fetaMusic)
2766 (glyph (ly:font-get-glyph font glyph-name)))
2767 (if (null? (ly:stencil-expr glyph))
2768 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2772 (define-markup-command (doublesharp layout props)
2775 "Draw a double sharp symbol.
2777 @lilypond[verbatim,quote]
2782 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2784 (define-markup-command (sesquisharp layout props)
2787 "Draw a 3/2 sharp symbol.
2789 @lilypond[verbatim,quote]
2794 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2796 (define-markup-command (sharp layout props)
2799 "Draw a sharp symbol.
2801 @lilypond[verbatim,quote]
2806 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2808 (define-markup-command (semisharp layout props)
2811 "Draw a semisharp symbol.
2813 @lilypond[verbatim,quote]
2818 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2820 (define-markup-command (natural layout props)
2823 "Draw a natural symbol.
2825 @lilypond[verbatim,quote]
2830 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2832 (define-markup-command (semiflat layout props)
2835 "Draw a semiflat symbol.
2837 @lilypond[verbatim,quote]
2842 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2844 (define-markup-command (flat layout props)
2847 "Draw a flat symbol.
2849 @lilypond[verbatim,quote]
2854 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2856 (define-markup-command (sesquiflat layout props)
2859 "Draw a 3/2 flat symbol.
2861 @lilypond[verbatim,quote]
2866 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2868 (define-markup-command (doubleflat layout props)
2871 "Draw a double flat symbol.
2873 @lilypond[verbatim,quote]
2878 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2880 (define-markup-command (with-color layout props color arg)
2884 @cindex coloring text
2886 Draw @var{arg} in color specified by @var{color}.
2888 @lilypond[verbatim,quote]
2900 (let ((stil (interpret-markup layout props arg)))
2901 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2902 (ly:stencil-extent stil X)
2903 (ly:stencil-extent stil Y))))
2905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2909 (define-markup-command (arrow-head layout props axis dir filled)
2910 (integer? ly:dir? boolean?)
2912 "Produce an arrow head in specified direction and axis.
2913 Use the filled head if @var{filled} is specified.
2914 @lilypond[verbatim,quote]
2917 \\general-align #Y #DOWN {
2918 \\arrow-head #Y #UP ##t
2919 \\arrow-head #Y #DOWN ##f
2921 \\arrow-head #X #RIGHT ##f
2922 \\arrow-head #X #LEFT ##f
2928 ((name (format #f "arrowheads.~a.~a~a"
2935 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2939 (define-markup-command (lookup layout props glyph-name)
2942 "Lookup a glyph by name.
2944 @lilypond[verbatim,quote]
2946 \\override #'(font-encoding . fetaBraces) {
2947 \\lookup #\"brace200\"
2950 \\lookup #\"brace180\"
2954 (ly:font-get-glyph (ly:paper-get-font layout props)
2957 (define-markup-command (char layout props num)
2960 "Produce a single character. Characters encoded in hexadecimal
2961 format require the prefix @code{#x}.
2963 @lilypond[verbatim,quote]
2965 \\char #65 \\char ##x00a9
2968 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2970 (define number->mark-letter-vector (make-vector 25 #\A))
2975 (if (= i (- (char->integer #\I) (char->integer #\A)))
2977 (vector-set! number->mark-letter-vector j
2978 (integer->char (+ i (char->integer #\A)))))
2980 (define number->mark-alphabet-vector (list->vector
2981 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2983 (define (number->markletter-string vec n)
2984 "Double letters for big marks."
2985 (let* ((lst (vector-length vec)))
2988 (string-append (number->markletter-string vec (1- (quotient n lst)))
2989 (number->markletter-string vec (remainder n lst)))
2990 (make-string 1 (vector-ref vec n)))))
2992 (define-markup-command (markletter layout props num)
2995 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2996 (skipping letter@tie{}I), and continue with double letters.
2998 @lilypond[verbatim,quote]
3005 (ly:text-interface::interpret-markup layout props
3006 (number->markletter-string number->mark-letter-vector num)))
3008 (define-markup-command (markalphabet layout props num)
3011 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3012 and continue with double letters.
3014 @lilypond[verbatim,quote]
3021 (ly:text-interface::interpret-markup layout props
3022 (number->markletter-string number->mark-alphabet-vector num)))
3024 (define-public (horizontal-slash-interval num forward number-interval mag)
3026 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
3027 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
3028 (else (interval-widen number-interval (* mag 0.25))))
3029 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3030 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
3031 (else (interval-widen number-interval (* mag 0.25))))
3034 (define-public (adjust-slash-stencil num forward stencil mag)
3037 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3039 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3041 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3043 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3046 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3048 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3053 (define (slashed-digit-internal layout props num forward font-size thickness)
3054 (let* ((mag (magstep font-size))
3056 (ly:output-def-lookup layout 'line-thickness)
3058 ; backward slashes might use slope and point in the other direction!
3059 (dy (* mag (if forward 0.4 -0.4)))
3060 (number-stencil (interpret-markup layout
3061 (prepend-alist-chain 'font-encoding 'fetaText props)
3062 (number->string num)))
3063 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3064 (center (interval-center (ly:stencil-extent number-stencil Y)))
3065 ; Use the real extents of the slash, not the whole number, because we
3066 ; might translate the slash later on!
3067 (num-y (interval-widen (cons center center) (abs dy)))
3068 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3069 (slash-stencil (if is-sane
3070 (make-line-stencil thickness
3071 (car num-x) (- (interval-center num-y) dy)
3072 (cdr num-x) (+ (interval-center num-y) dy))
3074 (if (ly:stencil? slash-stencil)
3076 ; for some numbers we need to shift the slash/backslash up or down to make
3077 ; the slashed digit look better
3078 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3079 (set! number-stencil
3080 (ly:stencil-add number-stencil slash-stencil)))
3081 (ly:warning "Unable to create slashed digit ~a" num))
3085 (define-markup-command (slashed-digit layout props num)
3088 #:properties ((font-size 0)
3091 @cindex slashed digits
3093 A feta number, with slash. This is for use in the context of
3094 figured bass notation.
3095 @lilypond[verbatim,quote]
3099 \\override #'(thickness . 3)
3103 (slashed-digit-internal layout props num #t font-size thickness))
3105 (define-markup-command (backslashed-digit layout props num)
3108 #:properties ((font-size 0)
3111 @cindex backslashed digits
3113 A feta number, with backslash. This is for use in the context of
3114 figured bass notation.
3115 @lilypond[verbatim,quote]
3117 \\backslashed-digit #5
3119 \\override #'(thickness . 3)
3120 \\backslashed-digit #7
3123 (slashed-digit-internal layout props num #f font-size thickness))
3126 (define eyeglassespath
3127 '((moveto 0.42 0.77)
3128 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3129 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3130 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3131 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3134 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3135 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3136 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3137 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3139 (moveto 1.025 0.935)
3140 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3141 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3144 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3147 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3149 (define-markup-command (eyeglasses layout props)
3152 "Prints out eyeglasses, indicating strongly to look at the conductor.
3153 @lilypond[verbatim,quote]
3154 \\markup { \\eyeglasses }
3156 (interpret-markup layout props
3157 (make-override-markup '(line-cap-style . butt)
3158 (make-path-markup 0.15 eyeglassespath))))
3160 (define-markup-command (left-brace layout props size)
3164 A feta brace in point size @var{size}.
3166 @lilypond[verbatim,quote]
3173 (let* ((font (ly:paper-get-font layout
3174 (cons '((font-encoding . fetaBraces)
3177 (glyph-count (1- (ly:otf-glyph-count font)))
3178 (scale (ly:output-def-lookup layout 'output-scale))
3179 (scaled-size (/ (ly:pt size) scale))
3181 (ly:font-get-glyph font (string-append "brace"
3182 (number->string n)))))
3183 (get-y-from-brace (lambda (brace)
3185 (ly:stencil-extent (glyph brace) Y))))
3186 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3187 (glyph-found (glyph find-brace)))
3189 (if (or (null? (ly:stencil-expr glyph-found))
3190 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3191 (> scaled-size (interval-length
3192 (ly:stencil-extent (glyph glyph-count) Y))))
3194 (ly:warning (_ "no brace found for point size ~S ") size)
3195 (ly:warning (_ "defaulting to ~S pt")
3196 (/ (* scale (interval-length
3197 (ly:stencil-extent glyph-found Y)))
3201 (define-markup-command (right-brace layout props size)
3205 A feta brace in point size @var{size}, rotated 180 degrees.
3207 @lilypond[verbatim,quote]
3214 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3217 ;; the note command.
3218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3220 ;; TODO: better syntax.
3222 (define-markup-command (note-by-number layout props log dot-count dir)
3223 (number? number? number?)
3225 #:properties ((font-size 0)
3229 @cindex notes within text by log and dot-count
3231 Construct a note symbol, with stem and flag. By using fractional values for
3232 @var{dir}, longer or shorter stems can be obtained.
3233 Supports all note-head-styles.
3234 Supported flag-styles are @code{default}, @code{old-straight-flag} and
3235 @code{modern-straight-flag}.
3237 @lilypond[verbatim,quote]
3239 \\note-by-number #3 #0 #DOWN
3241 \\note-by-number #1 #2 #0.8
3244 (define (get-glyph-name-candidates dir log style)
3245 (map (lambda (dir-name)
3246 (format #f "noteheads.~a~a" dir-name
3247 (if (and (symbol? style)
3248 (not (equal? 'default style)))
3249 (select-head-glyph style (min log 2))
3251 (list (if (= dir UP) "u" "d")
3254 (define (get-glyph-name font cands)
3257 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3258 (get-glyph-name font (cdr cands))
3261 (define (buildflags flag-stencil remain curr-stencil spacing)
3262 ;; Function to recursively create a stencil with @code{remain} flags
3263 ;; from the single-flag stencil @code{curr-stencil}, which is already
3264 ;; translated to the position of the previous flag position.
3266 ;; Copy and paste from /scm/flag-styles.scm
3268 (let* ((translated-stencil
3269 (ly:stencil-translate-axis curr-stencil spacing Y))
3270 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3271 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3274 (define (straight-flag-mrkp flag-thickness flag-spacing
3275 upflag-angle upflag-length
3276 downflag-angle downflag-length
3278 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3279 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3280 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3281 ;; @var{downflag-length} are given in staff spaces.
3283 ;; All lengths are scaled according to the font size of the note.
3285 ;; From /scm/flag-styles.scm, modified to fit here.
3287 (let* ((stem-up (> dir 0))
3288 ; scale with the note size
3289 (factor (magstep font-size))
3290 (stem-thickness (* factor 0.1))
3291 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3292 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3293 (raw-length (if stem-up upflag-length downflag-length))
3294 (angle (if stem-up upflag-angle downflag-angle))
3295 (flag-length (+ (* raw-length factor) half-stem-thickness))
3296 (flag-end (polar->rectangular flag-length angle))
3297 (thickness (* flag-thickness factor))
3298 (thickness-offset (cons 0 (* -1 thickness dir)))
3299 (spacing (* -1 flag-spacing factor dir))
3300 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3301 ; The points of a round-filled-polygon need to be given in
3302 ; clockwise order, otherwise the polygon will be enlarged by
3304 (points (if stem-up (list start flag-end
3305 (offset-add flag-end thickness-offset)
3306 (offset-add start thickness-offset))
3308 (offset-add start thickness-offset)
3309 (offset-add flag-end thickness-offset)
3311 (stencil (ly:round-filled-polygon points half-stem-thickness))
3312 ; Log for 1/8 is 3, so we need to subtract 3
3313 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3316 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3318 (size-factor (magstep font-size))
3319 (blot (ly:output-def-lookup layout 'blot-diameter))
3321 (let ((result (get-glyph-name font
3322 (get-glyph-name-candidates
3323 (sign dir) log style))))
3324 (if (string-null? result)
3325 ;; If no glyph name can be found, select default heads.
3326 ;; Though this usually means an unsupported style has been
3327 ;; chosen, it also prevents unrelated 'style settings from
3328 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3330 (get-glyph-name font
3331 (get-glyph-name-candidates
3332 (sign dir) log 'default))
3334 (head-glyph (ly:font-get-glyph font head-glyph-name))
3335 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3336 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3337 (stem-length (* size-factor (max 3 (- log 1))))
3338 ;; With ancient-flags we want a tighter stem
3339 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3340 (stemy (* dir stem-length))
3341 (attach-off (cons (interval-index
3342 (ly:stencil-extent head-glyph X)
3343 (* (sign dir) (car attach-indices)))
3344 ; fixme, this is inconsistent between X & Y.
3347 (ly:stencil-extent head-glyph Y)
3348 (cdr attach-indices)))))
3349 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3351 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3352 (stem-glyph (and (> log 0)
3353 (ly:round-filled-box
3354 (ordered-cons (+ stem-X-corr (car attach-off))
3355 (+ stem-X-corr (car attach-off)
3356 (* (- (sign dir)) stem-thickness)))
3357 (cons (min stemy (cdr attach-off))
3358 (max stemy (cdr attach-off)))
3359 (/ stem-thickness 3))))
3360 (dot (ly:font-get-glyph font "dots.dot"))
3361 (dotwid (interval-length (ly:stencil-extent dot X)))
3362 (dots (and (> dot-count 0)
3363 (apply ly:stencil-add
3365 (ly:stencil-translate-axis
3366 dot (* 2 x dotwid) X))
3367 (iota dot-count)))))
3368 ;; Straight-flags. Values taken from /scm/flag-style.scm
3369 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3370 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3371 ;; Calculate a corrective to avoid a gap between
3372 ;; straight-flags and the stem.
3373 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3374 (eq? flag-style 'old-straight-flag))
3375 (/ blot 10 (* -1 dir))
3377 (flaggl (and (> log 2)
3378 (ly:stencil-translate
3379 (cond ((eq? flag-style 'modern-straight-flag)
3380 modern-straight-flag)
3381 ((eq? flag-style 'old-straight-flag)
3384 (ly:font-get-glyph font
3385 (format #f (if ancient-flags?
3386 "flags.mensural~a2~a"
3388 (if (> dir 0) "u" "d")
3390 (cons (+ (car attach-off)
3391 ;; For tighter stems (with ancient-flags) the
3392 ;; flag has to be adjusted different.
3393 (if (and (not ancient-flags?) (< dir 0))
3396 (+ stemy flag-style-Y-corr))))))
3398 ;; If there is a flag on an upstem and the stem is short, move the dots
3399 ;; to avoid the flag. 16th notes get a special case because their flags
3400 ;; hang lower than any other flags.
3401 ;; Not with ancient flags or straight-flags.
3402 (if (and dots (> dir 0) (> log 2)
3403 (or (eq? flag-style 'default) (null? flag-style))
3404 (not ancient-flags?)
3405 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3406 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3408 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3409 (if (ly:stencil? stem-glyph)
3410 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3411 (set! stem-glyph head-glyph))
3412 (if (ly:stencil? dots)
3415 (ly:stencil-translate-axis
3417 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3423 (let ((divisor (log 2)))
3424 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3426 (define (parse-simple-duration duration-string)
3427 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3428 and return a (log dots) list."
3429 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3431 (if (and match (string=? duration-string (match:substring match 0)))
3432 (let ((len (match:substring match 1))
3433 (dots (match:substring match 2)))
3434 (list (cond ((string=? len "breve") -1)
3435 ((string=? len "longa") -2)
3436 ((string=? len "maxima") -3)
3437 (else (log2 (string->number len))))
3438 (if dots (string-length dots) 0)))
3439 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3441 (define-markup-command (note layout props duration dir)
3444 #:properties (note-by-number-markup)
3446 @cindex notes within text by string
3448 This produces a note with a stem pointing in @var{dir} direction, with
3449 the @var{duration} for the note head type and augmentation dots. For
3450 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3451 a shortened down stem.
3453 @lilypond[verbatim,quote]
3455 \\override #'(style . cross) {
3459 \\note #\"breve\" #0
3462 (let ((parsed (parse-simple-duration duration)))
3463 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3466 ;; the rest command.
3467 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3469 (define-markup-command (rest-by-number layout props log dot-count)
3472 #:properties ((font-size 0)
3474 (multi-measure-rest #f))
3476 @cindex rests or multi-measure-rests within text by log and dot-count
3478 A rest or multi-measure-rest symbol.
3480 @lilypond[verbatim,quote]
3482 \\rest-by-number #3 #2
3484 \\rest-by-number #0 #1
3486 \\override #'(multi-measure-rest . #t)
3487 \\rest-by-number #0 #0
3491 (define (get-glyph-name-candidates log style)
3492 (let* (;; Choose the style-string to be added.
3493 ;; If no glyph exists, select others for the specified styles
3494 ;; otherwise defaulting.
3497 ;; 'baroque needs to be special-cased, otherwise
3498 ;; `select-head-glyph´ would catch neomensural-glyphs for
3499 ;; this style, if (< log 0).
3500 (eq? style 'baroque)
3501 (string-append (number->string log) ""))
3502 ((eq? style 'petrucci)
3503 (string-append (number->string log) "mensural"))
3504 ;; In other cases `select-head-glyph´ from output-lib.scm
3505 ;; works for rest-glyphs, too.
3506 ((and (symbol? style) (not (eq? style 'default)))
3507 (select-head-glyph style log))
3509 ;; Choose ledgered glyphs for whole and half rest.
3510 ;; Except for the specified styles, logs and MultiMeasureRests.
3512 (if (and (or (list? style)
3514 '(neomensural mensural petrucci))))
3515 (not multi-measure-rest)
3516 (or (= log 0) (= log 1)))
3519 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3521 (define (get-glyph-name font cands)
3522 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3527 (ly:paper-get-font layout
3528 (cons '((font-encoding . fetaMusic)) props)))
3531 (get-glyph-name font
3532 (get-glyph-name-candidates log style))))
3533 (if (string-null? result)
3534 ;; If no glyph name can be found, select default rests. Though
3535 ;; this usually means an unsupported style has been chosen, it
3536 ;; also prevents unrelated 'style settings from other grobs
3537 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3538 (get-glyph-name font (get-glyph-name-candidates log 'default))
3540 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3541 (dot (ly:font-get-glyph font "dots.dot"))
3542 (dot-width (interval-length (ly:stencil-extent dot X)))
3543 (dots (and (> dot-count 0)
3544 (apply ly:stencil-add
3546 (ly:stencil-translate-axis
3547 dot (* 2 x dot-width) X))
3548 (iota dot-count))))))
3550 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3551 ;; glyphs are taken for whole and half rests.
3552 ;; If they are dotted, move the dots in X-direction to avoid collision.
3556 (not (member style '(neomensural mensural petrucci))))
3557 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3559 ;; Add dots to the rest-glyph.
3561 ;; Not sure how to vertical align dots.
3562 ;; For now the dots are centered for half, whole or longer rests.
3563 ;; Otherwise placed near the top of the rest.
3565 ;; Dots for rests with (< log 0) dots are allowed, but not
3566 ;; if multi-measure-rest is set #t.
3567 (if (and (not multi-measure-rest) dots)
3570 (ly:stencil-translate
3573 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3575 (interval-center (ly:stencil-extent rest-glyph Y))
3576 (- (interval-end (ly:stencil-extent rest-glyph Y))
3577 (/ (* 2 dot-width) 3)))))
3581 (define-markup-command (rest layout props duration)
3584 #:properties ((style '())
3585 (multi-measure-rest #f)
3586 (multi-measure-rest-number #t)
3589 @cindex rests or multi-measure-rests within text by string
3591 This produces a rest, with the @var{duration} for the rest type and
3593 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3596 Printing MultiMeasureRests could be enabled with
3597 @code{\\override #'(multi-measure-rest . #t)}
3598 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3599 This is enabled for all styles using default-glyphs.
3600 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3602 @lilypond[verbatim,quote]
3608 \\override #'(multi-measure-rest . #t)
3612 \\override #'(multi-measure-rest-number . #f)
3617 ;; Get the number of mmr-glyphs.
3618 ;; Store them in a list.
3619 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3620 (define (mmr-numbers nmbr)
3621 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3622 (8-remainder (remainder nmbr 8))
3623 (4-bar-glyph (floor (/ 8-remainder 4)))
3624 (4-remainder (remainder nmbr 4))
3625 (2-bar-glyph (floor (/ 4-remainder 2)))
3626 (2-remainder (remainder 4-remainder 2))
3627 (1-bar-glyph (floor (/ 2-remainder 1))))
3628 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3630 ;; Get the correct mmr-glyphs.
3631 ;; Store them in a list.
3633 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3634 ;; -> ("rests.M3" "rests.M1")
3635 (define (get-mmr-glyphs lst1 lst2)
3636 (define (helper l1 l2 l3)
3641 (append (make-list (car l1) (car l2)) l3))))
3642 (helper lst1 lst2 '()))
3644 ;; If duration is not valid, print a warning and return empty-stencil
3645 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3646 (not multi-measure-rest))
3647 (and (= (string-length (car (string-split duration #\. ))) 1)
3648 (= (string->number (car (string-split duration #\. ))) 0)))
3650 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3653 ;; For simple rests:
3654 ;; Get a (log dots) list.
3655 (parsed (parse-simple-duration duration))
3656 ;; Create the rest-stencil
3658 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3659 ;; For MultiMeasureRests:
3660 ;; Get the duration-part of duration
3661 (dur-part-string (car (string-split duration #\. )))
3662 ;; Get the duration of MMR:
3663 ;; If not a number (eg. "maxima") calculate it.
3665 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3666 ;; Get a list of the correct number of each mmr-glyph.
3667 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3668 ;; Create a list of mmr-stencils,
3669 ;; translating the glyph for a whole rest.
3673 (let ((single-mmr-stil
3674 (rest-by-number-markup layout props (* -1 x) 0)))
3676 (ly:stencil-translate-axis
3678 ;; Ugh, hard-coded, why 1?
3682 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3683 ;; Adjust the space between the mmr-glyphs,
3684 ;; if not default-glyphs are used.
3685 (word-space (if (member style
3686 '(neomensural mensural petrucci))
3687 (/ (* word-space 2) 3)
3689 ;; Create the final mmr-stencil
3690 ;; via `stack-stencil-line´ from /scm/markup.scm
3691 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3693 ;; Print the number above a multi-measure-rest
3694 ;; Depends on duration, style and multi-measure-rest-number set #t
3695 (if (and multi-measure-rest
3696 multi-measure-rest-number
3698 (not (member style '(neomensural mensural petrucci))))
3699 (let* ((mmr-stil-x-center
3700 (interval-center (ly:stencil-extent mmr-stil X)))
3704 #:override '(font-encoding . fetaText)
3705 (number->string mmr-duration)))
3707 (interpret-markup layout props duration-markup))
3708 (mmr-number-stil-x-center
3709 (interval-center (ly:stencil-extent mmr-number-stil X))))
3711 (set! mmr-stil (ly:stencil-combine-at-edge
3714 (ly:stencil-translate-axis
3716 (- mmr-stil-x-center mmr-number-stil-x-center)
3720 (if multi-measure-rest
3724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3728 (define-markup-command (lower layout props amount arg)
3732 @cindex lowering text
3734 Lower @var{arg} by the distance @var{amount}.
3735 A negative @var{amount} indicates raising; see also @code{\\raise}.
3737 @lilypond[verbatim,quote]
3745 (ly:stencil-translate-axis (interpret-markup layout props arg)
3748 (define-markup-command (translate-scaled layout props offset arg)
3749 (number-pair? markup?)
3751 #:properties ((font-size 0))
3753 @cindex translating text
3754 @cindex scaling text
3756 Translate @var{arg} by @var{offset}, scaling the offset by the
3759 @lilypond[verbatim,quote]
3762 * \\translate #'(2 . 3) translate
3764 * \\translate-scaled #'(2 . 3) translate-scaled
3768 (let* ((factor (magstep font-size))
3769 (scaled (cons (* factor (car offset))
3770 (* factor (cdr offset)))))
3771 (ly:stencil-translate (interpret-markup layout props arg)
3774 (define-markup-command (raise layout props amount arg)
3778 @cindex raising text
3780 Raise @var{arg} by the distance @var{amount}.
3781 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3783 The argument to @code{\\raise} is the vertical displacement amount,
3784 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3785 raise objects in relation to their surrounding markups.
3787 If the text object itself is positioned above or below the staff, then
3788 @code{\\raise} cannot be used to move it, since the mechanism that
3789 positions it next to the staff cancels any shift made with
3790 @code{\\raise}. For vertical positioning, use the @code{padding}
3791 and/or @code{extra-offset} properties.
3793 @lilypond[verbatim,quote]
3802 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3804 (define-markup-command (fraction layout props arg1 arg2)
3807 #:properties ((font-size 0))
3809 @cindex creating text fractions
3811 Make a fraction of two markups.
3812 @lilypond[verbatim,quote]
3818 (let* ((m1 (interpret-markup layout props arg1))
3819 (m2 (interpret-markup layout props arg2))
3820 (factor (magstep font-size))
3821 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3822 (padding (* factor 0.2))
3823 (baseline (* factor 0.6))
3824 (offset (* factor 0.75)))
3825 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3826 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3827 (let* ((x1 (ly:stencil-extent m1 X))
3828 (x2 (ly:stencil-extent m2 X))
3829 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3830 ;; should stack mols separately, to maintain LINE on baseline
3831 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3833 (ly:stencil-aligned-to stack Y CENTER))
3835 (ly:stencil-aligned-to stack X LEFT))
3836 ;; should have EX dimension
3838 (ly:stencil-translate-axis stack offset Y))))
3840 (define-markup-command (normal-size-super layout props arg)
3843 #:properties ((baseline-skip))
3845 @cindex setting superscript in standard font size
3847 Set @var{arg} in superscript with a normal font size.
3849 @lilypond[verbatim,quote]
3852 \\normal-size-super {
3853 superscript in standard size
3857 (ly:stencil-translate-axis
3858 (interpret-markup layout props arg)
3859 (* 0.5 baseline-skip) Y))
3861 (define-markup-command (super layout props arg)
3864 #:properties ((font-size 0)
3867 @cindex superscript text
3869 Set @var{arg} in superscript.
3871 @lilypond[verbatim,quote]
3881 (ly:stencil-translate-axis
3884 (cons `((font-size . ,(- font-size 3))) props)
3886 (* 0.5 baseline-skip)
3889 (define-markup-command (translate layout props offset arg)
3890 (number-pair? markup?)
3893 @cindex translating text
3895 Translate @var{arg} relative to its surroundings. @var{offset}
3896 is a pair of numbers representing the displacement in the X and Y axis.
3898 @lilypond[verbatim,quote]
3901 \\translate #'(2 . 3)
3902 \\line { translated two spaces right, three up }
3905 (ly:stencil-translate (interpret-markup layout props arg)
3908 (define-markup-command (sub layout props arg)
3911 #:properties ((font-size 0)
3914 @cindex subscript text
3916 Set @var{arg} in subscript.
3918 @lilypond[verbatim,quote]
3929 (ly:stencil-translate-axis
3932 (cons `((font-size . ,(- font-size 3))) props)
3934 (* -0.5 baseline-skip)
3937 (define-markup-command (normal-size-sub layout props arg)
3940 #:properties ((baseline-skip))
3942 @cindex setting subscript in standard font size
3944 Set @var{arg} in subscript with a normal font size.
3946 @lilypond[verbatim,quote]
3950 subscript in standard size
3954 (ly:stencil-translate-axis
3955 (interpret-markup layout props arg)
3956 (* -0.5 baseline-skip)
3959 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3961 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3963 (define-markup-command (hbracket layout props arg)
3967 @cindex placing horizontal brackets around text
3969 Draw horizontal brackets around @var{arg}.
3971 @lilypond[verbatim,quote]
3980 (let ((th 0.1) ;; todo: take from GROB.
3981 (m (interpret-markup layout props arg)))
3982 (bracketify-stencil m X th (* 2.5 th) th)))
3984 (define-markup-command (bracket layout props arg)
3988 @cindex placing vertical brackets around text
3990 Draw vertical brackets around @var{arg}.
3992 @lilypond[verbatim,quote]
3999 (let ((th 0.1) ;; todo: take from GROB.
4000 (m (interpret-markup layout props arg)))
4001 (bracketify-stencil m Y th (* 2.5 th) th)))
4003 (define-markup-command (parenthesize layout props arg)
4006 #:properties ((angularity 0)
4012 @cindex placing parentheses around text
4014 Draw parentheses around @var{arg}. This is useful for parenthesizing
4015 a column containing several lines of text.
4017 @lilypond[verbatim,quote]
4026 \\override #'(angularity . 2) {
4037 (let* ((markup (interpret-markup layout props arg))
4038 (scaled-width (* size width))
4040 (* (chain-assoc-get 'line-thickness props 0.1)
4043 (min (* size 0.5 scaled-thickness)
4044 (* (/ 4 3.0) scaled-width)))
4045 (padding (chain-assoc-get 'padding props half-thickness)))
4046 (parenthesize-stencil
4047 markup half-thickness scaled-width angularity padding)))
4050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4051 ;; Delayed markup evaluation
4052 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4054 (define-markup-command (page-ref layout props label gauge default)
4055 (symbol? markup? markup?)
4058 @cindex referencing page numbers in text
4060 Reference to a page number. @var{label} is the label set on the referenced
4061 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4062 the maximum width of the page number, and @var{default} the value to display
4063 when @var{label} is not found."
4064 (let* ((gauge-stencil (interpret-markup layout props gauge))
4065 (x-ext (ly:stencil-extent gauge-stencil X))
4066 (y-ext (ly:stencil-extent gauge-stencil Y)))
4068 `(delay-stencil-evaluation
4069 ,(delay (ly:stencil-expr
4070 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4071 (page-number (if (list? table)
4072 (assoc-get label table)
4074 (page-markup (if page-number (format #f "~a" page-number) default))
4075 (page-stencil (interpret-markup layout props page-markup))
4076 (gap (- (interval-length x-ext)
4077 (interval-length (ly:stencil-extent page-stencil X)))))
4078 (interpret-markup layout props
4079 (markup #:concat (#:hspace gap page-markup)))))))
4083 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4087 (define-markup-command (scale layout props factor-pair arg)
4088 (number-pair? markup?)
4091 @cindex scaling markup
4092 @cindex mirroring markup
4094 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4095 representing the scaling-factor in the X and Y axes.
4096 Negative values may be used to produce mirror images.
4098 @lilypond[verbatim,quote]
4108 (let ((stil (interpret-markup layout props arg))
4109 (sx (car factor-pair))
4110 (sy (cdr factor-pair)))
4111 (ly:stencil-scale stil sx sy)))
4113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4115 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4117 (define-markup-command (pattern layout props count axis space pattern)
4118 (integer? integer? number? markup?)
4121 Prints @var{count} times a @var{pattern} markup.
4122 Patterns are spaced apart by @var{space}.
4123 Patterns are distributed on @var{axis}.
4125 @lilypond[verbatim, quote]
4127 \"Horizontally repeated :\"
4128 \\pattern #7 #X #2 \\flat
4130 \"Vertically repeated :\"
4131 \\pattern #3 #Y #0.5 \\flat
4134 (let ((pattern-width (interval-length
4135 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4136 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4137 (let loop ((i (1- count)) (patterns (markup)))
4143 (markup patterns pattern)
4144 (markup #:column (patterns pattern))))
4147 (markup patterns pattern #:hspace space)
4148 (markup #:column (patterns pattern #:vspace space))))))))
4150 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4151 (number? ly:dir? markup? markup? markup?)
4153 #:properties ((word-space)
4156 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4157 with a line of markups @var{pattern} in between.
4158 Patterns are spaced apart by @var{space}.
4159 Patterns are aligned to the @var{dir} markup.
4161 @lilypond[verbatim, quote]
4164 \\fill-with-pattern #1 #RIGHT . first right
4165 \\fill-with-pattern #1 #RIGHT . second right
4167 \"center-aligned :\"
4168 \\fill-with-pattern #1.5 #CENTER - left right
4171 \\override #'(line-width . 50)
4172 \\fill-with-pattern #2 #LEFT : left first
4173 \\override #'(line-width . 50)
4174 \\fill-with-pattern #2 #LEFT : left second
4177 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4178 (pattern-width (interval-length pattern-x-extent))
4179 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4180 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4181 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4182 (period (+ space pattern-width))
4183 (count (truncate (/ (- middle-width pattern-width) period)))
4184 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4185 (interpret-markup layout props
4187 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4188 #:translate (cons x-offset 0)
4189 #:pattern (1+ count) X space pattern
4192 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4196 (define-markup-command (replace layout props replacements arg)
4200 Used to automatically replace a string by another in the markup @var{arg}.
4201 Each pair of the alist @var{replacements} specifies what should be replaced.
4202 The @code{key} is the string to be replaced by the @code{value} string.
4204 @lilypond[verbatim, quote]
4205 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4209 (internal-add-text-replacements
4214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4215 ;; Markup list commands
4216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4218 (define-public (space-lines baseline stils)
4219 (let space-stil ((stils stils)
4223 (let* ((stil (car stils))
4224 (dy-top (max (- (/ baseline 1.5)
4225 (interval-bound (ly:stencil-extent stil Y) UP))
4227 (dy-bottom (max (+ (/ baseline 3.0)
4228 (interval-bound (ly:stencil-extent stil Y) DOWN))
4230 (new-stil (ly:make-stencil
4231 (ly:stencil-expr stil)
4232 (ly:stencil-extent stil X)
4233 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4235 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4237 (space-stil (cdr stils) (cons new-stil result))))))
4239 (define-markup-list-command (justified-lines layout props args)
4241 #:properties ((baseline-skip)
4242 wordwrap-internal-markup-list)
4244 @cindex justifying lines of text
4246 Like @code{\\justify}, but return a list of lines instead of a single markup.
4247 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4248 @var{X}@tie{}is the number of staff spaces."
4249 (space-lines baseline-skip
4250 (interpret-markup-list layout props
4251 (make-wordwrap-internal-markup-list #t args))))
4253 (define-markup-list-command (wordwrap-lines layout props args)
4255 #:properties ((baseline-skip)
4256 wordwrap-internal-markup-list)
4257 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4258 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4259 where @var{X} is the number of staff spaces."
4260 (space-lines baseline-skip
4261 (interpret-markup-list layout props
4262 (make-wordwrap-internal-markup-list #f args))))
4264 (define-markup-list-command (column-lines layout props args)
4266 #:properties ((baseline-skip))
4267 "Like @code{\\column}, but return a list of lines instead of a single markup.
4268 @code{baseline-skip} determines the space between each markup in @var{args}."
4269 (space-lines baseline-skip
4270 (interpret-markup-list layout props args)))
4272 (define-markup-list-command (override-lines layout props new-prop args)
4273 (pair? markup-list?)
4274 "Like @code{\\override}, for markup lists."
4275 (interpret-markup-list layout (cons (list new-prop) props) args))