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)
50 (cons (min x 0) (max x 0))
51 (cons (min y 0) (max y 0)))))
53 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
54 (number? number? boolean?)
58 @cindex drawing circles within text
60 A circle of radius @var{radius}, thickness @var{thickness} and
63 @lilypond[verbatim,quote]
65 \\draw-circle #2 #0.5 ##f
67 \\draw-circle #2 #0 ##t
70 (make-circle-stencil radius thickness fill))
72 (define-builtin-markup-command (triangle layout props filled)
79 @cindex drawing triangles within text
81 A triangle, either filled or empty.
83 @lilypond[verbatim,quote]
90 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
99 (cons 0 (* .86 ex)))))
101 (define-builtin-markup-command (circle layout props arg)
106 (circle-padding 0.2))
108 @cindex circling text
110 Draw a circle around @var{arg}. Use @code{thickness},
111 @code{circle-padding} and @code{font-size} properties to determine line
112 thickness and padding around the markup.
114 @lilypond[verbatim,quote]
121 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
123 (pad (* (magstep font-size) circle-padding))
124 (m (interpret-markup layout props arg)))
125 (circle-stencil m th pad)))
127 (define-builtin-markup-command (with-url layout props url arg)
132 @cindex inserting URL links into text
134 Add a link to URL @var{url} around @var{arg}. This only works in
137 @lilypond[verbatim,quote]
139 \\with-url #\"http://lilypond.org/web/\" {
140 LilyPond ... \\italic {
141 music notation for everyone
146 (let* ((stil (interpret-markup layout props arg))
147 (xextent (ly:stencil-extent stil X))
148 (yextent (ly:stencil-extent stil Y))
149 (old-expr (ly:stencil-expr stil))
150 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
152 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
154 (define-builtin-markup-command (beam layout props width slope thickness)
155 (number? number? number?)
159 @cindex drawing beams within text
161 Create a beam with the specified parameters.
162 @lilypond[verbatim,quote]
167 (let* ((y (* slope width))
168 (yext (cons (min 0 y) (max 0 y)))
169 (half (/ thickness 2)))
174 width (+ (* width slope) (/ thickness -2))
175 width (+ (* width slope) (/ thickness 2))
177 ,(ly:output-def-lookup layout 'blot-diameter)
180 (cons (+ (- half) (car yext))
181 (+ half (cdr yext))))))
183 (define-builtin-markup-command (underline layout props arg)
188 @cindex underlining text
190 Underline @var{arg}. Looks at @code{thickness} to determine line
191 thickness and y offset.
193 @lilypond[verbatim,quote]
195 \\override #'(thickness . 2)
201 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
203 (markup (interpret-markup layout props arg))
204 (x1 (car (ly:stencil-extent markup X)))
205 (x2 (cdr (ly:stencil-extent markup X)))
207 (line (ly:make-stencil
208 `(draw-line ,thick ,x1 ,y ,x2 ,y)
209 (cons (min x1 0) (max x2 0))
210 (cons thick thick))))
211 (ly:stencil-add markup line)))
213 (define-builtin-markup-command (box layout props arg)
220 @cindex enclosing text within a box
222 Draw a box round @var{arg}. Looks at @code{thickness},
223 @code{box-padding} and @code{font-size} properties to determine line
224 thickness and padding around the markup.
226 @lilypond[verbatim,quote]
228 \\override #'(box-padding . 0.5)
233 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
235 (pad (* (magstep font-size) box-padding))
236 (m (interpret-markup layout props arg)))
237 (box-stencil m th pad)))
239 (define-builtin-markup-command (filled-box layout props xext yext blot)
240 (number-pair? number-pair? number?)
244 @cindex drawing solid boxes within text
245 @cindex drawing boxes with rounded corners
247 Draw a box with rounded corners of dimensions @var{xext} and
248 @var{yext}. For example,
250 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
252 creates a box extending horizontally from -0.3 to 1.8 and
253 vertically from -0.3 up to 1.8, with corners formed from a
254 circle of diameter@tie{}0 (i.e. sharp corners).
256 @lilypond[verbatim,quote]
258 \\filled-box #'(0 . 4) #'(0 . 4) #0
259 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
260 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
262 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
268 (define-builtin-markup-command (rounded-box layout props arg)
275 "@cindex enclosing text in a bow with rounded corners
276 @cindex drawing boxes with rounded corners around text
277 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
278 @code{box-padding} and @code{font-size} properties to determine line
279 thickness and padding around the markup; the @code{corner-radius} property
280 makes possible to define another shape for the corners (default is 1).
282 @lilypond[quote,verbatim,fragment,relative=2]
290 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
292 (pad (* (magstep font-size) box-padding))
293 (m (interpret-markup layout props arg)))
294 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
297 (define-builtin-markup-command (rotate layout props ang arg)
302 @cindex rotating text
304 Rotate object with @var{ang} degrees around its center."
305 (let* ((stil (interpret-markup layout props arg)))
306 (ly:stencil-rotate stil ang 0 0)))
308 (define-builtin-markup-command (whiteout layout props arg)
313 @cindex adding a white background to text
315 Provide a white background for @var{arg}."
316 (stencil-whiteout (interpret-markup layout props arg)))
318 (define-builtin-markup-command (pad-markup layout props padding arg)
324 @cindex putting space around text
326 Add space around a markup object."
328 ((stil (interpret-markup layout props arg))
329 (xext (ly:stencil-extent stil X))
330 (yext (ly:stencil-extent stil Y)))
333 (ly:stencil-expr stil)
334 (interval-widen xext padding)
335 (interval-widen yext padding))))
337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
339 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
341 (define-builtin-markup-command (strut layout props)
346 @cindex creating vertical spaces in text
348 Create a box of the same height as the space in the current font."
349 (let ((m (ly:text-interface::interpret-markup layout props " ")))
350 (ly:make-stencil (ly:stencil-expr m)
352 (ly:stencil-extent m X)
355 ;; todo: fix negative space
356 (define-builtin-markup-command (hspace layout props amount)
361 @cindex creating horizontal spaces in text
363 This produces an invisible object taking horizontal space. For example,
366 \\markup @{ A \\hspace #2.0 B @}
370 puts extra space between A and@tie{}B, on top of the space that is
371 normally inserted before elements on a line.
373 @lilypond[verbatim,quote]
383 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
384 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
387 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
388 ;; importing graphics.
389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
391 (define-builtin-markup-command (stencil layout props stil)
396 @cindex importing stencils into text
398 Use a stencil as markup."
402 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
404 (define (get-postscript-bbox string)
405 "Extract the bbox from STRING, or return #f if not present."
407 ((match (regexp-exec bbox-regexp string)))
411 (string->number (match:substring match x)))
416 (define-builtin-markup-command (epsfile layout props axis size file-name)
417 (number? number? string?)
421 @cindex inlining an Encapsulated PostScript image
423 Inline an EPS image. The image is scaled along @var{axis} to
426 @lilypond[verbatim,quote]
428 \\general-align #Y #DOWN {
429 \\epsfile #X #20 #\"context-example.eps\"
430 \\epsfile #Y #20 #\"context-example.eps\"
434 (if (ly:get-option 'safe)
435 (interpret-markup layout props "not allowed in safe")
436 (eps-file->stencil axis size file-name)
439 (define-builtin-markup-command (postscript layout props str)
444 @cindex inserting PostScript directly into text
446 This inserts @var{str} directly into the output as a PostScript
447 command string. Due to technicalities of the output backends,
448 different scales should be used for the @TeX{} and PostScript backend,
449 selected with @code{-f}.
451 For the @TeX{} backend, the following string prints a rotated text
454 0 0 moveto /ecrm10 findfont
455 1.75 scalefont setfont 90 rotate (hello) show
459 The magical constant 1.75 scales from LilyPond units (staff spaces) to
462 For the postscript backend, use the following
465 gsave /ecrm10 findfont
466 10.0 output-scale div
467 scalefont setfont 90 rotate (hello) show grestore
470 @lilypond[verbatim,quote]
476 0.7 0.7 0.5 0 361 arc
478 2.20 0.70 0.50 0 361 arc
480 1.45 0.85 0.30 0 180 arc
484 0.92 2.26 1.30 2.40 1.15 1.70 curveto
488 3.42 2.26 3.80 2.40 3.65 1.70 curveto
491 eyeglasses = \\markup {
492 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
493 \\postscript #eyeglassesps
505 gsave currentpoint translate
513 (define-builtin-markup-command (score layout props score)
518 @cindex inserting music into text
520 Inline an image of music.
522 @lilypond[verbatim,quote]
526 \\new Staff \\relative c' {
529 \\mark \\markup { Allegro }
535 \\new Staff \\relative c {
549 \\override RehearsalMark #'break-align-symbols =
550 #'(time-signature key-signature)
551 \\override RehearsalMark #'self-alignment-X = #LEFT
555 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
561 (let* ((output (ly:score-embedded-format score layout)))
563 (if (ly:music-output? output)
564 (paper-system-stencil
565 (vector-ref (ly:paper-score-paper-systems output) 0))
567 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
570 (define-builtin-markup-command (null layout props)
575 @cindex creating empty text objects
577 An empty markup with extents of a single point.
579 @lilypond[verbatim,quote]
586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
590 (define-builtin-markup-command (simple layout props str)
595 @cindex simple text strings
597 A simple text string; @code{\\markup @{ foo @}} is equivalent with
598 @code{\\markup @{ \\simple #\"foo\" @}}.
600 @lilypond[verbatim,quote]
604 \\simple #\"strings\"
607 (interpret-markup layout props str))
609 (define-builtin-markup-command (tied-lyric layout props str)
614 @cindex simple text strings with tie characters
616 Like simple-markup, but use tie characters for @q{~} tilde symbols.
618 @lilypond[verbatim,quote]
620 \\tied-lyric #\"Lasciate~i monti\"
623 (if (string-contains str "~")
625 ((parts (string-split str #\~))
626 (tie-str (ly:wide-char->utf-8 #x203f))
627 (joined (list-join parts tie-str))
628 (join-stencil (interpret-markup layout props tie-str))
631 (interpret-markup layout
634 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
636 (make-line-markup joined)))
637 ;(map (lambda (s) (interpret-markup layout props s)) parts))
638 (interpret-markup layout props str)))
640 (define-public empty-markup
641 (make-simple-markup ""))
643 ;; helper for justifying lines.
644 (define (get-fill-space word-count line-width text-widths)
645 "Calculate the necessary paddings between each two adjacent texts.
646 The lengths of all texts are stored in @var{text-widths}.
647 The normal formula for the padding between texts a and b is:
648 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
649 The first and last padding have to be calculated specially using the
650 whole length of the first or last text.
651 Return a list of paddings."
653 ((null? text-widths) '())
655 ;; special case first padding
656 ((= (length text-widths) word-count)
658 (- (- (/ line-width (1- word-count)) (car text-widths))
659 (/ (car (cdr text-widths)) 2))
660 (get-fill-space word-count line-width (cdr text-widths))))
661 ;; special case last padding
662 ((= (length text-widths) 2)
663 (list (- (/ line-width (1- word-count))
664 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
667 (- (/ line-width (1- word-count))
668 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
669 (get-fill-space word-count line-width (cdr text-widths))))))
671 (define-builtin-markup-command (fill-line layout props markups)
674 ((text-direction RIGHT)
677 "Put @var{markups} in a horizontal line of width @var{line-width}.
678 The markups are spaced or flushed to fill the entire line.
679 If there are no arguments, return an empty stencil.
681 @lilypond[verbatim,quote]
685 Words evenly spaced across the page
689 \\line { Text markups }
691 \\italic { evenly spaced }
693 \\line { across the page }
698 (let* ((orig-stencils (interpret-markup-list layout props markups))
701 (if (ly:stencil-empty? stc)
703 stc)) orig-stencils))
706 (if (ly:stencil-empty? stc)
708 (interval-length (ly:stencil-extent stc X))))
710 (text-width (apply + text-widths))
711 (word-count (length stencils))
712 (prop-line-width (chain-assoc-get 'line-width props #f))
713 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
718 (/ (- line-width text-width) 2)
719 (/ (- line-width text-width) 2)))
722 (- line-width text-width)))
724 (get-fill-space word-count line-width text-widths))))
732 (line-stencils (if (= word-count 1)
739 (if (= text-direction LEFT)
740 (set! line-stencils (reverse line-stencils)))
742 (if (null? (remove ly:stencil-empty? orig-stencils))
744 (stack-stencils-padding-list X
745 RIGHT fill-space-normal line-stencils))))
747 (define-builtin-markup-command (line layout props args)
751 (text-direction RIGHT))
752 "Put @var{args} in a horizontal line. The property @code{word-space}
753 determines the space between each markup in @var{args}.
755 @lilypond[verbatim,quote]
758 A simple line of text
762 (let ((stencils (interpret-markup-list layout props args)))
763 (if (= text-direction LEFT)
764 (set! stencils (reverse stencils)))
767 (remove ly:stencil-empty? stencils))))
769 (define-builtin-markup-command (concat layout props args)
774 @cindex concatenating text
775 @cindex ligatures in text
777 Concatenate @var{args} in a horizontal line, without spaces inbetween.
778 Strings and simple markups are concatenated on the input level, allowing
779 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
780 equivalent to @code{\"fi\"}.
782 @lilypond[verbatim,quote]
794 (define (concat-string-args arg-list)
795 (fold-right (lambda (arg result-list)
796 (let ((result (if (pair? result-list)
799 (if (and (pair? arg) (eqv? (car arg) simple-markup))
800 (set! arg (cadr arg)))
801 (if (and (string? result) (string? arg))
802 (cons (string-append arg result) (cdr result-list))
803 (cons arg result-list))))
807 (interpret-markup layout
808 (prepend-alist-chain 'word-space 0 props)
809 (make-line-markup (if (markup-command-list? args)
811 (concat-string-args args)))))
813 (define (wordwrap-stencils stencils
814 justify base-space line-width text-dir)
815 "Perform simple wordwrap, return stencil of each line."
816 (define space (if justify
817 ;; justify only stretches lines.
820 (define (take-list width space stencils
821 accumulator accumulated-width)
822 "Return (head-list . tail) pair, with head-list fitting into width"
824 (cons accumulator stencils)
825 (let* ((first (car stencils))
826 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
827 (newwid (+ space first-wid accumulated-width)))
828 (if (or (null? accumulator)
830 (take-list width space
832 (cons first accumulator)
834 (cons accumulator stencils)))))
835 (let loop ((lines '())
837 (let* ((line-break (take-list line-width space todo
839 (line-stencils (car line-break))
840 (space-left (- line-width
841 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
843 (line-word-space (cond ((not justify) space)
844 ;; don't stretch last line of paragraph.
845 ;; hmmm . bug - will overstretch the last line in some case.
846 ((null? (cdr line-break))
848 ((null? line-stencils) 0.0)
849 ((null? (cdr line-stencils)) 0.0)
850 (else (/ space-left (1- (length line-stencils))))))
851 (line (stack-stencil-line line-word-space
852 (if (= text-dir RIGHT)
853 (reverse line-stencils)
855 (if (pair? (cdr line-break))
856 (loop (cons line lines)
859 (if (= text-dir LEFT)
861 (ly:stencil-translate-axis
863 (- line-width (interval-end (ly:stencil-extent line X)))
865 (reverse (cons line lines)))))))
867 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
868 (boolean? markup-list?)
871 (text-direction RIGHT))
872 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
873 (wordwrap-stencils (remove ly:stencil-empty?
874 (interpret-markup-list layout props args))
878 (ly:output-def-lookup layout 'line-width))
881 (define-builtin-markup-command (justify layout props args)
885 wordwrap-internal-markup-list)
887 @cindex justifying text
889 Like wordwrap, but with lines stretched to justify the margins.
890 Use @code{\\override #'(line-width . @var{X})} to set the line width;
891 @var{X}@tie{}is the number of staff spaces."
892 (stack-lines DOWN 0.0 baseline-skip
893 (wordwrap-internal-markup-list layout props #t args)))
895 (define-builtin-markup-command (wordwrap layout props args)
899 wordwrap-internal-markup-list)
900 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
901 the line width, where @var{X} is the number of staff spaces."
902 (stack-lines DOWN 0.0 baseline-skip
903 (wordwrap-internal-markup-list layout props #f args)))
905 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
909 (text-direction RIGHT))
910 "Internal markup list command used to define @code{\\justify-string} and
911 @code{\\wordwrap-string}."
912 (let* ((para-strings (regexp-split
913 (string-regexp-substitute
915 (string-regexp-substitute "\r\n" "\n" arg))
916 "\n[ \t\n]*\n[ \t\n]*"))
917 (list-para-words (map (lambda (str)
918 (regexp-split str "[ \t\n]+"))
920 (para-lines (map (lambda (words)
922 (remove ly:stencil-empty?
924 (interpret-markup layout props x))
926 (wordwrap-stencils stencils
928 line-width text-direction)))
930 (apply append para-lines)))
932 (define-builtin-markup-command (wordwrap-string layout props arg)
936 wordwrap-string-internal-markup-list)
937 "Wordwrap a string. Paragraphs may be separated with double newlines."
938 (stack-lines DOWN 0.0 baseline-skip
939 (wordwrap-string-internal-markup-list layout props #f arg)))
941 (define-builtin-markup-command (justify-string layout props arg)
945 wordwrap-string-internal-markup-list)
946 "Justify a string. Paragraphs may be separated with double newlines"
947 (stack-lines DOWN 0.0 baseline-skip
948 (wordwrap-string-internal-markup-list layout props #t arg)))
950 (define-builtin-markup-command (wordwrap-field layout props symbol)
954 "Wordwrap the data which has been assigned to @var{symbol}."
955 (let* ((m (chain-assoc-get symbol props)))
957 (wordwrap-string-markup layout props m)
960 (define-builtin-markup-command (justify-field layout props symbol)
964 "Justify the data which has been assigned to @var{symbol}."
965 (let* ((m (chain-assoc-get symbol props)))
967 (justify-string-markup layout props m)
970 (define-builtin-markup-command (combine layout props m1 m2)
977 Print two markups on top of each other.
978 @lilypond[verbatim,quote]
981 \\override #'(thickness . 2)
983 \\draw-line #'(0 . 4)
984 \\arrow-head #Y #DOWN ##f
987 (let* ((s1 (interpret-markup layout props m1))
988 (s2 (interpret-markup layout props m2)))
989 (ly:stencil-add s1 s2)))
992 ;; TODO: should extract baseline-skip from each argument somehow..
994 (define-builtin-markup-command (column layout props args)
999 @cindex stacking text in a column
1001 Stack the markups in @var{args} vertically. The property
1002 @code{baseline-skip} determines the space between each
1003 markup in @var{args}.
1005 @lilypond[verbatim,quote]
1014 (let ((arg-stencils (interpret-markup-list layout props args)))
1015 (stack-lines -1 0.0 baseline-skip
1016 (remove ly:stencil-empty? arg-stencils))))
1018 (define-builtin-markup-command (dir-column layout props args)
1024 @cindex changing direction of text columns
1026 Make a column of args, going up or down, depending on the setting
1027 of the @code{#'direction} layout property.
1029 @lilypond[verbatim,quote]
1031 \\override #'(direction . 1) {
1041 (stack-lines (if (number? direction) direction -1)
1044 (interpret-markup-list layout props args)))
1046 (define-builtin-markup-command (center-align layout props args)
1051 @cindex centering a column of text
1053 Put @code{args} in a centered column.
1055 @lilypond[verbatim,quote]
1064 (let* ((mols (interpret-markup-list layout props args))
1065 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
1066 (stack-lines -1 0.0 baseline-skip cmols)))
1068 (define-builtin-markup-command (vcenter layout props arg)
1073 @cindex vertically centering text
1075 Align @code{arg} to its Y@tie{}center.
1077 @lilypond[verbatim,quote]
1079 \\arrow-head #X #RIGHT ##f
1082 \\arrow-head #X #LEFT ##f
1085 (let* ((mol (interpret-markup layout props arg)))
1086 (ly:stencil-aligned-to mol Y CENTER)))
1088 (define-builtin-markup-command (hcenter layout props arg)
1093 @cindex horizontally centering text
1095 Align @code{arg} to its X@tie{}center.
1097 @lilypond[verbatim,quote]
1106 (let* ((mol (interpret-markup layout props arg)))
1107 (ly:stencil-aligned-to mol X CENTER)))
1109 (define-builtin-markup-command (right-align layout props arg)
1114 @cindex right aligning text
1116 Align @var{arg} on its right edge.
1118 @lilypond[verbatim,quote]
1127 (let* ((m (interpret-markup layout props arg)))
1128 (ly:stencil-aligned-to m X RIGHT)))
1130 (define-builtin-markup-command (left-align layout props arg)
1135 @cindex left aligning text
1137 Align @var{arg} on its left edge.
1139 @lilypond[verbatim,quote]
1148 (let* ((m (interpret-markup layout props arg)))
1149 (ly:stencil-aligned-to m X LEFT)))
1151 (define-builtin-markup-command (general-align layout props axis dir arg)
1152 (integer? number? markup?)
1156 @cindex controlling general text alignment
1158 Align @var{arg} in @var{axis} direction to the @var{dir} side."
1159 (let* ((m (interpret-markup layout props arg)))
1160 (ly:stencil-aligned-to m axis dir)))
1162 (define-builtin-markup-command (halign layout props dir arg)
1167 @cindex setting horizontal text alignment
1169 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1170 left-aligned, while @code{+1} is right. Values in between interpolate
1171 alignment accordingly.
1173 @lilypond[verbatim,quote]
1193 (let* ((m (interpret-markup layout props arg)))
1194 (ly:stencil-aligned-to m X dir)))
1196 (define-builtin-markup-command (with-dimensions layout props x y arg)
1197 (number-pair? number-pair? markup?)
1201 @cindex setting extent of text objects
1203 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1204 (let* ((m (interpret-markup layout props arg)))
1205 (ly:make-stencil (ly:stencil-expr m) x y)))
1207 (define-builtin-markup-command (pad-around layout props amount arg)
1211 "Add padding @var{amount} all around @var{arg}."
1212 (let* ((m (interpret-markup layout props arg))
1213 (x (ly:stencil-extent m X))
1214 (y (ly:stencil-extent m Y)))
1215 (ly:make-stencil (ly:stencil-expr m)
1216 (interval-widen x amount)
1217 (interval-widen y amount))))
1219 (define-builtin-markup-command (pad-x layout props amount arg)
1224 @cindex padding text horizontally
1226 Add padding @var{amount} around @var{arg} in the X@tie{}direction."
1227 (let* ((m (interpret-markup layout props arg))
1228 (x (ly:stencil-extent m X))
1229 (y (ly:stencil-extent m Y)))
1230 (ly:make-stencil (ly:stencil-expr m)
1231 (interval-widen x amount)
1234 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2)
1235 (markup? integer? ly:dir? markup?)
1238 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1239 (let ((m1 (interpret-markup layout props arg1))
1240 (m2 (interpret-markup layout props arg2)))
1241 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1243 (define-builtin-markup-command (transparent layout props arg)
1247 "Make the argument transparent."
1248 (let* ((m (interpret-markup layout props arg))
1249 (x (ly:stencil-extent m X))
1250 (y (ly:stencil-extent m Y)))
1251 (ly:make-stencil "" x y)))
1253 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1254 (number-pair? number-pair? markup?)
1257 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
1258 (let* ((m (interpret-markup layout props arg))
1259 (x (ly:stencil-extent m X))
1260 (y (ly:stencil-extent m Y)))
1261 (ly:make-stencil (ly:stencil-expr m)
1262 (interval-union x-ext x)
1263 (interval-union y-ext y))))
1265 (define-builtin-markup-command (hcenter-in layout props length arg)
1269 "Center @var{arg} horizontally within a box of extending
1270 @var{length}/2 to the left and right."
1271 (interpret-markup layout props
1272 (make-pad-to-box-markup
1273 (cons (/ length -2) (/ length 2))
1275 (make-hcenter-markup arg))))
1277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1281 (define-builtin-markup-command (fromproperty layout props symbol)
1285 "Read the @var{symbol} from property settings, and produce a stencil
1286 from the markup contained within. If @var{symbol} is not defined, it
1287 returns an empty markup."
1288 (let ((m (chain-assoc-get symbol props)))
1290 (interpret-markup layout props m)
1293 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1297 "Apply the @var{procedure} markup command to @var{arg}.
1298 @var{procedure} should take a single argument."
1299 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1300 (set-object-property! anonymous-with-signature
1303 (interpret-markup layout props (list anonymous-with-signature arg))))
1305 (define-builtin-markup-command (override layout props new-prop arg)
1310 @cindex overriding properties within text markup
1312 Add the first argument in to the property list. Properties may be
1313 any sort of property supported by @rinternals{font-interface} and
1314 @rinternals{text-interface}, for example
1317 \\override #'(font-family . married) \"bla\"
1319 (interpret-markup layout (cons (list new-prop) props) arg))
1321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325 (define-builtin-markup-command (verbatim-file layout props name)
1329 "Read the contents of a file, and include it verbatim.
1331 @lilypond[verbatim,quote]
1333 \\verbatim-file #\"simple.ly\"
1335 (interpret-markup layout props
1336 (if (ly:get-option 'safe)
1337 "verbatim-file disabled in safe mode"
1338 (let* ((str (ly:gulp-file name))
1339 (lines (string-split str #\nl)))
1340 (make-typewriter-markup
1341 (make-column-markup lines))))))
1343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1347 (define-builtin-markup-command (bigger layout props arg)
1351 "Increase the font size relative to current setting.
1353 @lilypond[verbatim,quote]
1366 (interpret-markup layout props
1367 `(,fontsize-markup 1 ,arg)))
1369 (define-builtin-markup-command (smaller layout props arg)
1373 "Decrease the font size relative to current setting.
1375 @lilypond[verbatim,quote]
1388 (interpret-markup layout props
1389 `(,fontsize-markup -1 ,arg)))
1391 (define-builtin-markup-command (larger layout props arg)
1395 "Copy of the @code{\\bigger} command.
1397 @lilypond[verbatim,quote]
1405 (interpret-markup layout props (make-bigger-markup arg)))
1407 (define-builtin-markup-command (finger layout props arg)
1411 "Set the argument as small numbers.
1412 @lilypond[verbatim,quote]
1419 (interpret-markup layout
1420 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1423 (define-builtin-markup-command (fontsize layout props increment arg)
1429 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1430 @lilypond[verbatim,quote]
1438 (let ((entries (list
1439 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1440 (cons 'word-space (* word-space (magstep increment)))
1441 (cons 'font-size (+ font-size increment)))))
1442 (interpret-markup layout (cons entries props) arg)))
1444 (define-builtin-markup-command (magnify layout props sz arg)
1449 @cindex magnifying text
1451 Set the font magnification for its argument. In the following
1452 example, the middle@tie{}A is 10% larger:
1455 A \\magnify #1.1 @{ A @} A
1458 Note: Magnification only works if a font name is explicitly selected.
1459 Use @code{\\fontsize} otherwise.
1461 @lilypond[verbatim,quote]
1472 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1475 (define-builtin-markup-command (bold layout props arg)
1479 "Switch to bold font-series.
1481 @lilypond[verbatim,quote]
1489 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1491 (define-builtin-markup-command (sans layout props arg)
1495 "Switch to the sans serif family.
1497 @lilypond[verbatim,quote]
1506 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1508 (define-builtin-markup-command (number layout props arg)
1512 "Set font family to @code{number}, which yields the font used for
1513 time signatures and fingerings. This font only contains numbers and
1514 some punctuation. It doesn't have any letters.
1516 @lilypond[verbatim,quote]
1519 0 1 2 3 4 5 6 7 8 9 . ,
1523 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1525 (define-builtin-markup-command (roman layout props arg)
1529 "Set font family to @code{roman}.
1531 @lilypond[verbatim,quote]
1537 text in roman font family
1544 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1546 (define-builtin-markup-command (huge layout props arg)
1550 "Set font size to +2.
1552 @lilypond[verbatim,quote]
1560 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1562 (define-builtin-markup-command (large layout props arg)
1566 "Set font size to +1.
1568 @lilypond[verbatim,quote]
1576 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1578 (define-builtin-markup-command (normalsize layout props arg)
1582 "Set font size to default.
1584 @lilypond[verbatim,quote]
1597 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1599 (define-builtin-markup-command (small layout props arg)
1603 "Set font size to -1.
1605 @lilypond[verbatim,quote]
1613 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1615 (define-builtin-markup-command (tiny layout props arg)
1619 "Set font size to -2.
1621 @lilypond[verbatim,quote]
1629 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1631 (define-builtin-markup-command (teeny layout props arg)
1635 "Set font size to -3.
1637 @lilypond[verbatim,quote]
1645 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1647 (define-builtin-markup-command (fontCaps layout props arg)
1651 "Set @code{font-shape} to @code{caps}"
1652 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1655 (define-builtin-markup-command (smallCaps layout props text)
1659 "Emit @var{arg} as small caps.
1661 Note: @code{\\smallCaps} does not support accented characters.
1663 @lilypond[verbatim,quote]
1672 (define (char-list->markup chars lower)
1673 (let ((final-string (string-upcase (reverse-list->string chars))))
1675 (markup #:fontsize -2 final-string)
1677 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1678 (if (null? rest-chars)
1680 (reverse! (cons (char-list->markup currents current-is-lower)
1682 (let* ((ch (car rest-chars))
1683 (is-lower (char-lower-case? ch)))
1684 (if (or (and current-is-lower is-lower)
1685 (and (not current-is-lower) (not is-lower)))
1686 (make-small-caps (cdr rest-chars)
1690 (make-small-caps (cdr rest-chars)
1693 (if (null? currents)
1695 (cons (char-list->markup
1696 currents current-is-lower)
1698 (interpret-markup layout props
1700 (make-small-caps (string->list text) (list) #f (list))
1703 (define-builtin-markup-command (caps layout props arg)
1707 "Copy of the @code{\\smallCaps} command.
1709 @lilypond[verbatim,quote]
1718 (interpret-markup layout props (make-smallCaps-markup arg)))
1720 (define-builtin-markup-command (dynamic layout props arg)
1724 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
1725 @b{z}, @b{p}, and @b{r}. When producing phrases, like
1726 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
1727 done in a different font. The recommended font for this is bold and italic.
1728 @lilypond[verbatim,quote]
1736 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
1738 (define-builtin-markup-command (text layout props arg)
1742 "Use a text font instead of music symbol or music alphabet font.
1744 @lilypond[verbatim,quote]
1757 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1760 (define-builtin-markup-command (italic layout props arg)
1764 "Use italic @code{font-shape} for @var{arg}.
1766 @lilypond[verbatim,quote]
1774 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1776 (define-builtin-markup-command (typewriter layout props arg)
1780 "Use @code{font-family} typewriter for @var{arg}.
1782 @lilypond[verbatim,quote]
1791 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1793 (define-builtin-markup-command (upright layout props arg)
1797 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
1799 @lilypond[verbatim,quote]
1813 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1815 (define-builtin-markup-command (medium layout props arg)
1819 "Switch to medium font series (in contrast to bold).
1821 @lilypond[verbatim,quote]
1834 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1837 (define-builtin-markup-command (normal-text layout props arg)
1841 "Set all font related properties (except the size) to get the default
1842 normal text font, no matter what font was used earlier.
1844 @lilypond[verbatim,quote]
1846 \\huge \\bold \\sans \\caps {
1847 Some text with font overrides
1850 Default text, same font-size
1858 (interpret-markup layout
1859 (cons '((font-family . roman) (font-shape . upright)
1860 (font-series . medium) (font-encoding . latin1))
1864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1868 (define-builtin-markup-command (doublesharp layout props)
1872 "Draw a double sharp symbol.
1874 @lilypond[verbatim,quote]
1879 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1881 (define-builtin-markup-command (sesquisharp layout props)
1885 "Draw a 3/2 sharp symbol.
1887 @lilypond[verbatim,quote]
1892 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1894 (define-builtin-markup-command (sharp layout props)
1898 "Draw a sharp symbol.
1900 @lilypond[verbatim,quote]
1905 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1907 (define-builtin-markup-command (semisharp layout props)
1911 "Draw a semi sharp symbol.
1913 @lilypond[verbatim,quote]
1918 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1920 (define-builtin-markup-command (natural layout props)
1924 "Draw a natural symbol.
1926 @lilypond[verbatim,quote]
1931 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1933 (define-builtin-markup-command (semiflat layout props)
1937 "Draw a semiflat symbol.
1939 @lilypond[verbatim,quote]
1944 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1946 (define-builtin-markup-command (flat layout props)
1950 "Draw a flat symbol.
1952 @lilypond[verbatim,quote]
1957 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1959 (define-builtin-markup-command (sesquiflat layout props)
1963 "Draw a 3/2 flat symbol.
1965 @lilypond[verbatim,quote]
1970 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1972 (define-builtin-markup-command (doubleflat layout props)
1976 "Draw a double flat symbol.
1978 @lilypond[verbatim,quote]
1983 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1985 (define-builtin-markup-command (with-color layout props color arg)
1990 @cindex coloring text
1992 Draw @var{arg} in color specified by @var{color}."
1993 (let ((stil (interpret-markup layout props arg)))
1994 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1995 (ly:stencil-extent stil X)
1996 (ly:stencil-extent stil Y))))
1998 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2002 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2003 (integer? ly:dir? boolean?)
2006 "Produce an arrow head in specified direction and axis.
2007 Use the filled head if @var{filled} is specified.
2008 @lilypond[verbatim,quote]
2011 \\general-align #Y #DOWN {
2012 \\arrow-head #Y #UP ##t
2013 \\arrow-head #Y #DOWN ##f
2015 \\arrow-head #X #RIGHT ##f
2016 \\arrow-head #X #LEFT ##f
2022 ((name (format "arrowheads.~a.~a~a"
2029 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2033 (define-builtin-markup-command (musicglyph layout props glyph-name)
2037 "@var{glyph-name} is converted to a musical symbol; for example,
2038 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2039 the music font. See @ruser{The Feta font} for a complete listing of
2040 the possible glyphs.
2042 @lilypond[verbatim,quote]
2045 \\musicglyph #\"rests.2\"
2046 \\musicglyph #\"clefs.G_change\"
2049 (let* ((font (ly:paper-get-font layout
2050 (cons '((font-encoding . fetaMusic)
2054 (glyph (ly:font-get-glyph font glyph-name)))
2055 (if (null? (ly:stencil-expr glyph))
2056 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2061 (define-builtin-markup-command (lookup layout props glyph-name)
2065 "Lookup a glyph by name.
2067 @lilypond[verbatim,quote]
2069 \\override #'(font-encoding . fetaBraces) {
2070 \\lookup #\"brace200\"
2073 \\lookup #\"brace180\"
2077 (ly:font-get-glyph (ly:paper-get-font layout props)
2080 (define-builtin-markup-command (char layout props num)
2084 "Produce a single character. For example, @code{\\char #65} produces the
2086 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2088 (define number->mark-letter-vector (make-vector 25 #\A))
2093 (if (= i (- (char->integer #\I) (char->integer #\A)))
2095 (vector-set! number->mark-letter-vector j
2096 (integer->char (+ i (char->integer #\A)))))
2098 (define number->mark-alphabet-vector (list->vector
2099 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2101 (define (number->markletter-string vec n)
2102 "Double letters for big marks."
2103 (let* ((lst (vector-length vec)))
2106 (string-append (number->markletter-string vec (1- (quotient n lst)))
2107 (number->markletter-string vec (remainder n lst)))
2108 (make-string 1 (vector-ref vec n)))))
2110 (define-builtin-markup-command (markletter layout props num)
2114 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2115 (skipping letter@tie{}I), and continue with double letters.
2117 @lilypond[verbatim,quote]
2124 (ly:text-interface::interpret-markup layout props
2125 (number->markletter-string number->mark-letter-vector num)))
2127 (define-builtin-markup-command (markalphabet layout props num)
2131 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2132 and continue with double letters.
2134 @lilypond[verbatim,quote]
2141 (ly:text-interface::interpret-markup layout props
2142 (number->markletter-string number->mark-alphabet-vector num)))
2144 (define-public (horizontal-slash-interval num forward number-interval mag)
2145 (ly:message "Mag step: ~a" mag)
2147 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2148 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2149 (else (interval-widen number-interval (* mag 0.25))))
2150 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2151 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2152 (else (interval-widen number-interval (* mag 0.25))))
2155 (define-public (adjust-slash-stencil num forward stencil mag)
2158 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2160 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2162 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2164 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2167 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2169 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2174 (define (slashed-digit-internal layout props num forward font-size thickness)
2175 (let* ((mag (magstep font-size))
2177 (ly:output-def-lookup layout 'line-thickness)
2179 ; backward slashes might use slope and point in the other direction!
2180 (dy (* mag (if forward 0.4 -0.4)))
2181 (number-stencil (interpret-markup layout
2182 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2183 (number->string num)))
2184 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2185 (center (interval-center (ly:stencil-extent number-stencil Y)))
2186 ; Use the real extents of the slash, not the whole number, because we
2187 ; might translate the slash later on!
2188 (num-y (interval-widen (cons center center) (abs dy)))
2189 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2190 (slash-stencil (if is-sane
2192 `(draw-line ,thickness
2193 ,(car num-x) ,(- (interval-center num-y) dy)
2194 ,(cdr num-x) ,(+ (interval-center num-y) dy))
2197 (ly:message "Num: ~a, X-interval: ~a" num num-x)
2198 (if (ly:stencil? slash-stencil)
2200 ; for some numbers we need to shift the slash/backslash up or down to make
2201 ; the slashed digit look better
2202 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2203 (set! number-stencil
2204 (ly:stencil-add number-stencil slash-stencil)))
2205 (ly:warning "Unable to create slashed digit ~a" num))
2209 (define-builtin-markup-command (slashed-digit layout props num)
2215 @cindex slashed digits
2217 A feta number, with slash. This is for use in the context of
2218 figured bass notation.
2219 @lilypond[verbatim,quote]
2223 \\override #'(thickness . 3)
2227 (slashed-digit-internal layout props num #t font-size thickness))
2229 (define-builtin-markup-command (backslashed-digit layout props num)
2235 @cindex backslashed digits
2237 A feta number, with backslash. This is for use in the context of
2238 figured bass notation.
2239 @lilypond[verbatim,quote]
2241 \\backslashed-digit #5
2243 \\override #'(thickness . 3)
2244 \\backslashed-digit #7
2247 (slashed-digit-internal layout props num #f font-size thickness))
2249 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2250 ;; the note command.
2251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2253 ;; TODO: better syntax.
2255 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2256 (number? number? number?)
2261 @cindex notes within text by log and dot-count
2263 Construct a note symbol, with stem. By using fractional values for
2264 @var{dir}, you can obtain longer or shorter stems.
2266 @lilypond[verbatim,quote]
2268 \\note-by-number #3 #0 #DOWN
2270 \\note-by-number #1 #2 #0.8
2273 (define (get-glyph-name-candidates dir log style)
2274 (map (lambda (dir-name)
2275 (format "noteheads.~a~a~a" dir-name (min log 2)
2276 (if (and (symbol? style)
2277 (not (equal? 'default style)))
2278 (symbol->string style)
2280 (list (if (= dir UP) "u" "d")
2283 (define (get-glyph-name font cands)
2286 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2287 (get-glyph-name font (cdr cands))
2290 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2291 (size-factor (magstep font-size))
2292 (stem-length (* size-factor (max 3 (- log 1))))
2293 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2294 (head-glyph (ly:font-get-glyph font head-glyph-name))
2295 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2296 (stem-thickness (* size-factor 0.13))
2297 (stemy (* dir stem-length))
2298 (attach-off (cons (interval-index
2299 (ly:stencil-extent head-glyph X)
2300 (* (sign dir) (car attach-indices)))
2301 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2303 (ly:stencil-extent head-glyph Y)
2304 (cdr attach-indices)))))
2305 (stem-glyph (and (> log 0)
2306 (ly:round-filled-box
2307 (ordered-cons (car attach-off)
2308 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2309 (cons (min stemy (cdr attach-off))
2310 (max stemy (cdr attach-off)))
2311 (/ stem-thickness 3))))
2313 (dot (ly:font-get-glyph font "dots.dot"))
2314 (dotwid (interval-length (ly:stencil-extent dot X)))
2315 (dots (and (> dot-count 0)
2316 (apply ly:stencil-add
2318 (ly:stencil-translate-axis
2319 dot (* 2 x dotwid) X))
2320 (iota dot-count)))))
2321 (flaggl (and (> log 2)
2322 (ly:stencil-translate
2323 (ly:font-get-glyph font
2324 (string-append "flags."
2325 (if (> dir 0) "u" "d")
2326 (number->string log)))
2327 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2329 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2330 ; 16th notes get a special case because their flags hang lower than any other flags.
2331 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2332 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2334 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2335 (if (ly:stencil? stem-glyph)
2336 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2337 (set! stem-glyph head-glyph))
2338 (if (ly:stencil? dots)
2341 (ly:stencil-translate-axis
2343 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2349 (let ((divisor (log 2)))
2350 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2352 (define (parse-simple-duration duration-string)
2353 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2354 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2355 (if (and match (string=? duration-string (match:substring match 0)))
2356 (let ((len (match:substring match 1))
2357 (dots (match:substring match 2)))
2358 (list (cond ((string=? len "breve") -1)
2359 ((string=? len "longa") -2)
2360 ((string=? len "maxima") -3)
2361 (else (log2 (string->number len))))
2362 (if dots (string-length dots) 0)))
2363 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2365 (define-builtin-markup-command (note layout props duration dir)
2368 (note-by-number-markup)
2370 @cindex notes within text by string
2372 This produces a note with a stem pointing in @var{dir} direction, with
2373 the @var{duration} for the note head type and augmentation dots. For
2374 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2375 a shortened down stem.
2377 @lilypond[verbatim,quote]
2379 \\override #'(style . cross) {
2383 \\note #\"breve\" #0
2386 (let ((parsed (parse-simple-duration duration)))
2387 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2389 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2391 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2393 (define-builtin-markup-command (lower layout props amount arg)
2398 @cindex lowering text
2400 Lower @var{arg} by the distance @var{amount}.
2401 A negative @var{amount} indicates raising; see also @code{\\raise}."
2402 (ly:stencil-translate-axis (interpret-markup layout props arg)
2405 (define-builtin-markup-command (translate-scaled layout props offset arg)
2406 (number-pair? markup?)
2410 @cindex translating text
2411 @cindex scaling text
2413 Translate @var{arg} by @var{offset}, scaling the offset by the
2415 (let* ((factor (magstep font-size))
2416 (scaled (cons (* factor (car offset))
2417 (* factor (cdr offset)))))
2418 (ly:stencil-translate (interpret-markup layout props arg)
2421 (define-builtin-markup-command (raise layout props amount arg)
2426 @cindex raising text
2428 Raise @var{arg} by the distance @var{amount}.
2429 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2431 The argument to @code{\\raise} is the vertical displacement amount,
2432 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2433 raise objects in relation to their surrounding markups.
2435 If the text object itself is positioned above or below the staff, then
2436 @code{\\raise} cannot be used to move it, since the mechanism that
2437 positions it next to the staff cancels any shift made with
2438 @code{\\raise}. For vertical positioning, use the @code{padding}
2439 and/or @code{extra-offset} properties.
2441 @lilypond[verbatim,quote]
2450 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2452 (define-builtin-markup-command (fraction layout props arg1 arg2)
2457 @cindex creating text fractions
2459 Make a fraction of two markups.
2460 @lilypond[verbatim,quote]
2466 (let* ((m1 (interpret-markup layout props arg1))
2467 (m2 (interpret-markup layout props arg2))
2468 (factor (magstep font-size))
2469 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2470 (padding (* factor 0.2))
2471 (baseline (* factor 0.6))
2472 (offset (* factor 0.75)))
2473 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2474 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2475 (let* ((x1 (ly:stencil-extent m1 X))
2476 (x2 (ly:stencil-extent m2 X))
2477 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2478 ;; should stack mols separately, to maintain LINE on baseline
2479 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2481 (ly:stencil-aligned-to stack Y CENTER))
2483 (ly:stencil-aligned-to stack X LEFT))
2484 ;; should have EX dimension
2486 (ly:stencil-translate-axis stack offset Y))))
2488 (define-builtin-markup-command (normal-size-super layout props arg)
2493 @cindex setting superscript in standard font size
2495 Set @var{arg} in superscript with a normal font size.
2497 @lilypond[verbatim,quote]
2500 \\normal-size-super {
2501 superscript in standard size
2505 (ly:stencil-translate-axis
2506 (interpret-markup layout props arg)
2507 (* 0.5 baseline-skip) Y))
2509 (define-builtin-markup-command (super layout props arg)
2515 @cindex superscript text
2517 Raising and lowering texts can be done with @code{\\super} and
2520 @lilypond[verbatim,quote]
2530 (ly:stencil-translate-axis
2533 (cons `((font-size . ,(- font-size 3))) props)
2535 (* 0.5 baseline-skip)
2538 (define-builtin-markup-command (translate layout props offset arg)
2539 (number-pair? markup?)
2543 @cindex translating text
2545 This translates an object. Its first argument is a cons of numbers.
2548 A \\translate #(cons 2 -3) @{ B C @} D
2551 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2552 surroundings. This command cannot be used to move isolated scripts
2553 vertically, for the same reason that @code{\\raise} cannot be used for
2555 (ly:stencil-translate (interpret-markup layout props arg)
2558 (define-builtin-markup-command (sub layout props arg)
2564 @cindex subscript text
2566 Set @var{arg} in subscript.
2568 @lilypond[verbatim,quote]
2579 (ly:stencil-translate-axis
2582 (cons `((font-size . ,(- font-size 3))) props)
2584 (* -0.5 baseline-skip)
2587 (define-builtin-markup-command (normal-size-sub layout props arg)
2592 @cindex setting subscript in standard font size
2594 Set @var{arg} in subscript, in a normal font size.
2596 @lilypond[verbatim,quote]
2600 subscript in standard size
2604 (ly:stencil-translate-axis
2605 (interpret-markup layout props arg)
2606 (* -0.5 baseline-skip)
2609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2613 (define-builtin-markup-command (hbracket layout props arg)
2618 @cindex placing horizontal brackets around text
2620 Draw horizontal brackets around @var{arg}.
2622 @lilypond[verbatim,quote]
2631 (let ((th 0.1) ;; todo: take from GROB.
2632 (m (interpret-markup layout props arg)))
2633 (bracketify-stencil m X th (* 2.5 th) th)))
2635 (define-builtin-markup-command (bracket layout props arg)
2640 @cindex placing vertical brackets around text
2642 Draw vertical brackets around @var{arg}.
2644 @lilypond[verbatim,quote]
2651 (let ((th 0.1) ;; todo: take from GROB.
2652 (m (interpret-markup layout props arg)))
2653 (bracketify-stencil m Y th (* 2.5 th) th)))
2655 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2656 ;; Delayed markup evaluation
2657 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2659 (define-builtin-markup-command (page-ref layout props label gauge default)
2660 (symbol? markup? markup?)
2664 @cindex referencing page numbers in text
2666 Reference to a page number. @var{label} is the label set on the referenced
2667 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
2668 the maximum width of the page number, and @var{default} the value to display
2669 when @var{label} is not found."
2670 (let* ((gauge-stencil (interpret-markup layout props gauge))
2671 (x-ext (ly:stencil-extent gauge-stencil X))
2672 (y-ext (ly:stencil-extent gauge-stencil Y)))
2674 `(delay-stencil-evaluation
2675 ,(delay (ly:stencil-expr
2676 (let* ((table (ly:output-def-lookup layout 'label-page-table))
2677 (label-page (and (list? table) (assoc label table)))
2678 (page-number (and label-page (cdr label-page)))
2679 (page-markup (if page-number (format "~a" page-number) default))
2680 (page-stencil (interpret-markup layout props page-markup))
2681 (gap (- (interval-length x-ext)
2682 (interval-length (ly:stencil-extent page-stencil X)))))
2683 (interpret-markup layout props
2684 (markup #:concat (#:hspace gap page-markup)))))))
2688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2689 ;; Markup list commands
2690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2692 (define-public (space-lines baseline stils)
2693 (let space-stil ((prev-stil #f)
2696 (cond ((null? stils)
2699 (space-stil (car stils) (cdr stils) (list (car stils))))
2701 (let* ((stil (car stils))
2702 (dy (max (- baseline
2703 (+ (- (interval-bound (ly:stencil-extent prev-stil Y) DOWN))
2704 (interval-bound (ly:stencil-extent stil Y) UP)))
2706 (new-stil (ly:make-stencil
2707 (ly:stencil-expr stil)
2708 (ly:stencil-extent stil X)
2709 (cons (interval-bound (ly:stencil-extent stil Y) DOWN)
2710 (+ (interval-bound (ly:stencil-extent stil Y) UP) dy)))))
2711 (space-stil stil (cdr stils) (cons new-stil result)))))))
2713 (define-builtin-markup-list-command (justified-lines layout props args)
2716 wordwrap-internal-markup-list)
2718 @cindex justifying lines of text
2720 Like @code{\\justify}, but return a list of lines instead of a single markup.
2721 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
2722 @var{X}@tie{}is the number of staff spaces."
2723 (space-lines baseline-skip
2724 (interpret-markup-list layout props
2725 (make-wordwrap-internal-markup-list #t args))))
2727 (define-builtin-markup-list-command (wordwrap-lines layout props args)
2730 wordwrap-internal-markup-list)
2731 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
2732 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
2733 where @var{X} is the number of staff spaces."
2734 (space-lines baseline-skip
2735 (interpret-markup-list layout props
2736 (make-wordwrap-internal-markup-list #f args))))
2738 (define-builtin-markup-list-command (column-lines layout props args)
2741 "Like @code{\\column}, but return a list of lines instead of a single markup.
2742 @code{baseline-skip} determines the space between each markup in @var{args}."
2743 (space-lines (chain-assoc-get 'baseline-skip props)
2744 (interpret-markup-list layout props args)))
2746 (define-builtin-markup-list-command (override-lines layout props new-prop args)
2747 (pair? markup-list?)
2749 "Like @code{\\override}, for markup lists."
2750 (interpret-markup-list layout (cons (list new-prop) props) args))