1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2009 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 filled)
48 (number? number? boolean?)
52 @cindex drawing circles within text
54 A circle of radius @var{radius} and thickness @var{thickness},
57 @lilypond[verbatim,quote]
59 \\draw-circle #2 #0.5 ##f
61 \\draw-circle #2 #0 ##t
64 (make-circle-stencil radius thickness filled))
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 amount 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 amount)
361 (interval-widen yext amount))))
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 Create an invisible object taking up horizontal space @var{amount}.
391 @lilypond[verbatim,quote]
401 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
402 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
404 ;; todo: fix negative space
405 (define-builtin-markup-command (vspace layout props amount)
410 @cindex creating vertical spaces in text
412 Create an invisible object taking up vertical space
413 of @var{amount} multiplied by 3.
415 @lilypond[verbatim,quote]
426 (let ((amount (* amount 3.0)))
428 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
429 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
433 ;; importing graphics.
434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
436 (define-builtin-markup-command (stencil layout props stil)
441 @cindex importing stencils into text
443 Use a stencil as markup.
445 @lilypond[verbatim,quote]
447 \\stencil #(make-circle-stencil 2 0 #t)
453 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
455 (define (get-postscript-bbox string)
456 "Extract the bbox from STRING, or return #f if not present."
458 ((match (regexp-exec bbox-regexp string)))
462 (string->number (match:substring match x)))
467 (define-builtin-markup-command (epsfile layout props axis size file-name)
468 (number? number? string?)
472 @cindex inlining an Encapsulated PostScript image
474 Inline an EPS image. The image is scaled along @var{axis} to
477 @lilypond[verbatim,quote]
479 \\general-align #Y #DOWN {
480 \\epsfile #X #20 #\"context-example.eps\"
481 \\epsfile #Y #20 #\"context-example.eps\"
485 (if (ly:get-option 'safe)
486 (interpret-markup layout props "not allowed in safe")
487 (eps-file->stencil axis size file-name)
490 (define-builtin-markup-command (postscript layout props str)
495 @cindex inserting PostScript directly into text
496 This inserts @var{str} directly into the output as a PostScript
499 @lilypond[verbatim,quote]
503 0.4 0.6 0.5 0 361 arc
505 1.0 0.6 0.5 0 361 arc
510 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
511 \\postscript #ringsps
523 gsave currentpoint translate
531 (define-builtin-markup-command (score layout props score)
536 @cindex inserting music into text
538 Inline an image of music.
540 @lilypond[verbatim,quote]
544 \\new Staff \\relative c' {
547 \\mark \\markup { Allegro }
553 \\new Staff \\relative c {
567 \\override RehearsalMark #'break-align-symbols =
568 #'(time-signature key-signature)
569 \\override RehearsalMark #'self-alignment-X = #LEFT
573 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
579 (let ((output (ly:score-embedded-format score layout)))
581 (if (ly:music-output? output)
582 (stack-stencils Y DOWN baseline-skip
583 (map paper-system-stencil
585 (ly:paper-score-paper-systems output))))
587 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
590 (define-builtin-markup-command (null layout props)
595 @cindex creating empty text objects
597 An empty markup with extents of a single point.
599 @lilypond[verbatim,quote]
606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
610 (define-builtin-markup-command (simple layout props str)
615 @cindex simple text strings
617 A simple text string; @code{\\markup @{ foo @}} is equivalent with
618 @code{\\markup @{ \\simple #\"foo\" @}}.
620 Note: for creating standard text markup or defining new markup commands,
621 the use of @code{\\simple} is unnecessary.
623 @lilypond[verbatim,quote]
627 \\simple #\"strings\"
630 (interpret-markup layout props str))
632 (define-builtin-markup-command (tied-lyric layout props str)
637 @cindex simple text strings with tie characters
639 Like simple-markup, but use tie characters for @q{~} tilde symbols.
641 @lilypond[verbatim,quote]
643 \\tied-lyric #\"Lasciate~i monti\"
646 (if (string-contains str "~")
648 ((parts (string-split str #\~))
649 (tie-str (ly:wide-char->utf-8 #x203f))
650 (joined (list-join parts tie-str))
651 (join-stencil (interpret-markup layout props tie-str))
654 (interpret-markup layout
657 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
659 (make-line-markup joined)))
660 ;(map (lambda (s) (interpret-markup layout props s)) parts))
661 (interpret-markup layout props str)))
663 (define-public empty-markup
664 (make-simple-markup ""))
666 ;; helper for justifying lines.
667 (define (get-fill-space word-count line-width text-widths)
668 "Calculate the necessary paddings between each two adjacent texts.
669 The lengths of all texts are stored in @var{text-widths}.
670 The normal formula for the padding between texts a and b is:
671 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
672 The first and last padding have to be calculated specially using the
673 whole length of the first or last text.
674 Return a list of paddings."
676 ((null? text-widths) '())
678 ;; special case first padding
679 ((= (length text-widths) word-count)
681 (- (- (/ line-width (1- word-count)) (car text-widths))
682 (/ (car (cdr text-widths)) 2))
683 (get-fill-space word-count line-width (cdr text-widths))))
684 ;; special case last padding
685 ((= (length text-widths) 2)
686 (list (- (/ line-width (1- word-count))
687 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
690 (- (/ line-width (1- word-count))
691 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
692 (get-fill-space word-count line-width (cdr text-widths))))))
694 (define-builtin-markup-command (fill-line layout props args)
697 ((text-direction RIGHT)
700 "Put @var{markups} in a horizontal line of width @var{line-width}.
701 The markups are spaced or flushed to fill the entire line.
702 If there are no arguments, return an empty stencil.
704 @lilypond[verbatim,quote]
708 Words evenly spaced across the page
712 \\line { Text markups }
714 \\italic { evenly spaced }
716 \\line { across the page }
721 (let* ((orig-stencils (interpret-markup-list layout props args))
724 (if (ly:stencil-empty? stc)
726 stc)) orig-stencils))
729 (if (ly:stencil-empty? stc)
731 (interval-length (ly:stencil-extent stc X))))
733 (text-width (apply + text-widths))
734 (word-count (length stencils))
735 (prop-line-width (chain-assoc-get 'line-width props #f))
736 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
741 (/ (- line-width text-width) 2)
742 (/ (- line-width text-width) 2)))
745 (- line-width text-width)))
747 (get-fill-space word-count line-width text-widths))))
755 (line-stencils (if (= word-count 1)
762 (if (= text-direction LEFT)
763 (set! line-stencils (reverse line-stencils)))
765 (if (null? (remove ly:stencil-empty? orig-stencils))
767 (stack-stencils-padding-list X
768 RIGHT fill-space-normal line-stencils))))
770 (define-builtin-markup-command (line layout props args)
774 (text-direction RIGHT))
775 "Put @var{args} in a horizontal line. The property @code{word-space}
776 determines the space between markups in @var{args}.
778 @lilypond[verbatim,quote]
785 (let ((stencils (interpret-markup-list layout props args)))
786 (if (= text-direction LEFT)
787 (set! stencils (reverse stencils)))
790 (remove ly:stencil-empty? stencils))))
792 (define-builtin-markup-command (concat layout props args)
797 @cindex concatenating text
798 @cindex ligatures in text
800 Concatenate @var{args} in a horizontal line, without spaces in between.
801 Strings and simple markups are concatenated on the input level, allowing
802 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
803 equivalent to @code{\"fi\"}.
805 @lilypond[verbatim,quote]
814 (define (concat-string-args arg-list)
815 (fold-right (lambda (arg result-list)
816 (let ((result (if (pair? result-list)
819 (if (and (pair? arg) (eqv? (car arg) simple-markup))
820 (set! arg (cadr arg)))
821 (if (and (string? result) (string? arg))
822 (cons (string-append arg result) (cdr result-list))
823 (cons arg result-list))))
827 (interpret-markup layout
828 (prepend-alist-chain 'word-space 0 props)
829 (make-line-markup (if (markup-command-list? args)
831 (concat-string-args args)))))
833 (define (wordwrap-stencils stencils
834 justify base-space line-width text-dir)
835 "Perform simple wordwrap, return stencil of each line."
836 (define space (if justify
837 ;; justify only stretches lines.
840 (define (take-list width space stencils
841 accumulator accumulated-width)
842 "Return (head-list . tail) pair, with head-list fitting into width"
844 (cons accumulator stencils)
845 (let* ((first (car stencils))
846 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
847 (newwid (+ space first-wid accumulated-width)))
848 (if (or (null? accumulator)
850 (take-list width space
852 (cons first accumulator)
854 (cons accumulator stencils)))))
855 (let loop ((lines '())
857 (let* ((line-break (take-list line-width space todo
859 (line-stencils (car line-break))
860 (space-left (- line-width
861 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
863 (line-word-space (cond ((not justify) space)
864 ;; don't stretch last line of paragraph.
865 ;; hmmm . bug - will overstretch the last line in some case.
866 ((null? (cdr line-break))
868 ((null? line-stencils) 0.0)
869 ((null? (cdr line-stencils)) 0.0)
870 (else (/ space-left (1- (length line-stencils))))))
871 (line (stack-stencil-line line-word-space
872 (if (= text-dir RIGHT)
873 (reverse line-stencils)
875 (if (pair? (cdr line-break))
876 (loop (cons line lines)
879 (if (= text-dir LEFT)
881 (ly:stencil-translate-axis
883 (- line-width (interval-end (ly:stencil-extent line X)))
885 (reverse (cons line lines)))))))
887 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
888 (boolean? markup-list?)
891 (text-direction RIGHT))
892 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
893 (wordwrap-stencils (remove ly:stencil-empty?
894 (interpret-markup-list layout props args))
898 (ly:output-def-lookup layout 'line-width))
901 (define-builtin-markup-command (justify layout props args)
905 wordwrap-internal-markup-list)
907 @cindex justifying text
909 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
910 Use @code{\\override #'(line-width . @var{X})} to set the line width;
911 @var{X}@tie{}is the number of staff spaces.
913 @lilypond[verbatim,quote]
916 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
917 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
918 Ut enim ad minim veniam, quis nostrud exercitation ullamco
919 laboris nisi ut aliquip ex ea commodo consequat.
923 (stack-lines DOWN 0.0 baseline-skip
924 (wordwrap-internal-markup-list layout props #t args)))
926 (define-builtin-markup-command (wordwrap layout props args)
930 wordwrap-internal-markup-list)
931 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
932 the line width, where @var{X} is the number of staff spaces.
934 @lilypond[verbatim,quote]
937 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
938 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
939 Ut enim ad minim veniam, quis nostrud exercitation ullamco
940 laboris nisi ut aliquip ex ea commodo consequat.
944 (stack-lines DOWN 0.0 baseline-skip
945 (wordwrap-internal-markup-list layout props #f args)))
947 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
951 (text-direction RIGHT))
952 "Internal markup list command used to define @code{\\justify-string} and
953 @code{\\wordwrap-string}."
954 (let* ((para-strings (regexp-split
955 (string-regexp-substitute
957 (string-regexp-substitute "\r\n" "\n" arg))
958 "\n[ \t\n]*\n[ \t\n]*"))
959 (list-para-words (map (lambda (str)
960 (regexp-split str "[ \t\n]+"))
962 (para-lines (map (lambda (words)
964 (remove ly:stencil-empty?
966 (interpret-markup layout props x))
968 (wordwrap-stencils stencils
970 line-width text-direction)))
972 (apply append para-lines)))
974 (define-builtin-markup-command (wordwrap-string layout props arg)
978 wordwrap-string-internal-markup-list)
979 "Wordwrap a string. Paragraphs may be separated with double newlines.
981 @lilypond[verbatim,quote]
983 \\override #'(line-width . 40)
984 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
985 adipisicing elit, sed do eiusmod tempor incididunt ut labore
986 et dolore magna aliqua.
989 Ut enim ad minim veniam, quis nostrud exercitation ullamco
990 laboris nisi ut aliquip ex ea commodo consequat.
993 Excepteur sint occaecat cupidatat non proident, sunt in culpa
994 qui officia deserunt mollit anim id est laborum\"
997 (stack-lines DOWN 0.0 baseline-skip
998 (wordwrap-string-internal-markup-list layout props #f arg)))
1000 (define-builtin-markup-command (justify-string layout props arg)
1004 wordwrap-string-internal-markup-list)
1005 "Justify a string. Paragraphs may be separated with double newlines
1007 @lilypond[verbatim,quote]
1009 \\override #'(line-width . 40)
1010 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1011 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1012 et dolore magna aliqua.
1015 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1016 laboris nisi ut aliquip ex ea commodo consequat.
1019 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1020 qui officia deserunt mollit anim id est laborum\"
1023 (stack-lines DOWN 0.0 baseline-skip
1024 (wordwrap-string-internal-markup-list layout props #t arg)))
1026 (define-builtin-markup-command (wordwrap-field layout props symbol)
1030 "Wordwrap the data which has been assigned to @var{symbol}.
1032 @lilypond[verbatim,quote]
1034 title = \"My title\"
1035 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1036 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1037 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1038 laboris nisi ut aliquip ex ea commodo consequat.\"
1042 bookTitleMarkup = \\markup {
1044 \\fill-line { \\fromproperty #'header:title }
1046 \\wordwrap-field #'header:myText
1055 (let* ((m (chain-assoc-get symbol props)))
1057 (wordwrap-string-markup layout props m)
1060 (define-builtin-markup-command (justify-field layout props symbol)
1064 "Justify the data which has been assigned to @var{symbol}.
1066 @lilypond[verbatim,quote]
1068 title = \"My title\"
1069 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1070 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1071 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1072 laboris nisi ut aliquip ex ea commodo consequat.\"
1076 bookTitleMarkup = \\markup {
1078 \\fill-line { \\fromproperty #'header:title }
1080 \\justify-field #'header:myText
1089 (let* ((m (chain-assoc-get symbol props)))
1091 (justify-string-markup layout props m)
1094 (define-builtin-markup-command (combine layout props arg1 arg2)
1099 @cindex merging text
1101 Print two markups on top of each other.
1103 Note: @code{\\combine} cannot take a list of markups enclosed in
1104 curly braces as an argument; the follow example will not compile:
1107 \\combine @{ a list @}
1110 @lilypond[verbatim,quote]
1113 \\override #'(thickness . 2)
1115 \\draw-line #'(0 . 4)
1116 \\arrow-head #Y #DOWN ##f
1119 (let* ((s1 (interpret-markup layout props arg1))
1120 (s2 (interpret-markup layout props arg2)))
1121 (ly:stencil-add s1 s2)))
1124 ;; TODO: should extract baseline-skip from each argument somehow..
1126 (define-builtin-markup-command (column layout props args)
1131 @cindex stacking text in a column
1133 Stack the markups in @var{args} vertically. The property
1134 @code{baseline-skip} determines the space between markups
1137 @lilypond[verbatim,quote]
1146 (let ((arg-stencils (interpret-markup-list layout props args)))
1147 (stack-lines -1 0.0 baseline-skip
1148 (remove ly:stencil-empty? arg-stencils))))
1150 (define-builtin-markup-command (dir-column layout props args)
1156 @cindex changing direction of text columns
1158 Make a column of @var{args}, going up or down, depending on the
1159 setting of the @code{direction} layout property.
1161 @lilypond[verbatim,quote]
1163 \\override #`(direction . ,UP) {
1173 \\override #'(direction . 1) {
1180 (stack-lines (if (number? direction) direction -1)
1183 (interpret-markup-list layout props args)))
1185 (define (general-column align-dir baseline mols)
1186 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1188 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1189 (stack-lines -1 0.0 baseline aligned-mols)))
1191 (define-builtin-markup-command (center-column layout props args)
1196 @cindex centering a column of text
1198 Put @code{args} in a centered column.
1200 @lilypond[verbatim,quote]
1209 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1211 (define-builtin-markup-command (left-column layout props args)
1216 @cindex text columns, left-aligned
1218 Put @code{args} in a left-aligned column.
1220 @lilypond[verbatim,quote]
1229 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1231 (define-builtin-markup-command (right-column layout props args)
1236 @cindex text columns, right-aligned
1238 Put @code{args} in a right-aligned column.
1240 @lilypond[verbatim,quote]
1249 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1251 (define-builtin-markup-command (vcenter layout props arg)
1256 @cindex vertically centering text
1258 Align @code{arg} to its Y@tie{}center.
1260 @lilypond[verbatim,quote]
1268 (let* ((mol (interpret-markup layout props arg)))
1269 (ly:stencil-aligned-to mol Y CENTER)))
1271 (define-builtin-markup-command (center-align layout props arg)
1276 @cindex horizontally centering text
1278 Align @code{arg} to its X@tie{}center.
1280 @lilypond[verbatim,quote]
1290 (let* ((mol (interpret-markup layout props arg)))
1291 (ly:stencil-aligned-to mol X CENTER)))
1293 (define-builtin-markup-command (right-align layout props arg)
1298 @cindex right aligning text
1300 Align @var{arg} on its right edge.
1302 @lilypond[verbatim,quote]
1312 (let* ((m (interpret-markup layout props arg)))
1313 (ly:stencil-aligned-to m X RIGHT)))
1315 (define-builtin-markup-command (left-align layout props arg)
1320 @cindex left aligning text
1322 Align @var{arg} on its left edge.
1324 @lilypond[verbatim,quote]
1334 (let* ((m (interpret-markup layout props arg)))
1335 (ly:stencil-aligned-to m X LEFT)))
1337 (define-builtin-markup-command (general-align layout props axis dir arg)
1338 (integer? number? markup?)
1342 @cindex controlling general text alignment
1344 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1346 @lilypond[verbatim,quote]
1350 \\general-align #X #LEFT
1355 \\general-align #X #CENTER
1361 \\general-align #Y #UP
1368 \\general-align #Y #3.2
1375 (let* ((m (interpret-markup layout props arg)))
1376 (ly:stencil-aligned-to m axis dir)))
1378 (define-builtin-markup-command (halign layout props dir arg)
1383 @cindex setting horizontal text alignment
1385 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1386 left-aligned, while @code{+1} is right. Values in between interpolate
1387 alignment accordingly.
1389 @lilypond[verbatim,quote]
1414 (let* ((m (interpret-markup layout props arg)))
1415 (ly:stencil-aligned-to m X dir)))
1417 (define-builtin-markup-command (with-dimensions layout props x y arg)
1418 (number-pair? number-pair? markup?)
1422 @cindex setting extent of text objects
1424 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1425 (let* ((m (interpret-markup layout props arg)))
1426 (ly:make-stencil (ly:stencil-expr m) x y)))
1428 (define-builtin-markup-command (pad-around layout props amount arg)
1432 "Add padding @var{amount} all around @var{arg}.
1434 @lilypond[verbatim,quote]
1447 (let* ((m (interpret-markup layout props arg))
1448 (x (ly:stencil-extent m X))
1449 (y (ly:stencil-extent m Y)))
1450 (ly:make-stencil (ly:stencil-expr m)
1451 (interval-widen x amount)
1452 (interval-widen y amount))))
1454 (define-builtin-markup-command (pad-x layout props amount arg)
1459 @cindex padding text horizontally
1461 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1463 @lilypond[verbatim,quote]
1476 (let* ((m (interpret-markup layout props arg))
1477 (x (ly:stencil-extent m X))
1478 (y (ly:stencil-extent m Y)))
1479 (ly:make-stencil (ly:stencil-expr m)
1480 (interval-widen x amount)
1483 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1484 (integer? ly:dir? markup? markup?)
1487 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1488 (let ((m1 (interpret-markup layout props arg1))
1489 (m2 (interpret-markup layout props arg2)))
1490 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1492 (define-builtin-markup-command (transparent layout props arg)
1496 "Make @var{arg} transparent.
1498 @lilypond[verbatim,quote]
1505 (let* ((m (interpret-markup layout props arg))
1506 (x (ly:stencil-extent m X))
1507 (y (ly:stencil-extent m Y)))
1508 (ly:make-stencil "" x y)))
1510 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1511 (number-pair? number-pair? markup?)
1514 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1516 @lilypond[verbatim,quote]
1523 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1529 (let* ((m (interpret-markup layout props arg))
1530 (x (ly:stencil-extent m X))
1531 (y (ly:stencil-extent m Y)))
1532 (ly:make-stencil (ly:stencil-expr m)
1533 (interval-union x-ext x)
1534 (interval-union y-ext y))))
1536 (define-builtin-markup-command (hcenter-in layout props length arg)
1540 "Center @var{arg} horizontally within a box of extending
1541 @var{length}/2 to the left and right.
1543 @lilypond[quote,verbatim]
1546 \\set Staff.instrumentName = \\markup {
1553 \\set Staff.instrumentName = \\markup {
1562 (interpret-markup layout props
1563 (make-pad-to-box-markup
1564 (cons (/ length -2) (/ length 2))
1566 (make-center-align-markup arg))))
1568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1570 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1572 (define-builtin-markup-command (fromproperty layout props symbol)
1576 "Read the @var{symbol} from property settings, and produce a stencil
1577 from the markup contained within. If @var{symbol} is not defined, it
1578 returns an empty markup.
1580 @lilypond[verbatim,quote]
1582 myTitle = \"myTitle\"
1586 \\fromproperty #'header:myTitle
1593 (let ((m (chain-assoc-get symbol props)))
1595 (interpret-markup layout props m)
1598 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1602 "Apply the @var{procedure} markup command to @var{arg}.
1603 @var{procedure} should take a single argument."
1604 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1605 (set-object-property! anonymous-with-signature
1608 (interpret-markup layout props (list anonymous-with-signature arg))))
1610 (define-builtin-markup-command (override layout props new-prop arg)
1615 @cindex overriding properties within text markup
1617 Add the argument @var{new-prop} to the property list. Properties
1618 may be any property supported by @rinternals{font-interface},
1619 @rinternals{text-interface} and
1620 @rinternals{instrument-specific-markup-interface}.
1622 @lilypond[verbatim,quote]
1630 \\override #'(baseline-skip . 4) {
1639 (interpret-markup layout (cons (list new-prop) props) arg))
1641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1643 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1645 (define-builtin-markup-command (verbatim-file layout props name)
1649 "Read the contents of file @var{name}, and include it verbatim.
1651 @lilypond[verbatim,quote]
1653 \\verbatim-file #\"simple.ly\"
1656 (interpret-markup layout props
1657 (if (ly:get-option 'safe)
1658 "verbatim-file disabled in safe mode"
1659 (let* ((str (ly:gulp-file name))
1660 (lines (string-split str #\nl)))
1661 (make-typewriter-markup
1662 (make-column-markup lines))))))
1664 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1666 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1669 (define-builtin-markup-command (smaller layout props arg)
1673 "Decrease the font size relative to the current setting.
1675 @lilypond[verbatim,quote]
1688 (interpret-markup layout props
1689 `(,fontsize-markup -1 ,arg)))
1691 (define-builtin-markup-command (larger layout props arg)
1695 "Increase the font size relative to the current setting.
1697 @lilypond[verbatim,quote]
1705 (interpret-markup layout props
1706 `(,fontsize-markup 1 ,arg)))
1708 (define-builtin-markup-command (finger layout props arg)
1712 "Set @var{arg} as small numbers.
1714 @lilypond[verbatim,quote]
1721 (interpret-markup layout
1722 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1725 (define-builtin-markup-command (abs-fontsize layout props size arg)
1729 "Use @var{size} as the absolute font size to display @var{arg}.
1730 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1732 @lilypond[verbatim,quote]
1734 default text font size
1736 \\abs-fontsize #16 { text font size 16 }
1738 \\abs-fontsize #12 { text font size 12 }
1741 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1742 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1743 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1744 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1745 (magnification (/ size ref-size)))
1746 (interpret-markup layout
1747 (cons `((baseline-skip . ,(* magnification ref-baseline))
1748 (word-space . ,(* magnification ref-word-space))
1749 (font-size . ,(magnification->font-size magnification)))
1753 (define-builtin-markup-command (fontsize layout props increment arg)
1759 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1762 @lilypond[verbatim,quote]
1770 (let ((entries (list
1771 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1772 (cons 'word-space (* word-space (magstep increment)))
1773 (cons 'font-size (+ font-size increment)))))
1774 (interpret-markup layout (cons entries props) arg)))
1776 (define-builtin-markup-command (magnify layout props sz arg)
1781 @cindex magnifying text
1783 Set the font magnification for its argument. In the following
1784 example, the middle@tie{}A is 10% larger:
1787 A \\magnify #1.1 @{ A @} A
1790 Note: Magnification only works if a font name is explicitly selected.
1791 Use @code{\\fontsize} otherwise.
1793 @lilypond[verbatim,quote]
1804 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1807 (define-builtin-markup-command (bold layout props arg)
1811 "Switch to bold font-series.
1813 @lilypond[verbatim,quote]
1821 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1823 (define-builtin-markup-command (sans layout props arg)
1827 "Switch to the sans serif font family.
1829 @lilypond[verbatim,quote]
1838 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1840 (define-builtin-markup-command (number layout props arg)
1844 "Set font family to @code{number}, which yields the font used for
1845 time signatures and fingerings. This font contains numbers and
1846 some punctuation; it has no letters.
1848 @lilypond[verbatim,quote]
1851 0 1 2 3 4 5 6 7 8 9 . ,
1855 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1857 (define-builtin-markup-command (roman layout props arg)
1861 "Set font family to @code{roman}.
1863 @lilypond[verbatim,quote]
1869 text in roman font family
1876 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1878 (define-builtin-markup-command (huge layout props arg)
1882 "Set font size to +2.
1884 @lilypond[verbatim,quote]
1892 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1894 (define-builtin-markup-command (large layout props arg)
1898 "Set font size to +1.
1900 @lilypond[verbatim,quote]
1908 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1910 (define-builtin-markup-command (normalsize layout props arg)
1914 "Set font size to default.
1916 @lilypond[verbatim,quote]
1929 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1931 (define-builtin-markup-command (small layout props arg)
1935 "Set font size to -1.
1937 @lilypond[verbatim,quote]
1945 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1947 (define-builtin-markup-command (tiny layout props arg)
1951 "Set font size to -2.
1953 @lilypond[verbatim,quote]
1961 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1963 (define-builtin-markup-command (teeny layout props arg)
1967 "Set font size to -3.
1969 @lilypond[verbatim,quote]
1977 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1979 (define-builtin-markup-command (fontCaps layout props arg)
1983 "Set @code{font-shape} to @code{caps}
1985 Note: @code{\\fontCaps} requires the installation and selection of
1986 fonts which support the @code{caps} font shape."
1987 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1990 (define-builtin-markup-command (smallCaps layout props arg)
1994 "Emit @var{arg} as small caps.
1996 Note: @code{\\smallCaps} does not support accented characters.
1998 @lilypond[verbatim,quote]
2007 (define (char-list->markup chars lower)
2008 (let ((final-string (string-upcase (reverse-list->string chars))))
2010 (markup #:fontsize -2 final-string)
2012 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2013 (if (null? rest-chars)
2015 (reverse! (cons (char-list->markup currents current-is-lower)
2017 (let* ((ch (car rest-chars))
2018 (is-lower (char-lower-case? ch)))
2019 (if (or (and current-is-lower is-lower)
2020 (and (not current-is-lower) (not is-lower)))
2021 (make-small-caps (cdr rest-chars)
2025 (make-small-caps (cdr rest-chars)
2028 (if (null? currents)
2030 (cons (char-list->markup
2031 currents current-is-lower)
2033 (interpret-markup layout props
2035 (make-small-caps (string->list arg) (list) #f (list))
2038 (define-builtin-markup-command (caps layout props arg)
2042 "Copy of the @code{\\smallCaps} command.
2044 @lilypond[verbatim,quote]
2053 (interpret-markup layout props (make-smallCaps-markup arg)))
2055 (define-builtin-markup-command (dynamic layout props arg)
2059 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2060 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2061 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2062 done in a different font. The recommended font for this is bold and italic.
2063 @lilypond[verbatim,quote]
2071 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2073 (define-builtin-markup-command (text layout props arg)
2077 "Use a text font instead of music symbol or music alphabet font.
2079 @lilypond[verbatim,quote]
2092 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2095 (define-builtin-markup-command (italic layout props arg)
2099 "Use italic @code{font-shape} for @var{arg}.
2101 @lilypond[verbatim,quote]
2109 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2111 (define-builtin-markup-command (typewriter layout props arg)
2115 "Use @code{font-family} typewriter for @var{arg}.
2117 @lilypond[verbatim,quote]
2126 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2128 (define-builtin-markup-command (upright layout props arg)
2132 "Set @code{font-shape} to @code{upright}. This is the opposite
2135 @lilypond[verbatim,quote]
2149 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2151 (define-builtin-markup-command (medium layout props arg)
2155 "Switch to medium font-series (in contrast to bold).
2157 @lilypond[verbatim,quote]
2170 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2173 (define-builtin-markup-command (normal-text layout props arg)
2177 "Set all font related properties (except the size) to get the default
2178 normal text font, no matter what font was used earlier.
2180 @lilypond[verbatim,quote]
2182 \\huge \\bold \\sans \\caps {
2183 Some text with font overrides
2186 Default text, same font-size
2194 (interpret-markup layout
2195 (cons '((font-family . roman) (font-shape . upright)
2196 (font-series . medium) (font-encoding . latin1))
2200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2204 (define-builtin-markup-command (doublesharp layout props)
2208 "Draw a double sharp symbol.
2210 @lilypond[verbatim,quote]
2215 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2217 (define-builtin-markup-command (sesquisharp layout props)
2221 "Draw a 3/2 sharp symbol.
2223 @lilypond[verbatim,quote]
2228 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2230 (define-builtin-markup-command (sharp layout props)
2234 "Draw a sharp symbol.
2236 @lilypond[verbatim,quote]
2241 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2243 (define-builtin-markup-command (semisharp layout props)
2247 "Draw a semisharp symbol.
2249 @lilypond[verbatim,quote]
2254 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2256 (define-builtin-markup-command (natural layout props)
2260 "Draw a natural symbol.
2262 @lilypond[verbatim,quote]
2267 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2269 (define-builtin-markup-command (semiflat layout props)
2273 "Draw a semiflat symbol.
2275 @lilypond[verbatim,quote]
2280 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2282 (define-builtin-markup-command (flat layout props)
2286 "Draw a flat symbol.
2288 @lilypond[verbatim,quote]
2293 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2295 (define-builtin-markup-command (sesquiflat layout props)
2299 "Draw a 3/2 flat symbol.
2301 @lilypond[verbatim,quote]
2306 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2308 (define-builtin-markup-command (doubleflat layout props)
2312 "Draw a double flat symbol.
2314 @lilypond[verbatim,quote]
2319 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2321 (define-builtin-markup-command (with-color layout props color arg)
2326 @cindex coloring text
2328 Draw @var{arg} in color specified by @var{color}.
2330 @lilypond[verbatim,quote]
2342 (let ((stil (interpret-markup layout props arg)))
2343 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2344 (ly:stencil-extent stil X)
2345 (ly:stencil-extent stil Y))))
2347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2349 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2351 (define-builtin-markup-command (arrow-head layout props axis dir filled)
2352 (integer? ly:dir? boolean?)
2355 "Produce an arrow head in specified direction and axis.
2356 Use the filled head if @var{filled} is specified.
2357 @lilypond[verbatim,quote]
2360 \\general-align #Y #DOWN {
2361 \\arrow-head #Y #UP ##t
2362 \\arrow-head #Y #DOWN ##f
2364 \\arrow-head #X #RIGHT ##f
2365 \\arrow-head #X #LEFT ##f
2371 ((name (format "arrowheads.~a.~a~a"
2378 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2382 (define-builtin-markup-command (musicglyph layout props glyph-name)
2386 "@var{glyph-name} is converted to a musical symbol; for example,
2387 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2388 the music font. See @ruser{The Feta font} for a complete listing of
2389 the possible glyphs.
2391 @lilypond[verbatim,quote]
2394 \\musicglyph #\"rests.2\"
2395 \\musicglyph #\"clefs.G_change\"
2398 (let* ((font (ly:paper-get-font layout
2399 (cons '((font-encoding . fetaMusic)
2403 (glyph (ly:font-get-glyph font glyph-name)))
2404 (if (null? (ly:stencil-expr glyph))
2405 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2410 (define-builtin-markup-command (lookup layout props glyph-name)
2414 "Lookup a glyph by name.
2416 @lilypond[verbatim,quote]
2418 \\override #'(font-encoding . fetaBraces) {
2419 \\lookup #\"brace200\"
2422 \\lookup #\"brace180\"
2426 (ly:font-get-glyph (ly:paper-get-font layout props)
2429 (define-builtin-markup-command (char layout props num)
2433 "Produce a single character. Characters encoded in hexadecimal
2434 format require the prefix @code{#x}.
2436 @lilypond[verbatim,quote]
2438 \\char #65 \\char ##x00a9
2441 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2443 (define number->mark-letter-vector (make-vector 25 #\A))
2448 (if (= i (- (char->integer #\I) (char->integer #\A)))
2450 (vector-set! number->mark-letter-vector j
2451 (integer->char (+ i (char->integer #\A)))))
2453 (define number->mark-alphabet-vector (list->vector
2454 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2456 (define (number->markletter-string vec n)
2457 "Double letters for big marks."
2458 (let* ((lst (vector-length vec)))
2461 (string-append (number->markletter-string vec (1- (quotient n lst)))
2462 (number->markletter-string vec (remainder n lst)))
2463 (make-string 1 (vector-ref vec n)))))
2465 (define-builtin-markup-command (markletter layout props num)
2469 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2470 (skipping letter@tie{}I), and continue with double letters.
2472 @lilypond[verbatim,quote]
2479 (ly:text-interface::interpret-markup layout props
2480 (number->markletter-string number->mark-letter-vector num)))
2482 (define-builtin-markup-command (markalphabet layout props num)
2486 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2487 and continue with double letters.
2489 @lilypond[verbatim,quote]
2496 (ly:text-interface::interpret-markup layout props
2497 (number->markletter-string number->mark-alphabet-vector num)))
2499 (define-public (horizontal-slash-interval num forward number-interval mag)
2501 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2502 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2503 (else (interval-widen number-interval (* mag 0.25))))
2504 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2505 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2506 (else (interval-widen number-interval (* mag 0.25))))
2509 (define-public (adjust-slash-stencil num forward stencil mag)
2512 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2514 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2516 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2518 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2521 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2523 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2528 (define (slashed-digit-internal layout props num forward font-size thickness)
2529 (let* ((mag (magstep font-size))
2531 (ly:output-def-lookup layout 'line-thickness)
2533 ; backward slashes might use slope and point in the other direction!
2534 (dy (* mag (if forward 0.4 -0.4)))
2535 (number-stencil (interpret-markup layout
2536 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2537 (number->string num)))
2538 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2539 (center (interval-center (ly:stencil-extent number-stencil Y)))
2540 ; Use the real extents of the slash, not the whole number, because we
2541 ; might translate the slash later on!
2542 (num-y (interval-widen (cons center center) (abs dy)))
2543 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2544 (slash-stencil (if is-sane
2545 (make-line-stencil thickness
2546 (car num-x) (- (interval-center num-y) dy)
2547 (cdr num-x) (+ (interval-center num-y) dy))
2549 (if (ly:stencil? slash-stencil)
2551 ; for some numbers we need to shift the slash/backslash up or down to make
2552 ; the slashed digit look better
2553 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2554 (set! number-stencil
2555 (ly:stencil-add number-stencil slash-stencil)))
2556 (ly:warning "Unable to create slashed digit ~a" num))
2560 (define-builtin-markup-command (slashed-digit layout props num)
2566 @cindex slashed digits
2568 A feta number, with slash. This is for use in the context of
2569 figured bass notation.
2570 @lilypond[verbatim,quote]
2574 \\override #'(thickness . 3)
2578 (slashed-digit-internal layout props num #t font-size thickness))
2580 (define-builtin-markup-command (backslashed-digit layout props num)
2586 @cindex backslashed digits
2588 A feta number, with backslash. This is for use in the context of
2589 figured bass notation.
2590 @lilypond[verbatim,quote]
2592 \\backslashed-digit #5
2594 \\override #'(thickness . 3)
2595 \\backslashed-digit #7
2598 (slashed-digit-internal layout props num #f font-size thickness))
2601 (define eyeglassesps
2606 0.7 0.7 0.5 0 361 arc
2608 2.20 0.70 0.50 0 361 arc
2610 1.45 0.85 0.30 0 180 arc
2614 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2618 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2621 (define-builtin-markup-command (eyeglasses layout props) () other ()
2622 "Prints out eyeglasses, indicating strongly to look at the conductor.
2623 @lilypond[verbatim,quote]
2624 \\markup { \\eyeglasses }
2626 (interpret-markup layout props
2627 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2628 (make-postscript-markup eyeglassesps))))
2630 (define-builtin-markup-command (left-brace layout props size)
2635 A feta brace in point size @var{size}.
2637 @lilypond[verbatim,quote]
2644 (let* ((font (ly:paper-get-font layout
2645 (cons '((font-encoding . fetaBraces)
2648 (glyph-count (1- (ly:otf-glyph-count font)))
2649 (scale (ly:output-def-lookup layout 'output-scale))
2650 (scaled-size (/ (ly:pt size) scale))
2652 (ly:font-get-glyph font (string-append "brace"
2653 (number->string n)))))
2654 (get-y-from-brace (lambda (brace)
2656 (ly:stencil-extent (glyph brace) Y))))
2657 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2658 (glyph-found (glyph find-brace)))
2660 (if (or (null? (ly:stencil-expr glyph-found))
2661 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2662 (> scaled-size (interval-length
2663 (ly:stencil-extent (glyph glyph-count) Y))))
2665 (ly:warning (_ "no brace found for point size ~S ") size)
2666 (ly:warning (_ "defaulting to ~S pt")
2667 (/ (* scale (interval-length
2668 (ly:stencil-extent glyph-found Y)))
2672 (define-builtin-markup-command (right-brace layout props size)
2677 A feta brace in point size @var{size}, rotated 180 degrees.
2679 @lilypond[verbatim,quote]
2686 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2689 ;; the note command.
2690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2692 ;; TODO: better syntax.
2694 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2695 (number? number? number?)
2700 @cindex notes within text by log and dot-count
2702 Construct a note symbol, with stem. By using fractional values for
2703 @var{dir}, longer or shorter stems can be obtained.
2705 @lilypond[verbatim,quote]
2707 \\note-by-number #3 #0 #DOWN
2709 \\note-by-number #1 #2 #0.8
2712 (define (get-glyph-name-candidates dir log style)
2713 (map (lambda (dir-name)
2714 (format "noteheads.~a~a~a" dir-name (min log 2)
2715 (if (and (symbol? style)
2716 (not (equal? 'default style)))
2717 (symbol->string style)
2719 (list (if (= dir UP) "u" "d")
2722 (define (get-glyph-name font cands)
2725 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2726 (get-glyph-name font (cdr cands))
2729 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2730 (size-factor (magstep font-size))
2731 (stem-length (* size-factor (max 3 (- log 1))))
2732 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2733 (head-glyph (ly:font-get-glyph font head-glyph-name))
2734 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2735 (stem-thickness (* size-factor 0.13))
2736 (stemy (* dir stem-length))
2737 (attach-off (cons (interval-index
2738 (ly:stencil-extent head-glyph X)
2739 (* (sign dir) (car attach-indices)))
2740 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2742 (ly:stencil-extent head-glyph Y)
2743 (cdr attach-indices)))))
2744 (stem-glyph (and (> log 0)
2745 (ly:round-filled-box
2746 (ordered-cons (car attach-off)
2747 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2748 (cons (min stemy (cdr attach-off))
2749 (max stemy (cdr attach-off)))
2750 (/ stem-thickness 3))))
2752 (dot (ly:font-get-glyph font "dots.dot"))
2753 (dotwid (interval-length (ly:stencil-extent dot X)))
2754 (dots (and (> dot-count 0)
2755 (apply ly:stencil-add
2757 (ly:stencil-translate-axis
2758 dot (* 2 x dotwid) X))
2759 (iota dot-count)))))
2760 (flaggl (and (> log 2)
2761 (ly:stencil-translate
2762 (ly:font-get-glyph font
2763 (string-append "flags."
2764 (if (> dir 0) "u" "d")
2765 (number->string log)))
2766 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2768 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2769 ; 16th notes get a special case because their flags hang lower than any other flags.
2770 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2771 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2773 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2774 (if (ly:stencil? stem-glyph)
2775 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2776 (set! stem-glyph head-glyph))
2777 (if (ly:stencil? dots)
2780 (ly:stencil-translate-axis
2782 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2788 (let ((divisor (log 2)))
2789 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2791 (define (parse-simple-duration duration-string)
2792 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2793 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2794 (if (and match (string=? duration-string (match:substring match 0)))
2795 (let ((len (match:substring match 1))
2796 (dots (match:substring match 2)))
2797 (list (cond ((string=? len "breve") -1)
2798 ((string=? len "longa") -2)
2799 ((string=? len "maxima") -3)
2800 (else (log2 (string->number len))))
2801 (if dots (string-length dots) 0)))
2802 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2804 (define-builtin-markup-command (note layout props duration dir)
2807 (note-by-number-markup)
2809 @cindex notes within text by string
2811 This produces a note with a stem pointing in @var{dir} direction, with
2812 the @var{duration} for the note head type and augmentation dots. For
2813 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2814 a shortened down stem.
2816 @lilypond[verbatim,quote]
2818 \\override #'(style . cross) {
2822 \\note #\"breve\" #0
2825 (let ((parsed (parse-simple-duration duration)))
2826 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2832 (define-builtin-markup-command (lower layout props amount arg)
2837 @cindex lowering text
2839 Lower @var{arg} by the distance @var{amount}.
2840 A negative @var{amount} indicates raising; see also @code{\\raise}.
2842 @lilypond[verbatim,quote]
2850 (ly:stencil-translate-axis (interpret-markup layout props arg)
2853 (define-builtin-markup-command (translate-scaled layout props offset arg)
2854 (number-pair? markup?)
2858 @cindex translating text
2859 @cindex scaling text
2861 Translate @var{arg} by @var{offset}, scaling the offset by the
2864 @lilypond[verbatim,quote]
2867 * \\translate #'(2 . 3) translate
2869 * \\translate-scaled #'(2 . 3) translate-scaled
2873 (let* ((factor (magstep font-size))
2874 (scaled (cons (* factor (car offset))
2875 (* factor (cdr offset)))))
2876 (ly:stencil-translate (interpret-markup layout props arg)
2879 (define-builtin-markup-command (raise layout props amount arg)
2884 @cindex raising text
2886 Raise @var{arg} by the distance @var{amount}.
2887 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2889 The argument to @code{\\raise} is the vertical displacement amount,
2890 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2891 raise objects in relation to their surrounding markups.
2893 If the text object itself is positioned above or below the staff, then
2894 @code{\\raise} cannot be used to move it, since the mechanism that
2895 positions it next to the staff cancels any shift made with
2896 @code{\\raise}. For vertical positioning, use the @code{padding}
2897 and/or @code{extra-offset} properties.
2899 @lilypond[verbatim,quote]
2908 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2910 (define-builtin-markup-command (fraction layout props arg1 arg2)
2915 @cindex creating text fractions
2917 Make a fraction of two markups.
2918 @lilypond[verbatim,quote]
2924 (let* ((m1 (interpret-markup layout props arg1))
2925 (m2 (interpret-markup layout props arg2))
2926 (factor (magstep font-size))
2927 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2928 (padding (* factor 0.2))
2929 (baseline (* factor 0.6))
2930 (offset (* factor 0.75)))
2931 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2932 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2933 (let* ((x1 (ly:stencil-extent m1 X))
2934 (x2 (ly:stencil-extent m2 X))
2935 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2936 ;; should stack mols separately, to maintain LINE on baseline
2937 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2939 (ly:stencil-aligned-to stack Y CENTER))
2941 (ly:stencil-aligned-to stack X LEFT))
2942 ;; should have EX dimension
2944 (ly:stencil-translate-axis stack offset Y))))
2946 (define-builtin-markup-command (normal-size-super layout props arg)
2951 @cindex setting superscript in standard font size
2953 Set @var{arg} in superscript with a normal font size.
2955 @lilypond[verbatim,quote]
2958 \\normal-size-super {
2959 superscript in standard size
2963 (ly:stencil-translate-axis
2964 (interpret-markup layout props arg)
2965 (* 0.5 baseline-skip) Y))
2967 (define-builtin-markup-command (super layout props arg)
2973 @cindex superscript text
2975 Set @var{arg} in superscript.
2977 @lilypond[verbatim,quote]
2987 (ly:stencil-translate-axis
2990 (cons `((font-size . ,(- font-size 3))) props)
2992 (* 0.5 baseline-skip)
2995 (define-builtin-markup-command (translate layout props offset arg)
2996 (number-pair? markup?)
3000 @cindex translating text
3002 Translate @var{arg} relative to its surroundings. @var{offset}
3003 is a pair of numbers representing the displacement in the X and Y axis.
3005 @lilypond[verbatim,quote]
3008 \\translate #'(2 . 3)
3009 \\line { translated two spaces right, three up }
3012 (ly:stencil-translate (interpret-markup layout props arg)
3015 (define-builtin-markup-command (sub layout props arg)
3021 @cindex subscript text
3023 Set @var{arg} in subscript.
3025 @lilypond[verbatim,quote]
3036 (ly:stencil-translate-axis
3039 (cons `((font-size . ,(- font-size 3))) props)
3041 (* -0.5 baseline-skip)
3044 (define-builtin-markup-command (normal-size-sub layout props arg)
3049 @cindex setting subscript in standard font size
3051 Set @var{arg} in subscript with a normal font size.
3053 @lilypond[verbatim,quote]
3057 subscript in standard size
3061 (ly:stencil-translate-axis
3062 (interpret-markup layout props arg)
3063 (* -0.5 baseline-skip)
3066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3068 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3070 (define-builtin-markup-command (hbracket layout props arg)
3075 @cindex placing horizontal brackets around text
3077 Draw horizontal brackets around @var{arg}.
3079 @lilypond[verbatim,quote]
3088 (let ((th 0.1) ;; todo: take from GROB.
3089 (m (interpret-markup layout props arg)))
3090 (bracketify-stencil m X th (* 2.5 th) th)))
3092 (define-builtin-markup-command (bracket layout props arg)
3097 @cindex placing vertical brackets around text
3099 Draw vertical brackets around @var{arg}.
3101 @lilypond[verbatim,quote]
3108 (let ((th 0.1) ;; todo: take from GROB.
3109 (m (interpret-markup layout props arg)))
3110 (bracketify-stencil m Y th (* 2.5 th) th)))
3112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3113 ;; Delayed markup evaluation
3114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3116 (define-builtin-markup-command (page-ref layout props label gauge default)
3117 (symbol? markup? markup?)
3121 @cindex referencing page numbers in text
3123 Reference to a page number. @var{label} is the label set on the referenced
3124 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3125 the maximum width of the page number, and @var{default} the value to display
3126 when @var{label} is not found."
3127 (let* ((gauge-stencil (interpret-markup layout props gauge))
3128 (x-ext (ly:stencil-extent gauge-stencil X))
3129 (y-ext (ly:stencil-extent gauge-stencil Y)))
3131 `(delay-stencil-evaluation
3132 ,(delay (ly:stencil-expr
3133 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3134 (page-number (if (list? table)
3135 (assoc-get label table)
3137 (page-markup (if page-number (format "~a" page-number) default))
3138 (page-stencil (interpret-markup layout props page-markup))
3139 (gap (- (interval-length x-ext)
3140 (interval-length (ly:stencil-extent page-stencil X)))))
3141 (interpret-markup layout props
3142 (markup #:concat (#:hspace gap page-markup)))))))
3146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3147 ;; Markup list commands
3148 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3150 (define-public (space-lines baseline stils)
3151 (let space-stil ((stils stils)
3155 (let* ((stil (car stils))
3156 (dy-top (max (- (/ baseline 1.5)
3157 (interval-bound (ly:stencil-extent stil Y) UP))
3159 (dy-bottom (max (+ (/ baseline 3.0)
3160 (interval-bound (ly:stencil-extent stil Y) DOWN))
3162 (new-stil (ly:make-stencil
3163 (ly:stencil-expr stil)
3164 (ly:stencil-extent stil X)
3165 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3167 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3169 (space-stil (cdr stils) (cons new-stil result))))))
3171 (define-builtin-markup-list-command (justified-lines layout props args)
3174 wordwrap-internal-markup-list)
3176 @cindex justifying lines of text
3178 Like @code{\\justify}, but return a list of lines instead of a single markup.
3179 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3180 @var{X}@tie{}is the number of staff spaces."
3181 (space-lines baseline-skip
3182 (interpret-markup-list layout props
3183 (make-wordwrap-internal-markup-list #t args))))
3185 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3188 wordwrap-internal-markup-list)
3189 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3190 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3191 where @var{X} is the number of staff spaces."
3192 (space-lines baseline-skip
3193 (interpret-markup-list layout props
3194 (make-wordwrap-internal-markup-list #f args))))
3196 (define-builtin-markup-list-command (column-lines layout props args)
3199 "Like @code{\\column}, but return a list of lines instead of a single markup.
3200 @code{baseline-skip} determines the space between each markup in @var{args}."
3201 (space-lines (chain-assoc-get 'baseline-skip props)
3202 (interpret-markup-list layout props args)))
3204 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3205 (pair? markup-list?)
3207 "Like @code{\\override}, for markup lists."
3208 (interpret-markup-list layout (cons (list new-prop) props) args))