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-hline layout props)
145 #:properties ((draw-line-markup)
149 @cindex drawing a line across a page
151 Draws a line across a page, where the property @code{span-factor}
152 controls what fraction of the page is taken up.
153 @lilypond[verbatim,quote]
157 \\override #'(span-factor . 1/3)
162 (interpret-markup layout
164 (markup #:draw-line (cons (* line-width
168 (define-markup-command (draw-circle layout props radius thickness filled)
169 (number? number? boolean?)
172 @cindex drawing circles within text
174 A circle of radius @var{radius} and thickness @var{thickness},
177 @lilypond[verbatim,quote]
179 \\draw-circle #2 #0.5 ##f
181 \\draw-circle #2 #0 ##t
184 (make-circle-stencil radius thickness filled))
186 (define-markup-command (triangle layout props filled)
189 #:properties ((thickness 0.1)
193 @cindex drawing triangles within text
195 A triangle, either filled or empty.
197 @lilypond[verbatim,quote]
204 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
213 (cons 0 (* .86 ex)))))
215 (define-markup-command (circle layout props arg)
218 #:properties ((thickness 1)
220 (circle-padding 0.2))
222 @cindex circling text
224 Draw a circle around @var{arg}. Use @code{thickness},
225 @code{circle-padding} and @code{font-size} properties to determine line
226 thickness and padding around the markup.
228 @lilypond[verbatim,quote]
235 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
237 (pad (* (magstep font-size) circle-padding))
238 (m (interpret-markup layout props arg)))
239 (circle-stencil m th pad)))
241 (define-markup-command (with-url layout props url arg)
245 @cindex inserting URL links into text
247 Add a link to URL @var{url} around @var{arg}. This only works in
250 @lilypond[verbatim,quote]
252 \\with-url #\"http://lilypond.org/\" {
253 LilyPond ... \\italic {
254 music notation for everyone
259 (let* ((stil (interpret-markup layout props arg))
260 (xextent (ly:stencil-extent stil X))
261 (yextent (ly:stencil-extent stil Y))
262 (old-expr (ly:stencil-expr stil))
263 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
265 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
267 (define-markup-command (page-link layout props page-number arg)
271 @cindex referencing page numbers in text
273 Add a link to the page @var{page-number} around @var{arg}. This only works
276 @lilypond[verbatim,quote]
278 \\page-link #2 { \\italic { This links to page 2... } }
281 (let* ((stil (interpret-markup layout props arg))
282 (xextent (ly:stencil-extent stil X))
283 (yextent (ly:stencil-extent stil Y))
284 (old-expr (ly:stencil-expr stil))
285 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
287 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
289 (define-markup-command (with-link layout props label arg)
293 @cindex referencing page labels in text
295 Add a link to the page holding label @var{label} around @var{arg}. This
296 only works in the PDF backend.
298 @lilypond[verbatim,quote]
300 \\with-link #'label {
301 \\italic { This links to the page containing the label... }
305 (let* ((arg-stencil (interpret-markup layout props arg))
306 (x-ext (ly:stencil-extent arg-stencil X))
307 (y-ext (ly:stencil-extent arg-stencil Y)))
309 `(delay-stencil-evaluation
310 ,(delay (ly:stencil-expr
311 (let* ((table (ly:output-def-lookup layout 'label-page-table))
312 (page-number (if (list? table)
313 (assoc-get label table)
315 (link-expr (list 'page-link page-number
316 `(quote ,x-ext) `(quote ,y-ext))))
317 (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
323 (define-markup-command (beam layout props width slope thickness)
324 (number? number? number?)
327 @cindex drawing beams within text
329 Create a beam with the specified parameters.
330 @lilypond[verbatim,quote]
335 (let* ((y (* slope width))
336 (yext (cons (min 0 y) (max 0 y)))
337 (half (/ thickness 2)))
342 width (+ (* width slope) (/ thickness -2))
343 width (+ (* width slope) (/ thickness 2))
345 ,(ly:output-def-lookup layout 'blot-diameter)
348 (cons (+ (- half) (car yext))
349 (+ half (cdr yext))))))
351 (define-markup-command (underline layout props arg)
354 #:properties ((thickness 1) (offset 2))
356 @cindex underlining text
358 Underline @var{arg}. Looks at @code{thickness} to determine line
359 thickness, and @code{offset} to determine line y-offset.
361 @lilypond[verbatim,quote]
362 \\markup \\fill-line {
363 \\underline \"underlined\"
364 \\override #'(offset . 5)
365 \\override #'(thickness . 1)
366 \\underline \"underlined\"
367 \\override #'(offset . 1)
368 \\override #'(thickness . 5)
369 \\underline \"underlined\"
372 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
373 (underline-thick (* thickness thick))
374 (markup (interpret-markup layout props arg))
375 (x1 (car (ly:stencil-extent markup X)))
376 (x2 (cdr (ly:stencil-extent markup X)))
377 (y (* thick (- offset)))
378 (line (make-line-stencil underline-thick x1 y x2 y)))
379 (ly:stencil-add markup line)))
381 (define-markup-command (box layout props arg)
384 #:properties ((thickness 1)
388 @cindex enclosing text within a box
390 Draw a box round @var{arg}. Looks at @code{thickness},
391 @code{box-padding} and @code{font-size} properties to determine line
392 thickness and padding around the markup.
394 @lilypond[verbatim,quote]
396 \\override #'(box-padding . 0.5)
401 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
403 (pad (* (magstep font-size) box-padding))
404 (m (interpret-markup layout props arg)))
405 (box-stencil m th pad)))
407 (define-markup-command (filled-box layout props xext yext blot)
408 (number-pair? number-pair? number?)
411 @cindex drawing solid boxes within text
412 @cindex drawing boxes with rounded corners
414 Draw a box with rounded corners of dimensions @var{xext} and
415 @var{yext}. For example,
417 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
419 creates a box extending horizontally from -0.3 to 1.8 and
420 vertically from -0.3 up to 1.8, with corners formed from a
421 circle of diameter@tie{}0 (i.e., sharp corners).
423 @lilypond[verbatim,quote]
425 \\filled-box #'(0 . 4) #'(0 . 4) #0
426 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
427 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
429 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
435 (define-markup-command (rounded-box layout props arg)
438 #:properties ((thickness 1)
442 "@cindex enclosing text in a box with rounded corners
443 @cindex drawing boxes with rounded corners around text
444 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
445 @code{box-padding} and @code{font-size} properties to determine line
446 thickness and padding around the markup; the @code{corner-radius} property
447 makes it possible to define another shape for the corners (default is 1).
449 @lilypond[quote,verbatim,relative=2]
457 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
459 (pad (* (magstep font-size) box-padding))
460 (m (interpret-markup layout props arg)))
461 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
464 (define-markup-command (rotate layout props ang arg)
468 @cindex rotating text
470 Rotate object with @var{ang} degrees around its center.
472 @lilypond[verbatim,quote]
482 (let* ((stil (interpret-markup layout props arg)))
483 (ly:stencil-rotate stil ang 0 0)))
485 (define-markup-command (whiteout layout props arg)
489 @cindex adding a white background to text
491 Provide a white background for @var{arg}.
493 @lilypond[verbatim,quote]
496 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
500 (stencil-whiteout (interpret-markup layout props arg)))
502 (define-markup-command (pad-markup layout props amount arg)
507 @cindex putting space around text
509 Add space around a markup object.
511 @lilypond[verbatim,quote]
525 ((stil (interpret-markup layout props arg))
526 (xext (ly:stencil-extent stil X))
527 (yext (ly:stencil-extent stil Y)))
530 (ly:stencil-expr stil)
531 (interval-widen xext amount)
532 (interval-widen yext amount))))
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
538 (define-markup-command (strut layout props)
542 @cindex creating vertical spaces in text
544 Create a box of the same height as the space in the current font."
545 (let ((m (ly:text-interface::interpret-markup layout props " ")))
546 (ly:make-stencil (ly:stencil-expr m)
548 (ly:stencil-extent m X)
551 (define-markup-command (hspace layout props amount)
554 #:properties ((word-space))
556 @cindex creating horizontal spaces in text
558 Create an invisible object taking up horizontal space @var{amount}.
560 @lilypond[verbatim,quote]
569 (let ((corrected-space (- amount word-space)))
570 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))))
572 (define-markup-command (vspace layout props amount)
576 @cindex creating vertical spaces in text
578 Create an invisible object taking up vertical space
579 of @var{amount} multiplied by 3.
581 @lilypond[verbatim,quote]
592 (let ((amount (* amount 3.0)))
593 (ly:make-stencil "" (cons 0 0) (cons 0 amount))))
596 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
597 ;; importing graphics.
598 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
600 (define-markup-command (stencil layout props stil)
604 @cindex importing stencils into text
606 Use a stencil as markup.
608 @lilypond[verbatim,quote]
610 \\stencil #(make-circle-stencil 2 0 #t)
616 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
618 (define (get-postscript-bbox string)
619 "Extract the bbox from STRING, or return #f if not present."
621 ((match (regexp-exec bbox-regexp string)))
625 (string->number (match:substring match x)))
630 (define-markup-command (epsfile layout props axis size file-name)
631 (number? number? string?)
634 @cindex inlining an Encapsulated PostScript image
636 Inline an EPS image. The image is scaled along @var{axis} to
639 @lilypond[verbatim,quote]
641 \\general-align #Y #DOWN {
642 \\epsfile #X #20 #\"context-example.eps\"
643 \\epsfile #Y #20 #\"context-example.eps\"
647 (if (ly:get-option 'safe)
648 (interpret-markup layout props "not allowed in safe")
649 (eps-file->stencil axis size file-name)
652 (define-markup-command (postscript layout props str)
656 @cindex inserting PostScript directly into text
657 This inserts @var{str} directly into the output as a PostScript
660 @lilypond[verbatim,quote]
664 0.4 0.6 0.5 0 361 arc
666 1.0 0.6 0.5 0 361 arc
671 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
672 \\postscript #ringsps
684 gsave currentpoint translate
692 (define-markup-command (path layout props thickness commands) (number? list?)
694 #:properties ((line-cap-style 'round)
695 (line-join-style 'round)
698 @cindex paths, drawing
699 @cindex drawing paths
700 Draws a path with line thickness @var{thickness} according to the
701 directions given in @var{commands}. @var{commands} is a list of
702 lists where the @code{car} of each sublist is a drawing command and
703 the @code{cdr} comprises the associated arguments for each command.
705 Line-cap styles and line-join styles may be customized by
706 overriding the @code{line-cap-style} and @code{line-join-style}
707 properties, respectively. Available line-cap styles are
708 @code{'butt}, @code{'round}, and @code{'square}. Available
709 line-join styles are @code{'miter}, @code{'round}, and
712 The property @code{filled} specifies whether or not the path is
715 There are seven commands available to use in the list
716 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
717 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
718 @code{closepath}. Note that the commands that begin with @emph{r}
719 are the relative variants of the other three commands.
721 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
722 @code{rlineto} take 2 arguments; they are the X and Y coordinates
723 for the destination point.
725 The commands @code{curveto} and @code{rcurveto} create cubic
726 Bézier curves, and take 6 arguments; the first two are the X and Y
727 coordinates for the first control point, the second two are the X
728 and Y coordinates for the second control point, and the last two
729 are the X and Y coordinates for the destination point.
731 The @code{closepath} command takes zero arguments and closes the
732 current subpath in the active path.
734 Note that a sequence of commands @emph{must} begin with a
735 @code{moveto} or @code{rmoveto} to work with the SVG output.
737 @lilypond[verbatim,quote]
743 (curveto -5 -5 -5 5 -1 0)
747 \\path #0.25 #samplePath
750 (let* ((half-thickness (/ thickness 2))
751 (current-point '(0 . 0))
752 (set-point (lambda (lst) (set! current-point lst)))
753 (relative? (lambda (x)
754 (string-prefix? "r" (symbol->string (car x)))))
755 ;; For calculating extents, we want to modify the command
756 ;; list so that all coordinates are absolute.
757 (new-commands (map (lambda (x)
759 ;; for rmoveto, rlineto
760 ((and (relative? x) (eq? 3 (length x)))
762 (+ (car current-point)
764 (+ (cdr current-point)
770 ((and (relative? x) (eq? 7 (length x)))
771 (let* ((old-cp current-point)
778 (list (+ (car old-cp) (second x))
779 (+ (cdr old-cp) (third x))
780 (+ (car old-cp) (fourth x))
781 (+ (cdr old-cp) (fifth x))
784 ;; for moveto, lineto
786 (set-point (cons (second x)
791 (set-point (cons (sixth x)
794 ;; keep closepath for filtering;
795 ;; see `without-closepath'.
798 ;; path-min-max does not accept 0-arg lists,
799 ;; and since closepath does not affect extents, filter
800 ;; out those commands here.
801 (without-closepath (filter (lambda (x)
802 (not (equal? 'closepath (car x))))
804 (extents (path-min-max
805 ;; set the origin to the first moveto
806 (list (list-ref (car without-closepath) 0)
807 (list-ref (car without-closepath) 1))
809 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
810 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
811 (command-list (fold-right append '() commands)))
813 ;; account for line thickness
814 (set! X-extent (interval-widen X-extent half-thickness))
815 (set! Y-extent (interval-widen Y-extent half-thickness))
818 `(path ,thickness `(,@',command-list)
819 ',line-cap-style ',line-join-style ,filled)
823 (define-markup-command (score layout props score)
826 #:properties ((baseline-skip))
828 @cindex inserting music into text
830 Inline an image of music.
832 @lilypond[verbatim,quote]
836 \\new Staff \\relative c' {
839 \\mark \\markup { Allegro }
845 \\new Staff \\relative c {
859 \\override RehearsalMark
860 #'break-align-symbols = #'(time-signature key-signature)
861 \\override RehearsalMark
862 #'self-alignment-X = #LEFT
866 \\override TimeSignature
867 #'break-align-anchor-alignment = #LEFT
873 (let ((output (ly:score-embedded-format score layout)))
875 (if (ly:music-output? output)
876 (stack-stencils Y DOWN baseline-skip
877 (map paper-system-stencil
879 (ly:paper-score-paper-systems output))))
881 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
884 (define-markup-command (null layout props)
888 @cindex creating empty text objects
890 An empty markup with extents of a single point.
892 @lilypond[verbatim,quote]
899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
903 (define-markup-command (simple layout props str)
907 @cindex simple text strings
909 A simple text string; @code{\\markup @{ foo @}} is equivalent with
910 @code{\\markup @{ \\simple #\"foo\" @}}.
912 Note: for creating standard text markup or defining new markup commands,
913 the use of @code{\\simple} is unnecessary.
915 @lilypond[verbatim,quote]
919 \\simple #\"strings\"
922 (interpret-markup layout props str))
924 (define-markup-command (tied-lyric layout props str)
927 #:properties ((word-space))
929 @cindex simple text strings with tie characters
931 Like simple-markup, but use tie characters for @q{~} tilde symbols.
933 @lilypond[verbatim,quote]
935 \\tied-lyric #\"Siam navi~all'onde~algenti Lasciate~in abbandono\"
936 \\tied-lyric #\"Impetuosi venti I nostri~affetti sono\"
937 \\tied-lyric #\"Ogni diletto~e scoglio Tutta la vita~e~un mar.\"
940 (define (replace-ties tie str)
941 (if (string-contains str "~")
943 ((half-space (/ word-space 2))
944 (parts (string-split str #\~))
945 (tie-str (markup #:hspace half-space
947 #:hspace half-space))
948 (joined (list-join parts tie-str)))
949 (make-concat-markup joined))
952 (define short-tie-regexp (make-regexp "~[^.]~"))
953 (define (match-short str) (regexp-exec short-tie-regexp str))
955 (define (replace-short str mkp)
956 (let ((match (match-short str)))
958 (make-concat-markup (list
960 (replace-ties "ties.lyric.default" str)))
961 (let ((new-str (match:suffix match))
962 (new-mkp (make-concat-markup (list
964 (replace-ties "ties.lyric.default"
965 (match:prefix match))
966 (replace-ties "ties.lyric.short"
967 (match:substring match))))))
968 (replace-short new-str new-mkp)))))
970 (interpret-markup layout
972 (replace-short str (markup))))
974 (define-public empty-markup
975 (make-simple-markup ""))
977 ;; helper for justifying lines.
978 (define (get-fill-space word-count line-width word-space text-widths)
979 "Calculate the necessary paddings between each two adjacent texts.
980 The lengths of all texts are stored in @var{text-widths}.
981 The normal formula for the padding between texts a and b is:
982 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
983 The first and last padding have to be calculated specially using the
984 whole length of the first or last text.
985 All paddings are checked to be at least word-space, to ensure that
987 Return a list of paddings."
989 ((null? text-widths) '())
991 ;; special case first padding
992 ((= (length text-widths) word-count)
994 (- (- (/ line-width (1- word-count)) (car text-widths))
995 (/ (car (cdr text-widths)) 2))
996 (get-fill-space word-count line-width word-space (cdr text-widths))))
997 ;; special case last padding
998 ((= (length text-widths) 2)
999 (list (- (/ line-width (1- word-count))
1000 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
1002 (let ((default-padding
1003 (- (/ line-width (1- word-count))
1004 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
1006 (if (> word-space default-padding)
1009 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
1011 (define-markup-command (fill-line layout props args)
1014 #:properties ((text-direction RIGHT)
1017 "Put @var{markups} in a horizontal line of width @var{line-width}.
1018 The markups are spaced or flushed to fill the entire line.
1019 If there are no arguments, return an empty stencil.
1021 @lilypond[verbatim,quote]
1025 Words evenly spaced across the page
1029 \\line { Text markups }
1031 \\italic { evenly spaced }
1033 \\line { across the page }
1038 (let* ((orig-stencils (interpret-markup-list layout props args))
1041 (if (ly:stencil-empty? stc)
1043 stc)) orig-stencils))
1046 (if (ly:stencil-empty? stc)
1048 (interval-length (ly:stencil-extent stc X))))
1050 (text-width (apply + text-widths))
1051 (word-count (length stencils))
1052 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1057 (/ (- line-width text-width) 2)
1058 (/ (- line-width text-width) 2)))
1061 (- line-width text-width)))
1063 (get-fill-space word-count line-width word-space text-widths))))
1065 (line-contents (if (= word-count 1)
1072 (if (null? (remove ly:stencil-empty? orig-stencils))
1075 (if (= text-direction LEFT)
1076 (set! line-contents (reverse line-contents)))
1078 (stack-stencils-padding-list
1079 X RIGHT fill-space line-contents))
1080 (if (> word-count 1)
1081 ;; shift s.t. stencils align on the left edge, even if
1082 ;; first stencil had negative X-extent (e.g. center-column)
1083 ;; (if word-count = 1, X-extents are already normalized in
1084 ;; the definition of line-contents)
1086 (ly:stencil-translate-axis
1088 (- (car (ly:stencil-extent (car stencils) X)))
1092 (define-markup-command (line layout props args)
1095 #:properties ((word-space)
1096 (text-direction RIGHT))
1097 "Put @var{args} in a horizontal line. The property @code{word-space}
1098 determines the space between markups in @var{args}.
1100 @lilypond[verbatim,quote]
1107 (let ((stencils (interpret-markup-list layout props args)))
1108 (if (= text-direction LEFT)
1109 (set! stencils (reverse stencils)))
1112 (remove ly:stencil-empty? stencils))))
1114 (define-markup-command (concat layout props args)
1118 @cindex concatenating text
1119 @cindex ligatures in text
1121 Concatenate @var{args} in a horizontal line, without spaces in between.
1122 Strings and simple markups are concatenated on the input level, allowing
1123 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1124 equivalent to @code{\"fi\"}.
1126 @lilypond[verbatim,quote]
1135 (define (concat-string-args arg-list)
1136 (fold-right (lambda (arg result-list)
1137 (let ((result (if (pair? result-list)
1140 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1141 (set! arg (cadr arg)))
1142 (if (and (string? result) (string? arg))
1143 (cons (string-append arg result) (cdr result-list))
1144 (cons arg result-list))))
1148 (interpret-markup layout
1149 (prepend-alist-chain 'word-space 0 props)
1150 (make-line-markup (if (markup-command-list? args)
1152 (concat-string-args args)))))
1154 (define (wordwrap-stencils stencils
1155 justify base-space line-width text-dir)
1156 "Perform simple wordwrap, return stencil of each line."
1157 (define space (if justify
1158 ;; justify only stretches lines.
1161 (define (take-list width space stencils
1162 accumulator accumulated-width)
1163 "Return (head-list . tail) pair, with head-list fitting into width"
1164 (if (null? stencils)
1165 (cons accumulator stencils)
1166 (let* ((first (car stencils))
1167 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1168 (newwid (+ space first-wid accumulated-width)))
1169 (if (or (null? accumulator)
1171 (take-list width space
1173 (cons first accumulator)
1175 (cons accumulator stencils)))))
1176 (let loop ((lines '())
1178 (let* ((line-break (take-list line-width space todo
1180 (line-stencils (car line-break))
1181 (space-left (- line-width
1182 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1184 (line-word-space (cond ((not justify) space)
1185 ;; don't stretch last line of paragraph.
1186 ;; hmmm . bug - will overstretch the last line in some case.
1187 ((null? (cdr line-break))
1189 ((null? line-stencils) 0.0)
1190 ((null? (cdr line-stencils)) 0.0)
1191 (else (/ space-left (1- (length line-stencils))))))
1192 (line (stack-stencil-line line-word-space
1193 (if (= text-dir RIGHT)
1194 (reverse line-stencils)
1196 (if (pair? (cdr line-break))
1197 (loop (cons line lines)
1200 (if (= text-dir LEFT)
1202 (ly:stencil-translate-axis
1204 (- line-width (interval-end (ly:stencil-extent line X)))
1206 (reverse (cons line lines)))))))
1208 (define-markup-list-command (wordwrap-internal layout props justify args)
1209 (boolean? markup-list?)
1210 #:properties ((line-width #f)
1212 (text-direction RIGHT))
1213 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1214 (wordwrap-stencils (remove ly:stencil-empty?
1215 (interpret-markup-list layout props args))
1219 (ly:output-def-lookup layout 'line-width))
1222 (define-markup-command (justify layout props args)
1225 #:properties ((baseline-skip)
1226 wordwrap-internal-markup-list)
1228 @cindex justifying text
1230 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1231 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1232 @var{X}@tie{}is the number of staff spaces.
1234 @lilypond[verbatim,quote]
1237 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1238 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1239 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1240 laboris nisi ut aliquip ex ea commodo consequat.
1244 (stack-lines DOWN 0.0 baseline-skip
1245 (wordwrap-internal-markup-list layout props #t args)))
1247 (define-markup-command (wordwrap layout props args)
1250 #:properties ((baseline-skip)
1251 wordwrap-internal-markup-list)
1252 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1253 the line width, where @var{X} is the number of staff spaces.
1255 @lilypond[verbatim,quote]
1258 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1259 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1260 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1261 laboris nisi ut aliquip ex ea commodo consequat.
1265 (stack-lines DOWN 0.0 baseline-skip
1266 (wordwrap-internal-markup-list layout props #f args)))
1268 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1270 #:properties ((line-width)
1272 (text-direction RIGHT))
1273 "Internal markup list command used to define @code{\\justify-string} and
1274 @code{\\wordwrap-string}."
1275 (let* ((para-strings (regexp-split
1276 (string-regexp-substitute
1278 (string-regexp-substitute "\r\n" "\n" arg))
1279 "\n[ \t\n]*\n[ \t\n]*"))
1280 (list-para-words (map (lambda (str)
1281 (regexp-split str "[ \t\n]+"))
1283 (para-lines (map (lambda (words)
1285 (remove ly:stencil-empty?
1287 (interpret-markup layout props x))
1289 (wordwrap-stencils stencils
1291 line-width text-direction)))
1293 (apply append para-lines)))
1295 (define-markup-command (wordwrap-string layout props arg)
1298 #:properties ((baseline-skip)
1299 wordwrap-string-internal-markup-list)
1300 "Wordwrap a string. Paragraphs may be separated with double newlines.
1302 @lilypond[verbatim,quote]
1304 \\override #'(line-width . 40)
1305 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1306 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1307 et dolore magna aliqua.
1310 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1311 laboris nisi ut aliquip ex ea commodo consequat.
1314 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1315 qui officia deserunt mollit anim id est laborum\"
1318 (stack-lines DOWN 0.0 baseline-skip
1319 (wordwrap-string-internal-markup-list layout props #f arg)))
1321 (define-markup-command (justify-string layout props arg)
1324 #:properties ((baseline-skip)
1325 wordwrap-string-internal-markup-list)
1326 "Justify a string. Paragraphs may be separated with double newlines
1328 @lilypond[verbatim,quote]
1330 \\override #'(line-width . 40)
1331 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1332 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1333 et dolore magna aliqua.
1336 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1337 laboris nisi ut aliquip ex ea commodo consequat.
1340 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1341 qui officia deserunt mollit anim id est laborum\"
1344 (stack-lines DOWN 0.0 baseline-skip
1345 (wordwrap-string-internal-markup-list layout props #t arg)))
1347 (define-markup-command (wordwrap-field layout props symbol)
1350 "Wordwrap the data which has been assigned to @var{symbol}.
1352 @lilypond[verbatim,quote]
1354 title = \"My title\"
1355 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1356 elit, sed do eiusmod tempor incididunt ut labore et dolore
1357 magna aliqua. Ut enim ad minim veniam, quis nostrud
1358 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1363 bookTitleMarkup = \\markup {
1365 \\fill-line { \\fromproperty #'header:title }
1367 \\wordwrap-field #'header:myText
1376 (let* ((m (chain-assoc-get symbol props)))
1378 (wordwrap-string-markup layout props m)
1381 (define-markup-command (justify-field layout props symbol)
1384 "Justify the data which has been assigned to @var{symbol}.
1386 @lilypond[verbatim,quote]
1388 title = \"My title\"
1389 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1390 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1391 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1392 laboris nisi ut aliquip ex ea commodo consequat.\"
1396 bookTitleMarkup = \\markup {
1398 \\fill-line { \\fromproperty #'header:title }
1400 \\justify-field #'header:myText
1409 (let* ((m (chain-assoc-get symbol props)))
1411 (justify-string-markup layout props m)
1414 (define-markup-command (combine layout props arg1 arg2)
1418 @cindex merging text
1420 Print two markups on top of each other.
1422 Note: @code{\\combine} cannot take a list of markups enclosed in
1423 curly braces as an argument; the follow example will not compile:
1426 \\combine @{ a list @}
1429 @lilypond[verbatim,quote]
1432 \\override #'(thickness . 2)
1434 \\draw-line #'(0 . 4)
1435 \\arrow-head #Y #DOWN ##f
1438 (let* ((s1 (interpret-markup layout props arg1))
1439 (s2 (interpret-markup layout props arg2)))
1440 (ly:stencil-add s1 s2)))
1443 ;; TODO: should extract baseline-skip from each argument somehow..
1445 (define-markup-command (column layout props args)
1448 #:properties ((baseline-skip))
1450 @cindex stacking text in a column
1452 Stack the markups in @var{args} vertically. The property
1453 @code{baseline-skip} determines the space between markups
1456 @lilypond[verbatim,quote]
1465 (let ((arg-stencils (interpret-markup-list layout props args)))
1466 (stack-lines -1 0.0 baseline-skip
1467 (remove ly:stencil-empty? arg-stencils))))
1469 (define-markup-command (dir-column layout props args)
1472 #:properties ((direction)
1475 @cindex changing direction of text columns
1477 Make a column of @var{args}, going up or down, depending on the
1478 setting of the @code{direction} layout property.
1480 @lilypond[verbatim,quote]
1482 \\override #`(direction . ,UP) {
1492 \\override #'(direction . 1) {
1499 (stack-lines (if (number? direction) direction -1)
1502 (interpret-markup-list layout props args)))
1504 (define (general-column align-dir baseline mols)
1505 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1507 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1508 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1509 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1510 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1512 (define-markup-command (center-column layout props args)
1515 #:properties ((baseline-skip))
1517 @cindex centering a column of text
1519 Put @code{args} in a centered column.
1521 @lilypond[verbatim,quote]
1530 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1532 (define-markup-command (left-column layout props args)
1535 #:properties ((baseline-skip))
1537 @cindex text columns, left-aligned
1539 Put @code{args} in a left-aligned column.
1541 @lilypond[verbatim,quote]
1550 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1552 (define-markup-command (right-column layout props args)
1555 #:properties ((baseline-skip))
1557 @cindex text columns, right-aligned
1559 Put @code{args} in a right-aligned column.
1561 @lilypond[verbatim,quote]
1570 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1572 (define-markup-command (vcenter layout props arg)
1576 @cindex vertically centering text
1578 Align @code{arg} to its Y@tie{}center.
1580 @lilypond[verbatim,quote]
1588 (let* ((mol (interpret-markup layout props arg)))
1589 (ly:stencil-aligned-to mol Y CENTER)))
1591 (define-markup-command (center-align layout props arg)
1595 @cindex horizontally centering text
1597 Align @code{arg} to its X@tie{}center.
1599 @lilypond[verbatim,quote]
1609 (let* ((mol (interpret-markup layout props arg)))
1610 (ly:stencil-aligned-to mol X CENTER)))
1612 (define-markup-command (right-align layout props arg)
1616 @cindex right aligning text
1618 Align @var{arg} on its right edge.
1620 @lilypond[verbatim,quote]
1630 (let* ((m (interpret-markup layout props arg)))
1631 (ly:stencil-aligned-to m X RIGHT)))
1633 (define-markup-command (left-align layout props arg)
1637 @cindex left aligning text
1639 Align @var{arg} on its left edge.
1641 @lilypond[verbatim,quote]
1651 (let* ((m (interpret-markup layout props arg)))
1652 (ly:stencil-aligned-to m X LEFT)))
1654 (define-markup-command (general-align layout props axis dir arg)
1655 (integer? number? markup?)
1658 @cindex controlling general text alignment
1660 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1662 @lilypond[verbatim,quote]
1666 \\general-align #X #LEFT
1671 \\general-align #X #CENTER
1677 \\general-align #Y #UP
1684 \\general-align #Y #3.2
1691 (let* ((m (interpret-markup layout props arg)))
1692 (ly:stencil-aligned-to m axis dir)))
1694 (define-markup-command (halign layout props dir arg)
1698 @cindex setting horizontal text alignment
1700 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1701 left-aligned, while @code{+1} is right. Values in between interpolate
1702 alignment accordingly.
1704 @lilypond[verbatim,quote]
1729 (let* ((m (interpret-markup layout props arg)))
1730 (ly:stencil-aligned-to m X dir)))
1732 (define-markup-command (with-dimensions layout props x y arg)
1733 (number-pair? number-pair? markup?)
1736 @cindex setting extent of text objects
1738 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1739 (let* ((m (interpret-markup layout props arg)))
1740 (ly:make-stencil (ly:stencil-expr m) x y)))
1742 (define-markup-command (pad-around layout props amount arg)
1745 "Add padding @var{amount} all around @var{arg}.
1747 @lilypond[verbatim,quote]
1760 (let* ((m (interpret-markup layout props arg))
1761 (x (ly:stencil-extent m X))
1762 (y (ly:stencil-extent m Y)))
1763 (ly:make-stencil (ly:stencil-expr m)
1764 (interval-widen x amount)
1765 (interval-widen y amount))))
1767 (define-markup-command (pad-x layout props amount arg)
1771 @cindex padding text horizontally
1773 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1775 @lilypond[verbatim,quote]
1788 (let* ((m (interpret-markup layout props arg))
1789 (x (ly:stencil-extent m X))
1790 (y (ly:stencil-extent m Y)))
1791 (ly:make-stencil (ly:stencil-expr m)
1792 (interval-widen x amount)
1795 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1796 (integer? ly:dir? markup? markup?)
1798 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1799 (let ((m1 (interpret-markup layout props arg1))
1800 (m2 (interpret-markup layout props arg2)))
1801 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1803 (define-markup-command (transparent layout props arg)
1806 "Make @var{arg} transparent.
1808 @lilypond[verbatim,quote]
1815 (let* ((m (interpret-markup layout props arg))
1816 (x (ly:stencil-extent m X))
1817 (y (ly:stencil-extent m Y)))
1818 (ly:make-stencil "" x y)))
1820 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1821 (number-pair? number-pair? markup?)
1823 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1825 @lilypond[verbatim,quote]
1832 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1838 (let* ((m (interpret-markup layout props arg))
1839 (x (ly:stencil-extent m X))
1840 (y (ly:stencil-extent m Y)))
1841 (ly:make-stencil (ly:stencil-expr m)
1842 (interval-union x-ext x)
1843 (interval-union y-ext y))))
1845 (define-markup-command (hcenter-in layout props length arg)
1848 "Center @var{arg} horizontally within a box of extending
1849 @var{length}/2 to the left and right.
1851 @lilypond[quote,verbatim]
1854 \\set Staff.instrumentName = \\markup {
1861 \\set Staff.instrumentName = \\markup {
1870 (interpret-markup layout props
1871 (make-pad-to-box-markup
1872 (cons (/ length -2) (/ length 2))
1874 (make-center-align-markup arg))))
1876 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1880 (define-markup-command (property-recursive layout props symbol)
1883 "Print out a warning when a header field markup contains some recursive
1885 (ly:warning "Recursive definition of property ~a detected!" symbol)
1888 (define-markup-command (fromproperty layout props symbol)
1891 "Read the @var{symbol} from property settings, and produce a stencil
1892 from the markup contained within. If @var{symbol} is not defined, it
1893 returns an empty markup.
1895 @lilypond[verbatim,quote]
1897 myTitle = \"myTitle\"
1901 \\fromproperty #'header:myTitle
1908 (let ((m (chain-assoc-get symbol props)))
1910 ;; prevent infinite loops by clearing the interpreted property:
1911 (interpret-markup layout (cons (list (cons symbol `(,property-recursive-markup ,symbol))) props) m)
1914 (define-markup-command (on-the-fly layout props procedure arg)
1915 (procedure? markup?)
1917 "Apply the @var{procedure} markup command to @var{arg}.
1918 @var{procedure} should take a single argument."
1919 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1920 (set-object-property! anonymous-with-signature
1923 (interpret-markup layout props (list anonymous-with-signature arg))))
1925 (define-markup-command (footnote layout props mkup note)
1928 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
1930 @lilypond[verbatim,quote]
1933 \\override #'(padding . 0.2)
1937 The footnote will not be annotated automatically."
1938 (ly:stencil-combine-at-edge
1939 (interpret-markup layout props mkup)
1943 `(footnote (gensym "footnote") #f ,(interpret-markup layout props note))
1948 (define-markup-command (auto-footnote layout props mkup note)
1951 #:properties ((raise 0.5)
1953 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
1955 @lilypond[verbatim,quote]
1958 \\override #'(padding . 0.2)
1962 The footnote will be annotated automatically."
1963 (let* ((markup-stencil (interpret-markup layout props mkup))
1964 (footnote-hash (gensym "footnote"))
1966 (gauge-stencil (interpret-markup
1969 ((ly:output-def-lookup
1971 'footnote-numbering-function)
1973 (x-ext (ly:stencil-extent gauge-stencil X))
1974 (y-ext (ly:stencil-extent gauge-stencil Y))
1976 `(delay-stencil-evaluation
1980 (ly:output-def-lookup layout
1981 'number-footnote-table))
1982 (footnote-stencil (if (list? table)
1983 (assoc-get footnote-hash
1986 (footnote-stencil (if (ly:stencil? footnote-stencil)
1989 (ly:programming-error
1990 "Cannot find correct footnote for a markup object.")
1992 (gap (- (interval-length x-ext)
1994 (ly:stencil-extent footnote-stencil X))))
1995 (y-trans (- (+ (cdr y-ext)
1997 (cdr (ly:stencil-extent footnote-stencil
1999 (ly:stencil-translate footnote-stencil
2000 (cons gap y-trans)))))))
2001 (main-stencil (ly:stencil-combine-at-edge
2005 (ly:make-stencil footnote-number x-ext y-ext)
2010 `(footnote ,footnote-hash #t ,(interpret-markup layout props note))
2014 (define-markup-command (override layout props new-prop arg)
2018 @cindex overriding properties within text markup
2020 Add the argument @var{new-prop} to the property list. Properties
2021 may be any property supported by @rinternals{font-interface},
2022 @rinternals{text-interface} and
2023 @rinternals{instrument-specific-markup-interface}.
2025 @lilypond[verbatim,quote]
2033 \\override #'(baseline-skip . 4) {
2042 (interpret-markup layout (cons (list new-prop) props) arg))
2044 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2046 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2048 (define-markup-command (verbatim-file layout props name)
2051 "Read the contents of file @var{name}, and include it verbatim.
2053 @lilypond[verbatim,quote]
2055 \\verbatim-file #\"simple.ly\"
2058 (interpret-markup layout props
2059 (if (ly:get-option 'safe)
2060 "verbatim-file disabled in safe mode"
2061 (let* ((str (ly:gulp-file name))
2062 (lines (string-split str #\nl)))
2063 (make-typewriter-markup
2064 (make-column-markup lines))))))
2066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2071 (define-markup-command (smaller layout props arg)
2074 "Decrease the font size relative to the current setting.
2076 @lilypond[verbatim,quote]
2089 (interpret-markup layout props
2090 `(,fontsize-markup -1 ,arg)))
2092 (define-markup-command (larger layout props arg)
2095 "Increase the font size relative to the current setting.
2097 @lilypond[verbatim,quote]
2105 (interpret-markup layout props
2106 `(,fontsize-markup 1 ,arg)))
2108 (define-markup-command (finger layout props arg)
2111 "Set @var{arg} as small numbers.
2113 @lilypond[verbatim,quote]
2120 (interpret-markup layout
2121 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2124 (define-markup-command (abs-fontsize layout props size arg)
2127 "Use @var{size} as the absolute font size to display @var{arg}.
2128 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2130 @lilypond[verbatim,quote]
2132 default text font size
2134 \\abs-fontsize #16 { text font size 16 }
2136 \\abs-fontsize #12 { text font size 12 }
2139 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2140 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2141 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2142 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2143 (magnification (/ size ref-size)))
2147 `((baseline-skip . ,(* magnification ref-baseline))
2148 (word-space . ,(* magnification ref-word-space))
2149 (font-size . ,(magnification->font-size magnification)))
2153 (define-markup-command (fontsize layout props increment arg)
2156 #:properties ((font-size 0)
2159 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2162 @lilypond[verbatim,quote]
2173 `((baseline-skip . ,(* baseline-skip (magstep increment)))
2174 (word-space . ,(* word-space (magstep increment)))
2175 (font-size . ,(+ font-size increment)))
2179 (define-markup-command (magnify layout props sz arg)
2183 @cindex magnifying text
2185 Set the font magnification for its argument. In the following
2186 example, the middle@tie{}A is 10% larger:
2189 A \\magnify #1.1 @{ A @} A
2192 Note: Magnification only works if a font name is explicitly selected.
2193 Use @code{\\fontsize} otherwise.
2195 @lilypond[verbatim,quote]
2206 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2209 (define-markup-command (bold layout props arg)
2212 "Switch to bold font-series.
2214 @lilypond[verbatim,quote]
2222 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2224 (define-markup-command (sans layout props arg)
2227 "Switch to the sans serif font family.
2229 @lilypond[verbatim,quote]
2238 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2240 (define-markup-command (number layout props arg)
2243 "Set font family to @code{number}, which yields the font used for
2244 time signatures and fingerings. This font contains numbers and
2245 some punctuation; it has no letters.
2247 @lilypond[verbatim,quote]
2250 0 1 2 3 4 5 6 7 8 9 . ,
2254 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2256 (define-markup-command (roman layout props arg)
2259 "Set font family to @code{roman}.
2261 @lilypond[verbatim,quote]
2267 text in roman font family
2274 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2276 (define-markup-command (huge layout props arg)
2279 "Set font size to +2.
2281 @lilypond[verbatim,quote]
2289 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2291 (define-markup-command (large layout props arg)
2294 "Set font size to +1.
2296 @lilypond[verbatim,quote]
2304 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2306 (define-markup-command (normalsize layout props arg)
2309 "Set font size to default.
2311 @lilypond[verbatim,quote]
2324 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2326 (define-markup-command (small layout props arg)
2329 "Set font size to -1.
2331 @lilypond[verbatim,quote]
2339 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2341 (define-markup-command (tiny layout props arg)
2344 "Set font size to -2.
2346 @lilypond[verbatim,quote]
2354 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2356 (define-markup-command (teeny layout props arg)
2359 "Set font size to -3.
2361 @lilypond[verbatim,quote]
2369 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2371 (define-markup-command (fontCaps layout props arg)
2374 "Set @code{font-shape} to @code{caps}
2376 Note: @code{\\fontCaps} requires the installation and selection of
2377 fonts which support the @code{caps} font shape."
2378 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2381 (define-markup-command (smallCaps layout props arg)
2384 "Emit @var{arg} as small caps.
2386 Note: @code{\\smallCaps} does not support accented characters.
2388 @lilypond[verbatim,quote]
2397 (define (char-list->markup chars lower)
2398 (let ((final-string (string-upcase (reverse-list->string chars))))
2400 (markup #:fontsize -2 final-string)
2402 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2403 (if (null? rest-chars)
2405 (reverse! (cons (char-list->markup currents current-is-lower)
2407 (let* ((ch (car rest-chars))
2408 (is-lower (char-lower-case? ch)))
2409 (if (or (and current-is-lower is-lower)
2410 (and (not current-is-lower) (not is-lower)))
2411 (make-small-caps (cdr rest-chars)
2415 (make-small-caps (cdr rest-chars)
2418 (if (null? currents)
2420 (cons (char-list->markup
2421 currents current-is-lower)
2423 (interpret-markup layout props
2425 (make-small-caps (string->list arg) (list) #f (list))
2428 (define-markup-command (caps layout props arg)
2431 "Copy of the @code{\\smallCaps} command.
2433 @lilypond[verbatim,quote]
2442 (interpret-markup layout props (make-smallCaps-markup arg)))
2444 (define-markup-command (dynamic layout props arg)
2447 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2448 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2449 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2450 done in a different font. The recommended font for this is bold and italic.
2451 @lilypond[verbatim,quote]
2459 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2461 (define-markup-command (text layout props arg)
2464 "Use a text font instead of music symbol or music alphabet font.
2466 @lilypond[verbatim,quote]
2479 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2482 (define-markup-command (italic layout props arg)
2485 "Use italic @code{font-shape} for @var{arg}.
2487 @lilypond[verbatim,quote]
2495 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2497 (define-markup-command (typewriter layout props arg)
2500 "Use @code{font-family} typewriter for @var{arg}.
2502 @lilypond[verbatim,quote]
2511 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2513 (define-markup-command (upright layout props arg)
2516 "Set @code{font-shape} to @code{upright}. This is the opposite
2519 @lilypond[verbatim,quote]
2533 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2535 (define-markup-command (medium layout props arg)
2538 "Switch to medium font-series (in contrast to bold).
2540 @lilypond[verbatim,quote]
2553 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2556 (define-markup-command (normal-text layout props arg)
2559 "Set all font related properties (except the size) to get the default
2560 normal text font, no matter what font was used earlier.
2562 @lilypond[verbatim,quote]
2564 \\huge \\bold \\sans \\caps {
2576 (interpret-markup layout
2577 (cons '((font-family . roman) (font-shape . upright)
2578 (font-series . medium) (font-encoding . latin1))
2582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2586 (define-markup-command (musicglyph layout props glyph-name)
2589 "@var{glyph-name} is converted to a musical symbol; for example,
2590 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2591 the music font. See @ruser{The Feta font} for a complete listing of
2592 the possible glyphs.
2594 @lilypond[verbatim,quote]
2597 \\musicglyph #\"rests.2\"
2598 \\musicglyph #\"clefs.G_change\"
2601 (let* ((font (ly:paper-get-font layout
2602 (cons '((font-encoding . fetaMusic)
2606 (glyph (ly:font-get-glyph font glyph-name)))
2607 (if (null? (ly:stencil-expr glyph))
2608 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2612 (define-markup-command (doublesharp layout props)
2615 "Draw a double sharp symbol.
2617 @lilypond[verbatim,quote]
2622 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2624 (define-markup-command (sesquisharp layout props)
2627 "Draw a 3/2 sharp symbol.
2629 @lilypond[verbatim,quote]
2634 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2636 (define-markup-command (sharp layout props)
2639 "Draw a sharp symbol.
2641 @lilypond[verbatim,quote]
2646 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2648 (define-markup-command (semisharp layout props)
2651 "Draw a semisharp symbol.
2653 @lilypond[verbatim,quote]
2658 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2660 (define-markup-command (natural layout props)
2663 "Draw a natural symbol.
2665 @lilypond[verbatim,quote]
2670 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2672 (define-markup-command (semiflat layout props)
2675 "Draw a semiflat symbol.
2677 @lilypond[verbatim,quote]
2682 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2684 (define-markup-command (flat layout props)
2687 "Draw a flat symbol.
2689 @lilypond[verbatim,quote]
2694 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2696 (define-markup-command (sesquiflat layout props)
2699 "Draw a 3/2 flat symbol.
2701 @lilypond[verbatim,quote]
2706 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2708 (define-markup-command (doubleflat layout props)
2711 "Draw a double flat symbol.
2713 @lilypond[verbatim,quote]
2718 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2720 (define-markup-command (with-color layout props color arg)
2724 @cindex coloring text
2726 Draw @var{arg} in color specified by @var{color}.
2728 @lilypond[verbatim,quote]
2740 (let ((stil (interpret-markup layout props arg)))
2741 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2742 (ly:stencil-extent stil X)
2743 (ly:stencil-extent stil Y))))
2745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2749 (define-markup-command (arrow-head layout props axis dir filled)
2750 (integer? ly:dir? boolean?)
2752 "Produce an arrow head in specified direction and axis.
2753 Use the filled head if @var{filled} is specified.
2754 @lilypond[verbatim,quote]
2757 \\general-align #Y #DOWN {
2758 \\arrow-head #Y #UP ##t
2759 \\arrow-head #Y #DOWN ##f
2761 \\arrow-head #X #RIGHT ##f
2762 \\arrow-head #X #LEFT ##f
2768 ((name (format #f "arrowheads.~a.~a~a"
2775 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2779 (define-markup-command (lookup layout props glyph-name)
2782 "Lookup a glyph by name.
2784 @lilypond[verbatim,quote]
2786 \\override #'(font-encoding . fetaBraces) {
2787 \\lookup #\"brace200\"
2790 \\lookup #\"brace180\"
2794 (ly:font-get-glyph (ly:paper-get-font layout props)
2797 (define-markup-command (char layout props num)
2800 "Produce a single character. Characters encoded in hexadecimal
2801 format require the prefix @code{#x}.
2803 @lilypond[verbatim,quote]
2805 \\char #65 \\char ##x00a9
2808 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2810 (define number->mark-letter-vector (make-vector 25 #\A))
2815 (if (= i (- (char->integer #\I) (char->integer #\A)))
2817 (vector-set! number->mark-letter-vector j
2818 (integer->char (+ i (char->integer #\A)))))
2820 (define number->mark-alphabet-vector (list->vector
2821 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2823 (define (number->markletter-string vec n)
2824 "Double letters for big marks."
2825 (let* ((lst (vector-length vec)))
2828 (string-append (number->markletter-string vec (1- (quotient n lst)))
2829 (number->markletter-string vec (remainder n lst)))
2830 (make-string 1 (vector-ref vec n)))))
2832 (define-markup-command (markletter layout props num)
2835 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2836 (skipping letter@tie{}I), and continue with double letters.
2838 @lilypond[verbatim,quote]
2845 (ly:text-interface::interpret-markup layout props
2846 (number->markletter-string number->mark-letter-vector num)))
2848 (define-markup-command (markalphabet layout props num)
2851 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2852 and continue with double letters.
2854 @lilypond[verbatim,quote]
2861 (ly:text-interface::interpret-markup layout props
2862 (number->markletter-string number->mark-alphabet-vector num)))
2864 (define-public (horizontal-slash-interval num forward number-interval mag)
2866 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2867 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2868 (else (interval-widen number-interval (* mag 0.25))))
2869 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2870 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2871 (else (interval-widen number-interval (* mag 0.25))))
2874 (define-public (adjust-slash-stencil num forward stencil mag)
2877 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2879 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2881 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2883 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2886 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2888 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2893 (define (slashed-digit-internal layout props num forward font-size thickness)
2894 (let* ((mag (magstep font-size))
2896 (ly:output-def-lookup layout 'line-thickness)
2898 ; backward slashes might use slope and point in the other direction!
2899 (dy (* mag (if forward 0.4 -0.4)))
2900 (number-stencil (interpret-markup layout
2901 (prepend-alist-chain 'font-encoding 'fetaText props)
2902 (number->string num)))
2903 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2904 (center (interval-center (ly:stencil-extent number-stencil Y)))
2905 ; Use the real extents of the slash, not the whole number, because we
2906 ; might translate the slash later on!
2907 (num-y (interval-widen (cons center center) (abs dy)))
2908 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2909 (slash-stencil (if is-sane
2910 (make-line-stencil thickness
2911 (car num-x) (- (interval-center num-y) dy)
2912 (cdr num-x) (+ (interval-center num-y) dy))
2914 (if (ly:stencil? slash-stencil)
2916 ; for some numbers we need to shift the slash/backslash up or down to make
2917 ; the slashed digit look better
2918 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2919 (set! number-stencil
2920 (ly:stencil-add number-stencil slash-stencil)))
2921 (ly:warning "Unable to create slashed digit ~a" num))
2925 (define-markup-command (slashed-digit layout props num)
2928 #:properties ((font-size 0)
2931 @cindex slashed digits
2933 A feta number, with slash. This is for use in the context of
2934 figured bass notation.
2935 @lilypond[verbatim,quote]
2939 \\override #'(thickness . 3)
2943 (slashed-digit-internal layout props num #t font-size thickness))
2945 (define-markup-command (backslashed-digit layout props num)
2948 #:properties ((font-size 0)
2951 @cindex backslashed digits
2953 A feta number, with backslash. This is for use in the context of
2954 figured bass notation.
2955 @lilypond[verbatim,quote]
2957 \\backslashed-digit #5
2959 \\override #'(thickness . 3)
2960 \\backslashed-digit #7
2963 (slashed-digit-internal layout props num #f font-size thickness))
2966 (define eyeglassespath
2967 '((moveto 0.42 0.77)
2968 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2969 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2970 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2971 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2974 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2975 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2976 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2977 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2979 (moveto 1.025 0.935)
2980 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2981 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2984 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2987 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2989 (define-markup-command (eyeglasses layout props)
2992 "Prints out eyeglasses, indicating strongly to look at the conductor.
2993 @lilypond[verbatim,quote]
2994 \\markup { \\eyeglasses }
2996 (interpret-markup layout props
2997 (make-override-markup '(line-cap-style . butt)
2998 (make-path-markup 0.15 eyeglassespath))))
3000 (define-markup-command (left-brace layout props size)
3004 A feta brace in point size @var{size}.
3006 @lilypond[verbatim,quote]
3013 (let* ((font (ly:paper-get-font layout
3014 (cons '((font-encoding . fetaBraces)
3017 (glyph-count (1- (ly:otf-glyph-count font)))
3018 (scale (ly:output-def-lookup layout 'output-scale))
3019 (scaled-size (/ (ly:pt size) scale))
3021 (ly:font-get-glyph font (string-append "brace"
3022 (number->string n)))))
3023 (get-y-from-brace (lambda (brace)
3025 (ly:stencil-extent (glyph brace) Y))))
3026 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
3027 (glyph-found (glyph find-brace)))
3029 (if (or (null? (ly:stencil-expr glyph-found))
3030 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
3031 (> scaled-size (interval-length
3032 (ly:stencil-extent (glyph glyph-count) Y))))
3034 (ly:warning (_ "no brace found for point size ~S ") size)
3035 (ly:warning (_ "defaulting to ~S pt")
3036 (/ (* scale (interval-length
3037 (ly:stencil-extent glyph-found Y)))
3041 (define-markup-command (right-brace layout props size)
3045 A feta brace in point size @var{size}, rotated 180 degrees.
3047 @lilypond[verbatim,quote]
3054 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3057 ;; the note command.
3058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3060 ;; TODO: better syntax.
3062 (define-markup-command (note-by-number layout props log dot-count dir)
3063 (number? number? number?)
3065 #:properties ((font-size 0)
3068 @cindex notes within text by log and dot-count
3070 Construct a note symbol, with stem. By using fractional values for
3071 @var{dir}, longer or shorter stems can be obtained.
3073 @lilypond[verbatim,quote]
3075 \\note-by-number #3 #0 #DOWN
3077 \\note-by-number #1 #2 #0.8
3080 (define (get-glyph-name-candidates dir log style)
3081 (map (lambda (dir-name)
3082 (format #f "noteheads.~a~a" dir-name
3083 (if (and (symbol? style)
3084 (not (equal? 'default style)))
3085 (select-head-glyph style (min log 2))
3087 (list (if (= dir UP) "u" "d")
3090 (define (get-glyph-name font cands)
3093 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3094 (get-glyph-name font (cdr cands))
3097 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3099 (size-factor (magstep font-size))
3100 (stem-length (* size-factor (max 3 (- log 1))))
3102 (let ((result (get-glyph-name font (get-glyph-name-candidates
3103 (sign dir) log style))))
3104 (if (string-null? result)
3105 ;; If no glyph name can be found, select default heads. Though
3106 ;; this usually means an unsupported style has been chosen, it
3107 ;; also prevents unrelated 'style settings from other grobs
3108 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3109 (get-glyph-name font (get-glyph-name-candidates
3110 (sign dir) log 'default))
3112 (head-glyph (ly:font-get-glyph font head-glyph-name))
3113 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3114 (stem-thickness (* size-factor 0.13))
3115 (stemy (* dir stem-length))
3116 (attach-off (cons (interval-index
3117 (ly:stencil-extent head-glyph X)
3118 (* (sign dir) (car attach-indices)))
3119 (* (sign dir) ; fixme, this is inconsistent between X & Y.
3121 (ly:stencil-extent head-glyph Y)
3122 (cdr attach-indices)))))
3123 (stem-glyph (and (> log 0)
3124 (ly:round-filled-box
3125 (ordered-cons (car attach-off)
3127 (* (- (sign dir)) stem-thickness)))
3128 (cons (min stemy (cdr attach-off))
3129 (max stemy (cdr attach-off)))
3130 (/ stem-thickness 3))))
3132 (dot (ly:font-get-glyph font "dots.dot"))
3133 (dotwid (interval-length (ly:stencil-extent dot X)))
3134 (dots (and (> dot-count 0)
3135 (apply ly:stencil-add
3137 (ly:stencil-translate-axis
3138 dot (* 2 x dotwid) X))
3139 (iota dot-count)))))
3140 (flaggl (and (> log 2)
3141 (ly:stencil-translate
3142 (ly:font-get-glyph font
3143 (string-append "flags."
3144 (if (> dir 0) "u" "d")
3145 (number->string log)))
3146 (cons (+ (car attach-off) (if (< dir 0)
3150 ;; If there is a flag on an upstem and the stem is short, move the dots
3151 ;; to avoid the flag. 16th notes get a special case because their flags
3152 ;; hang lower than any other flags.
3153 (if (and dots (> dir 0) (> log 2)
3154 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3155 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3157 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3158 (if (ly:stencil? stem-glyph)
3159 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3160 (set! stem-glyph head-glyph))
3161 (if (ly:stencil? dots)
3164 (ly:stencil-translate-axis
3166 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3172 (let ((divisor (log 2)))
3173 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3175 (define (parse-simple-duration duration-string)
3176 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3177 and return a (log dots) list."
3178 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3180 (if (and match (string=? duration-string (match:substring match 0)))
3181 (let ((len (match:substring match 1))
3182 (dots (match:substring match 2)))
3183 (list (cond ((string=? len "breve") -1)
3184 ((string=? len "longa") -2)
3185 ((string=? len "maxima") -3)
3186 (else (log2 (string->number len))))
3187 (if dots (string-length dots) 0)))
3188 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3190 (define-markup-command (note layout props duration dir)
3193 #:properties (note-by-number-markup)
3195 @cindex notes within text by string
3197 This produces a note with a stem pointing in @var{dir} direction, with
3198 the @var{duration} for the note head type and augmentation dots. For
3199 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3200 a shortened down stem.
3202 @lilypond[verbatim,quote]
3204 \\override #'(style . cross) {
3208 \\note #\"breve\" #0
3211 (let ((parsed (parse-simple-duration duration)))
3212 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3215 ;; the rest command.
3216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3218 (define-markup-command (rest-by-number layout props log dot-count)
3221 #:properties ((font-size 0)
3223 (multi-measure-rest #f))
3225 @cindex rests or multi-measure-rests within text by log and dot-count
3227 A rest or multi-measure-rest symbol.
3229 @lilypond[verbatim,quote]
3231 \\rest-by-number #3 #2
3233 \\rest-by-number #0 #1
3235 \\override #'(multi-measure-rest . #t)
3236 \\rest-by-number #0 #0
3240 (define (get-glyph-name-candidates log style)
3241 (let* (;; Choose the style-string to be added.
3242 ;; If no glyph exists, select others for the specified styles
3243 ;; otherwise defaulting.
3246 ;; 'baroque needs to be special-cased, otherwise
3247 ;; `select-head-glyph´ would catch neomensural-glyphs for
3248 ;; this style, if (< log 0).
3249 (eq? style 'baroque)
3250 (string-append (number->string log) ""))
3251 ((eq? style 'petrucci)
3252 (string-append (number->string log) "mensural"))
3253 ;; In other cases `select-head-glyph´ from output-lib.scm
3254 ;; works for rest-glyphs, too.
3255 ((and (symbol? style) (not (eq? style 'default)))
3256 (select-head-glyph style log))
3258 ;; Choose ledgered glyphs for whole and half rest.
3259 ;; Except for the specified styles, logs and MultiMeasureRests.
3261 (if (and (or (list? style)
3263 '(neomensural mensural petrucci))))
3264 (not multi-measure-rest)
3265 (or (= log 0) (= log 1)))
3268 (format #f "rests.~a~a" style-strg ledger-style-rests)))
3270 (define (get-glyph-name font cands)
3271 (if (ly:stencil-empty? (ly:font-get-glyph font cands))
3276 (ly:paper-get-font layout
3277 (cons '((font-encoding . fetaMusic)) props)))
3280 (get-glyph-name font
3281 (get-glyph-name-candidates log style))))
3282 (if (string-null? result)
3283 ;; If no glyph name can be found, select default rests. Though
3284 ;; this usually means an unsupported style has been chosen, it
3285 ;; also prevents unrelated 'style settings from other grobs
3286 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3287 (get-glyph-name font (get-glyph-name-candidates log 'default))
3289 (rest-glyph (ly:font-get-glyph font rest-glyph-name))
3290 (dot (ly:font-get-glyph font "dots.dot"))
3291 (dot-width (interval-length (ly:stencil-extent dot X)))
3292 (dots (and (> dot-count 0)
3293 (apply ly:stencil-add
3295 (ly:stencil-translate-axis
3296 dot (* 2 x dot-width) X))
3297 (iota dot-count))))))
3299 ;; Apart from mensural-, neomensural- and petrucci-style ledgered
3300 ;; glyphs are taken for whole and half rests.
3301 ;; If they are dotted, move the dots in X-direction to avoid collision.
3305 (not (member style '(neomensural mensural petrucci))))
3306 (set! dots (ly:stencil-translate-axis dots dot-width X)))
3308 ;; Add dots to the rest-glyph.
3310 ;; Not sure how to vertical align dots.
3311 ;; For now the dots are centered for half, whole or longer rests.
3312 ;; Otherwise placed near the top of the rest.
3314 ;; Dots for rests with (< log 0) dots are allowed, but not
3315 ;; if multi-measure-rest is set #t.
3316 (if (and (not multi-measure-rest) dots)
3319 (ly:stencil-translate
3322 (+ (cdr (ly:stencil-extent rest-glyph X)) dot-width)
3324 (interval-center (ly:stencil-extent rest-glyph Y))
3325 (- (interval-end (ly:stencil-extent rest-glyph Y))
3326 (/ (* 2 dot-width) 3)))))
3330 (define-markup-command (rest layout props duration)
3333 #:properties ((style '())
3334 (multi-measure-rest #f)
3335 (multi-measure-rest-number #t)
3338 @cindex rests or multi-measure-rests within text by string
3340 This produces a rest, with the @var{duration} for the rest type and
3342 @code{\"breve\"}, @code{\"longa\"} and @code{\"maxima\"} are valid
3345 Printing MultiMeasureRests could be enabled with
3346 @code{\\override #'(multi-measure-rest . #t)}
3347 If MultiMeasureRests are taken, the MultiMeasureRestNumber is printed above.
3348 This is enabled for all styles using default-glyphs.
3349 Could be disabled with @code{\\override #'(multi-measure-rest-number . #f)}
3351 @lilypond[verbatim,quote]
3357 \\override #'(multi-measure-rest . #t)
3361 \\override #'(multi-measure-rest-number . #f)
3366 ;; Get the number of mmr-glyphs.
3367 ;; Store them in a list.
3368 ;; example: (mmr-numbers 25) -> '(3 0 0 1)
3369 (define (mmr-numbers nmbr)
3370 (let* ((8-bar-glyph (floor (/ nmbr 8)))
3371 (8-remainder (remainder nmbr 8))
3372 (4-bar-glyph (floor (/ 8-remainder 4)))
3373 (4-remainder (remainder nmbr 4))
3374 (2-bar-glyph (floor (/ 4-remainder 2)))
3375 (2-remainder (remainder 4-remainder 2))
3376 (1-bar-glyph (floor (/ 2-remainder 1))))
3377 (list 8-bar-glyph 4-bar-glyph 2-bar-glyph 1-bar-glyph)))
3379 ;; Get the correct mmr-glyphs.
3380 ;; Store them in a list.
3382 ;; (get-mmr-glyphs '(1 0 1 0) '("rests.M3" "rests.M2" "rests.M1" "rests.0"))
3383 ;; -> ("rests.M3" "rests.M1")
3384 (define (get-mmr-glyphs lst1 lst2)
3385 (define (helper l1 l2 l3)
3390 (append (make-list (car l1) (car l2)) l3))))
3391 (helper lst1 lst2 '()))
3393 ;; If duration is not valid, print a warning and return empty-stencil
3394 (if (or (and (not (integer? (car (parse-simple-duration duration))))
3395 (not multi-measure-rest))
3396 (and (= (string-length (car (string-split duration #\. ))) 1)
3397 (= (string->number (car (string-split duration #\. ))) 0)))
3399 (ly:warning (_ "not a valid duration string: ~a - ignoring") duration)
3402 ;; For simple rests:
3403 ;; Get a (log dots) list.
3404 (parsed (parse-simple-duration duration))
3405 ;; Create the rest-stencil
3407 (rest-by-number-markup layout props (car parsed) (cadr parsed)))
3408 ;; For MultiMeasureRests:
3409 ;; Get the duration-part of duration
3410 (dur-part-string (car (string-split duration #\. )))
3411 ;; Get the duration of MMR:
3412 ;; If not a number (eg. "maxima") calculate it.
3414 (or (string->number dur-part-string) (expt 2 (abs (car parsed)))))
3415 ;; Get a list of the correct number of each mmr-glyph.
3416 (count-mmr-glyphs-list (mmr-numbers mmr-duration))
3417 ;; Create a list of mmr-stencils,
3418 ;; translating the glyph for a whole rest.
3422 (let ((single-mmr-stil
3423 (rest-by-number-markup layout props (* -1 x) 0)))
3425 (ly:stencil-translate-axis
3427 ;; Ugh, hard-coded, why 1?
3431 (get-mmr-glyphs count-mmr-glyphs-list (reverse (iota 4)))))
3432 ;; Adjust the space between the mmr-glyphs,
3433 ;; if not default-glyphs are used.
3434 (word-space (if (member style
3435 '(neomensural mensural petrucci))
3436 (/ (* word-space 2) 3)
3438 ;; Create the final mmr-stencil
3439 ;; via `stack-stencil-line´ from /scm/markup.scm
3440 (mmr-stil (stack-stencil-line word-space mmr-stils-list)))
3442 ;; Print the number above a multi-measure-rest
3443 ;; Depends on duration, style and multi-measure-rest-number set #t
3444 (if (and multi-measure-rest
3445 multi-measure-rest-number
3447 (not (member style '(neomensural mensural petrucci))))
3448 (let* ((mmr-stil-x-center
3449 (interval-center (ly:stencil-extent mmr-stil X)))
3453 #:override '(font-encoding . fetaText)
3454 (number->string mmr-duration)))
3456 (interpret-markup layout props duration-markup))
3457 (mmr-number-stil-x-center
3458 (interval-center (ly:stencil-extent mmr-number-stil X))))
3460 (set! mmr-stil (ly:stencil-combine-at-edge
3463 (ly:stencil-translate-axis
3465 (- mmr-stil-x-center mmr-number-stil-x-center)
3469 (if multi-measure-rest
3473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3475 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3477 (define-markup-command (lower layout props amount arg)
3481 @cindex lowering text
3483 Lower @var{arg} by the distance @var{amount}.
3484 A negative @var{amount} indicates raising; see also @code{\\raise}.
3486 @lilypond[verbatim,quote]
3494 (ly:stencil-translate-axis (interpret-markup layout props arg)
3497 (define-markup-command (translate-scaled layout props offset arg)
3498 (number-pair? markup?)
3500 #:properties ((font-size 0))
3502 @cindex translating text
3503 @cindex scaling text
3505 Translate @var{arg} by @var{offset}, scaling the offset by the
3508 @lilypond[verbatim,quote]
3511 * \\translate #'(2 . 3) translate
3513 * \\translate-scaled #'(2 . 3) translate-scaled
3517 (let* ((factor (magstep font-size))
3518 (scaled (cons (* factor (car offset))
3519 (* factor (cdr offset)))))
3520 (ly:stencil-translate (interpret-markup layout props arg)
3523 (define-markup-command (raise layout props amount arg)
3527 @cindex raising text
3529 Raise @var{arg} by the distance @var{amount}.
3530 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3532 The argument to @code{\\raise} is the vertical displacement amount,
3533 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3534 raise objects in relation to their surrounding markups.
3536 If the text object itself is positioned above or below the staff, then
3537 @code{\\raise} cannot be used to move it, since the mechanism that
3538 positions it next to the staff cancels any shift made with
3539 @code{\\raise}. For vertical positioning, use the @code{padding}
3540 and/or @code{extra-offset} properties.
3542 @lilypond[verbatim,quote]
3551 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3553 (define-markup-command (fraction layout props arg1 arg2)
3556 #:properties ((font-size 0))
3558 @cindex creating text fractions
3560 Make a fraction of two markups.
3561 @lilypond[verbatim,quote]
3567 (let* ((m1 (interpret-markup layout props arg1))
3568 (m2 (interpret-markup layout props arg2))
3569 (factor (magstep font-size))
3570 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3571 (padding (* factor 0.2))
3572 (baseline (* factor 0.6))
3573 (offset (* factor 0.75)))
3574 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3575 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3576 (let* ((x1 (ly:stencil-extent m1 X))
3577 (x2 (ly:stencil-extent m2 X))
3578 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3579 ;; should stack mols separately, to maintain LINE on baseline
3580 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3582 (ly:stencil-aligned-to stack Y CENTER))
3584 (ly:stencil-aligned-to stack X LEFT))
3585 ;; should have EX dimension
3587 (ly:stencil-translate-axis stack offset Y))))
3589 (define-markup-command (normal-size-super layout props arg)
3592 #:properties ((baseline-skip))
3594 @cindex setting superscript in standard font size
3596 Set @var{arg} in superscript with a normal font size.
3598 @lilypond[verbatim,quote]
3601 \\normal-size-super {
3602 superscript in standard size
3606 (ly:stencil-translate-axis
3607 (interpret-markup layout props arg)
3608 (* 0.5 baseline-skip) Y))
3610 (define-markup-command (super layout props arg)
3613 #:properties ((font-size 0)
3616 @cindex superscript text
3618 Set @var{arg} in superscript.
3620 @lilypond[verbatim,quote]
3630 (ly:stencil-translate-axis
3633 (cons `((font-size . ,(- font-size 3))) props)
3635 (* 0.5 baseline-skip)
3638 (define-markup-command (translate layout props offset arg)
3639 (number-pair? markup?)
3642 @cindex translating text
3644 Translate @var{arg} relative to its surroundings. @var{offset}
3645 is a pair of numbers representing the displacement in the X and Y axis.
3647 @lilypond[verbatim,quote]
3650 \\translate #'(2 . 3)
3651 \\line { translated two spaces right, three up }
3654 (ly:stencil-translate (interpret-markup layout props arg)
3657 (define-markup-command (sub layout props arg)
3660 #:properties ((font-size 0)
3663 @cindex subscript text
3665 Set @var{arg} in subscript.
3667 @lilypond[verbatim,quote]
3678 (ly:stencil-translate-axis
3681 (cons `((font-size . ,(- font-size 3))) props)
3683 (* -0.5 baseline-skip)
3686 (define-markup-command (normal-size-sub layout props arg)
3689 #:properties ((baseline-skip))
3691 @cindex setting subscript in standard font size
3693 Set @var{arg} in subscript with a normal font size.
3695 @lilypond[verbatim,quote]
3699 subscript in standard size
3703 (ly:stencil-translate-axis
3704 (interpret-markup layout props arg)
3705 (* -0.5 baseline-skip)
3708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3712 (define-markup-command (hbracket layout props arg)
3716 @cindex placing horizontal brackets around text
3718 Draw horizontal brackets around @var{arg}.
3720 @lilypond[verbatim,quote]
3729 (let ((th 0.1) ;; todo: take from GROB.
3730 (m (interpret-markup layout props arg)))
3731 (bracketify-stencil m X th (* 2.5 th) th)))
3733 (define-markup-command (bracket layout props arg)
3737 @cindex placing vertical brackets around text
3739 Draw vertical brackets around @var{arg}.
3741 @lilypond[verbatim,quote]
3748 (let ((th 0.1) ;; todo: take from GROB.
3749 (m (interpret-markup layout props arg)))
3750 (bracketify-stencil m Y th (* 2.5 th) th)))
3752 (define-markup-command (parenthesize layout props arg)
3755 #:properties ((angularity 0)
3761 @cindex placing parentheses around text
3763 Draw parentheses around @var{arg}. This is useful for parenthesizing
3764 a column containing several lines of text.
3766 @lilypond[verbatim,quote]
3775 \\override #'(angularity . 2) {
3786 (let* ((markup (interpret-markup layout props arg))
3787 (scaled-width (* size width))
3789 (* (chain-assoc-get 'line-thickness props 0.1)
3792 (min (* size 0.5 scaled-thickness)
3793 (* (/ 4 3.0) scaled-width)))
3794 (padding (chain-assoc-get 'padding props half-thickness)))
3795 (parenthesize-stencil
3796 markup half-thickness scaled-width angularity padding)))
3799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3800 ;; Delayed markup evaluation
3801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3803 (define-markup-command (page-ref layout props label gauge default)
3804 (symbol? markup? markup?)
3807 @cindex referencing page numbers in text
3809 Reference to a page number. @var{label} is the label set on the referenced
3810 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3811 the maximum width of the page number, and @var{default} the value to display
3812 when @var{label} is not found."
3813 (let* ((gauge-stencil (interpret-markup layout props gauge))
3814 (x-ext (ly:stencil-extent gauge-stencil X))
3815 (y-ext (ly:stencil-extent gauge-stencil Y)))
3817 `(delay-stencil-evaluation
3818 ,(delay (ly:stencil-expr
3819 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3820 (page-number (if (list? table)
3821 (assoc-get label table)
3823 (page-markup (if page-number (format #f "~a" page-number) default))
3824 (page-stencil (interpret-markup layout props page-markup))
3825 (gap (- (interval-length x-ext)
3826 (interval-length (ly:stencil-extent page-stencil X)))))
3827 (interpret-markup layout props
3828 (markup #:concat (#:hspace gap page-markup)))))))
3832 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3836 (define-markup-command (scale layout props factor-pair arg)
3837 (number-pair? markup?)
3840 @cindex scaling markup
3841 @cindex mirroring markup
3843 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3844 representing the scaling-factor in the X and Y axes.
3845 Negative values may be used to produce mirror images.
3847 @lilypond[verbatim,quote]
3857 (let ((stil (interpret-markup layout props arg))
3858 (sx (car factor-pair))
3859 (sy (cdr factor-pair)))
3860 (ly:stencil-scale stil sx sy)))
3862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3866 (define-markup-command (pattern layout props count axis space pattern)
3867 (integer? integer? number? markup?)
3870 Prints @var{count} times a @var{pattern} markup.
3871 Patterns are spaced apart by @var{space}.
3872 Patterns are distributed on @var{axis}.
3874 @lilypond[verbatim, quote]
3876 \"Horizontally repeated :\"
3877 \\pattern #7 #X #2 \\flat
3879 \"Vertically repeated :\"
3880 \\pattern #3 #Y #0.5 \\flat
3883 (let ((pattern-width (interval-length
3884 (ly:stencil-extent (interpret-markup layout props pattern) X)))
3885 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3886 (let loop ((i (1- count)) (patterns (markup)))
3892 (markup patterns pattern)
3893 (markup #:column (patterns pattern))))
3896 (markup patterns pattern #:hspace space)
3897 (markup #:column (patterns pattern #:vspace space))))))))
3899 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3900 (number? ly:dir? markup? markup? markup?)
3902 #:properties ((word-space)
3905 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3906 with a line of markups @var{pattern} in between.
3907 Patterns are spaced apart by @var{space}.
3908 Patterns are aligned to the @var{dir} markup.
3910 @lilypond[verbatim, quote]
3913 \\fill-with-pattern #1 #RIGHT . first right
3914 \\fill-with-pattern #1 #RIGHT . second right
3916 \"center-aligned :\"
3917 \\fill-with-pattern #1.5 #CENTER - left right
3920 \\override #'(line-width . 50)
3921 \\fill-with-pattern #2 #LEFT : left first
3922 \\override #'(line-width . 50)
3923 \\fill-with-pattern #2 #LEFT : left second
3926 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3927 (pattern-width (interval-length pattern-x-extent))
3928 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3929 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3930 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
3931 (period (+ space pattern-width))
3932 (count (truncate (/ (- middle-width pattern-width) period)))
3933 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3934 (interpret-markup layout props
3936 #:with-dimensions (cons 0 middle-width) '(0 . 0)
3937 #:translate (cons x-offset 0)
3938 #:pattern (1+ count) X space pattern
3941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3945 (define-markup-command (replace layout props replacements arg)
3949 Used to automatically replace a string by another in the markup @var{arg}.
3950 Each pair of the alist @var{replacements} specifies what should be replaced.
3951 The @code{key} is the string to be replaced by the @code{value} string.
3953 @lilypond[verbatim, quote]
3954 \\markup \\replace #'((\"thx\" . \"Thanks!\")) thx
3958 (internal-add-text-replacements
3963 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3964 ;; Markup list commands
3965 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3967 (define-public (space-lines baseline stils)
3968 (let space-stil ((stils stils)
3972 (let* ((stil (car stils))
3973 (dy-top (max (- (/ baseline 1.5)
3974 (interval-bound (ly:stencil-extent stil Y) UP))
3976 (dy-bottom (max (+ (/ baseline 3.0)
3977 (interval-bound (ly:stencil-extent stil Y) DOWN))
3979 (new-stil (ly:make-stencil
3980 (ly:stencil-expr stil)
3981 (ly:stencil-extent stil X)
3982 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3984 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3986 (space-stil (cdr stils) (cons new-stil result))))))
3988 (define-markup-list-command (justified-lines layout props args)
3990 #:properties ((baseline-skip)
3991 wordwrap-internal-markup-list)
3993 @cindex justifying lines of text
3995 Like @code{\\justify}, but return a list of lines instead of a single markup.
3996 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3997 @var{X}@tie{}is the number of staff spaces."
3998 (space-lines baseline-skip
3999 (interpret-markup-list layout props
4000 (make-wordwrap-internal-markup-list #t args))))
4002 (define-markup-list-command (wordwrap-lines layout props args)
4004 #:properties ((baseline-skip)
4005 wordwrap-internal-markup-list)
4006 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
4007 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
4008 where @var{X} is the number of staff spaces."
4009 (space-lines baseline-skip
4010 (interpret-markup-list layout props
4011 (make-wordwrap-internal-markup-list #f args))))
4013 (define-markup-list-command (column-lines layout props args)
4015 #:properties ((baseline-skip))
4016 "Like @code{\\column}, but return a list of lines instead of a single markup.
4017 @code{baseline-skip} determines the space between each markup in @var{args}."
4018 (space-lines baseline-skip
4019 (interpret-markup-list layout props args)))
4021 (define-markup-list-command (override-lines layout props new-prop args)
4022 (pair? markup-list?)
4023 "Like @code{\\override}, for markup lists."
4024 (interpret-markup-list layout (cons (list new-prop) props) args))