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)
1311 (make-override-lines-markup-list
1313 (chain-assoc-get 'word-space props))
1314 (if (markup-command-list? args)
1316 (concat-string-args args))))))
1318 (define (wordwrap-stencils stencils
1319 justify base-space line-width text-dir)
1320 "Perform simple wordwrap, return stencil of each line."
1321 (define space (if justify
1322 ;; justify only stretches lines.
1325 (define (take-list width space stencils
1326 accumulator accumulated-width)
1327 "Return (head-list . tail) pair, with head-list fitting into width"
1328 (if (null? stencils)
1329 (cons accumulator stencils)
1330 (let* ((first (car stencils))
1331 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1332 (newwid (+ space first-wid accumulated-width)))
1333 (if (or (null? accumulator)
1335 (take-list width space
1337 (cons first accumulator)
1339 (cons accumulator stencils)))))
1340 (let loop ((lines '())
1342 (let* ((line-break (take-list line-width space todo
1344 (line-stencils (car line-break))
1345 (space-left (- line-width
1346 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1348 (line-word-space (cond ((not justify) space)
1349 ;; don't stretch last line of paragraph.
1350 ;; hmmm . bug - will overstretch the last line in some case.
1351 ((null? (cdr line-break))
1353 ((null? line-stencils) 0.0)
1354 ((null? (cdr line-stencils)) 0.0)
1355 (else (/ space-left (1- (length line-stencils))))))
1356 (line (stack-stencil-line line-word-space
1357 (if (= text-dir RIGHT)
1358 (reverse line-stencils)
1360 (if (pair? (cdr line-break))
1361 (loop (cons line lines)
1364 (if (= text-dir LEFT)
1366 (ly:stencil-translate-axis
1368 (- line-width (interval-end (ly:stencil-extent line X)))
1370 (reverse (cons line lines)))))))
1372 (define-markup-list-command (wordwrap-internal layout props justify args)
1373 (boolean? markup-list?)
1374 #:properties ((line-width #f)
1376 (text-direction RIGHT))
1377 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1378 (wordwrap-stencils (remove ly:stencil-empty?
1379 (interpret-markup-list layout props args))
1383 (ly:output-def-lookup layout 'line-width))
1386 (define-markup-command (justify layout props args)
1389 #:properties ((baseline-skip)
1390 wordwrap-internal-markup-list)
1392 @cindex justifying text
1394 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1395 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1396 @var{X}@tie{}is the number of staff spaces.
1398 @lilypond[verbatim,quote]
1401 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1402 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1403 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1404 laboris nisi ut aliquip ex ea commodo consequat.
1408 (stack-lines DOWN 0.0 baseline-skip
1409 (wordwrap-internal-markup-list layout props #t args)))
1411 (define-markup-command (wordwrap layout props args)
1414 #:properties ((baseline-skip)
1415 wordwrap-internal-markup-list)
1416 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1417 the line width, where @var{X} is the number of staff spaces.
1419 @lilypond[verbatim,quote]
1422 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1423 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1424 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1425 laboris nisi ut aliquip ex ea commodo consequat.
1429 (stack-lines DOWN 0.0 baseline-skip
1430 (wordwrap-internal-markup-list layout props #f args)))
1432 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1434 #:properties ((line-width)
1436 (text-direction RIGHT))
1437 "Internal markup list command used to define @code{\\justify-string} and
1438 @code{\\wordwrap-string}."
1439 (let* ((para-strings (regexp-split
1440 (string-regexp-substitute
1442 (string-regexp-substitute "\r\n" "\n" arg))
1443 "\n[ \t\n]*\n[ \t\n]*"))
1444 (list-para-words (map (lambda (str)
1445 (regexp-split str "[ \t\n]+"))
1447 (para-lines (map (lambda (words)
1449 (remove ly:stencil-empty?
1451 (interpret-markup layout props x))
1453 (wordwrap-stencils stencils
1455 line-width text-direction)))
1457 (apply append para-lines)))
1459 (define-markup-command (wordwrap-string layout props arg)
1462 #:properties ((baseline-skip)
1463 wordwrap-string-internal-markup-list)
1464 "Wordwrap a string. Paragraphs may be separated with double newlines.
1466 @lilypond[verbatim,quote]
1468 \\override #'(line-width . 40)
1469 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1470 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1471 et dolore magna aliqua.
1474 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1475 laboris nisi ut aliquip ex ea commodo consequat.
1478 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1479 qui officia deserunt mollit anim id est laborum\"
1482 (stack-lines DOWN 0.0 baseline-skip
1483 (wordwrap-string-internal-markup-list layout props #f arg)))
1485 (define-markup-command (justify-string layout props arg)
1488 #:properties ((baseline-skip)
1489 wordwrap-string-internal-markup-list)
1490 "Justify a string. Paragraphs may be separated with double newlines
1492 @lilypond[verbatim,quote]
1494 \\override #'(line-width . 40)
1495 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1496 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1497 et dolore magna aliqua.
1500 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1501 laboris nisi ut aliquip ex ea commodo consequat.
1504 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1505 qui officia deserunt mollit anim id est laborum\"
1508 (stack-lines DOWN 0.0 baseline-skip
1509 (wordwrap-string-internal-markup-list layout props #t arg)))
1511 (define-markup-command (wordwrap-field layout props symbol)
1514 "Wordwrap the data which has been assigned to @var{symbol}.
1516 @lilypond[verbatim,quote]
1518 title = \"My title\"
1519 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1520 elit, sed do eiusmod tempor incididunt ut labore et dolore
1521 magna aliqua. Ut enim ad minim veniam, quis nostrud
1522 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1527 bookTitleMarkup = \\markup {
1529 \\fill-line { \\fromproperty #'header:title }
1531 \\wordwrap-field #'header:myText
1540 (let* ((m (chain-assoc-get symbol props)))
1542 (wordwrap-string-markup layout props m)
1545 (define-markup-command (justify-field layout props symbol)
1548 "Justify the data which has been assigned to @var{symbol}.
1550 @lilypond[verbatim,quote]
1552 title = \"My title\"
1553 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1554 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1555 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1556 laboris nisi ut aliquip ex ea commodo consequat.\"
1560 bookTitleMarkup = \\markup {
1562 \\fill-line { \\fromproperty #'header:title }
1564 \\justify-field #'header:myText
1573 (let* ((m (chain-assoc-get symbol props)))
1575 (justify-string-markup layout props m)
1578 (define-markup-command (combine layout props arg1 arg2)
1582 @cindex merging text
1584 Print two markups on top of each other.
1586 Note: @code{\\combine} cannot take a list of markups enclosed in
1587 curly braces as an argument; the follow example will not compile:
1590 \\combine @{ a list @}
1593 @lilypond[verbatim,quote]
1596 \\override #'(thickness . 2)
1598 \\draw-line #'(0 . 4)
1599 \\arrow-head #Y #DOWN ##f
1602 (let* ((s1 (interpret-markup layout props arg1))
1603 (s2 (interpret-markup layout props arg2)))
1604 (ly:stencil-add s1 s2)))
1607 ;; TODO: should extract baseline-skip from each argument somehow..
1609 (define-markup-command (column layout props args)
1612 #:properties ((baseline-skip))
1614 @cindex stacking text in a column
1616 Stack the markups in @var{args} vertically. The property
1617 @code{baseline-skip} determines the space between markups
1620 @lilypond[verbatim,quote]
1629 (let ((arg-stencils (interpret-markup-list layout props args)))
1630 (stack-lines -1 0.0 baseline-skip
1631 (remove ly:stencil-empty? arg-stencils))))
1633 (define-markup-command (dir-column layout props args)
1636 #:properties ((direction)
1639 @cindex changing direction of text columns
1641 Make a column of @var{args}, going up or down, depending on the
1642 setting of the @code{direction} layout property.
1644 @lilypond[verbatim,quote]
1646 \\override #`(direction . ,UP) {
1656 \\override #'(direction . 1) {
1663 (stack-lines (if (number? direction) direction -1)
1666 (interpret-markup-list layout props args)))
1668 (define (general-column align-dir baseline mols)
1669 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1671 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1672 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1673 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1674 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1676 (define-markup-command (center-column layout props args)
1679 #:properties ((baseline-skip))
1681 @cindex centering a column of text
1683 Put @code{args} in a centered column.
1685 @lilypond[verbatim,quote]
1694 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1696 (define-markup-command (left-column layout props args)
1699 #:properties ((baseline-skip))
1701 @cindex text columns, left-aligned
1703 Put @code{args} in a left-aligned column.
1705 @lilypond[verbatim,quote]
1714 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1716 (define-markup-command (right-column layout props args)
1719 #:properties ((baseline-skip))
1721 @cindex text columns, right-aligned
1723 Put @code{args} in a right-aligned column.
1725 @lilypond[verbatim,quote]
1734 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1736 (define-markup-command (vcenter layout props arg)
1740 @cindex vertically centering text
1742 Align @code{arg} to its Y@tie{}center.
1744 @lilypond[verbatim,quote]
1752 (let* ((mol (interpret-markup layout props arg)))
1753 (ly:stencil-aligned-to mol Y CENTER)))
1755 (define-markup-command (center-align layout props arg)
1759 @cindex horizontally centering text
1761 Align @code{arg} to its X@tie{}center.
1763 @lilypond[verbatim,quote]
1773 (let* ((mol (interpret-markup layout props arg)))
1774 (ly:stencil-aligned-to mol X CENTER)))
1776 (define-markup-command (right-align layout props arg)
1780 @cindex right aligning text
1782 Align @var{arg} on its right edge.
1784 @lilypond[verbatim,quote]
1794 (let* ((m (interpret-markup layout props arg)))
1795 (ly:stencil-aligned-to m X RIGHT)))
1797 (define-markup-command (left-align layout props arg)
1801 @cindex left aligning text
1803 Align @var{arg} on its left edge.
1805 @lilypond[verbatim,quote]
1815 (let* ((m (interpret-markup layout props arg)))
1816 (ly:stencil-aligned-to m X LEFT)))
1818 (define-markup-command (general-align layout props axis dir arg)
1819 (integer? number? markup?)
1822 @cindex controlling general text alignment
1824 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1826 @lilypond[verbatim,quote]
1830 \\general-align #X #LEFT
1835 \\general-align #X #CENTER
1841 \\general-align #Y #UP
1848 \\general-align #Y #3.2
1855 (let* ((m (interpret-markup layout props arg)))
1856 (ly:stencil-aligned-to m axis dir)))
1858 (define-markup-command (halign layout props dir arg)
1862 @cindex setting horizontal text alignment
1864 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1865 left-aligned, while @code{+1} is right. Values in between interpolate
1866 alignment accordingly.
1868 @lilypond[verbatim,quote]
1893 (let* ((m (interpret-markup layout props arg)))
1894 (ly:stencil-aligned-to m X dir)))
1896 (define-markup-command (with-dimensions layout props x y arg)
1897 (number-pair? number-pair? markup?)
1900 @cindex setting extent of text objects
1902 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1903 (let* ((m (interpret-markup layout props arg)))
1904 (ly:make-stencil (ly:stencil-expr m) x y)))
1906 (define-markup-command (pad-around layout props amount arg)
1909 "Add padding @var{amount} all around @var{arg}.
1911 @lilypond[verbatim,quote]
1924 (let* ((m (interpret-markup layout props arg))
1925 (x (ly:stencil-extent m X))
1926 (y (ly:stencil-extent m Y)))
1927 (ly:make-stencil (ly:stencil-expr m)
1928 (interval-widen x amount)
1929 (interval-widen y amount))))
1931 (define-markup-command (pad-x layout props amount arg)
1935 @cindex padding text horizontally
1937 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1939 @lilypond[verbatim,quote]
1952 (let* ((m (interpret-markup layout props arg))
1953 (x (ly:stencil-extent m X))
1954 (y (ly:stencil-extent m Y)))
1955 (ly:make-stencil (ly:stencil-expr m)
1956 (interval-widen x amount)
1959 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1960 (integer? ly:dir? markup? markup?)
1962 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1963 (let ((m1 (interpret-markup layout props arg1))
1964 (m2 (interpret-markup layout props arg2)))
1965 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1967 (define-markup-command (transparent layout props arg)
1970 "Make @var{arg} transparent.
1972 @lilypond[verbatim,quote]
1979 (let* ((m (interpret-markup layout props arg))
1980 (x (ly:stencil-extent m X))
1981 (y (ly:stencil-extent m Y)))
1982 (ly:make-stencil "" x y)))
1984 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1985 (number-pair? number-pair? markup?)
1987 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1989 @lilypond[verbatim,quote]
1996 \\pad-to-box #'(0 . 10) #'(0 . 3) {
2002 (let* ((m (interpret-markup layout props arg))
2003 (x (ly:stencil-extent m X))
2004 (y (ly:stencil-extent m Y)))
2005 (ly:make-stencil (ly:stencil-expr m)
2006 (interval-union x-ext x)
2007 (interval-union y-ext y))))
2009 (define-markup-command (hcenter-in layout props length arg)
2012 "Center @var{arg} horizontally within a box of extending
2013 @var{length}/2 to the left and right.
2015 @lilypond[quote,verbatim]
2018 \\set Staff.instrumentName = \\markup {
2025 \\set Staff.instrumentName = \\markup {
2034 (interpret-markup layout props
2035 (make-pad-to-box-markup
2036 (cons (/ length -2) (/ length 2))
2038 (make-center-align-markup arg))))
2040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2044 (define-markup-command (property-recursive layout props symbol)
2047 "Print out a warning when a header field markup contains some recursive
2049 (ly:warning "Recursive definition of property ~a detected!" symbol)
2052 (define-markup-command (fromproperty layout props symbol)
2055 "Read the @var{symbol} from property settings, and produce a stencil
2056 from the markup contained within. If @var{symbol} is not defined, it
2057 returns an empty markup.
2059 @lilypond[verbatim,quote]
2061 myTitle = \"myTitle\"
2065 \\fromproperty #'header:myTitle
2072 (let ((m (chain-assoc-get symbol props)))
2074 ;; prevent infinite loops by clearing the interpreted property:
2075 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
2078 (define-markup-command (on-the-fly layout props procedure arg)
2079 (procedure? markup?)
2081 "Apply the @var{procedure} markup command to @var{arg}.
2082 @var{procedure} should take a single argument."
2083 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
2084 (set-object-property! anonymous-with-signature
2087 (interpret-markup layout props (list anonymous-with-signature arg))))
2089 (define-markup-command (footnote layout props mkup note)
2092 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2094 @lilypond[verbatim,quote]
2097 \\override #'(padding . 0.2)
2101 The footnote will not be annotated automatically."
2102 (ly:stencil-combine-at-edge
2103 (interpret-markup layout props mkup)
2107 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
2112 (define-markup-command (auto-footnote layout props mkup note)
2115 #:properties ((raise 0.5)
2117 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
2119 @lilypond[verbatim,quote]
2122 \\override #'(padding . 0.2)
2126 The footnote will be annotated automatically."
2127 (let* ((markup-stencil (interpret-markup layout props mkup))
2128 (footnote-hash (gensym "footnote"))
2130 (gauge-stencil (interpret-markup
2133 ((ly:output-def-lookup
2135 'footnote-numbering-function)
2137 (x-ext (ly:stencil-extent gauge-stencil X))
2138 (y-ext (ly:stencil-extent gauge-stencil Y))
2140 `(delay-stencil-evaluation
2144 (ly:output-def-lookup layout
2145 'number-footnote-table))
2146 (footnote-stencil (if (list? table)
2147 (assoc-get footnote-hash
2150 (footnote-stencil (if (ly:stencil? footnote-stencil)
2153 (ly:programming-error
2154 "Cannot find correct footnote for a markup object.")
2156 (gap (- (interval-length x-ext)
2158 (ly:stencil-extent footnote-stencil X))))
2159 (y-trans (- (+ (cdr y-ext)
2161 (cdr (ly:stencil-extent footnote-stencil
2163 (ly:stencil-translate footnote-stencil
2164 (cons gap y-trans)))))))
2165 (main-stencil (ly:stencil-combine-at-edge
2169 (ly:make-stencil footnote-number x-ext y-ext)
2174 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2178 (define-markup-command (override layout props new-prop arg)
2182 @cindex overriding properties within text markup
2184 Add the argument @var{new-prop} to the property list. Properties
2185 may be any property supported by @rinternals{font-interface},
2186 @rinternals{text-interface} and
2187 @rinternals{instrument-specific-markup-interface}.
2189 @lilypond[verbatim,quote]
2197 \\override #'(baseline-skip . 4) {
2206 (interpret-markup layout (cons (list new-prop) props) arg))
2208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2212 (define-markup-command (verbatim-file layout props name)
2215 "Read the contents of file @var{name}, and include it verbatim.
2217 @lilypond[verbatim,quote]
2219 \\verbatim-file #\"simple.ly\"
2222 (interpret-markup layout props
2223 (if (ly:get-option 'safe)
2224 "verbatim-file disabled in safe mode"
2225 (let* ((str (ly:gulp-file name))
2226 (lines (string-split str #\nl)))
2227 (make-typewriter-markup
2228 (make-column-markup lines))))))
2230 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2235 (define-markup-command (smaller layout props arg)
2238 "Decrease the font size relative to the current setting.
2240 @lilypond[verbatim,quote]
2253 (interpret-markup layout props
2254 `(,fontsize-markup -1 ,arg)))
2256 (define-markup-command (larger layout props arg)
2259 "Increase the font size relative to the current setting.
2261 @lilypond[verbatim,quote]
2269 (interpret-markup layout props
2270 `(,fontsize-markup 1 ,arg)))
2272 (define-markup-command (finger layout props arg)
2275 "Set @var{arg} as small numbers.
2277 @lilypond[verbatim,quote]
2284 (interpret-markup layout
2285 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2288 (define-markup-command (abs-fontsize layout props size arg)
2291 "Use @var{size} as the absolute font size to display @var{arg}.
2292 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2294 @lilypond[verbatim,quote]
2296 default text font size
2298 \\abs-fontsize #16 { text font size 16 }
2300 \\abs-fontsize #12 { text font size 12 }
2303 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2304 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2305 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2306 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2307 (magnification (/ size ref-size)))
2311 `((baseline-skip . ,(* magnification ref-baseline))
2312 (word-space . ,(* magnification ref-word-space))
2313 (font-size . ,(magnification->font-size magnification)))
2317 (define-markup-command (fontsize layout props increment arg)
2320 #:properties ((font-size 0)
2323 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2326 @lilypond[verbatim,quote]
2337 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2338 (word-space . ,(* word-space (magstep increment)))
2339 (font-size . ,(+ font-size increment)))
2343 (define-markup-command (magnify layout props sz arg)
2347 @cindex magnifying text
2349 Set the font magnification for its argument. In the following
2350 example, the middle@tie{}A is 10% larger:
2353 A \\magnify #1.1 @{ A @} A
2356 Note: Magnification only works if a font name is explicitly selected.
2357 Use @code{\\fontsize} otherwise.
2359 @lilypond[verbatim,quote]
2370 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2373 (define-markup-command (bold layout props arg)
2376 "Switch to bold font-series.
2378 @lilypond[verbatim,quote]
2386 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2388 (define-markup-command (sans layout props arg)
2391 "Switch to the sans serif font family.
2393 @lilypond[verbatim,quote]
2402 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2404 (define-markup-command (number layout props arg)
2407 "Set font family to @code{number}, which yields the font used for
2408 time signatures and fingerings. This font contains numbers and
2409 some punctuation; it has no letters.
2411 @lilypond[verbatim,quote]
2414 0 1 2 3 4 5 6 7 8 9 . ,
2418 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2420 (define-markup-command (roman layout props arg)
2423 "Set font family to @code{roman}.
2425 @lilypond[verbatim,quote]
2431 text in roman font family
2438 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2440 (define-markup-command (huge layout props arg)
2443 "Set font size to +2.
2445 @lilypond[verbatim,quote]
2453 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2455 (define-markup-command (large layout props arg)
2458 "Set font size to +1.
2460 @lilypond[verbatim,quote]
2468 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2470 (define-markup-command (normalsize layout props arg)
2473 "Set font size to default.
2475 @lilypond[verbatim,quote]
2488 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2490 (define-markup-command (small layout props arg)
2493 "Set font size to -1.
2495 @lilypond[verbatim,quote]
2503 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2505 (define-markup-command (tiny layout props arg)
2508 "Set font size to -2.
2510 @lilypond[verbatim,quote]
2518 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2520 (define-markup-command (teeny layout props arg)
2523 "Set font size to -3.
2525 @lilypond[verbatim,quote]
2533 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2535 (define-markup-command (fontCaps layout props arg)
2538 "Set @code{font-shape} to @code{caps}
2540 Note: @code{\\fontCaps} requires the installation and selection of
2541 fonts which support the @code{caps} font shape."
2542 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2545 (define-markup-command (smallCaps layout props arg)
2548 "Emit @var{arg} as small caps.
2550 Note: @code{\\smallCaps} does not support accented characters.
2552 @lilypond[verbatim,quote]
2561 (define (char-list->markup chars lower)
2562 (let ((final-string (string-upcase (reverse-list->string chars))))
2564 (markup #:fontsize -2 final-string)
2566 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2567 (if (null? rest-chars)
2569 (reverse! (cons (char-list->markup currents current-is-lower)
2571 (let* ((ch (car rest-chars))
2572 (is-lower (char-lower-case? ch)))
2573 (if (or (and current-is-lower is-lower)
2574 (and (not current-is-lower) (not is-lower)))
2575 (make-small-caps (cdr rest-chars)
2579 (make-small-caps (cdr rest-chars)
2582 (if (null? currents)
2584 (cons (char-list->markup
2585 currents current-is-lower)
2587 (interpret-markup layout props
2589 (make-small-caps (string->list arg) (list) #f (list))
2592 (define-markup-command (caps layout props arg)
2595 "Copy of the @code{\\smallCaps} command.
2597 @lilypond[verbatim,quote]
2606 (interpret-markup layout props (make-smallCaps-markup arg)))
2608 (define-markup-command (dynamic layout props arg)
2611 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2612 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2613 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2614 done in a different font. The recommended font for this is bold and italic.
2615 @lilypond[verbatim,quote]
2623 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2625 (define-markup-command (text layout props arg)
2628 "Use a text font instead of music symbol or music alphabet font.
2630 @lilypond[verbatim,quote]
2643 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2646 (define-markup-command (italic layout props arg)
2649 "Use italic @code{font-shape} for @var{arg}.
2651 @lilypond[verbatim,quote]
2659 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2661 (define-markup-command (typewriter layout props arg)
2664 "Use @code{font-family} typewriter for @var{arg}.
2666 @lilypond[verbatim,quote]
2675 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2677 (define-markup-command (upright layout props arg)
2680 "Set @code{font-shape} to @code{upright}. This is the opposite
2683 @lilypond[verbatim,quote]
2697 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2699 (define-markup-command (medium layout props arg)
2702 "Switch to medium font-series (in contrast to bold).
2704 @lilypond[verbatim,quote]
2717 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2720 (define-markup-command (normal-text layout props arg)
2723 "Set all font related properties (except the size) to get the default
2724 normal text font, no matter what font was used earlier.
2726 @lilypond[verbatim,quote]
2728 \\huge \\bold \\sans \\caps {
2740 (interpret-markup layout
2741 (cons '((font-family . roman) (font-shape . upright)
2742 (font-series . medium) (font-encoding . latin1))
2746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2748 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2750 (define-markup-command (musicglyph layout props glyph-name)
2753 "@var{glyph-name} is converted to a musical symbol; for example,
2754 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2755 the music font. See @ruser{The Feta font} for a complete listing of
2756 the possible glyphs.
2758 @lilypond[verbatim,quote]
2761 \\musicglyph #\"rests.2\"
2762 \\musicglyph #\"clefs.G_change\"
2765 (let* ((font (ly:paper-get-font layout
2766 (cons '((font-encoding . fetaMusic)
2770 (glyph (ly:font-get-glyph font glyph-name)))
2771 (if (null? (ly:stencil-expr glyph))
2772 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2776 (define-markup-command (doublesharp layout props)
2779 "Draw a double sharp symbol.
2781 @lilypond[verbatim,quote]
2786 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2788 (define-markup-command (sesquisharp layout props)
2791 "Draw a 3/2 sharp symbol.
2793 @lilypond[verbatim,quote]
2798 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2800 (define-markup-command (sharp layout props)
2803 "Draw a sharp symbol.
2805 @lilypond[verbatim,quote]
2810 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2812 (define-markup-command (semisharp layout props)
2815 "Draw a semisharp symbol.
2817 @lilypond[verbatim,quote]
2822 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2824 (define-markup-command (natural layout props)
2827 "Draw a natural symbol.
2829 @lilypond[verbatim,quote]
2834 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2836 (define-markup-command (semiflat layout props)
2839 "Draw a semiflat symbol.
2841 @lilypond[verbatim,quote]
2846 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2848 (define-markup-command (flat layout props)
2851 "Draw a flat symbol.
2853 @lilypond[verbatim,quote]
2858 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2860 (define-markup-command (sesquiflat layout props)
2863 "Draw a 3/2 flat symbol.
2865 @lilypond[verbatim,quote]
2870 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2872 (define-markup-command (doubleflat layout props)
2875 "Draw a double flat symbol.
2877 @lilypond[verbatim,quote]
2882 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2884 (define-markup-command (with-color layout props color arg)
2888 @cindex coloring text
2890 Draw @var{arg} in color specified by @var{color}.
2892 @lilypond[verbatim,quote]
2904 (let ((stil (interpret-markup layout props arg)))
2905 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2906 (ly:stencil-extent stil X)
2907 (ly:stencil-extent stil Y))))
2909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2911 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2913 (define-markup-command (arrow-head layout props axis dir filled)
2914 (integer? ly:dir? boolean?)
2916 "Produce an arrow head in specified direction and axis.
2917 Use the filled head if @var{filled} is specified.
2918 @lilypond[verbatim,quote]
2921 \\general-align #Y #DOWN {
2922 \\arrow-head #Y #UP ##t
2923 \\arrow-head #Y #DOWN ##f
2925 \\arrow-head #X #RIGHT ##f
2926 \\arrow-head #X #LEFT ##f
2932 ((name (format #f "arrowheads.~a.~a~a"
2939 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2943 (define-markup-command (lookup layout props glyph-name)
2946 "Lookup a glyph by name.
2948 @lilypond[verbatim,quote]
2950 \\override #'(font-encoding . fetaBraces) {
2951 \\lookup #\"brace200\"
2954 \\lookup #\"brace180\"
2958 (ly:font-get-glyph (ly:paper-get-font layout props)
2961 (define-markup-command (char layout props num)
2964 "Produce a single character. Characters encoded in hexadecimal
2965 format require the prefix @code{#x}.
2967 @lilypond[verbatim,quote]
2969 \\char #65 \\char ##x00a9
2972 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2974 (define number->mark-letter-vector (make-vector 25 #\A))
2979 (if (= i (- (char->integer #\I) (char->integer #\A)))
2981 (vector-set! number->mark-letter-vector j
2982 (integer->char (+ i (char->integer #\A)))))
2984 (define number->mark-alphabet-vector (list->vector
2985 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2987 (define (number->markletter-string vec n)
2988 "Double letters for big marks."
2989 (let* ((lst (vector-length vec)))
2992 (string-append (number->markletter-string vec (1- (quotient n lst)))
2993 (number->markletter-string vec (remainder n lst)))
2994 (make-string 1 (vector-ref vec n)))))
2996 (define-markup-command (markletter layout props num)
2999 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3000 (skipping letter@tie{}I), and continue with double letters.
3002 @lilypond[verbatim,quote]
3009 (ly:text-interface::interpret-markup layout props
3010 (number->markletter-string number->mark-letter-vector num)))
3012 (define-markup-command (markalphabet layout props num)
3015 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
3016 and continue with double letters.
3018 @lilypond[verbatim,quote]
3025 (ly:text-interface::interpret-markup layout props
3026 (number->markletter-string number->mark-alphabet-vector num)))
3028 (define-public (horizontal-slash-interval num forward number-interval mag)
3030 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
3031 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
3032 (else (interval-widen number-interval (* mag 0.25))))
3033 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
3034 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
3035 (else (interval-widen number-interval (* mag 0.25))))
3038 (define-public (adjust-slash-stencil num forward stencil mag)
3041 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3043 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
3045 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
3047 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3050 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
3052 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
3057 (define (slashed-digit-internal layout props num forward font-size thickness)
3058 (let* ((mag (magstep font-size))
3060 (ly:output-def-lookup layout 'line-thickness)
3062 ; backward slashes might use slope and point in the other direction!
3063 (dy (* mag (if forward 0.4 -0.4)))
3064 (number-stencil (interpret-markup layout
3065 (prepend-alist-chain 'font-encoding 'fetaText props)
3066 (number->string num)))
3067 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
3068 (center (interval-center (ly:stencil-extent number-stencil Y)))
3069 ; Use the real extents of the slash, not the whole number, because we
3070 ; might translate the slash later on!
3071 (num-y (interval-widen (cons center center) (abs dy)))
3072 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
3073 (slash-stencil (if is-sane
3074 (make-line-stencil thickness
3075 (car num-x) (- (interval-center num-y) dy)
3076 (cdr num-x) (+ (interval-center num-y) dy))
3078 (if (ly:stencil? slash-stencil)
3080 ; for some numbers we need to shift the slash/backslash up or down to make
3081 ; the slashed digit look better
3082 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
3083 (set! number-stencil
3084 (ly:stencil-add number-stencil slash-stencil)))
3085 (ly:warning "Unable to create slashed digit ~a" num))
3089 (define-markup-command (slashed-digit layout props num)
3092 #:properties ((font-size 0)
3095 @cindex slashed digits
3097 A feta number, with slash. This is for use in the context of
3098 figured bass notation.
3099 @lilypond[verbatim,quote]
3103 \\override #'(thickness . 3)
3107 (slashed-digit-internal layout props num #t font-size thickness))
3109 (define-markup-command (backslashed-digit layout props num)
3112 #:properties ((font-size 0)
3115 @cindex backslashed digits
3117 A feta number, with backslash. This is for use in the context of
3118 figured bass notation.
3119 @lilypond[verbatim,quote]
3121 \\backslashed-digit #5
3123 \\override #'(thickness . 3)
3124 \\backslashed-digit #7
3127 (slashed-digit-internal layout props num #f font-size thickness))
3130 (define eyeglassespath
3131 '((moveto 0.42 0.77)
3132 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3133 (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)
3138 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
3139 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
3140 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
3141 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
3143 (moveto 1.025 0.935)
3144 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
3145 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
3148 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
3151 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
3153 (define-markup-command (eyeglasses layout props)
3156 "Prints out eyeglasses, indicating strongly to look at the conductor.
3157 @lilypond[verbatim,quote]
3158 \\markup { \\eyeglasses }
3160 (interpret-markup layout props
3161 (make-override-markup '(line-cap-style . butt)
3162 (make-path-markup 0.15 eyeglassespath))))
3164 (define-markup-command (left-brace layout props size)
3168 A feta brace in point size @var{size}.
3170 @lilypond[verbatim,quote]
3177 (let* ((font (ly:paper-get-font layout
3178 (cons '((font-encoding . fetaBraces)
3181 (glyph-count (1- (ly:otf-glyph-count font)))
3182 (scale (ly:output-def-lookup layout 'output-scale))
3183 (scaled-size (/ (ly:pt size) scale))
3185 (ly:font-get-glyph font (string-append "brace"
3186 (number->string n)))))
3187 (get-y-from-brace (lambda (brace)
3189 (ly:stencil-extent (glyph brace) Y))))
3190 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3191 (glyph-found (glyph find-brace)))
3193 (if (or (null? (ly:stencil-expr glyph-found))
3194 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3195 (> scaled-size (interval-length
3196 (ly:stencil-extent (glyph glyph-count) Y))))
3198 (ly:warning (_ "no brace found for point size ~S ") size)
3199 (ly:warning (_ "defaulting to ~S pt")
3200 (/ (* scale (interval-length
3201 (ly:stencil-extent glyph-found Y)))
3205 (define-markup-command (right-brace layout props size)
3209 A feta brace in point size @var{size}, rotated 180 degrees.
3211 @lilypond[verbatim,quote]
3218 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3221 ;; the note command.
3222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3224 ;; TODO: better syntax.
3226 (define-markup-command (note-by-number layout props log dot-count dir)
3227 (number? number? number?)
3229 #:properties ((font-size 0)
3233 @cindex notes within text by log and dot-count
3235 Construct a note symbol, with stem and flag. By using fractional values for
3236 @var{dir}, longer or shorter stems can be obtained.
3237 Supports all note-head-styles.
3238 Supported flag-styles are @code{default}, @code{old-straight-flag} and
3239 @code{modern-straight-flag}.
3241 @lilypond[verbatim,quote]
3243 \\note-by-number #3 #0 #DOWN
3245 \\note-by-number #1 #2 #0.8
3248 (define (get-glyph-name-candidates dir log style)
3249 (map (lambda (dir-name)
3250 (format #f "noteheads.~a~a" dir-name
3251 (if (and (symbol? style)
3252 (not (equal? 'default style)))
3253 (select-head-glyph style (min log 2))
3255 (list (if (= dir UP) "u" "d")
3258 (define (get-glyph-name font cands)
3261 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3262 (get-glyph-name font (cdr cands))
3265 (define (buildflags flag-stencil remain curr-stencil spacing)
3266 ;; Function to recursively create a stencil with @code{remain} flags
3267 ;; from the single-flag stencil @code{curr-stencil}, which is already
3268 ;; translated to the position of the previous flag position.
3270 ;; Copy and paste from /scm/flag-styles.scm
3272 (let* ((translated-stencil
3273 (ly:stencil-translate-axis curr-stencil spacing Y))
3274 (new-stencil (ly:stencil-add flag-stencil translated-stencil)))
3275 (buildflags new-stencil (- remain 1) translated-stencil spacing))
3278 (define (straight-flag-mrkp flag-thickness flag-spacing
3279 upflag-angle upflag-length
3280 downflag-angle downflag-length
3282 ;; Create a stencil for a straight flag. @var{flag-thickness} and
3283 ;; @var{flag-spacing} are given in staff spaces, @var{upflag-angle} and
3284 ;; @var{downflag-angle} are given in degrees, and @var{upflag-length} and
3285 ;; @var{downflag-length} are given in staff spaces.
3287 ;; All lengths are scaled according to the font size of the note.
3289 ;; From /scm/flag-styles.scm, modified to fit here.
3291 (let* ((stem-up (> dir 0))
3292 ; scale with the note size
3293 (factor (magstep font-size))
3294 (stem-thickness (* factor 0.1))
3295 (line-thickness (ly:output-def-lookup layout 'line-thickness))
3296 (half-stem-thickness (/ (* stem-thickness line-thickness) 2))
3297 (raw-length (if stem-up upflag-length downflag-length))
3298 (angle (if stem-up upflag-angle downflag-angle))
3299 (flag-length (+ (* raw-length factor) half-stem-thickness))
3300 (flag-end (polar->rectangular flag-length angle))
3301 (thickness (* flag-thickness factor))
3302 (thickness-offset (cons 0 (* -1 thickness dir)))
3303 (spacing (* -1 flag-spacing factor dir))
3304 (start (cons (- half-stem-thickness) (* half-stem-thickness dir)))
3305 ; The points of a round-filled-polygon need to be given in
3306 ; clockwise order, otherwise the polygon will be enlarged by
3308 (points (if stem-up (list start flag-end
3309 (offset-add flag-end thickness-offset)
3310 (offset-add start thickness-offset))
3312 (offset-add start thickness-offset)
3313 (offset-add flag-end thickness-offset)
3315 (stencil (ly:round-filled-polygon points half-stem-thickness))
3316 ; Log for 1/8 is 3, so we need to subtract 3
3317 (flag-stencil (buildflags stencil (- log 3) stencil spacing)))
3320 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3322 (size-factor (magstep font-size))
3323 (blot (ly:output-def-lookup layout 'blot-diameter))
3325 (let ((result (get-glyph-name font
3326 (get-glyph-name-candidates
3327 (sign dir) log style))))
3328 (if (string-null? result)
3329 ;; If no glyph name can be found, select default heads.
3330 ;; Though this usually means an unsupported style has been
3331 ;; chosen, it also prevents unrelated 'style settings from
3332 ;; other grobs (e.g., TextSpanner and TimeSignature) leaking
3334 (get-glyph-name font
3335 (get-glyph-name-candidates
3336 (sign dir) log 'default))
3338 (head-glyph (ly:font-get-glyph font head-glyph-name))
3339 (ancient-flags? (or (eq? style 'mensural) (eq? style 'neomensural)))
3340 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3341 (stem-length (* size-factor (max 3 (- log 1))))
3342 ;; With ancient-flags we want a tighter stem
3343 (stem-thickness (* size-factor (if ancient-flags? 0.1 0.13)))
3344 (stemy (* dir stem-length))
3345 (attach-off (cons (interval-index
3346 (ly:stencil-extent head-glyph X)
3347 (* (sign dir) (car attach-indices)))
3348 ; fixme, this is inconsistent between X & Y.
3351 (ly:stencil-extent head-glyph Y)
3352 (cdr attach-indices)))))
3353 ;; For a tighter stem (with ancient-flags) the stem-width has to be
3355 (stem-X-corr (if ancient-flags? (* 0.5 dir stem-thickness) 0))
3356 (stem-glyph (and (> log 0)
3357 (ly:round-filled-box
3358 (ordered-cons (+ stem-X-corr (car attach-off))
3359 (+ stem-X-corr (car attach-off)
3360 (* (- (sign dir)) stem-thickness)))
3361 (cons (min stemy (cdr attach-off))
3362 (max stemy (cdr attach-off)))
3363 (/ stem-thickness 3))))
3364 (dot (ly:font-get-glyph font "dots.dot"))
3365 (dotwid (interval-length (ly:stencil-extent dot X)))
3366 (dots (and (> dot-count 0)
3367 (apply ly:stencil-add
3369 (ly:stencil-translate-axis
3370 dot (* 2 x dotwid) X))
3371 (iota dot-count)))))
3372 ;; Straight-flags. Values taken from /scm/flag-style.scm
3373 (modern-straight-flag (straight-flag-mrkp 0.55 1 -18 1.1 22 1.2 dir))
3374 (old-straight-flag (straight-flag-mrkp 0.55 1 -45 1.2 45 1.4 dir))
3375 ;; Calculate a corrective to avoid a gap between
3376 ;; straight-flags and the stem.
3377 (flag-style-Y-corr (if (or (eq? flag-style 'modern-straight-flag)
3378 (eq? flag-style 'old-straight-flag))
3379 (/ blot 10 (* -1 dir))
3381 (flaggl (and (> log 2)
3382 (ly:stencil-translate
3383 (cond ((eq? flag-style 'modern-straight-flag)
3384 modern-straight-flag)
3385 ((eq? flag-style 'old-straight-flag)
3388 (ly:font-get-glyph font
3389 (format #f (if ancient-flags?
3390 "flags.mensural~a2~a"
3392 (if (> dir 0) "u" "d")
3394 (cons (+ (car attach-off)
3395 ;; For tighter stems (with ancient-flags) the
3396 ;; flag has to be adjusted different.
3397 (if (and (not ancient-flags?) (< dir 0))
3400 (+ stemy flag-style-Y-corr))))))
3402 ;; If there is a flag on an upstem and the stem is short, move the dots
3403 ;; to avoid the flag. 16th notes get a special case because their flags
3404 ;; hang lower than any other flags.
3405 ;; Not with ancient flags or straight-flags.
3406 (if (and dots (> dir 0) (> log 2)
3407 (or (eq? flag-style 'default) (null? flag-style))
3408 (not ancient-flags?)
3409 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3410 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3412 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3413 (if (ly:stencil? stem-glyph)
3414 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3415 (set! stem-glyph head-glyph))
3416 (if (ly:stencil? dots)
3419 (ly:stencil-translate-axis
3421 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3427 (let ((divisor (log 2)))
3428 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3430 (define (parse-simple-duration duration-string)
3431 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3432 and return a (log dots) list."
3433 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3435 (if (and match (string=? duration-string (match:substring match 0)))
3436 (let ((len (match:substring match 1))
3437 (dots (match:substring match 2)))
3438 (list (cond ((string=? len "breve") -1)
3439 ((string=? len "longa") -2)
3440 ((string=? len "maxima") -3)
3441 (else (log2 (string->number len))))
3442 (if dots (string-length dots) 0)))
3443 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3445 (define-markup-command (note layout props duration dir)
3448 #:properties (note-by-number-markup)
3450 @cindex notes within text by string
3452 This produces a note with a stem pointing in @var{dir} direction, with
3453 the @var{duration} for the note head type and augmentation dots. For
3454 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3455 a shortened down stem.
3457 @lilypond[verbatim,quote]
3459 \\override #'(style . cross) {
3463 \\note #\"breve\" #0
3466 (let ((parsed (parse-simple-duration duration)))
3467 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3469 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3470 ;; the rest command.
3471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3473 (define-markup-command (rest-by-number layout props log dot-count)
3476 #:properties ((font-size 0)
3478 (multi-measure-rest #f))
3480 @cindex rests or multi-measure-rests within text by log and dot-count
3482 A rest or multi-measure-rest symbol.
3484 @lilypond[verbatim,quote]
3486 \\rest-by-number #3 #2
3488 \\rest-by-number #0 #1
3490 \\override #'(multi-measure-rest . #t)
3491 \\rest-by-number #0 #0
3495 (define (get-glyph-name-candidates log style)
3496 (let* (;; Choose the style-string to be added.
3497 ;; If no glyph exists, select others for the specified styles
3498 ;; otherwise defaulting.
3501 ;; 'baroque needs to be special-cased, otherwise
3502 ;; `select-head-glyph´ would catch neomensural-glyphs for
3503 ;; this style, if (< log 0).
3504 (eq? style 'baroque)
3505 (string-append (number->string log) ""))
3506 ((eq? style 'petrucci)
3507 (string-append (number->string log) "mensural"))
3508 ;; In other cases `select-head-glyph´ from output-lib.scm
3509 ;; works for rest-glyphs, too.
3510 ((and (symbol? style) (not (eq? style 'default)))
3511 (select-head-glyph style log))
3513 ;; Choose ledgered glyphs for whole and half rest.
3514 ;; Except for the specified styles, logs and MultiMeasureRests.
3516 (if (and (or (list? style)
3518 '(neomensural mensural petrucci))))
3519 (not multi-measure-rest)
3520 (or (= log 0) (= log 1)))
3523 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3525 (define (get-glyph-name font cands)
3526 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3531 (ly:paper-get-font layout
3532 (cons '((font-encoding . fetaMusic)) props)))
3535 (get-glyph-name font
3536 (get-glyph-name-candidates log style))))
3537 (if (string-null? result)
3538 ;; If no glyph name can be found, select default rests. Though
3539 ;; this usually means an unsupported style has been chosen, it
3540 ;; also prevents unrelated 'style settings from other grobs
3541 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3542 (get-glyph-name font (get-glyph-name-candidates log 'default))
3544 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3545 (dot (ly:font-get-glyph font "dots.dot"))
3546 (dot-width (interval-length (ly:stencil-extent dot X)))
3547 (dots (and (> dot-count 0)
3548 (apply ly:stencil-add
3550 (ly:stencil-translate-axis
3551 dot (* 2 x dot-width) X))
3552 (iota dot-count))))))
3554 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3555 ;; glyphs are taken for whole and half rests.
3556 ;; If they are dotted, move the dots in X-direction to avoid collision.
3560 (not (member style '(neomensural mensural petrucci))))
3561 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3563 ;; Add dots to the rest-glyph.
3565 ;; Not sure how to vertical align dots.
3566 ;; For now the dots are centered for half, whole or longer rests.
3567 ;; Otherwise placed near the top of the rest.
3569 ;; Dots for rests with (< log 0) dots are allowed, but not
3570 ;; if multi-measure-rest is set #t.
3571 (if (and (not multi-measure-rest) dots)
3574 (ly:stencil-translate
3577 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3579 (interval-center (ly:stencil-extent rest-glyph Y))
3580 (- (interval-end (ly:stencil-extent rest-glyph Y))
3581 (/ (* 2 dot-width) 3)))))
3585 (define-markup-command (rest layout props duration)
3588 #:properties ((style '())
3589 (multi-measure-rest #f)
3590 (multi-measure-rest-number #t)
3593 @cindex rests or multi-measure-rests within text by string
3595 This produces a rest, with the @var{duration} for the rest type and
3597 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3600 Printing MultiMeasureRests could be enabled with
3601 @code{\\override #'(multi-measure-rest . #t)}
3602 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3603 This is enabled for all styles using default-glyphs.
3604 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3606 @lilypond[verbatim,quote]
3612 \\override #'(multi-measure-rest . #t)
3616 \\override #'(multi-measure-rest-number . #f)
3621 ;; Get the number of mmr-glyphs.
3622 ;; Store them in a list.
3623 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3624 (define (mmr-numbers nmbr)
3625 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3626 (8-remainder (remainder nmbr 8))
3627 (4-bar-glyph (floor (/ 8-remainder 4)))
3628 (4-remainder (remainder nmbr 4))
3629 (2-bar-glyph (floor (/ 4-remainder 2)))
3630 (2-remainder (remainder 4-remainder 2))
3631 (1-bar-glyph (floor (/ 2-remainder 1))))
3632 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3634 ;; Get the correct mmr-glyphs.
3635 ;; Store them in a list.
3637 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3638 ;; -> ("rests.M3" "rests.M1")
3639 (define (get-mmr-glyphs lst1 lst2)
3640 (define (helper l1 l2 l3)
3645 (append (make-list (car l1) (car l2)) l3))))
3646 (helper lst1 lst2 '()))
3648 ;; If duration is not valid, print a warning and return empty-stencil
3649 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3650 (not multi-measure-rest))
3651 (and (= (string-length (car (string-split duration #\. ))) 1)
3652 (= (string->number (car (string-split duration #\. ))) 0)))
3654 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3657 ;; For simple rests:
3658 ;; Get a (log dots) list.
3659 (parsed (parse-simple-duration duration))
3660 ;; Create the rest-stencil
3662 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3663 ;; For MultiMeasureRests:
3664 ;; Get the duration-part of duration
3665 (dur-part-string (car (string-split duration #\. )))
3666 ;; Get the duration of MMR:
3667 ;; If not a number (eg. "maxima") calculate it.
3669 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3670 ;; Get a list of the correct number of each mmr-glyph.
3671 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3672 ;; Create a list of mmr-stencils,
3673 ;; translating the glyph for a whole rest.
3677 (let ((single-mmr-stil
3678 (rest-by-number-markup layout props (* -1 x) 0)))
3680 (ly:stencil-translate-axis
3682 ;; Ugh, hard-coded, why 1?
3686 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3687 ;; Adjust the space between the mmr-glyphs,
3688 ;; if not default-glyphs are used.
3689 (word-space (if (member style
3690 '(neomensural mensural petrucci))
3691 (/ (* word-space 2) 3)
3693 ;; Create the final mmr-stencil
3694 ;; via `stack-stencil-line´ from /scm/markup.scm
3695 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3697 ;; Print the number above a multi-measure-rest
3698 ;; Depends on duration, style and multi-measure-rest-number set #t
3699 (if (and multi-measure-rest
3700 multi-measure-rest-number
3702 (not (member style '(neomensural mensural petrucci))))
3703 (let* ((mmr-stil-x-center
3704 (interval-center (ly:stencil-extent mmr-stil X)))
3708 #:override '(font-encoding . fetaText)
3709 (number->string mmr-duration)))
3711 (interpret-markup layout props duration-markup))
3712 (mmr-number-stil-x-center
3713 (interval-center (ly:stencil-extent mmr-number-stil X))))
3715 (set! mmr-stil (ly:stencil-combine-at-edge
3718 (ly:stencil-translate-axis
3720 (- mmr-stil-x-center mmr-number-stil-x-center)
3724 (if multi-measure-rest
3728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3732 (define-markup-command (lower layout props amount arg)
3736 @cindex lowering text
3738 Lower @var{arg} by the distance @var{amount}.
3739 A negative @var{amount} indicates raising; see also @code{\\raise}.
3741 @lilypond[verbatim,quote]
3749 (ly:stencil-translate-axis (interpret-markup layout props arg)
3752 (define-markup-command (translate-scaled layout props offset arg)
3753 (number-pair? markup?)
3755 #:properties ((font-size 0))
3757 @cindex translating text
3758 @cindex scaling text
3760 Translate @var{arg} by @var{offset}, scaling the offset by the
3763 @lilypond[verbatim,quote]
3766 * \\translate #'(2 . 3) translate
3768 * \\translate-scaled #'(2 . 3) translate-scaled
3772 (let* ((factor (magstep font-size))
3773 (scaled (cons (* factor (car offset))
3774 (* factor (cdr offset)))))
3775 (ly:stencil-translate (interpret-markup layout props arg)
3778 (define-markup-command (raise layout props amount arg)
3782 @cindex raising text
3784 Raise @var{arg} by the distance @var{amount}.
3785 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3787 The argument to @code{\\raise} is the vertical displacement amount,
3788 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3789 raise objects in relation to their surrounding markups.
3791 If the text object itself is positioned above or below the staff, then
3792 @code{\\raise} cannot be used to move it, since the mechanism that
3793 positions it next to the staff cancels any shift made with
3794 @code{\\raise}. For vertical positioning, use the @code{padding}
3795 and/or @code{extra-offset} properties.
3797 @lilypond[verbatim,quote]
3806 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3808 (define-markup-command (fraction layout props arg1 arg2)
3811 #:properties ((font-size 0))
3813 @cindex creating text fractions
3815 Make a fraction of two markups.
3816 @lilypond[verbatim,quote]
3822 (let* ((m1 (interpret-markup layout props arg1))
3823 (m2 (interpret-markup layout props arg2))
3824 (factor (magstep font-size))
3825 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3826 (padding (* factor 0.2))
3827 (baseline (* factor 0.6))
3828 (offset (* factor 0.75)))
3829 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3830 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3831 (let* ((x1 (ly:stencil-extent m1 X))
3832 (x2 (ly:stencil-extent m2 X))
3833 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3834 ;; should stack mols separately, to maintain LINE on baseline
3835 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3837 (ly:stencil-aligned-to stack Y CENTER))
3839 (ly:stencil-aligned-to stack X LEFT))
3840 ;; should have EX dimension
3842 (ly:stencil-translate-axis stack offset Y))))
3844 (define-markup-command (normal-size-super layout props arg)
3847 #:properties ((baseline-skip))
3849 @cindex setting superscript in standard font size
3851 Set @var{arg} in superscript with a normal font size.
3853 @lilypond[verbatim,quote]
3856 \\normal-size-super {
3857 superscript in standard size
3861 (ly:stencil-translate-axis
3862 (interpret-markup layout props arg)
3863 (* 0.5 baseline-skip) Y))
3865 (define-markup-command (super layout props arg)
3868 #:properties ((font-size 0)
3871 @cindex superscript text
3873 Set @var{arg} in superscript.
3875 @lilypond[verbatim,quote]
3885 (ly:stencil-translate-axis
3888 (cons `((font-size . ,(- font-size 3))) props)
3890 (* 0.5 baseline-skip)
3893 (define-markup-command (translate layout props offset arg)
3894 (number-pair? markup?)
3897 @cindex translating text
3899 Translate @var{arg} relative to its surroundings. @var{offset}
3900 is a pair of numbers representing the displacement in the X and Y axis.
3902 @lilypond[verbatim,quote]
3905 \\translate #'(2 . 3)
3906 \\line { translated two spaces right, three up }
3909 (ly:stencil-translate (interpret-markup layout props arg)
3912 (define-markup-command (sub layout props arg)
3915 #:properties ((font-size 0)
3918 @cindex subscript text
3920 Set @var{arg} in subscript.
3922 @lilypond[verbatim,quote]
3933 (ly:stencil-translate-axis
3936 (cons `((font-size . ,(- font-size 3))) props)
3938 (* -0.5 baseline-skip)
3941 (define-markup-command (normal-size-sub layout props arg)
3944 #:properties ((baseline-skip))
3946 @cindex setting subscript in standard font size
3948 Set @var{arg} in subscript with a normal font size.
3950 @lilypond[verbatim,quote]
3954 subscript in standard size
3958 (ly:stencil-translate-axis
3959 (interpret-markup layout props arg)
3960 (* -0.5 baseline-skip)
3963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3967 (define-markup-command (hbracket layout props arg)
3971 @cindex placing horizontal brackets around text
3973 Draw horizontal brackets around @var{arg}.
3975 @lilypond[verbatim,quote]
3984 (let ((th 0.1) ;; todo: take from GROB.
3985 (m (interpret-markup layout props arg)))
3986 (bracketify-stencil m X th (* 2.5 th) th)))
3988 (define-markup-command (bracket layout props arg)
3992 @cindex placing vertical brackets around text
3994 Draw vertical brackets around @var{arg}.
3996 @lilypond[verbatim,quote]
4003 (let ((th 0.1) ;; todo: take from GROB.
4004 (m (interpret-markup layout props arg)))
4005 (bracketify-stencil m Y th (* 2.5 th) th)))
4007 (define-markup-command (parenthesize layout props arg)
4010 #:properties ((angularity 0)
4016 @cindex placing parentheses around text
4018 Draw parentheses around @var{arg}. This is useful for parenthesizing
4019 a column containing several lines of text.
4021 @lilypond[verbatim,quote]
4030 \\override #'(angularity . 2) {
4041 (let* ((markup (interpret-markup layout props arg))
4042 (scaled-width (* size width))
4044 (* (chain-assoc-get 'line-thickness props 0.1)
4047 (min (* size 0.5 scaled-thickness)
4048 (* (/ 4 3.0) scaled-width)))
4049 (padding (chain-assoc-get 'padding props half-thickness)))
4050 (parenthesize-stencil
4051 markup half-thickness scaled-width angularity padding)))
4054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4055 ;; Delayed markup evaluation
4056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4058 (define-markup-command (page-ref layout props label gauge default)
4059 (symbol? markup? markup?)
4062 @cindex referencing page numbers in text
4064 Reference to a page number. @var{label} is the label set on the referenced
4065 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
4066 the maximum width of the page number, and @var{default} the value to display
4067 when @var{label} is not found."
4068 (let* ((gauge-stencil (interpret-markup layout props gauge))
4069 (x-ext (ly:stencil-extent gauge-stencil X))
4070 (y-ext (ly:stencil-extent gauge-stencil Y)))
4072 `(delay-stencil-evaluation
4073 ,(delay (ly:stencil-expr
4074 (let* ((table (ly:output-def-lookup layout 'label-page-table))
4075 (page-number (if (list? table)
4076 (assoc-get label table)
4078 (page-markup (if page-number (format #f "~a" page-number) default))
4079 (page-stencil (interpret-markup layout props page-markup))
4080 (gap (- (interval-length x-ext)
4081 (interval-length (ly:stencil-extent page-stencil X)))))
4082 (interpret-markup layout props
4083 (markup #:concat (#:hspace gap page-markup)))))))
4087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4091 (define-markup-command (scale layout props factor-pair arg)
4092 (number-pair? markup?)
4095 @cindex scaling markup
4096 @cindex mirroring markup
4098 Scale @var{arg}. @var{factor-pair} is a pair of numbers
4099 representing the scaling-factor in the X and Y axes.
4100 Negative values may be used to produce mirror images.
4102 @lilypond[verbatim,quote]
4112 (let ((stil (interpret-markup layout props arg))
4113 (sx (car factor-pair))
4114 (sy (cdr factor-pair)))
4115 (ly:stencil-scale stil sx sy)))
4117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4121 (define-markup-command (pattern layout props count axis space pattern)
4122 (integer? integer? number? markup?)
4125 Prints @var{count} times a @var{pattern} markup.
4126 Patterns are spaced apart by @var{space}.
4127 Patterns are distributed on @var{axis}.
4129 @lilypond[verbatim, quote]
4131 \"Horizontally repeated :\"
4132 \\pattern #7 #X #2 \\flat
4134 \"Vertically repeated :\"
4135 \\pattern #3 #Y #0.5 \\flat
4138 (let ((pattern-width (interval-length
4139 (ly:stencil-extent (interpret-markup layout props pattern) X)))
4140 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
4141 (let loop ((i (1- count)) (patterns (markup)))
4147 (markup patterns pattern)
4148 (markup #:column (patterns pattern))))
4151 (markup patterns pattern #:hspace space)
4152 (markup #:column (patterns pattern #:vspace space))))))))
4154 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
4155 (number? ly:dir? markup? markup? markup?)
4157 #:properties ((word-space)
4160 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
4161 with a line of markups @var{pattern} in between.
4162 Patterns are spaced apart by @var{space}.
4163 Patterns are aligned to the @var{dir} markup.
4165 @lilypond[verbatim, quote]
4168 \\fill-with-pattern #1 #RIGHT . first right
4169 \\fill-with-pattern #1 #RIGHT . second right
4171 \"center-aligned :\"
4172 \\fill-with-pattern #1.5 #CENTER - left right
4175 \\override #'(line-width . 50)
4176 \\fill-with-pattern #2 #LEFT : left first
4177 \\override #'(line-width . 50)
4178 \\fill-with-pattern #2 #LEFT : left second
4181 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
4182 (pattern-width (interval-length pattern-x-extent))
4183 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
4184 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
4185 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
4186 (period (+ space pattern-width))
4187 (count (truncate (/ (- middle-width pattern-width) period)))
4188 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
4189 (interpret-markup layout props
4191 #:with-dimensions (cons 0 middle-width) '(0 . 0)
4192 #:translate (cons x-offset 0)
4193 #:pattern (1+ count) X space pattern
4196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4200 (define-markup-command (replace layout props replacements arg)
4204 Used to automatically replace a string by another in the markup @var{arg}.
4205 Each pair of the alist @var{replacements} specifies what should be replaced.
4206 The @code{key} is the string to be replaced by the @code{value} string.
4208 @lilypond[verbatim, quote]
4209 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
4213 (internal-add-text-replacements
4218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4219 ;; Markup list commands
4220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4222 (define-public (space-lines baseline stils)
4223 (let space-stil ((stils stils)
4227 (let* ((stil (car stils))
4228 (dy-top (max (- (/ baseline 1.5)
4229 (interval-bound (ly:stencil-extent stil Y) UP))
4231 (dy-bottom (max (+ (/ baseline 3.0)
4232 (interval-bound (ly:stencil-extent stil Y) DOWN))
4234 (new-stil (ly:make-stencil
4235 (ly:stencil-expr stil)
4236 (ly:stencil-extent stil X)
4237 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
4239 (+ (interval-bound (ly:stencil-extent stil Y) UP)
4241 (space-stil (cdr stils) (cons new-stil result))))))
4243 (define-markup-list-command (justified-lines layout props args)
4245 #:properties ((baseline-skip)
4246 wordwrap-internal-markup-list)
4248 @cindex justifying lines of text
4250 Like @code{\\justify}, but return a list of lines instead of a single markup.
4251 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
4252 @var{X}@tie{}is the number of staff spaces."
4253 (space-lines baseline-skip
4254 (interpret-markup-list layout props
4255 (make-wordwrap-internal-markup-list #t args))))
4257 (define-markup-list-command (wordwrap-lines layout props args)
4259 #:properties ((baseline-skip)
4260 wordwrap-internal-markup-list)
4261 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4262 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4263 where @var{X} is the number of staff spaces."
4264 (space-lines baseline-skip
4265 (interpret-markup-list layout props
4266 (make-wordwrap-internal-markup-list #f args))))
4268 (define-markup-list-command (column-lines layout props args)
4270 #:properties ((baseline-skip))
4271 "Like @code{\\column}, but return a list of lines instead of a single markup.
4272 @code{baseline-skip} determines the space between each markup in @var{args}."
4273 (space-lines baseline-skip
4274 (interpret-markup-list layout props args)))
4276 (define-markup-list-command (override-lines layout props new-prop args)
4277 (pair? markup-list?)
4278 "Like @code{\\override}, for markup lists."
4279 (interpret-markup-list layout (cons (list new-prop) props) args))
4281 (define-markup-list-command (map-markup-commands layout props compose args)
4282 (procedure? markup-list?)
4283 "This applies the function @var{compose} to every markup in
4284 @var{args} (including elements of markup list command calls) in order
4285 to produce a new markup list. Since the return value from a markup
4286 list command call is not a markup list but rather a list of stencils,
4287 this requires passing those stencils off as the results of individual
4288 markup calls. That way, the results should work out as long as no
4289 markups rely on side effects."
4290 (let ((key (make-symbol "key")))
4294 ;; if `compose' does not actually interpret its markup
4295 ;; argument, we still need to return a list of stencils,
4296 ;; created from the single returned stencil
4298 (interpret-markup layout props
4300 (make-on-the-fly-markup
4301 (lambda (layout props m)
4302 ;; here all effects of `compose' on the
4303 ;; properties should be visible, so we
4304 ;; call interpret-markup-list at this
4305 ;; point of time and harvest its
4308 (interpret-markup-list
4309 layout props args)))
4310 (make-null-markup))))))
4311 (lambda (key stencils)
4314 (interpret-markup layout props
4315 (compose (make-stencil-markup sten))))