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]
115 \\markup \\circle { Hi }
117 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
119 (pad (* (magstep font-size) circle-padding))
120 (m (interpret-markup layout props arg)))
121 (circle-stencil m th pad)))
123 (define-builtin-markup-command (with-url layout props url arg)
128 @cindex inserting URL links into text
130 Add a link to URL @var{url} around @var{arg}. This only works in
133 @lilypond[verbatim,quote]
135 \\with-url #\"http://lilypond.org/web/\" {
136 LilyPond ... \\italic { music notation for everyone }
140 (let* ((stil (interpret-markup layout props arg))
141 (xextent (ly:stencil-extent stil X))
142 (yextent (ly:stencil-extent stil Y))
143 (old-expr (ly:stencil-expr stil))
144 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
146 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
148 (define-builtin-markup-command (beam layout props width slope thickness)
149 (number? number? number?)
153 @cindex drawing beams within text
155 Create a beam with the specified parameters.
156 @lilypond[verbatim,quote]
157 \\markup \\beam #5 #1 #2
159 (let* ((y (* slope width))
160 (yext (cons (min 0 y) (max 0 y)))
161 (half (/ thickness 2)))
166 width (+ (* width slope) (/ thickness -2))
167 width (+ (* width slope) (/ thickness 2))
169 ,(ly:output-def-lookup layout 'blot-diameter)
172 (cons (+ (- half) (car yext))
173 (+ half (cdr yext))))))
175 (define-builtin-markup-command (underline layout props arg)
180 @cindex underlining text
182 Underline @var{arg}. Looks at @code{thickness} to determine line
183 thickness and y offset.
185 @lilypond[verbatim,quote]
186 \\markup \\underline { CONTENTS }
188 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
190 (markup (interpret-markup layout props arg))
191 (x1 (car (ly:stencil-extent markup X)))
192 (x2 (cdr (ly:stencil-extent markup X)))
194 (line (ly:make-stencil
195 `(draw-line ,thick ,x1 ,y ,x2 ,y)
196 (cons (min x1 0) (max x2 0))
197 (cons thick thick))))
198 (ly:stencil-add markup line)))
200 (define-builtin-markup-command (box layout props arg)
207 @cindex enclosing text within a box
209 Draw a box round @var{arg}. Looks at @code{thickness},
210 @code{box-padding} and @code{font-size} properties to determine line
211 thickness and padding around the markup.
213 @lilypond[verbatim,quote]
215 \\override #'(box-padding . 0.5)
220 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
222 (pad (* (magstep font-size) box-padding))
223 (m (interpret-markup layout props arg)))
224 (box-stencil m th pad)))
226 (define-builtin-markup-command (filled-box layout props xext yext blot)
227 (number-pair? number-pair? number?)
231 @cindex drawing solid boxes within text
232 @cindex drawing boxes with rounded corners
234 Draw a box with rounded corners of dimensions @var{xext} and
235 @var{yext}. For example,
237 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
239 creates a box extending horizontally from -0.3 to 1.8 and
240 vertically from -0.3 up to 1.8, with corners formed from a
241 circle of diameter@tie{}0 (i.e. sharp corners).
243 @lilypond[verbatim,quote]
245 \\filled-box #'(0 . 4) #'(0 . 4) #0
246 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
247 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
249 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
255 (define-builtin-markup-command (rounded-box layout props arg)
262 "@cindex enclosing text in a bow with rounded corners
263 @cindex drawing boxes with rounded corners around text
264 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
265 @code{box-padding} and @code{font-size} properties to determine line
266 thickness and padding around the markup; the @code{corner-radius} property
267 makes possible to define another shape for the corners (default is 1).
269 @lilypond[quote,verbatim,fragment,relative=2]
270 c^\\markup \\rounded-box { Overtura }
273 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
275 (pad (* (magstep font-size) box-padding))
276 (m (interpret-markup layout props arg)))
277 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
280 (define-builtin-markup-command (rotate layout props ang arg)
285 @cindex rotating text
287 Rotate object with @var{ang} degrees around its center."
288 (let* ((stil (interpret-markup layout props arg)))
289 (ly:stencil-rotate stil ang 0 0)))
291 (define-builtin-markup-command (whiteout layout props arg)
296 @cindex adding a white background to text
298 Provide a white background for @var{arg}."
299 (stencil-whiteout (interpret-markup layout props arg)))
301 (define-builtin-markup-command (pad-markup layout props padding arg)
307 @cindex putting space around text
309 Add space around a markup object."
311 ((stil (interpret-markup layout props arg))
312 (xext (ly:stencil-extent stil X))
313 (yext (ly:stencil-extent stil Y)))
316 (ly:stencil-expr stil)
317 (interval-widen xext padding)
318 (interval-widen yext padding))))
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
322 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
324 (define-builtin-markup-command (strut layout props)
329 @cindex creating vertical spaces in text
331 Create a box of the same height as the space in the current font."
332 (let ((m (ly:text-interface::interpret-markup layout props " ")))
333 (ly:make-stencil (ly:stencil-expr m)
335 (ly:stencil-extent m X)
338 ;; todo: fix negative space
339 (define-builtin-markup-command (hspace layout props amount)
344 @cindex creating horizontal spaces in text
346 This produces a invisible object taking horizontal space. For example,
349 \\markup @{ A \\hspace #2.0 B @}
353 puts extra space between A and@tie{}B, on top of the space that is
354 normally inserted before elements on a line."
356 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
357 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
361 ;; importing graphics.
362 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
364 (define-builtin-markup-command (stencil layout props stil)
369 @cindex importing stencils into text
371 Use a stencil as markup."
375 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
377 (define (get-postscript-bbox string)
378 "Extract the bbox from STRING, or return #f if not present."
380 ((match (regexp-exec bbox-regexp string)))
384 (string->number (match:substring match x)))
389 (define-builtin-markup-command (epsfile layout props axis size file-name)
390 (number? number? string?)
394 @cindex inlining an Encapsulated PostScript image
396 Inline an EPS image. The image is scaled along @var{axis} to
399 @lilypond[verbatim,quote]
401 \\general-align #Y #DOWN {
402 \\epsfile #X #20 #\"context-example.eps\"
403 \\epsfile #Y #20 #\"context-example.eps\"
407 (if (ly:get-option 'safe)
408 (interpret-markup layout props "not allowed in safe")
409 (eps-file->stencil axis size file-name)
412 (define-builtin-markup-command (postscript layout props str)
417 @cindex inserting PostScript directly into text
419 This inserts @var{str} directly into the output as a PostScript
420 command string. Due to technicalities of the output backends,
421 different scales should be used for the @TeX{} and PostScript backend,
422 selected with @code{-f}.
424 For the @TeX{} backend, the following string prints a rotated text
427 0 0 moveto /ecrm10 findfont
428 1.75 scalefont setfont 90 rotate (hello) show
432 The magical constant 1.75 scales from LilyPond units (staff spaces) to
435 For the postscript backend, use the following
438 gsave /ecrm10 findfont
439 10.0 output-scale div
440 scalefont setfont 90 rotate (hello) show grestore
443 @lilypond[verbatim,quote]
449 0.7 0.7 0.5 0 361 arc
451 2.20 0.70 0.50 0 361 arc
453 1.45 0.85 0.30 0 180 arc
457 0.92 2.26 1.30 2.40 1.15 1.70 curveto
461 3.42 2.26 3.80 2.40 3.65 1.70 curveto
464 eyeglasses = \\markup {
465 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
466 \\postscript #eyeglassesps
469 \\relative c'' { c2^\\eyeglasses a_\\eyeglasses }
475 gsave currentpoint translate
483 (define-builtin-markup-command (score layout props score)
488 @cindex inserting music into text
490 Inline an image of music.
492 @lilypond[verbatim,quote]
496 \\new Staff \\relative c' {
499 \\mark \\markup { Allegro }
505 \\new Staff \\relative c {
519 \\override RehearsalMark #'break-align-symbols =
520 #'(time-signature key-signature)
521 \\override RehearsalMark #'self-alignment-X = #LEFT
525 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
531 (let* ((output (ly:score-embedded-format score layout)))
533 (if (ly:music-output? output)
534 (paper-system-stencil
535 (vector-ref (ly:paper-score-paper-systems output) 0))
537 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
540 (define-builtin-markup-command (null layout props)
545 @cindex creating empty text objects
547 An empty markup with extents of a single point."
550 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
552 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
554 (define-builtin-markup-command (simple layout props str)
559 @cindex simple text strings
561 A simple text string; @code{\\markup @{ foo @}} is equivalent with
562 @code{\\markup @{ \\simple #\"foo\" @}}."
563 (interpret-markup layout props str))
565 (define-builtin-markup-command (tied-lyric layout props str)
570 @cindex simple text strings with tie characters
572 Like simple-markup, but use tie characters for @q{~} tilde symbols."
573 (if (string-contains str "~")
575 ((parts (string-split str #\~))
576 (tie-str (ly:wide-char->utf-8 #x203f))
577 (joined (list-join parts tie-str))
578 (join-stencil (interpret-markup layout props tie-str))
581 (interpret-markup layout
584 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
586 (make-line-markup joined)))
587 ;(map (lambda (s) (interpret-markup layout props s)) parts))
588 (interpret-markup layout props str)))
590 (define-public empty-markup
591 (make-simple-markup ""))
593 ;; helper for justifying lines.
594 (define (get-fill-space word-count line-width text-widths)
595 "Calculate the necessary paddings between each two adjacent texts.
596 The lengths of all texts are stored in @var{text-widths}.
597 The normal formula for the padding between texts a and b is:
598 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
599 The first and last padding have to be calculated specially using the
600 whole length of the first or last text.
601 Return a list of paddings."
603 ((null? text-widths) '())
605 ;; special case first padding
606 ((= (length text-widths) word-count)
608 (- (- (/ line-width (1- word-count)) (car text-widths))
609 (/ (car (cdr text-widths)) 2))
610 (get-fill-space word-count line-width (cdr text-widths))))
611 ;; special case last padding
612 ((= (length text-widths) 2)
613 (list (- (/ line-width (1- word-count))
614 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
617 (- (/ line-width (1- word-count))
618 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
619 (get-fill-space word-count line-width (cdr text-widths))))))
621 (define-builtin-markup-command (fill-line layout props markups)
624 ((text-direction RIGHT)
627 "Put @var{markups} in a horizontal line of width @var{line-width}.
628 The markups are spaced or flushed to fill the entire line.
629 If there are no arguments, return an empty stencil."
631 (let* ((orig-stencils (interpret-markup-list layout props markups))
634 (if (ly:stencil-empty? stc)
636 stc)) orig-stencils))
639 (if (ly:stencil-empty? stc)
641 (interval-length (ly:stencil-extent stc X))))
643 (text-width (apply + text-widths))
644 (word-count (length stencils))
645 (prop-line-width (chain-assoc-get 'line-width props #f))
646 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
651 (/ (- line-width text-width) 2)
652 (/ (- line-width text-width) 2)))
655 (- line-width text-width)))
657 (get-fill-space word-count line-width text-widths))))
665 (line-stencils (if (= word-count 1)
672 (if (= text-direction LEFT)
673 (set! line-stencils (reverse line-stencils)))
675 (if (null? (remove ly:stencil-empty? orig-stencils))
677 (stack-stencils-padding-list X
678 RIGHT fill-space-normal line-stencils))))
680 (define-builtin-markup-command (line layout props args)
684 (text-direction RIGHT))
685 "Put @var{args} in a horizontal line. The property @code{word-space}
686 determines the space between each markup in @var{args}."
687 (let ((stencils (interpret-markup-list layout props args)))
688 (if (= text-direction LEFT)
689 (set! stencils (reverse stencils)))
692 (remove ly:stencil-empty? stencils))))
694 (define-builtin-markup-command (concat layout props args)
699 @cindex concatenating text
700 @cindex ligatures in text
702 Concatenate @var{args} in a horizontal line, without spaces inbetween.
703 Strings and simple markups are concatenated on the input level, allowing
704 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
705 equivalent to @code{\"fi\"}."
706 (define (concat-string-args arg-list)
707 (fold-right (lambda (arg result-list)
708 (let ((result (if (pair? result-list)
711 (if (and (pair? arg) (eqv? (car arg) simple-markup))
712 (set! arg (cadr arg)))
713 (if (and (string? result) (string? arg))
714 (cons (string-append arg result) (cdr result-list))
715 (cons arg result-list))))
719 (interpret-markup layout
720 (prepend-alist-chain 'word-space 0 props)
721 (make-line-markup (if (markup-command-list? args)
723 (concat-string-args args)))))
725 (define (wordwrap-stencils stencils
726 justify base-space line-width text-dir)
727 "Perform simple wordwrap, return stencil of each line."
728 (define space (if justify
729 ;; justify only stretches lines.
732 (define (take-list width space stencils
733 accumulator accumulated-width)
734 "Return (head-list . tail) pair, with head-list fitting into width"
736 (cons accumulator stencils)
737 (let* ((first (car stencils))
738 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
739 (newwid (+ space first-wid accumulated-width)))
740 (if (or (null? accumulator)
742 (take-list width space
744 (cons first accumulator)
746 (cons accumulator stencils)))))
747 (let loop ((lines '())
749 (let* ((line-break (take-list line-width space todo
751 (line-stencils (car line-break))
752 (space-left (- line-width
753 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
755 (line-word-space (cond ((not justify) space)
756 ;; don't stretch last line of paragraph.
757 ;; hmmm . bug - will overstretch the last line in some case.
758 ((null? (cdr line-break))
760 ((null? line-stencils) 0.0)
761 ((null? (cdr line-stencils)) 0.0)
762 (else (/ space-left (1- (length line-stencils))))))
763 (line (stack-stencil-line line-word-space
764 (if (= text-dir RIGHT)
765 (reverse line-stencils)
767 (if (pair? (cdr line-break))
768 (loop (cons line lines)
771 (if (= text-dir LEFT)
773 (ly:stencil-translate-axis
775 (- line-width (interval-end (ly:stencil-extent line X)))
777 (reverse (cons line lines)))))))
779 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
780 (boolean? markup-list?)
783 (text-direction RIGHT))
784 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
785 (wordwrap-stencils (remove ly:stencil-empty?
786 (interpret-markup-list layout props args))
790 (ly:output-def-lookup layout 'line-width))
793 (define-builtin-markup-command (justify layout props args)
797 wordwrap-internal-markup-list)
799 @cindex justifying text
801 Like wordwrap, but with lines stretched to justify the margins.
802 Use @code{\\override #'(line-width . @var{X})} to set the line width;
803 @var{X}@tie{}is the number of staff spaces."
804 (stack-lines DOWN 0.0 baseline-skip
805 (wordwrap-internal-markup-list layout props #t args)))
807 (define-builtin-markup-command (wordwrap layout props args)
811 wordwrap-internal-markup-list)
812 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
813 the line width, where @var{X} is the number of staff spaces."
814 (stack-lines DOWN 0.0 baseline-skip
815 (wordwrap-internal-markup-list layout props #f args)))
817 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
821 (text-direction RIGHT))
822 "Internal markup list command used to define @code{\\justify-string} and
823 @code{\\wordwrap-string}."
824 (let* ((para-strings (regexp-split
825 (string-regexp-substitute
827 (string-regexp-substitute "\r\n" "\n" arg))
828 "\n[ \t\n]*\n[ \t\n]*"))
829 (list-para-words (map (lambda (str)
830 (regexp-split str "[ \t\n]+"))
832 (para-lines (map (lambda (words)
834 (remove ly:stencil-empty?
836 (interpret-markup layout props x))
838 (wordwrap-stencils stencils
840 line-width text-direction)))
842 (apply append para-lines)))
844 (define-builtin-markup-command (wordwrap-string layout props arg)
848 wordwrap-string-internal-markup-list)
849 "Wordwrap a string. Paragraphs may be separated with double newlines."
850 (stack-lines DOWN 0.0 baseline-skip
851 (wordwrap-string-internal-markup-list layout props #f arg)))
853 (define-builtin-markup-command (justify-string layout props arg)
857 wordwrap-string-internal-markup-list)
858 "Justify a string. Paragraphs may be separated with double newlines"
859 (stack-lines DOWN 0.0 baseline-skip
860 (wordwrap-string-internal-markup-list layout props #t arg)))
862 (define-builtin-markup-command (wordwrap-field layout props symbol)
866 "Wordwrap the data which has been assigned to @var{symbol}."
867 (let* ((m (chain-assoc-get symbol props)))
869 (wordwrap-string-markup layout props m)
872 (define-builtin-markup-command (justify-field layout props symbol)
876 "Justify the data which has been assigned to @var{symbol}."
877 (let* ((m (chain-assoc-get symbol props)))
879 (justify-string-markup layout props m)
882 (define-builtin-markup-command (combine layout props m1 m2)
889 Print two markups on top of each other.
890 @lilypond[verbatim,quote]
893 \\override #'(thickness . 2)
895 \\draw-line #'(0 . 4)
896 \\arrow-head #Y #DOWN ##f
899 (let* ((s1 (interpret-markup layout props m1))
900 (s2 (interpret-markup layout props m2)))
901 (ly:stencil-add s1 s2)))
904 ;; TODO: should extract baseline-skip from each argument somehow..
906 (define-builtin-markup-command (column layout props args)
911 @cindex stacking text in a column
913 Stack the markups in @var{args} vertically. The property
914 @code{baseline-skip} determines the space between each
915 markup in @var{args}.
917 @lilypond[verbatim,quote]
918 \\markup \\column { one two three }
920 (let ((arg-stencils (interpret-markup-list layout props args)))
921 (stack-lines -1 0.0 baseline-skip
922 (remove ly:stencil-empty? arg-stencils))))
924 (define-builtin-markup-command (dir-column layout props args)
930 @cindex changing direction of text columns
932 Make a column of args, going up or down, depending on the setting
933 of the @code{#'direction} layout property.
935 @lilypond[verbatim,quote]
937 \\override #'(direction . 1)
938 \\dir-column { going up }
939 \\dir-column { going down }
942 (stack-lines (if (number? direction) direction -1)
945 (interpret-markup-list layout props args)))
947 (define-builtin-markup-command (center-align layout props args)
952 @cindex centering a column of text
954 Put @code{args} in a centered column.
956 @lilypond[verbatim,quote]
957 \\markup \\center-align { one two three }
959 (let* ((mols (interpret-markup-list layout props args))
960 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
961 (stack-lines -1 0.0 baseline-skip cmols)))
963 (define-builtin-markup-command (vcenter layout props arg)
968 @cindex vertically centering text
970 Align @code{arg} to its Y@tie{}center."
971 (let* ((mol (interpret-markup layout props arg)))
972 (ly:stencil-aligned-to mol Y CENTER)))
974 (define-builtin-markup-command (hcenter layout props arg)
979 @cindex horizontally centering text
981 Align @code{arg} to its X@tie{}center."
982 (let* ((mol (interpret-markup layout props arg)))
983 (ly:stencil-aligned-to mol X CENTER)))
985 (define-builtin-markup-command (right-align layout props arg)
990 @cindex right aligning text
992 Align @var{arg} on its right edge."
993 (let* ((m (interpret-markup layout props arg)))
994 (ly:stencil-aligned-to m X RIGHT)))
996 (define-builtin-markup-command (left-align layout props arg)
1001 @cindex left aligning text
1003 Align @var{arg} on its left edge."
1004 (let* ((m (interpret-markup layout props arg)))
1005 (ly:stencil-aligned-to m X LEFT)))
1007 (define-builtin-markup-command (general-align layout props axis dir arg)
1008 (integer? number? markup?)
1012 @cindex controlling general text alignment
1014 Align @var{arg} in @var{axis} direction to the @var{dir} side."
1015 (let* ((m (interpret-markup layout props arg)))
1016 (ly:stencil-aligned-to m axis dir)))
1018 (define-builtin-markup-command (halign layout props dir arg)
1023 @cindex setting horizontal text alignment
1025 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1026 left-aligned, while @code{+1} is right. Values inbetween interpolate
1027 alignment accordingly."
1028 (let* ((m (interpret-markup layout props arg)))
1029 (ly:stencil-aligned-to m X dir)))
1031 (define-builtin-markup-command (with-dimensions layout props x y arg)
1032 (number-pair? number-pair? markup?)
1036 @cindex setting extent of text objects
1038 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1039 (let* ((m (interpret-markup layout props arg)))
1040 (ly:make-stencil (ly:stencil-expr m) x y)))
1042 (define-builtin-markup-command (pad-around layout props amount arg)
1046 "Add padding @var{amount} all around @var{arg}."
1047 (let* ((m (interpret-markup layout props arg))
1048 (x (ly:stencil-extent m X))
1049 (y (ly:stencil-extent m Y)))
1050 (ly:make-stencil (ly:stencil-expr m)
1051 (interval-widen x amount)
1052 (interval-widen y amount))))
1054 (define-builtin-markup-command (pad-x layout props amount arg)
1059 @cindex padding text horizontally
1061 Add padding @var{amount} around @var{arg} in the X@tie{}direction."
1062 (let* ((m (interpret-markup layout props arg))
1063 (x (ly:stencil-extent m X))
1064 (y (ly:stencil-extent m Y)))
1065 (ly:make-stencil (ly:stencil-expr m)
1066 (interval-widen x amount)
1069 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2)
1070 (markup? integer? ly:dir? markup?)
1073 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1074 (let ((m1 (interpret-markup layout props arg1))
1075 (m2 (interpret-markup layout props arg2)))
1076 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1078 (define-builtin-markup-command (transparent layout props arg)
1082 "Make the argument transparent."
1083 (let* ((m (interpret-markup layout props arg))
1084 (x (ly:stencil-extent m X))
1085 (y (ly:stencil-extent m Y)))
1086 (ly:make-stencil "" x y)))
1088 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1089 (number-pair? number-pair? markup?)
1092 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
1093 (let* ((m (interpret-markup layout props arg))
1094 (x (ly:stencil-extent m X))
1095 (y (ly:stencil-extent m Y)))
1096 (ly:make-stencil (ly:stencil-expr m)
1097 (interval-union x-ext x)
1098 (interval-union y-ext y))))
1100 (define-builtin-markup-command (hcenter-in layout props length arg)
1104 "Center @var{arg} horizontally within a box of extending
1105 @var{length}/2 to the left and right."
1106 (interpret-markup layout props
1107 (make-pad-to-box-markup
1108 (cons (/ length -2) (/ length 2))
1110 (make-hcenter-markup arg))))
1112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1116 (define-builtin-markup-command (fromproperty layout props symbol)
1120 "Read the @var{symbol} from property settings, and produce a stencil
1121 from the markup contained within. If @var{symbol} is not defined, it
1122 returns an empty markup."
1123 (let ((m (chain-assoc-get symbol props)))
1125 (interpret-markup layout props m)
1128 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1132 "Apply the @var{procedure} markup command to @var{arg}.
1133 @var{procedure} should take a single argument."
1134 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1135 (set-object-property! anonymous-with-signature
1138 (interpret-markup layout props (list anonymous-with-signature arg))))
1140 (define-builtin-markup-command (override layout props new-prop arg)
1145 @cindex overriding properties within text markup
1147 Add the first argument in to the property list. Properties may be
1148 any sort of property supported by @rinternals{font-interface} and
1149 @rinternals{text-interface}, for example
1152 \\override #'(font-family . married) \"bla\"
1154 (interpret-markup layout (cons (list new-prop) props) arg))
1156 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1158 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1160 (define-builtin-markup-command (verbatim-file layout props name)
1164 "Read the contents of a file, and include it verbatim.
1166 @lilypond[verbatim,quote]
1167 \\markup \\verbatim-file #\"simple.ly\"
1169 (interpret-markup layout props
1170 (if (ly:get-option 'safe)
1171 "verbatim-file disabled in safe mode"
1172 (let* ((str (ly:gulp-file name))
1173 (lines (string-split str #\nl)))
1174 (make-typewriter-markup
1175 (make-column-markup lines))))))
1177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1179 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1181 (define-builtin-markup-command (bigger layout props arg)
1185 "Increase the font size relative to current setting.
1187 @lilypond[verbatim,quote]
1189 Voici venir les temps où vibrant sur sa tige
1192 (interpret-markup layout props
1193 `(,fontsize-markup 1 ,arg)))
1195 (define-builtin-markup-command (smaller layout props arg)
1199 "Decrease the font size relative to current setting."
1200 (interpret-markup layout props
1201 `(,fontsize-markup -1 ,arg)))
1203 (define-builtin-markup-command larger
1208 (define-builtin-markup-command (finger layout props arg)
1212 "Set the argument as small numbers.
1213 @lilypond[verbatim,quote]
1214 \\markup \\finger { 1 2 3 4 5 }
1216 (interpret-markup layout
1217 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1220 (define-builtin-markup-command (fontsize layout props increment arg)
1226 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
1227 (let ((entries (list
1228 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1229 (cons 'word-space (* word-space (magstep increment)))
1230 (cons 'font-size (+ font-size increment)))))
1231 (interpret-markup layout (cons entries props) arg)))
1233 (define-builtin-markup-command (magnify layout props sz arg)
1238 @cindex magnifying text
1240 Set the font magnification for its argument. In the following
1241 example, the middle@tie{}A is 10% larger:
1244 A \\magnify #1.1 @{ A @} A
1247 Note: Magnification only works if a font name is explicitly selected.
1248 Use @code{\\fontsize} otherwise."
1251 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1254 (define-builtin-markup-command (bold layout props arg)
1258 "Switch to bold font-series.
1260 @lilypond[verbatim,quote]
1262 Chaque fleur s'évapore ainsi qu'un encensoir
1265 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1267 (define-builtin-markup-command (sans layout props arg)
1271 "Switch to the sans serif family."
1272 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1274 (define-builtin-markup-command (number layout props arg)
1278 "Set font family to @code{number}, which yields the font used for
1279 time signatures and fingerings. This font only contains numbers and
1280 some punctuation. It doesn't have any letters.
1282 @lilypond[verbatim,quote]
1283 \\markup \\number { 0 1 2 3 4 5 6 7 8 9 . , + - }
1285 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1287 (define-builtin-markup-command (roman layout props arg)
1291 "Set font family to @code{roman}."
1292 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1294 (define-builtin-markup-command (huge layout props arg)
1298 "Set font size to +2."
1299 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1301 (define-builtin-markup-command (large layout props arg)
1305 "Set font size to +1."
1306 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1308 (define-builtin-markup-command (normalsize layout props arg)
1312 "Set font size to default."
1313 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1315 (define-builtin-markup-command (small layout props arg)
1319 "Set font size to -1."
1320 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1322 (define-builtin-markup-command (tiny layout props arg)
1326 "Set font size to -2."
1327 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1329 (define-builtin-markup-command (teeny layout props arg)
1333 "Set font size to -3."
1334 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1336 (define-builtin-markup-command (fontCaps layout props arg)
1340 "Set @code{font-shape} to @code{caps}"
1341 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1344 (define-builtin-markup-command (smallCaps layout props text)
1348 "Turn @code{text}, which should be a string, to small caps.
1350 \\markup \\smallCaps \"Text between double quotes\"
1353 Note: @code{\\smallCaps} does not support accented characters."
1354 (define (char-list->markup chars lower)
1355 (let ((final-string (string-upcase (reverse-list->string chars))))
1357 (markup #:fontsize -2 final-string)
1359 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1360 (if (null? rest-chars)
1362 (reverse! (cons (char-list->markup currents current-is-lower)
1364 (let* ((ch (car rest-chars))
1365 (is-lower (char-lower-case? ch)))
1366 (if (or (and current-is-lower is-lower)
1367 (and (not current-is-lower) (not is-lower)))
1368 (make-small-caps (cdr rest-chars)
1372 (make-small-caps (cdr rest-chars)
1375 (if (null? currents)
1377 (cons (char-list->markup
1378 currents current-is-lower)
1380 (interpret-markup layout props
1382 (make-small-caps (string->list text) (list) #f (list))
1385 (define-builtin-markup-command (caps layout props arg)
1389 "Emit @var{arg} as small caps.
1391 @lilypond[verbatim,quote]
1393 Les sons et les parfums tournent dans l'air du soir
1396 (interpret-markup layout props (make-smallCaps-markup arg)))
1398 (define-builtin-markup-command (dynamic layout props arg)
1402 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
1403 @b{z}, @b{p}, and @b{r}. When producing phrases, like
1404 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
1405 done in a different font. The recommended font for this is bold and italic.
1406 @lilypond[verbatim,quote]
1407 \\markup { \\dynamic sfzp }
1410 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
1412 (define-builtin-markup-command (text layout props arg)
1416 "Use a text font instead of music symbol or music alphabet font."
1419 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1422 (define-builtin-markup-command (italic layout props arg)
1426 "Use italic @code{font-shape} for @var{arg}.
1428 @lilypond[verbatim,quote]
1429 \\markup \\italic { scherzando e leggiero }
1431 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1433 (define-builtin-markup-command (typewriter layout props arg)
1437 "Use @code{font-family} typewriter for @var{arg}."
1439 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1441 (define-builtin-markup-command (upright layout props arg)
1445 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1447 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1449 (define-builtin-markup-command (medium layout props arg)
1453 "Switch to medium font series (in contrast to bold)."
1454 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1457 (define-builtin-markup-command (normal-text layout props arg)
1461 "Set all font related properties (except the size) to get the default
1462 normal text font, no matter what font was used earlier."
1464 (interpret-markup layout
1465 (cons '((font-family . roman) (font-shape . upright)
1466 (font-series . medium) (font-encoding . latin1))
1470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1472 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1474 (define-builtin-markup-command (doublesharp layout props)
1478 "Draw a double sharp symbol.
1480 @lilypond[verbatim,quote]
1481 \\markup { \\doublesharp }
1483 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1485 (define-builtin-markup-command (sesquisharp layout props)
1489 "Draw a 3/2 sharp symbol.
1491 @lilypond[verbatim,quote]
1492 \\markup { \\sesquisharp }
1494 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1496 (define-builtin-markup-command (sharp layout props)
1500 "Draw a sharp symbol.
1502 @lilypond[verbatim,quote]
1503 \\markup { \\sharp }
1505 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1507 (define-builtin-markup-command (semisharp layout props)
1511 "Draw a semi sharp symbol.
1513 @lilypond[verbatim,quote]
1514 \\markup { \\semisharp }
1516 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1518 (define-builtin-markup-command (natural layout props)
1522 "Draw a natural symbol.
1524 @lilypond[verbatim,quote]
1525 \\markup { \\natural }
1527 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1529 (define-builtin-markup-command (semiflat layout props)
1533 "Draw a semiflat symbol.
1535 @lilypond[verbatim,quote]
1536 \\markup { \\semiflat }
1538 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1540 (define-builtin-markup-command (flat layout props)
1544 "Draw a flat symbol.
1546 @lilypond[verbatim,quote]
1549 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1551 (define-builtin-markup-command (sesquiflat layout props)
1555 "Draw a 3/2 flat symbol.
1557 @lilypond[verbatim,quote]
1558 \\markup { \\sesquiflat }
1560 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1562 (define-builtin-markup-command (doubleflat layout props)
1566 "Draw a double flat symbol.
1568 @lilypond[verbatim,quote]
1569 \\markup { \\doubleflat }
1571 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1573 (define-builtin-markup-command (with-color layout props color arg)
1578 @cindex coloring text
1580 Draw @var{arg} in color specified by @var{color}."
1581 (let ((stil (interpret-markup layout props arg)))
1582 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1583 (ly:stencil-extent stil X)
1584 (ly:stencil-extent stil Y))))
1586 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1588 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1590 (define-builtin-markup-command (arrow-head layout props axis direction filled)
1591 (integer? ly:dir? boolean?)
1594 "Produce an arrow head in specified direction and axis.
1595 Use the filled head if @var{filled} is specified.
1596 @lilypond[verbatim,quote]
1599 \\general-align #Y #DOWN {
1600 \\arrow-head #Y #UP ##t
1601 \\arrow-head #Y #DOWN ##f
1603 \\arrow-head #X #RIGHT ##f
1604 \\arrow-head #X #LEFT ##f
1609 ((name (format "arrowheads.~a.~a~a"
1616 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1620 (define-builtin-markup-command (musicglyph layout props glyph-name)
1624 "@var{glyph-name} is converted to a musical symbol; for example,
1625 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
1626 the music font. See @ruser{The Feta font} for a complete listing of
1627 the possible glyphs.
1629 @lilypond[verbatim,quote]
1632 \\musicglyph #\"rests.2\"
1633 \\musicglyph #\"clefs.G_change\"
1636 (let* ((font (ly:paper-get-font layout
1637 (cons '((font-encoding . fetaMusic)
1641 (glyph (ly:font-get-glyph font glyph-name)))
1642 (if (null? (ly:stencil-expr glyph))
1643 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
1648 (define-builtin-markup-command (lookup layout props glyph-name)
1652 "Lookup a glyph by name."
1653 (ly:font-get-glyph (ly:paper-get-font layout props)
1656 (define-builtin-markup-command (char layout props num)
1660 "Produce a single character. For example, @code{\\char #65} produces the
1662 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1664 (define number->mark-letter-vector (make-vector 25 #\A))
1669 (if (= i (- (char->integer #\I) (char->integer #\A)))
1671 (vector-set! number->mark-letter-vector j
1672 (integer->char (+ i (char->integer #\A)))))
1674 (define number->mark-alphabet-vector (list->vector
1675 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1677 (define (number->markletter-string vec n)
1678 "Double letters for big marks."
1679 (let* ((lst (vector-length vec)))
1682 (string-append (number->markletter-string vec (1- (quotient n lst)))
1683 (number->markletter-string vec (remainder n lst)))
1684 (make-string 1 (vector-ref vec n)))))
1686 (define-builtin-markup-command (markletter layout props num)
1690 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1691 (skipping letter@tie{}I), and continue with double letters.
1693 @lilypond[verbatim,quote]
1694 \\markup { \\markletter #8 \\hspace #2 \\markletter #26 }
1696 (ly:text-interface::interpret-markup layout props
1697 (number->markletter-string number->mark-letter-vector num)))
1699 (define-builtin-markup-command (markalphabet layout props num)
1703 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1704 and continue with double letters.
1706 @lilypond[verbatim,quote]
1707 \\markup { \\markalphabet #8 \\hspace #2 \\markalphabet #26 }
1709 (ly:text-interface::interpret-markup layout props
1710 (number->markletter-string number->mark-alphabet-vector num)))
1712 (define-builtin-markup-command (slashed-digit layout props num)
1718 @cindex slashed digits
1720 A feta number, with slash. This is for use in the context of
1721 figured bass notation.
1722 @lilypond[verbatim,quote]
1726 \\override #'(thickness . 3)
1730 (let* ((mag (magstep font-size))
1732 (ly:output-def-lookup layout 'line-thickness)
1735 (number-stencil (interpret-markup layout
1736 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1737 (number->string num)))
1738 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1740 (num-y (ly:stencil-extent number-stencil Y))
1741 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
1742 (slash-stencil (if is-sane
1744 `(draw-line ,thickness
1745 ,(car num-x) ,(- (interval-center num-y) dy)
1746 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1750 (cond ((not (ly:stencil? slash-stencil)) #f)
1752 (ly:stencil-translate slash-stencil
1753 ;;(cons (* mag -0.05) (* mag 0.42))
1754 (cons (* mag -0.00) (* mag -0.07))))
1756 (ly:stencil-translate slash-stencil
1757 ;;(cons (* mag -0.05) (* mag 0.42))
1758 (cons (* mag -0.00) (* mag -0.15))))
1759 (else slash-stencil)))
1761 (set! number-stencil
1762 (ly:stencil-add number-stencil slash-stencil))
1763 (ly:warning "invalid number for slashed digit ~a" num))
1766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1767 ;; the note command.
1768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1770 ;; TODO: better syntax.
1772 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
1773 (number? number? number?)
1778 @cindex notes within text by log and dot-count
1780 Construct a note symbol, with stem. By using fractional values for
1781 @var{dir}, you can obtain longer or shorter stems.
1783 @lilypond[verbatim,quote]
1785 \\note-by-number #3 #0 #DOWN
1787 \\note-by-number #1 #2 #0.8
1790 (define (get-glyph-name-candidates dir log style)
1791 (map (lambda (dir-name)
1792 (format "noteheads.~a~a~a" dir-name (min log 2)
1793 (if (and (symbol? style)
1794 (not (equal? 'default style)))
1795 (symbol->string style)
1797 (list (if (= dir UP) "u" "d")
1800 (define (get-glyph-name font cands)
1803 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1804 (get-glyph-name font (cdr cands))
1807 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1808 (size-factor (magstep font-size))
1809 (stem-length (* size-factor (max 3 (- log 1))))
1810 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
1811 (head-glyph (ly:font-get-glyph font head-glyph-name))
1812 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1813 (stem-thickness (* size-factor 0.13))
1814 (stemy (* dir stem-length))
1815 (attach-off (cons (interval-index
1816 (ly:stencil-extent head-glyph X)
1817 (* (sign dir) (car attach-indices)))
1818 (* (sign dir) ; fixme, this is inconsistent between X & Y.
1820 (ly:stencil-extent head-glyph Y)
1821 (cdr attach-indices)))))
1822 (stem-glyph (and (> log 0)
1823 (ly:round-filled-box
1824 (ordered-cons (car attach-off)
1825 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
1826 (cons (min stemy (cdr attach-off))
1827 (max stemy (cdr attach-off)))
1828 (/ stem-thickness 3))))
1830 (dot (ly:font-get-glyph font "dots.dot"))
1831 (dotwid (interval-length (ly:stencil-extent dot X)))
1832 (dots (and (> dot-count 0)
1833 (apply ly:stencil-add
1835 (ly:stencil-translate-axis
1836 dot (* 2 x dotwid) X))
1837 (iota dot-count)))))
1838 (flaggl (and (> log 2)
1839 (ly:stencil-translate
1840 (ly:font-get-glyph font
1841 (string-append "flags."
1842 (if (> dir 0) "u" "d")
1843 (number->string log)))
1844 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
1846 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
1847 ; 16th notes get a special case because their flags hang lower than any other flags.
1848 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
1849 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
1851 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1852 (if (ly:stencil? stem-glyph)
1853 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1854 (set! stem-glyph head-glyph))
1855 (if (ly:stencil? dots)
1858 (ly:stencil-translate-axis
1860 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
1866 (let ((divisor (log 2)))
1867 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1869 (define (parse-simple-duration duration-string)
1870 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1871 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1872 (if (and match (string=? duration-string (match:substring match 0)))
1873 (let ((len (match:substring match 1))
1874 (dots (match:substring match 2)))
1875 (list (cond ((string=? len "breve") -1)
1876 ((string=? len "longa") -2)
1877 ((string=? len "maxima") -3)
1878 (else (log2 (string->number len))))
1879 (if dots (string-length dots) 0)))
1880 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1882 (define-builtin-markup-command (note layout props duration dir)
1885 (note-by-number-markup)
1887 @cindex notes within text by string
1889 This produces a note with a stem pointing in @var{dir} direction, with
1890 the @var{duration} for the note head type and augmentation dots. For
1891 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1892 a shortened down stem.
1894 @lilypond[verbatim,quote]
1896 \\override #'(style . cross)
1899 \\note #\"breve\" #0
1902 (let ((parsed (parse-simple-duration duration)))
1903 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1909 (define-builtin-markup-command (lower layout props amount arg)
1914 @cindex lowering text
1916 Lower @var{arg} by the distance @var{amount}.
1917 A negative @var{amount} indicates raising; see also @code{\\raise}."
1918 (ly:stencil-translate-axis (interpret-markup layout props arg)
1921 (define-builtin-markup-command (translate-scaled layout props offset arg)
1922 (number-pair? markup?)
1926 @cindex translating text
1927 @cindex scaling text
1929 Translate @var{arg} by @var{offset}, scaling the offset by the
1931 (let* ((factor (magstep font-size))
1932 (scaled (cons (* factor (car offset))
1933 (* factor (cdr offset)))))
1934 (ly:stencil-translate (interpret-markup layout props arg)
1937 (define-builtin-markup-command (raise layout props amount arg)
1942 @cindex raising text
1944 Raise @var{arg} by the distance @var{amount}.
1945 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1947 The argument to @code{\\raise} is the vertical displacement amount,
1948 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1949 raise objects in relation to their surrounding markups.
1951 If the text object itself is positioned above or below the staff, then
1952 @code{\\raise} cannot be used to move it, since the mechanism that
1953 positions it next to the staff cancels any shift made with
1954 @code{\\raise}. For vertical positioning, use the @code{padding}
1955 and/or @code{extra-offset} properties.
1957 @lilypond[verbatim,quote]
1958 \\markup { C \\small \\raise #1.0 \\bold 9/7+ }
1960 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1962 (define-builtin-markup-command (fraction layout props arg1 arg2)
1967 @cindex creating text fractions
1969 Make a fraction of two markups.
1970 @lilypond[verbatim,quote]
1971 \\markup { π ≈ \\fraction 355 113 }
1973 (let* ((m1 (interpret-markup layout props arg1))
1974 (m2 (interpret-markup layout props arg2))
1975 (factor (magstep font-size))
1976 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
1977 (padding (* factor 0.2))
1978 (baseline (* factor 0.6))
1979 (offset (* factor 0.75)))
1980 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1981 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1982 (let* ((x1 (ly:stencil-extent m1 X))
1983 (x2 (ly:stencil-extent m2 X))
1984 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
1985 ;; should stack mols separately, to maintain LINE on baseline
1986 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
1988 (ly:stencil-aligned-to stack Y CENTER))
1990 (ly:stencil-aligned-to stack X LEFT))
1991 ;; should have EX dimension
1993 (ly:stencil-translate-axis stack offset Y))))
1995 (define-builtin-markup-command (normal-size-super layout props arg)
2000 @cindex setting superscript in standard font size
2002 Set @var{arg} in superscript with a normal font size."
2003 (ly:stencil-translate-axis
2004 (interpret-markup layout props arg)
2005 (* 0.5 baseline-skip) Y))
2007 (define-builtin-markup-command (super layout props arg)
2013 @cindex superscript text
2015 Raising and lowering texts can be done with @code{\\super} and
2018 @lilypond[verbatim,quote]
2019 \\markup { E = \\concat { mc \\super 2 } }
2021 (ly:stencil-translate-axis
2024 (cons `((font-size . ,(- font-size 3))) props)
2026 (* 0.5 baseline-skip)
2029 (define-builtin-markup-command (translate layout props offset arg)
2030 (number-pair? markup?)
2034 @cindex translating text
2036 This translates an object. Its first argument is a cons of numbers.
2039 A \\translate #(cons 2 -3) @{ B C @} D
2042 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2043 surroundings. This command cannot be used to move isolated scripts
2044 vertically, for the same reason that @code{\\raise} cannot be used for
2046 (ly:stencil-translate (interpret-markup layout props arg)
2049 (define-builtin-markup-command (sub layout props arg)
2055 @cindex subscript text
2057 Set @var{arg} in subscript."
2058 (ly:stencil-translate-axis
2061 (cons `((font-size . ,(- font-size 3))) props)
2063 (* -0.5 baseline-skip)
2066 (define-builtin-markup-command (normal-size-sub layout props arg)
2071 @cindex setting subscript in standard font size
2073 Set @var{arg} in subscript, in a normal font size."
2074 (ly:stencil-translate-axis
2075 (interpret-markup layout props arg)
2076 (* -0.5 baseline-skip)
2079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2083 (define-builtin-markup-command (hbracket layout props arg)
2088 @cindex placing horizontal brackets around text
2090 Draw horizontal brackets around @var{arg}."
2091 (let ((th 0.1) ;; todo: take from GROB.
2092 (m (interpret-markup layout props arg)))
2093 (bracketify-stencil m X th (* 2.5 th) th)))
2095 (define-builtin-markup-command (bracket layout props arg)
2100 @cindex placing vertical brackets around text
2102 Draw vertical brackets around @var{arg}.
2104 @lilypond[verbatim,quote]
2105 \\markup \\bracket \\note #\"2.\" #UP
2107 (let ((th 0.1) ;; todo: take from GROB.
2108 (m (interpret-markup layout props arg)))
2109 (bracketify-stencil m Y th (* 2.5 th) th)))
2111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2112 ;; Delayed markup evaluation
2113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2115 (define-builtin-markup-command (page-ref layout props label gauge default)
2116 (symbol? markup? markup?)
2120 @cindex referencing page numbers in text
2122 Reference to a page number. @var{label} is the label set on the referenced
2123 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
2124 the maximum width of the page number, and @var{default} the value to display
2125 when @var{label} is not found."
2126 (let* ((gauge-stencil (interpret-markup layout props gauge))
2127 (x-ext (ly:stencil-extent gauge-stencil X))
2128 (y-ext (ly:stencil-extent gauge-stencil Y)))
2130 `(delay-stencil-evaluation
2131 ,(delay (ly:stencil-expr
2132 (let* ((table (ly:output-def-lookup layout 'label-page-table))
2133 (label-page (and (list? table) (assoc label table)))
2134 (page-number (and label-page (cdr label-page)))
2135 (page-markup (if page-number (format "~a" page-number) default))
2136 (page-stencil (interpret-markup layout props page-markup))
2137 (gap (- (interval-length x-ext)
2138 (interval-length (ly:stencil-extent page-stencil X)))))
2139 (interpret-markup layout props
2140 (markup #:concat (#:hspace gap page-markup)))))))
2144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2145 ;; Markup list commands
2146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2148 (define-public (space-lines baseline-skip lines)
2150 (stack-lines DOWN 0.0 (/ baseline-skip 2.0)
2156 (define-builtin-markup-list-command (justified-lines layout props args)
2159 wordwrap-internal-markup-list)
2161 @cindex justifying lines of text
2163 Like @code{\\justify}, but return a list of lines instead of a single markup.
2164 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
2165 @var{X}@tie{}is the number of staff spaces."
2166 (space-lines baseline-skip
2167 (interpret-markup-list layout props
2168 (make-wordwrap-internal-markup-list #t args))))
2170 (define-builtin-markup-list-command (wordwrap-lines layout props args)
2173 wordwrap-internal-markup-list)
2174 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
2175 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
2176 where @var{X} is the number of staff spaces."
2177 (space-lines baseline-skip
2178 (interpret-markup-list layout props
2179 (make-wordwrap-internal-markup-list #f args))))
2181 (define-builtin-markup-list-command (column-lines layout props args)
2184 "Like @code{\\column}, but return a list of lines instead of a single markup.
2185 @code{baseline-skip} determines the space between each markup in @var{args}."
2186 (space-lines (chain-assoc-get 'baseline-skip props)
2187 (interpret-markup-list layout props args)))
2189 (define-builtin-markup-list-command (override-lines layout props new-prop args)
2190 (pair? markup-list?)
2192 "Like @code{\\override}, for markup lists."
2193 (interpret-markup-list layout (cons (list new-prop) props) args))