1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2008 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))))
405 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
406 ;; importing graphics.
407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 (define-builtin-markup-command (stencil layout props stil)
414 @cindex importing stencils into text
416 Use a stencil as markup.
418 @lilypond[verbatim,quote]
420 \\stencil #(make-circle-stencil 2 0 #t)
426 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
428 (define (get-postscript-bbox string)
429 "Extract the bbox from STRING, or return #f if not present."
431 ((match (regexp-exec bbox-regexp string)))
435 (string->number (match:substring match x)))
440 (define-builtin-markup-command (epsfile layout props axis size file-name)
441 (number? number? string?)
445 @cindex inlining an Encapsulated PostScript image
447 Inline an EPS image. The image is scaled along @var{axis} to
450 @lilypond[verbatim,quote]
452 \\general-align #Y #DOWN {
453 \\epsfile #X #20 #\"context-example.eps\"
454 \\epsfile #Y #20 #\"context-example.eps\"
458 (if (ly:get-option 'safe)
459 (interpret-markup layout props "not allowed in safe")
460 (eps-file->stencil axis size file-name)
463 (define-builtin-markup-command (postscript layout props str)
468 @cindex inserting PostScript directly into text
469 This inserts @var{str} directly into the output as a PostScript
472 @lilypond[verbatim,quote]
478 0.7 0.7 0.5 0 361 arc
480 2.20 0.70 0.50 0 361 arc
482 1.45 0.85 0.30 0 180 arc
486 0.92 2.26 1.30 2.40 1.15 1.70 curveto
490 3.42 2.26 3.80 2.40 3.65 1.70 curveto
493 eyeglasses = \\markup {
494 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
495 \\postscript #eyeglassesps
507 gsave currentpoint translate
515 (define-builtin-markup-command (score layout props score)
520 @cindex inserting music into text
522 Inline an image of music.
524 @lilypond[verbatim,quote]
528 \\new Staff \\relative c' {
531 \\mark \\markup { Allegro }
537 \\new Staff \\relative c {
551 \\override RehearsalMark #'break-align-symbols =
552 #'(time-signature key-signature)
553 \\override RehearsalMark #'self-alignment-X = #LEFT
557 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
563 (let* ((output (ly:score-embedded-format score layout)))
565 (if (ly:music-output? output)
566 (paper-system-stencil
567 (vector-ref (ly:paper-score-paper-systems output) 0))
569 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
572 (define-builtin-markup-command (null layout props)
577 @cindex creating empty text objects
579 An empty markup with extents of a single point.
581 @lilypond[verbatim,quote]
588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
592 (define-builtin-markup-command (simple layout props str)
597 @cindex simple text strings
599 A simple text string; @code{\\markup @{ foo @}} is equivalent with
600 @code{\\markup @{ \\simple #\"foo\" @}}.
602 Note: for creating standard text markup or defining new markup commands,
603 the use of @code{\\simple} is unnecessary.
605 @lilypond[verbatim,quote]
609 \\simple #\"strings\"
612 (interpret-markup layout props str))
614 (define-builtin-markup-command (tied-lyric layout props str)
619 @cindex simple text strings with tie characters
621 Like simple-markup, but use tie characters for @q{~} tilde symbols.
623 @lilypond[verbatim,quote]
625 \\tied-lyric #\"Lasciate~i monti\"
628 (if (string-contains str "~")
630 ((parts (string-split str #\~))
631 (tie-str (ly:wide-char->utf-8 #x203f))
632 (joined (list-join parts tie-str))
633 (join-stencil (interpret-markup layout props tie-str))
636 (interpret-markup layout
639 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
641 (make-line-markup joined)))
642 ;(map (lambda (s) (interpret-markup layout props s)) parts))
643 (interpret-markup layout props str)))
645 (define-public empty-markup
646 (make-simple-markup ""))
648 ;; helper for justifying lines.
649 (define (get-fill-space word-count line-width text-widths)
650 "Calculate the necessary paddings between each two adjacent texts.
651 The lengths of all texts are stored in @var{text-widths}.
652 The normal formula for the padding between texts a and b is:
653 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
654 The first and last padding have to be calculated specially using the
655 whole length of the first or last text.
656 Return a list of paddings."
658 ((null? text-widths) '())
660 ;; special case first padding
661 ((= (length text-widths) word-count)
663 (- (- (/ line-width (1- word-count)) (car text-widths))
664 (/ (car (cdr text-widths)) 2))
665 (get-fill-space word-count line-width (cdr text-widths))))
666 ;; special case last padding
667 ((= (length text-widths) 2)
668 (list (- (/ line-width (1- word-count))
669 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
672 (- (/ line-width (1- word-count))
673 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
674 (get-fill-space word-count line-width (cdr text-widths))))))
676 (define-builtin-markup-command (fill-line layout props args)
679 ((text-direction RIGHT)
682 "Put @var{markups} in a horizontal line of width @var{line-width}.
683 The markups are spaced or flushed to fill the entire line.
684 If there are no arguments, return an empty stencil.
686 @lilypond[verbatim,quote]
690 Words evenly spaced across the page
694 \\line { Text markups }
696 \\italic { evenly spaced }
698 \\line { across the page }
703 (let* ((orig-stencils (interpret-markup-list layout props args))
706 (if (ly:stencil-empty? stc)
708 stc)) orig-stencils))
711 (if (ly:stencil-empty? stc)
713 (interval-length (ly:stencil-extent stc X))))
715 (text-width (apply + text-widths))
716 (word-count (length stencils))
717 (prop-line-width (chain-assoc-get 'line-width props #f))
718 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
723 (/ (- line-width text-width) 2)
724 (/ (- line-width text-width) 2)))
727 (- line-width text-width)))
729 (get-fill-space word-count line-width text-widths))))
737 (line-stencils (if (= word-count 1)
744 (if (= text-direction LEFT)
745 (set! line-stencils (reverse line-stencils)))
747 (if (null? (remove ly:stencil-empty? orig-stencils))
749 (stack-stencils-padding-list X
750 RIGHT fill-space-normal line-stencils))))
752 (define-builtin-markup-command (line layout props args)
756 (text-direction RIGHT))
757 "Put @var{args} in a horizontal line. The property @code{word-space}
758 determines the space between markups in @var{args}.
760 @lilypond[verbatim,quote]
767 (let ((stencils (interpret-markup-list layout props args)))
768 (if (= text-direction LEFT)
769 (set! stencils (reverse stencils)))
772 (remove ly:stencil-empty? stencils))))
774 (define-builtin-markup-command (concat layout props args)
779 @cindex concatenating text
780 @cindex ligatures in text
782 Concatenate @var{args} in a horizontal line, without spaces in between.
783 Strings and simple markups are concatenated on the input level, allowing
784 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
785 equivalent to @code{\"fi\"}.
787 @lilypond[verbatim,quote]
796 (define (concat-string-args arg-list)
797 (fold-right (lambda (arg result-list)
798 (let ((result (if (pair? result-list)
801 (if (and (pair? arg) (eqv? (car arg) simple-markup))
802 (set! arg (cadr arg)))
803 (if (and (string? result) (string? arg))
804 (cons (string-append arg result) (cdr result-list))
805 (cons arg result-list))))
809 (interpret-markup layout
810 (prepend-alist-chain 'word-space 0 props)
811 (make-line-markup (if (markup-command-list? args)
813 (concat-string-args args)))))
815 (define (wordwrap-stencils stencils
816 justify base-space line-width text-dir)
817 "Perform simple wordwrap, return stencil of each line."
818 (define space (if justify
819 ;; justify only stretches lines.
822 (define (take-list width space stencils
823 accumulator accumulated-width)
824 "Return (head-list . tail) pair, with head-list fitting into width"
826 (cons accumulator stencils)
827 (let* ((first (car stencils))
828 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
829 (newwid (+ space first-wid accumulated-width)))
830 (if (or (null? accumulator)
832 (take-list width space
834 (cons first accumulator)
836 (cons accumulator stencils)))))
837 (let loop ((lines '())
839 (let* ((line-break (take-list line-width space todo
841 (line-stencils (car line-break))
842 (space-left (- line-width
843 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
845 (line-word-space (cond ((not justify) space)
846 ;; don't stretch last line of paragraph.
847 ;; hmmm . bug - will overstretch the last line in some case.
848 ((null? (cdr line-break))
850 ((null? line-stencils) 0.0)
851 ((null? (cdr line-stencils)) 0.0)
852 (else (/ space-left (1- (length line-stencils))))))
853 (line (stack-stencil-line line-word-space
854 (if (= text-dir RIGHT)
855 (reverse line-stencils)
857 (if (pair? (cdr line-break))
858 (loop (cons line lines)
861 (if (= text-dir LEFT)
863 (ly:stencil-translate-axis
865 (- line-width (interval-end (ly:stencil-extent line X)))
867 (reverse (cons line lines)))))))
869 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
870 (boolean? markup-list?)
873 (text-direction RIGHT))
874 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
875 (wordwrap-stencils (remove ly:stencil-empty?
876 (interpret-markup-list layout props args))
880 (ly:output-def-lookup layout 'line-width))
883 (define-builtin-markup-command (justify layout props args)
887 wordwrap-internal-markup-list)
889 @cindex justifying text
891 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
892 Use @code{\\override #'(line-width . @var{X})} to set the line width;
893 @var{X}@tie{}is the number of staff spaces.
895 @lilypond[verbatim,quote]
898 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
899 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
900 Ut enim ad minim veniam, quis nostrud exercitation ullamco
901 laboris nisi ut aliquip ex ea commodo consequat.
905 (stack-lines DOWN 0.0 baseline-skip
906 (wordwrap-internal-markup-list layout props #t args)))
908 (define-builtin-markup-command (wordwrap layout props args)
912 wordwrap-internal-markup-list)
913 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
914 the line width, where @var{X} is the number of staff spaces.
916 @lilypond[verbatim,quote]
919 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
920 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
921 Ut enim ad minim veniam, quis nostrud exercitation ullamco
922 laboris nisi ut aliquip ex ea commodo consequat.
926 (stack-lines DOWN 0.0 baseline-skip
927 (wordwrap-internal-markup-list layout props #f args)))
929 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
933 (text-direction RIGHT))
934 "Internal markup list command used to define @code{\\justify-string} and
935 @code{\\wordwrap-string}."
936 (let* ((para-strings (regexp-split
937 (string-regexp-substitute
939 (string-regexp-substitute "\r\n" "\n" arg))
940 "\n[ \t\n]*\n[ \t\n]*"))
941 (list-para-words (map (lambda (str)
942 (regexp-split str "[ \t\n]+"))
944 (para-lines (map (lambda (words)
946 (remove ly:stencil-empty?
948 (interpret-markup layout props x))
950 (wordwrap-stencils stencils
952 line-width text-direction)))
954 (apply append para-lines)))
956 (define-builtin-markup-command (wordwrap-string layout props arg)
960 wordwrap-string-internal-markup-list)
961 "Wordwrap a string. Paragraphs may be separated with double newlines.
963 @lilypond[verbatim,quote]
965 \\override #'(line-width . 40)
966 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
967 adipisicing elit, sed do eiusmod tempor incididunt ut labore
968 et dolore magna aliqua.
971 Ut enim ad minim veniam, quis nostrud exercitation ullamco
972 laboris nisi ut aliquip ex ea commodo consequat.
975 Excepteur sint occaecat cupidatat non proident, sunt in culpa
976 qui officia deserunt mollit anim id est laborum\"
979 (stack-lines DOWN 0.0 baseline-skip
980 (wordwrap-string-internal-markup-list layout props #f arg)))
982 (define-builtin-markup-command (justify-string layout props arg)
986 wordwrap-string-internal-markup-list)
987 "Justify a string. Paragraphs may be separated with double newlines
989 @lilypond[verbatim,quote]
991 \\override #'(line-width . 40)
992 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
993 adipisicing elit, sed do eiusmod tempor incididunt ut labore
994 et dolore magna aliqua.
997 Ut enim ad minim veniam, quis nostrud exercitation ullamco
998 laboris nisi ut aliquip ex ea commodo consequat.
1001 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1002 qui officia deserunt mollit anim id est laborum\"
1005 (stack-lines DOWN 0.0 baseline-skip
1006 (wordwrap-string-internal-markup-list layout props #t arg)))
1008 (define-builtin-markup-command (wordwrap-field layout props symbol)
1012 "Wordwrap the data which has been assigned to @var{symbol}.
1014 @lilypond[verbatim,quote]
1016 title = \"My title\"
1017 description = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1018 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1019 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1020 laboris nisi ut aliquip ex ea commodo consequat.\"
1024 bookTitleMarkup = \\markup {
1026 \\fill-line { \\fromproperty #'header:title }
1028 \\wordwrap-field #'header:descr
1037 (let* ((m (chain-assoc-get symbol props)))
1039 (wordwrap-string-markup layout props m)
1042 (define-builtin-markup-command (justify-field layout props symbol)
1046 "Justify the data which has been assigned to @var{symbol}.
1048 @lilypond[verbatim,quote]
1050 title = \"My title\"
1051 description = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1052 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1053 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1054 laboris nisi ut aliquip ex ea commodo consequat.\"
1058 bookTitleMarkup = \\markup {
1060 \\fill-line { \\fromproperty #'header:title }
1062 \\justify-field #'header:description
1071 (let* ((m (chain-assoc-get symbol props)))
1073 (justify-string-markup layout props m)
1076 (define-builtin-markup-command (combine layout props arg1 arg2)
1081 @cindex merging text
1083 Print two markups on top of each other.
1085 Note: @code{\\combine} cannot take a list of markups enclosed in
1086 curly braces as an argument; the follow example will not compile:
1089 \\combine @{ a list @}
1092 @lilypond[verbatim,quote]
1095 \\override #'(thickness . 2)
1097 \\draw-line #'(0 . 4)
1098 \\arrow-head #Y #DOWN ##f
1101 (let* ((s1 (interpret-markup layout props arg1))
1102 (s2 (interpret-markup layout props arg2)))
1103 (ly:stencil-add s1 s2)))
1106 ;; TODO: should extract baseline-skip from each argument somehow..
1108 (define-builtin-markup-command (column layout props args)
1113 @cindex stacking text in a column
1115 Stack the markups in @var{args} vertically. The property
1116 @code{baseline-skip} determines the space between markups
1119 @lilypond[verbatim,quote]
1128 (let ((arg-stencils (interpret-markup-list layout props args)))
1129 (stack-lines -1 0.0 baseline-skip
1130 (remove ly:stencil-empty? arg-stencils))))
1132 (define-builtin-markup-command (dir-column layout props args)
1138 @cindex changing direction of text columns
1140 Make a column of @var{args}, going up or down, depending on the
1141 setting of the @code{direction} layout property.
1143 @lilypond[verbatim,quote]
1145 \\override #`(direction . ,UP) {
1155 \\override #'(direction . 1) {
1162 (stack-lines (if (number? direction) direction -1)
1165 (interpret-markup-list layout props args)))
1167 (define (general-column align-dir baseline mols)
1168 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1170 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1171 (stack-lines -1 0.0 baseline aligned-mols)))
1173 (define-builtin-markup-command (center-column layout props args)
1178 @cindex centering a column of text
1180 Put @code{args} in a centered column.
1182 @lilypond[verbatim,quote]
1191 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1193 (define-builtin-markup-command (left-column layout props args)
1198 @cindex text columns, left-aligned
1200 Put @code{args} in a left-aligned column.
1202 @lilypond[verbatim,quote]
1211 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1213 (define-builtin-markup-command (right-column layout props args)
1218 @cindex text columns, right-aligned
1220 Put @code{args} in a right-aligned column.
1222 @lilypond[verbatim,quote]
1231 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1233 (define-builtin-markup-command (vcenter layout props arg)
1238 @cindex vertically centering text
1240 Align @code{arg} to its Y@tie{}center.
1242 @lilypond[verbatim,quote]
1250 (let* ((mol (interpret-markup layout props arg)))
1251 (ly:stencil-aligned-to mol Y CENTER)))
1253 (define-builtin-markup-command (center-align layout props arg)
1258 @cindex horizontally centering text
1260 Align @code{arg} to its X@tie{}center.
1262 @lilypond[verbatim,quote]
1272 (let* ((mol (interpret-markup layout props arg)))
1273 (ly:stencil-aligned-to mol X CENTER)))
1275 (define-builtin-markup-command (right-align layout props arg)
1280 @cindex right aligning text
1282 Align @var{arg} on its right edge.
1284 @lilypond[verbatim,quote]
1294 (let* ((m (interpret-markup layout props arg)))
1295 (ly:stencil-aligned-to m X RIGHT)))
1297 (define-builtin-markup-command (left-align layout props arg)
1302 @cindex left aligning text
1304 Align @var{arg} on its left edge.
1306 @lilypond[verbatim,quote]
1316 (let* ((m (interpret-markup layout props arg)))
1317 (ly:stencil-aligned-to m X LEFT)))
1319 (define-builtin-markup-command (general-align layout props axis dir arg)
1320 (integer? number? markup?)
1324 @cindex controlling general text alignment
1326 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1328 @lilypond[verbatim,quote]
1332 \\general-align #X #LEFT
1337 \\general-align #X #CENTER
1343 \\general-align #Y #UP
1350 \\general-align #Y #3.2
1357 (let* ((m (interpret-markup layout props arg)))
1358 (ly:stencil-aligned-to m axis dir)))
1360 (define-builtin-markup-command (halign layout props dir arg)
1365 @cindex setting horizontal text alignment
1367 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1368 left-aligned, while @code{+1} is right. Values in between interpolate
1369 alignment accordingly.
1371 @lilypond[verbatim,quote]
1396 (let* ((m (interpret-markup layout props arg)))
1397 (ly:stencil-aligned-to m X dir)))
1399 (define-builtin-markup-command (with-dimensions layout props x y arg)
1400 (number-pair? number-pair? markup?)
1404 @cindex setting extent of text objects
1406 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1407 (let* ((m (interpret-markup layout props arg)))
1408 (ly:make-stencil (ly:stencil-expr m) x y)))
1410 (define-builtin-markup-command (pad-around layout props amount arg)
1414 "Add padding @var{amount} all around @var{arg}.
1416 @lilypond[verbatim,quote]
1429 (let* ((m (interpret-markup layout props arg))
1430 (x (ly:stencil-extent m X))
1431 (y (ly:stencil-extent m Y)))
1432 (ly:make-stencil (ly:stencil-expr m)
1433 (interval-widen x amount)
1434 (interval-widen y amount))))
1436 (define-builtin-markup-command (pad-x layout props amount arg)
1441 @cindex padding text horizontally
1443 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1445 @lilypond[verbatim,quote]
1458 (let* ((m (interpret-markup layout props arg))
1459 (x (ly:stencil-extent m X))
1460 (y (ly:stencil-extent m Y)))
1461 (ly:make-stencil (ly:stencil-expr m)
1462 (interval-widen x amount)
1465 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1466 (integer? ly:dir? markup? markup?)
1469 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1470 (let ((m1 (interpret-markup layout props arg1))
1471 (m2 (interpret-markup layout props arg2)))
1472 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1474 (define-builtin-markup-command (transparent layout props arg)
1478 "Make @var{arg} transparent.
1480 @lilypond[verbatim,quote]
1487 (let* ((m (interpret-markup layout props arg))
1488 (x (ly:stencil-extent m X))
1489 (y (ly:stencil-extent m Y)))
1490 (ly:make-stencil "" x y)))
1492 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1493 (number-pair? number-pair? markup?)
1496 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1498 @lilypond[verbatim,quote]
1505 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1511 (let* ((m (interpret-markup layout props arg))
1512 (x (ly:stencil-extent m X))
1513 (y (ly:stencil-extent m Y)))
1514 (ly:make-stencil (ly:stencil-expr m)
1515 (interval-union x-ext x)
1516 (interval-union y-ext y))))
1518 (define-builtin-markup-command (hcenter-in layout props length arg)
1522 "Center @var{arg} horizontally within a box of extending
1523 @var{length}/2 to the left and right.
1525 @lilypond[quote,verbatim]
1528 \\set Staff.instrumentName = \\markup {
1535 \\set Staff.instrumentName = \\markup {
1544 (interpret-markup layout props
1545 (make-pad-to-box-markup
1546 (cons (/ length -2) (/ length 2))
1548 (make-center-align-markup arg))))
1550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1554 (define-builtin-markup-command (fromproperty layout props symbol)
1558 "Read the @var{symbol} from property settings, and produce a stencil
1559 from the markup contained within. If @var{symbol} is not defined, it
1560 returns an empty markup.
1562 @lilypond[verbatim,quote]
1564 myTitle = \"myTitle\"
1568 \\fromproperty #'header:myTitle
1575 (let ((m (chain-assoc-get symbol props)))
1577 (interpret-markup layout props m)
1580 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1584 "Apply the @var{procedure} markup command to @var{arg}.
1585 @var{procedure} should take a single argument."
1586 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1587 (set-object-property! anonymous-with-signature
1590 (interpret-markup layout props (list anonymous-with-signature arg))))
1592 (define-builtin-markup-command (override layout props new-prop arg)
1597 @cindex overriding properties within text markup
1599 Add the argument @var{new-prop} to the property list. Properties
1600 may be any property supported by @rinternals{font-interface},
1601 @rinternals{text-interface} and
1602 @rinternals{instrument-specific-markup-interface}.
1604 @lilypond[verbatim,quote]
1612 \\override #'(baseline-skip . 4) {
1621 (interpret-markup layout (cons (list new-prop) props) arg))
1623 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1625 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1627 (define-builtin-markup-command (verbatim-file layout props name)
1631 "Read the contents of file @var{name}, and include it verbatim.
1633 @lilypond[verbatim,quote]
1635 \\verbatim-file #\"simple.ly\"
1638 (interpret-markup layout props
1639 (if (ly:get-option 'safe)
1640 "verbatim-file disabled in safe mode"
1641 (let* ((str (ly:gulp-file name))
1642 (lines (string-split str #\nl)))
1643 (make-typewriter-markup
1644 (make-column-markup lines))))))
1646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1651 (define-builtin-markup-command (smaller layout props arg)
1655 "Decrease the font size relative to the current setting.
1657 @lilypond[verbatim,quote]
1670 (interpret-markup layout props
1671 `(,fontsize-markup -1 ,arg)))
1673 (define-builtin-markup-command (larger layout props arg)
1677 "Increase the font size relative to the current setting.
1679 @lilypond[verbatim,quote]
1687 (interpret-markup layout props
1688 `(,fontsize-markup 1 ,arg)))
1690 (define-builtin-markup-command (finger layout props arg)
1694 "Set @var{arg} as small numbers.
1696 @lilypond[verbatim,quote]
1703 (interpret-markup layout
1704 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1707 (define-builtin-markup-command (abs-fontsize layout props size arg)
1711 "Use @var{size} as the absolute font size to display @var{arg}.
1712 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1714 @lilypond[verbatim,quote]
1716 default text font size
1718 \\abs-fontsize #16 { text font size 16 }
1720 \\abs-fontsize #12 { text font size 12 }
1723 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1724 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1725 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1726 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1727 (magnification (/ size ref-size)))
1728 (interpret-markup layout
1729 (cons `((baseline-skip . ,(* magnification ref-baseline))
1730 (word-space . ,(* magnification ref-word-space))
1731 (font-size . ,(magnification->font-size magnification)))
1735 (define-builtin-markup-command (fontsize layout props increment arg)
1741 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1744 @lilypond[verbatim,quote]
1752 (let ((entries (list
1753 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1754 (cons 'word-space (* word-space (magstep increment)))
1755 (cons 'font-size (+ font-size increment)))))
1756 (interpret-markup layout (cons entries props) arg)))
1758 (define-builtin-markup-command (magnify layout props sz arg)
1763 @cindex magnifying text
1765 Set the font magnification for its argument. In the following
1766 example, the middle@tie{}A is 10% larger:
1769 A \\magnify #1.1 @{ A @} A
1772 Note: Magnification only works if a font name is explicitly selected.
1773 Use @code{\\fontsize} otherwise.
1775 @lilypond[verbatim,quote]
1786 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1789 (define-builtin-markup-command (bold layout props arg)
1793 "Switch to bold font-series.
1795 @lilypond[verbatim,quote]
1803 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1805 (define-builtin-markup-command (sans layout props arg)
1809 "Switch to the sans serif font family.
1811 @lilypond[verbatim,quote]
1820 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1822 (define-builtin-markup-command (number layout props arg)
1826 "Set font family to @code{number}, which yields the font used for
1827 time signatures and fingerings. This font contains numbers and
1828 some punctuation; it has no letters.
1830 @lilypond[verbatim,quote]
1833 0 1 2 3 4 5 6 7 8 9 . ,
1837 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1839 (define-builtin-markup-command (roman layout props arg)
1843 "Set font family to @code{roman}.
1845 @lilypond[verbatim,quote]
1851 text in roman font family
1858 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1860 (define-builtin-markup-command (huge layout props arg)
1864 "Set font size to +2.
1866 @lilypond[verbatim,quote]
1874 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1876 (define-builtin-markup-command (large layout props arg)
1880 "Set font size to +1.
1882 @lilypond[verbatim,quote]
1890 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1892 (define-builtin-markup-command (normalsize layout props arg)
1896 "Set font size to default.
1898 @lilypond[verbatim,quote]
1911 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1913 (define-builtin-markup-command (small layout props arg)
1917 "Set font size to -1.
1919 @lilypond[verbatim,quote]
1927 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1929 (define-builtin-markup-command (tiny layout props arg)
1933 "Set font size to -2.
1935 @lilypond[verbatim,quote]
1943 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1945 (define-builtin-markup-command (teeny layout props arg)
1949 "Set font size to -3.
1951 @lilypond[verbatim,quote]
1959 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1961 (define-builtin-markup-command (fontCaps layout props arg)
1965 "Set @code{font-shape} to @code{caps}
1967 Note: @code{\\fontCaps} requires the installation and selection of
1968 fonts which support the @code{caps} font shape."
1969 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1972 (define-builtin-markup-command (smallCaps layout props arg)
1976 "Emit @var{arg} as small caps.
1978 Note: @code{\\smallCaps} does not support accented characters.
1980 @lilypond[verbatim,quote]
1989 (define (char-list->markup chars lower)
1990 (let ((final-string (string-upcase (reverse-list->string chars))))
1992 (markup #:fontsize -2 final-string)
1994 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1995 (if (null? rest-chars)
1997 (reverse! (cons (char-list->markup currents current-is-lower)
1999 (let* ((ch (car rest-chars))
2000 (is-lower (char-lower-case? ch)))
2001 (if (or (and current-is-lower is-lower)
2002 (and (not current-is-lower) (not is-lower)))
2003 (make-small-caps (cdr rest-chars)
2007 (make-small-caps (cdr rest-chars)
2010 (if (null? currents)
2012 (cons (char-list->markup
2013 currents current-is-lower)
2015 (interpret-markup layout props
2017 (make-small-caps (string->list arg) (list) #f (list))
2020 (define-builtin-markup-command (caps layout props arg)
2024 "Copy of the @code{\\smallCaps} command.
2026 @lilypond[verbatim,quote]
2035 (interpret-markup layout props (make-smallCaps-markup arg)))
2037 (define-builtin-markup-command (dynamic layout props arg)
2041 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2042 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2043 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2044 done in a different font. The recommended font for this is bold and italic.
2045 @lilypond[verbatim,quote]
2053 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2055 (define-builtin-markup-command (text layout props arg)
2059 "Use a text font instead of music symbol or music alphabet font.
2061 @lilypond[verbatim,quote]
2074 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2077 (define-builtin-markup-command (italic layout props arg)
2081 "Use italic @code{font-shape} for @var{arg}.
2083 @lilypond[verbatim,quote]
2091 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2093 (define-builtin-markup-command (typewriter layout props arg)
2097 "Use @code{font-family} typewriter for @var{arg}.
2099 @lilypond[verbatim,quote]
2108 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2110 (define-builtin-markup-command (upright layout props arg)
2114 "Set @code{font-shape} to @code{upright}. This is the opposite
2117 @lilypond[verbatim,quote]
2131 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2133 (define-builtin-markup-command (medium layout props arg)
2137 "Switch to medium font-series (in contrast to bold).
2139 @lilypond[verbatim,quote]
2152 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2155 (define-builtin-markup-command (normal-text layout props arg)
2159 "Set all font related properties (except the size) to get the default
2160 normal text font, no matter what font was used earlier.
2162 @lilypond[verbatim,quote]
2164 \\huge \\bold \\sans \\caps {
2165 Some text with font overrides
2168 Default text, same font-size
2176 (interpret-markup layout
2177 (cons '((font-family . roman) (font-shape . upright)
2178 (font-series . medium) (font-encoding . latin1))
2182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2186 (define-builtin-markup-command (doublesharp layout props)
2190 "Draw a double sharp symbol.
2192 @lilypond[verbatim,quote]
2197 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2199 (define-builtin-markup-command (sesquisharp layout props)
2203 "Draw a 3/2 sharp symbol.
2205 @lilypond[verbatim,quote]
2210 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2212 (define-builtin-markup-command (sharp layout props)
2216 "Draw a sharp symbol.
2218 @lilypond[verbatim,quote]
2223 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2225 (define-builtin-markup-command (semisharp layout props)
2229 "Draw a semisharp symbol.
2231 @lilypond[verbatim,quote]
2236 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2238 (define-builtin-markup-command (natural layout props)
2242 "Draw a natural symbol.
2244 @lilypond[verbatim,quote]
2249 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2251 (define-builtin-markup-command (semiflat layout props)
2255 "Draw a semiflat symbol.
2257 @lilypond[verbatim,quote]
2262 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2264 (define-builtin-markup-command (flat layout props)
2268 "Draw a flat symbol.
2270 @lilypond[verbatim,quote]
2275 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2277 (define-builtin-markup-command (sesquiflat layout props)
2281 "Draw a 3/2 flat symbol.
2283 @lilypond[verbatim,quote]
2288 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2290 (define-builtin-markup-command (doubleflat layout props)
2294 "Draw a double flat symbol.
2296 @lilypond[verbatim,quote]
2301 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2303 (define-builtin-markup-command (with-color layout props color arg)
2308 @cindex coloring text
2310 Draw @var{arg} in color specified by @var{color}.
2312 @lilypond[verbatim,quote]
2324 (let ((stil (interpret-markup layout props arg)))
2325 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2326 (ly:stencil-extent stil X)
2327 (ly:stencil-extent stil Y))))
2329 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2331 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2333 (define-builtin-markup-command (arrow-head layout props axis dir filled)
2334 (integer? ly:dir? boolean?)
2337 "Produce an arrow head in specified direction and axis.
2338 Use the filled head if @var{filled} is specified.
2339 @lilypond[verbatim,quote]
2342 \\general-align #Y #DOWN {
2343 \\arrow-head #Y #UP ##t
2344 \\arrow-head #Y #DOWN ##f
2346 \\arrow-head #X #RIGHT ##f
2347 \\arrow-head #X #LEFT ##f
2353 ((name (format "arrowheads.~a.~a~a"
2360 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2364 (define-builtin-markup-command (musicglyph layout props glyph-name)
2368 "@var{glyph-name} is converted to a musical symbol; for example,
2369 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2370 the music font. See @ruser{The Feta font} for a complete listing of
2371 the possible glyphs.
2373 @lilypond[verbatim,quote]
2376 \\musicglyph #\"rests.2\"
2377 \\musicglyph #\"clefs.G_change\"
2380 (let* ((font (ly:paper-get-font layout
2381 (cons '((font-encoding . fetaMusic)
2385 (glyph (ly:font-get-glyph font glyph-name)))
2386 (if (null? (ly:stencil-expr glyph))
2387 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2392 (define-builtin-markup-command (lookup layout props glyph-name)
2396 "Lookup a glyph by name.
2398 @lilypond[verbatim,quote]
2400 \\override #'(font-encoding . fetaBraces) {
2401 \\lookup #\"brace200\"
2404 \\lookup #\"brace180\"
2408 (ly:font-get-glyph (ly:paper-get-font layout props)
2411 (define-builtin-markup-command (char layout props num)
2415 "Produce a single character. Characters encoded in hexadecimal
2416 format require the prefix @code{#x}.
2418 @lilypond[verbatim,quote]
2420 \\char #65 \\char ##x00a9
2423 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2425 (define number->mark-letter-vector (make-vector 25 #\A))
2430 (if (= i (- (char->integer #\I) (char->integer #\A)))
2432 (vector-set! number->mark-letter-vector j
2433 (integer->char (+ i (char->integer #\A)))))
2435 (define number->mark-alphabet-vector (list->vector
2436 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2438 (define (number->markletter-string vec n)
2439 "Double letters for big marks."
2440 (let* ((lst (vector-length vec)))
2443 (string-append (number->markletter-string vec (1- (quotient n lst)))
2444 (number->markletter-string vec (remainder n lst)))
2445 (make-string 1 (vector-ref vec n)))))
2447 (define-builtin-markup-command (markletter layout props num)
2451 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2452 (skipping letter@tie{}I), and continue with double letters.
2454 @lilypond[verbatim,quote]
2461 (ly:text-interface::interpret-markup layout props
2462 (number->markletter-string number->mark-letter-vector num)))
2464 (define-builtin-markup-command (markalphabet layout props num)
2468 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2469 and continue with double letters.
2471 @lilypond[verbatim,quote]
2478 (ly:text-interface::interpret-markup layout props
2479 (number->markletter-string number->mark-alphabet-vector num)))
2481 (define-public (horizontal-slash-interval num forward number-interval mag)
2483 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2484 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2485 (else (interval-widen number-interval (* mag 0.25))))
2486 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2487 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2488 (else (interval-widen number-interval (* mag 0.25))))
2491 (define-public (adjust-slash-stencil num forward stencil mag)
2494 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2496 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2498 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2500 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2503 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2505 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2510 (define (slashed-digit-internal layout props num forward font-size thickness)
2511 (let* ((mag (magstep font-size))
2513 (ly:output-def-lookup layout 'line-thickness)
2515 ; backward slashes might use slope and point in the other direction!
2516 (dy (* mag (if forward 0.4 -0.4)))
2517 (number-stencil (interpret-markup layout
2518 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2519 (number->string num)))
2520 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2521 (center (interval-center (ly:stencil-extent number-stencil Y)))
2522 ; Use the real extents of the slash, not the whole number, because we
2523 ; might translate the slash later on!
2524 (num-y (interval-widen (cons center center) (abs dy)))
2525 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2526 (slash-stencil (if is-sane
2527 (make-line-stencil thickness
2528 (car num-x) (- (interval-center num-y) dy)
2529 (cdr num-x) (+ (interval-center num-y) dy))
2531 (if (ly:stencil? slash-stencil)
2533 ; for some numbers we need to shift the slash/backslash up or down to make
2534 ; the slashed digit look better
2535 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2536 (set! number-stencil
2537 (ly:stencil-add number-stencil slash-stencil)))
2538 (ly:warning "Unable to create slashed digit ~a" num))
2542 (define-builtin-markup-command (slashed-digit layout props num)
2548 @cindex slashed digits
2550 A feta number, with slash. This is for use in the context of
2551 figured bass notation.
2552 @lilypond[verbatim,quote]
2556 \\override #'(thickness . 3)
2560 (slashed-digit-internal layout props num #t font-size thickness))
2562 (define-builtin-markup-command (backslashed-digit layout props num)
2568 @cindex backslashed digits
2570 A feta number, with backslash. This is for use in the context of
2571 figured bass notation.
2572 @lilypond[verbatim,quote]
2574 \\backslashed-digit #5
2576 \\override #'(thickness . 3)
2577 \\backslashed-digit #7
2580 (slashed-digit-internal layout props num #f font-size thickness))
2582 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2583 ;; the note command.
2584 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2586 ;; TODO: better syntax.
2588 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2589 (number? number? number?)
2594 @cindex notes within text by log and dot-count
2596 Construct a note symbol, with stem. By using fractional values for
2597 @var{dir}, longer or shorter stems can be obtained.
2599 @lilypond[verbatim,quote]
2601 \\note-by-number #3 #0 #DOWN
2603 \\note-by-number #1 #2 #0.8
2606 (define (get-glyph-name-candidates dir log style)
2607 (map (lambda (dir-name)
2608 (format "noteheads.~a~a~a" dir-name (min log 2)
2609 (if (and (symbol? style)
2610 (not (equal? 'default style)))
2611 (symbol->string style)
2613 (list (if (= dir UP) "u" "d")
2616 (define (get-glyph-name font cands)
2619 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2620 (get-glyph-name font (cdr cands))
2623 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2624 (size-factor (magstep font-size))
2625 (stem-length (* size-factor (max 3 (- log 1))))
2626 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2627 (head-glyph (ly:font-get-glyph font head-glyph-name))
2628 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2629 (stem-thickness (* size-factor 0.13))
2630 (stemy (* dir stem-length))
2631 (attach-off (cons (interval-index
2632 (ly:stencil-extent head-glyph X)
2633 (* (sign dir) (car attach-indices)))
2634 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2636 (ly:stencil-extent head-glyph Y)
2637 (cdr attach-indices)))))
2638 (stem-glyph (and (> log 0)
2639 (ly:round-filled-box
2640 (ordered-cons (car attach-off)
2641 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2642 (cons (min stemy (cdr attach-off))
2643 (max stemy (cdr attach-off)))
2644 (/ stem-thickness 3))))
2646 (dot (ly:font-get-glyph font "dots.dot"))
2647 (dotwid (interval-length (ly:stencil-extent dot X)))
2648 (dots (and (> dot-count 0)
2649 (apply ly:stencil-add
2651 (ly:stencil-translate-axis
2652 dot (* 2 x dotwid) X))
2653 (iota dot-count)))))
2654 (flaggl (and (> log 2)
2655 (ly:stencil-translate
2656 (ly:font-get-glyph font
2657 (string-append "flags."
2658 (if (> dir 0) "u" "d")
2659 (number->string log)))
2660 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2662 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2663 ; 16th notes get a special case because their flags hang lower than any other flags.
2664 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2665 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2667 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2668 (if (ly:stencil? stem-glyph)
2669 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2670 (set! stem-glyph head-glyph))
2671 (if (ly:stencil? dots)
2674 (ly:stencil-translate-axis
2676 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2682 (let ((divisor (log 2)))
2683 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2685 (define (parse-simple-duration duration-string)
2686 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2687 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2688 (if (and match (string=? duration-string (match:substring match 0)))
2689 (let ((len (match:substring match 1))
2690 (dots (match:substring match 2)))
2691 (list (cond ((string=? len "breve") -1)
2692 ((string=? len "longa") -2)
2693 ((string=? len "maxima") -3)
2694 (else (log2 (string->number len))))
2695 (if dots (string-length dots) 0)))
2696 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2698 (define-builtin-markup-command (note layout props duration dir)
2701 (note-by-number-markup)
2703 @cindex notes within text by string
2705 This produces a note with a stem pointing in @var{dir} direction, with
2706 the @var{duration} for the note head type and augmentation dots. For
2707 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2708 a shortened down stem.
2710 @lilypond[verbatim,quote]
2712 \\override #'(style . cross) {
2716 \\note #\"breve\" #0
2719 (let ((parsed (parse-simple-duration duration)))
2720 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2724 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2726 (define-builtin-markup-command (lower layout props amount arg)
2731 @cindex lowering text
2733 Lower @var{arg} by the distance @var{amount}.
2734 A negative @var{amount} indicates raising; see also @code{\\raise}.
2736 @lilypond[verbatim,quote]
2744 (ly:stencil-translate-axis (interpret-markup layout props arg)
2747 (define-builtin-markup-command (translate-scaled layout props offset arg)
2748 (number-pair? markup?)
2752 @cindex translating text
2753 @cindex scaling text
2755 Translate @var{arg} by @var{offset}, scaling the offset by the
2758 @lilypond[verbatim,quote]
2761 * \\translate #'(2 . 3) translate
2763 * \\translate-scaled #'(2 . 3) translate-scaled
2767 (let* ((factor (magstep font-size))
2768 (scaled (cons (* factor (car offset))
2769 (* factor (cdr offset)))))
2770 (ly:stencil-translate (interpret-markup layout props arg)
2773 (define-builtin-markup-command (raise layout props amount arg)
2778 @cindex raising text
2780 Raise @var{arg} by the distance @var{amount}.
2781 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2783 The argument to @code{\\raise} is the vertical displacement amount,
2784 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2785 raise objects in relation to their surrounding markups.
2787 If the text object itself is positioned above or below the staff, then
2788 @code{\\raise} cannot be used to move it, since the mechanism that
2789 positions it next to the staff cancels any shift made with
2790 @code{\\raise}. For vertical positioning, use the @code{padding}
2791 and/or @code{extra-offset} properties.
2793 @lilypond[verbatim,quote]
2802 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2804 (define-builtin-markup-command (fraction layout props arg1 arg2)
2809 @cindex creating text fractions
2811 Make a fraction of two markups.
2812 @lilypond[verbatim,quote]
2818 (let* ((m1 (interpret-markup layout props arg1))
2819 (m2 (interpret-markup layout props arg2))
2820 (factor (magstep font-size))
2821 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2822 (padding (* factor 0.2))
2823 (baseline (* factor 0.6))
2824 (offset (* factor 0.75)))
2825 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2826 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2827 (let* ((x1 (ly:stencil-extent m1 X))
2828 (x2 (ly:stencil-extent m2 X))
2829 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2830 ;; should stack mols separately, to maintain LINE on baseline
2831 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2833 (ly:stencil-aligned-to stack Y CENTER))
2835 (ly:stencil-aligned-to stack X LEFT))
2836 ;; should have EX dimension
2838 (ly:stencil-translate-axis stack offset Y))))
2840 (define-builtin-markup-command (normal-size-super layout props arg)
2845 @cindex setting superscript in standard font size
2847 Set @var{arg} in superscript with a normal font size.
2849 @lilypond[verbatim,quote]
2852 \\normal-size-super {
2853 superscript in standard size
2857 (ly:stencil-translate-axis
2858 (interpret-markup layout props arg)
2859 (* 0.5 baseline-skip) Y))
2861 (define-builtin-markup-command (super layout props arg)
2867 @cindex superscript text
2869 Set @var{arg} in superscript.
2871 @lilypond[verbatim,quote]
2881 (ly:stencil-translate-axis
2884 (cons `((font-size . ,(- font-size 3))) props)
2886 (* 0.5 baseline-skip)
2889 (define-builtin-markup-command (translate layout props offset arg)
2890 (number-pair? markup?)
2894 @cindex translating text
2896 Translate @var{arg} relative to its surroundings. @var{offset}
2897 is a pair of numbers representing the displacement in the X and Y axis.
2899 @lilypond[verbatim,quote]
2902 \\translate #'(2 . 3)
2903 \\line { translated two spaces right, three up }
2906 (ly:stencil-translate (interpret-markup layout props arg)
2909 (define-builtin-markup-command (sub layout props arg)
2915 @cindex subscript text
2917 Set @var{arg} in subscript.
2919 @lilypond[verbatim,quote]
2930 (ly:stencil-translate-axis
2933 (cons `((font-size . ,(- font-size 3))) props)
2935 (* -0.5 baseline-skip)
2938 (define-builtin-markup-command (normal-size-sub layout props arg)
2943 @cindex setting subscript in standard font size
2945 Set @var{arg} in subscript with a normal font size.
2947 @lilypond[verbatim,quote]
2951 subscript in standard size
2955 (ly:stencil-translate-axis
2956 (interpret-markup layout props arg)
2957 (* -0.5 baseline-skip)
2960 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2962 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2964 (define-builtin-markup-command (hbracket layout props arg)
2969 @cindex placing horizontal brackets around text
2971 Draw horizontal brackets around @var{arg}.
2973 @lilypond[verbatim,quote]
2982 (let ((th 0.1) ;; todo: take from GROB.
2983 (m (interpret-markup layout props arg)))
2984 (bracketify-stencil m X th (* 2.5 th) th)))
2986 (define-builtin-markup-command (bracket layout props arg)
2991 @cindex placing vertical brackets around text
2993 Draw vertical brackets around @var{arg}.
2995 @lilypond[verbatim,quote]
3002 (let ((th 0.1) ;; todo: take from GROB.
3003 (m (interpret-markup layout props arg)))
3004 (bracketify-stencil m Y th (* 2.5 th) th)))
3006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3007 ;; Delayed markup evaluation
3008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3010 (define-builtin-markup-command (page-ref layout props label gauge default)
3011 (symbol? markup? markup?)
3015 @cindex referencing page numbers in text
3017 Reference to a page number. @var{label} is the label set on the referenced
3018 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3019 the maximum width of the page number, and @var{default} the value to display
3020 when @var{label} is not found."
3021 (let* ((gauge-stencil (interpret-markup layout props gauge))
3022 (x-ext (ly:stencil-extent gauge-stencil X))
3023 (y-ext (ly:stencil-extent gauge-stencil Y)))
3025 `(delay-stencil-evaluation
3026 ,(delay (ly:stencil-expr
3027 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3028 (label-page (and (list? table) (assoc label table)))
3029 (page-number (and label-page (cdr label-page)))
3030 (page-markup (if page-number (format "~a" page-number) default))
3031 (page-stencil (interpret-markup layout props page-markup))
3032 (gap (- (interval-length x-ext)
3033 (interval-length (ly:stencil-extent page-stencil X)))))
3034 (interpret-markup layout props
3035 (markup #:concat (#:hspace gap page-markup)))))))
3039 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3040 ;; Markup list commands
3041 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3043 (define-public (space-lines baseline stils)
3044 (let space-stil ((stils stils)
3048 (let* ((stil (car stils))
3049 (dy-top (max (- (/ baseline 1.5)
3050 (interval-bound (ly:stencil-extent stil Y) UP))
3052 (dy-bottom (max (+ (/ baseline 3.0)
3053 (interval-bound (ly:stencil-extent stil Y) DOWN))
3055 (new-stil (ly:make-stencil
3056 (ly:stencil-expr stil)
3057 (ly:stencil-extent stil X)
3058 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3060 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3062 (space-stil (cdr stils) (cons new-stil result))))))
3064 (define-builtin-markup-list-command (justified-lines layout props args)
3067 wordwrap-internal-markup-list)
3069 @cindex justifying lines of text
3071 Like @code{\\justify}, but return a list of lines instead of a single markup.
3072 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3073 @var{X}@tie{}is the number of staff spaces."
3074 (space-lines baseline-skip
3075 (interpret-markup-list layout props
3076 (make-wordwrap-internal-markup-list #t args))))
3078 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3081 wordwrap-internal-markup-list)
3082 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3083 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3084 where @var{X} is the number of staff spaces."
3085 (space-lines baseline-skip
3086 (interpret-markup-list layout props
3087 (make-wordwrap-internal-markup-list #f args))))
3089 (define-builtin-markup-list-command (column-lines layout props args)
3092 "Like @code{\\column}, but return a list of lines instead of a single markup.
3093 @code{baseline-skip} determines the space between each markup in @var{args}."
3094 (space-lines (chain-assoc-get 'baseline-skip props)
3095 (interpret-markup-list layout props args)))
3097 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3098 (pair? markup-list?)
3100 "Like @code{\\override}, for markup lists."
3101 (interpret-markup-list layout (cons (list new-prop) props) args))