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 bow 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 possible to define another shape for the corners (default is 1).
284 @lilypond[quote,verbatim,fragment,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 ((stil (interpret-markup layout props arg))
350 (xext (ly:stencil-extent stil X))
351 (yext (ly:stencil-extent stil Y)))
354 (ly:stencil-expr stil)
355 (interval-widen xext padding)
356 (interval-widen yext padding))))
358 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
360 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
362 (define-builtin-markup-command (strut layout props)
367 @cindex creating vertical spaces in text
369 Create a box of the same height as the space in the current font."
370 (let ((m (ly:text-interface::interpret-markup layout props " ")))
371 (ly:make-stencil (ly:stencil-expr m)
373 (ly:stencil-extent m X)
376 ;; todo: fix negative space
377 (define-builtin-markup-command (hspace layout props amount)
382 @cindex creating horizontal spaces in text
384 This produces an invisible object taking horizontal space. For example,
387 \\markup @{ A \\hspace #2.0 B @}
391 puts extra space between A and@tie{}B, on top of the space that is
392 normally inserted before elements on a line.
394 @lilypond[verbatim,quote]
404 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
405 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
409 ;; importing graphics.
410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 (define-builtin-markup-command (stencil layout props stil)
417 @cindex importing stencils into text
419 Use a stencil as markup.
421 @c FIXME works in .ly file, produces empty stencil in docs
422 @lilypond[verbatim,quote]
424 \\stencil #(dimension-arrows '(15 . 0))
430 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
432 (define (get-postscript-bbox string)
433 "Extract the bbox from STRING, or return #f if not present."
435 ((match (regexp-exec bbox-regexp string)))
439 (string->number (match:substring match x)))
444 (define-builtin-markup-command (epsfile layout props axis size file-name)
445 (number? number? string?)
449 @cindex inlining an Encapsulated PostScript image
451 Inline an EPS image. The image is scaled along @var{axis} to
454 @lilypond[verbatim,quote]
456 \\general-align #Y #DOWN {
457 \\epsfile #X #20 #\"context-example.eps\"
458 \\epsfile #Y #20 #\"context-example.eps\"
462 (if (ly:get-option 'safe)
463 (interpret-markup layout props "not allowed in safe")
464 (eps-file->stencil axis size file-name)
467 (define-builtin-markup-command (postscript layout props str)
472 @cindex inserting PostScript directly into text
474 This inserts @var{str} directly into the output as a PostScript
475 command string. Due to technicalities of the output backends,
476 different scales should be used for the @TeX{} and PostScript backend,
477 selected with @code{-f}.
479 For the @TeX{} backend, the following string prints a rotated text
482 0 0 moveto /ecrm10 findfont
483 1.75 scalefont setfont 90 rotate (hello) show
487 The magical constant 1.75 scales from LilyPond units (staff spaces) to
490 For the postscript backend, use the following
493 gsave /ecrm10 findfont
494 10.0 output-scale div
495 scalefont setfont 90 rotate (hello) show grestore
498 @lilypond[verbatim,quote]
504 0.7 0.7 0.5 0 361 arc
506 2.20 0.70 0.50 0 361 arc
508 1.45 0.85 0.30 0 180 arc
512 0.92 2.26 1.30 2.40 1.15 1.70 curveto
516 3.42 2.26 3.80 2.40 3.65 1.70 curveto
519 eyeglasses = \\markup {
520 \\with-dimensions #'(0 . 4.4) #'(0 . 2.5)
521 \\postscript #eyeglassesps
533 gsave currentpoint translate
541 (define-builtin-markup-command (score layout props score)
546 @cindex inserting music into text
548 Inline an image of music.
550 @lilypond[verbatim,quote]
554 \\new Staff \\relative c' {
557 \\mark \\markup { Allegro }
563 \\new Staff \\relative c {
577 \\override RehearsalMark #'break-align-symbols =
578 #'(time-signature key-signature)
579 \\override RehearsalMark #'self-alignment-X = #LEFT
583 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
589 (let* ((output (ly:score-embedded-format score layout)))
591 (if (ly:music-output? output)
592 (paper-system-stencil
593 (vector-ref (ly:paper-score-paper-systems output) 0))
595 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
598 (define-builtin-markup-command (null layout props)
603 @cindex creating empty text objects
605 An empty markup with extents of a single point.
607 @lilypond[verbatim,quote]
614 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
618 (define-builtin-markup-command (simple layout props str)
623 @cindex simple text strings
625 A simple text string; @code{\\markup @{ foo @}} is equivalent with
626 @code{\\markup @{ \\simple #\"foo\" @}}.
628 Note: for creating standard text markup or defining new markup commands,
629 the use of @code{\\simple} is unnecessary.
631 @lilypond[verbatim,quote]
635 \\simple #\"strings\"
638 (interpret-markup layout props str))
640 (define-builtin-markup-command (tied-lyric layout props str)
645 @cindex simple text strings with tie characters
647 Like simple-markup, but use tie characters for @q{~} tilde symbols.
649 @lilypond[verbatim,quote]
651 \\tied-lyric #\"Lasciate~i monti\"
654 (if (string-contains str "~")
656 ((parts (string-split str #\~))
657 (tie-str (ly:wide-char->utf-8 #x203f))
658 (joined (list-join parts tie-str))
659 (join-stencil (interpret-markup layout props tie-str))
662 (interpret-markup layout
665 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
667 (make-line-markup joined)))
668 ;(map (lambda (s) (interpret-markup layout props s)) parts))
669 (interpret-markup layout props str)))
671 (define-public empty-markup
672 (make-simple-markup ""))
674 ;; helper for justifying lines.
675 (define (get-fill-space word-count line-width text-widths)
676 "Calculate the necessary paddings between each two adjacent texts.
677 The lengths of all texts are stored in @var{text-widths}.
678 The normal formula for the padding between texts a and b is:
679 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
680 The first and last padding have to be calculated specially using the
681 whole length of the first or last text.
682 Return a list of paddings."
684 ((null? text-widths) '())
686 ;; special case first padding
687 ((= (length text-widths) word-count)
689 (- (- (/ line-width (1- word-count)) (car text-widths))
690 (/ (car (cdr text-widths)) 2))
691 (get-fill-space word-count line-width (cdr text-widths))))
692 ;; special case last padding
693 ((= (length text-widths) 2)
694 (list (- (/ line-width (1- word-count))
695 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
698 (- (/ line-width (1- word-count))
699 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
700 (get-fill-space word-count line-width (cdr text-widths))))))
702 (define-builtin-markup-command (fill-line layout props markups)
705 ((text-direction RIGHT)
708 "Put @var{markups} in a horizontal line of width @var{line-width}.
709 The markups are spaced or flushed to fill the entire line.
710 If there are no arguments, return an empty stencil.
712 @lilypond[verbatim,quote]
716 Words evenly spaced across the page
720 \\line { Text markups }
722 \\italic { evenly spaced }
724 \\line { across the page }
729 (let* ((orig-stencils (interpret-markup-list layout props markups))
732 (if (ly:stencil-empty? stc)
734 stc)) orig-stencils))
737 (if (ly:stencil-empty? stc)
739 (interval-length (ly:stencil-extent stc X))))
741 (text-width (apply + text-widths))
742 (word-count (length stencils))
743 (prop-line-width (chain-assoc-get 'line-width props #f))
744 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
749 (/ (- line-width text-width) 2)
750 (/ (- line-width text-width) 2)))
753 (- line-width text-width)))
755 (get-fill-space word-count line-width text-widths))))
763 (line-stencils (if (= word-count 1)
770 (if (= text-direction LEFT)
771 (set! line-stencils (reverse line-stencils)))
773 (if (null? (remove ly:stencil-empty? orig-stencils))
775 (stack-stencils-padding-list X
776 RIGHT fill-space-normal line-stencils))))
778 (define-builtin-markup-command (line layout props args)
782 (text-direction RIGHT))
783 "Put @var{args} in a horizontal line. The property @code{word-space}
784 determines the space between each markup in @var{args}.
786 @lilypond[verbatim,quote]
789 A simple line of text
793 (let ((stencils (interpret-markup-list layout props args)))
794 (if (= text-direction LEFT)
795 (set! stencils (reverse stencils)))
798 (remove ly:stencil-empty? stencils))))
800 (define-builtin-markup-command (concat layout props args)
805 @cindex concatenating text
806 @cindex ligatures in text
808 Concatenate @var{args} in a horizontal line, without spaces inbetween.
809 Strings and simple markups are concatenated on the input level, allowing
810 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
811 equivalent to @code{\"fi\"}.
813 @lilypond[verbatim,quote]
825 (define (concat-string-args arg-list)
826 (fold-right (lambda (arg result-list)
827 (let ((result (if (pair? result-list)
830 (if (and (pair? arg) (eqv? (car arg) simple-markup))
831 (set! arg (cadr arg)))
832 (if (and (string? result) (string? arg))
833 (cons (string-append arg result) (cdr result-list))
834 (cons arg result-list))))
838 (interpret-markup layout
839 (prepend-alist-chain 'word-space 0 props)
840 (make-line-markup (if (markup-command-list? args)
842 (concat-string-args args)))))
844 (define (wordwrap-stencils stencils
845 justify base-space line-width text-dir)
846 "Perform simple wordwrap, return stencil of each line."
847 (define space (if justify
848 ;; justify only stretches lines.
851 (define (take-list width space stencils
852 accumulator accumulated-width)
853 "Return (head-list . tail) pair, with head-list fitting into width"
855 (cons accumulator stencils)
856 (let* ((first (car stencils))
857 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
858 (newwid (+ space first-wid accumulated-width)))
859 (if (or (null? accumulator)
861 (take-list width space
863 (cons first accumulator)
865 (cons accumulator stencils)))))
866 (let loop ((lines '())
868 (let* ((line-break (take-list line-width space todo
870 (line-stencils (car line-break))
871 (space-left (- line-width
872 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
874 (line-word-space (cond ((not justify) space)
875 ;; don't stretch last line of paragraph.
876 ;; hmmm . bug - will overstretch the last line in some case.
877 ((null? (cdr line-break))
879 ((null? line-stencils) 0.0)
880 ((null? (cdr line-stencils)) 0.0)
881 (else (/ space-left (1- (length line-stencils))))))
882 (line (stack-stencil-line line-word-space
883 (if (= text-dir RIGHT)
884 (reverse line-stencils)
886 (if (pair? (cdr line-break))
887 (loop (cons line lines)
890 (if (= text-dir LEFT)
892 (ly:stencil-translate-axis
894 (- line-width (interval-end (ly:stencil-extent line X)))
896 (reverse (cons line lines)))))))
898 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
899 (boolean? markup-list?)
902 (text-direction RIGHT))
903 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
904 (wordwrap-stencils (remove ly:stencil-empty?
905 (interpret-markup-list layout props args))
909 (ly:output-def-lookup layout 'line-width))
912 (define-builtin-markup-command (justify layout props args)
916 wordwrap-internal-markup-list)
918 @cindex justifying text
920 Like wordwrap, but with lines stretched to justify the margins.
921 Use @code{\\override #'(line-width . @var{X})} to set the line width;
922 @var{X}@tie{}is the number of staff spaces.
924 @lilypond[verbatim,quote]
927 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
928 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
929 Ut enim ad minim veniam, quis nostrud exercitation ullamco
930 laboris nisi ut aliquip ex ea commodo consequat.
934 (stack-lines DOWN 0.0 baseline-skip
935 (wordwrap-internal-markup-list layout props #t args)))
937 (define-builtin-markup-command (wordwrap layout props args)
941 wordwrap-internal-markup-list)
942 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
943 the line width, where @var{X} is the number of staff spaces.
945 @lilypond[verbatim,quote]
948 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
949 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
950 Ut enim ad minim veniam, quis nostrud exercitation ullamco
951 laboris nisi ut aliquip ex ea commodo consequat.
955 (stack-lines DOWN 0.0 baseline-skip
956 (wordwrap-internal-markup-list layout props #f args)))
958 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
962 (text-direction RIGHT))
963 "Internal markup list command used to define @code{\\justify-string} and
964 @code{\\wordwrap-string}."
965 (let* ((para-strings (regexp-split
966 (string-regexp-substitute
968 (string-regexp-substitute "\r\n" "\n" arg))
969 "\n[ \t\n]*\n[ \t\n]*"))
970 (list-para-words (map (lambda (str)
971 (regexp-split str "[ \t\n]+"))
973 (para-lines (map (lambda (words)
975 (remove ly:stencil-empty?
977 (interpret-markup layout props x))
979 (wordwrap-stencils stencils
981 line-width text-direction)))
983 (apply append para-lines)))
985 (define-builtin-markup-command (wordwrap-string layout props arg)
989 wordwrap-string-internal-markup-list)
990 "Wordwrap a string. Paragraphs may be separated with double newlines.
992 @lilypond[verbatim,quote]
994 \\override #'(line-width . 40)
995 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
996 adipisicing elit, sed do eiusmod tempor incididunt ut labore
997 et dolore magna aliqua.
1000 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1001 laboris nisi ut aliquip ex ea commodo consequat.
1004 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1005 qui officia deserunt mollit anim id est laborum\"
1008 (stack-lines DOWN 0.0 baseline-skip
1009 (wordwrap-string-internal-markup-list layout props #f arg)))
1011 (define-builtin-markup-command (justify-string layout props arg)
1015 wordwrap-string-internal-markup-list)
1016 "Justify a string. Paragraphs may be separated with double newlines
1018 @lilypond[verbatim,quote]
1020 \\override #'(line-width . 40)
1021 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1022 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1023 et dolore magna aliqua.
1026 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1027 laboris nisi ut aliquip ex ea commodo consequat.
1030 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1031 qui officia deserunt mollit anim id est laborum\"
1034 (stack-lines DOWN 0.0 baseline-skip
1035 (wordwrap-string-internal-markup-list layout props #t arg)))
1037 (define-builtin-markup-command (wordwrap-field layout props symbol)
1041 "Wordwrap the data which has been assigned to @var{symbol}.
1043 @lilypond[verbatim,quote]
1045 title = \"My title\"
1046 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1047 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1048 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1049 nisi ut aliquip ex ea commodo consequat.\"
1053 bookTitleMarkup = \\markup {
1055 \\fill-line { \\fromproperty #'header:title }
1057 \\wordwrap-field #'header:descr
1066 (let* ((m (chain-assoc-get symbol props)))
1068 (wordwrap-string-markup layout props m)
1071 (define-builtin-markup-command (justify-field layout props symbol)
1075 "Justify the data which has been assigned to @var{symbol}.
1077 @lilypond[verbatim,quote]
1079 title = \"My title\"
1080 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1081 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1082 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1083 nisi ut aliquip ex ea commodo consequat.\"
1087 bookTitleMarkup = \\markup {
1089 \\fill-line { \\fromproperty #'header:title }
1091 \\justify-field #'header:descr
1100 (let* ((m (chain-assoc-get symbol props)))
1102 (justify-string-markup layout props m)
1105 (define-builtin-markup-command (combine layout props m1 m2)
1110 @cindex merging text
1112 Print two markups on top of each other.
1114 Note: @code{\\combine} cannot take a list of markups enclosed in
1115 curly braces as an argument; the follow example will not compile:
1118 \\combine @{ a list @}
1121 @lilypond[verbatim,quote]
1124 \\override #'(thickness . 2)
1126 \\draw-line #'(0 . 4)
1127 \\arrow-head #Y #DOWN ##f
1130 (let* ((s1 (interpret-markup layout props m1))
1131 (s2 (interpret-markup layout props m2)))
1132 (ly:stencil-add s1 s2)))
1135 ;; TODO: should extract baseline-skip from each argument somehow..
1137 (define-builtin-markup-command (column layout props args)
1142 @cindex stacking text in a column
1144 Stack the markups in @var{args} vertically. The property
1145 @code{baseline-skip} determines the space between each
1146 markup in @var{args}.
1148 @lilypond[verbatim,quote]
1157 (let ((arg-stencils (interpret-markup-list layout props args)))
1158 (stack-lines -1 0.0 baseline-skip
1159 (remove ly:stencil-empty? arg-stencils))))
1161 (define-builtin-markup-command (dir-column layout props args)
1167 @cindex changing direction of text columns
1169 Make a column of args, going up or down, depending on the setting
1170 of the @code{#'direction} layout property.
1172 @lilypond[verbatim,quote]
1174 \\override #'(direction . 1) {
1184 (stack-lines (if (number? direction) direction -1)
1187 (interpret-markup-list layout props args)))
1189 (define-builtin-markup-command (center-align layout props args)
1194 @cindex centering a column of text
1196 Put @code{args} in a centered column.
1198 @lilypond[verbatim,quote]
1207 (let* ((mols (interpret-markup-list layout props args))
1208 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
1209 (stack-lines -1 0.0 baseline-skip cmols)))
1211 (define-builtin-markup-command (vcenter layout props arg)
1216 @cindex vertically centering text
1218 Align @code{arg} to its Y@tie{}center.
1220 @lilypond[verbatim,quote]
1222 \\arrow-head #X #RIGHT ##f
1225 \\arrow-head #X #LEFT ##f
1228 (let* ((mol (interpret-markup layout props arg)))
1229 (ly:stencil-aligned-to mol Y CENTER)))
1231 (define-builtin-markup-command (hcenter layout props arg)
1236 @cindex horizontally centering text
1238 Align @code{arg} to its X@tie{}center.
1240 @lilypond[verbatim,quote]
1249 (let* ((mol (interpret-markup layout props arg)))
1250 (ly:stencil-aligned-to mol X CENTER)))
1252 (define-builtin-markup-command (right-align layout props arg)
1257 @cindex right aligning text
1259 Align @var{arg} on its right edge.
1261 @lilypond[verbatim,quote]
1270 (let* ((m (interpret-markup layout props arg)))
1271 (ly:stencil-aligned-to m X RIGHT)))
1273 (define-builtin-markup-command (left-align layout props arg)
1278 @cindex left aligning text
1280 Align @var{arg} on its left edge.
1282 @lilypond[verbatim,quote]
1291 (let* ((m (interpret-markup layout props arg)))
1292 (ly:stencil-aligned-to m X LEFT)))
1294 (define-builtin-markup-command (general-align layout props axis dir arg)
1295 (integer? number? markup?)
1299 @cindex controlling general text alignment
1301 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1303 @lilypond[verbatim,quote]
1307 \\general-align #X #LEFT
1310 \\general-align #X #CENTER
1311 \\line { X, Center }
1314 \\arrow-head #X #RIGHT ##f
1315 \\general-align #Y #DOWN
1317 \\arrow-head #X #LEFT ##f
1320 \\arrow-head #X #RIGHT ##f
1321 \\general-align #Y #3.2
1323 \\line { Y, Arbitrary alignment }
1325 \\arrow-head #X #LEFT ##f
1330 (let* ((m (interpret-markup layout props arg)))
1331 (ly:stencil-aligned-to m axis dir)))
1333 (define-builtin-markup-command (halign layout props dir arg)
1338 @cindex setting horizontal text alignment
1340 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1341 left-aligned, while @code{+1} is right. Values in between interpolate
1342 alignment accordingly.
1344 @lilypond[verbatim,quote]
1364 (let* ((m (interpret-markup layout props arg)))
1365 (ly:stencil-aligned-to m X dir)))
1367 (define-builtin-markup-command (with-dimensions layout props x y arg)
1368 (number-pair? number-pair? markup?)
1372 @cindex setting extent of text objects
1374 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1375 (let* ((m (interpret-markup layout props arg)))
1376 (ly:make-stencil (ly:stencil-expr m) x y)))
1378 (define-builtin-markup-command (pad-around layout props amount arg)
1382 "Add padding @var{amount} all around @var{arg}."
1383 (let* ((m (interpret-markup layout props arg))
1384 (x (ly:stencil-extent m X))
1385 (y (ly:stencil-extent m Y)))
1386 (ly:make-stencil (ly:stencil-expr m)
1387 (interval-widen x amount)
1388 (interval-widen y amount))))
1390 (define-builtin-markup-command (pad-x layout props amount arg)
1395 @cindex padding text horizontally
1397 Add padding @var{amount} around @var{arg} in the X@tie{}direction."
1398 (let* ((m (interpret-markup layout props arg))
1399 (x (ly:stencil-extent m X))
1400 (y (ly:stencil-extent m Y)))
1401 (ly:make-stencil (ly:stencil-expr m)
1402 (interval-widen x amount)
1405 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2)
1406 (markup? integer? ly:dir? markup?)
1409 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1410 (let ((m1 (interpret-markup layout props arg1))
1411 (m2 (interpret-markup layout props arg2)))
1412 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1414 (define-builtin-markup-command (transparent layout props arg)
1418 "Make the argument transparent.
1420 @lilypond[verbatim,quote]
1427 (let* ((m (interpret-markup layout props arg))
1428 (x (ly:stencil-extent m X))
1429 (y (ly:stencil-extent m Y)))
1430 (ly:make-stencil "" x y)))
1432 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1433 (number-pair? number-pair? markup?)
1436 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
1437 (let* ((m (interpret-markup layout props arg))
1438 (x (ly:stencil-extent m X))
1439 (y (ly:stencil-extent m Y)))
1440 (ly:make-stencil (ly:stencil-expr m)
1441 (interval-union x-ext x)
1442 (interval-union y-ext y))))
1444 (define-builtin-markup-command (hcenter-in layout props length arg)
1448 "Center @var{arg} horizontally within a box of extending
1449 @var{length}/2 to the left and right."
1450 (interpret-markup layout props
1451 (make-pad-to-box-markup
1452 (cons (/ length -2) (/ length 2))
1454 (make-hcenter-markup arg))))
1456 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1460 (define-builtin-markup-command (fromproperty layout props symbol)
1464 "Read the @var{symbol} from property settings, and produce a stencil
1465 from the markup contained within. If @var{symbol} is not defined, it
1466 returns an empty markup.
1468 @lilypond[verbatim,quote]
1470 myTitle = \"myTitle\"
1474 \\fromproperty #'header:myTitle
1481 (let ((m (chain-assoc-get symbol props)))
1483 (interpret-markup layout props m)
1486 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1490 "Apply the @var{procedure} markup command to @var{arg}.
1491 @var{procedure} should take a single argument."
1492 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1493 (set-object-property! anonymous-with-signature
1496 (interpret-markup layout props (list anonymous-with-signature arg))))
1498 (define-builtin-markup-command (override layout props new-prop arg)
1503 @cindex overriding properties within text markup
1505 Add the first argument in to the property list. Properties may be
1506 any sort of property supported by @rinternals{font-interface} and
1507 @rinternals{text-interface}, for example
1510 \\override #'(font-family . married) \"bla\"
1513 @lilypond[verbatim,quote]
1521 \\override #'(baseline-skip . 4) {
1530 (interpret-markup layout (cons (list new-prop) props) arg))
1532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1536 (define-builtin-markup-command (verbatim-file layout props name)
1540 "Read the contents of a file, and include it verbatim.
1542 @lilypond[verbatim,quote]
1544 \\verbatim-file #\"simple.ly\"
1547 (interpret-markup layout props
1548 (if (ly:get-option 'safe)
1549 "verbatim-file disabled in safe mode"
1550 (let* ((str (ly:gulp-file name))
1551 (lines (string-split str #\nl)))
1552 (make-typewriter-markup
1553 (make-column-markup lines))))))
1555 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1557 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1559 (define-builtin-markup-command (bigger layout props arg)
1563 "Increase the font size relative to current setting.
1565 @lilypond[verbatim,quote]
1578 (interpret-markup layout props
1579 `(,fontsize-markup 1 ,arg)))
1581 (define-builtin-markup-command (smaller layout props arg)
1585 "Decrease the font size relative to current setting.
1587 @lilypond[verbatim,quote]
1600 (interpret-markup layout props
1601 `(,fontsize-markup -1 ,arg)))
1603 (define-builtin-markup-command (larger layout props arg)
1607 "Copy of the @code{\\bigger} command.
1609 @lilypond[verbatim,quote]
1617 (interpret-markup layout props (make-bigger-markup arg)))
1619 (define-builtin-markup-command (finger layout props arg)
1623 "Set the argument as small numbers.
1624 @lilypond[verbatim,quote]
1631 (interpret-markup layout
1632 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1635 (define-builtin-markup-command (abs-fontsize layout props size arg)
1639 "Use @var{size} as the absolute font size to display @var{arg}.
1640 Adjust baseline skip and word space accordingly.
1641 @lilypond[verbatim,quote]
1643 default text font size
1645 \\abs-fontsize #16 { text font size 16 }
1647 \\abs-fontsize #12 { text font size 12 }
1650 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1651 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1652 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1653 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1654 (magnification (/ size ref-size)))
1655 (interpret-markup layout
1656 (cons `((baseline-skip . ,(* magnification ref-baseline))
1657 (word-space . ,(* magnification ref-word-space))
1658 (font-size . ,(magnification->font-size magnification)))
1662 (define-builtin-markup-command (fontsize layout props increment arg)
1668 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1669 @lilypond[verbatim,quote]
1677 (let ((entries (list
1678 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1679 (cons 'word-space (* word-space (magstep increment)))
1680 (cons 'font-size (+ font-size increment)))))
1681 (interpret-markup layout (cons entries props) arg)))
1683 (define-builtin-markup-command (magnify layout props sz arg)
1688 @cindex magnifying text
1690 Set the font magnification for its argument. In the following
1691 example, the middle@tie{}A is 10% larger:
1694 A \\magnify #1.1 @{ A @} A
1697 Note: Magnification only works if a font name is explicitly selected.
1698 Use @code{\\fontsize} otherwise.
1700 @lilypond[verbatim,quote]
1711 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1714 (define-builtin-markup-command (bold layout props arg)
1718 "Switch to bold font-series.
1720 @lilypond[verbatim,quote]
1728 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1730 (define-builtin-markup-command (sans layout props arg)
1734 "Switch to the sans serif family.
1736 @lilypond[verbatim,quote]
1745 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1747 (define-builtin-markup-command (number layout props arg)
1751 "Set font family to @code{number}, which yields the font used for
1752 time signatures and fingerings. This font only contains numbers and
1753 some punctuation. It doesn't have any letters.
1755 @lilypond[verbatim,quote]
1758 0 1 2 3 4 5 6 7 8 9 . ,
1762 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1764 (define-builtin-markup-command (roman layout props arg)
1768 "Set font family to @code{roman}.
1770 @lilypond[verbatim,quote]
1776 text in roman font family
1783 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1785 (define-builtin-markup-command (huge layout props arg)
1789 "Set font size to +2.
1791 @lilypond[verbatim,quote]
1799 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1801 (define-builtin-markup-command (large layout props arg)
1805 "Set font size to +1.
1807 @lilypond[verbatim,quote]
1815 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1817 (define-builtin-markup-command (normalsize layout props arg)
1821 "Set font size to default.
1823 @lilypond[verbatim,quote]
1836 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1838 (define-builtin-markup-command (small layout props arg)
1842 "Set font size to -1.
1844 @lilypond[verbatim,quote]
1852 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1854 (define-builtin-markup-command (tiny layout props arg)
1858 "Set font size to -2.
1860 @lilypond[verbatim,quote]
1868 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1870 (define-builtin-markup-command (teeny layout props arg)
1874 "Set font size to -3.
1876 @lilypond[verbatim,quote]
1884 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1886 (define-builtin-markup-command (fontCaps layout props arg)
1890 "Set @code{font-shape} to @code{caps}
1892 Note: @code{\\fontCaps} requires the installation and selection of
1893 fonts which support the @code{caps} font shape."
1894 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1897 (define-builtin-markup-command (smallCaps layout props text)
1901 "Emit @var{arg} as small caps.
1903 Note: @code{\\smallCaps} does not support accented characters.
1905 @lilypond[verbatim,quote]
1914 (define (char-list->markup chars lower)
1915 (let ((final-string (string-upcase (reverse-list->string chars))))
1917 (markup #:fontsize -2 final-string)
1919 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1920 (if (null? rest-chars)
1922 (reverse! (cons (char-list->markup currents current-is-lower)
1924 (let* ((ch (car rest-chars))
1925 (is-lower (char-lower-case? ch)))
1926 (if (or (and current-is-lower is-lower)
1927 (and (not current-is-lower) (not is-lower)))
1928 (make-small-caps (cdr rest-chars)
1932 (make-small-caps (cdr rest-chars)
1935 (if (null? currents)
1937 (cons (char-list->markup
1938 currents current-is-lower)
1940 (interpret-markup layout props
1942 (make-small-caps (string->list text) (list) #f (list))
1945 (define-builtin-markup-command (caps layout props arg)
1949 "Copy of the @code{\\smallCaps} command.
1951 @lilypond[verbatim,quote]
1960 (interpret-markup layout props (make-smallCaps-markup arg)))
1962 (define-builtin-markup-command (dynamic layout props arg)
1966 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
1967 @b{z}, @b{p}, and @b{r}. When producing phrases, like
1968 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
1969 done in a different font. The recommended font for this is bold and italic.
1970 @lilypond[verbatim,quote]
1978 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
1980 (define-builtin-markup-command (text layout props arg)
1984 "Use a text font instead of music symbol or music alphabet font.
1986 @lilypond[verbatim,quote]
1999 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2002 (define-builtin-markup-command (italic layout props arg)
2006 "Use italic @code{font-shape} for @var{arg}.
2008 @lilypond[verbatim,quote]
2016 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2018 (define-builtin-markup-command (typewriter layout props arg)
2022 "Use @code{font-family} typewriter for @var{arg}.
2024 @lilypond[verbatim,quote]
2033 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2035 (define-builtin-markup-command (upright layout props arg)
2039 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
2041 @lilypond[verbatim,quote]
2055 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2057 (define-builtin-markup-command (medium layout props arg)
2061 "Switch to medium font series (in contrast to bold).
2063 @lilypond[verbatim,quote]
2076 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2079 (define-builtin-markup-command (normal-text layout props arg)
2083 "Set all font related properties (except the size) to get the default
2084 normal text font, no matter what font was used earlier.
2086 @lilypond[verbatim,quote]
2088 \\huge \\bold \\sans \\caps {
2089 Some text with font overrides
2092 Default text, same font-size
2100 (interpret-markup layout
2101 (cons '((font-family . roman) (font-shape . upright)
2102 (font-series . medium) (font-encoding . latin1))
2106 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2110 (define-builtin-markup-command (doublesharp layout props)
2114 "Draw a double sharp symbol.
2116 @lilypond[verbatim,quote]
2121 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2123 (define-builtin-markup-command (sesquisharp layout props)
2127 "Draw a 3/2 sharp symbol.
2129 @lilypond[verbatim,quote]
2134 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2136 (define-builtin-markup-command (sharp layout props)
2140 "Draw a sharp symbol.
2142 @lilypond[verbatim,quote]
2147 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2149 (define-builtin-markup-command (semisharp layout props)
2153 "Draw a semi sharp symbol.
2155 @lilypond[verbatim,quote]
2160 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2162 (define-builtin-markup-command (natural layout props)
2166 "Draw a natural symbol.
2168 @lilypond[verbatim,quote]
2173 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2175 (define-builtin-markup-command (semiflat layout props)
2179 "Draw a semiflat symbol.
2181 @lilypond[verbatim,quote]
2186 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2188 (define-builtin-markup-command (flat layout props)
2192 "Draw a flat symbol.
2194 @lilypond[verbatim,quote]
2199 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2201 (define-builtin-markup-command (sesquiflat layout props)
2205 "Draw a 3/2 flat symbol.
2207 @lilypond[verbatim,quote]
2212 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2214 (define-builtin-markup-command (doubleflat layout props)
2218 "Draw a double flat symbol.
2220 @lilypond[verbatim,quote]
2225 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2227 (define-builtin-markup-command (with-color layout props color arg)
2232 @cindex coloring text
2234 Draw @var{arg} in color specified by @var{color}.
2236 @lilypond[verbatim,quote]
2248 (let ((stil (interpret-markup layout props arg)))
2249 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2250 (ly:stencil-extent stil X)
2251 (ly:stencil-extent stil Y))))
2253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2255 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2257 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2258 (integer? ly:dir? boolean?)
2261 "Produce an arrow head in specified direction and axis.
2262 Use the filled head if @var{filled} is specified.
2263 @lilypond[verbatim,quote]
2266 \\general-align #Y #DOWN {
2267 \\arrow-head #Y #UP ##t
2268 \\arrow-head #Y #DOWN ##f
2270 \\arrow-head #X #RIGHT ##f
2271 \\arrow-head #X #LEFT ##f
2277 ((name (format "arrowheads.~a.~a~a"
2284 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2288 (define-builtin-markup-command (musicglyph layout props glyph-name)
2292 "@var{glyph-name} is converted to a musical symbol; for example,
2293 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2294 the music font. See @ruser{The Feta font} for a complete listing of
2295 the possible glyphs.
2297 @lilypond[verbatim,quote]
2300 \\musicglyph #\"rests.2\"
2301 \\musicglyph #\"clefs.G_change\"
2304 (let* ((font (ly:paper-get-font layout
2305 (cons '((font-encoding . fetaMusic)
2309 (glyph (ly:font-get-glyph font glyph-name)))
2310 (if (null? (ly:stencil-expr glyph))
2311 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2316 (define-builtin-markup-command (lookup layout props glyph-name)
2320 "Lookup a glyph by name.
2322 @lilypond[verbatim,quote]
2324 \\override #'(font-encoding . fetaBraces) {
2325 \\lookup #\"brace200\"
2328 \\lookup #\"brace180\"
2332 (ly:font-get-glyph (ly:paper-get-font layout props)
2335 (define-builtin-markup-command (char layout props num)
2339 "Produce a single character. For example, @code{\\char #65} produces the
2342 @lilypond[verbatim,quote]
2347 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2349 (define number->mark-letter-vector (make-vector 25 #\A))
2354 (if (= i (- (char->integer #\I) (char->integer #\A)))
2356 (vector-set! number->mark-letter-vector j
2357 (integer->char (+ i (char->integer #\A)))))
2359 (define number->mark-alphabet-vector (list->vector
2360 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2362 (define (number->markletter-string vec n)
2363 "Double letters for big marks."
2364 (let* ((lst (vector-length vec)))
2367 (string-append (number->markletter-string vec (1- (quotient n lst)))
2368 (number->markletter-string vec (remainder n lst)))
2369 (make-string 1 (vector-ref vec n)))))
2371 (define-builtin-markup-command (markletter layout props num)
2375 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2376 (skipping letter@tie{}I), and continue with double letters.
2378 @lilypond[verbatim,quote]
2385 (ly:text-interface::interpret-markup layout props
2386 (number->markletter-string number->mark-letter-vector num)))
2388 (define-builtin-markup-command (markalphabet layout props num)
2392 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2393 and continue with double letters.
2395 @lilypond[verbatim,quote]
2402 (ly:text-interface::interpret-markup layout props
2403 (number->markletter-string number->mark-alphabet-vector num)))
2405 (define-public (horizontal-slash-interval num forward number-interval mag)
2406 (ly:message "Mag step: ~a" mag)
2408 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2409 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2410 (else (interval-widen number-interval (* mag 0.25))))
2411 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2412 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2413 (else (interval-widen number-interval (* mag 0.25))))
2416 (define-public (adjust-slash-stencil num forward stencil mag)
2419 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2421 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2423 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2425 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2428 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2430 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2435 (define (slashed-digit-internal layout props num forward font-size thickness)
2436 (let* ((mag (magstep font-size))
2438 (ly:output-def-lookup layout 'line-thickness)
2440 ; backward slashes might use slope and point in the other direction!
2441 (dy (* mag (if forward 0.4 -0.4)))
2442 (number-stencil (interpret-markup layout
2443 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2444 (number->string num)))
2445 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2446 (center (interval-center (ly:stencil-extent number-stencil Y)))
2447 ; Use the real extents of the slash, not the whole number, because we
2448 ; might translate the slash later on!
2449 (num-y (interval-widen (cons center center) (abs dy)))
2450 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2451 (slash-stencil (if is-sane
2453 `(draw-line ,thickness
2454 ,(car num-x) ,(- (interval-center num-y) dy)
2455 ,(cdr num-x) ,(+ (interval-center num-y) dy))
2458 (ly:message "Num: ~a, X-interval: ~a" num num-x)
2459 (if (ly:stencil? slash-stencil)
2461 ; for some numbers we need to shift the slash/backslash up or down to make
2462 ; the slashed digit look better
2463 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2464 (set! number-stencil
2465 (ly:stencil-add number-stencil slash-stencil)))
2466 (ly:warning "Unable to create slashed digit ~a" num))
2470 (define-builtin-markup-command (slashed-digit layout props num)
2476 @cindex slashed digits
2478 A feta number, with slash. This is for use in the context of
2479 figured bass notation.
2480 @lilypond[verbatim,quote]
2484 \\override #'(thickness . 3)
2488 (slashed-digit-internal layout props num #t font-size thickness))
2490 (define-builtin-markup-command (backslashed-digit layout props num)
2496 @cindex backslashed digits
2498 A feta number, with backslash. This is for use in the context of
2499 figured bass notation.
2500 @lilypond[verbatim,quote]
2502 \\backslashed-digit #5
2504 \\override #'(thickness . 3)
2505 \\backslashed-digit #7
2508 (slashed-digit-internal layout props num #f font-size thickness))
2510 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2511 ;; the note command.
2512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2514 ;; TODO: better syntax.
2516 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2517 (number? number? number?)
2522 @cindex notes within text by log and dot-count
2524 Construct a note symbol, with stem. By using fractional values for
2525 @var{dir}, you can obtain longer or shorter stems.
2527 @lilypond[verbatim,quote]
2529 \\note-by-number #3 #0 #DOWN
2531 \\note-by-number #1 #2 #0.8
2534 (define (get-glyph-name-candidates dir log style)
2535 (map (lambda (dir-name)
2536 (format "noteheads.~a~a~a" dir-name (min log 2)
2537 (if (and (symbol? style)
2538 (not (equal? 'default style)))
2539 (symbol->string style)
2541 (list (if (= dir UP) "u" "d")
2544 (define (get-glyph-name font cands)
2547 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2548 (get-glyph-name font (cdr cands))
2551 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2552 (size-factor (magstep font-size))
2553 (stem-length (* size-factor (max 3 (- log 1))))
2554 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2555 (head-glyph (ly:font-get-glyph font head-glyph-name))
2556 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2557 (stem-thickness (* size-factor 0.13))
2558 (stemy (* dir stem-length))
2559 (attach-off (cons (interval-index
2560 (ly:stencil-extent head-glyph X)
2561 (* (sign dir) (car attach-indices)))
2562 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2564 (ly:stencil-extent head-glyph Y)
2565 (cdr attach-indices)))))
2566 (stem-glyph (and (> log 0)
2567 (ly:round-filled-box
2568 (ordered-cons (car attach-off)
2569 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2570 (cons (min stemy (cdr attach-off))
2571 (max stemy (cdr attach-off)))
2572 (/ stem-thickness 3))))
2574 (dot (ly:font-get-glyph font "dots.dot"))
2575 (dotwid (interval-length (ly:stencil-extent dot X)))
2576 (dots (and (> dot-count 0)
2577 (apply ly:stencil-add
2579 (ly:stencil-translate-axis
2580 dot (* 2 x dotwid) X))
2581 (iota dot-count)))))
2582 (flaggl (and (> log 2)
2583 (ly:stencil-translate
2584 (ly:font-get-glyph font
2585 (string-append "flags."
2586 (if (> dir 0) "u" "d")
2587 (number->string log)))
2588 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2590 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2591 ; 16th notes get a special case because their flags hang lower than any other flags.
2592 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2593 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2595 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2596 (if (ly:stencil? stem-glyph)
2597 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2598 (set! stem-glyph head-glyph))
2599 (if (ly:stencil? dots)
2602 (ly:stencil-translate-axis
2604 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2610 (let ((divisor (log 2)))
2611 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2613 (define (parse-simple-duration duration-string)
2614 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2615 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2616 (if (and match (string=? duration-string (match:substring match 0)))
2617 (let ((len (match:substring match 1))
2618 (dots (match:substring match 2)))
2619 (list (cond ((string=? len "breve") -1)
2620 ((string=? len "longa") -2)
2621 ((string=? len "maxima") -3)
2622 (else (log2 (string->number len))))
2623 (if dots (string-length dots) 0)))
2624 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2626 (define-builtin-markup-command (note layout props duration dir)
2629 (note-by-number-markup)
2631 @cindex notes within text by string
2633 This produces a note with a stem pointing in @var{dir} direction, with
2634 the @var{duration} for the note head type and augmentation dots. For
2635 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2636 a shortened down stem.
2638 @lilypond[verbatim,quote]
2640 \\override #'(style . cross) {
2644 \\note #\"breve\" #0
2647 (let ((parsed (parse-simple-duration duration)))
2648 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2650 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2654 (define-builtin-markup-command (lower layout props amount arg)
2659 @cindex lowering text
2661 Lower @var{arg} by the distance @var{amount}.
2662 A negative @var{amount} indicates raising; see also @code{\\raise}.
2664 @lilypond[verbatim,quote]
2672 (ly:stencil-translate-axis (interpret-markup layout props arg)
2675 (define-builtin-markup-command (translate-scaled layout props offset arg)
2676 (number-pair? markup?)
2680 @cindex translating text
2681 @cindex scaling text
2683 Translate @var{arg} by @var{offset}, scaling the offset by the
2686 @lilypond[verbatim,quote]
2689 * \\translate #'(2 . 3) translate
2691 * \\translate-scaled #'(2 . 3) translate-scaled
2695 (let* ((factor (magstep font-size))
2696 (scaled (cons (* factor (car offset))
2697 (* factor (cdr offset)))))
2698 (ly:stencil-translate (interpret-markup layout props arg)
2701 (define-builtin-markup-command (raise layout props amount arg)
2706 @cindex raising text
2708 Raise @var{arg} by the distance @var{amount}.
2709 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2711 The argument to @code{\\raise} is the vertical displacement amount,
2712 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2713 raise objects in relation to their surrounding markups.
2715 If the text object itself is positioned above or below the staff, then
2716 @code{\\raise} cannot be used to move it, since the mechanism that
2717 positions it next to the staff cancels any shift made with
2718 @code{\\raise}. For vertical positioning, use the @code{padding}
2719 and/or @code{extra-offset} properties.
2721 @lilypond[verbatim,quote]
2730 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2732 (define-builtin-markup-command (fraction layout props arg1 arg2)
2737 @cindex creating text fractions
2739 Make a fraction of two markups.
2740 @lilypond[verbatim,quote]
2746 (let* ((m1 (interpret-markup layout props arg1))
2747 (m2 (interpret-markup layout props arg2))
2748 (factor (magstep font-size))
2749 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2750 (padding (* factor 0.2))
2751 (baseline (* factor 0.6))
2752 (offset (* factor 0.75)))
2753 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2754 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2755 (let* ((x1 (ly:stencil-extent m1 X))
2756 (x2 (ly:stencil-extent m2 X))
2757 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2758 ;; should stack mols separately, to maintain LINE on baseline
2759 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2761 (ly:stencil-aligned-to stack Y CENTER))
2763 (ly:stencil-aligned-to stack X LEFT))
2764 ;; should have EX dimension
2766 (ly:stencil-translate-axis stack offset Y))))
2768 (define-builtin-markup-command (normal-size-super layout props arg)
2773 @cindex setting superscript in standard font size
2775 Set @var{arg} in superscript with a normal font size.
2777 @lilypond[verbatim,quote]
2780 \\normal-size-super {
2781 superscript in standard size
2785 (ly:stencil-translate-axis
2786 (interpret-markup layout props arg)
2787 (* 0.5 baseline-skip) Y))
2789 (define-builtin-markup-command (super layout props arg)
2795 @cindex superscript text
2797 Raising and lowering texts can be done with @code{\\super} and
2800 @lilypond[verbatim,quote]
2810 (ly:stencil-translate-axis
2813 (cons `((font-size . ,(- font-size 3))) props)
2815 (* 0.5 baseline-skip)
2818 (define-builtin-markup-command (translate layout props offset arg)
2819 (number-pair? markup?)
2823 @cindex translating text
2825 This translates an object. Its first argument is a cons of numbers.
2828 A \\translate #(cons 2 -3) @{ B C @} D
2831 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2832 surroundings. This command cannot be used to move isolated scripts
2833 vertically, for the same reason that @code{\\raise} cannot be used for
2836 @lilypond[verbatim,quote]
2839 \\translate #'(2 . 3)
2840 \\line { translated two spaces right, three up }
2843 (ly:stencil-translate (interpret-markup layout props arg)
2846 (define-builtin-markup-command (sub layout props arg)
2852 @cindex subscript text
2854 Set @var{arg} in subscript.
2856 @lilypond[verbatim,quote]
2867 (ly:stencil-translate-axis
2870 (cons `((font-size . ,(- font-size 3))) props)
2872 (* -0.5 baseline-skip)
2875 (define-builtin-markup-command (normal-size-sub layout props arg)
2880 @cindex setting subscript in standard font size
2882 Set @var{arg} in subscript, in a normal font size.
2884 @lilypond[verbatim,quote]
2888 subscript in standard size
2892 (ly:stencil-translate-axis
2893 (interpret-markup layout props arg)
2894 (* -0.5 baseline-skip)
2897 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2901 (define-builtin-markup-command (hbracket layout props arg)
2906 @cindex placing horizontal brackets around text
2908 Draw horizontal brackets around @var{arg}.
2910 @lilypond[verbatim,quote]
2919 (let ((th 0.1) ;; todo: take from GROB.
2920 (m (interpret-markup layout props arg)))
2921 (bracketify-stencil m X th (* 2.5 th) th)))
2923 (define-builtin-markup-command (bracket layout props arg)
2928 @cindex placing vertical brackets around text
2930 Draw vertical brackets around @var{arg}.
2932 @lilypond[verbatim,quote]
2939 (let ((th 0.1) ;; todo: take from GROB.
2940 (m (interpret-markup layout props arg)))
2941 (bracketify-stencil m Y th (* 2.5 th) th)))
2943 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2944 ;; Delayed markup evaluation
2945 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2947 (define-builtin-markup-command (page-ref layout props label gauge default)
2948 (symbol? markup? markup?)
2952 @cindex referencing page numbers in text
2954 Reference to a page number. @var{label} is the label set on the referenced
2955 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
2956 the maximum width of the page number, and @var{default} the value to display
2957 when @var{label} is not found."
2958 (let* ((gauge-stencil (interpret-markup layout props gauge))
2959 (x-ext (ly:stencil-extent gauge-stencil X))
2960 (y-ext (ly:stencil-extent gauge-stencil Y)))
2962 `(delay-stencil-evaluation
2963 ,(delay (ly:stencil-expr
2964 (let* ((table (ly:output-def-lookup layout 'label-page-table))
2965 (label-page (and (list? table) (assoc label table)))
2966 (page-number (and label-page (cdr label-page)))
2967 (page-markup (if page-number (format "~a" page-number) default))
2968 (page-stencil (interpret-markup layout props page-markup))
2969 (gap (- (interval-length x-ext)
2970 (interval-length (ly:stencil-extent page-stencil X)))))
2971 (interpret-markup layout props
2972 (markup #:concat (#:hspace gap page-markup)))))))
2976 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2977 ;; Markup list commands
2978 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2980 (define-public (space-lines baseline stils)
2981 (let space-stil ((stils stils)
2985 (let* ((stil (car stils))
2986 (dy-top (max (- (/ baseline 1.5)
2987 (interval-bound (ly:stencil-extent stil Y) UP))
2989 (dy-bottom (max (+ (/ baseline 3.0)
2990 (interval-bound (ly:stencil-extent stil Y) DOWN))
2992 (new-stil (ly:make-stencil
2993 (ly:stencil-expr stil)
2994 (ly:stencil-extent stil X)
2995 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
2997 (+ (interval-bound (ly:stencil-extent stil Y) UP)
2999 (space-stil (cdr stils) (cons new-stil result))))))
3001 (define-builtin-markup-list-command (justified-lines layout props args)
3004 wordwrap-internal-markup-list)
3006 @cindex justifying lines of text
3008 Like @code{\\justify}, but return a list of lines instead of a single markup.
3009 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3010 @var{X}@tie{}is the number of staff spaces."
3011 (space-lines baseline-skip
3012 (interpret-markup-list layout props
3013 (make-wordwrap-internal-markup-list #t args))))
3015 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3018 wordwrap-internal-markup-list)
3019 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3020 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3021 where @var{X} is the number of staff spaces."
3022 (space-lines baseline-skip
3023 (interpret-markup-list layout props
3024 (make-wordwrap-internal-markup-list #f args))))
3026 (define-builtin-markup-list-command (column-lines layout props args)
3029 "Like @code{\\column}, but return a list of lines instead of a single markup.
3030 @code{baseline-skip} determines the space between each markup in @var{args}."
3031 (space-lines (chain-assoc-get 'baseline-skip props)
3032 (interpret-markup-list layout props args)))
3034 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3035 (pair? markup-list?)
3037 "Like @code{\\override}, for markup lists."
3038 (interpret-markup-list layout (cons (list new-prop) props) args))