1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (define-builtin-markup-command (draw-line layout props dest)
31 @cindex drawing lines within text
34 @lilypond[verbatim,quote]
37 \\override #'(thickness . 5)
38 \\draw-line #'(-3 . 0)
41 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
45 (make-line-stencil th 0 0 x y)))
47 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
48 (number? number? boolean?)
52 @cindex drawing circles within text
54 A circle of radius @var{radius}, thickness @var{thickness} and
57 @lilypond[verbatim,quote]
59 \\draw-circle #2 #0.5 ##f
61 \\draw-circle #2 #0 ##t
64 (make-circle-stencil radius thickness fill))
66 (define-builtin-markup-command (triangle layout props filled)
73 @cindex drawing triangles within text
75 A triangle, either filled or empty.
77 @lilypond[verbatim,quote]
84 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
93 (cons 0 (* .86 ex)))))
95 (define-builtin-markup-command (circle layout props arg)
100 (circle-padding 0.2))
102 @cindex circling text
104 Draw a circle around @var{arg}. Use @code{thickness},
105 @code{circle-padding} and @code{font-size} properties to determine line
106 thickness and padding around the markup.
108 @lilypond[verbatim,quote]
115 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
117 (pad (* (magstep font-size) circle-padding))
118 (m (interpret-markup layout props arg)))
119 (circle-stencil m th pad)))
121 (define-builtin-markup-command (with-url layout props url arg)
126 @cindex inserting URL links into text
128 Add a link to URL @var{url} around @var{arg}. This only works in
131 @lilypond[verbatim,quote]
133 \\with-url #\"http://lilypond.org/web/\" {
134 LilyPond ... \\italic {
135 music notation for everyone
140 (let* ((stil (interpret-markup layout props arg))
141 (xextent (ly:stencil-extent stil X))
142 (yextent (ly:stencil-extent stil Y))
143 (old-expr (ly:stencil-expr stil))
144 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
146 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
148 (define-builtin-markup-command (beam layout props width slope thickness)
149 (number? number? number?)
153 @cindex drawing beams within text
155 Create a beam with the specified parameters.
156 @lilypond[verbatim,quote]
161 (let* ((y (* slope width))
162 (yext (cons (min 0 y) (max 0 y)))
163 (half (/ thickness 2)))
168 width (+ (* width slope) (/ thickness -2))
169 width (+ (* width slope) (/ thickness 2))
171 ,(ly:output-def-lookup layout 'blot-diameter)
174 (cons (+ (- half) (car yext))
175 (+ half (cdr yext))))))
177 (define-builtin-markup-command (underline layout props arg)
182 @cindex underlining text
184 Underline @var{arg}. Looks at @code{thickness} to determine line
185 thickness and y offset.
187 @lilypond[verbatim,quote]
191 \\override #'(thickness . 2)
197 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
199 (markup (interpret-markup layout props arg))
200 (x1 (car (ly:stencil-extent markup X)))
201 (x2 (cdr (ly:stencil-extent markup X)))
203 (line (make-line-stencil thick x1 y x2 y)))
204 (ly:stencil-add markup line)))
206 (define-builtin-markup-command (box layout props arg)
213 @cindex enclosing text within a box
215 Draw a box round @var{arg}. Looks at @code{thickness},
216 @code{box-padding} and @code{font-size} properties to determine line
217 thickness and padding around the markup.
219 @lilypond[verbatim,quote]
221 \\override #'(box-padding . 0.5)
226 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
228 (pad (* (magstep font-size) box-padding))
229 (m (interpret-markup layout props arg)))
230 (box-stencil m th pad)))
232 (define-builtin-markup-command (filled-box layout props xext yext blot)
233 (number-pair? number-pair? number?)
237 @cindex drawing solid boxes within text
238 @cindex drawing boxes with rounded corners
240 Draw a box with rounded corners of dimensions @var{xext} and
241 @var{yext}. For example,
243 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
245 creates a box extending horizontally from -0.3 to 1.8 and
246 vertically from -0.3 up to 1.8, with corners formed from a
247 circle of diameter@tie{}0 (i.e. sharp corners).
249 @lilypond[verbatim,quote]
251 \\filled-box #'(0 . 4) #'(0 . 4) #0
252 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
253 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
255 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
261 (define-builtin-markup-command (rounded-box layout props arg)
268 "@cindex enclosing text in a box with rounded corners
269 @cindex drawing boxes with rounded corners around text
270 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
271 @code{box-padding} and @code{font-size} properties to determine line
272 thickness and padding around the markup; the @code{corner-radius} property
273 makes it possible to define another shape for the corners (default is 1).
275 @lilypond[quote,verbatim,relative=2]
283 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
285 (pad (* (magstep font-size) box-padding))
286 (m (interpret-markup layout props arg)))
287 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
290 (define-builtin-markup-command (rotate layout props ang arg)
295 @cindex rotating text
297 Rotate object with @var{ang} degrees around its center.
299 @lilypond[verbatim,quote]
309 (let* ((stil (interpret-markup layout props arg)))
310 (ly:stencil-rotate stil ang 0 0)))
312 (define-builtin-markup-command (whiteout layout props arg)
317 @cindex adding a white background to text
319 Provide a white background for @var{arg}.
321 @lilypond[verbatim,quote]
324 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
328 (stencil-whiteout (interpret-markup layout props arg)))
330 (define-builtin-markup-command (pad-markup layout props padding arg)
336 @cindex putting space around text
338 Add space around a markup object.
340 @lilypond[verbatim,quote]
354 ((stil (interpret-markup layout props arg))
355 (xext (ly:stencil-extent stil X))
356 (yext (ly:stencil-extent stil Y)))
359 (ly:stencil-expr stil)
360 (interval-widen xext padding)
361 (interval-widen yext padding))))
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
367 (define-builtin-markup-command (strut layout props)
372 @cindex creating vertical spaces in text
374 Create a box of the same height as the space in the current font."
375 (let ((m (ly:text-interface::interpret-markup layout props " ")))
376 (ly:make-stencil (ly:stencil-expr m)
378 (ly:stencil-extent m X)
381 ;; todo: fix negative space
382 (define-builtin-markup-command (hspace layout props amount)
387 @cindex creating horizontal spaces in text
389 This produces an invisible object taking horizontal space. For example,
392 \\markup @{ A \\hspace #2.0 B @}
396 puts extra space between A and@tie{}B, on top of the space that is
397 normally inserted before elements on a line.
399 @lilypond[verbatim,quote]
409 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
410 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
414 ;; importing graphics.
415 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
417 (define-builtin-markup-command (stencil layout props stil)
422 @cindex importing stencils into text
424 Use a stencil as markup.
426 @lilypond[verbatim,quote]
428 \\stencil #(make-circle-stencil 2 0 #t)
434 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
436 (define (get-postscript-bbox string)
437 "Extract the bbox from STRING, or return #f if not present."
439 ((match (regexp-exec bbox-regexp string)))
443 (string->number (match:substring match x)))
448 (define-builtin-markup-command (epsfile layout props axis size file-name)
449 (number? number? string?)
453 @cindex inlining an Encapsulated PostScript image
455 Inline an EPS image. The image is scaled along @var{axis} to
458 @lilypond[verbatim,quote]
460 \\general-align #Y #DOWN {
461 \\epsfile #X #20 #\"context-example.eps\"
462 \\epsfile #Y #20 #\"context-example.eps\"
466 (if (ly:get-option 'safe)
467 (interpret-markup layout props "not allowed in safe")
468 (eps-file->stencil axis size file-name)
471 (define-builtin-markup-command (postscript layout props str)
476 @cindex inserting PostScript directly into text
478 This inserts @var{str} directly into the output as a PostScript
479 command string. Due to technicalities of the output backends,
480 different scales should be used for the @TeX{} and PostScript backend,
481 selected with @code{-f}.
483 For the @TeX{} backend, the following string prints a rotated text
486 0 0 moveto /ecrm10 findfont
487 1.75 scalefont setfont 90 rotate (hello) show
491 The magical constant 1.75 scales from LilyPond units (staff spaces) to
494 For the postscript backend, use the following
497 gsave /ecrm10 findfont
498 10.0 output-scale div
499 scalefont setfont 90 rotate (hello) show grestore
502 @lilypond[verbatim,quote]
508 0.7 0.7 0.5 0 361 arc
510 2.20 0.70 0.50 0 361 arc
512 1.45 0.85 0.30 0 180 arc
516 0.92 2.26 1.30 2.40 1.15 1.70 curveto
520 3.42 2.26 3.80 2.40 3.65 1.70 curveto
523 eyeglasses = \\markup {
524 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
525 \\postscript #eyeglassesps
537 gsave currentpoint translate
545 (define-builtin-markup-command (score layout props score)
550 @cindex inserting music into text
552 Inline an image of music.
554 @lilypond[verbatim,quote]
558 \\new Staff \\relative c' {
561 \\mark \\markup { Allegro }
567 \\new Staff \\relative c {
581 \\override RehearsalMark #'break-align-symbols =
582 #'(time-signature key-signature)
583 \\override RehearsalMark #'self-alignment-X = #LEFT
587 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
593 (let* ((output (ly:score-embedded-format score layout)))
595 (if (ly:music-output? output)
596 (paper-system-stencil
597 (vector-ref (ly:paper-score-paper-systems output) 0))
599 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
602 (define-builtin-markup-command (null layout props)
607 @cindex creating empty text objects
609 An empty markup with extents of a single point.
611 @lilypond[verbatim,quote]
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
620 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
622 (define-builtin-markup-command (simple layout props str)
627 @cindex simple text strings
629 A simple text string; @code{\\markup @{ foo @}} is equivalent with
630 @code{\\markup @{ \\simple #\"foo\" @}}.
632 Note: for creating standard text markup or defining new markup commands,
633 the use of @code{\\simple} is unnecessary.
635 @lilypond[verbatim,quote]
639 \\simple #\"strings\"
642 (interpret-markup layout props str))
644 (define-builtin-markup-command (tied-lyric layout props str)
649 @cindex simple text strings with tie characters
651 Like simple-markup, but use tie characters for @q{~} tilde symbols.
653 @lilypond[verbatim,quote]
655 \\tied-lyric #\"Lasciate~i monti\"
658 (if (string-contains str "~")
660 ((parts (string-split str #\~))
661 (tie-str (ly:wide-char->utf-8 #x203f))
662 (joined (list-join parts tie-str))
663 (join-stencil (interpret-markup layout props tie-str))
666 (interpret-markup layout
669 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
671 (make-line-markup joined)))
672 ;(map (lambda (s) (interpret-markup layout props s)) parts))
673 (interpret-markup layout props str)))
675 (define-public empty-markup
676 (make-simple-markup ""))
678 ;; helper for justifying lines.
679 (define (get-fill-space word-count line-width text-widths)
680 "Calculate the necessary paddings between each two adjacent texts.
681 The lengths of all texts are stored in @var{text-widths}.
682 The normal formula for the padding between texts a and b is:
683 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
684 The first and last padding have to be calculated specially using the
685 whole length of the first or last text.
686 Return a list of paddings."
688 ((null? text-widths) '())
690 ;; special case first padding
691 ((= (length text-widths) word-count)
693 (- (- (/ line-width (1- word-count)) (car text-widths))
694 (/ (car (cdr text-widths)) 2))
695 (get-fill-space word-count line-width (cdr text-widths))))
696 ;; special case last padding
697 ((= (length text-widths) 2)
698 (list (- (/ line-width (1- word-count))
699 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
702 (- (/ line-width (1- word-count))
703 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
704 (get-fill-space word-count line-width (cdr text-widths))))))
706 (define-builtin-markup-command (fill-line layout props markups)
709 ((text-direction RIGHT)
712 "Put @var{markups} in a horizontal line of width @var{line-width}.
713 The markups are spaced or flushed to fill the entire line.
714 If there are no arguments, return an empty stencil.
716 @lilypond[verbatim,quote]
720 Words evenly spaced across the page
724 \\line { Text markups }
726 \\italic { evenly spaced }
728 \\line { across the page }
733 (let* ((orig-stencils (interpret-markup-list layout props markups))
736 (if (ly:stencil-empty? stc)
738 stc)) orig-stencils))
741 (if (ly:stencil-empty? stc)
743 (interval-length (ly:stencil-extent stc X))))
745 (text-width (apply + text-widths))
746 (word-count (length stencils))
747 (prop-line-width (chain-assoc-get 'line-width props #f))
748 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
753 (/ (- line-width text-width) 2)
754 (/ (- line-width text-width) 2)))
757 (- line-width text-width)))
759 (get-fill-space word-count line-width text-widths))))
767 (line-stencils (if (= word-count 1)
774 (if (= text-direction LEFT)
775 (set! line-stencils (reverse line-stencils)))
777 (if (null? (remove ly:stencil-empty? orig-stencils))
779 (stack-stencils-padding-list X
780 RIGHT fill-space-normal line-stencils))))
782 (define-builtin-markup-command (line layout props args)
786 (text-direction RIGHT))
787 "Put @var{args} in a horizontal line. The property @code{word-space}
788 determines the space between each markup in @var{args}.
790 @lilypond[verbatim,quote]
797 (let ((stencils (interpret-markup-list layout props args)))
798 (if (= text-direction LEFT)
799 (set! stencils (reverse stencils)))
802 (remove ly:stencil-empty? stencils))))
804 (define-builtin-markup-command (concat layout props args)
809 @cindex concatenating text
810 @cindex ligatures in text
812 Concatenate @var{args} in a horizontal line, without spaces inbetween.
813 Strings and simple markups are concatenated on the input level, allowing
814 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
815 equivalent to @code{\"fi\"}.
817 @lilypond[verbatim,quote]
826 (define (concat-string-args arg-list)
827 (fold-right (lambda (arg result-list)
828 (let ((result (if (pair? result-list)
831 (if (and (pair? arg) (eqv? (car arg) simple-markup))
832 (set! arg (cadr arg)))
833 (if (and (string? result) (string? arg))
834 (cons (string-append arg result) (cdr result-list))
835 (cons arg result-list))))
839 (interpret-markup layout
840 (prepend-alist-chain 'word-space 0 props)
841 (make-line-markup (if (markup-command-list? args)
843 (concat-string-args args)))))
845 (define (wordwrap-stencils stencils
846 justify base-space line-width text-dir)
847 "Perform simple wordwrap, return stencil of each line."
848 (define space (if justify
849 ;; justify only stretches lines.
852 (define (take-list width space stencils
853 accumulator accumulated-width)
854 "Return (head-list . tail) pair, with head-list fitting into width"
856 (cons accumulator stencils)
857 (let* ((first (car stencils))
858 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
859 (newwid (+ space first-wid accumulated-width)))
860 (if (or (null? accumulator)
862 (take-list width space
864 (cons first accumulator)
866 (cons accumulator stencils)))))
867 (let loop ((lines '())
869 (let* ((line-break (take-list line-width space todo
871 (line-stencils (car line-break))
872 (space-left (- line-width
873 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
875 (line-word-space (cond ((not justify) space)
876 ;; don't stretch last line of paragraph.
877 ;; hmmm . bug - will overstretch the last line in some case.
878 ((null? (cdr line-break))
880 ((null? line-stencils) 0.0)
881 ((null? (cdr line-stencils)) 0.0)
882 (else (/ space-left (1- (length line-stencils))))))
883 (line (stack-stencil-line line-word-space
884 (if (= text-dir RIGHT)
885 (reverse line-stencils)
887 (if (pair? (cdr line-break))
888 (loop (cons line lines)
891 (if (= text-dir LEFT)
893 (ly:stencil-translate-axis
895 (- line-width (interval-end (ly:stencil-extent line X)))
897 (reverse (cons line lines)))))))
899 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
900 (boolean? markup-list?)
903 (text-direction RIGHT))
904 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
905 (wordwrap-stencils (remove ly:stencil-empty?
906 (interpret-markup-list layout props args))
910 (ly:output-def-lookup layout 'line-width))
913 (define-builtin-markup-command (justify layout props args)
917 wordwrap-internal-markup-list)
919 @cindex justifying text
921 Like wordwrap, but with lines stretched to justify the margins.
922 Use @code{\\override #'(line-width . @var{X})} to set the line width;
923 @var{X}@tie{}is the number of staff spaces.
925 @lilypond[verbatim,quote]
928 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
929 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
930 Ut enim ad minim veniam, quis nostrud exercitation ullamco
931 laboris nisi ut aliquip ex ea commodo consequat.
935 (stack-lines DOWN 0.0 baseline-skip
936 (wordwrap-internal-markup-list layout props #t args)))
938 (define-builtin-markup-command (wordwrap layout props args)
942 wordwrap-internal-markup-list)
943 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
944 the line width, where @var{X} is the number of staff spaces.
946 @lilypond[verbatim,quote]
949 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
950 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
951 Ut enim ad minim veniam, quis nostrud exercitation ullamco
952 laboris nisi ut aliquip ex ea commodo consequat.
956 (stack-lines DOWN 0.0 baseline-skip
957 (wordwrap-internal-markup-list layout props #f args)))
959 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
963 (text-direction RIGHT))
964 "Internal markup list command used to define @code{\\justify-string} and
965 @code{\\wordwrap-string}."
966 (let* ((para-strings (regexp-split
967 (string-regexp-substitute
969 (string-regexp-substitute "\r\n" "\n" arg))
970 "\n[ \t\n]*\n[ \t\n]*"))
971 (list-para-words (map (lambda (str)
972 (regexp-split str "[ \t\n]+"))
974 (para-lines (map (lambda (words)
976 (remove ly:stencil-empty?
978 (interpret-markup layout props x))
980 (wordwrap-stencils stencils
982 line-width text-direction)))
984 (apply append para-lines)))
986 (define-builtin-markup-command (wordwrap-string layout props arg)
990 wordwrap-string-internal-markup-list)
991 "Wordwrap a string. Paragraphs may be separated with double newlines.
993 @lilypond[verbatim,quote]
995 \\override #'(line-width . 40)
996 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
997 adipisicing elit, sed do eiusmod tempor incididunt ut labore
998 et dolore magna aliqua.
1001 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1002 laboris nisi ut aliquip ex ea commodo consequat.
1005 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1006 qui officia deserunt mollit anim id est laborum\"
1009 (stack-lines DOWN 0.0 baseline-skip
1010 (wordwrap-string-internal-markup-list layout props #f arg)))
1012 (define-builtin-markup-command (justify-string layout props arg)
1016 wordwrap-string-internal-markup-list)
1017 "Justify a string. Paragraphs may be separated with double newlines
1019 @lilypond[verbatim,quote]
1021 \\override #'(line-width . 40)
1022 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1023 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1024 et dolore magna aliqua.
1027 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1028 laboris nisi ut aliquip ex ea commodo consequat.
1031 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1032 qui officia deserunt mollit anim id est laborum\"
1035 (stack-lines DOWN 0.0 baseline-skip
1036 (wordwrap-string-internal-markup-list layout props #t arg)))
1038 (define-builtin-markup-command (wordwrap-field layout props symbol)
1042 "Wordwrap the data which has been assigned to @var{symbol}.
1044 @lilypond[verbatim,quote]
1046 title = \"My title\"
1047 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1048 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1049 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1050 nisi ut aliquip ex ea commodo consequat.\"
1054 bookTitleMarkup = \\markup {
1056 \\fill-line { \\fromproperty #'header:title }
1058 \\wordwrap-field #'header:descr
1067 (let* ((m (chain-assoc-get symbol props)))
1069 (wordwrap-string-markup layout props m)
1072 (define-builtin-markup-command (justify-field layout props symbol)
1076 "Justify the data which has been assigned to @var{symbol}.
1078 @lilypond[verbatim,quote]
1080 title = \"My title\"
1081 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1082 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1083 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1084 nisi ut aliquip ex ea commodo consequat.\"
1088 bookTitleMarkup = \\markup {
1090 \\fill-line { \\fromproperty #'header:title }
1092 \\justify-field #'header:descr
1101 (let* ((m (chain-assoc-get symbol props)))
1103 (justify-string-markup layout props m)
1106 (define-builtin-markup-command (combine layout props m1 m2)
1111 @cindex merging text
1113 Print two markups on top of each other.
1115 Note: @code{\\combine} cannot take a list of markups enclosed in
1116 curly braces as an argument; the follow example will not compile:
1119 \\combine @{ a list @}
1122 @lilypond[verbatim,quote]
1125 \\override #'(thickness . 2)
1127 \\draw-line #'(0 . 4)
1128 \\arrow-head #Y #DOWN ##f
1131 (let* ((s1 (interpret-markup layout props m1))
1132 (s2 (interpret-markup layout props m2)))
1133 (ly:stencil-add s1 s2)))
1136 ;; TODO: should extract baseline-skip from each argument somehow..
1138 (define-builtin-markup-command (column layout props args)
1143 @cindex stacking text in a column
1145 Stack the markups in @var{args} vertically. The property
1146 @code{baseline-skip} determines the space between each
1147 markup in @var{args}.
1149 @lilypond[verbatim,quote]
1158 (let ((arg-stencils (interpret-markup-list layout props args)))
1159 (stack-lines -1 0.0 baseline-skip
1160 (remove ly:stencil-empty? arg-stencils))))
1162 (define-builtin-markup-command (dir-column layout props args)
1168 @cindex changing direction of text columns
1170 Make a column of args, going up or down, depending on the setting
1171 of the @code{#'direction} layout property.
1173 @lilypond[verbatim,quote]
1175 \\override #'(direction . 1) {
1185 (stack-lines (if (number? direction) direction -1)
1188 (interpret-markup-list layout props args)))
1190 (define (general-column align-dir baseline mols)
1191 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1193 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1194 (stack-lines -1 0.0 baseline aligned-mols)))
1196 (define-builtin-markup-command (center-column layout props args)
1201 @cindex centering a column of text
1203 Put @code{args} in a centered column.
1205 @lilypond[verbatim,quote]
1214 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1216 (define-builtin-markup-command (left-column layout props args)
1221 @cindex text columns, left-aligned
1223 Put @code{args} in a left-aligned column.
1225 @lilypond[verbatim,quote]
1234 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1236 (define-builtin-markup-command (right-column layout props args)
1241 @cindex text columns, right-aligned
1243 Put @code{args} in a right-aligned column.
1245 @lilypond[verbatim,quote]
1254 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1256 (define-builtin-markup-command (vcenter layout props arg)
1261 @cindex vertically centering text
1263 Align @code{arg} to its Y@tie{}center.
1265 @lilypond[verbatim,quote]
1273 (let* ((mol (interpret-markup layout props arg)))
1274 (ly:stencil-aligned-to mol Y CENTER)))
1276 (define-builtin-markup-command (center-align layout props arg)
1281 @cindex horizontally centering text
1283 Align @code{arg} to its X@tie{}center.
1285 @lilypond[verbatim,quote]
1295 (let* ((mol (interpret-markup layout props arg)))
1296 (ly:stencil-aligned-to mol X CENTER)))
1298 (define-builtin-markup-command (right-align layout props arg)
1303 @cindex right aligning text
1305 Align @var{arg} on its right edge.
1307 @lilypond[verbatim,quote]
1317 (let* ((m (interpret-markup layout props arg)))
1318 (ly:stencil-aligned-to m X RIGHT)))
1320 (define-builtin-markup-command (left-align layout props arg)
1325 @cindex left aligning text
1327 Align @var{arg} on its left edge.
1329 @lilypond[verbatim,quote]
1339 (let* ((m (interpret-markup layout props arg)))
1340 (ly:stencil-aligned-to m X LEFT)))
1342 (define-builtin-markup-command (general-align layout props axis dir arg)
1343 (integer? number? markup?)
1347 @cindex controlling general text alignment
1349 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1351 @lilypond[verbatim,quote]
1355 \\general-align #X #LEFT
1360 \\general-align #X #CENTER
1366 \\general-align #Y #UP
1373 \\general-align #Y #3.2
1380 (let* ((m (interpret-markup layout props arg)))
1381 (ly:stencil-aligned-to m axis dir)))
1383 (define-builtin-markup-command (halign layout props dir arg)
1388 @cindex setting horizontal text alignment
1390 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1391 left-aligned, while @code{+1} is right. Values in between interpolate
1392 alignment accordingly.
1394 @lilypond[verbatim,quote]
1419 (let* ((m (interpret-markup layout props arg)))
1420 (ly:stencil-aligned-to m X dir)))
1422 (define-builtin-markup-command (with-dimensions layout props x y arg)
1423 (number-pair? number-pair? markup?)
1427 @cindex setting extent of text objects
1429 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1430 (let* ((m (interpret-markup layout props arg)))
1431 (ly:make-stencil (ly:stencil-expr m) x y)))
1433 (define-builtin-markup-command (pad-around layout props amount arg)
1437 "Add padding @var{amount} all around @var{arg}.
1439 @lilypond[verbatim,quote]
1452 (let* ((m (interpret-markup layout props arg))
1453 (x (ly:stencil-extent m X))
1454 (y (ly:stencil-extent m Y)))
1455 (ly:make-stencil (ly:stencil-expr m)
1456 (interval-widen x amount)
1457 (interval-widen y amount))))
1459 (define-builtin-markup-command (pad-x layout props amount arg)
1464 @cindex padding text horizontally
1466 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1468 @lilypond[verbatim,quote]
1481 (let* ((m (interpret-markup layout props arg))
1482 (x (ly:stencil-extent m X))
1483 (y (ly:stencil-extent m Y)))
1484 (ly:make-stencil (ly:stencil-expr m)
1485 (interval-widen x amount)
1488 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1489 (integer? ly:dir? markup? markup?)
1492 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1493 (let ((m1 (interpret-markup layout props arg1))
1494 (m2 (interpret-markup layout props arg2)))
1495 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1497 (define-builtin-markup-command (transparent layout props arg)
1501 "Make the argument transparent.
1503 @lilypond[verbatim,quote]
1510 (let* ((m (interpret-markup layout props arg))
1511 (x (ly:stencil-extent m X))
1512 (y (ly:stencil-extent m Y)))
1513 (ly:make-stencil "" x y)))
1515 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1516 (number-pair? number-pair? markup?)
1519 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1521 @lilypond[verbatim,quote]
1528 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1534 (let* ((m (interpret-markup layout props arg))
1535 (x (ly:stencil-extent m X))
1536 (y (ly:stencil-extent m Y)))
1537 (ly:make-stencil (ly:stencil-expr m)
1538 (interval-union x-ext x)
1539 (interval-union y-ext y))))
1541 (define-builtin-markup-command (hcenter-in layout props length arg)
1545 "Center @var{arg} horizontally within a box of extending
1546 @var{length}/2 to the left and right.
1548 @lilypond[quote,verbatim]
1551 \\set Staff.instrumentName = \\markup {
1558 \\set Staff.instrumentName = \\markup {
1567 (interpret-markup layout props
1568 (make-pad-to-box-markup
1569 (cons (/ length -2) (/ length 2))
1571 (make-center-align-markup arg))))
1573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1575 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1577 (define-builtin-markup-command (fromproperty layout props symbol)
1581 "Read the @var{symbol} from property settings, and produce a stencil
1582 from the markup contained within. If @var{symbol} is not defined, it
1583 returns an empty markup.
1585 @lilypond[verbatim,quote]
1587 myTitle = \"myTitle\"
1591 \\fromproperty #'header:myTitle
1598 (let ((m (chain-assoc-get symbol props)))
1600 (interpret-markup layout props m)
1603 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1607 "Apply the @var{procedure} markup command to @var{arg}.
1608 @var{procedure} should take a single argument."
1609 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1610 (set-object-property! anonymous-with-signature
1613 (interpret-markup layout props (list anonymous-with-signature arg))))
1615 (define-builtin-markup-command (override layout props new-prop arg)
1620 @cindex overriding properties within text markup
1622 Add the first argument in to the property list. Properties may be
1623 any sort of property supported by @rinternals{font-interface} and
1624 @rinternals{text-interface}, for example
1627 \\override #'(font-family . married) \"bla\"
1630 @lilypond[verbatim,quote]
1638 \\override #'(baseline-skip . 4) {
1647 (interpret-markup layout (cons (list new-prop) props) arg))
1649 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1653 (define-builtin-markup-command (verbatim-file layout props name)
1657 "Read the contents of a file, and include it verbatim.
1659 @lilypond[verbatim,quote]
1661 \\verbatim-file #\"simple.ly\"
1664 (interpret-markup layout props
1665 (if (ly:get-option 'safe)
1666 "verbatim-file disabled in safe mode"
1667 (let* ((str (ly:gulp-file name))
1668 (lines (string-split str #\nl)))
1669 (make-typewriter-markup
1670 (make-column-markup lines))))))
1672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1676 (define-builtin-markup-command (bigger layout props arg)
1680 "Increase the font size relative to current setting.
1682 @lilypond[verbatim,quote]
1695 (interpret-markup layout props
1696 `(,fontsize-markup 1 ,arg)))
1698 (define-builtin-markup-command (smaller layout props arg)
1702 "Decrease the font size relative to current setting.
1704 @lilypond[verbatim,quote]
1717 (interpret-markup layout props
1718 `(,fontsize-markup -1 ,arg)))
1720 (define-builtin-markup-command (larger layout props arg)
1724 "Copy of the @code{\\bigger} command.
1726 @lilypond[verbatim,quote]
1734 (interpret-markup layout props (make-bigger-markup arg)))
1736 (define-builtin-markup-command (finger layout props arg)
1740 "Set the argument as small numbers.
1741 @lilypond[verbatim,quote]
1748 (interpret-markup layout
1749 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1752 (define-builtin-markup-command (abs-fontsize layout props size arg)
1756 "Use @var{size} as the absolute font size to display @var{arg}.
1757 Adjust baseline skip and word space accordingly.
1758 @lilypond[verbatim,quote]
1760 default text font size
1762 \\abs-fontsize #16 { text font size 16 }
1764 \\abs-fontsize #12 { text font size 12 }
1767 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1768 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1769 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1770 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1771 (magnification (/ size ref-size)))
1772 (interpret-markup layout
1773 (cons `((baseline-skip . ,(* magnification ref-baseline))
1774 (word-space . ,(* magnification ref-word-space))
1775 (font-size . ,(magnification->font-size magnification)))
1779 (define-builtin-markup-command (fontsize layout props increment arg)
1785 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1786 @lilypond[verbatim,quote]
1794 (let ((entries (list
1795 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1796 (cons 'word-space (* word-space (magstep increment)))
1797 (cons 'font-size (+ font-size increment)))))
1798 (interpret-markup layout (cons entries props) arg)))
1800 (define-builtin-markup-command (magnify layout props sz arg)
1805 @cindex magnifying text
1807 Set the font magnification for its argument. In the following
1808 example, the middle@tie{}A is 10% larger:
1811 A \\magnify #1.1 @{ A @} A
1814 Note: Magnification only works if a font name is explicitly selected.
1815 Use @code{\\fontsize} otherwise.
1817 @lilypond[verbatim,quote]
1828 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1831 (define-builtin-markup-command (bold layout props arg)
1835 "Switch to bold font-series.
1837 @lilypond[verbatim,quote]
1845 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1847 (define-builtin-markup-command (sans layout props arg)
1851 "Switch to the sans serif family.
1853 @lilypond[verbatim,quote]
1862 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1864 (define-builtin-markup-command (number layout props arg)
1868 "Set font family to @code{number}, which yields the font used for
1869 time signatures and fingerings. This font only contains numbers and
1870 some punctuation. It doesn't have any letters.
1872 @lilypond[verbatim,quote]
1875 0 1 2 3 4 5 6 7 8 9 . ,
1879 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1881 (define-builtin-markup-command (roman layout props arg)
1885 "Set font family to @code{roman}.
1887 @lilypond[verbatim,quote]
1893 text in roman font family
1900 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1902 (define-builtin-markup-command (huge layout props arg)
1906 "Set font size to +2.
1908 @lilypond[verbatim,quote]
1916 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1918 (define-builtin-markup-command (large layout props arg)
1922 "Set font size to +1.
1924 @lilypond[verbatim,quote]
1932 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1934 (define-builtin-markup-command (normalsize layout props arg)
1938 "Set font size to default.
1940 @lilypond[verbatim,quote]
1953 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1955 (define-builtin-markup-command (small layout props arg)
1959 "Set font size to -1.
1961 @lilypond[verbatim,quote]
1969 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1971 (define-builtin-markup-command (tiny layout props arg)
1975 "Set font size to -2.
1977 @lilypond[verbatim,quote]
1985 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1987 (define-builtin-markup-command (teeny layout props arg)
1991 "Set font size to -3.
1993 @lilypond[verbatim,quote]
2001 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2003 (define-builtin-markup-command (fontCaps layout props arg)
2007 "Set @code{font-shape} to @code{caps}
2009 Note: @code{\\fontCaps} requires the installation and selection of
2010 fonts which support the @code{caps} font shape."
2011 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2014 (define-builtin-markup-command (smallCaps layout props text)
2018 "Emit @var{arg} as small caps.
2020 Note: @code{\\smallCaps} does not support accented characters.
2022 @lilypond[verbatim,quote]
2031 (define (char-list->markup chars lower)
2032 (let ((final-string (string-upcase (reverse-list->string chars))))
2034 (markup #:fontsize -2 final-string)
2036 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2037 (if (null? rest-chars)
2039 (reverse! (cons (char-list->markup currents current-is-lower)
2041 (let* ((ch (car rest-chars))
2042 (is-lower (char-lower-case? ch)))
2043 (if (or (and current-is-lower is-lower)
2044 (and (not current-is-lower) (not is-lower)))
2045 (make-small-caps (cdr rest-chars)
2049 (make-small-caps (cdr rest-chars)
2052 (if (null? currents)
2054 (cons (char-list->markup
2055 currents current-is-lower)
2057 (interpret-markup layout props
2059 (make-small-caps (string->list text) (list) #f (list))
2062 (define-builtin-markup-command (caps layout props arg)
2066 "Copy of the @code{\\smallCaps} command.
2068 @lilypond[verbatim,quote]
2077 (interpret-markup layout props (make-smallCaps-markup arg)))
2079 (define-builtin-markup-command (dynamic layout props arg)
2083 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2084 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2085 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2086 done in a different font. The recommended font for this is bold and italic.
2087 @lilypond[verbatim,quote]
2095 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2097 (define-builtin-markup-command (text layout props arg)
2101 "Use a text font instead of music symbol or music alphabet font.
2103 @lilypond[verbatim,quote]
2116 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2119 (define-builtin-markup-command (italic layout props arg)
2123 "Use italic @code{font-shape} for @var{arg}.
2125 @lilypond[verbatim,quote]
2133 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2135 (define-builtin-markup-command (typewriter layout props arg)
2139 "Use @code{font-family} typewriter for @var{arg}.
2141 @lilypond[verbatim,quote]
2150 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2152 (define-builtin-markup-command (upright layout props arg)
2156 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
2158 @lilypond[verbatim,quote]
2172 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2174 (define-builtin-markup-command (medium layout props arg)
2178 "Switch to medium font series (in contrast to bold).
2180 @lilypond[verbatim,quote]
2193 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2196 (define-builtin-markup-command (normal-text layout props arg)
2200 "Set all font related properties (except the size) to get the default
2201 normal text font, no matter what font was used earlier.
2203 @lilypond[verbatim,quote]
2205 \\huge \\bold \\sans \\caps {
2206 Some text with font overrides
2209 Default text, same font-size
2217 (interpret-markup layout
2218 (cons '((font-family . roman) (font-shape . upright)
2219 (font-series . medium) (font-encoding . latin1))
2223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2227 (define-builtin-markup-command (doublesharp layout props)
2231 "Draw a double sharp symbol.
2233 @lilypond[verbatim,quote]
2238 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2240 (define-builtin-markup-command (sesquisharp layout props)
2244 "Draw a 3/2 sharp symbol.
2246 @lilypond[verbatim,quote]
2251 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2253 (define-builtin-markup-command (sharp layout props)
2257 "Draw a sharp symbol.
2259 @lilypond[verbatim,quote]
2264 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2266 (define-builtin-markup-command (semisharp layout props)
2270 "Draw a semi sharp symbol.
2272 @lilypond[verbatim,quote]
2277 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2279 (define-builtin-markup-command (natural layout props)
2283 "Draw a natural symbol.
2285 @lilypond[verbatim,quote]
2290 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2292 (define-builtin-markup-command (semiflat layout props)
2296 "Draw a semiflat symbol.
2298 @lilypond[verbatim,quote]
2303 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2305 (define-builtin-markup-command (flat layout props)
2309 "Draw a flat symbol.
2311 @lilypond[verbatim,quote]
2316 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2318 (define-builtin-markup-command (sesquiflat layout props)
2322 "Draw a 3/2 flat symbol.
2324 @lilypond[verbatim,quote]
2329 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2331 (define-builtin-markup-command (doubleflat layout props)
2335 "Draw a double flat symbol.
2337 @lilypond[verbatim,quote]
2342 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2344 (define-builtin-markup-command (with-color layout props color arg)
2349 @cindex coloring text
2351 Draw @var{arg} in color specified by @var{color}.
2353 @lilypond[verbatim,quote]
2365 (let ((stil (interpret-markup layout props arg)))
2366 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2367 (ly:stencil-extent stil X)
2368 (ly:stencil-extent stil Y))))
2370 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2374 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2375 (integer? ly:dir? boolean?)
2378 "Produce an arrow head in specified direction and axis.
2379 Use the filled head if @var{filled} is specified.
2380 @lilypond[verbatim,quote]
2383 \\general-align #Y #DOWN {
2384 \\arrow-head #Y #UP ##t
2385 \\arrow-head #Y #DOWN ##f
2387 \\arrow-head #X #RIGHT ##f
2388 \\arrow-head #X #LEFT ##f
2394 ((name (format "arrowheads.~a.~a~a"
2401 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2405 (define-builtin-markup-command (musicglyph layout props glyph-name)
2409 "@var{glyph-name} is converted to a musical symbol; for example,
2410 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2411 the music font. See @ruser{The Feta font} for a complete listing of
2412 the possible glyphs.
2414 @lilypond[verbatim,quote]
2417 \\musicglyph #\"rests.2\"
2418 \\musicglyph #\"clefs.G_change\"
2421 (let* ((font (ly:paper-get-font layout
2422 (cons '((font-encoding . fetaMusic)
2426 (glyph (ly:font-get-glyph font glyph-name)))
2427 (if (null? (ly:stencil-expr glyph))
2428 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2433 (define-builtin-markup-command (lookup layout props glyph-name)
2437 "Lookup a glyph by name.
2439 @lilypond[verbatim,quote]
2441 \\override #'(font-encoding . fetaBraces) {
2442 \\lookup #\"brace200\"
2445 \\lookup #\"brace180\"
2449 (ly:font-get-glyph (ly:paper-get-font layout props)
2452 (define-builtin-markup-command (char layout props num)
2456 "Produce a single character. For example, @code{\\char #65} produces the
2459 @lilypond[verbatim,quote]
2464 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2466 (define number->mark-letter-vector (make-vector 25 #\A))
2471 (if (= i (- (char->integer #\I) (char->integer #\A)))
2473 (vector-set! number->mark-letter-vector j
2474 (integer->char (+ i (char->integer #\A)))))
2476 (define number->mark-alphabet-vector (list->vector
2477 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2479 (define (number->markletter-string vec n)
2480 "Double letters for big marks."
2481 (let* ((lst (vector-length vec)))
2484 (string-append (number->markletter-string vec (1- (quotient n lst)))
2485 (number->markletter-string vec (remainder n lst)))
2486 (make-string 1 (vector-ref vec n)))))
2488 (define-builtin-markup-command (markletter layout props num)
2492 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2493 (skipping letter@tie{}I), and continue with double letters.
2495 @lilypond[verbatim,quote]
2502 (ly:text-interface::interpret-markup layout props
2503 (number->markletter-string number->mark-letter-vector num)))
2505 (define-builtin-markup-command (markalphabet layout props num)
2509 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2510 and continue with double letters.
2512 @lilypond[verbatim,quote]
2519 (ly:text-interface::interpret-markup layout props
2520 (number->markletter-string number->mark-alphabet-vector num)))
2522 (define-public (horizontal-slash-interval num forward number-interval mag)
2524 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2525 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2526 (else (interval-widen number-interval (* mag 0.25))))
2527 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2528 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2529 (else (interval-widen number-interval (* mag 0.25))))
2532 (define-public (adjust-slash-stencil num forward stencil mag)
2535 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2537 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2539 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2541 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2544 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2546 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2551 (define (slashed-digit-internal layout props num forward font-size thickness)
2552 (let* ((mag (magstep font-size))
2554 (ly:output-def-lookup layout 'line-thickness)
2556 ; backward slashes might use slope and point in the other direction!
2557 (dy (* mag (if forward 0.4 -0.4)))
2558 (number-stencil (interpret-markup layout
2559 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2560 (number->string num)))
2561 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2562 (center (interval-center (ly:stencil-extent number-stencil Y)))
2563 ; Use the real extents of the slash, not the whole number, because we
2564 ; might translate the slash later on!
2565 (num-y (interval-widen (cons center center) (abs dy)))
2566 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2567 (slash-stencil (if is-sane
2568 (make-line-stencil thickness
2569 (car num-x) (- (interval-center num-y) dy)
2570 (cdr num-x) (+ (interval-center num-y) dy))
2572 (if (ly:stencil? slash-stencil)
2574 ; for some numbers we need to shift the slash/backslash up or down to make
2575 ; the slashed digit look better
2576 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2577 (set! number-stencil
2578 (ly:stencil-add number-stencil slash-stencil)))
2579 (ly:warning "Unable to create slashed digit ~a" num))
2583 (define-builtin-markup-command (slashed-digit layout props num)
2589 @cindex slashed digits
2591 A feta number, with slash. This is for use in the context of
2592 figured bass notation.
2593 @lilypond[verbatim,quote]
2597 \\override #'(thickness . 3)
2601 (slashed-digit-internal layout props num #t font-size thickness))
2603 (define-builtin-markup-command (backslashed-digit layout props num)
2609 @cindex backslashed digits
2611 A feta number, with backslash. This is for use in the context of
2612 figured bass notation.
2613 @lilypond[verbatim,quote]
2615 \\backslashed-digit #5
2617 \\override #'(thickness . 3)
2618 \\backslashed-digit #7
2621 (slashed-digit-internal layout props num #f font-size thickness))
2623 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2624 ;; the note command.
2625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2627 ;; TODO: better syntax.
2629 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2630 (number? number? number?)
2635 @cindex notes within text by log and dot-count
2637 Construct a note symbol, with stem. By using fractional values for
2638 @var{dir}, you can obtain longer or shorter stems.
2640 @lilypond[verbatim,quote]
2642 \\note-by-number #3 #0 #DOWN
2644 \\note-by-number #1 #2 #0.8
2647 (define (get-glyph-name-candidates dir log style)
2648 (map (lambda (dir-name)
2649 (format "noteheads.~a~a~a" dir-name (min log 2)
2650 (if (and (symbol? style)
2651 (not (equal? 'default style)))
2652 (symbol->string style)
2654 (list (if (= dir UP) "u" "d")
2657 (define (get-glyph-name font cands)
2660 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2661 (get-glyph-name font (cdr cands))
2664 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2665 (size-factor (magstep font-size))
2666 (stem-length (* size-factor (max 3 (- log 1))))
2667 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2668 (head-glyph (ly:font-get-glyph font head-glyph-name))
2669 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2670 (stem-thickness (* size-factor 0.13))
2671 (stemy (* dir stem-length))
2672 (attach-off (cons (interval-index
2673 (ly:stencil-extent head-glyph X)
2674 (* (sign dir) (car attach-indices)))
2675 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2677 (ly:stencil-extent head-glyph Y)
2678 (cdr attach-indices)))))
2679 (stem-glyph (and (> log 0)
2680 (ly:round-filled-box
2681 (ordered-cons (car attach-off)
2682 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2683 (cons (min stemy (cdr attach-off))
2684 (max stemy (cdr attach-off)))
2685 (/ stem-thickness 3))))
2687 (dot (ly:font-get-glyph font "dots.dot"))
2688 (dotwid (interval-length (ly:stencil-extent dot X)))
2689 (dots (and (> dot-count 0)
2690 (apply ly:stencil-add
2692 (ly:stencil-translate-axis
2693 dot (* 2 x dotwid) X))
2694 (iota dot-count)))))
2695 (flaggl (and (> log 2)
2696 (ly:stencil-translate
2697 (ly:font-get-glyph font
2698 (string-append "flags."
2699 (if (> dir 0) "u" "d")
2700 (number->string log)))
2701 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2703 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2704 ; 16th notes get a special case because their flags hang lower than any other flags.
2705 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2706 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2708 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2709 (if (ly:stencil? stem-glyph)
2710 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2711 (set! stem-glyph head-glyph))
2712 (if (ly:stencil? dots)
2715 (ly:stencil-translate-axis
2717 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2723 (let ((divisor (log 2)))
2724 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2726 (define (parse-simple-duration duration-string)
2727 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2728 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2729 (if (and match (string=? duration-string (match:substring match 0)))
2730 (let ((len (match:substring match 1))
2731 (dots (match:substring match 2)))
2732 (list (cond ((string=? len "breve") -1)
2733 ((string=? len "longa") -2)
2734 ((string=? len "maxima") -3)
2735 (else (log2 (string->number len))))
2736 (if dots (string-length dots) 0)))
2737 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2739 (define-builtin-markup-command (note layout props duration dir)
2742 (note-by-number-markup)
2744 @cindex notes within text by string
2746 This produces a note with a stem pointing in @var{dir} direction, with
2747 the @var{duration} for the note head type and augmentation dots. For
2748 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2749 a shortened down stem.
2751 @lilypond[verbatim,quote]
2753 \\override #'(style . cross) {
2757 \\note #\"breve\" #0
2760 (let ((parsed (parse-simple-duration duration)))
2761 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2765 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2767 (define-builtin-markup-command (lower layout props amount arg)
2772 @cindex lowering text
2774 Lower @var{arg} by the distance @var{amount}.
2775 A negative @var{amount} indicates raising; see also @code{\\raise}.
2777 @lilypond[verbatim,quote]
2785 (ly:stencil-translate-axis (interpret-markup layout props arg)
2788 (define-builtin-markup-command (translate-scaled layout props offset arg)
2789 (number-pair? markup?)
2793 @cindex translating text
2794 @cindex scaling text
2796 Translate @var{arg} by @var{offset}, scaling the offset by the
2799 @lilypond[verbatim,quote]
2802 * \\translate #'(2 . 3) translate
2804 * \\translate-scaled #'(2 . 3) translate-scaled
2808 (let* ((factor (magstep font-size))
2809 (scaled (cons (* factor (car offset))
2810 (* factor (cdr offset)))))
2811 (ly:stencil-translate (interpret-markup layout props arg)
2814 (define-builtin-markup-command (raise layout props amount arg)
2819 @cindex raising text
2821 Raise @var{arg} by the distance @var{amount}.
2822 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2824 The argument to @code{\\raise} is the vertical displacement amount,
2825 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2826 raise objects in relation to their surrounding markups.
2828 If the text object itself is positioned above or below the staff, then
2829 @code{\\raise} cannot be used to move it, since the mechanism that
2830 positions it next to the staff cancels any shift made with
2831 @code{\\raise}. For vertical positioning, use the @code{padding}
2832 and/or @code{extra-offset} properties.
2834 @lilypond[verbatim,quote]
2843 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2845 (define-builtin-markup-command (fraction layout props arg1 arg2)
2850 @cindex creating text fractions
2852 Make a fraction of two markups.
2853 @lilypond[verbatim,quote]
2859 (let* ((m1 (interpret-markup layout props arg1))
2860 (m2 (interpret-markup layout props arg2))
2861 (factor (magstep font-size))
2862 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2863 (padding (* factor 0.2))
2864 (baseline (* factor 0.6))
2865 (offset (* factor 0.75)))
2866 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2867 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2868 (let* ((x1 (ly:stencil-extent m1 X))
2869 (x2 (ly:stencil-extent m2 X))
2870 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2871 ;; should stack mols separately, to maintain LINE on baseline
2872 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2874 (ly:stencil-aligned-to stack Y CENTER))
2876 (ly:stencil-aligned-to stack X LEFT))
2877 ;; should have EX dimension
2879 (ly:stencil-translate-axis stack offset Y))))
2881 (define-builtin-markup-command (normal-size-super layout props arg)
2886 @cindex setting superscript in standard font size
2888 Set @var{arg} in superscript with a normal font size.
2890 @lilypond[verbatim,quote]
2893 \\normal-size-super {
2894 superscript in standard size
2898 (ly:stencil-translate-axis
2899 (interpret-markup layout props arg)
2900 (* 0.5 baseline-skip) Y))
2902 (define-builtin-markup-command (super layout props arg)
2908 @cindex superscript text
2910 Raising and lowering texts can be done with @code{\\super} and
2913 @lilypond[verbatim,quote]
2923 (ly:stencil-translate-axis
2926 (cons `((font-size . ,(- font-size 3))) props)
2928 (* 0.5 baseline-skip)
2931 (define-builtin-markup-command (translate layout props offset arg)
2932 (number-pair? markup?)
2936 @cindex translating text
2938 This translates an object. Its first argument is a cons of numbers.
2941 A \\translate #(cons 2 -3) @{ B C @} D
2944 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2945 surroundings. This command cannot be used to move isolated scripts
2946 vertically, for the same reason that @code{\\raise} cannot be used for
2949 @lilypond[verbatim,quote]
2952 \\translate #'(2 . 3)
2953 \\line { translated two spaces right, three up }
2956 (ly:stencil-translate (interpret-markup layout props arg)
2959 (define-builtin-markup-command (sub layout props arg)
2965 @cindex subscript text
2967 Set @var{arg} in subscript.
2969 @lilypond[verbatim,quote]
2980 (ly:stencil-translate-axis
2983 (cons `((font-size . ,(- font-size 3))) props)
2985 (* -0.5 baseline-skip)
2988 (define-builtin-markup-command (normal-size-sub layout props arg)
2993 @cindex setting subscript in standard font size
2995 Set @var{arg} in subscript, in a normal font size.
2997 @lilypond[verbatim,quote]
3001 subscript in standard size
3005 (ly:stencil-translate-axis
3006 (interpret-markup layout props arg)
3007 (* -0.5 baseline-skip)
3010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3014 (define-builtin-markup-command (hbracket layout props arg)
3019 @cindex placing horizontal brackets around text
3021 Draw horizontal brackets around @var{arg}.
3023 @lilypond[verbatim,quote]
3032 (let ((th 0.1) ;; todo: take from GROB.
3033 (m (interpret-markup layout props arg)))
3034 (bracketify-stencil m X th (* 2.5 th) th)))
3036 (define-builtin-markup-command (bracket layout props arg)
3041 @cindex placing vertical brackets around text
3043 Draw vertical brackets around @var{arg}.
3045 @lilypond[verbatim,quote]
3052 (let ((th 0.1) ;; todo: take from GROB.
3053 (m (interpret-markup layout props arg)))
3054 (bracketify-stencil m Y th (* 2.5 th) th)))
3056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3057 ;; Delayed markup evaluation
3058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3060 (define-builtin-markup-command (page-ref layout props label gauge default)
3061 (symbol? markup? markup?)
3065 @cindex referencing page numbers in text
3067 Reference to a page number. @var{label} is the label set on the referenced
3068 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3069 the maximum width of the page number, and @var{default} the value to display
3070 when @var{label} is not found."
3071 (let* ((gauge-stencil (interpret-markup layout props gauge))
3072 (x-ext (ly:stencil-extent gauge-stencil X))
3073 (y-ext (ly:stencil-extent gauge-stencil Y)))
3075 `(delay-stencil-evaluation
3076 ,(delay (ly:stencil-expr
3077 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3078 (label-page (and (list? table) (assoc label table)))
3079 (page-number (and label-page (cdr label-page)))
3080 (page-markup (if page-number (format "~a" page-number) default))
3081 (page-stencil (interpret-markup layout props page-markup))
3082 (gap (- (interval-length x-ext)
3083 (interval-length (ly:stencil-extent page-stencil X)))))
3084 (interpret-markup layout props
3085 (markup #:concat (#:hspace gap page-markup)))))))
3089 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3090 ;; Markup list commands
3091 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3093 (define-public (space-lines baseline stils)
3094 (let space-stil ((stils stils)
3098 (let* ((stil (car stils))
3099 (dy-top (max (- (/ baseline 1.5)
3100 (interval-bound (ly:stencil-extent stil Y) UP))
3102 (dy-bottom (max (+ (/ baseline 3.0)
3103 (interval-bound (ly:stencil-extent stil Y) DOWN))
3105 (new-stil (ly:make-stencil
3106 (ly:stencil-expr stil)
3107 (ly:stencil-extent stil X)
3108 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3110 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3112 (space-stil (cdr stils) (cons new-stil result))))))
3114 (define-builtin-markup-list-command (justified-lines layout props args)
3117 wordwrap-internal-markup-list)
3119 @cindex justifying lines of text
3121 Like @code{\\justify}, but return a list of lines instead of a single markup.
3122 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3123 @var{X}@tie{}is the number of staff spaces."
3124 (space-lines baseline-skip
3125 (interpret-markup-list layout props
3126 (make-wordwrap-internal-markup-list #t args))))
3128 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3131 wordwrap-internal-markup-list)
3132 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3133 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3134 where @var{X} is the number of staff spaces."
3135 (space-lines baseline-skip
3136 (interpret-markup-list layout props
3137 (make-wordwrap-internal-markup-list #f args))))
3139 (define-builtin-markup-list-command (column-lines layout props args)
3142 "Like @code{\\column}, but return a list of lines instead of a single markup.
3143 @code{baseline-skip} determines the space between each markup in @var{args}."
3144 (space-lines (chain-assoc-get 'baseline-skip props)
3145 (interpret-markup-list layout props args)))
3147 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3148 (pair? markup-list?)
3150 "Like @code{\\override}, for markup lists."
3151 (interpret-markup-list layout (cons (list new-prop) props) args))