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,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]
802 A simple line of text
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]
838 (define (concat-string-args arg-list)
839 (fold-right (lambda (arg result-list)
840 (let ((result (if (pair? result-list)
843 (if (and (pair? arg) (eqv? (car arg) simple-markup))
844 (set! arg (cadr arg)))
845 (if (and (string? result) (string? arg))
846 (cons (string-append arg result) (cdr result-list))
847 (cons arg result-list))))
851 (interpret-markup layout
852 (prepend-alist-chain 'word-space 0 props)
853 (make-line-markup (if (markup-command-list? args)
855 (concat-string-args args)))))
857 (define (wordwrap-stencils stencils
858 justify base-space line-width text-dir)
859 "Perform simple wordwrap, return stencil of each line."
860 (define space (if justify
861 ;; justify only stretches lines.
864 (define (take-list width space stencils
865 accumulator accumulated-width)
866 "Return (head-list . tail) pair, with head-list fitting into width"
868 (cons accumulator stencils)
869 (let* ((first (car stencils))
870 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
871 (newwid (+ space first-wid accumulated-width)))
872 (if (or (null? accumulator)
874 (take-list width space
876 (cons first accumulator)
878 (cons accumulator stencils)))))
879 (let loop ((lines '())
881 (let* ((line-break (take-list line-width space todo
883 (line-stencils (car line-break))
884 (space-left (- line-width
885 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
887 (line-word-space (cond ((not justify) space)
888 ;; don't stretch last line of paragraph.
889 ;; hmmm . bug - will overstretch the last line in some case.
890 ((null? (cdr line-break))
892 ((null? line-stencils) 0.0)
893 ((null? (cdr line-stencils)) 0.0)
894 (else (/ space-left (1- (length line-stencils))))))
895 (line (stack-stencil-line line-word-space
896 (if (= text-dir RIGHT)
897 (reverse line-stencils)
899 (if (pair? (cdr line-break))
900 (loop (cons line lines)
903 (if (= text-dir LEFT)
905 (ly:stencil-translate-axis
907 (- line-width (interval-end (ly:stencil-extent line X)))
909 (reverse (cons line lines)))))))
911 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
912 (boolean? markup-list?)
915 (text-direction RIGHT))
916 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
917 (wordwrap-stencils (remove ly:stencil-empty?
918 (interpret-markup-list layout props args))
922 (ly:output-def-lookup layout 'line-width))
925 (define-builtin-markup-command (justify layout props args)
929 wordwrap-internal-markup-list)
931 @cindex justifying text
933 Like wordwrap, but with lines stretched to justify the margins.
934 Use @code{\\override #'(line-width . @var{X})} to set the line width;
935 @var{X}@tie{}is the number of staff spaces.
937 @lilypond[verbatim,quote]
940 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
941 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
942 Ut enim ad minim veniam, quis nostrud exercitation ullamco
943 laboris nisi ut aliquip ex ea commodo consequat.
947 (stack-lines DOWN 0.0 baseline-skip
948 (wordwrap-internal-markup-list layout props #t args)))
950 (define-builtin-markup-command (wordwrap layout props args)
954 wordwrap-internal-markup-list)
955 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
956 the line width, where @var{X} is the number of staff spaces.
958 @lilypond[verbatim,quote]
961 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
962 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
963 Ut enim ad minim veniam, quis nostrud exercitation ullamco
964 laboris nisi ut aliquip ex ea commodo consequat.
968 (stack-lines DOWN 0.0 baseline-skip
969 (wordwrap-internal-markup-list layout props #f args)))
971 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
975 (text-direction RIGHT))
976 "Internal markup list command used to define @code{\\justify-string} and
977 @code{\\wordwrap-string}."
978 (let* ((para-strings (regexp-split
979 (string-regexp-substitute
981 (string-regexp-substitute "\r\n" "\n" arg))
982 "\n[ \t\n]*\n[ \t\n]*"))
983 (list-para-words (map (lambda (str)
984 (regexp-split str "[ \t\n]+"))
986 (para-lines (map (lambda (words)
988 (remove ly:stencil-empty?
990 (interpret-markup layout props x))
992 (wordwrap-stencils stencils
994 line-width text-direction)))
996 (apply append para-lines)))
998 (define-builtin-markup-command (wordwrap-string layout props arg)
1002 wordwrap-string-internal-markup-list)
1003 "Wordwrap a string. Paragraphs may be separated with double newlines.
1005 @lilypond[verbatim,quote]
1007 \\override #'(line-width . 40)
1008 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1009 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1010 et dolore magna aliqua.
1013 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1014 laboris nisi ut aliquip ex ea commodo consequat.
1017 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1018 qui officia deserunt mollit anim id est laborum\"
1021 (stack-lines DOWN 0.0 baseline-skip
1022 (wordwrap-string-internal-markup-list layout props #f arg)))
1024 (define-builtin-markup-command (justify-string layout props arg)
1028 wordwrap-string-internal-markup-list)
1029 "Justify a string. Paragraphs may be separated with double newlines
1031 @lilypond[verbatim,quote]
1033 \\override #'(line-width . 40)
1034 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1035 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1036 et dolore magna aliqua.
1039 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1040 laboris nisi ut aliquip ex ea commodo consequat.
1043 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1044 qui officia deserunt mollit anim id est laborum\"
1047 (stack-lines DOWN 0.0 baseline-skip
1048 (wordwrap-string-internal-markup-list layout props #t arg)))
1050 (define-builtin-markup-command (wordwrap-field layout props symbol)
1054 "Wordwrap the data which has been assigned to @var{symbol}.
1056 @lilypond[verbatim,quote]
1058 title = \"My title\"
1059 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1060 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1061 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1062 nisi ut aliquip ex ea commodo consequat.\"
1066 bookTitleMarkup = \\markup {
1068 \\fill-line { \\fromproperty #'header:title }
1070 \\wordwrap-field #'header:descr
1079 (let* ((m (chain-assoc-get symbol props)))
1081 (wordwrap-string-markup layout props m)
1084 (define-builtin-markup-command (justify-field layout props symbol)
1088 "Justify the data which has been assigned to @var{symbol}.
1090 @lilypond[verbatim,quote]
1092 title = \"My title\"
1093 descr = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit,
1094 sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1095 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
1096 nisi ut aliquip ex ea commodo consequat.\"
1100 bookTitleMarkup = \\markup {
1102 \\fill-line { \\fromproperty #'header:title }
1104 \\justify-field #'header:descr
1113 (let* ((m (chain-assoc-get symbol props)))
1115 (justify-string-markup layout props m)
1118 (define-builtin-markup-command (combine layout props m1 m2)
1123 @cindex merging text
1125 Print two markups on top of each other.
1127 Note: @code{\\combine} cannot take a list of markups enclosed in
1128 curly braces as an argument; the follow example will not compile:
1131 \\combine @{ a list @}
1134 @lilypond[verbatim,quote]
1137 \\override #'(thickness . 2)
1139 \\draw-line #'(0 . 4)
1140 \\arrow-head #Y #DOWN ##f
1143 (let* ((s1 (interpret-markup layout props m1))
1144 (s2 (interpret-markup layout props m2)))
1145 (ly:stencil-add s1 s2)))
1148 ;; TODO: should extract baseline-skip from each argument somehow..
1150 (define-builtin-markup-command (column layout props args)
1155 @cindex stacking text in a column
1157 Stack the markups in @var{args} vertically. The property
1158 @code{baseline-skip} determines the space between each
1159 markup in @var{args}.
1161 @lilypond[verbatim,quote]
1170 (let ((arg-stencils (interpret-markup-list layout props args)))
1171 (stack-lines -1 0.0 baseline-skip
1172 (remove ly:stencil-empty? arg-stencils))))
1174 (define-builtin-markup-command (dir-column layout props args)
1180 @cindex changing direction of text columns
1182 Make a column of args, going up or down, depending on the setting
1183 of the @code{#'direction} layout property.
1185 @lilypond[verbatim,quote]
1187 \\override #'(direction . 1) {
1197 (stack-lines (if (number? direction) direction -1)
1200 (interpret-markup-list layout props args)))
1202 (define-builtin-markup-command (center-align layout props args)
1207 @cindex centering a column of text
1209 Put @code{args} in a centered column.
1211 @lilypond[verbatim,quote]
1220 (let* ((mols (interpret-markup-list layout props args))
1221 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
1222 (stack-lines -1 0.0 baseline-skip cmols)))
1224 (define-builtin-markup-command (vcenter layout props arg)
1229 @cindex vertically centering text
1231 Align @code{arg} to its Y@tie{}center.
1233 @lilypond[verbatim,quote]
1235 \\arrow-head #X #RIGHT ##f
1238 \\arrow-head #X #LEFT ##f
1241 (let* ((mol (interpret-markup layout props arg)))
1242 (ly:stencil-aligned-to mol Y CENTER)))
1244 (define-builtin-markup-command (hcenter layout props arg)
1249 @cindex horizontally centering text
1251 Align @code{arg} to its X@tie{}center.
1253 @lilypond[verbatim,quote]
1262 (let* ((mol (interpret-markup layout props arg)))
1263 (ly:stencil-aligned-to mol X CENTER)))
1265 (define-builtin-markup-command (right-align layout props arg)
1270 @cindex right aligning text
1272 Align @var{arg} on its right edge.
1274 @lilypond[verbatim,quote]
1283 (let* ((m (interpret-markup layout props arg)))
1284 (ly:stencil-aligned-to m X RIGHT)))
1286 (define-builtin-markup-command (left-align layout props arg)
1291 @cindex left aligning text
1293 Align @var{arg} on its left edge.
1295 @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
1323 \\general-align #X #CENTER
1324 \\line { X, Center }
1327 \\arrow-head #X #RIGHT ##f
1328 \\general-align #Y #DOWN
1330 \\arrow-head #X #LEFT ##f
1333 \\arrow-head #X #RIGHT ##f
1334 \\general-align #Y #3.2
1336 \\line { Y, Arbitrary alignment }
1338 \\arrow-head #X #LEFT ##f
1343 (let* ((m (interpret-markup layout props arg)))
1344 (ly:stencil-aligned-to m axis dir)))
1346 (define-builtin-markup-command (halign layout props dir arg)
1351 @cindex setting horizontal text alignment
1353 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1354 left-aligned, while @code{+1} is right. Values in between interpolate
1355 alignment accordingly.
1357 @lilypond[verbatim,quote]
1377 (let* ((m (interpret-markup layout props arg)))
1378 (ly:stencil-aligned-to m X dir)))
1380 (define-builtin-markup-command (with-dimensions layout props x y arg)
1381 (number-pair? number-pair? markup?)
1385 @cindex setting extent of text objects
1387 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1388 (let* ((m (interpret-markup layout props arg)))
1389 (ly:make-stencil (ly:stencil-expr m) x y)))
1391 (define-builtin-markup-command (pad-around layout props amount arg)
1395 "Add padding @var{amount} all around @var{arg}.
1397 @lilypond[verbatim,quote]
1410 (let* ((m (interpret-markup layout props arg))
1411 (x (ly:stencil-extent m X))
1412 (y (ly:stencil-extent m Y)))
1413 (ly:make-stencil (ly:stencil-expr m)
1414 (interval-widen x amount)
1415 (interval-widen y amount))))
1417 (define-builtin-markup-command (pad-x layout props amount arg)
1422 @cindex padding text horizontally
1424 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1426 @lilypond[verbatim,quote]
1439 (let* ((m (interpret-markup layout props arg))
1440 (x (ly:stencil-extent m X))
1441 (y (ly:stencil-extent m Y)))
1442 (ly:make-stencil (ly:stencil-expr m)
1443 (interval-widen x amount)
1446 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1447 (integer? ly:dir? markup? markup?)
1450 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1451 (let ((m1 (interpret-markup layout props arg1))
1452 (m2 (interpret-markup layout props arg2)))
1453 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1455 (define-builtin-markup-command (transparent layout props arg)
1459 "Make the argument transparent.
1461 @lilypond[verbatim,quote]
1468 (let* ((m (interpret-markup layout props arg))
1469 (x (ly:stencil-extent m X))
1470 (y (ly:stencil-extent m Y)))
1471 (ly:make-stencil "" x y)))
1473 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1474 (number-pair? number-pair? markup?)
1477 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1479 @lilypond[verbatim,quote]
1486 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1492 (let* ((m (interpret-markup layout props arg))
1493 (x (ly:stencil-extent m X))
1494 (y (ly:stencil-extent m Y)))
1495 (ly:make-stencil (ly:stencil-expr m)
1496 (interval-union x-ext x)
1497 (interval-union y-ext y))))
1499 (define-builtin-markup-command (hcenter-in layout props length arg)
1503 "Center @var{arg} horizontally within a box of extending
1504 @var{length}/2 to the left and right.
1506 @lilypond[quote,verbatim]
1509 \\set Staff.instrumentName = \\markup {
1516 \\set Staff.instrumentName = \\markup {
1525 (interpret-markup layout props
1526 (make-pad-to-box-markup
1527 (cons (/ length -2) (/ length 2))
1529 (make-hcenter-markup arg))))
1531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1535 (define-builtin-markup-command (fromproperty layout props symbol)
1539 "Read the @var{symbol} from property settings, and produce a stencil
1540 from the markup contained within. If @var{symbol} is not defined, it
1541 returns an empty markup.
1543 @lilypond[verbatim,quote]
1545 myTitle = \"myTitle\"
1549 \\fromproperty #'header:myTitle
1556 (let ((m (chain-assoc-get symbol props)))
1558 (interpret-markup layout props m)
1561 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1565 "Apply the @var{procedure} markup command to @var{arg}.
1566 @var{procedure} should take a single argument."
1567 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1568 (set-object-property! anonymous-with-signature
1571 (interpret-markup layout props (list anonymous-with-signature arg))))
1573 (define-builtin-markup-command (override layout props new-prop arg)
1578 @cindex overriding properties within text markup
1580 Add the first argument in to the property list. Properties may be
1581 any sort of property supported by @rinternals{font-interface} and
1582 @rinternals{text-interface}, for example
1585 \\override #'(font-family . married) \"bla\"
1588 @lilypond[verbatim,quote]
1596 \\override #'(baseline-skip . 4) {
1605 (interpret-markup layout (cons (list new-prop) props) arg))
1607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1611 (define-builtin-markup-command (verbatim-file layout props name)
1615 "Read the contents of a file, and include it verbatim.
1617 @lilypond[verbatim,quote]
1619 \\verbatim-file #\"simple.ly\"
1622 (interpret-markup layout props
1623 (if (ly:get-option 'safe)
1624 "verbatim-file disabled in safe mode"
1625 (let* ((str (ly:gulp-file name))
1626 (lines (string-split str #\nl)))
1627 (make-typewriter-markup
1628 (make-column-markup lines))))))
1630 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1632 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1634 (define-builtin-markup-command (bigger layout props arg)
1638 "Increase the font size relative to current setting.
1640 @lilypond[verbatim,quote]
1653 (interpret-markup layout props
1654 `(,fontsize-markup 1 ,arg)))
1656 (define-builtin-markup-command (smaller layout props arg)
1660 "Decrease the font size relative to current setting.
1662 @lilypond[verbatim,quote]
1675 (interpret-markup layout props
1676 `(,fontsize-markup -1 ,arg)))
1678 (define-builtin-markup-command (larger layout props arg)
1682 "Copy of the @code{\\bigger} command.
1684 @lilypond[verbatim,quote]
1692 (interpret-markup layout props (make-bigger-markup arg)))
1694 (define-builtin-markup-command (finger layout props arg)
1698 "Set the argument as small numbers.
1699 @lilypond[verbatim,quote]
1706 (interpret-markup layout
1707 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1710 (define-builtin-markup-command (abs-fontsize layout props size arg)
1714 "Use @var{size} as the absolute font size to display @var{arg}.
1715 Adjust baseline skip and word space accordingly.
1716 @lilypond[verbatim,quote]
1718 default text font size
1720 \\abs-fontsize #16 { text font size 16 }
1722 \\abs-fontsize #12 { text font size 12 }
1725 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1726 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1727 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1728 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1729 (magnification (/ size ref-size)))
1730 (interpret-markup layout
1731 (cons `((baseline-skip . ,(* magnification ref-baseline))
1732 (word-space . ,(* magnification ref-word-space))
1733 (font-size . ,(magnification->font-size magnification)))
1737 (define-builtin-markup-command (fontsize layout props increment arg)
1743 "Add @var{increment} to the font-size. Adjust baseline skip accordingly.
1744 @lilypond[verbatim,quote]
1752 (let ((entries (list
1753 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1754 (cons 'word-space (* word-space (magstep increment)))
1755 (cons 'font-size (+ font-size increment)))))
1756 (interpret-markup layout (cons entries props) arg)))
1758 (define-builtin-markup-command (magnify layout props sz arg)
1763 @cindex magnifying text
1765 Set the font magnification for its argument. In the following
1766 example, the middle@tie{}A is 10% larger:
1769 A \\magnify #1.1 @{ A @} A
1772 Note: Magnification only works if a font name is explicitly selected.
1773 Use @code{\\fontsize} otherwise.
1775 @lilypond[verbatim,quote]
1786 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1789 (define-builtin-markup-command (bold layout props arg)
1793 "Switch to bold font-series.
1795 @lilypond[verbatim,quote]
1803 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1805 (define-builtin-markup-command (sans layout props arg)
1809 "Switch to the sans serif family.
1811 @lilypond[verbatim,quote]
1820 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1822 (define-builtin-markup-command (number layout props arg)
1826 "Set font family to @code{number}, which yields the font used for
1827 time signatures and fingerings. This font only contains numbers and
1828 some punctuation. It doesn't have any letters.
1830 @lilypond[verbatim,quote]
1833 0 1 2 3 4 5 6 7 8 9 . ,
1837 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1839 (define-builtin-markup-command (roman layout props arg)
1843 "Set font family to @code{roman}.
1845 @lilypond[verbatim,quote]
1851 text in roman font family
1858 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1860 (define-builtin-markup-command (huge layout props arg)
1864 "Set font size to +2.
1866 @lilypond[verbatim,quote]
1874 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1876 (define-builtin-markup-command (large layout props arg)
1880 "Set font size to +1.
1882 @lilypond[verbatim,quote]
1890 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1892 (define-builtin-markup-command (normalsize layout props arg)
1896 "Set font size to default.
1898 @lilypond[verbatim,quote]
1911 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1913 (define-builtin-markup-command (small layout props arg)
1917 "Set font size to -1.
1919 @lilypond[verbatim,quote]
1927 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1929 (define-builtin-markup-command (tiny layout props arg)
1933 "Set font size to -2.
1935 @lilypond[verbatim,quote]
1943 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
1945 (define-builtin-markup-command (teeny layout props arg)
1949 "Set font size to -3.
1951 @lilypond[verbatim,quote]
1959 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
1961 (define-builtin-markup-command (fontCaps layout props arg)
1965 "Set @code{font-shape} to @code{caps}
1967 Note: @code{\\fontCaps} requires the installation and selection of
1968 fonts which support the @code{caps} font shape."
1969 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
1972 (define-builtin-markup-command (smallCaps layout props text)
1976 "Emit @var{arg} as small caps.
1978 Note: @code{\\smallCaps} does not support accented characters.
1980 @lilypond[verbatim,quote]
1989 (define (char-list->markup chars lower)
1990 (let ((final-string (string-upcase (reverse-list->string chars))))
1992 (markup #:fontsize -2 final-string)
1994 (define (make-small-caps rest-chars currents current-is-lower prev-result)
1995 (if (null? rest-chars)
1997 (reverse! (cons (char-list->markup currents current-is-lower)
1999 (let* ((ch (car rest-chars))
2000 (is-lower (char-lower-case? ch)))
2001 (if (or (and current-is-lower is-lower)
2002 (and (not current-is-lower) (not is-lower)))
2003 (make-small-caps (cdr rest-chars)
2007 (make-small-caps (cdr rest-chars)
2010 (if (null? currents)
2012 (cons (char-list->markup
2013 currents current-is-lower)
2015 (interpret-markup layout props
2017 (make-small-caps (string->list text) (list) #f (list))
2020 (define-builtin-markup-command (caps layout props arg)
2024 "Copy of the @code{\\smallCaps} command.
2026 @lilypond[verbatim,quote]
2035 (interpret-markup layout props (make-smallCaps-markup arg)))
2037 (define-builtin-markup-command (dynamic layout props arg)
2041 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2042 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2043 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2044 done in a different font. The recommended font for this is bold and italic.
2045 @lilypond[verbatim,quote]
2053 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2055 (define-builtin-markup-command (text layout props arg)
2059 "Use a text font instead of music symbol or music alphabet font.
2061 @lilypond[verbatim,quote]
2074 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2077 (define-builtin-markup-command (italic layout props arg)
2081 "Use italic @code{font-shape} for @var{arg}.
2083 @lilypond[verbatim,quote]
2091 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2093 (define-builtin-markup-command (typewriter layout props arg)
2097 "Use @code{font-family} typewriter for @var{arg}.
2099 @lilypond[verbatim,quote]
2108 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2110 (define-builtin-markup-command (upright layout props arg)
2114 "Set font shape to @code{upright}. This is the opposite of @code{italic}.
2116 @lilypond[verbatim,quote]
2130 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2132 (define-builtin-markup-command (medium layout props arg)
2136 "Switch to medium font series (in contrast to bold).
2138 @lilypond[verbatim,quote]
2151 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2154 (define-builtin-markup-command (normal-text layout props arg)
2158 "Set all font related properties (except the size) to get the default
2159 normal text font, no matter what font was used earlier.
2161 @lilypond[verbatim,quote]
2163 \\huge \\bold \\sans \\caps {
2164 Some text with font overrides
2167 Default text, same font-size
2175 (interpret-markup layout
2176 (cons '((font-family . roman) (font-shape . upright)
2177 (font-series . medium) (font-encoding . latin1))
2181 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2185 (define-builtin-markup-command (doublesharp layout props)
2189 "Draw a double sharp symbol.
2191 @lilypond[verbatim,quote]
2196 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2198 (define-builtin-markup-command (sesquisharp layout props)
2202 "Draw a 3/2 sharp symbol.
2204 @lilypond[verbatim,quote]
2209 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2211 (define-builtin-markup-command (sharp layout props)
2215 "Draw a sharp symbol.
2217 @lilypond[verbatim,quote]
2222 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2224 (define-builtin-markup-command (semisharp layout props)
2228 "Draw a semi sharp symbol.
2230 @lilypond[verbatim,quote]
2235 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2237 (define-builtin-markup-command (natural layout props)
2241 "Draw a natural symbol.
2243 @lilypond[verbatim,quote]
2248 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2250 (define-builtin-markup-command (semiflat layout props)
2254 "Draw a semiflat symbol.
2256 @lilypond[verbatim,quote]
2261 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2263 (define-builtin-markup-command (flat layout props)
2267 "Draw a flat symbol.
2269 @lilypond[verbatim,quote]
2274 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2276 (define-builtin-markup-command (sesquiflat layout props)
2280 "Draw a 3/2 flat symbol.
2282 @lilypond[verbatim,quote]
2287 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2289 (define-builtin-markup-command (doubleflat layout props)
2293 "Draw a double flat symbol.
2295 @lilypond[verbatim,quote]
2300 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2302 (define-builtin-markup-command (with-color layout props color arg)
2307 @cindex coloring text
2309 Draw @var{arg} in color specified by @var{color}.
2311 @lilypond[verbatim,quote]
2323 (let ((stil (interpret-markup layout props arg)))
2324 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2325 (ly:stencil-extent stil X)
2326 (ly:stencil-extent stil Y))))
2328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2330 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2332 (define-builtin-markup-command (arrow-head layout props axis direction filled)
2333 (integer? ly:dir? boolean?)
2336 "Produce an arrow head in specified direction and axis.
2337 Use the filled head if @var{filled} is specified.
2338 @lilypond[verbatim,quote]
2341 \\general-align #Y #DOWN {
2342 \\arrow-head #Y #UP ##t
2343 \\arrow-head #Y #DOWN ##f
2345 \\arrow-head #X #RIGHT ##f
2346 \\arrow-head #X #LEFT ##f
2352 ((name (format "arrowheads.~a.~a~a"
2359 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2363 (define-builtin-markup-command (musicglyph layout props glyph-name)
2367 "@var{glyph-name} is converted to a musical symbol; for example,
2368 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2369 the music font. See @ruser{The Feta font} for a complete listing of
2370 the possible glyphs.
2372 @lilypond[verbatim,quote]
2375 \\musicglyph #\"rests.2\"
2376 \\musicglyph #\"clefs.G_change\"
2379 (let* ((font (ly:paper-get-font layout
2380 (cons '((font-encoding . fetaMusic)
2384 (glyph (ly:font-get-glyph font glyph-name)))
2385 (if (null? (ly:stencil-expr glyph))
2386 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2391 (define-builtin-markup-command (lookup layout props glyph-name)
2395 "Lookup a glyph by name.
2397 @lilypond[verbatim,quote]
2399 \\override #'(font-encoding . fetaBraces) {
2400 \\lookup #\"brace200\"
2403 \\lookup #\"brace180\"
2407 (ly:font-get-glyph (ly:paper-get-font layout props)
2410 (define-builtin-markup-command (char layout props num)
2414 "Produce a single character. For example, @code{\\char #65} produces the
2417 @lilypond[verbatim,quote]
2422 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2424 (define number->mark-letter-vector (make-vector 25 #\A))
2429 (if (= i (- (char->integer #\I) (char->integer #\A)))
2431 (vector-set! number->mark-letter-vector j
2432 (integer->char (+ i (char->integer #\A)))))
2434 (define number->mark-alphabet-vector (list->vector
2435 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2437 (define (number->markletter-string vec n)
2438 "Double letters for big marks."
2439 (let* ((lst (vector-length vec)))
2442 (string-append (number->markletter-string vec (1- (quotient n lst)))
2443 (number->markletter-string vec (remainder n lst)))
2444 (make-string 1 (vector-ref vec n)))))
2446 (define-builtin-markup-command (markletter layout props num)
2450 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2451 (skipping letter@tie{}I), and continue with double letters.
2453 @lilypond[verbatim,quote]
2460 (ly:text-interface::interpret-markup layout props
2461 (number->markletter-string number->mark-letter-vector num)))
2463 (define-builtin-markup-command (markalphabet layout props num)
2467 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2468 and continue with double letters.
2470 @lilypond[verbatim,quote]
2477 (ly:text-interface::interpret-markup layout props
2478 (number->markletter-string number->mark-alphabet-vector num)))
2480 (define-public (horizontal-slash-interval num forward number-interval mag)
2482 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2483 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2484 (else (interval-widen number-interval (* mag 0.25))))
2485 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2486 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2487 (else (interval-widen number-interval (* mag 0.25))))
2490 (define-public (adjust-slash-stencil num forward stencil mag)
2493 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2495 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2497 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2499 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2502 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2504 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2509 (define (slashed-digit-internal layout props num forward font-size thickness)
2510 (let* ((mag (magstep font-size))
2512 (ly:output-def-lookup layout 'line-thickness)
2514 ; backward slashes might use slope and point in the other direction!
2515 (dy (* mag (if forward 0.4 -0.4)))
2516 (number-stencil (interpret-markup layout
2517 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2518 (number->string num)))
2519 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2520 (center (interval-center (ly:stencil-extent number-stencil Y)))
2521 ; Use the real extents of the slash, not the whole number, because we
2522 ; might translate the slash later on!
2523 (num-y (interval-widen (cons center center) (abs dy)))
2524 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2525 (slash-stencil (if is-sane
2527 `(draw-line ,thickness
2528 ,(car num-x) ,(- (interval-center num-y) dy)
2529 ,(cdr num-x) ,(+ (interval-center num-y) dy))
2532 (if (ly:stencil? slash-stencil)
2534 ; for some numbers we need to shift the slash/backslash up or down to make
2535 ; the slashed digit look better
2536 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2537 (set! number-stencil
2538 (ly:stencil-add number-stencil slash-stencil)))
2539 (ly:warning "Unable to create slashed digit ~a" num))
2543 (define-builtin-markup-command (slashed-digit layout props num)
2549 @cindex slashed digits
2551 A feta number, with slash. This is for use in the context of
2552 figured bass notation.
2553 @lilypond[verbatim,quote]
2557 \\override #'(thickness . 3)
2561 (slashed-digit-internal layout props num #t font-size thickness))
2563 (define-builtin-markup-command (backslashed-digit layout props num)
2569 @cindex backslashed digits
2571 A feta number, with backslash. This is for use in the context of
2572 figured bass notation.
2573 @lilypond[verbatim,quote]
2575 \\backslashed-digit #5
2577 \\override #'(thickness . 3)
2578 \\backslashed-digit #7
2581 (slashed-digit-internal layout props num #f font-size thickness))
2583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2584 ;; the note command.
2585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2587 ;; TODO: better syntax.
2589 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2590 (number? number? number?)
2595 @cindex notes within text by log and dot-count
2597 Construct a note symbol, with stem. By using fractional values for
2598 @var{dir}, you can obtain longer or shorter stems.
2600 @lilypond[verbatim,quote]
2602 \\note-by-number #3 #0 #DOWN
2604 \\note-by-number #1 #2 #0.8
2607 (define (get-glyph-name-candidates dir log style)
2608 (map (lambda (dir-name)
2609 (format "noteheads.~a~a~a" dir-name (min log 2)
2610 (if (and (symbol? style)
2611 (not (equal? 'default style)))
2612 (symbol->string style)
2614 (list (if (= dir UP) "u" "d")
2617 (define (get-glyph-name font cands)
2620 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2621 (get-glyph-name font (cdr cands))
2624 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
2625 (size-factor (magstep font-size))
2626 (stem-length (* size-factor (max 3 (- log 1))))
2627 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
2628 (head-glyph (ly:font-get-glyph font head-glyph-name))
2629 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2630 (stem-thickness (* size-factor 0.13))
2631 (stemy (* dir stem-length))
2632 (attach-off (cons (interval-index
2633 (ly:stencil-extent head-glyph X)
2634 (* (sign dir) (car attach-indices)))
2635 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2637 (ly:stencil-extent head-glyph Y)
2638 (cdr attach-indices)))))
2639 (stem-glyph (and (> log 0)
2640 (ly:round-filled-box
2641 (ordered-cons (car attach-off)
2642 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
2643 (cons (min stemy (cdr attach-off))
2644 (max stemy (cdr attach-off)))
2645 (/ stem-thickness 3))))
2647 (dot (ly:font-get-glyph font "dots.dot"))
2648 (dotwid (interval-length (ly:stencil-extent dot X)))
2649 (dots (and (> dot-count 0)
2650 (apply ly:stencil-add
2652 (ly:stencil-translate-axis
2653 dot (* 2 x dotwid) X))
2654 (iota dot-count)))))
2655 (flaggl (and (> log 2)
2656 (ly:stencil-translate
2657 (ly:font-get-glyph font
2658 (string-append "flags."
2659 (if (> dir 0) "u" "d")
2660 (number->string log)))
2661 (cons (+ (car attach-off) (if (< dir 0) stem-thickness 0)) stemy)))))
2663 ; If there is a flag on an upstem and the stem is short, move the dots to avoid the flag.
2664 ; 16th notes get a special case because their flags hang lower than any other flags.
2665 (if (and dots (> dir 0) (> log 2) (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2666 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2668 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2669 (if (ly:stencil? stem-glyph)
2670 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2671 (set! stem-glyph head-glyph))
2672 (if (ly:stencil? dots)
2675 (ly:stencil-translate-axis
2677 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2683 (let ((divisor (log 2)))
2684 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2686 (define (parse-simple-duration duration-string)
2687 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
2688 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
2689 (if (and match (string=? duration-string (match:substring match 0)))
2690 (let ((len (match:substring match 1))
2691 (dots (match:substring match 2)))
2692 (list (cond ((string=? len "breve") -1)
2693 ((string=? len "longa") -2)
2694 ((string=? len "maxima") -3)
2695 (else (log2 (string->number len))))
2696 (if dots (string-length dots) 0)))
2697 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2699 (define-builtin-markup-command (note layout props duration dir)
2702 (note-by-number-markup)
2704 @cindex notes within text by string
2706 This produces a note with a stem pointing in @var{dir} direction, with
2707 the @var{duration} for the note head type and augmentation dots. For
2708 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2709 a shortened down stem.
2711 @lilypond[verbatim,quote]
2713 \\override #'(style . cross) {
2717 \\note #\"breve\" #0
2720 (let ((parsed (parse-simple-duration duration)))
2721 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2723 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2725 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2727 (define-builtin-markup-command (lower layout props amount arg)
2732 @cindex lowering text
2734 Lower @var{arg} by the distance @var{amount}.
2735 A negative @var{amount} indicates raising; see also @code{\\raise}.
2737 @lilypond[verbatim,quote]
2745 (ly:stencil-translate-axis (interpret-markup layout props arg)
2748 (define-builtin-markup-command (translate-scaled layout props offset arg)
2749 (number-pair? markup?)
2753 @cindex translating text
2754 @cindex scaling text
2756 Translate @var{arg} by @var{offset}, scaling the offset by the
2759 @lilypond[verbatim,quote]
2762 * \\translate #'(2 . 3) translate
2764 * \\translate-scaled #'(2 . 3) translate-scaled
2768 (let* ((factor (magstep font-size))
2769 (scaled (cons (* factor (car offset))
2770 (* factor (cdr offset)))))
2771 (ly:stencil-translate (interpret-markup layout props arg)
2774 (define-builtin-markup-command (raise layout props amount arg)
2779 @cindex raising text
2781 Raise @var{arg} by the distance @var{amount}.
2782 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2784 The argument to @code{\\raise} is the vertical displacement amount,
2785 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2786 raise objects in relation to their surrounding markups.
2788 If the text object itself is positioned above or below the staff, then
2789 @code{\\raise} cannot be used to move it, since the mechanism that
2790 positions it next to the staff cancels any shift made with
2791 @code{\\raise}. For vertical positioning, use the @code{padding}
2792 and/or @code{extra-offset} properties.
2794 @lilypond[verbatim,quote]
2803 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2805 (define-builtin-markup-command (fraction layout props arg1 arg2)
2810 @cindex creating text fractions
2812 Make a fraction of two markups.
2813 @lilypond[verbatim,quote]
2819 (let* ((m1 (interpret-markup layout props arg1))
2820 (m2 (interpret-markup layout props arg2))
2821 (factor (magstep font-size))
2822 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2823 (padding (* factor 0.2))
2824 (baseline (* factor 0.6))
2825 (offset (* factor 0.75)))
2826 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2827 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2828 (let* ((x1 (ly:stencil-extent m1 X))
2829 (x2 (ly:stencil-extent m2 X))
2830 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2831 ;; should stack mols separately, to maintain LINE on baseline
2832 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2834 (ly:stencil-aligned-to stack Y CENTER))
2836 (ly:stencil-aligned-to stack X LEFT))
2837 ;; should have EX dimension
2839 (ly:stencil-translate-axis stack offset Y))))
2841 (define-builtin-markup-command (normal-size-super layout props arg)
2846 @cindex setting superscript in standard font size
2848 Set @var{arg} in superscript with a normal font size.
2850 @lilypond[verbatim,quote]
2853 \\normal-size-super {
2854 superscript in standard size
2858 (ly:stencil-translate-axis
2859 (interpret-markup layout props arg)
2860 (* 0.5 baseline-skip) Y))
2862 (define-builtin-markup-command (super layout props arg)
2868 @cindex superscript text
2870 Raising and lowering texts can be done with @code{\\super} and
2873 @lilypond[verbatim,quote]
2883 (ly:stencil-translate-axis
2886 (cons `((font-size . ,(- font-size 3))) props)
2888 (* 0.5 baseline-skip)
2891 (define-builtin-markup-command (translate layout props offset arg)
2892 (number-pair? markup?)
2896 @cindex translating text
2898 This translates an object. Its first argument is a cons of numbers.
2901 A \\translate #(cons 2 -3) @{ B C @} D
2904 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
2905 surroundings. This command cannot be used to move isolated scripts
2906 vertically, for the same reason that @code{\\raise} cannot be used for
2909 @lilypond[verbatim,quote]
2912 \\translate #'(2 . 3)
2913 \\line { translated two spaces right, three up }
2916 (ly:stencil-translate (interpret-markup layout props arg)
2919 (define-builtin-markup-command (sub layout props arg)
2925 @cindex subscript text
2927 Set @var{arg} in subscript.
2929 @lilypond[verbatim,quote]
2940 (ly:stencil-translate-axis
2943 (cons `((font-size . ,(- font-size 3))) props)
2945 (* -0.5 baseline-skip)
2948 (define-builtin-markup-command (normal-size-sub layout props arg)
2953 @cindex setting subscript in standard font size
2955 Set @var{arg} in subscript, in a normal font size.
2957 @lilypond[verbatim,quote]
2961 subscript in standard size
2965 (ly:stencil-translate-axis
2966 (interpret-markup layout props arg)
2967 (* -0.5 baseline-skip)
2970 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2972 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2974 (define-builtin-markup-command (hbracket layout props arg)
2979 @cindex placing horizontal brackets around text
2981 Draw horizontal brackets around @var{arg}.
2983 @lilypond[verbatim,quote]
2992 (let ((th 0.1) ;; todo: take from GROB.
2993 (m (interpret-markup layout props arg)))
2994 (bracketify-stencil m X th (* 2.5 th) th)))
2996 (define-builtin-markup-command (bracket layout props arg)
3001 @cindex placing vertical brackets around text
3003 Draw vertical brackets around @var{arg}.
3005 @lilypond[verbatim,quote]
3012 (let ((th 0.1) ;; todo: take from GROB.
3013 (m (interpret-markup layout props arg)))
3014 (bracketify-stencil m Y th (* 2.5 th) th)))
3016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3017 ;; Delayed markup evaluation
3018 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3020 (define-builtin-markup-command (page-ref layout props label gauge default)
3021 (symbol? markup? markup?)
3025 @cindex referencing page numbers in text
3027 Reference to a page number. @var{label} is the label set on the referenced
3028 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3029 the maximum width of the page number, and @var{default} the value to display
3030 when @var{label} is not found."
3031 (let* ((gauge-stencil (interpret-markup layout props gauge))
3032 (x-ext (ly:stencil-extent gauge-stencil X))
3033 (y-ext (ly:stencil-extent gauge-stencil Y)))
3035 `(delay-stencil-evaluation
3036 ,(delay (ly:stencil-expr
3037 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3038 (label-page (and (list? table) (assoc label table)))
3039 (page-number (and label-page (cdr label-page)))
3040 (page-markup (if page-number (format "~a" page-number) default))
3041 (page-stencil (interpret-markup layout props page-markup))
3042 (gap (- (interval-length x-ext)
3043 (interval-length (ly:stencil-extent page-stencil X)))))
3044 (interpret-markup layout props
3045 (markup #:concat (#:hspace gap page-markup)))))))
3049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3050 ;; Markup list commands
3051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3053 (define-public (space-lines baseline stils)
3054 (let space-stil ((stils stils)
3058 (let* ((stil (car stils))
3059 (dy-top (max (- (/ baseline 1.5)
3060 (interval-bound (ly:stencil-extent stil Y) UP))
3062 (dy-bottom (max (+ (/ baseline 3.0)
3063 (interval-bound (ly:stencil-extent stil Y) DOWN))
3065 (new-stil (ly:make-stencil
3066 (ly:stencil-expr stil)
3067 (ly:stencil-extent stil X)
3068 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3070 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3072 (space-stil (cdr stils) (cons new-stil result))))))
3074 (define-builtin-markup-list-command (justified-lines layout props args)
3077 wordwrap-internal-markup-list)
3079 @cindex justifying lines of text
3081 Like @code{\\justify}, but return a list of lines instead of a single markup.
3082 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3083 @var{X}@tie{}is the number of staff spaces."
3084 (space-lines baseline-skip
3085 (interpret-markup-list layout props
3086 (make-wordwrap-internal-markup-list #t args))))
3088 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3091 wordwrap-internal-markup-list)
3092 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3093 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3094 where @var{X} is the number of staff spaces."
3095 (space-lines baseline-skip
3096 (interpret-markup-list layout props
3097 (make-wordwrap-internal-markup-list #f args))))
3099 (define-builtin-markup-list-command (column-lines layout props args)
3102 "Like @code{\\column}, but return a list of lines instead of a single markup.
3103 @code{baseline-skip} determines the space between each markup in @var{args}."
3104 (space-lines (chain-assoc-get 'baseline-skip props)
3105 (interpret-markup-list layout props args)))
3107 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3108 (pair? markup-list?)
3110 "Like @code{\\override}, for markup lists."
3111 (interpret-markup-list layout (cons (list new-prop) props) args))