1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (define-builtin-markup-command (draw-line layout props dest)
31 @cindex drawing lines within text
34 @lilypond[verbatim,quote]
37 \\override #'(thickness . 5)
38 \\draw-line #'(-3 . 0)
41 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
50 (cons (min x 0) (max x 0))
51 (cons (min y 0) (max y 0)))))
53 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
54 (number? number? boolean?)
58 @cindex drawing circles within text
60 A circle of radius @var{radius}, thickness @var{thickness} and
63 @lilypond[verbatim,quote]
65 \\draw-circle #2 #0.5 ##f
67 \\draw-circle #2 #0 ##t
70 (make-circle-stencil radius thickness fill))
72 (define-builtin-markup-command (triangle layout props filled)
79 @cindex drawing triangles within text
81 A triangle, either filled or empty.
83 @lilypond[verbatim,quote]
90 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
99 (cons 0 (* .86 ex)))))
101 (define-builtin-markup-command (circle layout props arg)
106 (circle-padding 0.2))
108 @cindex circling text
110 Draw a circle around @var{arg}. Use @code{thickness},
111 @code{circle-padding} and @code{font-size} properties to determine line
112 thickness and padding around the markup.
114 @lilypond[verbatim,quote]
121 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
123 (pad (* (magstep font-size) circle-padding))
124 (m (interpret-markup layout props arg)))
125 (circle-stencil m th pad)))
127 (define-builtin-markup-command (with-url layout props url arg)
132 @cindex inserting URL links into text
134 Add a link to URL @var{url} around @var{arg}. This only works in
137 @lilypond[verbatim,quote]
139 \\with-url #\"http://lilypond.org/web/\" {
140 LilyPond ... \\italic {
141 music notation for everyone
146 (let* ((stil (interpret-markup layout props arg))
147 (xextent (ly:stencil-extent stil X))
148 (yextent (ly:stencil-extent stil Y))
149 (old-expr (ly:stencil-expr stil))
150 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
152 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
154 (define-builtin-markup-command (beam layout props width slope thickness)
155 (number? number? number?)
159 @cindex drawing beams within text
161 Create a beam with the specified parameters.
162 @lilypond[verbatim,quote]
167 (let* ((y (* slope width))
168 (yext (cons (min 0 y) (max 0 y)))
169 (half (/ thickness 2)))
174 width (+ (* width slope) (/ thickness -2))
175 width (+ (* width slope) (/ thickness 2))
177 ,(ly:output-def-lookup layout 'blot-diameter)
180 (cons (+ (- half) (car yext))
181 (+ half (cdr yext))))))
183 (define-builtin-markup-command (underline layout props arg)
188 @cindex underlining text
190 Underline @var{arg}. Looks at @code{thickness} to determine line
191 thickness and y offset.
193 @lilypond[verbatim,quote]
197 \\override #'(thickness . 2)
203 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
205 (markup (interpret-markup layout props arg))
206 (x1 (car (ly:stencil-extent markup X)))
207 (x2 (cdr (ly:stencil-extent markup X)))
209 (line (ly:make-stencil
210 `(draw-line ,thick ,x1 ,y ,x2 ,y)
211 (cons (min x1 0) (max x2 0))
212 (cons thick thick))))
213 (ly:stencil-add markup line)))
215 (define-builtin-markup-command (box layout props arg)
222 @cindex enclosing text within a box
224 Draw a box round @var{arg}. Looks at @code{thickness},
225 @code{box-padding} and @code{font-size} properties to determine line
226 thickness and padding around the markup.
228 @lilypond[verbatim,quote]
230 \\override #'(box-padding . 0.5)
235 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
237 (pad (* (magstep font-size) box-padding))
238 (m (interpret-markup layout props arg)))
239 (box-stencil m th pad)))
241 (define-builtin-markup-command (filled-box layout props xext yext blot)
242 (number-pair? number-pair? number?)
246 @cindex drawing solid boxes within text
247 @cindex drawing boxes with rounded corners
249 Draw a box with rounded corners of dimensions @var{xext} and
250 @var{yext}. For example,
252 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
254 creates a box extending horizontally from -0.3 to 1.8 and
255 vertically from -0.3 up to 1.8, with corners formed from a
256 circle of diameter@tie{}0 (i.e. sharp corners).
258 @lilypond[verbatim,quote]
260 \\filled-box #'(0 . 4) #'(0 . 4) #0
261 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
262 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
264 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
270 (define-builtin-markup-command (rounded-box layout props arg)
277 "@cindex enclosing text in a box with rounded corners
278 @cindex drawing boxes with rounded corners around text
279 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
280 @code{box-padding} and @code{font-size} properties to determine line
281 thickness and padding around the markup; the @code{corner-radius} property
282 makes it possible to define another shape for the corners (default is 1).
284 @lilypond[quote,verbatim,relative=2]
292 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
294 (pad (* (magstep font-size) box-padding))
295 (m (interpret-markup layout props arg)))
296 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
299 (define-builtin-markup-command (rotate layout props ang arg)
304 @cindex rotating text
306 Rotate object with @var{ang} degrees around its center.
308 @lilypond[verbatim,quote]
318 (let* ((stil (interpret-markup layout props arg)))
319 (ly:stencil-rotate stil ang 0 0)))
321 (define-builtin-markup-command (whiteout layout props arg)
326 @cindex adding a white background to text
328 Provide a white background for @var{arg}.
330 @lilypond[verbatim,quote]
333 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
337 (stencil-whiteout (interpret-markup layout props arg)))
339 (define-builtin-markup-command (pad-markup layout props padding arg)
345 @cindex putting space around text
347 Add space around a markup object.
349 @lilypond[verbatim,quote]
363 ((stil (interpret-markup layout props arg))
364 (xext (ly:stencil-extent stil X))
365 (yext (ly:stencil-extent stil Y)))
368 (ly:stencil-expr stil)
369 (interval-widen xext padding)
370 (interval-widen yext padding))))
372 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
374 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376 (define-builtin-markup-command (strut layout props)
381 @cindex creating vertical spaces in text
383 Create a box of the same height as the space in the current font."
384 (let ((m (ly:text-interface::interpret-markup layout props " ")))
385 (ly:make-stencil (ly:stencil-expr m)
387 (ly:stencil-extent m X)
390 ;; todo: fix negative space
391 (define-builtin-markup-command (hspace layout props amount)
396 @cindex creating horizontal spaces in text
398 This produces an invisible object taking horizontal space. For example,
401 \\markup @{ A \\hspace #2.0 B @}
405 puts extra space between A and@tie{}B, on top of the space that is
406 normally inserted before elements on a line.
408 @lilypond[verbatim,quote]
418 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
419 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
423 ;; importing graphics.
424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426 (define-builtin-markup-command (stencil layout props stil)
431 @cindex importing stencils into text
433 Use a stencil as markup.
435 @lilypond[verbatim,quote]
437 \\stencil #(make-circle-stencil 2 0 #t)
443 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
445 (define (get-postscript-bbox string)
446 "Extract the bbox from STRING, or return #f if not present."
448 ((match (regexp-exec bbox-regexp string)))
452 (string->number (match:substring match x)))
457 (define-builtin-markup-command (epsfile layout props axis size file-name)
458 (number? number? string?)
462 @cindex inlining an Encapsulated PostScript image
464 Inline an EPS image. The image is scaled along @var{axis} to
467 @lilypond[verbatim,quote]
469 \\general-align #Y #DOWN {
470 \\epsfile #X #20 #\"context-example.eps\"
471 \\epsfile #Y #20 #\"context-example.eps\"
475 (if (ly:get-option 'safe)
476 (interpret-markup layout props "not allowed in safe")
477 (eps-file->stencil axis size file-name)
480 (define-builtin-markup-command (postscript layout props str)
485 @cindex inserting PostScript directly into text
487 This inserts @var{str} directly into the output as a PostScript
488 command string. Due to technicalities of the output backends,
489 different scales should be used for the @TeX{} and PostScript backend,
490 selected with @code{-f}.
492 For the @TeX{} backend, the following string prints a rotated text
495 0 0 moveto /ecrm10 findfont
496 1.75 scalefont setfont 90 rotate (hello) show
500 The magical constant 1.75 scales from LilyPond units (staff spaces) to
503 For the postscript backend, use the following
506 gsave /ecrm10 findfont
507 10.0 output-scale div
508 scalefont setfont 90 rotate (hello) show grestore
511 @lilypond[verbatim,quote]
517 0.7 0.7 0.5 0 361 arc
519 2.20 0.70 0.50 0 361 arc
521 1.45 0.85 0.30 0 180 arc
525 0.92 2.26 1.30 2.40 1.15 1.70 curveto
529 3.42 2.26 3.80 2.40 3.65 1.70 curveto
532 eyeglasses = \\markup {
533 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
534 \\postscript #eyeglassesps
546 gsave currentpoint translate
554 (define-builtin-markup-command (score layout props score)
559 @cindex inserting music into text
561 Inline an image of music.
563 @lilypond[verbatim,quote]
567 \\new Staff \\relative c' {
570 \\mark \\markup { Allegro }
576 \\new Staff \\relative c {
590 \\override RehearsalMark #'break-align-symbols =
591 #'(time-signature key-signature)
592 \\override RehearsalMark #'self-alignment-X = #LEFT
596 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
602 (let* ((output (ly:score-embedded-format score layout)))
604 (if (ly:music-output? output)
605 (paper-system-stencil
606 (vector-ref (ly:paper-score-paper-systems output) 0))
608 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
611 (define-builtin-markup-command (null layout props)
616 @cindex creating empty text objects
618 An empty markup with extents of a single point.
620 @lilypond[verbatim,quote]
627 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
629 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631 (define-builtin-markup-command (simple layout props str)
636 @cindex simple text strings
638 A simple text string; @code{\\markup @{ foo @}} is equivalent with
639 @code{\\markup @{ \\simple #\"foo\" @}}.
641 Note: for creating standard text markup or defining new markup commands,
642 the use of @code{\\simple} is unnecessary.
644 @lilypond[verbatim,quote]
648 \\simple #\"strings\"
651 (interpret-markup layout props str))
653 (define-builtin-markup-command (tied-lyric layout props str)
658 @cindex simple text strings with tie characters
660 Like simple-markup, but use tie characters for @q{~} tilde symbols.
662 @lilypond[verbatim,quote]
664 \\tied-lyric #\"Lasciate~i monti\"
667 (if (string-contains str "~")
669 ((parts (string-split str #\~))
670 (tie-str (ly:wide-char->utf-8 #x203f))
671 (joined (list-join parts tie-str))
672 (join-stencil (interpret-markup layout props tie-str))
675 (interpret-markup layout
678 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
680 (make-line-markup joined)))
681 ;(map (lambda (s) (interpret-markup layout props s)) parts))
682 (interpret-markup layout props str)))
684 (define-public empty-markup
685 (make-simple-markup ""))
687 ;; helper for justifying lines.
688 (define (get-fill-space word-count line-width text-widths)
689 "Calculate the necessary paddings between each two adjacent texts.
690 The lengths of all texts are stored in @var{text-widths}.
691 The normal formula for the padding between texts a and b is:
692 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
693 The first and last padding have to be calculated specially using the
694 whole length of the first or last text.
695 Return a list of paddings."
697 ((null? text-widths) '())
699 ;; special case first padding
700 ((= (length text-widths) word-count)
702 (- (- (/ line-width (1- word-count)) (car text-widths))
703 (/ (car (cdr text-widths)) 2))
704 (get-fill-space word-count line-width (cdr text-widths))))
705 ;; special case last padding
706 ((= (length text-widths) 2)
707 (list (- (/ line-width (1- word-count))
708 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
711 (- (/ line-width (1- word-count))
712 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
713 (get-fill-space word-count line-width (cdr text-widths))))))
715 (define-builtin-markup-command (fill-line layout props markups)
718 ((text-direction RIGHT)
721 "Put @var{markups} in a horizontal line of width @var{line-width}.
722 The markups are spaced or flushed to fill the entire line.
723 If there are no arguments, return an empty stencil.
725 @lilypond[verbatim,quote]
729 Words evenly spaced across the page
733 \\line { Text markups }
735 \\italic { evenly spaced }
737 \\line { across the page }
742 (let* ((orig-stencils (interpret-markup-list layout props markups))
745 (if (ly:stencil-empty? stc)
747 stc)) orig-stencils))
750 (if (ly:stencil-empty? stc)
752 (interval-length (ly:stencil-extent stc X))))
754 (text-width (apply + text-widths))
755 (word-count (length stencils))
756 (prop-line-width (chain-assoc-get 'line-width props #f))
757 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
762 (/ (- line-width text-width) 2)
763 (/ (- line-width text-width) 2)))
766 (- line-width text-width)))
768 (get-fill-space word-count line-width text-widths))))
776 (line-stencils (if (= word-count 1)
783 (if (= text-direction LEFT)
784 (set! line-stencils (reverse line-stencils)))
786 (if (null? (remove ly:stencil-empty? orig-stencils))
788 (stack-stencils-padding-list X
789 RIGHT fill-space-normal line-stencils))))
791 (define-builtin-markup-command (line layout props args)
795 (text-direction RIGHT))
796 "Put @var{args} in a horizontal line. The property @code{word-space}
797 determines the space between each markup in @var{args}.
799 @lilypond[verbatim,quote]
806 (let ((stencils (interpret-markup-list layout props args)))
807 (if (= text-direction LEFT)
808 (set! stencils (reverse stencils)))
811 (remove ly:stencil-empty? stencils))))
813 (define-builtin-markup-command (concat layout props args)
818 @cindex concatenating text
819 @cindex ligatures in text
821 Concatenate @var{args} in a horizontal line, without spaces inbetween.
822 Strings and simple markups are concatenated on the input level, allowing
823 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
824 equivalent to @code{\"fi\"}.
826 @lilypond[verbatim,quote]
835 (define (concat-string-args arg-list)
836 (fold-right (lambda (arg result-list)
837 (let ((result (if (pair? result-list)
840 (if (and (pair? arg) (eqv? (car arg) simple-markup))
841 (set! arg (cadr arg)))
842 (if (and (string? result) (string? arg))
843 (cons (string-append arg result) (cdr result-list))
844 (cons arg result-list))))
848 (interpret-markup layout
849 (prepend-alist-chain 'word-space 0 props)
850 (make-line-markup (if (markup-command-list? args)
852 (concat-string-args args)))))
854 (define (wordwrap-stencils stencils
855 justify base-space line-width text-dir)
856 "Perform simple wordwrap, return stencil of each line."
857 (define space (if justify
858 ;; justify only stretches lines.
861 (define (take-list width space stencils
862 accumulator accumulated-width)
863 "Return (head-list . tail) pair, with head-list fitting into width"
865 (cons accumulator stencils)
866 (let* ((first (car stencils))
867 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
868 (newwid (+ space first-wid accumulated-width)))
869 (if (or (null? accumulator)
871 (take-list width space
873 (cons first accumulator)
875 (cons accumulator stencils)))))
876 (let loop ((lines '())
878 (let* ((line-break (take-list line-width space todo
880 (line-stencils (car line-break))
881 (space-left (- line-width
882 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
884 (line-word-space (cond ((not justify) space)
885 ;; don't stretch last line of paragraph.
886 ;; hmmm . bug - will overstretch the last line in some case.
887 ((null? (cdr line-break))
889 ((null? line-stencils) 0.0)
890 ((null? (cdr line-stencils)) 0.0)
891 (else (/ space-left (1- (length line-stencils))))))
892 (line (stack-stencil-line line-word-space
893 (if (= text-dir RIGHT)
894 (reverse line-stencils)
896 (if (pair? (cdr line-break))
897 (loop (cons line lines)
900 (if (= text-dir LEFT)
902 (ly:stencil-translate-axis
904 (- line-width (interval-end (ly:stencil-extent line X)))
906 (reverse (cons line lines)))))))
908 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
909 (boolean? markup-list?)
912 (text-direction RIGHT))
913 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
914 (wordwrap-stencils (remove ly:stencil-empty?
915 (interpret-markup-list layout props args))
919 (ly:output-def-lookup layout 'line-width))
922 (define-builtin-markup-command (justify layout props args)
926 wordwrap-internal-markup-list)
928 @cindex justifying text
930 Like wordwrap, but with lines stretched to justify the margins.
931 Use @code{\\override #'(line-width . @var{X})} to set the line width;
932 @var{X}@tie{}is the number of staff spaces.
934 @lilypond[verbatim,quote]
937 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
938 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
939 Ut enim ad minim veniam, quis nostrud exercitation ullamco
940 laboris nisi ut aliquip ex ea commodo consequat.
944 (stack-lines DOWN 0.0 baseline-skip
945 (wordwrap-internal-markup-list layout props #t args)))
947 (define-builtin-markup-command (wordwrap layout props args)
951 wordwrap-internal-markup-list)
952 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
953 the line width, where @var{X} is the number of staff spaces.
955 @lilypond[verbatim,quote]
958 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
959 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
960 Ut enim ad minim veniam, quis nostrud exercitation ullamco
961 laboris nisi ut aliquip ex ea commodo consequat.
965 (stack-lines DOWN 0.0 baseline-skip
966 (wordwrap-internal-markup-list layout props #f args)))
968 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
972 (text-direction RIGHT))
973 "Internal markup list command used to define @code{\\justify-string} and
974 @code{\\wordwrap-string}."
975 (let* ((para-strings (regexp-split
976 (string-regexp-substitute
978 (string-regexp-substitute "\r\n" "\n" arg))
979 "\n[ \t\n]*\n[ \t\n]*"))
980 (list-para-words (map (lambda (str)
981 (regexp-split str "[ \t\n]+"))
983 (para-lines (map (lambda (words)
985 (remove ly:stencil-empty?
987 (interpret-markup layout props x))
989 (wordwrap-stencils stencils
991 line-width text-direction)))
993 (apply append para-lines)))
995 (define-builtin-markup-command (wordwrap-string layout props arg)
999 wordwrap-string-internal-markup-list)
1000 "Wordwrap a string. Paragraphs may be separated with double newlines.
1002 @lilypond[verbatim,quote]
1004 \\override #'(line-width . 40)
1005 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1006 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1007 et dolore magna aliqua.
1010 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1011 laboris nisi ut aliquip ex ea commodo consequat.
1014 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1015 qui officia deserunt mollit anim id est laborum\"
1018 (stack-lines DOWN 0.0 baseline-skip
1019 (wordwrap-string-internal-markup-list layout props #f arg)))
1021 (define-builtin-markup-command (justify-string layout props arg)
1025 wordwrap-string-internal-markup-list)
1026 "Justify a string. Paragraphs may be separated with double newlines
1028 @lilypond[verbatim,quote]
1030 \\override #'(line-width . 40)
1031 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1032 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1033 et dolore magna aliqua.
1036 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1037 laboris nisi ut aliquip ex ea commodo consequat.
1040 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1041 qui officia deserunt mollit anim id est laborum\"
1044 (stack-lines DOWN 0.0 baseline-skip
1045 (wordwrap-string-internal-markup-list layout props #t arg)))
1047 (define-builtin-markup-command (wordwrap-field layout props symbol)
1051 "Wordwrap the data which has been assigned to @var{symbol}.
1053 @lilypond[verbatim,quote]
1055 title = \"My title\"
1056 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1057 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1058 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1059 nisi ut aliquip ex ea commodo consequat.\"
1063 bookTitleMarkup = \\markup {
1065 \\fill-line { \\fromproperty #'header:title }
1067 \\wordwrap-field #'header:descr
1076 (let* ((m (chain-assoc-get symbol props)))
1078 (wordwrap-string-markup layout props m)
1081 (define-builtin-markup-command (justify-field layout props symbol)
1085 "Justify the data which has been assigned to @var{symbol}.
1087 @lilypond[verbatim,quote]
1089 title = \"My title\"
1090 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1091 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1092 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1093 nisi ut aliquip ex ea commodo consequat.\"
1097 bookTitleMarkup = \\markup {
1099 \\fill-line { \\fromproperty #'header:title }
1101 \\justify-field #'header:descr
1110 (let* ((m (chain-assoc-get symbol props)))
1112 (justify-string-markup layout props m)
1115 (define-builtin-markup-command (combine layout props m1 m2)
1120 @cindex merging text
1122 Print two markups on top of each other.
1124 Note: @code{\\combine} cannot take a list of markups enclosed in
1125 curly braces as an argument; the follow example will not compile:
1128 \\combine @{ a list @}
1131 @lilypond[verbatim,quote]
1134 \\override #'(thickness . 2)
1136 \\draw-line #'(0 . 4)
1137 \\arrow-head #Y #DOWN ##f
1140 (let* ((s1 (interpret-markup layout props m1))
1141 (s2 (interpret-markup layout props m2)))
1142 (ly:stencil-add s1 s2)))
1145 ;; TODO: should extract baseline-skip from each argument somehow..
1147 (define-builtin-markup-command (column layout props args)
1152 @cindex stacking text in a column
1154 Stack the markups in @var{args} vertically. The property
1155 @code{baseline-skip} determines the space between each
1156 markup in @var{args}.
1158 @lilypond[verbatim,quote]
1167 (let ((arg-stencils (interpret-markup-list layout props args)))
1168 (stack-lines -1 0.0 baseline-skip
1169 (remove ly:stencil-empty? arg-stencils))))
1171 (define-builtin-markup-command (dir-column layout props args)
1177 @cindex changing direction of text columns
1179 Make a column of args, going up or down, depending on the setting
1180 of the @code{#'direction} layout property.
1182 @lilypond[verbatim,quote]
1184 \\override #'(direction . 1) {
1194 (stack-lines (if (number? direction) direction -1)
1197 (interpret-markup-list layout props args)))
1199 (define-builtin-markup-command (center-align layout props args)
1204 @cindex centering a column of text
1206 Put @code{args} in a centered column.
1208 @lilypond[verbatim,quote]
1217 (let* ((mols (interpret-markup-list layout props args))
1218 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
1219 (stack-lines -1 0.0 baseline-skip cmols)))
1221 (define-builtin-markup-command (vcenter layout props arg)
1226 @cindex vertically centering text
1228 Align @code{arg} to its Y@tie{}center.
1230 @lilypond[verbatim,quote]
1238 (let* ((mol (interpret-markup layout props arg)))
1239 (ly:stencil-aligned-to mol Y CENTER)))
1241 (define-builtin-markup-command (hcenter layout props arg)
1246 @cindex horizontally centering text
1248 Align @code{arg} to its X@tie{}center.
1250 @lilypond[verbatim,quote]
1260 (let* ((mol (interpret-markup layout props arg)))
1261 (ly:stencil-aligned-to mol X CENTER)))
1263 (define-builtin-markup-command (right-align layout props arg)
1268 @cindex right aligning text
1270 Align @var{arg} on its right edge.
1272 @lilypond[verbatim,quote]
1282 (let* ((m (interpret-markup layout props arg)))
1283 (ly:stencil-aligned-to m X RIGHT)))
1285 (define-builtin-markup-command (left-align layout props arg)
1290 @cindex left aligning text
1292 Align @var{arg} on its left edge.
1294 @lilypond[verbatim,quote]
1304 (let* ((m (interpret-markup layout props arg)))
1305 (ly:stencil-aligned-to m X LEFT)))
1307 (define-builtin-markup-command (general-align layout props axis dir arg)
1308 (integer? number? markup?)
1312 @cindex controlling general text alignment
1314 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1316 @lilypond[verbatim,quote]
1320 \\general-align #X #LEFT
1325 \\general-align #X #CENTER
1331 \\general-align #Y #UP
1338 \\general-align #Y #3.2
1345 (let* ((m (interpret-markup layout props arg)))
1346 (ly:stencil-aligned-to m axis dir)))
1348 (define-builtin-markup-command (halign layout props dir arg)
1353 @cindex setting horizontal text alignment
1355 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1356 left-aligned, while @code{+1} is right. Values in between interpolate
1357 alignment accordingly.
1359 @lilypond[verbatim,quote]
1384 (let* ((m (interpret-markup layout props arg)))
1385 (ly:stencil-aligned-to m X dir)))
1387 (define-builtin-markup-command (with-dimensions layout props x y arg)
1388 (number-pair? number-pair? markup?)
1392 @cindex setting extent of text objects
1394 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1395 (let* ((m (interpret-markup layout props arg)))
1396 (ly:make-stencil (ly:stencil-expr m) x y)))
1398 (define-builtin-markup-command (pad-around layout props amount arg)
1402 "Add padding @var{amount} all around @var{arg}.
1404 @lilypond[verbatim,quote]
1417 (let* ((m (interpret-markup layout props arg))
1418 (x (ly:stencil-extent m X))
1419 (y (ly:stencil-extent m Y)))
1420 (ly:make-stencil (ly:stencil-expr m)
1421 (interval-widen x amount)
1422 (interval-widen y amount))))
1424 (define-builtin-markup-command (pad-x layout props amount arg)
1429 @cindex padding text horizontally
1431 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1433 @lilypond[verbatim,quote]
1446 (let* ((m (interpret-markup layout props arg))
1447 (x (ly:stencil-extent m X))
1448 (y (ly:stencil-extent m Y)))
1449 (ly:make-stencil (ly:stencil-expr m)
1450 (interval-widen x amount)
1453 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1454 (integer? ly:dir? markup? markup?)
1457 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1458 (let ((m1 (interpret-markup layout props arg1))
1459 (m2 (interpret-markup layout props arg2)))
1460 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1462 (define-builtin-markup-command (transparent layout props arg)
1466 "Make the argument transparent.
1468 @lilypond[verbatim,quote]
1475 (let* ((m (interpret-markup layout props arg))
1476 (x (ly:stencil-extent m X))
1477 (y (ly:stencil-extent m Y)))
1478 (ly:make-stencil "" x y)))
1480 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1481 (number-pair? number-pair? markup?)
1484 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1486 @lilypond[verbatim,quote]
1493 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1499 (let* ((m (interpret-markup layout props arg))
1500 (x (ly:stencil-extent m X))
1501 (y (ly:stencil-extent m Y)))
1502 (ly:make-stencil (ly:stencil-expr m)
1503 (interval-union x-ext x)
1504 (interval-union y-ext y))))
1506 (define-builtin-markup-command (hcenter-in layout props length arg)
1510 "Center @var{arg} horizontally within a box of extending
1511 @var{length}/2 to the left and right.
1513 @lilypond[quote,verbatim]
1516 \\set Staff.instrumentName = \\markup {
1523 \\set Staff.instrumentName = \\markup {
1532 (interpret-markup layout props
1533 (make-pad-to-box-markup
1534 (cons (/ length -2) (/ length 2))
1536 (make-hcenter-markup arg))))
1538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1542 (define-builtin-markup-command (fromproperty layout props symbol)
1546 "Read the @var{symbol} from property settings, and produce a stencil
1547 from the markup contained within. If @var{symbol} is not defined, it
1548 returns an empty markup.
1550 @lilypond[verbatim,quote]
1552 myTitle = \"myTitle\"
1556 \\fromproperty #'header:myTitle
1563 (let ((m (chain-assoc-get symbol props)))
1565 (interpret-markup layout props m)
1568 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1572 "Apply the @var{procedure} markup command to @var{arg}.
1573 @var{procedure} should take a single argument."
1574 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1575 (set-object-property! anonymous-with-signature
1578 (interpret-markup layout props (list anonymous-with-signature arg))))
1580 (define-builtin-markup-command (override layout props new-prop arg)
1585 @cindex overriding properties within text markup
1587 Add the first argument in to the property list. Properties may be
1588 any sort of property supported by @rinternals{font-interface} and
1589 @rinternals{text-interface}, for example
1592 \\override #'(font-family . married) \"bla\"
1595 @lilypond[verbatim,quote]
1603 \\override #'(baseline-skip . 4) {
1612 (interpret-markup layout (cons (list new-prop) props) arg))
1614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1618 (define-builtin-markup-command (verbatim-file layout props name)
1622 "Read the contents of a file, and include it verbatim.
1624 @lilypond[verbatim,quote]
1626 \\verbatim-file #\"simple.ly\"
1629 (interpret-markup layout props
1630 (if (ly:get-option 'safe)
1631 "verbatim-file disabled in safe mode"
1632 (let* ((str (ly:gulp-file name))
1633 (lines (string-split str #\nl)))
1634 (make-typewriter-markup
1635 (make-column-markup lines))))))
1637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1641 (define-builtin-markup-command (bigger layout props arg)
1645 "Increase the font size relative to current setting.
1647 @lilypond[verbatim,quote]
1660 (interpret-markup layout props
1661 `(,fontsize-markup 1 ,arg)))
1663 (define-builtin-markup-command (smaller layout props arg)
1667 "Decrease the font size relative to current setting.
1669 @lilypond[verbatim,quote]
1682 (interpret-markup layout props
1683 `(,fontsize-markup -1 ,arg)))
1685 (define-builtin-markup-command (larger layout props arg)
1689 "Copy of the @code{\\bigger} command.
1691 @lilypond[verbatim,quote]
1699 (interpret-markup layout props (make-bigger-markup arg)))
1701 (define-builtin-markup-command (finger layout props arg)
1705 "Set the argument as small numbers.
1706 @lilypond[verbatim,quote]
1713 (interpret-markup layout
1714 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1717 (define-builtin-markup-command (abs-fontsize layout props size arg)
1721 "Use @var{size} as the absolute font size to display @var{arg}.
1722 Adjust baseline skip and word space accordingly.
1723 @lilypond[verbatim,quote]
1725 default text font size
1727 \\abs-fontsize #16 { text font size 16 }
1729 \\abs-fontsize #12 { text font size 12 }
1732 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1733 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1734 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1735 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1736 (magnification (/ size ref-size)))
1737 (interpret-markup layout
1738 (cons `((baseline-skip . ,(* magnification ref-baseline))
1739 (word-space . ,(* magnification ref-word-space))
1740 (font-size . ,(magnification->font-size magnification)))
1744 (define-builtin-markup-command (fontsize layout props increment arg)
1750 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1751 @lilypond[verbatim,quote]
1759 (let ((entries (list
1760 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1761 (cons 'word-space (* word-space (magstep increment)))
1762 (cons 'font-size (+ font-size increment)))))
1763 (interpret-markup layout (cons entries props) arg)))
1765 (define-builtin-markup-command (magnify layout props sz arg)
1770 @cindex magnifying text
1772 Set the font magnification for its argument. In the following
1773 example, the middle@tie{}A is 10% larger:
1776 A \\magnify #1.1 @{ A @} A
1779 Note: Magnification only works if a font name is explicitly selected.
1780 Use @code{\\fontsize} otherwise.
1782 @lilypond[verbatim,quote]
1793 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1796 (define-builtin-markup-command (bold layout props arg)
1800 "Switch to bold font-series.
1802 @lilypond[verbatim,quote]
1810 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1812 (define-builtin-markup-command (sans layout props arg)
1816 "Switch to the sans serif family.
1818 @lilypond[verbatim,quote]
1827 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1829 (define-builtin-markup-command (number layout props arg)
1833 "Set font family to @code{number}, which yields the font used for
1834 time signatures and fingerings. This font only contains numbers and
1835 some punctuation. It doesn't have any letters.
1837 @lilypond[verbatim,quote]
1840 0 1 2 3 4 5 6 7 8 9 . ,
1844 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1846 (define-builtin-markup-command (roman layout props arg)
1850 "Set font family to @code{roman}.
1852 @lilypond[verbatim,quote]
1858 text in roman font family
1865 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1867 (define-builtin-markup-command (huge layout props arg)
1871 "Set font size to +2.
1873 @lilypond[verbatim,quote]
1881 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1883 (define-builtin-markup-command (large layout props arg)
1887 "Set font size to +1.
1889 @lilypond[verbatim,quote]
1897 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1899 (define-builtin-markup-command (normalsize layout props arg)
1903 "Set font size to default.
1905 @lilypond[verbatim,quote]
1918 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1920 (define-builtin-markup-command (small layout props arg)
1924 "Set font size to -1.
1926 @lilypond[verbatim,quote]
1934 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1936 (define-builtin-markup-command (tiny layout props arg)
1940 "Set font size to -2.
1942 @lilypond[verbatim,quote]
1950 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1952 (define-builtin-markup-command (teeny layout props arg)
1956 "Set font size to -3.
1958 @lilypond[verbatim,quote]
1966 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1968 (define-builtin-markup-command (fontCaps layout props arg)
1972 "Set @code{font-shape} to @code{caps}
1974 Note: @code{\\fontCaps} requires the installation and selection of
1975 fonts which support the @code{caps} font shape."
1976 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1979 (define-builtin-markup-command (smallCaps layout props text)
1983 "Emit @var{arg} as small caps.
1985 Note: @code{\\smallCaps} does not support accented characters.
1987 @lilypond[verbatim,quote]
1996 (define (char-list->markup chars lower)
1997 (let ((final-string (string-upcase (reverse-list->string chars))))
1999 (markup #:fontsize -2 final-string)
2001 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2002 (if (null? rest-chars)
2004 (reverse! (cons (char-list->markup currents current-is-lower)
2006 (let* ((ch (car rest-chars))
2007 (is-lower (char-lower-case? ch)))
2008 (if (or (and current-is-lower is-lower)
2009 (and (not current-is-lower) (not is-lower)))
2010 (make-small-caps (cdr rest-chars)
2014 (make-small-caps (cdr rest-chars)
2017 (if (null? currents)
2019 (cons (char-list->markup
2020 currents current-is-lower)
2022 (interpret-markup layout props
2024 (make-small-caps (string->list text) (list) #f (list))
2027 (define-builtin-markup-command (caps layout props arg)
2031 "Copy of the @code{\\smallCaps} command.
2033 @lilypond[verbatim,quote]
2042 (interpret-markup layout props (make-smallCaps-markup arg)))
2044 (define-builtin-markup-command (dynamic layout props arg)
2048 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2049 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2050 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2051 done in a different font. The recommended font for this is bold and italic.
2052 @lilypond[verbatim,quote]
2060 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2062 (define-builtin-markup-command (text layout props arg)
2066 "Use a text font instead of music symbol or music alphabet font.
2068 @lilypond[verbatim,quote]
2081 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2084 (define-builtin-markup-command (italic layout props arg)
2088 "Use italic @code{font-shape} for @var{arg}.
2090 @lilypond[verbatim,quote]
2098 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2100 (define-builtin-markup-command (typewriter layout props arg)
2104 "Use @code{font-family} typewriter for @var{arg}.
2106 @lilypond[verbatim,quote]
2115 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2117 (define-builtin-markup-command (upright layout props arg)
2121 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
2123 @lilypond[verbatim,quote]
2137 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2139 (define-builtin-markup-command (medium layout props arg)
2143 "Switch to medium font series (in contrast to bold).
2145 @lilypond[verbatim,quote]
2158 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2161 (define-builtin-markup-command (normal-text layout props arg)
2165 "Set all font related properties (except the size) to get the default
2166 normal text font, no matter what font was used earlier.
2168 @lilypond[verbatim,quote]
2170 \\huge \\bold \\sans \\caps {
2171 Some text with font overrides
2174 Default text, same font-size
2182 (interpret-markup layout
2183 (cons '((font-family . roman) (font-shape . upright)
2184 (font-series . medium) (font-encoding . latin1))
2188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2190 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2192 (define-builtin-markup-command (doublesharp layout props)
2196 "Draw a double sharp symbol.
2198 @lilypond[verbatim,quote]
2203 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2205 (define-builtin-markup-command (sesquisharp layout props)
2209 "Draw a 3/2 sharp symbol.
2211 @lilypond[verbatim,quote]
2216 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2218 (define-builtin-markup-command (sharp layout props)
2222 "Draw a sharp symbol.
2224 @lilypond[verbatim,quote]
2229 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2231 (define-builtin-markup-command (semisharp layout props)
2235 "Draw a semi sharp symbol.
2237 @lilypond[verbatim,quote]
2242 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2244 (define-builtin-markup-command (natural layout props)
2248 "Draw a natural symbol.
2250 @lilypond[verbatim,quote]
2255 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2257 (define-builtin-markup-command (semiflat layout props)
2261 "Draw a semiflat symbol.
2263 @lilypond[verbatim,quote]
2268 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2270 (define-builtin-markup-command (flat layout props)
2274 "Draw a flat symbol.
2276 @lilypond[verbatim,quote]
2281 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2283 (define-builtin-markup-command (sesquiflat layout props)
2287 "Draw a 3/2 flat symbol.
2289 @lilypond[verbatim,quote]
2294 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2296 (define-builtin-markup-command (doubleflat layout props)
2300 "Draw a double flat symbol.
2302 @lilypond[verbatim,quote]
2307 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2309 (define-builtin-markup-command (with-color layout props color arg)
2314 @cindex coloring text
2316 Draw @var{arg} in color specified by @var{color}.
2318 @lilypond[verbatim,quote]
2330 (let ((stil (interpret-markup layout props arg)))
2331 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2332 (ly:stencil-extent stil X)
2333 (ly:stencil-extent stil Y))))
2335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2339 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2340 (integer? ly:dir? boolean?)
2343 "Produce an arrow head in specified direction and axis.
2344 Use the filled head if @var{filled} is specified.
2345 @lilypond[verbatim,quote]
2348 \\general-align #Y #DOWN {
2349 \\arrow-head #Y #UP ##t
2350 \\arrow-head #Y #DOWN ##f
2352 \\arrow-head #X #RIGHT ##f
2353 \\arrow-head #X #LEFT ##f
2359 ((name (format "arrowheads.~a.~a~a"
2366 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2370 (define-builtin-markup-command (musicglyph layout props glyph-name)
2374 "@var{glyph-name} is converted to a musical symbol; for example,
2375 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2376 the music font. See @ruser{The Feta font} for a complete listing of
2377 the possible glyphs.
2379 @lilypond[verbatim,quote]
2382 \\musicglyph #\"rests.2\"
2383 \\musicglyph #\"clefs.G_change\"
2386 (let* ((font (ly:paper-get-font layout
2387 (cons '((font-encoding . fetaMusic)
2391 (glyph (ly:font-get-glyph font glyph-name)))
2392 (if (null? (ly:stencil-expr glyph))
2393 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2398 (define-builtin-markup-command (lookup layout props glyph-name)
2402 "Lookup a glyph by name.
2404 @lilypond[verbatim,quote]
2406 \\override #'(font-encoding . fetaBraces) {
2407 \\lookup #\"brace200\"
2410 \\lookup #\"brace180\"
2414 (ly:font-get-glyph (ly:paper-get-font layout props)
2417 (define-builtin-markup-command (char layout props num)
2421 "Produce a single character. For example, @code{\\char #65} produces the
2424 @lilypond[verbatim,quote]
2429 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2431 (define number->mark-letter-vector (make-vector 25 #\A))
2436 (if (= i (- (char->integer #\I) (char->integer #\A)))
2438 (vector-set! number->mark-letter-vector j
2439 (integer->char (+ i (char->integer #\A)))))
2441 (define number->mark-alphabet-vector (list->vector
2442 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2444 (define (number->markletter-string vec n)
2445 "Double letters for big marks."
2446 (let* ((lst (vector-length vec)))
2449 (string-append (number->markletter-string vec (1- (quotient n lst)))
2450 (number->markletter-string vec (remainder n lst)))
2451 (make-string 1 (vector-ref vec n)))))
2453 (define-builtin-markup-command (markletter layout props num)
2457 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2458 (skipping letter@tie{}I), and continue with double letters.
2460 @lilypond[verbatim,quote]
2467 (ly:text-interface::interpret-markup layout props
2468 (number->markletter-string number->mark-letter-vector num)))
2470 (define-builtin-markup-command (markalphabet layout props num)
2474 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2475 and continue with double letters.
2477 @lilypond[verbatim,quote]
2484 (ly:text-interface::interpret-markup layout props
2485 (number->markletter-string number->mark-alphabet-vector num)))
2487 (define-public (horizontal-slash-interval num forward number-interval mag)
2489 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2490 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2491 (else (interval-widen number-interval (* mag 0.25))))
2492 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2493 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2494 (else (interval-widen number-interval (* mag 0.25))))
2497 (define-public (adjust-slash-stencil num forward stencil mag)
2500 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2502 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2504 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2506 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2509 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2511 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2516 (define (slashed-digit-internal layout props num forward font-size thickness)
2517 (let* ((mag (magstep font-size))
2519 (ly:output-def-lookup layout 'line-thickness)
2521 ; backward slashes might use slope and point in the other direction!
2522 (dy (* mag (if forward 0.4 -0.4)))
2523 (number-stencil (interpret-markup layout
2524 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2525 (number->string num)))
2526 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2527 (center (interval-center (ly:stencil-extent number-stencil Y)))
2528 ; Use the real extents of the slash, not the whole number, because we
2529 ; might translate the slash later on!
2530 (num-y (interval-widen (cons center center) (abs dy)))
2531 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2532 (slash-stencil (if is-sane
2534 `(draw-line ,thickness
2535 ,(car num-x) ,(- (interval-center num-y) dy)
2536 ,(cdr num-x) ,(+ (interval-center num-y) dy))
2539 (if (ly:stencil? slash-stencil)
2541 ; for some numbers we need to shift the slash/backslash up or down to make
2542 ; the slashed digit look better
2543 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2544 (set! number-stencil
2545 (ly:stencil-add number-stencil slash-stencil)))
2546 (ly:warning "Unable to create slashed digit ~a" num))
2550 (define-builtin-markup-command (slashed-digit layout props num)
2556 @cindex slashed digits
2558 A feta number, with slash. This is for use in the context of
2559 figured bass notation.
2560 @lilypond[verbatim,quote]
2564 \\override #'(thickness . 3)
2568 (slashed-digit-internal layout props num #t font-size thickness))
2570 (define-builtin-markup-command (backslashed-digit layout props num)
2576 @cindex backslashed digits
2578 A feta number, with backslash. This is for use in the context of
2579 figured bass notation.
2580 @lilypond[verbatim,quote]
2582 \\backslashed-digit #5
2584 \\override #'(thickness . 3)
2585 \\backslashed-digit #7
2588 (slashed-digit-internal layout props num #f font-size thickness))
2590 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2591 ;; the note command.
2592 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2594 ;; TODO: better syntax.
2596 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2597 (number? number? number?)
2602 @cindex notes within text by log and dot-count
2604 Construct a note symbol, with stem. By using fractional values for
2605 @var{dir}, you can obtain longer or shorter stems.
2607 @lilypond[verbatim,quote]
2609 \\note-by-number #3 #0 #DOWN
2611 \\note-by-number #1 #2 #0.8
2614 (define (get-glyph-name-candidates dir log style)
2615 (map (lambda (dir-name)
2616 (format "noteheads.~a~a~a" dir-name (min log 2)
2617 (if (and (symbol? style)
2618 (not (equal? 'default style)))
2619 (symbol->string style)
2621 (list (if (= dir UP) "u" "d")
2624 (define (get-glyph-name font cands)
2627 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2628 (get-glyph-name font (cdr cands))
2631 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2632 (size-factor (magstep font-size))
2633 (stem-length (* size-factor (max 3 (- log 1))))
2634 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2635 (head-glyph (ly:font-get-glyph font head-glyph-name))
2636 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2637 (stem-thickness (* size-factor 0.13))
2638 (stemy (* dir stem-length))
2639 (attach-off (cons (interval-index
2640 (ly:stencil-extent head-glyph X)
2641 (* (sign dir) (car attach-indices)))
2642 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2644 (ly:stencil-extent head-glyph Y)
2645 (cdr attach-indices)))))
2646 (stem-glyph (and (> log 0)
2647 (ly:round-filled-box
2648 (ordered-cons (car attach-off)
2649 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2650 (cons (min stemy (cdr attach-off))
2651 (max stemy (cdr attach-off)))
2652 (/ stem-thickness 3))))
2654 (dot (ly:font-get-glyph font "dots.dot"))
2655 (dotwid (interval-length (ly:stencil-extent dot X)))
2656 (dots (and (> dot-count 0)
2657 (apply ly:stencil-add
2659 (ly:stencil-translate-axis
2660 dot (* 2 x dotwid) X))
2661 (iota dot-count)))))
2662 (flaggl (and (> log 2)
2663 (ly:stencil-translate
2664 (ly:font-get-glyph font
2665 (string-append "flags."
2666 (if (> dir 0) "u" "d")
2667 (number->string log)))
2668 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2670 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2671 ; 16th notes get a special case because their flags hang lower than any other flags.
2672 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2673 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2675 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2676 (if (ly:stencil? stem-glyph)
2677 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2678 (set! stem-glyph head-glyph))
2679 (if (ly:stencil? dots)
2682 (ly:stencil-translate-axis
2684 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2690 (let ((divisor (log 2)))
2691 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2693 (define (parse-simple-duration duration-string)
2694 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2695 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2696 (if (and match (string=? duration-string (match:substring match 0)))
2697 (let ((len (match:substring match 1))
2698 (dots (match:substring match 2)))
2699 (list (cond ((string=? len "breve") -1)
2700 ((string=? len "longa") -2)
2701 ((string=? len "maxima") -3)
2702 (else (log2 (string->number len))))
2703 (if dots (string-length dots) 0)))
2704 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2706 (define-builtin-markup-command (note layout props duration dir)
2709 (note-by-number-markup)
2711 @cindex notes within text by string
2713 This produces a note with a stem pointing in @var{dir} direction, with
2714 the @var{duration} for the note head type and augmentation dots. For
2715 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2716 a shortened down stem.
2718 @lilypond[verbatim,quote]
2720 \\override #'(style . cross) {
2724 \\note #\"breve\" #0
2727 (let ((parsed (parse-simple-duration duration)))
2728 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2730 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2734 (define-builtin-markup-command (lower layout props amount arg)
2739 @cindex lowering text
2741 Lower @var{arg} by the distance @var{amount}.
2742 A negative @var{amount} indicates raising; see also @code{\\raise}.
2744 @lilypond[verbatim,quote]
2752 (ly:stencil-translate-axis (interpret-markup layout props arg)
2755 (define-builtin-markup-command (translate-scaled layout props offset arg)
2756 (number-pair? markup?)
2760 @cindex translating text
2761 @cindex scaling text
2763 Translate @var{arg} by @var{offset}, scaling the offset by the
2766 @lilypond[verbatim,quote]
2769 * \\translate #'(2 . 3) translate
2771 * \\translate-scaled #'(2 . 3) translate-scaled
2775 (let* ((factor (magstep font-size))
2776 (scaled (cons (* factor (car offset))
2777 (* factor (cdr offset)))))
2778 (ly:stencil-translate (interpret-markup layout props arg)
2781 (define-builtin-markup-command (raise layout props amount arg)
2786 @cindex raising text
2788 Raise @var{arg} by the distance @var{amount}.
2789 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2791 The argument to @code{\\raise} is the vertical displacement amount,
2792 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2793 raise objects in relation to their surrounding markups.
2795 If the text object itself is positioned above or below the staff, then
2796 @code{\\raise} cannot be used to move it, since the mechanism that
2797 positions it next to the staff cancels any shift made with
2798 @code{\\raise}. For vertical positioning, use the @code{padding}
2799 and/or @code{extra-offset} properties.
2801 @lilypond[verbatim,quote]
2810 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2812 (define-builtin-markup-command (fraction layout props arg1 arg2)
2817 @cindex creating text fractions
2819 Make a fraction of two markups.
2820 @lilypond[verbatim,quote]
2826 (let* ((m1 (interpret-markup layout props arg1))
2827 (m2 (interpret-markup layout props arg2))
2828 (factor (magstep font-size))
2829 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2830 (padding (* factor 0.2))
2831 (baseline (* factor 0.6))
2832 (offset (* factor 0.75)))
2833 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2834 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2835 (let* ((x1 (ly:stencil-extent m1 X))
2836 (x2 (ly:stencil-extent m2 X))
2837 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2838 ;; should stack mols separately, to maintain LINE on baseline
2839 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2841 (ly:stencil-aligned-to stack Y CENTER))
2843 (ly:stencil-aligned-to stack X LEFT))
2844 ;; should have EX dimension
2846 (ly:stencil-translate-axis stack offset Y))))
2848 (define-builtin-markup-command (normal-size-super layout props arg)
2853 @cindex setting superscript in standard font size
2855 Set @var{arg} in superscript with a normal font size.
2857 @lilypond[verbatim,quote]
2860 \\normal-size-super {
2861 superscript in standard size
2865 (ly:stencil-translate-axis
2866 (interpret-markup layout props arg)
2867 (* 0.5 baseline-skip) Y))
2869 (define-builtin-markup-command (super layout props arg)
2875 @cindex superscript text
2877 Raising and lowering texts can be done with @code{\\super} and
2880 @lilypond[verbatim,quote]
2890 (ly:stencil-translate-axis
2893 (cons `((font-size . ,(- font-size 3))) props)
2895 (* 0.5 baseline-skip)
2898 (define-builtin-markup-command (translate layout props offset arg)
2899 (number-pair? markup?)
2903 @cindex translating text
2905 This translates an object. Its first argument is a cons of numbers.
2908 A \\translate #(cons 2 -3) @{ B C @} D
2911 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2912 surroundings. This command cannot be used to move isolated scripts
2913 vertically, for the same reason that @code{\\raise} cannot be used for
2916 @lilypond[verbatim,quote]
2919 \\translate #'(2 . 3)
2920 \\line { translated two spaces right, three up }
2923 (ly:stencil-translate (interpret-markup layout props arg)
2926 (define-builtin-markup-command (sub layout props arg)
2932 @cindex subscript text
2934 Set @var{arg} in subscript.
2936 @lilypond[verbatim,quote]
2947 (ly:stencil-translate-axis
2950 (cons `((font-size . ,(- font-size 3))) props)
2952 (* -0.5 baseline-skip)
2955 (define-builtin-markup-command (normal-size-sub layout props arg)
2960 @cindex setting subscript in standard font size
2962 Set @var{arg} in subscript, in a normal font size.
2964 @lilypond[verbatim,quote]
2968 subscript in standard size
2972 (ly:stencil-translate-axis
2973 (interpret-markup layout props arg)
2974 (* -0.5 baseline-skip)
2977 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2979 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2981 (define-builtin-markup-command (hbracket layout props arg)
2986 @cindex placing horizontal brackets around text
2988 Draw horizontal brackets around @var{arg}.
2990 @lilypond[verbatim,quote]
2999 (let ((th 0.1) ;; todo: take from GROB.
3000 (m (interpret-markup layout props arg)))
3001 (bracketify-stencil m X th (* 2.5 th) th)))
3003 (define-builtin-markup-command (bracket layout props arg)
3008 @cindex placing vertical brackets around text
3010 Draw vertical brackets around @var{arg}.
3012 @lilypond[verbatim,quote]
3019 (let ((th 0.1) ;; todo: take from GROB.
3020 (m (interpret-markup layout props arg)))
3021 (bracketify-stencil m Y th (* 2.5 th) th)))
3023 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3024 ;; Delayed markup evaluation
3025 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3027 (define-builtin-markup-command (page-ref layout props label gauge default)
3028 (symbol? markup? markup?)
3032 @cindex referencing page numbers in text
3034 Reference to a page number. @var{label} is the label set on the referenced
3035 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3036 the maximum width of the page number, and @var{default} the value to display
3037 when @var{label} is not found."
3038 (let* ((gauge-stencil (interpret-markup layout props gauge))
3039 (x-ext (ly:stencil-extent gauge-stencil X))
3040 (y-ext (ly:stencil-extent gauge-stencil Y)))
3042 `(delay-stencil-evaluation
3043 ,(delay (ly:stencil-expr
3044 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3045 (label-page (and (list? table) (assoc label table)))
3046 (page-number (and label-page (cdr label-page)))
3047 (page-markup (if page-number (format "~a" page-number) default))
3048 (page-stencil (interpret-markup layout props page-markup))
3049 (gap (- (interval-length x-ext)
3050 (interval-length (ly:stencil-extent page-stencil X)))))
3051 (interpret-markup layout props
3052 (markup #:concat (#:hspace gap page-markup)))))))
3056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3057 ;; Markup list commands
3058 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3060 (define-public (space-lines baseline stils)
3061 (let space-stil ((stils stils)
3065 (let* ((stil (car stils))
3066 (dy-top (max (- (/ baseline 1.5)
3067 (interval-bound (ly:stencil-extent stil Y) UP))
3069 (dy-bottom (max (+ (/ baseline 3.0)
3070 (interval-bound (ly:stencil-extent stil Y) DOWN))
3072 (new-stil (ly:make-stencil
3073 (ly:stencil-expr stil)
3074 (ly:stencil-extent stil X)
3075 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3077 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3079 (space-stil (cdr stils) (cons new-stil result))))))
3081 (define-builtin-markup-list-command (justified-lines layout props args)
3084 wordwrap-internal-markup-list)
3086 @cindex justifying lines of text
3088 Like @code{\\justify}, but return a list of lines instead of a single markup.
3089 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3090 @var{X}@tie{}is the number of staff spaces."
3091 (space-lines baseline-skip
3092 (interpret-markup-list layout props
3093 (make-wordwrap-internal-markup-list #t args))))
3095 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3098 wordwrap-internal-markup-list)
3099 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3100 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3101 where @var{X} is the number of staff spaces."
3102 (space-lines baseline-skip
3103 (interpret-markup-list layout props
3104 (make-wordwrap-internal-markup-list #f args))))
3106 (define-builtin-markup-list-command (column-lines layout props args)
3109 "Like @code{\\column}, but return a list of lines instead of a single markup.
3110 @code{baseline-skip} determines the space between each markup in @var{args}."
3111 (space-lines (chain-assoc-get 'baseline-skip props)
3112 (interpret-markup-list layout props args)))
3114 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3115 (pair? markup-list?)
3117 "Like @code{\\override}, for markup lists."
3118 (interpret-markup-list layout (cons (list new-prop) props) args))