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 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
43 (cons (min x 0) (max x 0))
44 (cons (min y 0) (max y 0)))))
46 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
47 (number? number? boolean?)
51 @cindex drawing circles within text
53 A circle of radius @var{radius}, thickness @var{thickness} and
56 @lilypond[verbatim,quote]
57 \\markup { \\draw-circle #2 #0.5 ##f \\hspace #2 \\draw-circle #2 #0 ##t }
59 (make-circle-stencil radius thickness fill))
61 (define-builtin-markup-command (triangle layout props filled)
68 @cindex drawing triangles within text
70 A triangle, either filled or empty.
72 @lilypond[verbatim,quote]
73 \\markup { \\triangle ##t \\hspace #2 \\triangle ##f }
75 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
84 (cons 0 (* .86 ex)))))
86 (define-builtin-markup-command (circle layout props arg)
95 Draw a circle around @var{arg}. Use @code{thickness},
96 @code{circle-padding} and @code{font-size} properties to determine line
97 thickness and padding around the markup."
98 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
100 (pad (* (magstep font-size) circle-padding))
101 (m (interpret-markup layout props arg)))
102 (circle-stencil m th pad)))
104 (define-builtin-markup-command (with-url layout props url arg)
109 @cindex inserting URL links into text
111 Add a link to URL @var{url} around @var{arg}. This only works in
114 @lilypond[verbatim,quote]
116 \\with-url #\"http://lilypond.org/web/\" {
117 LilyPond ... \\italic { music notation for everyone }
121 (let* ((stil (interpret-markup layout props arg))
122 (xextent (ly:stencil-extent stil X))
123 (yextent (ly:stencil-extent stil Y))
124 (old-expr (ly:stencil-expr stil))
125 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
127 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
129 (define-builtin-markup-command (beam layout props width slope thickness)
130 (number? number? number?)
134 @cindex drawing beams within text
136 Create a beam with the specified parameters."
137 (let* ((y (* slope width))
138 (yext (cons (min 0 y) (max 0 y)))
139 (half (/ thickness 2)))
144 width (+ (* width slope) (/ thickness -2))
145 width (+ (* width slope) (/ thickness 2))
147 ,(ly:output-def-lookup layout 'blot-diameter)
150 (cons (+ (- half) (car yext))
151 (+ half (cdr yext))))))
153 (define-builtin-markup-command (underline layout props arg)
158 @cindex underlining text
160 Underline @var{arg}. Looks at @code{thickness} to determine line
161 thickness and y offset."
162 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
164 (markup (interpret-markup layout props arg))
165 (x1 (car (ly:stencil-extent markup X)))
166 (x2 (cdr (ly:stencil-extent markup X)))
168 (line (ly:make-stencil
169 `(draw-line ,thick ,x1 ,y ,x2 ,y)
170 (cons (min x1 0) (max x2 0))
171 (cons thick thick))))
172 (ly:stencil-add markup line)))
174 (define-builtin-markup-command (box layout props arg)
181 @cindex enclosing text within a box
183 Draw a box round @var{arg}. Looks at @code{thickness},
184 @code{box-padding} and @code{font-size} properties to determine line
185 thickness and padding around the markup."
186 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
188 (pad (* (magstep font-size) box-padding))
189 (m (interpret-markup layout props arg)))
190 (box-stencil m th pad)))
192 (define-builtin-markup-command (filled-box layout props xext yext blot)
193 (number-pair? number-pair? number?)
197 @cindex drawing solid boxes within text
198 @cindex drawing boxes with rounded corners
200 Draw a box with rounded corners of dimensions @var{xext} and
201 @var{yext}. For example,
203 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
205 creates a box extending horizontally from -0.3 to 1.8 and
206 vertically from -0.3 up to 1.8, with corners formed from a
207 circle of diameter@tie{}0 (i.e. sharp corners).
209 @lilypond[verbatim,quote]
211 \\filled-box #'(0 . 4) #'(0 . 4) #0
212 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
213 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
214 \\with-color #white \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
220 (define-builtin-markup-command (rounded-box layout props arg)
227 "@cindex enclosing text in a bow with rounded corners
228 @cindex drawing boxes with rounded corners around text
229 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
230 @code{box-padding} and @code{font-size} properties to determine line
231 thickness and padding around the markup; the @code{corner-radius} property
232 makes possible to define another shape for the corners (default is 1).
234 @lilypond[quote,verbatim,fragment,relative=2]
235 c^\\markup{ \\rounded-box Overtura }
238 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
240 (pad (* (magstep font-size) box-padding))
241 (m (interpret-markup layout props arg)))
242 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
245 (define-builtin-markup-command (rotate layout props ang arg)
250 @cindex rotating text
252 Rotate object with @var{ang} degrees around its center."
253 (let* ((stil (interpret-markup layout props arg)))
254 (ly:stencil-rotate stil ang 0 0)))
256 (define-builtin-markup-command (whiteout layout props arg)
261 @cindex adding a white background to text
263 Provide a white background for @var{arg}."
264 (stencil-whiteout (interpret-markup layout props arg)))
266 (define-builtin-markup-command (pad-markup layout props padding arg)
272 @cindex putting space around text
274 Add space around a markup object."
276 ((stil (interpret-markup layout props arg))
277 (xext (ly:stencil-extent stil X))
278 (yext (ly:stencil-extent stil Y)))
281 (ly:stencil-expr stil)
282 (interval-widen xext padding)
283 (interval-widen yext padding))))
285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
289 (define-builtin-markup-command (strut layout props)
294 @cindex creating vertical spaces in text
296 Create a box of the same height as the space in the current font."
297 (let ((m (ly:text-interface::interpret-markup layout props " ")))
298 (ly:make-stencil (ly:stencil-expr m)
300 (ly:stencil-extent m X)
303 ;; todo: fix negative space
304 (define-builtin-markup-command (hspace layout props amount)
309 @cindex creating horizontal spaces in text
311 This produces a invisible object taking horizontal space. For example,
314 \\markup @{ A \\hspace #2.0 B @}
318 puts extra space between A and@tie{}B, on top of the space that is
319 normally inserted before elements on a line."
321 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
322 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
326 ;; importing graphics.
327 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
329 (define-builtin-markup-command (stencil layout props stil)
334 @cindex importing stencils into text
336 Use a stencil as markup."
340 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
342 (define (get-postscript-bbox string)
343 "Extract the bbox from STRING, or return #f if not present."
345 ((match (regexp-exec bbox-regexp string)))
349 (string->number (match:substring match x)))
354 (define-builtin-markup-command (epsfile layout props axis size file-name)
355 (number? number? string?)
359 @cindex inlining an Encapsulated PostScript image
361 Inline an EPS image. The image is scaled along @var{axis} to
364 @lilypond[verbatim,quote]
366 \\general-align #Y #DOWN {
367 \\epsfile #X #20 #\"context-example.eps\"
368 \\epsfile #Y #20 #\"context-example.eps\"
372 (if (ly:get-option 'safe)
373 (interpret-markup layout props "not allowed in safe")
374 (eps-file->stencil axis size file-name)
377 (define-builtin-markup-command (postscript layout props str)
382 @cindex inserting PostScript directly into text
384 This inserts @var{str} directly into the output as a PostScript
385 command string. Due to technicalities of the output backends,
386 different scales should be used for the @TeX{} and PostScript backend,
387 selected with @code{-f}.
389 For the @TeX{} backend, the following string prints a rotated text
392 0 0 moveto /ecrm10 findfont
393 1.75 scalefont setfont 90 rotate (hello) show
397 The magical constant 1.75 scales from LilyPond units (staff spaces) to
400 For the postscript backend, use the following
403 gsave /ecrm10 findfont
404 10.0 output-scale div
405 scalefont setfont 90 rotate (hello) show grestore
408 @lilypond[verbatim,quote]
414 0.7 0.7 0.5 0 361 arc
416 2.20 0.70 0.50 0 361 arc
418 1.45 0.85 0.30 0 180 arc
422 0.92 2.26 1.30 2.40 1.15 1.70 curveto
426 3.42 2.26 3.80 2.40 3.65 1.70 curveto
429 eyeglasses = \\markup {
430 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
431 \\postscript #eyeglassesps
434 \\relative c'' { c2^\\eyeglasses a_\\eyeglasses }
440 gsave currentpoint translate
448 (define-builtin-markup-command (score layout props score)
453 @cindex inserting music into text
455 Inline an image of music.
457 @lilypond[verbatim,quote]
461 \\new Staff \\relative c' {
464 \\mark \\markup { Allegro }
470 \\new Staff \\relative c {
484 \\override RehearsalMark #'break-align-symbols =
485 #'(time-signature key-signature)
486 \\override RehearsalMark #'self-alignment-X = #LEFT
490 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
496 (let* ((output (ly:score-embedded-format score layout)))
498 (if (ly:music-output? output)
499 (paper-system-stencil
500 (vector-ref (ly:paper-score-paper-systems output) 0))
502 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
505 (define-builtin-markup-command (null layout props)
510 @cindex creating empty text objects
512 An empty markup with extents of a single point."
515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
517 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
519 (define-builtin-markup-command (simple layout props str)
524 @cindex simple text strings
526 A simple text string; @code{\\markup @{ foo @}} is equivalent with
527 @code{\\markup @{ \\simple #\"foo\" @}}."
528 (interpret-markup layout props str))
530 (define-builtin-markup-command (tied-lyric layout props str)
535 @cindex simple text strings with tie characters
537 Like simple-markup, but use tie characters for @q{~} tilde symbols."
538 (if (string-contains str "~")
540 ((parts (string-split str #\~))
541 (tie-str (ly:wide-char->utf-8 #x203f))
542 (joined (list-join parts tie-str))
543 (join-stencil (interpret-markup layout props tie-str))
546 (interpret-markup layout
549 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
551 (make-line-markup joined)))
552 ;(map (lambda (s) (interpret-markup layout props s)) parts))
553 (interpret-markup layout props str)))
555 (define-public empty-markup
556 (make-simple-markup ""))
558 ;; helper for justifying lines.
559 (define (get-fill-space word-count line-width text-widths)
560 "Calculate the necessary paddings between each two adjacent texts.
561 The lengths of all texts are stored in @var{text-widths}.
562 The normal formula for the padding between texts a and b is:
563 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
564 The first and last padding have to be calculated specially using the
565 whole length of the first or last text.
566 Return a list of paddings."
568 ((null? text-widths) '())
570 ;; special case first padding
571 ((= (length text-widths) word-count)
573 (- (- (/ line-width (1- word-count)) (car text-widths))
574 (/ (car (cdr text-widths)) 2))
575 (get-fill-space word-count line-width (cdr text-widths))))
576 ;; special case last padding
577 ((= (length text-widths) 2)
578 (list (- (/ line-width (1- word-count))
579 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
582 (- (/ line-width (1- word-count))
583 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
584 (get-fill-space word-count line-width (cdr text-widths))))))
586 (define-builtin-markup-command (fill-line layout props markups)
589 ((text-direction RIGHT)
592 "Put @var{markups} in a horizontal line of width @var{line-width}.
593 The markups are spaced or flushed to fill the entire line.
594 If there are no arguments, return an empty stencil."
596 (let* ((orig-stencils (interpret-markup-list layout props markups))
599 (if (ly:stencil-empty? stc)
601 stc)) orig-stencils))
604 (if (ly:stencil-empty? stc)
606 (interval-length (ly:stencil-extent stc X))))
608 (text-width (apply + text-widths))
609 (word-count (length stencils))
610 (prop-line-width (chain-assoc-get 'line-width props #f))
611 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
616 (/ (- line-width text-width) 2)
617 (/ (- line-width text-width) 2)))
620 (- line-width text-width)))
622 (get-fill-space word-count line-width text-widths))))
630 (line-stencils (if (= word-count 1)
637 (if (= text-direction LEFT)
638 (set! line-stencils (reverse line-stencils)))
640 (if (null? (remove ly:stencil-empty? orig-stencils))
642 (stack-stencils-padding-list X
643 RIGHT fill-space-normal line-stencils))))
645 (define-builtin-markup-command (line layout props args)
649 (text-direction RIGHT))
650 "Put @var{args} in a horizontal line. The property @code{word-space}
651 determines the space between each markup in @var{args}."
652 (let ((stencils (interpret-markup-list layout props args)))
653 (if (= text-direction LEFT)
654 (set! stencils (reverse stencils)))
657 (remove ly:stencil-empty? stencils))))
659 (define-builtin-markup-command (concat layout props args)
664 @cindex concatenating text
665 @cindex ligatures in text
667 Concatenate @var{args} in a horizontal line, without spaces inbetween.
668 Strings and simple markups are concatenated on the input level, allowing
669 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
670 equivalent to @code{\"fi\"}."
671 (define (concat-string-args arg-list)
672 (fold-right (lambda (arg result-list)
673 (let ((result (if (pair? result-list)
676 (if (and (pair? arg) (eqv? (car arg) simple-markup))
677 (set! arg (cadr arg)))
678 (if (and (string? result) (string? arg))
679 (cons (string-append arg result) (cdr result-list))
680 (cons arg result-list))))
684 (interpret-markup layout
685 (prepend-alist-chain 'word-space 0 props)
686 (make-line-markup (if (markup-command-list? args)
688 (concat-string-args args)))))
690 (define (wordwrap-stencils stencils
691 justify base-space line-width text-dir)
692 "Perform simple wordwrap, return stencil of each line."
693 (define space (if justify
694 ;; justify only stretches lines.
697 (define (take-list width space stencils
698 accumulator accumulated-width)
699 "Return (head-list . tail) pair, with head-list fitting into width"
701 (cons accumulator stencils)
702 (let* ((first (car stencils))
703 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
704 (newwid (+ space first-wid accumulated-width)))
705 (if (or (null? accumulator)
707 (take-list width space
709 (cons first accumulator)
711 (cons accumulator stencils)))))
712 (let loop ((lines '())
714 (let* ((line-break (take-list line-width space todo
716 (line-stencils (car line-break))
717 (space-left (- line-width
718 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
720 (line-word-space (cond ((not justify) space)
721 ;; don't stretch last line of paragraph.
722 ;; hmmm . bug - will overstretch the last line in some case.
723 ((null? (cdr line-break))
725 ((null? line-stencils) 0.0)
726 ((null? (cdr line-stencils)) 0.0)
727 (else (/ space-left (1- (length line-stencils))))))
728 (line (stack-stencil-line line-word-space
729 (if (= text-dir RIGHT)
730 (reverse line-stencils)
732 (if (pair? (cdr line-break))
733 (loop (cons line lines)
736 (if (= text-dir LEFT)
738 (ly:stencil-translate-axis
740 (- line-width (interval-end (ly:stencil-extent line X)))
742 (reverse (cons line lines)))))))
744 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
745 (boolean? markup-list?)
748 (text-direction RIGHT))
749 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
750 (wordwrap-stencils (remove ly:stencil-empty?
751 (interpret-markup-list layout props args))
755 (ly:output-def-lookup layout 'line-width))
758 (define-builtin-markup-command (justify layout props args)
762 wordwrap-internal-markup-list)
764 @cindex justifying text
766 Like wordwrap, but with lines stretched to justify the margins.
767 Use @code{\\override #'(line-width . @var{X})} to set the line width;
768 @var{X}@tie{}is the number of staff spaces."
769 (stack-lines DOWN 0.0 baseline-skip
770 (wordwrap-internal-markup-list layout props #t args)))
772 (define-builtin-markup-command (wordwrap layout props args)
776 wordwrap-internal-markup-list)
777 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
778 the line width, where @var{X} is the number of staff spaces."
779 (stack-lines DOWN 0.0 baseline-skip
780 (wordwrap-internal-markup-list layout props #f args)))
782 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
786 (text-direction RIGHT))
787 "Internal markup list command used to define @code{\\justify-string} and
788 @code{\\wordwrap-string}."
789 (let* ((para-strings (regexp-split
790 (string-regexp-substitute
792 (string-regexp-substitute "\r\n" "\n" arg))
793 "\n[ \t\n]*\n[ \t\n]*"))
794 (list-para-words (map (lambda (str)
795 (regexp-split str "[ \t\n]+"))
797 (para-lines (map (lambda (words)
799 (remove ly:stencil-empty?
801 (interpret-markup layout props x))
803 (wordwrap-stencils stencils
805 line-width text-direction)))
807 (apply append para-lines)))
809 (define-builtin-markup-command (wordwrap-string layout props arg)
813 wordwrap-string-internal-markup-list)
814 "Wordwrap a string. Paragraphs may be separated with double newlines."
815 (stack-lines DOWN 0.0 baseline-skip
816 (wordwrap-string-internal-markup-list layout props #f arg)))
818 (define-builtin-markup-command (justify-string layout props arg)
822 wordwrap-string-internal-markup-list)
823 "Justify a string. Paragraphs may be separated with double newlines"
824 (stack-lines DOWN 0.0 baseline-skip
825 (wordwrap-string-internal-markup-list layout props #t arg)))
827 (define-builtin-markup-command (wordwrap-field layout props symbol)
831 "Wordwrap the data which has been assigned to @var{symbol}."
832 (let* ((m (chain-assoc-get symbol props)))
834 (wordwrap-string-markup layout props m)
837 (define-builtin-markup-command (justify-field layout props symbol)
841 "Justify the data which has been assigned to @var{symbol}."
842 (let* ((m (chain-assoc-get symbol props)))
844 (justify-string-markup layout props m)
847 (define-builtin-markup-command (combine layout props m1 m2)
854 Print two markups on top of each other.
855 @lilypond[verbatim,quote]
858 \\override #'(thickness . 2)
859 \\combine \\draw-line #'(0 . 4) \\arrow-head #Y #DOWN ##f
862 (let* ((s1 (interpret-markup layout props m1))
863 (s2 (interpret-markup layout props m2)))
864 (ly:stencil-add s1 s2)))
867 ;; TODO: should extract baseline-skip from each argument somehow..
869 (define-builtin-markup-command (column layout props args)
874 @cindex stacking text in a column
876 Stack the markups in @var{args} vertically. The property
877 @code{baseline-skip} determines the space between each markup in @var{args}."
878 (let ((arg-stencils (interpret-markup-list layout props args)))
879 (stack-lines -1 0.0 baseline-skip
880 (remove ly:stencil-empty? arg-stencils))))
882 (define-builtin-markup-command (dir-column layout props args)
888 @cindex changing direction of text columns
890 Make a column of args, going up or down, depending on the setting
891 of the @code{#'direction} layout property."
892 (stack-lines (if (number? direction) direction -1)
895 (interpret-markup-list layout props args)))
897 (define-builtin-markup-command (center-align layout props args)
902 @cindex centering a column of text
904 Put @code{args} in a centered column."
905 (let* ((mols (interpret-markup-list layout props args))
906 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
907 (stack-lines -1 0.0 baseline-skip cmols)))
909 (define-builtin-markup-command (vcenter layout props arg)
914 @cindex vertically centering text
916 Align @code{arg} to its Y@tie{}center."
917 (let* ((mol (interpret-markup layout props arg)))
918 (ly:stencil-aligned-to mol Y CENTER)))
920 (define-builtin-markup-command (hcenter layout props arg)
925 @cindex horizontally centering text
927 Align @code{arg} to its X@tie{}center."
928 (let* ((mol (interpret-markup layout props arg)))
929 (ly:stencil-aligned-to mol X CENTER)))
931 (define-builtin-markup-command (right-align layout props arg)
936 @cindex right aligning text
938 Align @var{arg} on its right edge."
939 (let* ((m (interpret-markup layout props arg)))
940 (ly:stencil-aligned-to m X RIGHT)))
942 (define-builtin-markup-command (left-align layout props arg)
947 @cindex left aligning text
949 Align @var{arg} on its left edge."
950 (let* ((m (interpret-markup layout props arg)))
951 (ly:stencil-aligned-to m X LEFT)))
953 (define-builtin-markup-command (general-align layout props axis dir arg)
954 (integer? number? markup?)
958 @cindex controlling general text alignment
960 Align @var{arg} in @var{axis} direction to the @var{dir} side."
961 (let* ((m (interpret-markup layout props arg)))
962 (ly:stencil-aligned-to m axis dir)))
964 (define-builtin-markup-command (halign layout props dir arg)
969 @cindex setting horizontal text alignment
971 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
972 left-aligned, while @code{+1} is right. Values inbetween interpolate
973 alignment accordingly."
974 (let* ((m (interpret-markup layout props arg)))
975 (ly:stencil-aligned-to m X dir)))
977 (define-builtin-markup-command (with-dimensions layout props x y arg)
978 (number-pair? number-pair? markup?)
982 @cindex setting extent of text objects
984 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
985 (let* ((m (interpret-markup layout props arg)))
986 (ly:make-stencil (ly:stencil-expr m) x y)))
988 (define-builtin-markup-command (pad-around layout props amount arg)
992 "Add padding @var{amount} all around @var{arg}."
993 (let* ((m (interpret-markup layout props arg))
994 (x (ly:stencil-extent m X))
995 (y (ly:stencil-extent m Y)))
996 (ly:make-stencil (ly:stencil-expr m)
997 (interval-widen x amount)
998 (interval-widen y amount))))
1000 (define-builtin-markup-command (pad-x layout props amount arg)
1005 @cindex padding text horizontally
1007 Add padding @var{amount} around @var{arg} in the X@tie{}direction."
1008 (let* ((m (interpret-markup layout props arg))
1009 (x (ly:stencil-extent m X))
1010 (y (ly:stencil-extent m Y)))
1011 (ly:make-stencil (ly:stencil-expr m)
1012 (interval-widen x amount)
1015 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2)
1016 (markup? integer? ly:dir? markup?)
1019 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1020 (let ((m1 (interpret-markup layout props arg1))
1021 (m2 (interpret-markup layout props arg2)))
1022 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1024 (define-builtin-markup-command (transparent layout props arg)
1028 "Make the argument transparent."
1029 (let* ((m (interpret-markup layout props arg))
1030 (x (ly:stencil-extent m X))
1031 (y (ly:stencil-extent m Y)))
1032 (ly:make-stencil "" x y)))
1034 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1035 (number-pair? number-pair? markup?)
1038 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
1039 (let* ((m (interpret-markup layout props arg))
1040 (x (ly:stencil-extent m X))
1041 (y (ly:stencil-extent m Y)))
1042 (ly:make-stencil (ly:stencil-expr m)
1043 (interval-union x-ext x)
1044 (interval-union y-ext y))))
1046 (define-builtin-markup-command (hcenter-in layout props length arg)
1050 "Center @var{arg} horizontally within a box of extending
1051 @var{length}/2 to the left and right."
1052 (interpret-markup layout props
1053 (make-pad-to-box-markup
1054 (cons (/ length -2) (/ length 2))
1056 (make-hcenter-markup arg))))
1058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1060 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1062 (define-builtin-markup-command (fromproperty layout props symbol)
1066 "Read the @var{symbol} from property settings, and produce a stencil
1067 from the markup contained within. If @var{symbol} is not defined, it
1068 returns an empty markup."
1069 (let ((m (chain-assoc-get symbol props)))
1071 (interpret-markup layout props m)
1074 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1078 "Apply the @var{procedure} markup command to @var{arg}.
1079 @var{procedure} should take a single argument."
1080 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1081 (set-object-property! anonymous-with-signature
1084 (interpret-markup layout props (list anonymous-with-signature arg))))
1086 (define-builtin-markup-command (override layout props new-prop arg)
1091 @cindex overriding properties within text markup
1093 Add the first argument in to the property list. Properties may be
1094 any sort of property supported by @rinternals{font-interface} and
1095 @rinternals{text-interface}, for example
1098 \\override #'(font-family . married) \"bla\"
1100 (interpret-markup layout (cons (list new-prop) props) arg))
1102 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1104 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1106 (define-builtin-markup-command (verbatim-file layout props name)
1110 "Read the contents of a file, and include it verbatim.
1112 @lilypond[verbatim,quote]
1113 \\markup \\verbatim-file #\"simple.ly\"
1115 (interpret-markup layout props
1116 (if (ly:get-option 'safe)
1117 "verbatim-file disabled in safe mode"
1118 (let* ((str (ly:gulp-file name))
1119 (lines (string-split str #\nl)))
1120 (make-typewriter-markup
1121 (make-column-markup lines))))))
1123 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1127 (define-builtin-markup-command (bigger layout props arg)
1131 "Increase the font size relative to current setting."
1132 (interpret-markup layout props
1133 `(,fontsize-markup 1 ,arg)))
1135 (define-builtin-markup-command (smaller layout props arg)
1139 "Decrease the font size relative to current setting."
1140 (interpret-markup layout props
1141 `(,fontsize-markup -1 ,arg)))
1143 (define-builtin-markup-command larger
1148 (define-builtin-markup-command (finger layout props arg)
1152 "Set the argument as small numbers.
1153 @lilypond[verbatim,quote]
1154 \\markup \\finger { 1 2 3 4 5 }
1156 (interpret-markup layout
1157 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1160 (define-builtin-markup-command (fontsize layout props increment arg)
1166 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
1167 (let ((entries (list
1168 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1169 (cons 'word-space (* word-space (magstep increment)))
1170 (cons 'font-size (+ font-size increment)))))
1171 (interpret-markup layout (cons entries props) arg)))
1173 (define-builtin-markup-command (magnify layout props sz arg)
1178 @cindex magnifying text
1180 Set the font magnification for its argument. In the following
1181 example, the middle@tie{}A is 10% larger:
1184 A \\magnify #1.1 @{ A @} A
1187 Note: Magnification only works if a font name is explicitly selected.
1188 Use @code{\\fontsize} otherwise."
1191 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1194 (define-builtin-markup-command (bold layout props arg)
1198 "Switch to bold font-series."
1199 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1201 (define-builtin-markup-command (sans layout props arg)
1205 "Switch to the sans serif family."
1206 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1208 (define-builtin-markup-command (number layout props arg)
1212 "Set font family to @code{number}, which yields the font used for
1213 time signatures and fingerings. This font only contains numbers and
1214 some punctuation. It doesn't have any letters.
1216 @lilypond[verbatim,quote]
1217 \\markup \\number { 0 1 2 3 4 5 6 7 8 9 . , + - }
1219 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1221 (define-builtin-markup-command (roman layout props arg)
1225 "Set font family to @code{roman}."
1226 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1228 (define-builtin-markup-command (huge layout props arg)
1232 "Set font size to +2."
1233 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1235 (define-builtin-markup-command (large layout props arg)
1239 "Set font size to +1."
1240 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1242 (define-builtin-markup-command (normalsize layout props arg)
1246 "Set font size to default."
1247 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1249 (define-builtin-markup-command (small layout props arg)
1253 "Set font size to -1."
1254 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1256 (define-builtin-markup-command (tiny layout props arg)
1260 "Set font size to -2."
1261 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1263 (define-builtin-markup-command (teeny layout props arg)
1267 "Set font size to -3."
1268 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1270 (define-builtin-markup-command (fontCaps layout props arg)
1274 "Set @code{font-shape} to @code{caps}."
1275 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1278 (define-builtin-markup-command (smallCaps layout props text)
1282 "Turn @code{text}, which should be a string, to small caps.
1284 \\markup \\smallCaps \"Text between double quotes\"
1287 Note: @code{\\smallCaps} does not support accented characters."
1288 (define (char-list->markup chars lower)
1289 (let ((final-string (string-upcase (reverse-list->string chars))))
1291 (markup #:fontsize -2 final-string)
1293 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1294 (if (null? rest-chars)
1296 (reverse! (cons (char-list->markup currents current-is-lower)
1298 (let* ((ch (car rest-chars))
1299 (is-lower (char-lower-case? ch)))
1300 (if (or (and current-is-lower is-lower)
1301 (and (not current-is-lower) (not is-lower)))
1302 (make-small-caps (cdr rest-chars)
1306 (make-small-caps (cdr rest-chars)
1309 (if (null? currents)
1311 (cons (char-list->markup
1312 currents current-is-lower)
1314 (interpret-markup layout props
1316 (make-small-caps (string->list text) (list) #f (list))
1319 (define-builtin-markup-command (caps layout props arg)
1323 "Emit @var{arg} as small caps."
1324 (interpret-markup layout props (make-smallCaps-markup arg)))
1326 (define-builtin-markup-command (dynamic layout props arg)
1330 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
1331 @b{z}, @b{p}, and @b{r}. When producing phrases, like
1332 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
1333 done in a different font. The recommended font for this is bold and italic.
1334 @lilypond[verbatim,quote]
1335 \\markup { \\dynamic sfzp }
1338 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
1340 (define-builtin-markup-command (text layout props arg)
1344 "Use a text font instead of music symbol or music alphabet font."
1347 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1350 (define-builtin-markup-command (italic layout props arg)
1354 "Use italic @code{font-shape} for @var{arg}.
1356 @lilypond[verbatim,quote]
1357 \\markup \\italic { scherzando e leggiero }
1359 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1361 (define-builtin-markup-command (typewriter layout props arg)
1365 "Use @code{font-family} typewriter for @var{arg}."
1367 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1369 (define-builtin-markup-command (upright layout props arg)
1373 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1375 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1377 (define-builtin-markup-command (medium layout props arg)
1381 "Switch to medium font series (in contrast to bold)."
1382 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1385 (define-builtin-markup-command (normal-text layout props arg)
1389 "Set all font related properties (except the size) to get the default
1390 normal text font, no matter what font was used earlier."
1392 (interpret-markup layout
1393 (cons '((font-family . roman) (font-shape . upright)
1394 (font-series . medium) (font-encoding . latin1))
1398 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1400 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1402 (define-builtin-markup-command (doublesharp layout props)
1406 "Draw a double sharp symbol.
1408 @lilypond[verbatim,quote]
1409 \\markup { \\doublesharp }
1411 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1413 (define-builtin-markup-command (sesquisharp layout props)
1417 "Draw a 3/2 sharp symbol.
1419 @lilypond[verbatim,quote]
1420 \\markup { \\sesquisharp }
1422 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1424 (define-builtin-markup-command (sharp layout props)
1428 "Draw a sharp symbol.
1430 @lilypond[verbatim,quote]
1431 \\markup { \\sharp }
1433 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1435 (define-builtin-markup-command (semisharp layout props)
1439 "Draw a semi sharp symbol.
1441 @lilypond[verbatim,quote]
1442 \\markup { \\semisharp }
1444 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1446 (define-builtin-markup-command (natural layout props)
1450 "Draw a natural symbol.
1452 @lilypond[verbatim,quote]
1453 \\markup { \\natural }
1455 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1457 (define-builtin-markup-command (semiflat layout props)
1461 "Draw a semiflat symbol.
1463 @lilypond[verbatim,quote]
1464 \\markup { \\semiflat }
1466 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1468 (define-builtin-markup-command (flat layout props)
1472 "Draw a flat symbol.
1474 @lilypond[verbatim,quote]
1477 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1479 (define-builtin-markup-command (sesquiflat layout props)
1483 "Draw a 3/2 flat symbol.
1485 @lilypond[verbatim,quote]
1486 \\markup { \\sesquiflat }
1488 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1490 (define-builtin-markup-command (doubleflat layout props)
1494 "Draw a double flat symbol.
1496 @lilypond[verbatim,quote]
1497 \\markup { \\doubleflat }
1499 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1501 (define-builtin-markup-command (with-color layout props color arg)
1506 @cindex coloring text
1508 Draw @var{arg} in color specified by @var{color}."
1509 (let ((stil (interpret-markup layout props arg)))
1510 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1511 (ly:stencil-extent stil X)
1512 (ly:stencil-extent stil Y))))
1514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1518 (define-builtin-markup-command (arrow-head layout props axis direction filled)
1519 (integer? ly:dir? boolean?)
1522 "Produce an arrow head in specified direction and axis.
1523 Use the filled head if @var{filled} is specified.
1524 @lilypond[verbatim,quote]
1527 \\general-align #Y #DOWN {
1528 \\arrow-head #Y #UP ##t
1529 \\arrow-head #Y #DOWN ##f
1531 \\arrow-head #X #RIGHT ##f
1532 \\arrow-head #X #LEFT ##f
1537 ((name (format "arrowheads.~a.~a~a"
1544 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1548 (define-builtin-markup-command (musicglyph layout props glyph-name)
1552 "@var{glyph-name} is converted to a musical symbol; for example,
1553 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
1554 the music font. See @ruser{The Feta font} for a complete listing of
1555 the possible glyphs.
1557 @lilypond[verbatim,quote]
1560 \\musicglyph #\"rests.2\"
1561 \\musicglyph #\"clefs.G_change\"
1565 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1567 (glyph (ly:font-get-glyph font glyph-name)))
1568 (if (null? (ly:stencil-expr glyph))
1569 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
1573 (define-builtin-markup-command (lookup layout props glyph-name)
1577 "Lookup a glyph by name."
1578 (ly:font-get-glyph (ly:paper-get-font layout props)
1581 (define-builtin-markup-command (char layout props num)
1585 "Produce a single character. For example, @code{\\char #65} produces the
1587 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1589 (define number->mark-letter-vector (make-vector 25 #\A))
1594 (if (= i (- (char->integer #\I) (char->integer #\A)))
1596 (vector-set! number->mark-letter-vector j
1597 (integer->char (+ i (char->integer #\A)))))
1599 (define number->mark-alphabet-vector (list->vector
1600 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1602 (define (number->markletter-string vec n)
1603 "Double letters for big marks."
1604 (let* ((lst (vector-length vec)))
1607 (string-append (number->markletter-string vec (1- (quotient n lst)))
1608 (number->markletter-string vec (remainder n lst)))
1609 (make-string 1 (vector-ref vec n)))))
1611 (define-builtin-markup-command (markletter layout props num)
1615 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1616 (skipping letter@tie{}I), and continue with double letters.
1618 @lilypond[verbatim,quote]
1619 \\markup { \\markletter #8 \\hspace #2 \\markletter #26 }
1621 (ly:text-interface::interpret-markup layout props
1622 (number->markletter-string number->mark-letter-vector num)))
1624 (define-builtin-markup-command (markalphabet layout props num)
1628 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1629 and continue with double letters.
1631 @lilypond[verbatim,quote]
1632 \\markup { \\markalphabet #8 \\hspace #2 \\markalphabet #26 }
1634 (ly:text-interface::interpret-markup layout props
1635 (number->markletter-string number->mark-alphabet-vector num)))
1637 (define-builtin-markup-command (slashed-digit layout props num)
1643 @cindex slashed digits
1645 A feta number, with slash. This is for use in the context of
1646 figured bass notation.
1647 @lilypond[verbatim,quote]
1651 \\override #'(thickness . 3)
1655 (let* ((mag (magstep font-size))
1657 (ly:output-def-lookup layout 'line-thickness)
1660 (number-stencil (interpret-markup layout
1661 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1662 (number->string num)))
1663 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1665 (num-y (ly:stencil-extent number-stencil Y))
1666 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
1667 (slash-stencil (if is-sane
1669 `(draw-line ,thickness
1670 ,(car num-x) ,(- (interval-center num-y) dy)
1671 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1675 (cond ((not (ly:stencil? slash-stencil)) #f)
1677 (ly:stencil-translate slash-stencil
1678 ;;(cons (* mag -0.05) (* mag 0.42))
1679 (cons (* mag -0.00) (* mag -0.07))))
1681 (ly:stencil-translate slash-stencil
1682 ;;(cons (* mag -0.05) (* mag 0.42))
1683 (cons (* mag -0.00) (* mag -0.15))))
1684 (else slash-stencil)))
1686 (set! number-stencil
1687 (ly:stencil-add number-stencil slash-stencil))
1688 (ly:warning "invalid number for slashed digit ~a" num))
1691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1692 ;; the note command.
1693 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1695 ;; TODO: better syntax.
1697 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
1698 (number? number? number?)
1703 @cindex notes within text by log and dot-count
1705 Construct a note symbol, with stem. By using fractional values for
1706 @var{dir}, you can obtain longer or shorter stems."
1708 (define (get-glyph-name-candidates dir log style)
1709 (map (lambda (dir-name)
1710 (format "noteheads.~a~a~a" dir-name (min log 2)
1711 (if (and (symbol? style)
1712 (not (equal? 'default style)))
1713 (symbol->string style)
1715 (list (if (= dir UP) "u" "d")
1718 (define (get-glyph-name font cands)
1721 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1722 (get-glyph-name font (cdr cands))
1725 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1726 (size-factor (magstep font-size))
1727 (stem-length (* size-factor (max 3 (- log 1))))
1728 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
1729 (head-glyph (ly:font-get-glyph font head-glyph-name))
1730 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1731 (stem-thickness (* size-factor 0.13))
1732 (stemy (* dir stem-length))
1733 (attach-off (cons (interval-index
1734 (ly:stencil-extent head-glyph X)
1735 (* (sign dir) (car attach-indices)))
1736 (* (sign dir) ; fixme, this is inconsistent between X & Y.
1738 (ly:stencil-extent head-glyph Y)
1739 (cdr attach-indices)))))
1740 (stem-glyph (and (> log 0)
1741 (ly:round-filled-box
1742 (ordered-cons (car attach-off)
1743 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
1744 (cons (min stemy (cdr attach-off))
1745 (max stemy (cdr attach-off)))
1746 (/ stem-thickness 3))))
1748 (dot (ly:font-get-glyph font "dots.dot"))
1749 (dotwid (interval-length (ly:stencil-extent dot X)))
1750 (dots (and (> dot-count 0)
1751 (apply ly:stencil-add
1753 (ly:stencil-translate-axis
1754 dot (* 2 x dotwid) X))
1755 (iota dot-count)))))
1756 (flaggl (and (> log 2)
1757 (ly:stencil-translate
1758 (ly:font-get-glyph font
1759 (string-append "flags."
1760 (if (> dir 0) "u" "d")
1761 (number->string log)))
1762 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
1764 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
1765 ; 16th notes get a special case because their flags hang lower than any other flags.
1766 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
1767 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
1769 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1770 (if (ly:stencil? stem-glyph)
1771 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1772 (set! stem-glyph head-glyph))
1773 (if (ly:stencil? dots)
1776 (ly:stencil-translate-axis
1778 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
1784 (let ((divisor (log 2)))
1785 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1787 (define (parse-simple-duration duration-string)
1788 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1789 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1790 (if (and match (string=? duration-string (match:substring match 0)))
1791 (let ((len (match:substring match 1))
1792 (dots (match:substring match 2)))
1793 (list (cond ((string=? len "breve") -1)
1794 ((string=? len "longa") -2)
1795 ((string=? len "maxima") -3)
1796 (else (log2 (string->number len))))
1797 (if dots (string-length dots) 0)))
1798 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1800 (define-builtin-markup-command (note layout props duration dir)
1803 (note-by-number-markup)
1805 @cindex notes within text by string
1807 This produces a note with a stem pointing in @var{dir} direction, with
1808 the @var{duration} for the note head type and augmentation dots. For
1809 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1810 a shortened down stem."
1811 (let ((parsed (parse-simple-duration duration)))
1812 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1814 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1816 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1818 (define-builtin-markup-command (lower layout props amount arg)
1823 @cindex lowering text
1825 Lower @var{arg} by the distance @var{amount}.
1826 A negative @var{amount} indicates raising; see also @code{\\raise}."
1827 (ly:stencil-translate-axis (interpret-markup layout props arg)
1830 (define-builtin-markup-command (translate-scaled layout props offset arg)
1831 (number-pair? markup?)
1835 @cindex translating text
1836 @cindex scaling text
1838 Translate @var{arg} by @var{offset}, scaling the offset by the
1840 (let* ((factor (magstep font-size))
1841 (scaled (cons (* factor (car offset))
1842 (* factor (cdr offset)))))
1843 (ly:stencil-translate (interpret-markup layout props arg)
1846 (define-builtin-markup-command (raise layout props amount arg)
1851 @cindex raising text
1853 Raise @var{arg} by the distance @var{amount}.
1854 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1856 The argument to @code{\\raise} is the vertical displacement amount,
1857 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1858 raise objects in relation to their surrounding markups.
1860 If the text object itself is positioned above or below the staff, then
1861 @code{\\raise} cannot be used to move it, since the mechanism that
1862 positions it next to the staff cancels any shift made with
1863 @code{\\raise}. For vertical positioning, use the @code{padding}
1864 and/or @code{extra-offset} properties.
1866 @lilypond[verbatim,quote]
1867 \\markup { C \\small \\raise #1.0 \\bold 9/7+ }
1869 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1871 (define-builtin-markup-command (fraction layout props arg1 arg2)
1876 @cindex creating text fractions
1878 Make a fraction of two markups.
1879 @lilypond[verbatim,quote]
1880 \\markup { π ≈ \\fraction 355 113 }
1882 (let* ((m1 (interpret-markup layout props arg1))
1883 (m2 (interpret-markup layout props arg2))
1884 (factor (magstep font-size))
1885 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
1886 (padding (* factor 0.2))
1887 (baseline (* factor 0.6))
1888 (offset (* factor 0.75)))
1889 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1890 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1891 (let* ((x1 (ly:stencil-extent m1 X))
1892 (x2 (ly:stencil-extent m2 X))
1893 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
1894 ;; should stack mols separately, to maintain LINE on baseline
1895 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
1897 (ly:stencil-aligned-to stack Y CENTER))
1899 (ly:stencil-aligned-to stack X LEFT))
1900 ;; should have EX dimension
1902 (ly:stencil-translate-axis stack offset Y))))
1904 (define-builtin-markup-command (normal-size-super layout props arg)
1909 @cindex setting superscript in standard font size
1911 Set @var{arg} in superscript with a normal font size."
1912 (ly:stencil-translate-axis
1913 (interpret-markup layout props arg)
1914 (* 0.5 baseline-skip) Y))
1916 (define-builtin-markup-command (super layout props arg)
1922 @cindex superscript text
1924 Raising and lowering texts can be done with @code{\\super} and
1927 @lilypond[verbatim,quote]
1928 \\markup { E = \\concat { mc \\super 2 } }
1930 (ly:stencil-translate-axis
1933 (cons `((font-size . ,(- font-size 3))) props)
1935 (* 0.5 baseline-skip)
1938 (define-builtin-markup-command (translate layout props offset arg)
1939 (number-pair? markup?)
1943 @cindex translating text
1945 This translates an object. Its first argument is a cons of numbers.
1948 A \\translate #(cons 2 -3) @{ B C @} D
1951 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
1952 surroundings. This command cannot be used to move isolated scripts
1953 vertically, for the same reason that @code{\\raise} cannot be used for
1955 (ly:stencil-translate (interpret-markup layout props arg)
1958 (define-builtin-markup-command (sub layout props arg)
1964 @cindex subscript text
1966 Set @var{arg} in subscript."
1967 (ly:stencil-translate-axis
1970 (cons `((font-size . ,(- font-size 3))) props)
1972 (* -0.5 baseline-skip)
1975 (define-builtin-markup-command (normal-size-sub layout props arg)
1980 @cindex setting subscript in standard font size
1982 Set @var{arg} in subscript, in a normal font size."
1983 (ly:stencil-translate-axis
1984 (interpret-markup layout props arg)
1985 (* -0.5 baseline-skip)
1988 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1992 (define-builtin-markup-command (hbracket layout props arg)
1997 @cindex placing horizontal brackets around text
1999 Draw horizontal brackets around @var{arg}."
2000 (let ((th 0.1) ;; todo: take from GROB.
2001 (m (interpret-markup layout props arg)))
2002 (bracketify-stencil m X th (* 2.5 th) th)))
2004 (define-builtin-markup-command (bracket layout props arg)
2009 @cindex placing vertical brackets around text
2011 Draw vertical brackets around @var{arg}."
2012 (let ((th 0.1) ;; todo: take from GROB.
2013 (m (interpret-markup layout props arg)))
2014 (bracketify-stencil m Y th (* 2.5 th) th)))
2016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2017 ;; Delayed markup evaluation
2018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2020 (define-builtin-markup-command (page-ref layout props label gauge default)
2021 (symbol? markup? markup?)
2025 @cindex referencing page numbers in text
2027 Reference to a page number. @var{label} is the label set on the referenced
2028 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
2029 the maximum width of the page number, and @var{default} the value to display
2030 when @var{label} is not found."
2031 (let* ((gauge-stencil (interpret-markup layout props gauge))
2032 (x-ext (ly:stencil-extent gauge-stencil X))
2033 (y-ext (ly:stencil-extent gauge-stencil Y)))
2035 `(delay-stencil-evaluation
2036 ,(delay (ly:stencil-expr
2037 (let* ((table (ly:output-def-lookup layout 'label-page-table))
2038 (label-page (and (list? table) (assoc label table)))
2039 (page-number (and label-page (cdr label-page)))
2040 (page-markup (if page-number (format "~a" page-number) default))
2041 (page-stencil (interpret-markup layout props page-markup))
2042 (gap (- (interval-length x-ext)
2043 (interval-length (ly:stencil-extent page-stencil X)))))
2044 (interpret-markup layout props
2045 (markup #:concat (#:hspace gap page-markup)))))))
2049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2050 ;; Markup list commands
2051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2053 (define-public (space-lines baseline-skip lines)
2055 (stack-lines DOWN 0.0 (/ baseline-skip 2.0)
2061 (define-builtin-markup-list-command (justified-lines layout props args)
2064 wordwrap-internal-markup-list)
2066 @cindex justifying lines of text
2068 Like @code{\\justify}, but return a list of lines instead of a single markup.
2069 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
2070 @var{X}@tie{}is the number of staff spaces."
2071 (space-lines baseline-skip
2072 (interpret-markup-list layout props
2073 (make-wordwrap-internal-markup-list #t args))))
2075 (define-builtin-markup-list-command (wordwrap-lines layout props args)
2078 wordwrap-internal-markup-list)
2079 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
2080 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
2081 where @var{X} is the number of staff spaces."
2082 (space-lines baseline-skip
2083 (interpret-markup-list layout props
2084 (make-wordwrap-internal-markup-list #f args))))
2086 (define-builtin-markup-list-command (column-lines layout props args)
2089 "Like @code{\\column}, but return a list of lines instead of a single markup.
2090 @code{baseline-skip} determines the space between each markup in @var{args}."
2091 (space-lines (chain-assoc-get 'baseline-skip props)
2092 (interpret-markup-list layout props args)))
2094 (define-builtin-markup-list-command (override-lines layout props new-prop args)
2095 (pair? markup-list?)
2097 "Like @code{\\override}, for markup lists."
2098 (interpret-markup-list layout (cons (list new-prop) props) args))