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\"
1336 (interpret-markup layout props
1337 (if (ly:get-option 'safe)
1338 "verbatim-file disabled in safe mode"
1339 (let* ((str (ly:gulp-file name))
1340 (lines (string-split str #\nl)))
1341 (make-typewriter-markup
1342 (make-column-markup lines))))))
1344 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1346 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1348 (define-builtin-markup-command (bigger layout props arg)
1352 "Increase the font size relative to current setting.
1354 @lilypond[verbatim,quote]
1367 (interpret-markup layout props
1368 `(,fontsize-markup 1 ,arg)))
1370 (define-builtin-markup-command (smaller layout props arg)
1374 "Decrease the font size relative to current setting.
1376 @lilypond[verbatim,quote]
1389 (interpret-markup layout props
1390 `(,fontsize-markup -1 ,arg)))
1392 (define-builtin-markup-command (larger layout props arg)
1396 "Copy of the @code{\\bigger} command.
1398 @lilypond[verbatim,quote]
1406 (interpret-markup layout props (make-bigger-markup arg)))
1408 (define-builtin-markup-command (finger layout props arg)
1412 "Set the argument as small numbers.
1413 @lilypond[verbatim,quote]
1420 (interpret-markup layout
1421 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1424 (define-builtin-markup-command (abs-fontsize layout props size arg)
1428 "Use @var{size} as the absolute font size to display @var{arg}.
1429 Adjust baseline skip and word space accordingly.
1430 @lilypond[verbatim,quote]
1432 default text font size
1434 \\abs-fontsize #16 { text font size 16 }
1436 \\abs-fontsize #12 { text font size 12 }
1439 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1440 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1441 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1442 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1443 (magnification (/ size ref-size)))
1444 (interpret-markup layout
1445 (cons `((baseline-skip . ,(* magnification ref-baseline))
1446 (word-space . ,(* magnification ref-word-space))
1447 (font-size . ,(magnification->font-size magnification)))
1451 (define-builtin-markup-command (fontsize layout props increment arg)
1457 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1458 @lilypond[verbatim,quote]
1466 (let ((entries (list
1467 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1468 (cons 'word-space (* word-space (magstep increment)))
1469 (cons 'font-size (+ font-size increment)))))
1470 (interpret-markup layout (cons entries props) arg)))
1472 (define-builtin-markup-command (magnify layout props sz arg)
1477 @cindex magnifying text
1479 Set the font magnification for its argument. In the following
1480 example, the middle@tie{}A is 10% larger:
1483 A \\magnify #1.1 @{ A @} A
1486 Note: Magnification only works if a font name is explicitly selected.
1487 Use @code{\\fontsize} otherwise.
1489 @lilypond[verbatim,quote]
1500 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1503 (define-builtin-markup-command (bold layout props arg)
1507 "Switch to bold font-series.
1509 @lilypond[verbatim,quote]
1517 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1519 (define-builtin-markup-command (sans layout props arg)
1523 "Switch to the sans serif family.
1525 @lilypond[verbatim,quote]
1534 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1536 (define-builtin-markup-command (number layout props arg)
1540 "Set font family to @code{number}, which yields the font used for
1541 time signatures and fingerings. This font only contains numbers and
1542 some punctuation. It doesn't have any letters.
1544 @lilypond[verbatim,quote]
1547 0 1 2 3 4 5 6 7 8 9 . ,
1551 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1553 (define-builtin-markup-command (roman layout props arg)
1557 "Set font family to @code{roman}.
1559 @lilypond[verbatim,quote]
1565 text in roman font family
1572 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1574 (define-builtin-markup-command (huge layout props arg)
1578 "Set font size to +2.
1580 @lilypond[verbatim,quote]
1588 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1590 (define-builtin-markup-command (large layout props arg)
1594 "Set font size to +1.
1596 @lilypond[verbatim,quote]
1604 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1606 (define-builtin-markup-command (normalsize layout props arg)
1610 "Set font size to default.
1612 @lilypond[verbatim,quote]
1625 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1627 (define-builtin-markup-command (small layout props arg)
1631 "Set font size to -1.
1633 @lilypond[verbatim,quote]
1641 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1643 (define-builtin-markup-command (tiny layout props arg)
1647 "Set font size to -2.
1649 @lilypond[verbatim,quote]
1657 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1659 (define-builtin-markup-command (teeny layout props arg)
1663 "Set font size to -3.
1665 @lilypond[verbatim,quote]
1673 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1675 (define-builtin-markup-command (fontCaps layout props arg)
1679 "Set @code{font-shape} to @code{caps}"
1680 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1683 (define-builtin-markup-command (smallCaps layout props text)
1687 "Emit @var{arg} as small caps.
1689 Note: @code{\\smallCaps} does not support accented characters.
1691 @lilypond[verbatim,quote]
1700 (define (char-list->markup chars lower)
1701 (let ((final-string (string-upcase (reverse-list->string chars))))
1703 (markup #:fontsize -2 final-string)
1705 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1706 (if (null? rest-chars)
1708 (reverse! (cons (char-list->markup currents current-is-lower)
1710 (let* ((ch (car rest-chars))
1711 (is-lower (char-lower-case? ch)))
1712 (if (or (and current-is-lower is-lower)
1713 (and (not current-is-lower) (not is-lower)))
1714 (make-small-caps (cdr rest-chars)
1718 (make-small-caps (cdr rest-chars)
1721 (if (null? currents)
1723 (cons (char-list->markup
1724 currents current-is-lower)
1726 (interpret-markup layout props
1728 (make-small-caps (string->list text) (list) #f (list))
1731 (define-builtin-markup-command (caps layout props arg)
1735 "Copy of the @code{\\smallCaps} command.
1737 @lilypond[verbatim,quote]
1746 (interpret-markup layout props (make-smallCaps-markup arg)))
1748 (define-builtin-markup-command (dynamic layout props arg)
1752 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
1753 @b{z}, @b{p}, and @b{r}. When producing phrases, like
1754 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
1755 done in a different font. The recommended font for this is bold and italic.
1756 @lilypond[verbatim,quote]
1764 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
1766 (define-builtin-markup-command (text layout props arg)
1770 "Use a text font instead of music symbol or music alphabet font.
1772 @lilypond[verbatim,quote]
1785 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1788 (define-builtin-markup-command (italic layout props arg)
1792 "Use italic @code{font-shape} for @var{arg}.
1794 @lilypond[verbatim,quote]
1802 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1804 (define-builtin-markup-command (typewriter layout props arg)
1808 "Use @code{font-family} typewriter for @var{arg}.
1810 @lilypond[verbatim,quote]
1819 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1821 (define-builtin-markup-command (upright layout props arg)
1825 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
1827 @lilypond[verbatim,quote]
1841 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1843 (define-builtin-markup-command (medium layout props arg)
1847 "Switch to medium font series (in contrast to bold).
1849 @lilypond[verbatim,quote]
1862 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1865 (define-builtin-markup-command (normal-text layout props arg)
1869 "Set all font related properties (except the size) to get the default
1870 normal text font, no matter what font was used earlier.
1872 @lilypond[verbatim,quote]
1874 \\huge \\bold \\sans \\caps {
1875 Some text with font overrides
1878 Default text, same font-size
1886 (interpret-markup layout
1887 (cons '((font-family . roman) (font-shape . upright)
1888 (font-series . medium) (font-encoding . latin1))
1892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1896 (define-builtin-markup-command (doublesharp layout props)
1900 "Draw a double sharp symbol.
1902 @lilypond[verbatim,quote]
1907 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1909 (define-builtin-markup-command (sesquisharp layout props)
1913 "Draw a 3/2 sharp symbol.
1915 @lilypond[verbatim,quote]
1920 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1922 (define-builtin-markup-command (sharp layout props)
1926 "Draw a sharp symbol.
1928 @lilypond[verbatim,quote]
1933 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1935 (define-builtin-markup-command (semisharp layout props)
1939 "Draw a semi sharp symbol.
1941 @lilypond[verbatim,quote]
1946 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1948 (define-builtin-markup-command (natural layout props)
1952 "Draw a natural symbol.
1954 @lilypond[verbatim,quote]
1959 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1961 (define-builtin-markup-command (semiflat layout props)
1965 "Draw a semiflat symbol.
1967 @lilypond[verbatim,quote]
1972 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1974 (define-builtin-markup-command (flat layout props)
1978 "Draw a flat symbol.
1980 @lilypond[verbatim,quote]
1985 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1987 (define-builtin-markup-command (sesquiflat layout props)
1991 "Draw a 3/2 flat symbol.
1993 @lilypond[verbatim,quote]
1998 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2000 (define-builtin-markup-command (doubleflat layout props)
2004 "Draw a double flat symbol.
2006 @lilypond[verbatim,quote]
2011 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2013 (define-builtin-markup-command (with-color layout props color arg)
2018 @cindex coloring text
2020 Draw @var{arg} in color specified by @var{color}."
2021 (let ((stil (interpret-markup layout props arg)))
2022 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2023 (ly:stencil-extent stil X)
2024 (ly:stencil-extent stil Y))))
2026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2028 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2030 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2031 (integer? ly:dir? boolean?)
2034 "Produce an arrow head in specified direction and axis.
2035 Use the filled head if @var{filled} is specified.
2036 @lilypond[verbatim,quote]
2039 \\general-align #Y #DOWN {
2040 \\arrow-head #Y #UP ##t
2041 \\arrow-head #Y #DOWN ##f
2043 \\arrow-head #X #RIGHT ##f
2044 \\arrow-head #X #LEFT ##f
2050 ((name (format "arrowheads.~a.~a~a"
2057 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2061 (define-builtin-markup-command (musicglyph layout props glyph-name)
2065 "@var{glyph-name} is converted to a musical symbol; for example,
2066 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2067 the music font. See @ruser{The Feta font} for a complete listing of
2068 the possible glyphs.
2070 @lilypond[verbatim,quote]
2073 \\musicglyph #\"rests.2\"
2074 \\musicglyph #\"clefs.G_change\"
2077 (let* ((font (ly:paper-get-font layout
2078 (cons '((font-encoding . fetaMusic)
2082 (glyph (ly:font-get-glyph font glyph-name)))
2083 (if (null? (ly:stencil-expr glyph))
2084 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2089 (define-builtin-markup-command (lookup layout props glyph-name)
2093 "Lookup a glyph by name.
2095 @lilypond[verbatim,quote]
2097 \\override #'(font-encoding . fetaBraces) {
2098 \\lookup #\"brace200\"
2101 \\lookup #\"brace180\"
2105 (ly:font-get-glyph (ly:paper-get-font layout props)
2108 (define-builtin-markup-command (char layout props num)
2112 "Produce a single character. For example, @code{\\char #65} produces the
2114 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2116 (define number->mark-letter-vector (make-vector 25 #\A))
2121 (if (= i (- (char->integer #\I) (char->integer #\A)))
2123 (vector-set! number->mark-letter-vector j
2124 (integer->char (+ i (char->integer #\A)))))
2126 (define number->mark-alphabet-vector (list->vector
2127 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2129 (define (number->markletter-string vec n)
2130 "Double letters for big marks."
2131 (let* ((lst (vector-length vec)))
2134 (string-append (number->markletter-string vec (1- (quotient n lst)))
2135 (number->markletter-string vec (remainder n lst)))
2136 (make-string 1 (vector-ref vec n)))))
2138 (define-builtin-markup-command (markletter layout props num)
2142 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2143 (skipping letter@tie{}I), and continue with double letters.
2145 @lilypond[verbatim,quote]
2152 (ly:text-interface::interpret-markup layout props
2153 (number->markletter-string number->mark-letter-vector num)))
2155 (define-builtin-markup-command (markalphabet layout props num)
2159 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2160 and continue with double letters.
2162 @lilypond[verbatim,quote]
2169 (ly:text-interface::interpret-markup layout props
2170 (number->markletter-string number->mark-alphabet-vector num)))
2172 (define-public (horizontal-slash-interval num forward number-interval mag)
2173 (ly:message "Mag step: ~a" mag)
2175 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2176 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2177 (else (interval-widen number-interval (* mag 0.25))))
2178 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2179 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2180 (else (interval-widen number-interval (* mag 0.25))))
2183 (define-public (adjust-slash-stencil num forward stencil mag)
2186 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2188 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2190 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2192 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2195 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2197 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2202 (define (slashed-digit-internal layout props num forward font-size thickness)
2203 (let* ((mag (magstep font-size))
2205 (ly:output-def-lookup layout 'line-thickness)
2207 ; backward slashes might use slope and point in the other direction!
2208 (dy (* mag (if forward 0.4 -0.4)))
2209 (number-stencil (interpret-markup layout
2210 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2211 (number->string num)))
2212 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2213 (center (interval-center (ly:stencil-extent number-stencil Y)))
2214 ; Use the real extents of the slash, not the whole number, because we
2215 ; might translate the slash later on!
2216 (num-y (interval-widen (cons center center) (abs dy)))
2217 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2218 (slash-stencil (if is-sane
2220 `(draw-line ,thickness
2221 ,(car num-x) ,(- (interval-center num-y) dy)
2222 ,(cdr num-x) ,(+ (interval-center num-y) dy))
2225 (ly:message "Num: ~a, X-interval: ~a" num num-x)
2226 (if (ly:stencil? slash-stencil)
2228 ; for some numbers we need to shift the slash/backslash up or down to make
2229 ; the slashed digit look better
2230 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2231 (set! number-stencil
2232 (ly:stencil-add number-stencil slash-stencil)))
2233 (ly:warning "Unable to create slashed digit ~a" num))
2237 (define-builtin-markup-command (slashed-digit layout props num)
2243 @cindex slashed digits
2245 A feta number, with slash. This is for use in the context of
2246 figured bass notation.
2247 @lilypond[verbatim,quote]
2251 \\override #'(thickness . 3)
2255 (slashed-digit-internal layout props num #t font-size thickness))
2257 (define-builtin-markup-command (backslashed-digit layout props num)
2263 @cindex backslashed digits
2265 A feta number, with backslash. This is for use in the context of
2266 figured bass notation.
2267 @lilypond[verbatim,quote]
2269 \\backslashed-digit #5
2271 \\override #'(thickness . 3)
2272 \\backslashed-digit #7
2275 (slashed-digit-internal layout props num #f font-size thickness))
2277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2278 ;; the note command.
2279 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2281 ;; TODO: better syntax.
2283 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2284 (number? number? number?)
2289 @cindex notes within text by log and dot-count
2291 Construct a note symbol, with stem. By using fractional values for
2292 @var{dir}, you can obtain longer or shorter stems.
2294 @lilypond[verbatim,quote]
2296 \\note-by-number #3 #0 #DOWN
2298 \\note-by-number #1 #2 #0.8
2301 (define (get-glyph-name-candidates dir log style)
2302 (map (lambda (dir-name)
2303 (format "noteheads.~a~a~a" dir-name (min log 2)
2304 (if (and (symbol? style)
2305 (not (equal? 'default style)))
2306 (symbol->string style)
2308 (list (if (= dir UP) "u" "d")
2311 (define (get-glyph-name font cands)
2314 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2315 (get-glyph-name font (cdr cands))
2318 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2319 (size-factor (magstep font-size))
2320 (stem-length (* size-factor (max 3 (- log 1))))
2321 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2322 (head-glyph (ly:font-get-glyph font head-glyph-name))
2323 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2324 (stem-thickness (* size-factor 0.13))
2325 (stemy (* dir stem-length))
2326 (attach-off (cons (interval-index
2327 (ly:stencil-extent head-glyph X)
2328 (* (sign dir) (car attach-indices)))
2329 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2331 (ly:stencil-extent head-glyph Y)
2332 (cdr attach-indices)))))
2333 (stem-glyph (and (> log 0)
2334 (ly:round-filled-box
2335 (ordered-cons (car attach-off)
2336 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2337 (cons (min stemy (cdr attach-off))
2338 (max stemy (cdr attach-off)))
2339 (/ stem-thickness 3))))
2341 (dot (ly:font-get-glyph font "dots.dot"))
2342 (dotwid (interval-length (ly:stencil-extent dot X)))
2343 (dots (and (> dot-count 0)
2344 (apply ly:stencil-add
2346 (ly:stencil-translate-axis
2347 dot (* 2 x dotwid) X))
2348 (iota dot-count)))))
2349 (flaggl (and (> log 2)
2350 (ly:stencil-translate
2351 (ly:font-get-glyph font
2352 (string-append "flags."
2353 (if (> dir 0) "u" "d")
2354 (number->string log)))
2355 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2357 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2358 ; 16th notes get a special case because their flags hang lower than any other flags.
2359 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2360 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2362 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2363 (if (ly:stencil? stem-glyph)
2364 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2365 (set! stem-glyph head-glyph))
2366 (if (ly:stencil? dots)
2369 (ly:stencil-translate-axis
2371 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2377 (let ((divisor (log 2)))
2378 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2380 (define (parse-simple-duration duration-string)
2381 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2382 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2383 (if (and match (string=? duration-string (match:substring match 0)))
2384 (let ((len (match:substring match 1))
2385 (dots (match:substring match 2)))
2386 (list (cond ((string=? len "breve") -1)
2387 ((string=? len "longa") -2)
2388 ((string=? len "maxima") -3)
2389 (else (log2 (string->number len))))
2390 (if dots (string-length dots) 0)))
2391 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2393 (define-builtin-markup-command (note layout props duration dir)
2396 (note-by-number-markup)
2398 @cindex notes within text by string
2400 This produces a note with a stem pointing in @var{dir} direction, with
2401 the @var{duration} for the note head type and augmentation dots. For
2402 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2403 a shortened down stem.
2405 @lilypond[verbatim,quote]
2407 \\override #'(style . cross) {
2411 \\note #\"breve\" #0
2414 (let ((parsed (parse-simple-duration duration)))
2415 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2417 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2419 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2421 (define-builtin-markup-command (lower layout props amount arg)
2426 @cindex lowering text
2428 Lower @var{arg} by the distance @var{amount}.
2429 A negative @var{amount} indicates raising; see also @code{\\raise}."
2430 (ly:stencil-translate-axis (interpret-markup layout props arg)
2433 (define-builtin-markup-command (translate-scaled layout props offset arg)
2434 (number-pair? markup?)
2438 @cindex translating text
2439 @cindex scaling text
2441 Translate @var{arg} by @var{offset}, scaling the offset by the
2443 (let* ((factor (magstep font-size))
2444 (scaled (cons (* factor (car offset))
2445 (* factor (cdr offset)))))
2446 (ly:stencil-translate (interpret-markup layout props arg)
2449 (define-builtin-markup-command (raise layout props amount arg)
2454 @cindex raising text
2456 Raise @var{arg} by the distance @var{amount}.
2457 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2459 The argument to @code{\\raise} is the vertical displacement amount,
2460 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2461 raise objects in relation to their surrounding markups.
2463 If the text object itself is positioned above or below the staff, then
2464 @code{\\raise} cannot be used to move it, since the mechanism that
2465 positions it next to the staff cancels any shift made with
2466 @code{\\raise}. For vertical positioning, use the @code{padding}
2467 and/or @code{extra-offset} properties.
2469 @lilypond[verbatim,quote]
2478 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2480 (define-builtin-markup-command (fraction layout props arg1 arg2)
2485 @cindex creating text fractions
2487 Make a fraction of two markups.
2488 @lilypond[verbatim,quote]
2494 (let* ((m1 (interpret-markup layout props arg1))
2495 (m2 (interpret-markup layout props arg2))
2496 (factor (magstep font-size))
2497 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2498 (padding (* factor 0.2))
2499 (baseline (* factor 0.6))
2500 (offset (* factor 0.75)))
2501 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2502 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2503 (let* ((x1 (ly:stencil-extent m1 X))
2504 (x2 (ly:stencil-extent m2 X))
2505 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2506 ;; should stack mols separately, to maintain LINE on baseline
2507 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2509 (ly:stencil-aligned-to stack Y CENTER))
2511 (ly:stencil-aligned-to stack X LEFT))
2512 ;; should have EX dimension
2514 (ly:stencil-translate-axis stack offset Y))))
2516 (define-builtin-markup-command (normal-size-super layout props arg)
2521 @cindex setting superscript in standard font size
2523 Set @var{arg} in superscript with a normal font size.
2525 @lilypond[verbatim,quote]
2528 \\normal-size-super {
2529 superscript in standard size
2533 (ly:stencil-translate-axis
2534 (interpret-markup layout props arg)
2535 (* 0.5 baseline-skip) Y))
2537 (define-builtin-markup-command (super layout props arg)
2543 @cindex superscript text
2545 Raising and lowering texts can be done with @code{\\super} and
2548 @lilypond[verbatim,quote]
2558 (ly:stencil-translate-axis
2561 (cons `((font-size . ,(- font-size 3))) props)
2563 (* 0.5 baseline-skip)
2566 (define-builtin-markup-command (translate layout props offset arg)
2567 (number-pair? markup?)
2571 @cindex translating text
2573 This translates an object. Its first argument is a cons of numbers.
2576 A \\translate #(cons 2 -3) @{ B C @} D
2579 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2580 surroundings. This command cannot be used to move isolated scripts
2581 vertically, for the same reason that @code{\\raise} cannot be used for
2583 (ly:stencil-translate (interpret-markup layout props arg)
2586 (define-builtin-markup-command (sub layout props arg)
2592 @cindex subscript text
2594 Set @var{arg} in subscript.
2596 @lilypond[verbatim,quote]
2607 (ly:stencil-translate-axis
2610 (cons `((font-size . ,(- font-size 3))) props)
2612 (* -0.5 baseline-skip)
2615 (define-builtin-markup-command (normal-size-sub layout props arg)
2620 @cindex setting subscript in standard font size
2622 Set @var{arg} in subscript, in a normal font size.
2624 @lilypond[verbatim,quote]
2628 subscript in standard size
2632 (ly:stencil-translate-axis
2633 (interpret-markup layout props arg)
2634 (* -0.5 baseline-skip)
2637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2641 (define-builtin-markup-command (hbracket layout props arg)
2646 @cindex placing horizontal brackets around text
2648 Draw horizontal brackets around @var{arg}.
2650 @lilypond[verbatim,quote]
2659 (let ((th 0.1) ;; todo: take from GROB.
2660 (m (interpret-markup layout props arg)))
2661 (bracketify-stencil m X th (* 2.5 th) th)))
2663 (define-builtin-markup-command (bracket layout props arg)
2668 @cindex placing vertical brackets around text
2670 Draw vertical brackets around @var{arg}.
2672 @lilypond[verbatim,quote]
2679 (let ((th 0.1) ;; todo: take from GROB.
2680 (m (interpret-markup layout props arg)))
2681 (bracketify-stencil m Y th (* 2.5 th) th)))
2683 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2684 ;; Delayed markup evaluation
2685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2687 (define-builtin-markup-command (page-ref layout props label gauge default)
2688 (symbol? markup? markup?)
2692 @cindex referencing page numbers in text
2694 Reference to a page number. @var{label} is the label set on the referenced
2695 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
2696 the maximum width of the page number, and @var{default} the value to display
2697 when @var{label} is not found."
2698 (let* ((gauge-stencil (interpret-markup layout props gauge))
2699 (x-ext (ly:stencil-extent gauge-stencil X))
2700 (y-ext (ly:stencil-extent gauge-stencil Y)))
2702 `(delay-stencil-evaluation
2703 ,(delay (ly:stencil-expr
2704 (let* ((table (ly:output-def-lookup layout 'label-page-table))
2705 (label-page (and (list? table) (assoc label table)))
2706 (page-number (and label-page (cdr label-page)))
2707 (page-markup (if page-number (format "~a" page-number) default))
2708 (page-stencil (interpret-markup layout props page-markup))
2709 (gap (- (interval-length x-ext)
2710 (interval-length (ly:stencil-extent page-stencil X)))))
2711 (interpret-markup layout props
2712 (markup #:concat (#:hspace gap page-markup)))))))
2716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2717 ;; Markup list commands
2718 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2720 (define-public (space-lines baseline stils)
2721 (let space-stil ((prev-stil #f)
2724 (cond ((null? stils)
2727 (space-stil (car stils) (cdr stils) (list (car stils))))
2729 (let* ((stil (car stils))
2730 (dy (max (- baseline
2731 (+ (- (interval-bound (ly:stencil-extent prev-stil Y) DOWN))
2732 (interval-bound (ly:stencil-extent stil Y) UP)))
2734 (new-stil (ly:make-stencil
2735 (ly:stencil-expr stil)
2736 (ly:stencil-extent stil X)
2737 (cons (interval-bound (ly:stencil-extent stil Y) DOWN)
2738 (+ (interval-bound (ly:stencil-extent stil Y) UP) dy)))))
2739 (space-stil stil (cdr stils) (cons new-stil result)))))))
2741 (define-builtin-markup-list-command (justified-lines layout props args)
2744 wordwrap-internal-markup-list)
2746 @cindex justifying lines of text
2748 Like @code{\\justify}, but return a list of lines instead of a single markup.
2749 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
2750 @var{X}@tie{}is the number of staff spaces."
2751 (space-lines baseline-skip
2752 (interpret-markup-list layout props
2753 (make-wordwrap-internal-markup-list #t args))))
2755 (define-builtin-markup-list-command (wordwrap-lines layout props args)
2758 wordwrap-internal-markup-list)
2759 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
2760 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
2761 where @var{X} is the number of staff spaces."
2762 (space-lines baseline-skip
2763 (interpret-markup-list layout props
2764 (make-wordwrap-internal-markup-list #f args))))
2766 (define-builtin-markup-list-command (column-lines layout props args)
2769 "Like @code{\\column}, but return a list of lines instead of a single markup.
2770 @code{baseline-skip} determines the space between each markup in @var{args}."
2771 (space-lines (chain-assoc-get 'baseline-skip props)
2772 (interpret-markup-list layout props args)))
2774 (define-builtin-markup-list-command (override-lines layout props new-prop args)
2775 (pair? markup-list?)
2777 "Like @code{\\override}, for markup lists."
2778 (interpret-markup-list layout (cons (list new-prop) props) args))