1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (define-builtin-markup-command (draw-line layout props dest)
31 @cindex drawing lines within text
34 @lilypond[verbatim,quote]
37 \\override #'(thickness . 5)
38 \\draw-line #'(-3 . 0)
41 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
45 (make-line-stencil th 0 0 x y)))
47 (define-builtin-markup-command (draw-circle layout props radius thickness filled)
48 (number? number? boolean?)
52 @cindex drawing circles within text
54 A circle of radius @var{radius} and thickness @var{thickness},
57 @lilypond[verbatim,quote]
59 \\draw-circle #2 #0.5 ##f
61 \\draw-circle #2 #0 ##t
64 (make-circle-stencil radius thickness filled))
66 (define-builtin-markup-command (triangle layout props filled)
73 @cindex drawing triangles within text
75 A triangle, either filled or empty.
77 @lilypond[verbatim,quote]
84 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
93 (cons 0 (* .86 ex)))))
95 (define-builtin-markup-command (circle layout props arg)
100 (circle-padding 0.2))
102 @cindex circling text
104 Draw a circle around @var{arg}. Use @code{thickness},
105 @code{circle-padding} and @code{font-size} properties to determine line
106 thickness and padding around the markup.
108 @lilypond[verbatim,quote]
115 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
117 (pad (* (magstep font-size) circle-padding))
118 (m (interpret-markup layout props arg)))
119 (circle-stencil m th pad)))
121 (define-builtin-markup-command (with-url layout props url arg)
126 @cindex inserting URL links into text
128 Add a link to URL @var{url} around @var{arg}. This only works in
131 @lilypond[verbatim,quote]
133 \\with-url #\"http://lilypond.org/web/\" {
134 LilyPond ... \\italic {
135 music notation for everyone
140 (let* ((stil (interpret-markup layout props arg))
141 (xextent (ly:stencil-extent stil X))
142 (yextent (ly:stencil-extent stil Y))
143 (old-expr (ly:stencil-expr stil))
144 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
146 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
148 (define-builtin-markup-command (beam layout props width slope thickness)
149 (number? number? number?)
153 @cindex drawing beams within text
155 Create a beam with the specified parameters.
156 @lilypond[verbatim,quote]
161 (let* ((y (* slope width))
162 (yext (cons (min 0 y) (max 0 y)))
163 (half (/ thickness 2)))
168 width (+ (* width slope) (/ thickness -2))
169 width (+ (* width slope) (/ thickness 2))
171 ,(ly:output-def-lookup layout 'blot-diameter)
174 (cons (+ (- half) (car yext))
175 (+ half (cdr yext))))))
177 (define-builtin-markup-command (underline layout props arg)
182 @cindex underlining text
184 Underline @var{arg}. Looks at @code{thickness} to determine line
185 thickness and y-offset.
187 @lilypond[verbatim,quote]
191 \\override #'(thickness . 2)
197 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
199 (markup (interpret-markup layout props arg))
200 (x1 (car (ly:stencil-extent markup X)))
201 (x2 (cdr (ly:stencil-extent markup X)))
203 (line (make-line-stencil thick x1 y x2 y)))
204 (ly:stencil-add markup line)))
206 (define-builtin-markup-command (box layout props arg)
213 @cindex enclosing text within a box
215 Draw a box round @var{arg}. Looks at @code{thickness},
216 @code{box-padding} and @code{font-size} properties to determine line
217 thickness and padding around the markup.
219 @lilypond[verbatim,quote]
221 \\override #'(box-padding . 0.5)
226 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
228 (pad (* (magstep font-size) box-padding))
229 (m (interpret-markup layout props arg)))
230 (box-stencil m th pad)))
232 (define-builtin-markup-command (filled-box layout props xext yext blot)
233 (number-pair? number-pair? number?)
237 @cindex drawing solid boxes within text
238 @cindex drawing boxes with rounded corners
240 Draw a box with rounded corners of dimensions @var{xext} and
241 @var{yext}. For example,
243 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
245 creates a box extending horizontally from -0.3 to 1.8 and
246 vertically from -0.3 up to 1.8, with corners formed from a
247 circle of diameter@tie{}0 (i.e., sharp corners).
249 @lilypond[verbatim,quote]
251 \\filled-box #'(0 . 4) #'(0 . 4) #0
252 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
253 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
255 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
261 (define-builtin-markup-command (rounded-box layout props arg)
268 "@cindex enclosing text in a box with rounded corners
269 @cindex drawing boxes with rounded corners around text
270 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
271 @code{box-padding} and @code{font-size} properties to determine line
272 thickness and padding around the markup; the @code{corner-radius} property
273 makes it possible to define another shape for the corners (default is 1).
275 @lilypond[quote,verbatim,relative=2]
283 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
285 (pad (* (magstep font-size) box-padding))
286 (m (interpret-markup layout props arg)))
287 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
290 (define-builtin-markup-command (rotate layout props ang arg)
295 @cindex rotating text
297 Rotate object with @var{ang} degrees around its center.
299 @lilypond[verbatim,quote]
309 (let* ((stil (interpret-markup layout props arg)))
310 (ly:stencil-rotate stil ang 0 0)))
312 (define-builtin-markup-command (whiteout layout props arg)
317 @cindex adding a white background to text
319 Provide a white background for @var{arg}.
321 @lilypond[verbatim,quote]
324 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
328 (stencil-whiteout (interpret-markup layout props arg)))
330 (define-builtin-markup-command (pad-markup layout props amount arg)
336 @cindex putting space around text
338 Add space around a markup object.
340 @lilypond[verbatim,quote]
354 ((stil (interpret-markup layout props arg))
355 (xext (ly:stencil-extent stil X))
356 (yext (ly:stencil-extent stil Y)))
359 (ly:stencil-expr stil)
360 (interval-widen xext amount)
361 (interval-widen yext amount))))
363 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
367 (define-builtin-markup-command (strut layout props)
372 @cindex creating vertical spaces in text
374 Create a box of the same height as the space in the current font."
375 (let ((m (ly:text-interface::interpret-markup layout props " ")))
376 (ly:make-stencil (ly:stencil-expr m)
378 (ly:stencil-extent m X)
381 ;; todo: fix negative space
382 (define-builtin-markup-command (hspace layout props amount)
387 @cindex creating horizontal spaces in text
389 Create an invisible object taking up horizontal space @var{amount}.
391 @lilypond[verbatim,quote]
401 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
402 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
404 ;; todo: fix negative space
405 (define-builtin-markup-command (vspace layout props amount)
410 @cindex creating vertical spaces in text
412 Create an invisible object taking up vertical space
413 of @var{amount} multiplied by 3.
415 @lilypond[verbatim,quote]
426 (let ((amount (* amount 3.0)))
428 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
429 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
433 ;; importing graphics.
434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
436 (define-builtin-markup-command (stencil layout props stil)
441 @cindex importing stencils into text
443 Use a stencil as markup.
445 @lilypond[verbatim,quote]
447 \\stencil #(make-circle-stencil 2 0 #t)
453 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
455 (define (get-postscript-bbox string)
456 "Extract the bbox from STRING, or return #f if not present."
458 ((match (regexp-exec bbox-regexp string)))
462 (string->number (match:substring match x)))
467 (define-builtin-markup-command (epsfile layout props axis size file-name)
468 (number? number? string?)
472 @cindex inlining an Encapsulated PostScript image
474 Inline an EPS image. The image is scaled along @var{axis} to
477 @lilypond[verbatim,quote]
479 \\general-align #Y #DOWN {
480 \\epsfile #X #20 #\"context-example.eps\"
481 \\epsfile #Y #20 #\"context-example.eps\"
485 (if (ly:get-option 'safe)
486 (interpret-markup layout props "not allowed in safe")
487 (eps-file->stencil axis size file-name)
490 (define-builtin-markup-command (postscript layout props str)
495 @cindex inserting PostScript directly into text
496 This inserts @var{str} directly into the output as a PostScript
499 @lilypond[verbatim,quote]
503 0.4 0.6 0.5 0 361 arc
505 1.0 0.6 0.5 0 361 arc
510 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
511 \\postscript #ringsps
523 gsave currentpoint translate
531 (define-builtin-markup-command (score layout props score)
536 @cindex inserting music into text
538 Inline an image of music.
540 @lilypond[verbatim,quote]
544 \\new Staff \\relative c' {
547 \\mark \\markup { Allegro }
553 \\new Staff \\relative c {
567 \\override RehearsalMark #'break-align-symbols =
568 #'(time-signature key-signature)
569 \\override RehearsalMark #'self-alignment-X = #LEFT
573 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
579 (let* ((output (ly:score-embedded-format score layout)))
581 (if (ly:music-output? output)
582 (paper-system-stencil
583 (vector-ref (ly:paper-score-paper-systems output) 0))
585 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
588 (define-builtin-markup-command (null layout props)
593 @cindex creating empty text objects
595 An empty markup with extents of a single point.
597 @lilypond[verbatim,quote]
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
606 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
608 (define-builtin-markup-command (simple layout props str)
613 @cindex simple text strings
615 A simple text string; @code{\\markup @{ foo @}} is equivalent with
616 @code{\\markup @{ \\simple #\"foo\" @}}.
618 Note: for creating standard text markup or defining new markup commands,
619 the use of @code{\\simple} is unnecessary.
621 @lilypond[verbatim,quote]
625 \\simple #\"strings\"
628 (interpret-markup layout props str))
630 (define-builtin-markup-command (tied-lyric layout props str)
635 @cindex simple text strings with tie characters
637 Like simple-markup, but use tie characters for @q{~} tilde symbols.
639 @lilypond[verbatim,quote]
641 \\tied-lyric #\"Lasciate~i monti\"
644 (if (string-contains str "~")
646 ((parts (string-split str #\~))
647 (tie-str (ly:wide-char->utf-8 #x203f))
648 (joined (list-join parts tie-str))
649 (join-stencil (interpret-markup layout props tie-str))
652 (interpret-markup layout
655 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
657 (make-line-markup joined)))
658 ;(map (lambda (s) (interpret-markup layout props s)) parts))
659 (interpret-markup layout props str)))
661 (define-public empty-markup
662 (make-simple-markup ""))
664 ;; helper for justifying lines.
665 (define (get-fill-space word-count line-width text-widths)
666 "Calculate the necessary paddings between each two adjacent texts.
667 The lengths of all texts are stored in @var{text-widths}.
668 The normal formula for the padding between texts a and b is:
669 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
670 The first and last padding have to be calculated specially using the
671 whole length of the first or last text.
672 Return a list of paddings."
674 ((null? text-widths) '())
676 ;; special case first padding
677 ((= (length text-widths) word-count)
679 (- (- (/ line-width (1- word-count)) (car text-widths))
680 (/ (car (cdr text-widths)) 2))
681 (get-fill-space word-count line-width (cdr text-widths))))
682 ;; special case last padding
683 ((= (length text-widths) 2)
684 (list (- (/ line-width (1- word-count))
685 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
688 (- (/ line-width (1- word-count))
689 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
690 (get-fill-space word-count line-width (cdr text-widths))))))
692 (define-builtin-markup-command (fill-line layout props args)
695 ((text-direction RIGHT)
698 "Put @var{markups} in a horizontal line of width @var{line-width}.
699 The markups are spaced or flushed to fill the entire line.
700 If there are no arguments, return an empty stencil.
702 @lilypond[verbatim,quote]
706 Words evenly spaced across the page
710 \\line { Text markups }
712 \\italic { evenly spaced }
714 \\line { across the page }
719 (let* ((orig-stencils (interpret-markup-list layout props args))
722 (if (ly:stencil-empty? stc)
724 stc)) orig-stencils))
727 (if (ly:stencil-empty? stc)
729 (interval-length (ly:stencil-extent stc X))))
731 (text-width (apply + text-widths))
732 (word-count (length stencils))
733 (prop-line-width (chain-assoc-get 'line-width props #f))
734 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
739 (/ (- line-width text-width) 2)
740 (/ (- line-width text-width) 2)))
743 (- line-width text-width)))
745 (get-fill-space word-count line-width text-widths))))
753 (line-stencils (if (= word-count 1)
760 (if (= text-direction LEFT)
761 (set! line-stencils (reverse line-stencils)))
763 (if (null? (remove ly:stencil-empty? orig-stencils))
765 (stack-stencils-padding-list X
766 RIGHT fill-space-normal line-stencils))))
768 (define-builtin-markup-command (line layout props args)
772 (text-direction RIGHT))
773 "Put @var{args} in a horizontal line. The property @code{word-space}
774 determines the space between markups in @var{args}.
776 @lilypond[verbatim,quote]
783 (let ((stencils (interpret-markup-list layout props args)))
784 (if (= text-direction LEFT)
785 (set! stencils (reverse stencils)))
788 (remove ly:stencil-empty? stencils))))
790 (define-builtin-markup-command (concat layout props args)
795 @cindex concatenating text
796 @cindex ligatures in text
798 Concatenate @var{args} in a horizontal line, without spaces in between.
799 Strings and simple markups are concatenated on the input level, allowing
800 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
801 equivalent to @code{\"fi\"}.
803 @lilypond[verbatim,quote]
812 (define (concat-string-args arg-list)
813 (fold-right (lambda (arg result-list)
814 (let ((result (if (pair? result-list)
817 (if (and (pair? arg) (eqv? (car arg) simple-markup))
818 (set! arg (cadr arg)))
819 (if (and (string? result) (string? arg))
820 (cons (string-append arg result) (cdr result-list))
821 (cons arg result-list))))
825 (interpret-markup layout
826 (prepend-alist-chain 'word-space 0 props)
827 (make-line-markup (if (markup-command-list? args)
829 (concat-string-args args)))))
831 (define (wordwrap-stencils stencils
832 justify base-space line-width text-dir)
833 "Perform simple wordwrap, return stencil of each line."
834 (define space (if justify
835 ;; justify only stretches lines.
838 (define (take-list width space stencils
839 accumulator accumulated-width)
840 "Return (head-list . tail) pair, with head-list fitting into width"
842 (cons accumulator stencils)
843 (let* ((first (car stencils))
844 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
845 (newwid (+ space first-wid accumulated-width)))
846 (if (or (null? accumulator)
848 (take-list width space
850 (cons first accumulator)
852 (cons accumulator stencils)))))
853 (let loop ((lines '())
855 (let* ((line-break (take-list line-width space todo
857 (line-stencils (car line-break))
858 (space-left (- line-width
859 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
861 (line-word-space (cond ((not justify) space)
862 ;; don't stretch last line of paragraph.
863 ;; hmmm . bug - will overstretch the last line in some case.
864 ((null? (cdr line-break))
866 ((null? line-stencils) 0.0)
867 ((null? (cdr line-stencils)) 0.0)
868 (else (/ space-left (1- (length line-stencils))))))
869 (line (stack-stencil-line line-word-space
870 (if (= text-dir RIGHT)
871 (reverse line-stencils)
873 (if (pair? (cdr line-break))
874 (loop (cons line lines)
877 (if (= text-dir LEFT)
879 (ly:stencil-translate-axis
881 (- line-width (interval-end (ly:stencil-extent line X)))
883 (reverse (cons line lines)))))))
885 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
886 (boolean? markup-list?)
889 (text-direction RIGHT))
890 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
891 (wordwrap-stencils (remove ly:stencil-empty?
892 (interpret-markup-list layout props args))
896 (ly:output-def-lookup layout 'line-width))
899 (define-builtin-markup-command (justify layout props args)
903 wordwrap-internal-markup-list)
905 @cindex justifying text
907 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
908 Use @code{\\override #'(line-width . @var{X})} to set the line width;
909 @var{X}@tie{}is the number of staff spaces.
911 @lilypond[verbatim,quote]
914 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
915 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
916 Ut enim ad minim veniam, quis nostrud exercitation ullamco
917 laboris nisi ut aliquip ex ea commodo consequat.
921 (stack-lines DOWN 0.0 baseline-skip
922 (wordwrap-internal-markup-list layout props #t args)))
924 (define-builtin-markup-command (wordwrap layout props args)
928 wordwrap-internal-markup-list)
929 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
930 the line width, where @var{X} is the number of staff spaces.
932 @lilypond[verbatim,quote]
935 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
936 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
937 Ut enim ad minim veniam, quis nostrud exercitation ullamco
938 laboris nisi ut aliquip ex ea commodo consequat.
942 (stack-lines DOWN 0.0 baseline-skip
943 (wordwrap-internal-markup-list layout props #f args)))
945 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
949 (text-direction RIGHT))
950 "Internal markup list command used to define @code{\\justify-string} and
951 @code{\\wordwrap-string}."
952 (let* ((para-strings (regexp-split
953 (string-regexp-substitute
955 (string-regexp-substitute "\r\n" "\n" arg))
956 "\n[ \t\n]*\n[ \t\n]*"))
957 (list-para-words (map (lambda (str)
958 (regexp-split str "[ \t\n]+"))
960 (para-lines (map (lambda (words)
962 (remove ly:stencil-empty?
964 (interpret-markup layout props x))
966 (wordwrap-stencils stencils
968 line-width text-direction)))
970 (apply append para-lines)))
972 (define-builtin-markup-command (wordwrap-string layout props arg)
976 wordwrap-string-internal-markup-list)
977 "Wordwrap a string. Paragraphs may be separated with double newlines.
979 @lilypond[verbatim,quote]
981 \\override #'(line-width . 40)
982 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
983 adipisicing elit, sed do eiusmod tempor incididunt ut labore
984 et dolore magna aliqua.
987 Ut enim ad minim veniam, quis nostrud exercitation ullamco
988 laboris nisi ut aliquip ex ea commodo consequat.
991 Excepteur sint occaecat cupidatat non proident, sunt in culpa
992 qui officia deserunt mollit anim id est laborum\"
995 (stack-lines DOWN 0.0 baseline-skip
996 (wordwrap-string-internal-markup-list layout props #f arg)))
998 (define-builtin-markup-command (justify-string layout props arg)
1002 wordwrap-string-internal-markup-list)
1003 "Justify a string. Paragraphs may be separated with double newlines
1005 @lilypond[verbatim,quote]
1007 \\override #'(line-width . 40)
1008 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1009 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1010 et dolore magna aliqua.
1013 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1014 laboris nisi ut aliquip ex ea commodo consequat.
1017 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1018 qui officia deserunt mollit anim id est laborum\"
1021 (stack-lines DOWN 0.0 baseline-skip
1022 (wordwrap-string-internal-markup-list layout props #t arg)))
1024 (define-builtin-markup-command (wordwrap-field layout props symbol)
1028 "Wordwrap the data which has been assigned to @var{symbol}.
1030 @lilypond[verbatim,quote]
1032 title = \"My title\"
1033 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1034 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1035 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1036 laboris nisi ut aliquip ex ea commodo consequat.\"
1040 bookTitleMarkup = \\markup {
1042 \\fill-line { \\fromproperty #'header:title }
1044 \\wordwrap-field #'header:myText
1053 (let* ((m (chain-assoc-get symbol props)))
1055 (wordwrap-string-markup layout props m)
1058 (define-builtin-markup-command (justify-field layout props symbol)
1062 "Justify the data which has been assigned to @var{symbol}.
1064 @lilypond[verbatim,quote]
1066 title = \"My title\"
1067 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1068 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1069 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1070 laboris nisi ut aliquip ex ea commodo consequat.\"
1074 bookTitleMarkup = \\markup {
1076 \\fill-line { \\fromproperty #'header:title }
1078 \\justify-field #'header:myText
1087 (let* ((m (chain-assoc-get symbol props)))
1089 (justify-string-markup layout props m)
1092 (define-builtin-markup-command (combine layout props arg1 arg2)
1097 @cindex merging text
1099 Print two markups on top of each other.
1101 Note: @code{\\combine} cannot take a list of markups enclosed in
1102 curly braces as an argument; the follow example will not compile:
1105 \\combine @{ a list @}
1108 @lilypond[verbatim,quote]
1111 \\override #'(thickness . 2)
1113 \\draw-line #'(0 . 4)
1114 \\arrow-head #Y #DOWN ##f
1117 (let* ((s1 (interpret-markup layout props arg1))
1118 (s2 (interpret-markup layout props arg2)))
1119 (ly:stencil-add s1 s2)))
1122 ;; TODO: should extract baseline-skip from each argument somehow..
1124 (define-builtin-markup-command (column layout props args)
1129 @cindex stacking text in a column
1131 Stack the markups in @var{args} vertically. The property
1132 @code{baseline-skip} determines the space between markups
1135 @lilypond[verbatim,quote]
1144 (let ((arg-stencils (interpret-markup-list layout props args)))
1145 (stack-lines -1 0.0 baseline-skip
1146 (remove ly:stencil-empty? arg-stencils))))
1148 (define-builtin-markup-command (dir-column layout props args)
1154 @cindex changing direction of text columns
1156 Make a column of @var{args}, going up or down, depending on the
1157 setting of the @code{direction} layout property.
1159 @lilypond[verbatim,quote]
1161 \\override #`(direction . ,UP) {
1171 \\override #'(direction . 1) {
1178 (stack-lines (if (number? direction) direction -1)
1181 (interpret-markup-list layout props args)))
1183 (define (general-column align-dir baseline mols)
1184 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1186 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1187 (stack-lines -1 0.0 baseline aligned-mols)))
1189 (define-builtin-markup-command (center-column layout props args)
1194 @cindex centering a column of text
1196 Put @code{args} in a centered column.
1198 @lilypond[verbatim,quote]
1207 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1209 (define-builtin-markup-command (left-column layout props args)
1214 @cindex text columns, left-aligned
1216 Put @code{args} in a left-aligned column.
1218 @lilypond[verbatim,quote]
1227 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1229 (define-builtin-markup-command (right-column layout props args)
1234 @cindex text columns, right-aligned
1236 Put @code{args} in a right-aligned column.
1238 @lilypond[verbatim,quote]
1247 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1249 (define-builtin-markup-command (vcenter layout props arg)
1254 @cindex vertically centering text
1256 Align @code{arg} to its Y@tie{}center.
1258 @lilypond[verbatim,quote]
1266 (let* ((mol (interpret-markup layout props arg)))
1267 (ly:stencil-aligned-to mol Y CENTER)))
1269 (define-builtin-markup-command (center-align layout props arg)
1274 @cindex horizontally centering text
1276 Align @code{arg} to its X@tie{}center.
1278 @lilypond[verbatim,quote]
1288 (let* ((mol (interpret-markup layout props arg)))
1289 (ly:stencil-aligned-to mol X CENTER)))
1291 (define-builtin-markup-command (right-align layout props arg)
1296 @cindex right aligning text
1298 Align @var{arg} on its right edge.
1300 @lilypond[verbatim,quote]
1310 (let* ((m (interpret-markup layout props arg)))
1311 (ly:stencil-aligned-to m X RIGHT)))
1313 (define-builtin-markup-command (left-align layout props arg)
1318 @cindex left aligning text
1320 Align @var{arg} on its left edge.
1322 @lilypond[verbatim,quote]
1332 (let* ((m (interpret-markup layout props arg)))
1333 (ly:stencil-aligned-to m X LEFT)))
1335 (define-builtin-markup-command (general-align layout props axis dir arg)
1336 (integer? number? markup?)
1340 @cindex controlling general text alignment
1342 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1344 @lilypond[verbatim,quote]
1348 \\general-align #X #LEFT
1353 \\general-align #X #CENTER
1359 \\general-align #Y #UP
1366 \\general-align #Y #3.2
1373 (let* ((m (interpret-markup layout props arg)))
1374 (ly:stencil-aligned-to m axis dir)))
1376 (define-builtin-markup-command (halign layout props dir arg)
1381 @cindex setting horizontal text alignment
1383 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1384 left-aligned, while @code{+1} is right. Values in between interpolate
1385 alignment accordingly.
1387 @lilypond[verbatim,quote]
1412 (let* ((m (interpret-markup layout props arg)))
1413 (ly:stencil-aligned-to m X dir)))
1415 (define-builtin-markup-command (with-dimensions layout props x y arg)
1416 (number-pair? number-pair? markup?)
1420 @cindex setting extent of text objects
1422 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1423 (let* ((m (interpret-markup layout props arg)))
1424 (ly:make-stencil (ly:stencil-expr m) x y)))
1426 (define-builtin-markup-command (pad-around layout props amount arg)
1430 "Add padding @var{amount} all around @var{arg}.
1432 @lilypond[verbatim,quote]
1445 (let* ((m (interpret-markup layout props arg))
1446 (x (ly:stencil-extent m X))
1447 (y (ly:stencil-extent m Y)))
1448 (ly:make-stencil (ly:stencil-expr m)
1449 (interval-widen x amount)
1450 (interval-widen y amount))))
1452 (define-builtin-markup-command (pad-x layout props amount arg)
1457 @cindex padding text horizontally
1459 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1461 @lilypond[verbatim,quote]
1474 (let* ((m (interpret-markup layout props arg))
1475 (x (ly:stencil-extent m X))
1476 (y (ly:stencil-extent m Y)))
1477 (ly:make-stencil (ly:stencil-expr m)
1478 (interval-widen x amount)
1481 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1482 (integer? ly:dir? markup? markup?)
1485 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1486 (let ((m1 (interpret-markup layout props arg1))
1487 (m2 (interpret-markup layout props arg2)))
1488 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1490 (define-builtin-markup-command (transparent layout props arg)
1494 "Make @var{arg} transparent.
1496 @lilypond[verbatim,quote]
1503 (let* ((m (interpret-markup layout props arg))
1504 (x (ly:stencil-extent m X))
1505 (y (ly:stencil-extent m Y)))
1506 (ly:make-stencil "" x y)))
1508 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1509 (number-pair? number-pair? markup?)
1512 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1514 @lilypond[verbatim,quote]
1521 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1527 (let* ((m (interpret-markup layout props arg))
1528 (x (ly:stencil-extent m X))
1529 (y (ly:stencil-extent m Y)))
1530 (ly:make-stencil (ly:stencil-expr m)
1531 (interval-union x-ext x)
1532 (interval-union y-ext y))))
1534 (define-builtin-markup-command (hcenter-in layout props length arg)
1538 "Center @var{arg} horizontally within a box of extending
1539 @var{length}/2 to the left and right.
1541 @lilypond[quote,verbatim]
1544 \\set Staff.instrumentName = \\markup {
1551 \\set Staff.instrumentName = \\markup {
1560 (interpret-markup layout props
1561 (make-pad-to-box-markup
1562 (cons (/ length -2) (/ length 2))
1564 (make-center-align-markup arg))))
1566 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1568 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1570 (define-builtin-markup-command (fromproperty layout props symbol)
1574 "Read the @var{symbol} from property settings, and produce a stencil
1575 from the markup contained within. If @var{symbol} is not defined, it
1576 returns an empty markup.
1578 @lilypond[verbatim,quote]
1580 myTitle = \"myTitle\"
1584 \\fromproperty #'header:myTitle
1591 (let ((m (chain-assoc-get symbol props)))
1593 (interpret-markup layout props m)
1596 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1600 "Apply the @var{procedure} markup command to @var{arg}.
1601 @var{procedure} should take a single argument."
1602 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1603 (set-object-property! anonymous-with-signature
1606 (interpret-markup layout props (list anonymous-with-signature arg))))
1608 (define-builtin-markup-command (override layout props new-prop arg)
1613 @cindex overriding properties within text markup
1615 Add the argument @var{new-prop} to the property list. Properties
1616 may be any property supported by @rinternals{font-interface},
1617 @rinternals{text-interface} and
1618 @rinternals{instrument-specific-markup-interface}.
1620 @lilypond[verbatim,quote]
1628 \\override #'(baseline-skip . 4) {
1637 (interpret-markup layout (cons (list new-prop) props) arg))
1639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1643 (define-builtin-markup-command (verbatim-file layout props name)
1647 "Read the contents of file @var{name}, and include it verbatim.
1649 @lilypond[verbatim,quote]
1651 \\verbatim-file #\"simple.ly\"
1654 (interpret-markup layout props
1655 (if (ly:get-option 'safe)
1656 "verbatim-file disabled in safe mode"
1657 (let* ((str (ly:gulp-file name))
1658 (lines (string-split str #\nl)))
1659 (make-typewriter-markup
1660 (make-column-markup lines))))))
1662 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1664 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1667 (define-builtin-markup-command (smaller layout props arg)
1671 "Decrease the font size relative to the current setting.
1673 @lilypond[verbatim,quote]
1686 (interpret-markup layout props
1687 `(,fontsize-markup -1 ,arg)))
1689 (define-builtin-markup-command (larger layout props arg)
1693 "Increase the font size relative to the current setting.
1695 @lilypond[verbatim,quote]
1703 (interpret-markup layout props
1704 `(,fontsize-markup 1 ,arg)))
1706 (define-builtin-markup-command (finger layout props arg)
1710 "Set @var{arg} as small numbers.
1712 @lilypond[verbatim,quote]
1719 (interpret-markup layout
1720 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1723 (define-builtin-markup-command (abs-fontsize layout props size arg)
1727 "Use @var{size} as the absolute font size to display @var{arg}.
1728 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1730 @lilypond[verbatim,quote]
1732 default text font size
1734 \\abs-fontsize #16 { text font size 16 }
1736 \\abs-fontsize #12 { text font size 12 }
1739 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1740 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1741 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1742 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1743 (magnification (/ size ref-size)))
1744 (interpret-markup layout
1745 (cons `((baseline-skip . ,(* magnification ref-baseline))
1746 (word-space . ,(* magnification ref-word-space))
1747 (font-size . ,(magnification->font-size magnification)))
1751 (define-builtin-markup-command (fontsize layout props increment arg)
1757 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1760 @lilypond[verbatim,quote]
1768 (let ((entries (list
1769 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1770 (cons 'word-space (* word-space (magstep increment)))
1771 (cons 'font-size (+ font-size increment)))))
1772 (interpret-markup layout (cons entries props) arg)))
1774 (define-builtin-markup-command (magnify layout props sz arg)
1779 @cindex magnifying text
1781 Set the font magnification for its argument. In the following
1782 example, the middle@tie{}A is 10% larger:
1785 A \\magnify #1.1 @{ A @} A
1788 Note: Magnification only works if a font name is explicitly selected.
1789 Use @code{\\fontsize} otherwise.
1791 @lilypond[verbatim,quote]
1802 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1805 (define-builtin-markup-command (bold layout props arg)
1809 "Switch to bold font-series.
1811 @lilypond[verbatim,quote]
1819 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1821 (define-builtin-markup-command (sans layout props arg)
1825 "Switch to the sans serif font family.
1827 @lilypond[verbatim,quote]
1836 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1838 (define-builtin-markup-command (number layout props arg)
1842 "Set font family to @code{number}, which yields the font used for
1843 time signatures and fingerings. This font contains numbers and
1844 some punctuation; it has no letters.
1846 @lilypond[verbatim,quote]
1849 0 1 2 3 4 5 6 7 8 9 . ,
1853 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1855 (define-builtin-markup-command (roman layout props arg)
1859 "Set font family to @code{roman}.
1861 @lilypond[verbatim,quote]
1867 text in roman font family
1874 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1876 (define-builtin-markup-command (huge layout props arg)
1880 "Set font size to +2.
1882 @lilypond[verbatim,quote]
1890 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1892 (define-builtin-markup-command (large layout props arg)
1896 "Set font size to +1.
1898 @lilypond[verbatim,quote]
1906 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1908 (define-builtin-markup-command (normalsize layout props arg)
1912 "Set font size to default.
1914 @lilypond[verbatim,quote]
1927 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1929 (define-builtin-markup-command (small layout props arg)
1933 "Set font size to -1.
1935 @lilypond[verbatim,quote]
1943 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1945 (define-builtin-markup-command (tiny layout props arg)
1949 "Set font size to -2.
1951 @lilypond[verbatim,quote]
1959 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1961 (define-builtin-markup-command (teeny layout props arg)
1965 "Set font size to -3.
1967 @lilypond[verbatim,quote]
1975 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1977 (define-builtin-markup-command (fontCaps layout props arg)
1981 "Set @code{font-shape} to @code{caps}
1983 Note: @code{\\fontCaps} requires the installation and selection of
1984 fonts which support the @code{caps} font shape."
1985 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1988 (define-builtin-markup-command (smallCaps layout props arg)
1992 "Emit @var{arg} as small caps.
1994 Note: @code{\\smallCaps} does not support accented characters.
1996 @lilypond[verbatim,quote]
2005 (define (char-list->markup chars lower)
2006 (let ((final-string (string-upcase (reverse-list->string chars))))
2008 (markup #:fontsize -2 final-string)
2010 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2011 (if (null? rest-chars)
2013 (reverse! (cons (char-list->markup currents current-is-lower)
2015 (let* ((ch (car rest-chars))
2016 (is-lower (char-lower-case? ch)))
2017 (if (or (and current-is-lower is-lower)
2018 (and (not current-is-lower) (not is-lower)))
2019 (make-small-caps (cdr rest-chars)
2023 (make-small-caps (cdr rest-chars)
2026 (if (null? currents)
2028 (cons (char-list->markup
2029 currents current-is-lower)
2031 (interpret-markup layout props
2033 (make-small-caps (string->list arg) (list) #f (list))
2036 (define-builtin-markup-command (caps layout props arg)
2040 "Copy of the @code{\\smallCaps} command.
2042 @lilypond[verbatim,quote]
2051 (interpret-markup layout props (make-smallCaps-markup arg)))
2053 (define-builtin-markup-command (dynamic layout props arg)
2057 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2058 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2059 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2060 done in a different font. The recommended font for this is bold and italic.
2061 @lilypond[verbatim,quote]
2069 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2071 (define-builtin-markup-command (text layout props arg)
2075 "Use a text font instead of music symbol or music alphabet font.
2077 @lilypond[verbatim,quote]
2090 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2093 (define-builtin-markup-command (italic layout props arg)
2097 "Use italic @code{font-shape} for @var{arg}.
2099 @lilypond[verbatim,quote]
2107 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2109 (define-builtin-markup-command (typewriter layout props arg)
2113 "Use @code{font-family} typewriter for @var{arg}.
2115 @lilypond[verbatim,quote]
2124 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2126 (define-builtin-markup-command (upright layout props arg)
2130 "Set @code{font-shape} to @code{upright}. This is the opposite
2133 @lilypond[verbatim,quote]
2147 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2149 (define-builtin-markup-command (medium layout props arg)
2153 "Switch to medium font-series (in contrast to bold).
2155 @lilypond[verbatim,quote]
2168 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2171 (define-builtin-markup-command (normal-text layout props arg)
2175 "Set all font related properties (except the size) to get the default
2176 normal text font, no matter what font was used earlier.
2178 @lilypond[verbatim,quote]
2180 \\huge \\bold \\sans \\caps {
2181 Some text with font overrides
2184 Default text, same font-size
2192 (interpret-markup layout
2193 (cons '((font-family . roman) (font-shape . upright)
2194 (font-series . medium) (font-encoding . latin1))
2198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2202 (define-builtin-markup-command (doublesharp layout props)
2206 "Draw a double sharp symbol.
2208 @lilypond[verbatim,quote]
2213 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2215 (define-builtin-markup-command (sesquisharp layout props)
2219 "Draw a 3/2 sharp symbol.
2221 @lilypond[verbatim,quote]
2226 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2228 (define-builtin-markup-command (sharp layout props)
2232 "Draw a sharp symbol.
2234 @lilypond[verbatim,quote]
2239 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2241 (define-builtin-markup-command (semisharp layout props)
2245 "Draw a semisharp symbol.
2247 @lilypond[verbatim,quote]
2252 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2254 (define-builtin-markup-command (natural layout props)
2258 "Draw a natural symbol.
2260 @lilypond[verbatim,quote]
2265 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2267 (define-builtin-markup-command (semiflat layout props)
2271 "Draw a semiflat symbol.
2273 @lilypond[verbatim,quote]
2278 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2280 (define-builtin-markup-command (flat layout props)
2284 "Draw a flat symbol.
2286 @lilypond[verbatim,quote]
2291 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2293 (define-builtin-markup-command (sesquiflat layout props)
2297 "Draw a 3/2 flat symbol.
2299 @lilypond[verbatim,quote]
2304 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2306 (define-builtin-markup-command (doubleflat layout props)
2310 "Draw a double flat symbol.
2312 @lilypond[verbatim,quote]
2317 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2319 (define-builtin-markup-command (with-color layout props color arg)
2324 @cindex coloring text
2326 Draw @var{arg} in color specified by @var{color}.
2328 @lilypond[verbatim,quote]
2340 (let ((stil (interpret-markup layout props arg)))
2341 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2342 (ly:stencil-extent stil X)
2343 (ly:stencil-extent stil Y))))
2345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2349 (define-builtin-markup-command (arrow-head layout props axis dir filled)
2350 (integer? ly:dir? boolean?)
2353 "Produce an arrow head in specified direction and axis.
2354 Use the filled head if @var{filled} is specified.
2355 @lilypond[verbatim,quote]
2358 \\general-align #Y #DOWN {
2359 \\arrow-head #Y #UP ##t
2360 \\arrow-head #Y #DOWN ##f
2362 \\arrow-head #X #RIGHT ##f
2363 \\arrow-head #X #LEFT ##f
2369 ((name (format "arrowheads.~a.~a~a"
2376 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2380 (define-builtin-markup-command (musicglyph layout props glyph-name)
2384 "@var{glyph-name} is converted to a musical symbol; for example,
2385 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2386 the music font. See @ruser{The Feta font} for a complete listing of
2387 the possible glyphs.
2389 @lilypond[verbatim,quote]
2392 \\musicglyph #\"rests.2\"
2393 \\musicglyph #\"clefs.G_change\"
2396 (let* ((font (ly:paper-get-font layout
2397 (cons '((font-encoding . fetaMusic)
2401 (glyph (ly:font-get-glyph font glyph-name)))
2402 (if (null? (ly:stencil-expr glyph))
2403 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2408 (define-builtin-markup-command (lookup layout props glyph-name)
2412 "Lookup a glyph by name.
2414 @lilypond[verbatim,quote]
2416 \\override #'(font-encoding . fetaBraces) {
2417 \\lookup #\"brace200\"
2420 \\lookup #\"brace180\"
2424 (ly:font-get-glyph (ly:paper-get-font layout props)
2427 (define-builtin-markup-command (char layout props num)
2431 "Produce a single character. Characters encoded in hexadecimal
2432 format require the prefix @code{#x}.
2434 @lilypond[verbatim,quote]
2436 \\char #65 \\char ##x00a9
2439 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2441 (define number->mark-letter-vector (make-vector 25 #\A))
2446 (if (= i (- (char->integer #\I) (char->integer #\A)))
2448 (vector-set! number->mark-letter-vector j
2449 (integer->char (+ i (char->integer #\A)))))
2451 (define number->mark-alphabet-vector (list->vector
2452 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2454 (define (number->markletter-string vec n)
2455 "Double letters for big marks."
2456 (let* ((lst (vector-length vec)))
2459 (string-append (number->markletter-string vec (1- (quotient n lst)))
2460 (number->markletter-string vec (remainder n lst)))
2461 (make-string 1 (vector-ref vec n)))))
2463 (define-builtin-markup-command (markletter layout props num)
2467 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2468 (skipping letter@tie{}I), and continue with double letters.
2470 @lilypond[verbatim,quote]
2477 (ly:text-interface::interpret-markup layout props
2478 (number->markletter-string number->mark-letter-vector num)))
2480 (define-builtin-markup-command (markalphabet layout props num)
2484 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2485 and continue with double letters.
2487 @lilypond[verbatim,quote]
2494 (ly:text-interface::interpret-markup layout props
2495 (number->markletter-string number->mark-alphabet-vector num)))
2497 (define-public (horizontal-slash-interval num forward number-interval mag)
2499 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2500 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2501 (else (interval-widen number-interval (* mag 0.25))))
2502 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2503 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2504 (else (interval-widen number-interval (* mag 0.25))))
2507 (define-public (adjust-slash-stencil num forward stencil mag)
2510 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2512 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2514 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2516 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2519 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2521 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2526 (define (slashed-digit-internal layout props num forward font-size thickness)
2527 (let* ((mag (magstep font-size))
2529 (ly:output-def-lookup layout 'line-thickness)
2531 ; backward slashes might use slope and point in the other direction!
2532 (dy (* mag (if forward 0.4 -0.4)))
2533 (number-stencil (interpret-markup layout
2534 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2535 (number->string num)))
2536 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2537 (center (interval-center (ly:stencil-extent number-stencil Y)))
2538 ; Use the real extents of the slash, not the whole number, because we
2539 ; might translate the slash later on!
2540 (num-y (interval-widen (cons center center) (abs dy)))
2541 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2542 (slash-stencil (if is-sane
2543 (make-line-stencil thickness
2544 (car num-x) (- (interval-center num-y) dy)
2545 (cdr num-x) (+ (interval-center num-y) dy))
2547 (if (ly:stencil? slash-stencil)
2549 ; for some numbers we need to shift the slash/backslash up or down to make
2550 ; the slashed digit look better
2551 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2552 (set! number-stencil
2553 (ly:stencil-add number-stencil slash-stencil)))
2554 (ly:warning "Unable to create slashed digit ~a" num))
2558 (define-builtin-markup-command (slashed-digit layout props num)
2564 @cindex slashed digits
2566 A feta number, with slash. This is for use in the context of
2567 figured bass notation.
2568 @lilypond[verbatim,quote]
2572 \\override #'(thickness . 3)
2576 (slashed-digit-internal layout props num #t font-size thickness))
2578 (define-builtin-markup-command (backslashed-digit layout props num)
2584 @cindex backslashed digits
2586 A feta number, with backslash. This is for use in the context of
2587 figured bass notation.
2588 @lilypond[verbatim,quote]
2590 \\backslashed-digit #5
2592 \\override #'(thickness . 3)
2593 \\backslashed-digit #7
2596 (slashed-digit-internal layout props num #f font-size thickness))
2599 (define eyeglassesps
2604 0.7 0.7 0.5 0 361 arc
2606 2.20 0.70 0.50 0 361 arc
2608 1.45 0.85 0.30 0 180 arc
2612 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2616 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2619 (define-builtin-markup-command (eyeglasses layout props) () other ()
2620 "Prints out eyeglasses, indicating strongly to look at the conductor.
2621 @lilypond[verbatim,quote]
2622 \\markup { \\eyeglasses }
2624 (interpret-markup layout props
2625 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2626 (make-postscript-markup eyeglassesps))))
2628 (define-builtin-markup-command (left-brace layout props size)
2633 A feta brace in point size @var{size}.
2635 @lilypond[verbatim,quote]
2642 (let* ((font (ly:paper-get-font layout
2643 (cons '((font-encoding . fetaBraces)
2646 (glyph-count (1- (ly:otf-glyph-count font)))
2647 (scale (ly:output-def-lookup layout 'output-scale))
2648 (scaled-size (/ (ly:pt size) scale))
2650 (ly:font-get-glyph font (string-append "brace"
2651 (number->string n)))))
2652 (get-y-from-brace (lambda (brace)
2654 (ly:stencil-extent (glyph brace) Y))))
2655 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2656 (glyph-found (glyph find-brace)))
2658 (if (or (null? (ly:stencil-expr glyph-found))
2659 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2660 (> scaled-size (interval-length
2661 (ly:stencil-extent (glyph glyph-count) Y))))
2663 (ly:warning (_ "no brace found for point size ~S ") size)
2664 (ly:warning (_ "defaulting to ~S pt")
2665 (/ (* scale (interval-length
2666 (ly:stencil-extent glyph-found Y)))
2670 (define-builtin-markup-command (right-brace layout props size)
2675 A feta brace in point size @var{size}, rotated 180 degrees.
2677 @lilypond[verbatim,quote]
2684 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2687 ;; the note command.
2688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2690 ;; TODO: better syntax.
2692 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2693 (number? number? number?)
2698 @cindex notes within text by log and dot-count
2700 Construct a note symbol, with stem. By using fractional values for
2701 @var{dir}, longer or shorter stems can be obtained.
2703 @lilypond[verbatim,quote]
2705 \\note-by-number #3 #0 #DOWN
2707 \\note-by-number #1 #2 #0.8
2710 (define (get-glyph-name-candidates dir log style)
2711 (map (lambda (dir-name)
2712 (format "noteheads.~a~a~a" dir-name (min log 2)
2713 (if (and (symbol? style)
2714 (not (equal? 'default style)))
2715 (symbol->string style)
2717 (list (if (= dir UP) "u" "d")
2720 (define (get-glyph-name font cands)
2723 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2724 (get-glyph-name font (cdr cands))
2727 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2728 (size-factor (magstep font-size))
2729 (stem-length (* size-factor (max 3 (- log 1))))
2730 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2731 (head-glyph (ly:font-get-glyph font head-glyph-name))
2732 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2733 (stem-thickness (* size-factor 0.13))
2734 (stemy (* dir stem-length))
2735 (attach-off (cons (interval-index
2736 (ly:stencil-extent head-glyph X)
2737 (* (sign dir) (car attach-indices)))
2738 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2740 (ly:stencil-extent head-glyph Y)
2741 (cdr attach-indices)))))
2742 (stem-glyph (and (> log 0)
2743 (ly:round-filled-box
2744 (ordered-cons (car attach-off)
2745 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2746 (cons (min stemy (cdr attach-off))
2747 (max stemy (cdr attach-off)))
2748 (/ stem-thickness 3))))
2750 (dot (ly:font-get-glyph font "dots.dot"))
2751 (dotwid (interval-length (ly:stencil-extent dot X)))
2752 (dots (and (> dot-count 0)
2753 (apply ly:stencil-add
2755 (ly:stencil-translate-axis
2756 dot (* 2 x dotwid) X))
2757 (iota dot-count)))))
2758 (flaggl (and (> log 2)
2759 (ly:stencil-translate
2760 (ly:font-get-glyph font
2761 (string-append "flags."
2762 (if (> dir 0) "u" "d")
2763 (number->string log)))
2764 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2766 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2767 ; 16th notes get a special case because their flags hang lower than any other flags.
2768 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2769 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2771 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2772 (if (ly:stencil? stem-glyph)
2773 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2774 (set! stem-glyph head-glyph))
2775 (if (ly:stencil? dots)
2778 (ly:stencil-translate-axis
2780 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2786 (let ((divisor (log 2)))
2787 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2789 (define (parse-simple-duration duration-string)
2790 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2791 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2792 (if (and match (string=? duration-string (match:substring match 0)))
2793 (let ((len (match:substring match 1))
2794 (dots (match:substring match 2)))
2795 (list (cond ((string=? len "breve") -1)
2796 ((string=? len "longa") -2)
2797 ((string=? len "maxima") -3)
2798 (else (log2 (string->number len))))
2799 (if dots (string-length dots) 0)))
2800 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2802 (define-builtin-markup-command (note layout props duration dir)
2805 (note-by-number-markup)
2807 @cindex notes within text by string
2809 This produces a note with a stem pointing in @var{dir} direction, with
2810 the @var{duration} for the note head type and augmentation dots. For
2811 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2812 a shortened down stem.
2814 @lilypond[verbatim,quote]
2816 \\override #'(style . cross) {
2820 \\note #\"breve\" #0
2823 (let ((parsed (parse-simple-duration duration)))
2824 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2826 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2830 (define-builtin-markup-command (lower layout props amount arg)
2835 @cindex lowering text
2837 Lower @var{arg} by the distance @var{amount}.
2838 A negative @var{amount} indicates raising; see also @code{\\raise}.
2840 @lilypond[verbatim,quote]
2848 (ly:stencil-translate-axis (interpret-markup layout props arg)
2851 (define-builtin-markup-command (translate-scaled layout props offset arg)
2852 (number-pair? markup?)
2856 @cindex translating text
2857 @cindex scaling text
2859 Translate @var{arg} by @var{offset}, scaling the offset by the
2862 @lilypond[verbatim,quote]
2865 * \\translate #'(2 . 3) translate
2867 * \\translate-scaled #'(2 . 3) translate-scaled
2871 (let* ((factor (magstep font-size))
2872 (scaled (cons (* factor (car offset))
2873 (* factor (cdr offset)))))
2874 (ly:stencil-translate (interpret-markup layout props arg)
2877 (define-builtin-markup-command (raise layout props amount arg)
2882 @cindex raising text
2884 Raise @var{arg} by the distance @var{amount}.
2885 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2887 The argument to @code{\\raise} is the vertical displacement amount,
2888 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2889 raise objects in relation to their surrounding markups.
2891 If the text object itself is positioned above or below the staff, then
2892 @code{\\raise} cannot be used to move it, since the mechanism that
2893 positions it next to the staff cancels any shift made with
2894 @code{\\raise}. For vertical positioning, use the @code{padding}
2895 and/or @code{extra-offset} properties.
2897 @lilypond[verbatim,quote]
2906 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2908 (define-builtin-markup-command (fraction layout props arg1 arg2)
2913 @cindex creating text fractions
2915 Make a fraction of two markups.
2916 @lilypond[verbatim,quote]
2922 (let* ((m1 (interpret-markup layout props arg1))
2923 (m2 (interpret-markup layout props arg2))
2924 (factor (magstep font-size))
2925 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2926 (padding (* factor 0.2))
2927 (baseline (* factor 0.6))
2928 (offset (* factor 0.75)))
2929 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2930 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2931 (let* ((x1 (ly:stencil-extent m1 X))
2932 (x2 (ly:stencil-extent m2 X))
2933 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2934 ;; should stack mols separately, to maintain LINE on baseline
2935 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2937 (ly:stencil-aligned-to stack Y CENTER))
2939 (ly:stencil-aligned-to stack X LEFT))
2940 ;; should have EX dimension
2942 (ly:stencil-translate-axis stack offset Y))))
2944 (define-builtin-markup-command (normal-size-super layout props arg)
2949 @cindex setting superscript in standard font size
2951 Set @var{arg} in superscript with a normal font size.
2953 @lilypond[verbatim,quote]
2956 \\normal-size-super {
2957 superscript in standard size
2961 (ly:stencil-translate-axis
2962 (interpret-markup layout props arg)
2963 (* 0.5 baseline-skip) Y))
2965 (define-builtin-markup-command (super layout props arg)
2971 @cindex superscript text
2973 Set @var{arg} in superscript.
2975 @lilypond[verbatim,quote]
2985 (ly:stencil-translate-axis
2988 (cons `((font-size . ,(- font-size 3))) props)
2990 (* 0.5 baseline-skip)
2993 (define-builtin-markup-command (translate layout props offset arg)
2994 (number-pair? markup?)
2998 @cindex translating text
3000 Translate @var{arg} relative to its surroundings. @var{offset}
3001 is a pair of numbers representing the displacement in the X and Y axis.
3003 @lilypond[verbatim,quote]
3006 \\translate #'(2 . 3)
3007 \\line { translated two spaces right, three up }
3010 (ly:stencil-translate (interpret-markup layout props arg)
3013 (define-builtin-markup-command (sub layout props arg)
3019 @cindex subscript text
3021 Set @var{arg} in subscript.
3023 @lilypond[verbatim,quote]
3034 (ly:stencil-translate-axis
3037 (cons `((font-size . ,(- font-size 3))) props)
3039 (* -0.5 baseline-skip)
3042 (define-builtin-markup-command (normal-size-sub layout props arg)
3047 @cindex setting subscript in standard font size
3049 Set @var{arg} in subscript with a normal font size.
3051 @lilypond[verbatim,quote]
3055 subscript in standard size
3059 (ly:stencil-translate-axis
3060 (interpret-markup layout props arg)
3061 (* -0.5 baseline-skip)
3064 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3066 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3068 (define-builtin-markup-command (hbracket layout props arg)
3073 @cindex placing horizontal brackets around text
3075 Draw horizontal brackets around @var{arg}.
3077 @lilypond[verbatim,quote]
3086 (let ((th 0.1) ;; todo: take from GROB.
3087 (m (interpret-markup layout props arg)))
3088 (bracketify-stencil m X th (* 2.5 th) th)))
3090 (define-builtin-markup-command (bracket layout props arg)
3095 @cindex placing vertical brackets around text
3097 Draw vertical brackets around @var{arg}.
3099 @lilypond[verbatim,quote]
3106 (let ((th 0.1) ;; todo: take from GROB.
3107 (m (interpret-markup layout props arg)))
3108 (bracketify-stencil m Y th (* 2.5 th) th)))
3110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3111 ;; Delayed markup evaluation
3112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3114 (define-builtin-markup-command (page-ref layout props label gauge default)
3115 (symbol? markup? markup?)
3119 @cindex referencing page numbers in text
3121 Reference to a page number. @var{label} is the label set on the referenced
3122 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3123 the maximum width of the page number, and @var{default} the value to display
3124 when @var{label} is not found."
3125 (let* ((gauge-stencil (interpret-markup layout props gauge))
3126 (x-ext (ly:stencil-extent gauge-stencil X))
3127 (y-ext (ly:stencil-extent gauge-stencil Y)))
3129 `(delay-stencil-evaluation
3130 ,(delay (ly:stencil-expr
3131 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3132 (page-number (if (list? table)
3133 (assoc-get label table)
3135 (page-markup (if page-number (format "~a" page-number) default))
3136 (page-stencil (interpret-markup layout props page-markup))
3137 (gap (- (interval-length x-ext)
3138 (interval-length (ly:stencil-extent page-stencil X)))))
3139 (interpret-markup layout props
3140 (markup #:concat (#:hspace gap page-markup)))))))
3144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3145 ;; Markup list commands
3146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3148 (define-public (space-lines baseline stils)
3149 (let space-stil ((stils stils)
3153 (let* ((stil (car stils))
3154 (dy-top (max (- (/ baseline 1.5)
3155 (interval-bound (ly:stencil-extent stil Y) UP))
3157 (dy-bottom (max (+ (/ baseline 3.0)
3158 (interval-bound (ly:stencil-extent stil Y) DOWN))
3160 (new-stil (ly:make-stencil
3161 (ly:stencil-expr stil)
3162 (ly:stencil-extent stil X)
3163 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3165 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3167 (space-stil (cdr stils) (cons new-stil result))))))
3169 (define-builtin-markup-list-command (justified-lines layout props args)
3172 wordwrap-internal-markup-list)
3174 @cindex justifying lines of text
3176 Like @code{\\justify}, but return a list of lines instead of a single markup.
3177 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3178 @var{X}@tie{}is the number of staff spaces."
3179 (space-lines baseline-skip
3180 (interpret-markup-list layout props
3181 (make-wordwrap-internal-markup-list #t args))))
3183 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3186 wordwrap-internal-markup-list)
3187 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3188 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3189 where @var{X} is the number of staff spaces."
3190 (space-lines baseline-skip
3191 (interpret-markup-list layout props
3192 (make-wordwrap-internal-markup-list #f args))))
3194 (define-builtin-markup-list-command (column-lines layout props args)
3197 "Like @code{\\column}, but return a list of lines instead of a single markup.
3198 @code{baseline-skip} determines the space between each markup in @var{args}."
3199 (space-lines (chain-assoc-get 'baseline-skip props)
3200 (interpret-markup-list layout props args)))
3202 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3203 (pair? markup-list?)
3205 "Like @code{\\override}, for markup lists."
3206 (interpret-markup-list layout (cons (list new-prop) props) args))