1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (define-builtin-markup-command (draw-line layout props dest)
31 @cindex drawing lines within text
34 @lilypond[verbatim,quote]
37 \\override #'(thickness . 5)
38 \\draw-line #'(-3 . 0)
41 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
45 (make-line-stencil th 0 0 x y)))
47 (define-builtin-markup-command (draw-circle layout props radius thickness 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
470 This inserts @var{str} directly into the output as a PostScript
471 command string. Due to technicalities of the output backends,
472 different scales should be used for the @TeX{} and PostScript backend,
473 selected with @code{-f}.
475 For the @TeX{} backend, the following string prints a rotated text
478 0 0 moveto /ecrm10 findfont
479 1.75 scalefont setfont 90 rotate (hello) show
483 The magical constant 1.75 scales from LilyPond units (staff spaces) to
486 For the postscript backend, use the following
489 gsave /ecrm10 findfont
490 10.0 output-scale div
491 scalefont setfont 90 rotate (hello) show grestore
494 @lilypond[verbatim,quote]
500 0.7 0.7 0.5 0 361 arc
502 2.20 0.70 0.50 0 361 arc
504 1.45 0.85 0.30 0 180 arc
508 0.92 2.26 1.30 2.40 1.15 1.70 curveto
512 3.42 2.26 3.80 2.40 3.65 1.70 curveto
515 eyeglasses = \\markup {
516 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
517 \\postscript #eyeglassesps
529 gsave currentpoint translate
537 (define-builtin-markup-command (score layout props score)
542 @cindex inserting music into text
544 Inline an image of music.
546 @lilypond[verbatim,quote]
550 \\new Staff \\relative c' {
553 \\mark \\markup { Allegro }
559 \\new Staff \\relative c {
573 \\override RehearsalMark #'break-align-symbols =
574 #'(time-signature key-signature)
575 \\override RehearsalMark #'self-alignment-X = #LEFT
579 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
585 (let* ((output (ly:score-embedded-format score layout)))
587 (if (ly:music-output? output)
588 (paper-system-stencil
589 (vector-ref (ly:paper-score-paper-systems output) 0))
591 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
594 (define-builtin-markup-command (null layout props)
599 @cindex creating empty text objects
601 An empty markup with extents of a single point.
603 @lilypond[verbatim,quote]
610 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
612 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
614 (define-builtin-markup-command (simple layout props str)
619 @cindex simple text strings
621 A simple text string; @code{\\markup @{ foo @}} is equivalent with
622 @code{\\markup @{ \\simple #\"foo\" @}}.
624 Note: for creating standard text markup or defining new markup commands,
625 the use of @code{\\simple} is unnecessary.
627 @lilypond[verbatim,quote]
631 \\simple #\"strings\"
634 (interpret-markup layout props str))
636 (define-builtin-markup-command (tied-lyric layout props str)
641 @cindex simple text strings with tie characters
643 Like simple-markup, but use tie characters for @q{~} tilde symbols.
645 @lilypond[verbatim,quote]
647 \\tied-lyric #\"Lasciate~i monti\"
650 (if (string-contains str "~")
652 ((parts (string-split str #\~))
653 (tie-str (ly:wide-char->utf-8 #x203f))
654 (joined (list-join parts tie-str))
655 (join-stencil (interpret-markup layout props tie-str))
658 (interpret-markup layout
661 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
663 (make-line-markup joined)))
664 ;(map (lambda (s) (interpret-markup layout props s)) parts))
665 (interpret-markup layout props str)))
667 (define-public empty-markup
668 (make-simple-markup ""))
670 ;; helper for justifying lines.
671 (define (get-fill-space word-count line-width text-widths)
672 "Calculate the necessary paddings between each two adjacent texts.
673 The lengths of all texts are stored in @var{text-widths}.
674 The normal formula for the padding between texts a and b is:
675 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
676 The first and last padding have to be calculated specially using the
677 whole length of the first or last text.
678 Return a list of paddings."
680 ((null? text-widths) '())
682 ;; special case first padding
683 ((= (length text-widths) word-count)
685 (- (- (/ line-width (1- word-count)) (car text-widths))
686 (/ (car (cdr text-widths)) 2))
687 (get-fill-space word-count line-width (cdr text-widths))))
688 ;; special case last padding
689 ((= (length text-widths) 2)
690 (list (- (/ line-width (1- word-count))
691 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
694 (- (/ line-width (1- word-count))
695 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
696 (get-fill-space word-count line-width (cdr text-widths))))))
698 (define-builtin-markup-command (fill-line layout props args)
701 ((text-direction RIGHT)
704 "Put @var{markups} in a horizontal line of width @var{line-width}.
705 The markups are spaced or flushed to fill the entire line.
706 If there are no arguments, return an empty stencil.
708 @lilypond[verbatim,quote]
712 Words evenly spaced across the page
716 \\line { Text markups }
718 \\italic { evenly spaced }
720 \\line { across the page }
725 (let* ((orig-stencils (interpret-markup-list layout props args))
728 (if (ly:stencil-empty? stc)
730 stc)) orig-stencils))
733 (if (ly:stencil-empty? stc)
735 (interval-length (ly:stencil-extent stc X))))
737 (text-width (apply + text-widths))
738 (word-count (length stencils))
739 (prop-line-width (chain-assoc-get 'line-width props #f))
740 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
745 (/ (- line-width text-width) 2)
746 (/ (- line-width text-width) 2)))
749 (- line-width text-width)))
751 (get-fill-space word-count line-width text-widths))))
759 (line-stencils (if (= word-count 1)
766 (if (= text-direction LEFT)
767 (set! line-stencils (reverse line-stencils)))
769 (if (null? (remove ly:stencil-empty? orig-stencils))
771 (stack-stencils-padding-list X
772 RIGHT fill-space-normal line-stencils))))
774 (define-builtin-markup-command (line layout props args)
778 (text-direction RIGHT))
779 "Put @var{args} in a horizontal line. The property @code{word-space}
780 determines the space between markups in @var{args}.
782 @lilypond[verbatim,quote]
789 (let ((stencils (interpret-markup-list layout props args)))
790 (if (= text-direction LEFT)
791 (set! stencils (reverse stencils)))
794 (remove ly:stencil-empty? stencils))))
796 (define-builtin-markup-command (concat layout props args)
801 @cindex concatenating text
802 @cindex ligatures in text
804 Concatenate @var{args} in a horizontal line, without spaces in between.
805 Strings and simple markups are concatenated on the input level, allowing
806 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
807 equivalent to @code{\"fi\"}.
809 @lilypond[verbatim,quote]
818 (define (concat-string-args arg-list)
819 (fold-right (lambda (arg result-list)
820 (let ((result (if (pair? result-list)
823 (if (and (pair? arg) (eqv? (car arg) simple-markup))
824 (set! arg (cadr arg)))
825 (if (and (string? result) (string? arg))
826 (cons (string-append arg result) (cdr result-list))
827 (cons arg result-list))))
831 (interpret-markup layout
832 (prepend-alist-chain 'word-space 0 props)
833 (make-line-markup (if (markup-command-list? args)
835 (concat-string-args args)))))
837 (define (wordwrap-stencils stencils
838 justify base-space line-width text-dir)
839 "Perform simple wordwrap, return stencil of each line."
840 (define space (if justify
841 ;; justify only stretches lines.
844 (define (take-list width space stencils
845 accumulator accumulated-width)
846 "Return (head-list . tail) pair, with head-list fitting into width"
848 (cons accumulator stencils)
849 (let* ((first (car stencils))
850 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
851 (newwid (+ space first-wid accumulated-width)))
852 (if (or (null? accumulator)
854 (take-list width space
856 (cons first accumulator)
858 (cons accumulator stencils)))))
859 (let loop ((lines '())
861 (let* ((line-break (take-list line-width space todo
863 (line-stencils (car line-break))
864 (space-left (- line-width
865 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
867 (line-word-space (cond ((not justify) space)
868 ;; don't stretch last line of paragraph.
869 ;; hmmm . bug - will overstretch the last line in some case.
870 ((null? (cdr line-break))
872 ((null? line-stencils) 0.0)
873 ((null? (cdr line-stencils)) 0.0)
874 (else (/ space-left (1- (length line-stencils))))))
875 (line (stack-stencil-line line-word-space
876 (if (= text-dir RIGHT)
877 (reverse line-stencils)
879 (if (pair? (cdr line-break))
880 (loop (cons line lines)
883 (if (= text-dir LEFT)
885 (ly:stencil-translate-axis
887 (- line-width (interval-end (ly:stencil-extent line X)))
889 (reverse (cons line lines)))))))
891 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
892 (boolean? markup-list?)
895 (text-direction RIGHT))
896 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
897 (wordwrap-stencils (remove ly:stencil-empty?
898 (interpret-markup-list layout props args))
902 (ly:output-def-lookup layout 'line-width))
905 (define-builtin-markup-command (justify layout props args)
909 wordwrap-internal-markup-list)
911 @cindex justifying text
913 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
914 Use @code{\\override #'(line-width . @var{X})} to set the line width;
915 @var{X}@tie{}is the number of staff spaces.
917 @lilypond[verbatim,quote]
920 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
921 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
922 Ut enim ad minim veniam, quis nostrud exercitation ullamco
923 laboris nisi ut aliquip ex ea commodo consequat.
927 (stack-lines DOWN 0.0 baseline-skip
928 (wordwrap-internal-markup-list layout props #t args)))
930 (define-builtin-markup-command (wordwrap layout props args)
934 wordwrap-internal-markup-list)
935 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
936 the line width, where @var{X} is the number of staff spaces.
938 @lilypond[verbatim,quote]
941 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
942 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
943 Ut enim ad minim veniam, quis nostrud exercitation ullamco
944 laboris nisi ut aliquip ex ea commodo consequat.
948 (stack-lines DOWN 0.0 baseline-skip
949 (wordwrap-internal-markup-list layout props #f args)))
951 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
955 (text-direction RIGHT))
956 "Internal markup list command used to define @code{\\justify-string} and
957 @code{\\wordwrap-string}."
958 (let* ((para-strings (regexp-split
959 (string-regexp-substitute
961 (string-regexp-substitute "\r\n" "\n" arg))
962 "\n[ \t\n]*\n[ \t\n]*"))
963 (list-para-words (map (lambda (str)
964 (regexp-split str "[ \t\n]+"))
966 (para-lines (map (lambda (words)
968 (remove ly:stencil-empty?
970 (interpret-markup layout props x))
972 (wordwrap-stencils stencils
974 line-width text-direction)))
976 (apply append para-lines)))
978 (define-builtin-markup-command (wordwrap-string layout props arg)
982 wordwrap-string-internal-markup-list)
983 "Wordwrap a string. Paragraphs may be separated with double newlines.
985 @lilypond[verbatim,quote]
987 \\override #'(line-width . 40)
988 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
989 adipisicing elit, sed do eiusmod tempor incididunt ut labore
990 et dolore magna aliqua.
993 Ut enim ad minim veniam, quis nostrud exercitation ullamco
994 laboris nisi ut aliquip ex ea commodo consequat.
997 Excepteur sint occaecat cupidatat non proident, sunt in culpa
998 qui officia deserunt mollit anim id est laborum\"
1001 (stack-lines DOWN 0.0 baseline-skip
1002 (wordwrap-string-internal-markup-list layout props #f arg)))
1004 (define-builtin-markup-command (justify-string layout props arg)
1008 wordwrap-string-internal-markup-list)
1009 "Justify a string. Paragraphs may be separated with double newlines
1011 @lilypond[verbatim,quote]
1013 \\override #'(line-width . 40)
1014 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1015 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1016 et dolore magna aliqua.
1019 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1020 laboris nisi ut aliquip ex ea commodo consequat.
1023 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1024 qui officia deserunt mollit anim id est laborum\"
1027 (stack-lines DOWN 0.0 baseline-skip
1028 (wordwrap-string-internal-markup-list layout props #t arg)))
1030 (define-builtin-markup-command (wordwrap-field layout props symbol)
1034 "Wordwrap the data which has been assigned to @var{symbol}.
1036 @lilypond[verbatim,quote]
1038 title = \"My title\"
1039 description = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1040 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1041 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1042 laboris nisi ut aliquip ex ea commodo consequat.\"
1046 bookTitleMarkup = \\markup {
1048 \\fill-line { \\fromproperty #'header:title }
1050 \\wordwrap-field #'header:descr
1059 (let* ((m (chain-assoc-get symbol props)))
1061 (wordwrap-string-markup layout props m)
1064 (define-builtin-markup-command (justify-field layout props symbol)
1068 "Justify the data which has been assigned to @var{symbol}.
1070 @lilypond[verbatim,quote]
1072 title = \"My title\"
1073 description = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1074 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1075 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1076 laboris nisi ut aliquip ex ea commodo consequat.\"
1080 bookTitleMarkup = \\markup {
1082 \\fill-line { \\fromproperty #'header:title }
1084 \\justify-field #'header:description
1093 (let* ((m (chain-assoc-get symbol props)))
1095 (justify-string-markup layout props m)
1098 (define-builtin-markup-command (combine layout props arg1 arg2)
1103 @cindex merging text
1105 Print two markups on top of each other.
1107 Note: @code{\\combine} cannot take a list of markups enclosed in
1108 curly braces as an argument; the follow example will not compile:
1111 \\combine @{ a list @}
1114 @lilypond[verbatim,quote]
1117 \\override #'(thickness . 2)
1119 \\draw-line #'(0 . 4)
1120 \\arrow-head #Y #DOWN ##f
1123 (let* ((s1 (interpret-markup layout props arg1))
1124 (s2 (interpret-markup layout props arg2)))
1125 (ly:stencil-add s1 s2)))
1128 ;; TODO: should extract baseline-skip from each argument somehow..
1130 (define-builtin-markup-command (column layout props args)
1135 @cindex stacking text in a column
1137 Stack the markups in @var{args} vertically. The property
1138 @code{baseline-skip} determines the space between markups
1141 @lilypond[verbatim,quote]
1150 (let ((arg-stencils (interpret-markup-list layout props args)))
1151 (stack-lines -1 0.0 baseline-skip
1152 (remove ly:stencil-empty? arg-stencils))))
1154 (define-builtin-markup-command (dir-column layout props args)
1160 @cindex changing direction of text columns
1162 Make a column of @var{args}, going up or down, depending on the
1163 setting of the @code{direction} layout property.
1165 @lilypond[verbatim,quote]
1167 \\override #`(direction . ,UP) {
1177 \\override #'(direction . 1) {
1184 (stack-lines (if (number? direction) direction -1)
1187 (interpret-markup-list layout props args)))
1189 (define (general-column align-dir baseline mols)
1190 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1192 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1193 (stack-lines -1 0.0 baseline aligned-mols)))
1195 (define-builtin-markup-command (center-column layout props args)
1200 @cindex centering a column of text
1202 Put @code{args} in a centered column.
1204 @lilypond[verbatim,quote]
1213 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1215 (define-builtin-markup-command (left-column layout props args)
1220 @cindex text columns, left-aligned
1222 Put @code{args} in a left-aligned column.
1224 @lilypond[verbatim,quote]
1233 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1235 (define-builtin-markup-command (right-column layout props args)
1240 @cindex text columns, right-aligned
1242 Put @code{args} in a right-aligned column.
1244 @lilypond[verbatim,quote]
1253 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1255 (define-builtin-markup-command (vcenter layout props arg)
1260 @cindex vertically centering text
1262 Align @code{arg} to its Y@tie{}center.
1264 @lilypond[verbatim,quote]
1272 (let* ((mol (interpret-markup layout props arg)))
1273 (ly:stencil-aligned-to mol Y CENTER)))
1275 (define-builtin-markup-command (center-align layout props arg)
1280 @cindex horizontally centering text
1282 Align @code{arg} to its X@tie{}center.
1284 @lilypond[verbatim,quote]
1294 (let* ((mol (interpret-markup layout props arg)))
1295 (ly:stencil-aligned-to mol X CENTER)))
1297 (define-builtin-markup-command (right-align layout props arg)
1302 @cindex right aligning text
1304 Align @var{arg} on its right edge.
1306 @lilypond[verbatim,quote]
1316 (let* ((m (interpret-markup layout props arg)))
1317 (ly:stencil-aligned-to m X RIGHT)))
1319 (define-builtin-markup-command (left-align layout props arg)
1324 @cindex left aligning text
1326 Align @var{arg} on its left edge.
1328 @lilypond[verbatim,quote]
1338 (let* ((m (interpret-markup layout props arg)))
1339 (ly:stencil-aligned-to m X LEFT)))
1341 (define-builtin-markup-command (general-align layout props axis dir arg)
1342 (integer? number? markup?)
1346 @cindex controlling general text alignment
1348 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1350 @lilypond[verbatim,quote]
1354 \\general-align #X #LEFT
1359 \\general-align #X #CENTER
1365 \\general-align #Y #UP
1372 \\general-align #Y #3.2
1379 (let* ((m (interpret-markup layout props arg)))
1380 (ly:stencil-aligned-to m axis dir)))
1382 (define-builtin-markup-command (halign layout props dir arg)
1387 @cindex setting horizontal text alignment
1389 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1390 left-aligned, while @code{+1} is right. Values in between interpolate
1391 alignment accordingly.
1393 @lilypond[verbatim,quote]
1418 (let* ((m (interpret-markup layout props arg)))
1419 (ly:stencil-aligned-to m X dir)))
1421 (define-builtin-markup-command (with-dimensions layout props x y arg)
1422 (number-pair? number-pair? markup?)
1426 @cindex setting extent of text objects
1428 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1429 (let* ((m (interpret-markup layout props arg)))
1430 (ly:make-stencil (ly:stencil-expr m) x y)))
1432 (define-builtin-markup-command (pad-around layout props amount arg)
1436 "Add padding @var{amount} all around @var{arg}.
1438 @lilypond[verbatim,quote]
1451 (let* ((m (interpret-markup layout props arg))
1452 (x (ly:stencil-extent m X))
1453 (y (ly:stencil-extent m Y)))
1454 (ly:make-stencil (ly:stencil-expr m)
1455 (interval-widen x amount)
1456 (interval-widen y amount))))
1458 (define-builtin-markup-command (pad-x layout props amount arg)
1463 @cindex padding text horizontally
1465 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1467 @lilypond[verbatim,quote]
1480 (let* ((m (interpret-markup layout props arg))
1481 (x (ly:stencil-extent m X))
1482 (y (ly:stencil-extent m Y)))
1483 (ly:make-stencil (ly:stencil-expr m)
1484 (interval-widen x amount)
1487 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1488 (integer? ly:dir? markup? markup?)
1491 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1492 (let ((m1 (interpret-markup layout props arg1))
1493 (m2 (interpret-markup layout props arg2)))
1494 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1496 (define-builtin-markup-command (transparent layout props arg)
1500 "Make @var{arg} transparent.
1502 @lilypond[verbatim,quote]
1509 (let* ((m (interpret-markup layout props arg))
1510 (x (ly:stencil-extent m X))
1511 (y (ly:stencil-extent m Y)))
1512 (ly:make-stencil "" x y)))
1514 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1515 (number-pair? number-pair? markup?)
1518 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1520 @lilypond[verbatim,quote]
1527 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1533 (let* ((m (interpret-markup layout props arg))
1534 (x (ly:stencil-extent m X))
1535 (y (ly:stencil-extent m Y)))
1536 (ly:make-stencil (ly:stencil-expr m)
1537 (interval-union x-ext x)
1538 (interval-union y-ext y))))
1540 (define-builtin-markup-command (hcenter-in layout props length arg)
1544 "Center @var{arg} horizontally within a box of extending
1545 @var{length}/2 to the left and right.
1547 @lilypond[quote,verbatim]
1550 \\set Staff.instrumentName = \\markup {
1557 \\set Staff.instrumentName = \\markup {
1566 (interpret-markup layout props
1567 (make-pad-to-box-markup
1568 (cons (/ length -2) (/ length 2))
1570 (make-center-align-markup arg))))
1572 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1576 (define-builtin-markup-command (fromproperty layout props symbol)
1580 "Read the @var{symbol} from property settings, and produce a stencil
1581 from the markup contained within. If @var{symbol} is not defined, it
1582 returns an empty markup.
1584 @lilypond[verbatim,quote]
1586 myTitle = \"myTitle\"
1590 \\fromproperty #'header:myTitle
1597 (let ((m (chain-assoc-get symbol props)))
1599 (interpret-markup layout props m)
1602 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1606 "Apply the @var{procedure} markup command to @var{arg}.
1607 @var{procedure} should take a single argument."
1608 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1609 (set-object-property! anonymous-with-signature
1612 (interpret-markup layout props (list anonymous-with-signature arg))))
1614 (define-builtin-markup-command (override layout props new-prop arg)
1619 @cindex overriding properties within text markup
1621 Add the argument @var{new-prop} to the property list. Properties
1622 may be any property supported by @rinternals{font-interface},
1623 @rinternals{text-interface} and
1624 @rinternals{instrument-specific-markup-interface}.
1626 @lilypond[verbatim,quote]
1634 \\override #'(baseline-skip . 4) {
1643 (interpret-markup layout (cons (list new-prop) props) arg))
1645 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1649 (define-builtin-markup-command (verbatim-file layout props name)
1653 "Read the contents of file @var{name}, and include it verbatim.
1655 @lilypond[verbatim,quote]
1657 \\verbatim-file #\"simple.ly\"
1660 (interpret-markup layout props
1661 (if (ly:get-option 'safe)
1662 "verbatim-file disabled in safe mode"
1663 (let* ((str (ly:gulp-file name))
1664 (lines (string-split str #\nl)))
1665 (make-typewriter-markup
1666 (make-column-markup lines))))))
1668 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1673 (define-builtin-markup-command (smaller layout props arg)
1677 "Decrease the font size relative to the current setting.
1679 @lilypond[verbatim,quote]
1692 (interpret-markup layout props
1693 `(,fontsize-markup -1 ,arg)))
1695 (define-builtin-markup-command (larger layout props arg)
1699 "Increase the font size relative to the current setting.
1701 @lilypond[verbatim,quote]
1709 (interpret-markup layout props
1710 `(,fontsize-markup 1 ,arg)))
1712 (define-builtin-markup-command (finger layout props arg)
1716 "Set @var{arg} as small numbers.
1718 @lilypond[verbatim,quote]
1725 (interpret-markup layout
1726 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1729 (define-builtin-markup-command (abs-fontsize layout props size arg)
1733 "Use @var{size} as the absolute font size to display @var{arg}.
1734 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1736 @lilypond[verbatim,quote]
1738 default text font size
1740 \\abs-fontsize #16 { text font size 16 }
1742 \\abs-fontsize #12 { text font size 12 }
1745 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1746 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1747 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1748 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1749 (magnification (/ size ref-size)))
1750 (interpret-markup layout
1751 (cons `((baseline-skip . ,(* magnification ref-baseline))
1752 (word-space . ,(* magnification ref-word-space))
1753 (font-size . ,(magnification->font-size magnification)))
1757 (define-builtin-markup-command (fontsize layout props increment arg)
1763 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1766 @lilypond[verbatim,quote]
1774 (let ((entries (list
1775 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1776 (cons 'word-space (* word-space (magstep increment)))
1777 (cons 'font-size (+ font-size increment)))))
1778 (interpret-markup layout (cons entries props) arg)))
1780 (define-builtin-markup-command (magnify layout props sz arg)
1785 @cindex magnifying text
1787 Set the font magnification for its argument. In the following
1788 example, the middle@tie{}A is 10% larger:
1791 A \\magnify #1.1 @{ A @} A
1794 Note: Magnification only works if a font name is explicitly selected.
1795 Use @code{\\fontsize} otherwise.
1797 @lilypond[verbatim,quote]
1808 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1811 (define-builtin-markup-command (bold layout props arg)
1815 "Switch to bold font-series.
1817 @lilypond[verbatim,quote]
1825 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1827 (define-builtin-markup-command (sans layout props arg)
1831 "Switch to the sans serif font family.
1833 @lilypond[verbatim,quote]
1842 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1844 (define-builtin-markup-command (number layout props arg)
1848 "Set font family to @code{number}, which yields the font used for
1849 time signatures and fingerings. This font contains numbers and
1850 some punctuation; it has no letters.
1852 @lilypond[verbatim,quote]
1855 0 1 2 3 4 5 6 7 8 9 . ,
1859 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1861 (define-builtin-markup-command (roman layout props arg)
1865 "Set font family to @code{roman}.
1867 @lilypond[verbatim,quote]
1873 text in roman font family
1880 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1882 (define-builtin-markup-command (huge layout props arg)
1886 "Set font size to +2.
1888 @lilypond[verbatim,quote]
1896 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1898 (define-builtin-markup-command (large layout props arg)
1902 "Set font size to +1.
1904 @lilypond[verbatim,quote]
1912 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1914 (define-builtin-markup-command (normalsize layout props arg)
1918 "Set font size to default.
1920 @lilypond[verbatim,quote]
1933 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1935 (define-builtin-markup-command (small layout props arg)
1939 "Set font size to -1.
1941 @lilypond[verbatim,quote]
1949 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1951 (define-builtin-markup-command (tiny layout props arg)
1955 "Set font size to -2.
1957 @lilypond[verbatim,quote]
1965 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1967 (define-builtin-markup-command (teeny layout props arg)
1971 "Set font size to -3.
1973 @lilypond[verbatim,quote]
1981 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1983 (define-builtin-markup-command (fontCaps layout props arg)
1987 "Set @code{font-shape} to @code{caps}
1989 Note: @code{\\fontCaps} requires the installation and selection of
1990 fonts which support the @code{caps} font shape."
1991 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1994 (define-builtin-markup-command (smallCaps layout props arg)
1998 "Emit @var{arg} as small caps.
2000 Note: @code{\\smallCaps} does not support accented characters.
2002 @lilypond[verbatim,quote]
2011 (define (char-list->markup chars lower)
2012 (let ((final-string (string-upcase (reverse-list->string chars))))
2014 (markup #:fontsize -2 final-string)
2016 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2017 (if (null? rest-chars)
2019 (reverse! (cons (char-list->markup currents current-is-lower)
2021 (let* ((ch (car rest-chars))
2022 (is-lower (char-lower-case? ch)))
2023 (if (or (and current-is-lower is-lower)
2024 (and (not current-is-lower) (not is-lower)))
2025 (make-small-caps (cdr rest-chars)
2029 (make-small-caps (cdr rest-chars)
2032 (if (null? currents)
2034 (cons (char-list->markup
2035 currents current-is-lower)
2037 (interpret-markup layout props
2039 (make-small-caps (string->list arg) (list) #f (list))
2042 (define-builtin-markup-command (caps layout props arg)
2046 "Copy of the @code{\\smallCaps} command.
2048 @lilypond[verbatim,quote]
2057 (interpret-markup layout props (make-smallCaps-markup arg)))
2059 (define-builtin-markup-command (dynamic layout props arg)
2063 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2064 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2065 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2066 done in a different font. The recommended font for this is bold and italic.
2067 @lilypond[verbatim,quote]
2075 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2077 (define-builtin-markup-command (text layout props arg)
2081 "Use a text font instead of music symbol or music alphabet font.
2083 @lilypond[verbatim,quote]
2096 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2099 (define-builtin-markup-command (italic layout props arg)
2103 "Use italic @code{font-shape} for @var{arg}.
2105 @lilypond[verbatim,quote]
2113 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2115 (define-builtin-markup-command (typewriter layout props arg)
2119 "Use @code{font-family} typewriter for @var{arg}.
2121 @lilypond[verbatim,quote]
2130 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2132 (define-builtin-markup-command (upright layout props arg)
2136 "Set @code{font-shape} to @code{upright}. This is the opposite
2139 @lilypond[verbatim,quote]
2153 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2155 (define-builtin-markup-command (medium layout props arg)
2159 "Switch to medium font-series (in contrast to bold).
2161 @lilypond[verbatim,quote]
2174 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2177 (define-builtin-markup-command (normal-text layout props arg)
2181 "Set all font related properties (except the size) to get the default
2182 normal text font, no matter what font was used earlier.
2184 @lilypond[verbatim,quote]
2186 \\huge \\bold \\sans \\caps {
2187 Some text with font overrides
2190 Default text, same font-size
2198 (interpret-markup layout
2199 (cons '((font-family . roman) (font-shape . upright)
2200 (font-series . medium) (font-encoding . latin1))
2204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2206 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2208 (define-builtin-markup-command (doublesharp layout props)
2212 "Draw a double sharp symbol.
2214 @lilypond[verbatim,quote]
2219 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2221 (define-builtin-markup-command (sesquisharp layout props)
2225 "Draw a 3/2 sharp symbol.
2227 @lilypond[verbatim,quote]
2232 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2234 (define-builtin-markup-command (sharp layout props)
2238 "Draw a sharp symbol.
2240 @lilypond[verbatim,quote]
2245 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2247 (define-builtin-markup-command (semisharp layout props)
2251 "Draw a semisharp symbol.
2253 @lilypond[verbatim,quote]
2258 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2260 (define-builtin-markup-command (natural layout props)
2264 "Draw a natural symbol.
2266 @lilypond[verbatim,quote]
2271 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2273 (define-builtin-markup-command (semiflat layout props)
2277 "Draw a semiflat symbol.
2279 @lilypond[verbatim,quote]
2284 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2286 (define-builtin-markup-command (flat layout props)
2290 "Draw a flat symbol.
2292 @lilypond[verbatim,quote]
2297 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2299 (define-builtin-markup-command (sesquiflat layout props)
2303 "Draw a 3/2 flat symbol.
2305 @lilypond[verbatim,quote]
2310 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2312 (define-builtin-markup-command (doubleflat layout props)
2316 "Draw a double flat symbol.
2318 @lilypond[verbatim,quote]
2323 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2325 (define-builtin-markup-command (with-color layout props color arg)
2330 @cindex coloring text
2332 Draw @var{arg} in color specified by @var{color}.
2334 @lilypond[verbatim,quote]
2346 (let ((stil (interpret-markup layout props arg)))
2347 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2348 (ly:stencil-extent stil X)
2349 (ly:stencil-extent stil Y))))
2351 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2353 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2355 (define-builtin-markup-command (arrow-head layout props axis dir filled)
2356 (integer? ly:dir? boolean?)
2359 "Produce an arrow head in specified direction and axis.
2360 Use the filled head if @var{filled} is specified.
2361 @lilypond[verbatim,quote]
2364 \\general-align #Y #DOWN {
2365 \\arrow-head #Y #UP ##t
2366 \\arrow-head #Y #DOWN ##f
2368 \\arrow-head #X #RIGHT ##f
2369 \\arrow-head #X #LEFT ##f
2375 ((name (format "arrowheads.~a.~a~a"
2382 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2386 (define-builtin-markup-command (musicglyph layout props glyph-name)
2390 "@var{glyph-name} is converted to a musical symbol; for example,
2391 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2392 the music font. See @ruser{The Feta font} for a complete listing of
2393 the possible glyphs.
2395 @lilypond[verbatim,quote]
2398 \\musicglyph #\"rests.2\"
2399 \\musicglyph #\"clefs.G_change\"
2402 (let* ((font (ly:paper-get-font layout
2403 (cons '((font-encoding . fetaMusic)
2407 (glyph (ly:font-get-glyph font glyph-name)))
2408 (if (null? (ly:stencil-expr glyph))
2409 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2414 (define-builtin-markup-command (lookup layout props glyph-name)
2418 "Lookup a glyph by name.
2420 @lilypond[verbatim,quote]
2422 \\override #'(font-encoding . fetaBraces) {
2423 \\lookup #\"brace200\"
2426 \\lookup #\"brace180\"
2430 (ly:font-get-glyph (ly:paper-get-font layout props)
2433 (define-builtin-markup-command (char layout props num)
2437 "Produce a single character. Characters encoded in hexadecimal
2438 format require the prefix @code{#x}.
2440 @lilypond[verbatim,quote]
2442 \\char #65 \\char ##x00a9
2445 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2447 (define number->mark-letter-vector (make-vector 25 #\A))
2452 (if (= i (- (char->integer #\I) (char->integer #\A)))
2454 (vector-set! number->mark-letter-vector j
2455 (integer->char (+ i (char->integer #\A)))))
2457 (define number->mark-alphabet-vector (list->vector
2458 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2460 (define (number->markletter-string vec n)
2461 "Double letters for big marks."
2462 (let* ((lst (vector-length vec)))
2465 (string-append (number->markletter-string vec (1- (quotient n lst)))
2466 (number->markletter-string vec (remainder n lst)))
2467 (make-string 1 (vector-ref vec n)))))
2469 (define-builtin-markup-command (markletter layout props num)
2473 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2474 (skipping letter@tie{}I), and continue with double letters.
2476 @lilypond[verbatim,quote]
2483 (ly:text-interface::interpret-markup layout props
2484 (number->markletter-string number->mark-letter-vector num)))
2486 (define-builtin-markup-command (markalphabet layout props num)
2490 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2491 and continue with double letters.
2493 @lilypond[verbatim,quote]
2500 (ly:text-interface::interpret-markup layout props
2501 (number->markletter-string number->mark-alphabet-vector num)))
2503 (define-public (horizontal-slash-interval num forward number-interval mag)
2505 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2506 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2507 (else (interval-widen number-interval (* mag 0.25))))
2508 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2509 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2510 (else (interval-widen number-interval (* mag 0.25))))
2513 (define-public (adjust-slash-stencil num forward stencil mag)
2516 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2518 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2520 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2522 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2525 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2527 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2532 (define (slashed-digit-internal layout props num forward font-size thickness)
2533 (let* ((mag (magstep font-size))
2535 (ly:output-def-lookup layout 'line-thickness)
2537 ; backward slashes might use slope and point in the other direction!
2538 (dy (* mag (if forward 0.4 -0.4)))
2539 (number-stencil (interpret-markup layout
2540 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2541 (number->string num)))
2542 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2543 (center (interval-center (ly:stencil-extent number-stencil Y)))
2544 ; Use the real extents of the slash, not the whole number, because we
2545 ; might translate the slash later on!
2546 (num-y (interval-widen (cons center center) (abs dy)))
2547 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2548 (slash-stencil (if is-sane
2549 (make-line-stencil thickness
2550 (car num-x) (- (interval-center num-y) dy)
2551 (cdr num-x) (+ (interval-center num-y) dy))
2553 (if (ly:stencil? slash-stencil)
2555 ; for some numbers we need to shift the slash/backslash up or down to make
2556 ; the slashed digit look better
2557 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2558 (set! number-stencil
2559 (ly:stencil-add number-stencil slash-stencil)))
2560 (ly:warning "Unable to create slashed digit ~a" num))
2564 (define-builtin-markup-command (slashed-digit layout props num)
2570 @cindex slashed digits
2572 A feta number, with slash. This is for use in the context of
2573 figured bass notation.
2574 @lilypond[verbatim,quote]
2578 \\override #'(thickness . 3)
2582 (slashed-digit-internal layout props num #t font-size thickness))
2584 (define-builtin-markup-command (backslashed-digit layout props num)
2590 @cindex backslashed digits
2592 A feta number, with backslash. This is for use in the context of
2593 figured bass notation.
2594 @lilypond[verbatim,quote]
2596 \\backslashed-digit #5
2598 \\override #'(thickness . 3)
2599 \\backslashed-digit #7
2602 (slashed-digit-internal layout props num #f font-size thickness))
2604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2605 ;; the note command.
2606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2608 ;; TODO: better syntax.
2610 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2611 (number? number? number?)
2616 @cindex notes within text by log and dot-count
2618 Construct a note symbol, with stem. By using fractional values for
2619 @var{dir}, longer or shorter stems can be obtained.
2621 @lilypond[verbatim,quote]
2623 \\note-by-number #3 #0 #DOWN
2625 \\note-by-number #1 #2 #0.8
2628 (define (get-glyph-name-candidates dir log style)
2629 (map (lambda (dir-name)
2630 (format "noteheads.~a~a~a" dir-name (min log 2)
2631 (if (and (symbol? style)
2632 (not (equal? 'default style)))
2633 (symbol->string style)
2635 (list (if (= dir UP) "u" "d")
2638 (define (get-glyph-name font cands)
2641 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2642 (get-glyph-name font (cdr cands))
2645 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2646 (size-factor (magstep font-size))
2647 (stem-length (* size-factor (max 3 (- log 1))))
2648 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2649 (head-glyph (ly:font-get-glyph font head-glyph-name))
2650 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2651 (stem-thickness (* size-factor 0.13))
2652 (stemy (* dir stem-length))
2653 (attach-off (cons (interval-index
2654 (ly:stencil-extent head-glyph X)
2655 (* (sign dir) (car attach-indices)))
2656 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2658 (ly:stencil-extent head-glyph Y)
2659 (cdr attach-indices)))))
2660 (stem-glyph (and (> log 0)
2661 (ly:round-filled-box
2662 (ordered-cons (car attach-off)
2663 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2664 (cons (min stemy (cdr attach-off))
2665 (max stemy (cdr attach-off)))
2666 (/ stem-thickness 3))))
2668 (dot (ly:font-get-glyph font "dots.dot"))
2669 (dotwid (interval-length (ly:stencil-extent dot X)))
2670 (dots (and (> dot-count 0)
2671 (apply ly:stencil-add
2673 (ly:stencil-translate-axis
2674 dot (* 2 x dotwid) X))
2675 (iota dot-count)))))
2676 (flaggl (and (> log 2)
2677 (ly:stencil-translate
2678 (ly:font-get-glyph font
2679 (string-append "flags."
2680 (if (> dir 0) "u" "d")
2681 (number->string log)))
2682 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2684 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2685 ; 16th notes get a special case because their flags hang lower than any other flags.
2686 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2687 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2689 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2690 (if (ly:stencil? stem-glyph)
2691 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2692 (set! stem-glyph head-glyph))
2693 (if (ly:stencil? dots)
2696 (ly:stencil-translate-axis
2698 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2704 (let ((divisor (log 2)))
2705 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2707 (define (parse-simple-duration duration-string)
2708 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2709 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2710 (if (and match (string=? duration-string (match:substring match 0)))
2711 (let ((len (match:substring match 1))
2712 (dots (match:substring match 2)))
2713 (list (cond ((string=? len "breve") -1)
2714 ((string=? len "longa") -2)
2715 ((string=? len "maxima") -3)
2716 (else (log2 (string->number len))))
2717 (if dots (string-length dots) 0)))
2718 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2720 (define-builtin-markup-command (note layout props duration dir)
2723 (note-by-number-markup)
2725 @cindex notes within text by string
2727 This produces a note with a stem pointing in @var{dir} direction, with
2728 the @var{duration} for the note head type and augmentation dots. For
2729 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2730 a shortened down stem.
2732 @lilypond[verbatim,quote]
2734 \\override #'(style . cross) {
2738 \\note #\"breve\" #0
2741 (let ((parsed (parse-simple-duration duration)))
2742 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2744 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2746 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2748 (define-builtin-markup-command (lower layout props amount arg)
2753 @cindex lowering text
2755 Lower @var{arg} by the distance @var{amount}.
2756 A negative @var{amount} indicates raising; see also @code{\\raise}.
2758 @lilypond[verbatim,quote]
2766 (ly:stencil-translate-axis (interpret-markup layout props arg)
2769 (define-builtin-markup-command (translate-scaled layout props offset arg)
2770 (number-pair? markup?)
2774 @cindex translating text
2775 @cindex scaling text
2777 Translate @var{arg} by @var{offset}, scaling the offset by the
2780 @lilypond[verbatim,quote]
2783 * \\translate #'(2 . 3) translate
2785 * \\translate-scaled #'(2 . 3) translate-scaled
2789 (let* ((factor (magstep font-size))
2790 (scaled (cons (* factor (car offset))
2791 (* factor (cdr offset)))))
2792 (ly:stencil-translate (interpret-markup layout props arg)
2795 (define-builtin-markup-command (raise layout props amount arg)
2800 @cindex raising text
2802 Raise @var{arg} by the distance @var{amount}.
2803 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2805 The argument to @code{\\raise} is the vertical displacement amount,
2806 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2807 raise objects in relation to their surrounding markups.
2809 If the text object itself is positioned above or below the staff, then
2810 @code{\\raise} cannot be used to move it, since the mechanism that
2811 positions it next to the staff cancels any shift made with
2812 @code{\\raise}. For vertical positioning, use the @code{padding}
2813 and/or @code{extra-offset} properties.
2815 @lilypond[verbatim,quote]
2824 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2826 (define-builtin-markup-command (fraction layout props arg1 arg2)
2831 @cindex creating text fractions
2833 Make a fraction of two markups.
2834 @lilypond[verbatim,quote]
2840 (let* ((m1 (interpret-markup layout props arg1))
2841 (m2 (interpret-markup layout props arg2))
2842 (factor (magstep font-size))
2843 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2844 (padding (* factor 0.2))
2845 (baseline (* factor 0.6))
2846 (offset (* factor 0.75)))
2847 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2848 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2849 (let* ((x1 (ly:stencil-extent m1 X))
2850 (x2 (ly:stencil-extent m2 X))
2851 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2852 ;; should stack mols separately, to maintain LINE on baseline
2853 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2855 (ly:stencil-aligned-to stack Y CENTER))
2857 (ly:stencil-aligned-to stack X LEFT))
2858 ;; should have EX dimension
2860 (ly:stencil-translate-axis stack offset Y))))
2862 (define-builtin-markup-command (normal-size-super layout props arg)
2867 @cindex setting superscript in standard font size
2869 Set @var{arg} in superscript with a normal font size.
2871 @lilypond[verbatim,quote]
2874 \\normal-size-super {
2875 superscript in standard size
2879 (ly:stencil-translate-axis
2880 (interpret-markup layout props arg)
2881 (* 0.5 baseline-skip) Y))
2883 (define-builtin-markup-command (super layout props arg)
2889 @cindex superscript text
2891 Set @var{arg} in superscript.
2893 @lilypond[verbatim,quote]
2903 (ly:stencil-translate-axis
2906 (cons `((font-size . ,(- font-size 3))) props)
2908 (* 0.5 baseline-skip)
2911 (define-builtin-markup-command (translate layout props offset arg)
2912 (number-pair? markup?)
2916 @cindex translating text
2918 Translate @var{arg} relative to its surroundings. @var{offset}
2919 is a pair of numbers representing the displacement in the X and Y axis.
2921 @lilypond[verbatim,quote]
2924 \\translate #'(2 . 3)
2925 \\line { translated two spaces right, three up }
2928 (ly:stencil-translate (interpret-markup layout props arg)
2931 (define-builtin-markup-command (sub layout props arg)
2937 @cindex subscript text
2939 Set @var{arg} in subscript.
2941 @lilypond[verbatim,quote]
2952 (ly:stencil-translate-axis
2955 (cons `((font-size . ,(- font-size 3))) props)
2957 (* -0.5 baseline-skip)
2960 (define-builtin-markup-command (normal-size-sub layout props arg)
2965 @cindex setting subscript in standard font size
2967 Set @var{arg} in subscript with a normal font size.
2969 @lilypond[verbatim,quote]
2973 subscript in standard size
2977 (ly:stencil-translate-axis
2978 (interpret-markup layout props arg)
2979 (* -0.5 baseline-skip)
2982 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2984 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2986 (define-builtin-markup-command (hbracket layout props arg)
2991 @cindex placing horizontal brackets around text
2993 Draw horizontal brackets around @var{arg}.
2995 @lilypond[verbatim,quote]
3004 (let ((th 0.1) ;; todo: take from GROB.
3005 (m (interpret-markup layout props arg)))
3006 (bracketify-stencil m X th (* 2.5 th) th)))
3008 (define-builtin-markup-command (bracket layout props arg)
3013 @cindex placing vertical brackets around text
3015 Draw vertical brackets around @var{arg}.
3017 @lilypond[verbatim,quote]
3024 (let ((th 0.1) ;; todo: take from GROB.
3025 (m (interpret-markup layout props arg)))
3026 (bracketify-stencil m Y th (* 2.5 th) th)))
3028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3029 ;; Delayed markup evaluation
3030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3032 (define-builtin-markup-command (page-ref layout props label gauge default)
3033 (symbol? markup? markup?)
3037 @cindex referencing page numbers in text
3039 Reference to a page number. @var{label} is the label set on the referenced
3040 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3041 the maximum width of the page number, and @var{default} the value to display
3042 when @var{label} is not found."
3043 (let* ((gauge-stencil (interpret-markup layout props gauge))
3044 (x-ext (ly:stencil-extent gauge-stencil X))
3045 (y-ext (ly:stencil-extent gauge-stencil Y)))
3047 `(delay-stencil-evaluation
3048 ,(delay (ly:stencil-expr
3049 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3050 (label-page (and (list? table) (assoc label table)))
3051 (page-number (and label-page (cdr label-page)))
3052 (page-markup (if page-number (format "~a" page-number) default))
3053 (page-stencil (interpret-markup layout props page-markup))
3054 (gap (- (interval-length x-ext)
3055 (interval-length (ly:stencil-extent page-stencil X)))))
3056 (interpret-markup layout props
3057 (markup #:concat (#:hspace gap page-markup)))))))
3061 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3062 ;; Markup list commands
3063 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3065 (define-public (space-lines baseline stils)
3066 (let space-stil ((stils stils)
3070 (let* ((stil (car stils))
3071 (dy-top (max (- (/ baseline 1.5)
3072 (interval-bound (ly:stencil-extent stil Y) UP))
3074 (dy-bottom (max (+ (/ baseline 3.0)
3075 (interval-bound (ly:stencil-extent stil Y) DOWN))
3077 (new-stil (ly:make-stencil
3078 (ly:stencil-expr stil)
3079 (ly:stencil-extent stil X)
3080 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3082 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3084 (space-stil (cdr stils) (cons new-stil result))))))
3086 (define-builtin-markup-list-command (justified-lines layout props args)
3089 wordwrap-internal-markup-list)
3091 @cindex justifying lines of text
3093 Like @code{\\justify}, but return a list of lines instead of a single markup.
3094 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3095 @var{X}@tie{}is the number of staff spaces."
3096 (space-lines baseline-skip
3097 (interpret-markup-list layout props
3098 (make-wordwrap-internal-markup-list #t args))))
3100 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3103 wordwrap-internal-markup-list)
3104 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3105 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3106 where @var{X} is the number of staff spaces."
3107 (space-lines baseline-skip
3108 (interpret-markup-list layout props
3109 (make-wordwrap-internal-markup-list #f args))))
3111 (define-builtin-markup-list-command (column-lines layout props args)
3114 "Like @code{\\column}, but return a list of lines instead of a single markup.
3115 @code{baseline-skip} determines the space between each markup in @var{args}."
3116 (space-lines (chain-assoc-get 'baseline-skip props)
3117 (interpret-markup-list layout props args)))
3119 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3120 (pair? markup-list?)
3122 "Like @code{\\override}, for markup lists."
3123 (interpret-markup-list layout (cons (list new-prop) props) args))