1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Markup commands and markup-list commands definitions.
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-builtin-markup-command' macro.
28 ;;; (define-builtin-markup-command (command-name layout props args...)
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
42 ;;; `layout' is an output def, which properties can be accessed
43 ;;; using `ly:output-def-lookup'.
44 ;;; `props' is a list of property settings which can be accessed
45 ;;; using `chain-assoc-get' (more on that below)
48 ;;; the command arguments. There are restrictions on the
49 ;;; possible arguments for a markup command.
50 ;;; First, arguments are distingued according to their type:
51 ;;; 1) a markup (or a string), corresponding to type predicate `markup?'
52 ;;; 2) a list of markups, corresponding to type predicate `markup-list?'
53 ;;; 3) any scheme object, corresponding to type predicates such as
54 ;;; `list?', 'number?', 'boolean?', etc.
55 ;;; The supported arrangements of arguments, according to their type, are:
63 ;;; - scheme, scheme, markup
64 ;;; - scheme, scheme, markup, markup
65 ;;; - scheme, markup, markup
66 ;;; - scheme, scheme, scheme
67 ;;; This combinations are hard-coded in the lexer and in the parser
68 ;;; (lily/lexer.ll and lily/parser.yy)
71 ;;; the arguments signature, i.e. a list of type predicates which
72 ;;; are used to type check the arguments, and also to define the general
73 ;;; argument types (markup, markup-list, scheme) that the command is
75 ;;; For instance, if a command expects a number, then a markup, the
76 ;;; signature would be: (number? markup?)
79 ;;; for documentation purpose, builtin markup commands are grouped by
80 ;;; category. This can be any symbol. When documentation is generated,
81 ;;; the symbol is converted to a capitalized string, where hyphens are
82 ;;; replaced by spaces.
85 ;;; this is used both for documentation generation, and to ease
86 ;;; programming the command itself. It is list of
87 ;;; (property-name default-value)
88 ;;; or (property-name)
89 ;;; elements. Each property is looked-up in the `props' argument, and
90 ;;; the symbol naming the property is bound to its value.
91 ;;; When the property is not found in `props', then the symbol is bound
92 ;;; to the given default value. When no default value is given, #f is
94 ;;; Thus, using the following property bindings:
97 ;;; is equivalent to writing:
98 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
99 ;;; (font-size (chain-assoc-get 'font-size props 0)))
101 ;;; When a command `B' internally calls an other command `A', it may
102 ;;; desirable to see in `B' documentation all the properties and
103 ;;; default values used by `A'. In that case, add `A-markup' to the
104 ;;; property-bindings of B. (This is used when generating
105 ;;; documentation, but won't create bindings.)
107 ;;; documentation-string
108 ;;; the command documentation string (used to generate manuals)
111 ;;; the command body. The function is supposed to return a stencil.
113 ;;; Each markup command definition shall have a documentation string
114 ;;; with description, syntax and example.
116 (use-modules (ice-9 regex))
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
123 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 (define-builtin-markup-command (draw-line layout props dest)
134 @cindex drawing lines within text
137 @lilypond[verbatim,quote]
139 \\draw-line #'(4 . 4)
140 \\override #'(thickness . 5)
141 \\draw-line #'(-3 . 0)
144 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
148 (make-line-stencil th 0 0 x y)))
150 (define-builtin-markup-command (draw-circle layout props radius thickness filled)
151 (number? number? boolean?)
155 @cindex drawing circles within text
157 A circle of radius @var{radius} and thickness @var{thickness},
160 @lilypond[verbatim,quote]
162 \\draw-circle #2 #0.5 ##f
164 \\draw-circle #2 #0 ##t
167 (make-circle-stencil radius thickness filled))
169 (define-builtin-markup-command (triangle layout props filled)
176 @cindex drawing triangles within text
178 A triangle, either filled or empty.
180 @lilypond[verbatim,quote]
187 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
196 (cons 0 (* .86 ex)))))
198 (define-builtin-markup-command (circle layout props arg)
203 (circle-padding 0.2))
205 @cindex circling text
207 Draw a circle around @var{arg}. Use @code{thickness},
208 @code{circle-padding} and @code{font-size} properties to determine line
209 thickness and padding around the markup.
211 @lilypond[verbatim,quote]
218 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
220 (pad (* (magstep font-size) circle-padding))
221 (m (interpret-markup layout props arg)))
222 (circle-stencil m th pad)))
224 (define-builtin-markup-command (with-url layout props url arg)
229 @cindex inserting URL links into text
231 Add a link to URL @var{url} around @var{arg}. This only works in
234 @lilypond[verbatim,quote]
236 \\with-url #\"http://lilypond.org/web/\" {
237 LilyPond ... \\italic {
238 music notation for everyone
243 (let* ((stil (interpret-markup layout props arg))
244 (xextent (ly:stencil-extent stil X))
245 (yextent (ly:stencil-extent stil Y))
246 (old-expr (ly:stencil-expr stil))
247 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
249 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
251 (define-builtin-markup-command (beam layout props width slope thickness)
252 (number? number? number?)
256 @cindex drawing beams within text
258 Create a beam with the specified parameters.
259 @lilypond[verbatim,quote]
264 (let* ((y (* slope width))
265 (yext (cons (min 0 y) (max 0 y)))
266 (half (/ thickness 2)))
271 width (+ (* width slope) (/ thickness -2))
272 width (+ (* width slope) (/ thickness 2))
274 ,(ly:output-def-lookup layout 'blot-diameter)
277 (cons (+ (- half) (car yext))
278 (+ half (cdr yext))))))
280 (define-builtin-markup-command (underline layout props arg)
285 @cindex underlining text
287 Underline @var{arg}. Looks at @code{thickness} to determine line
288 thickness and y-offset.
290 @lilypond[verbatim,quote]
294 \\override #'(thickness . 2)
300 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
302 (markup (interpret-markup layout props arg))
303 (x1 (car (ly:stencil-extent markup X)))
304 (x2 (cdr (ly:stencil-extent markup X)))
306 (line (make-line-stencil thick x1 y x2 y)))
307 (ly:stencil-add markup line)))
309 (define-builtin-markup-command (box layout props arg)
316 @cindex enclosing text within a box
318 Draw a box round @var{arg}. Looks at @code{thickness},
319 @code{box-padding} and @code{font-size} properties to determine line
320 thickness and padding around the markup.
322 @lilypond[verbatim,quote]
324 \\override #'(box-padding . 0.5)
329 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
331 (pad (* (magstep font-size) box-padding))
332 (m (interpret-markup layout props arg)))
333 (box-stencil m th pad)))
335 (define-builtin-markup-command (filled-box layout props xext yext blot)
336 (number-pair? number-pair? number?)
340 @cindex drawing solid boxes within text
341 @cindex drawing boxes with rounded corners
343 Draw a box with rounded corners of dimensions @var{xext} and
344 @var{yext}. For example,
346 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
348 creates a box extending horizontally from -0.3 to 1.8 and
349 vertically from -0.3 up to 1.8, with corners formed from a
350 circle of diameter@tie{}0 (i.e., sharp corners).
352 @lilypond[verbatim,quote]
354 \\filled-box #'(0 . 4) #'(0 . 4) #0
355 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
356 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
358 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
364 (define-builtin-markup-command (rounded-box layout props arg)
371 "@cindex enclosing text in a box with rounded corners
372 @cindex drawing boxes with rounded corners around text
373 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
374 @code{box-padding} and @code{font-size} properties to determine line
375 thickness and padding around the markup; the @code{corner-radius} property
376 makes it possible to define another shape for the corners (default is 1).
378 @lilypond[quote,verbatim,relative=2]
386 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
388 (pad (* (magstep font-size) box-padding))
389 (m (interpret-markup layout props arg)))
390 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
393 (define-builtin-markup-command (rotate layout props ang arg)
398 @cindex rotating text
400 Rotate object with @var{ang} degrees around its center.
402 @lilypond[verbatim,quote]
412 (let* ((stil (interpret-markup layout props arg)))
413 (ly:stencil-rotate stil ang 0 0)))
415 (define-builtin-markup-command (whiteout layout props arg)
420 @cindex adding a white background to text
422 Provide a white background for @var{arg}.
424 @lilypond[verbatim,quote]
427 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
431 (stencil-whiteout (interpret-markup layout props arg)))
433 (define-builtin-markup-command (pad-markup layout props amount arg)
439 @cindex putting space around text
441 Add space around a markup object.
443 @lilypond[verbatim,quote]
457 ((stil (interpret-markup layout props arg))
458 (xext (ly:stencil-extent stil X))
459 (yext (ly:stencil-extent stil Y)))
462 (ly:stencil-expr stil)
463 (interval-widen xext amount)
464 (interval-widen yext amount))))
466 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
470 (define-builtin-markup-command (strut layout props)
475 @cindex creating vertical spaces in text
477 Create a box of the same height as the space in the current font."
478 (let ((m (ly:text-interface::interpret-markup layout props " ")))
479 (ly:make-stencil (ly:stencil-expr m)
481 (ly:stencil-extent m X)
484 ;; todo: fix negative space
485 (define-builtin-markup-command (hspace layout props amount)
490 @cindex creating horizontal spaces in text
492 Create an invisible object taking up horizontal space @var{amount}.
494 @lilypond[verbatim,quote]
504 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
505 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
507 ;; todo: fix negative space
508 (define-builtin-markup-command (vspace layout props amount)
513 @cindex creating vertical spaces in text
515 Create an invisible object taking up vertical space
516 of @var{amount} multiplied by 3.
518 @lilypond[verbatim,quote]
529 (let ((amount (* amount 3.0)))
531 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
532 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 ;; importing graphics.
537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
539 (define-builtin-markup-command (stencil layout props stil)
544 @cindex importing stencils into text
546 Use a stencil as markup.
548 @lilypond[verbatim,quote]
550 \\stencil #(make-circle-stencil 2 0 #t)
556 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
558 (define (get-postscript-bbox string)
559 "Extract the bbox from STRING, or return #f if not present."
561 ((match (regexp-exec bbox-regexp string)))
565 (string->number (match:substring match x)))
570 (define-builtin-markup-command (epsfile layout props axis size file-name)
571 (number? number? string?)
575 @cindex inlining an Encapsulated PostScript image
577 Inline an EPS image. The image is scaled along @var{axis} to
580 @lilypond[verbatim,quote]
582 \\general-align #Y #DOWN {
583 \\epsfile #X #20 #\"context-example.eps\"
584 \\epsfile #Y #20 #\"context-example.eps\"
588 (if (ly:get-option 'safe)
589 (interpret-markup layout props "not allowed in safe")
590 (eps-file->stencil axis size file-name)
593 (define-builtin-markup-command (postscript layout props str)
598 @cindex inserting PostScript directly into text
599 This inserts @var{str} directly into the output as a PostScript
602 @lilypond[verbatim,quote]
606 0.4 0.6 0.5 0 361 arc
608 1.0 0.6 0.5 0 361 arc
613 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
614 \\postscript #ringsps
626 gsave currentpoint translate
634 (define-builtin-markup-command (score layout props score)
639 @cindex inserting music into text
641 Inline an image of music.
643 @lilypond[verbatim,quote]
647 \\new Staff \\relative c' {
650 \\mark \\markup { Allegro }
656 \\new Staff \\relative c {
670 \\override RehearsalMark #'break-align-symbols =
671 #'(time-signature key-signature)
672 \\override RehearsalMark #'self-alignment-X = #LEFT
676 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
682 (let ((output (ly:score-embedded-format score layout)))
684 (if (ly:music-output? output)
685 (stack-stencils Y DOWN baseline-skip
686 (map paper-system-stencil
688 (ly:paper-score-paper-systems output))))
690 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
693 (define-builtin-markup-command (null layout props)
698 @cindex creating empty text objects
700 An empty markup with extents of a single point.
702 @lilypond[verbatim,quote]
709 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
711 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
713 (define-builtin-markup-command (simple layout props str)
718 @cindex simple text strings
720 A simple text string; @code{\\markup @{ foo @}} is equivalent with
721 @code{\\markup @{ \\simple #\"foo\" @}}.
723 Note: for creating standard text markup or defining new markup commands,
724 the use of @code{\\simple} is unnecessary.
726 @lilypond[verbatim,quote]
730 \\simple #\"strings\"
733 (interpret-markup layout props str))
735 (define-builtin-markup-command (tied-lyric layout props str)
740 @cindex simple text strings with tie characters
742 Like simple-markup, but use tie characters for @q{~} tilde symbols.
744 @lilypond[verbatim,quote]
746 \\tied-lyric #\"Lasciate~i monti\"
749 (if (string-contains str "~")
751 ((parts (string-split str #\~))
752 (tie-str (ly:wide-char->utf-8 #x203f))
753 (joined (list-join parts tie-str))
754 (join-stencil (interpret-markup layout props tie-str))
757 (interpret-markup layout
760 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
762 (make-line-markup joined)))
763 ;(map (lambda (s) (interpret-markup layout props s)) parts))
764 (interpret-markup layout props str)))
766 (define-public empty-markup
767 (make-simple-markup ""))
769 ;; helper for justifying lines.
770 (define (get-fill-space word-count line-width text-widths)
771 "Calculate the necessary paddings between each two adjacent texts.
772 The lengths of all texts are stored in @var{text-widths}.
773 The normal formula for the padding between texts a and b is:
774 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
775 The first and last padding have to be calculated specially using the
776 whole length of the first or last text.
777 Return a list of paddings."
779 ((null? text-widths) '())
781 ;; special case first padding
782 ((= (length text-widths) word-count)
784 (- (- (/ line-width (1- word-count)) (car text-widths))
785 (/ (car (cdr text-widths)) 2))
786 (get-fill-space word-count line-width (cdr text-widths))))
787 ;; special case last padding
788 ((= (length text-widths) 2)
789 (list (- (/ line-width (1- word-count))
790 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
793 (- (/ line-width (1- word-count))
794 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
795 (get-fill-space word-count line-width (cdr text-widths))))))
797 (define-builtin-markup-command (fill-line layout props args)
800 ((text-direction RIGHT)
803 "Put @var{markups} in a horizontal line of width @var{line-width}.
804 The markups are spaced or flushed to fill the entire line.
805 If there are no arguments, return an empty stencil.
807 @lilypond[verbatim,quote]
811 Words evenly spaced across the page
815 \\line { Text markups }
817 \\italic { evenly spaced }
819 \\line { across the page }
824 (let* ((orig-stencils (interpret-markup-list layout props args))
827 (if (ly:stencil-empty? stc)
829 stc)) orig-stencils))
832 (if (ly:stencil-empty? stc)
834 (interval-length (ly:stencil-extent stc X))))
836 (text-width (apply + text-widths))
837 (word-count (length stencils))
838 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
843 (/ (- line-width text-width) 2)
844 (/ (- line-width text-width) 2)))
847 (- line-width text-width)))
849 (get-fill-space word-count line-width text-widths))))
857 (line-stencils (if (= word-count 1)
864 (if (= text-direction LEFT)
865 (set! line-stencils (reverse line-stencils)))
867 (if (null? (remove ly:stencil-empty? orig-stencils))
869 (stack-stencils-padding-list X
870 RIGHT fill-space-normal line-stencils))))
872 (define-builtin-markup-command (line layout props args)
876 (text-direction RIGHT))
877 "Put @var{args} in a horizontal line. The property @code{word-space}
878 determines the space between markups in @var{args}.
880 @lilypond[verbatim,quote]
887 (let ((stencils (interpret-markup-list layout props args)))
888 (if (= text-direction LEFT)
889 (set! stencils (reverse stencils)))
892 (remove ly:stencil-empty? stencils))))
894 (define-builtin-markup-command (concat layout props args)
899 @cindex concatenating text
900 @cindex ligatures in text
902 Concatenate @var{args} in a horizontal line, without spaces in between.
903 Strings and simple markups are concatenated on the input level, allowing
904 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
905 equivalent to @code{\"fi\"}.
907 @lilypond[verbatim,quote]
916 (define (concat-string-args arg-list)
917 (fold-right (lambda (arg result-list)
918 (let ((result (if (pair? result-list)
921 (if (and (pair? arg) (eqv? (car arg) simple-markup))
922 (set! arg (cadr arg)))
923 (if (and (string? result) (string? arg))
924 (cons (string-append arg result) (cdr result-list))
925 (cons arg result-list))))
929 (interpret-markup layout
930 (prepend-alist-chain 'word-space 0 props)
931 (make-line-markup (if (markup-command-list? args)
933 (concat-string-args args)))))
935 (define (wordwrap-stencils stencils
936 justify base-space line-width text-dir)
937 "Perform simple wordwrap, return stencil of each line."
938 (define space (if justify
939 ;; justify only stretches lines.
942 (define (take-list width space stencils
943 accumulator accumulated-width)
944 "Return (head-list . tail) pair, with head-list fitting into width"
946 (cons accumulator stencils)
947 (let* ((first (car stencils))
948 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
949 (newwid (+ space first-wid accumulated-width)))
950 (if (or (null? accumulator)
952 (take-list width space
954 (cons first accumulator)
956 (cons accumulator stencils)))))
957 (let loop ((lines '())
959 (let* ((line-break (take-list line-width space todo
961 (line-stencils (car line-break))
962 (space-left (- line-width
963 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
965 (line-word-space (cond ((not justify) space)
966 ;; don't stretch last line of paragraph.
967 ;; hmmm . bug - will overstretch the last line in some case.
968 ((null? (cdr line-break))
970 ((null? line-stencils) 0.0)
971 ((null? (cdr line-stencils)) 0.0)
972 (else (/ space-left (1- (length line-stencils))))))
973 (line (stack-stencil-line line-word-space
974 (if (= text-dir RIGHT)
975 (reverse line-stencils)
977 (if (pair? (cdr line-break))
978 (loop (cons line lines)
981 (if (= text-dir LEFT)
983 (ly:stencil-translate-axis
985 (- line-width (interval-end (ly:stencil-extent line X)))
987 (reverse (cons line lines)))))))
989 (define-builtin-markup-list-command (wordwrap-internal layout props justify args)
990 (boolean? markup-list?)
993 (text-direction RIGHT))
994 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
995 (wordwrap-stencils (remove ly:stencil-empty?
996 (interpret-markup-list layout props args))
1000 (ly:output-def-lookup layout 'line-width))
1003 (define-builtin-markup-command (justify layout props args)
1007 wordwrap-internal-markup-list)
1009 @cindex justifying text
1011 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1012 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1013 @var{X}@tie{}is the number of staff spaces.
1015 @lilypond[verbatim,quote]
1018 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1019 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1020 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1021 laboris nisi ut aliquip ex ea commodo consequat.
1025 (stack-lines DOWN 0.0 baseline-skip
1026 (wordwrap-internal-markup-list layout props #t args)))
1028 (define-builtin-markup-command (wordwrap layout props args)
1032 wordwrap-internal-markup-list)
1033 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1034 the line width, where @var{X} is the number of staff spaces.
1036 @lilypond[verbatim,quote]
1039 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1040 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1041 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1042 laboris nisi ut aliquip ex ea commodo consequat.
1046 (stack-lines DOWN 0.0 baseline-skip
1047 (wordwrap-internal-markup-list layout props #f args)))
1049 (define-builtin-markup-list-command (wordwrap-string-internal layout props justify arg)
1053 (text-direction RIGHT))
1054 "Internal markup list command used to define @code{\\justify-string} and
1055 @code{\\wordwrap-string}."
1056 (let* ((para-strings (regexp-split
1057 (string-regexp-substitute
1059 (string-regexp-substitute "\r\n" "\n" arg))
1060 "\n[ \t\n]*\n[ \t\n]*"))
1061 (list-para-words (map (lambda (str)
1062 (regexp-split str "[ \t\n]+"))
1064 (para-lines (map (lambda (words)
1066 (remove ly:stencil-empty?
1068 (interpret-markup layout props x))
1070 (wordwrap-stencils stencils
1072 line-width text-direction)))
1074 (apply append para-lines)))
1076 (define-builtin-markup-command (wordwrap-string layout props arg)
1080 wordwrap-string-internal-markup-list)
1081 "Wordwrap a string. Paragraphs may be separated with double newlines.
1083 @lilypond[verbatim,quote]
1085 \\override #'(line-width . 40)
1086 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1087 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1088 et dolore magna aliqua.
1091 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1092 laboris nisi ut aliquip ex ea commodo consequat.
1095 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1096 qui officia deserunt mollit anim id est laborum\"
1099 (stack-lines DOWN 0.0 baseline-skip
1100 (wordwrap-string-internal-markup-list layout props #f arg)))
1102 (define-builtin-markup-command (justify-string layout props arg)
1106 wordwrap-string-internal-markup-list)
1107 "Justify a string. Paragraphs may be separated with double newlines
1109 @lilypond[verbatim,quote]
1111 \\override #'(line-width . 40)
1112 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1113 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1114 et dolore magna aliqua.
1117 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1118 laboris nisi ut aliquip ex ea commodo consequat.
1121 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1122 qui officia deserunt mollit anim id est laborum\"
1125 (stack-lines DOWN 0.0 baseline-skip
1126 (wordwrap-string-internal-markup-list layout props #t arg)))
1128 (define-builtin-markup-command (wordwrap-field layout props symbol)
1132 "Wordwrap the data which has been assigned to @var{symbol}.
1134 @lilypond[verbatim,quote]
1136 title = \"My title\"
1137 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1138 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1139 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1140 laboris nisi ut aliquip ex ea commodo consequat.\"
1144 bookTitleMarkup = \\markup {
1146 \\fill-line { \\fromproperty #'header:title }
1148 \\wordwrap-field #'header:myText
1157 (let* ((m (chain-assoc-get symbol props)))
1159 (wordwrap-string-markup layout props m)
1162 (define-builtin-markup-command (justify-field layout props symbol)
1166 "Justify the data which has been assigned to @var{symbol}.
1168 @lilypond[verbatim,quote]
1170 title = \"My title\"
1171 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1172 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1173 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1174 laboris nisi ut aliquip ex ea commodo consequat.\"
1178 bookTitleMarkup = \\markup {
1180 \\fill-line { \\fromproperty #'header:title }
1182 \\justify-field #'header:myText
1191 (let* ((m (chain-assoc-get symbol props)))
1193 (justify-string-markup layout props m)
1196 (define-builtin-markup-command (combine layout props arg1 arg2)
1201 @cindex merging text
1203 Print two markups on top of each other.
1205 Note: @code{\\combine} cannot take a list of markups enclosed in
1206 curly braces as an argument; the follow example will not compile:
1209 \\combine @{ a list @}
1212 @lilypond[verbatim,quote]
1215 \\override #'(thickness . 2)
1217 \\draw-line #'(0 . 4)
1218 \\arrow-head #Y #DOWN ##f
1221 (let* ((s1 (interpret-markup layout props arg1))
1222 (s2 (interpret-markup layout props arg2)))
1223 (ly:stencil-add s1 s2)))
1226 ;; TODO: should extract baseline-skip from each argument somehow..
1228 (define-builtin-markup-command (column layout props args)
1233 @cindex stacking text in a column
1235 Stack the markups in @var{args} vertically. The property
1236 @code{baseline-skip} determines the space between markups
1239 @lilypond[verbatim,quote]
1248 (let ((arg-stencils (interpret-markup-list layout props args)))
1249 (stack-lines -1 0.0 baseline-skip
1250 (remove ly:stencil-empty? arg-stencils))))
1252 (define-builtin-markup-command (dir-column layout props args)
1258 @cindex changing direction of text columns
1260 Make a column of @var{args}, going up or down, depending on the
1261 setting of the @code{direction} layout property.
1263 @lilypond[verbatim,quote]
1265 \\override #`(direction . ,UP) {
1275 \\override #'(direction . 1) {
1282 (stack-lines (if (number? direction) direction -1)
1285 (interpret-markup-list layout props args)))
1287 (define (general-column align-dir baseline mols)
1288 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1290 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1291 (stack-lines -1 0.0 baseline aligned-mols)))
1293 (define-builtin-markup-command (center-column layout props args)
1298 @cindex centering a column of text
1300 Put @code{args} in a centered column.
1302 @lilypond[verbatim,quote]
1311 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1313 (define-builtin-markup-command (left-column layout props args)
1318 @cindex text columns, left-aligned
1320 Put @code{args} in a left-aligned column.
1322 @lilypond[verbatim,quote]
1331 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1333 (define-builtin-markup-command (right-column layout props args)
1338 @cindex text columns, right-aligned
1340 Put @code{args} in a right-aligned column.
1342 @lilypond[verbatim,quote]
1351 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1353 (define-builtin-markup-command (vcenter layout props arg)
1358 @cindex vertically centering text
1360 Align @code{arg} to its Y@tie{}center.
1362 @lilypond[verbatim,quote]
1370 (let* ((mol (interpret-markup layout props arg)))
1371 (ly:stencil-aligned-to mol Y CENTER)))
1373 (define-builtin-markup-command (center-align layout props arg)
1378 @cindex horizontally centering text
1380 Align @code{arg} to its X@tie{}center.
1382 @lilypond[verbatim,quote]
1392 (let* ((mol (interpret-markup layout props arg)))
1393 (ly:stencil-aligned-to mol X CENTER)))
1395 (define-builtin-markup-command (right-align layout props arg)
1400 @cindex right aligning text
1402 Align @var{arg} on its right edge.
1404 @lilypond[verbatim,quote]
1414 (let* ((m (interpret-markup layout props arg)))
1415 (ly:stencil-aligned-to m X RIGHT)))
1417 (define-builtin-markup-command (left-align layout props arg)
1422 @cindex left aligning text
1424 Align @var{arg} on its left edge.
1426 @lilypond[verbatim,quote]
1436 (let* ((m (interpret-markup layout props arg)))
1437 (ly:stencil-aligned-to m X LEFT)))
1439 (define-builtin-markup-command (general-align layout props axis dir arg)
1440 (integer? number? markup?)
1444 @cindex controlling general text alignment
1446 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1448 @lilypond[verbatim,quote]
1452 \\general-align #X #LEFT
1457 \\general-align #X #CENTER
1463 \\general-align #Y #UP
1470 \\general-align #Y #3.2
1477 (let* ((m (interpret-markup layout props arg)))
1478 (ly:stencil-aligned-to m axis dir)))
1480 (define-builtin-markup-command (halign layout props dir arg)
1485 @cindex setting horizontal text alignment
1487 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1488 left-aligned, while @code{+1} is right. Values in between interpolate
1489 alignment accordingly.
1491 @lilypond[verbatim,quote]
1516 (let* ((m (interpret-markup layout props arg)))
1517 (ly:stencil-aligned-to m X dir)))
1519 (define-builtin-markup-command (with-dimensions layout props x y arg)
1520 (number-pair? number-pair? markup?)
1524 @cindex setting extent of text objects
1526 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1527 (let* ((m (interpret-markup layout props arg)))
1528 (ly:make-stencil (ly:stencil-expr m) x y)))
1530 (define-builtin-markup-command (pad-around layout props amount arg)
1534 "Add padding @var{amount} all around @var{arg}.
1536 @lilypond[verbatim,quote]
1549 (let* ((m (interpret-markup layout props arg))
1550 (x (ly:stencil-extent m X))
1551 (y (ly:stencil-extent m Y)))
1552 (ly:make-stencil (ly:stencil-expr m)
1553 (interval-widen x amount)
1554 (interval-widen y amount))))
1556 (define-builtin-markup-command (pad-x layout props amount arg)
1561 @cindex padding text horizontally
1563 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1565 @lilypond[verbatim,quote]
1578 (let* ((m (interpret-markup layout props arg))
1579 (x (ly:stencil-extent m X))
1580 (y (ly:stencil-extent m Y)))
1581 (ly:make-stencil (ly:stencil-expr m)
1582 (interval-widen x amount)
1585 (define-builtin-markup-command (put-adjacent layout props axis dir arg1 arg2)
1586 (integer? ly:dir? markup? markup?)
1589 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1590 (let ((m1 (interpret-markup layout props arg1))
1591 (m2 (interpret-markup layout props arg2)))
1592 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1594 (define-builtin-markup-command (transparent layout props arg)
1598 "Make @var{arg} transparent.
1600 @lilypond[verbatim,quote]
1607 (let* ((m (interpret-markup layout props arg))
1608 (x (ly:stencil-extent m X))
1609 (y (ly:stencil-extent m Y)))
1610 (ly:make-stencil "" x y)))
1612 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
1613 (number-pair? number-pair? markup?)
1616 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1618 @lilypond[verbatim,quote]
1625 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1631 (let* ((m (interpret-markup layout props arg))
1632 (x (ly:stencil-extent m X))
1633 (y (ly:stencil-extent m Y)))
1634 (ly:make-stencil (ly:stencil-expr m)
1635 (interval-union x-ext x)
1636 (interval-union y-ext y))))
1638 (define-builtin-markup-command (hcenter-in layout props length arg)
1642 "Center @var{arg} horizontally within a box of extending
1643 @var{length}/2 to the left and right.
1645 @lilypond[quote,verbatim]
1648 \\set Staff.instrumentName = \\markup {
1655 \\set Staff.instrumentName = \\markup {
1664 (interpret-markup layout props
1665 (make-pad-to-box-markup
1666 (cons (/ length -2) (/ length 2))
1668 (make-center-align-markup arg))))
1670 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1672 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1674 (define-builtin-markup-command (fromproperty layout props symbol)
1678 "Read the @var{symbol} from property settings, and produce a stencil
1679 from the markup contained within. If @var{symbol} is not defined, it
1680 returns an empty markup.
1682 @lilypond[verbatim,quote]
1684 myTitle = \"myTitle\"
1688 \\fromproperty #'header:myTitle
1695 (let ((m (chain-assoc-get symbol props)))
1697 (interpret-markup layout props m)
1700 (define-builtin-markup-command (on-the-fly layout props procedure arg)
1704 "Apply the @var{procedure} markup command to @var{arg}.
1705 @var{procedure} should take a single argument."
1706 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1707 (set-object-property! anonymous-with-signature
1710 (interpret-markup layout props (list anonymous-with-signature arg))))
1712 (define-builtin-markup-command (override layout props new-prop arg)
1717 @cindex overriding properties within text markup
1719 Add the argument @var{new-prop} to the property list. Properties
1720 may be any property supported by @rinternals{font-interface},
1721 @rinternals{text-interface} and
1722 @rinternals{instrument-specific-markup-interface}.
1724 @lilypond[verbatim,quote]
1732 \\override #'(baseline-skip . 4) {
1741 (interpret-markup layout (cons (list new-prop) props) arg))
1743 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1747 (define-builtin-markup-command (verbatim-file layout props name)
1751 "Read the contents of file @var{name}, and include it verbatim.
1753 @lilypond[verbatim,quote]
1755 \\verbatim-file #\"simple.ly\"
1758 (interpret-markup layout props
1759 (if (ly:get-option 'safe)
1760 "verbatim-file disabled in safe mode"
1761 (let* ((str (ly:gulp-file name))
1762 (lines (string-split str #\nl)))
1763 (make-typewriter-markup
1764 (make-column-markup lines))))))
1766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1771 (define-builtin-markup-command (smaller layout props arg)
1775 "Decrease the font size relative to the current setting.
1777 @lilypond[verbatim,quote]
1790 (interpret-markup layout props
1791 `(,fontsize-markup -1 ,arg)))
1793 (define-builtin-markup-command (larger layout props arg)
1797 "Increase the font size relative to the current setting.
1799 @lilypond[verbatim,quote]
1807 (interpret-markup layout props
1808 `(,fontsize-markup 1 ,arg)))
1810 (define-builtin-markup-command (finger layout props arg)
1814 "Set @var{arg} as small numbers.
1816 @lilypond[verbatim,quote]
1823 (interpret-markup layout
1824 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1827 (define-builtin-markup-command (abs-fontsize layout props size arg)
1831 "Use @var{size} as the absolute font size to display @var{arg}.
1832 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1834 @lilypond[verbatim,quote]
1836 default text font size
1838 \\abs-fontsize #16 { text font size 16 }
1840 \\abs-fontsize #12 { text font size 12 }
1843 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1844 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1845 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1846 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1847 (magnification (/ size ref-size)))
1848 (interpret-markup layout
1849 (cons `((baseline-skip . ,(* magnification ref-baseline))
1850 (word-space . ,(* magnification ref-word-space))
1851 (font-size . ,(magnification->font-size magnification)))
1855 (define-builtin-markup-command (fontsize layout props increment arg)
1861 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1864 @lilypond[verbatim,quote]
1872 (let ((entries (list
1873 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1874 (cons 'word-space (* word-space (magstep increment)))
1875 (cons 'font-size (+ font-size increment)))))
1876 (interpret-markup layout (cons entries props) arg)))
1878 (define-builtin-markup-command (magnify layout props sz arg)
1883 @cindex magnifying text
1885 Set the font magnification for its argument. In the following
1886 example, the middle@tie{}A is 10% larger:
1889 A \\magnify #1.1 @{ A @} A
1892 Note: Magnification only works if a font name is explicitly selected.
1893 Use @code{\\fontsize} otherwise.
1895 @lilypond[verbatim,quote]
1906 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1909 (define-builtin-markup-command (bold layout props arg)
1913 "Switch to bold font-series.
1915 @lilypond[verbatim,quote]
1923 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1925 (define-builtin-markup-command (sans layout props arg)
1929 "Switch to the sans serif font family.
1931 @lilypond[verbatim,quote]
1940 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1942 (define-builtin-markup-command (number layout props arg)
1946 "Set font family to @code{number}, which yields the font used for
1947 time signatures and fingerings. This font contains numbers and
1948 some punctuation; it has no letters.
1950 @lilypond[verbatim,quote]
1953 0 1 2 3 4 5 6 7 8 9 . ,
1957 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1959 (define-builtin-markup-command (roman layout props arg)
1963 "Set font family to @code{roman}.
1965 @lilypond[verbatim,quote]
1971 text in roman font family
1978 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1980 (define-builtin-markup-command (huge layout props arg)
1984 "Set font size to +2.
1986 @lilypond[verbatim,quote]
1994 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1996 (define-builtin-markup-command (large layout props arg)
2000 "Set font size to +1.
2002 @lilypond[verbatim,quote]
2010 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2012 (define-builtin-markup-command (normalsize layout props arg)
2016 "Set font size to default.
2018 @lilypond[verbatim,quote]
2031 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2033 (define-builtin-markup-command (small layout props arg)
2037 "Set font size to -1.
2039 @lilypond[verbatim,quote]
2047 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2049 (define-builtin-markup-command (tiny layout props arg)
2053 "Set font size to -2.
2055 @lilypond[verbatim,quote]
2063 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2065 (define-builtin-markup-command (teeny layout props arg)
2069 "Set font size to -3.
2071 @lilypond[verbatim,quote]
2079 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2081 (define-builtin-markup-command (fontCaps layout props arg)
2085 "Set @code{font-shape} to @code{caps}
2087 Note: @code{\\fontCaps} requires the installation and selection of
2088 fonts which support the @code{caps} font shape."
2089 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2092 (define-builtin-markup-command (smallCaps layout props arg)
2096 "Emit @var{arg} as small caps.
2098 Note: @code{\\smallCaps} does not support accented characters.
2100 @lilypond[verbatim,quote]
2109 (define (char-list->markup chars lower)
2110 (let ((final-string (string-upcase (reverse-list->string chars))))
2112 (markup #:fontsize -2 final-string)
2114 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2115 (if (null? rest-chars)
2117 (reverse! (cons (char-list->markup currents current-is-lower)
2119 (let* ((ch (car rest-chars))
2120 (is-lower (char-lower-case? ch)))
2121 (if (or (and current-is-lower is-lower)
2122 (and (not current-is-lower) (not is-lower)))
2123 (make-small-caps (cdr rest-chars)
2127 (make-small-caps (cdr rest-chars)
2130 (if (null? currents)
2132 (cons (char-list->markup
2133 currents current-is-lower)
2135 (interpret-markup layout props
2137 (make-small-caps (string->list arg) (list) #f (list))
2140 (define-builtin-markup-command (caps layout props arg)
2144 "Copy of the @code{\\smallCaps} command.
2146 @lilypond[verbatim,quote]
2155 (interpret-markup layout props (make-smallCaps-markup arg)))
2157 (define-builtin-markup-command (dynamic layout props arg)
2161 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2162 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2163 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2164 done in a different font. The recommended font for this is bold and italic.
2165 @lilypond[verbatim,quote]
2173 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2175 (define-builtin-markup-command (text layout props arg)
2179 "Use a text font instead of music symbol or music alphabet font.
2181 @lilypond[verbatim,quote]
2194 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2197 (define-builtin-markup-command (italic layout props arg)
2201 "Use italic @code{font-shape} for @var{arg}.
2203 @lilypond[verbatim,quote]
2211 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2213 (define-builtin-markup-command (typewriter layout props arg)
2217 "Use @code{font-family} typewriter for @var{arg}.
2219 @lilypond[verbatim,quote]
2228 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2230 (define-builtin-markup-command (upright layout props arg)
2234 "Set @code{font-shape} to @code{upright}. This is the opposite
2237 @lilypond[verbatim,quote]
2251 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2253 (define-builtin-markup-command (medium layout props arg)
2257 "Switch to medium font-series (in contrast to bold).
2259 @lilypond[verbatim,quote]
2272 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2275 (define-builtin-markup-command (normal-text layout props arg)
2279 "Set all font related properties (except the size) to get the default
2280 normal text font, no matter what font was used earlier.
2282 @lilypond[verbatim,quote]
2284 \\huge \\bold \\sans \\caps {
2285 Some text with font overrides
2288 Default text, same font-size
2296 (interpret-markup layout
2297 (cons '((font-family . roman) (font-shape . upright)
2298 (font-series . medium) (font-encoding . latin1))
2302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2306 (define-builtin-markup-command (doublesharp layout props)
2310 "Draw a double sharp symbol.
2312 @lilypond[verbatim,quote]
2317 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2319 (define-builtin-markup-command (sesquisharp layout props)
2323 "Draw a 3/2 sharp symbol.
2325 @lilypond[verbatim,quote]
2330 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2332 (define-builtin-markup-command (sharp layout props)
2336 "Draw a sharp symbol.
2338 @lilypond[verbatim,quote]
2343 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2345 (define-builtin-markup-command (semisharp layout props)
2349 "Draw a semisharp symbol.
2351 @lilypond[verbatim,quote]
2356 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2358 (define-builtin-markup-command (natural layout props)
2362 "Draw a natural symbol.
2364 @lilypond[verbatim,quote]
2369 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2371 (define-builtin-markup-command (semiflat layout props)
2375 "Draw a semiflat symbol.
2377 @lilypond[verbatim,quote]
2382 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2384 (define-builtin-markup-command (flat layout props)
2388 "Draw a flat symbol.
2390 @lilypond[verbatim,quote]
2395 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2397 (define-builtin-markup-command (sesquiflat layout props)
2401 "Draw a 3/2 flat symbol.
2403 @lilypond[verbatim,quote]
2408 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2410 (define-builtin-markup-command (doubleflat layout props)
2414 "Draw a double flat symbol.
2416 @lilypond[verbatim,quote]
2421 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2423 (define-builtin-markup-command (with-color layout props color arg)
2428 @cindex coloring text
2430 Draw @var{arg} in color specified by @var{color}.
2432 @lilypond[verbatim,quote]
2444 (let ((stil (interpret-markup layout props arg)))
2445 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2446 (ly:stencil-extent stil X)
2447 (ly:stencil-extent stil Y))))
2449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2453 (define-builtin-markup-command (arrow-head layout props axis dir filled)
2454 (integer? ly:dir? boolean?)
2457 "Produce an arrow head in specified direction and axis.
2458 Use the filled head if @var{filled} is specified.
2459 @lilypond[verbatim,quote]
2462 \\general-align #Y #DOWN {
2463 \\arrow-head #Y #UP ##t
2464 \\arrow-head #Y #DOWN ##f
2466 \\arrow-head #X #RIGHT ##f
2467 \\arrow-head #X #LEFT ##f
2473 ((name (format "arrowheads.~a.~a~a"
2480 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2484 (define-builtin-markup-command (musicglyph layout props glyph-name)
2488 "@var{glyph-name} is converted to a musical symbol; for example,
2489 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2490 the music font. See @ruser{The Feta font} for a complete listing of
2491 the possible glyphs.
2493 @lilypond[verbatim,quote]
2496 \\musicglyph #\"rests.2\"
2497 \\musicglyph #\"clefs.G_change\"
2500 (let* ((font (ly:paper-get-font layout
2501 (cons '((font-encoding . fetaMusic)
2505 (glyph (ly:font-get-glyph font glyph-name)))
2506 (if (null? (ly:stencil-expr glyph))
2507 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2512 (define-builtin-markup-command (lookup layout props glyph-name)
2516 "Lookup a glyph by name.
2518 @lilypond[verbatim,quote]
2520 \\override #'(font-encoding . fetaBraces) {
2521 \\lookup #\"brace200\"
2524 \\lookup #\"brace180\"
2528 (ly:font-get-glyph (ly:paper-get-font layout props)
2531 (define-builtin-markup-command (char layout props num)
2535 "Produce a single character. Characters encoded in hexadecimal
2536 format require the prefix @code{#x}.
2538 @lilypond[verbatim,quote]
2540 \\char #65 \\char ##x00a9
2543 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2545 (define number->mark-letter-vector (make-vector 25 #\A))
2550 (if (= i (- (char->integer #\I) (char->integer #\A)))
2552 (vector-set! number->mark-letter-vector j
2553 (integer->char (+ i (char->integer #\A)))))
2555 (define number->mark-alphabet-vector (list->vector
2556 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2558 (define (number->markletter-string vec n)
2559 "Double letters for big marks."
2560 (let* ((lst (vector-length vec)))
2563 (string-append (number->markletter-string vec (1- (quotient n lst)))
2564 (number->markletter-string vec (remainder n lst)))
2565 (make-string 1 (vector-ref vec n)))))
2567 (define-builtin-markup-command (markletter layout props num)
2571 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2572 (skipping letter@tie{}I), and continue with double letters.
2574 @lilypond[verbatim,quote]
2581 (ly:text-interface::interpret-markup layout props
2582 (number->markletter-string number->mark-letter-vector num)))
2584 (define-builtin-markup-command (markalphabet layout props num)
2588 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2589 and continue with double letters.
2591 @lilypond[verbatim,quote]
2598 (ly:text-interface::interpret-markup layout props
2599 (number->markletter-string number->mark-alphabet-vector num)))
2601 (define-public (horizontal-slash-interval num forward number-interval mag)
2603 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2604 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2605 (else (interval-widen number-interval (* mag 0.25))))
2606 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2607 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2608 (else (interval-widen number-interval (* mag 0.25))))
2611 (define-public (adjust-slash-stencil num forward stencil mag)
2614 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2616 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2618 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2620 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2623 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2625 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2630 (define (slashed-digit-internal layout props num forward font-size thickness)
2631 (let* ((mag (magstep font-size))
2633 (ly:output-def-lookup layout 'line-thickness)
2635 ; backward slashes might use slope and point in the other direction!
2636 (dy (* mag (if forward 0.4 -0.4)))
2637 (number-stencil (interpret-markup layout
2638 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2639 (number->string num)))
2640 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2641 (center (interval-center (ly:stencil-extent number-stencil Y)))
2642 ; Use the real extents of the slash, not the whole number, because we
2643 ; might translate the slash later on!
2644 (num-y (interval-widen (cons center center) (abs dy)))
2645 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2646 (slash-stencil (if is-sane
2647 (make-line-stencil thickness
2648 (car num-x) (- (interval-center num-y) dy)
2649 (cdr num-x) (+ (interval-center num-y) dy))
2651 (if (ly:stencil? slash-stencil)
2653 ; for some numbers we need to shift the slash/backslash up or down to make
2654 ; the slashed digit look better
2655 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2656 (set! number-stencil
2657 (ly:stencil-add number-stencil slash-stencil)))
2658 (ly:warning "Unable to create slashed digit ~a" num))
2662 (define-builtin-markup-command (slashed-digit layout props num)
2668 @cindex slashed digits
2670 A feta number, with slash. This is for use in the context of
2671 figured bass notation.
2672 @lilypond[verbatim,quote]
2676 \\override #'(thickness . 3)
2680 (slashed-digit-internal layout props num #t font-size thickness))
2682 (define-builtin-markup-command (backslashed-digit layout props num)
2688 @cindex backslashed digits
2690 A feta number, with backslash. This is for use in the context of
2691 figured bass notation.
2692 @lilypond[verbatim,quote]
2694 \\backslashed-digit #5
2696 \\override #'(thickness . 3)
2697 \\backslashed-digit #7
2700 (slashed-digit-internal layout props num #f font-size thickness))
2703 (define eyeglassesps
2708 0.7 0.7 0.5 0 361 arc
2710 2.20 0.70 0.50 0 361 arc
2712 1.45 0.85 0.30 0 180 arc
2716 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2720 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2723 (define-builtin-markup-command (eyeglasses layout props) () other ()
2724 "Prints out eyeglasses, indicating strongly to look at the conductor.
2725 @lilypond[verbatim,quote]
2726 \\markup { \\eyeglasses }
2728 (interpret-markup layout props
2729 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2730 (make-postscript-markup eyeglassesps))))
2732 (define-builtin-markup-command (left-brace layout props size)
2737 A feta brace in point size @var{size}.
2739 @lilypond[verbatim,quote]
2746 (let* ((font (ly:paper-get-font layout
2747 (cons '((font-encoding . fetaBraces)
2750 (glyph-count (1- (ly:otf-glyph-count font)))
2751 (scale (ly:output-def-lookup layout 'output-scale))
2752 (scaled-size (/ (ly:pt size) scale))
2754 (ly:font-get-glyph font (string-append "brace"
2755 (number->string n)))))
2756 (get-y-from-brace (lambda (brace)
2758 (ly:stencil-extent (glyph brace) Y))))
2759 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2760 (glyph-found (glyph find-brace)))
2762 (if (or (null? (ly:stencil-expr glyph-found))
2763 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2764 (> scaled-size (interval-length
2765 (ly:stencil-extent (glyph glyph-count) Y))))
2767 (ly:warning (_ "no brace found for point size ~S ") size)
2768 (ly:warning (_ "defaulting to ~S pt")
2769 (/ (* scale (interval-length
2770 (ly:stencil-extent glyph-found Y)))
2774 (define-builtin-markup-command (right-brace layout props size)
2779 A feta brace in point size @var{size}, rotated 180 degrees.
2781 @lilypond[verbatim,quote]
2788 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2791 ;; the note command.
2792 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2794 ;; TODO: better syntax.
2796 (define-builtin-markup-command (note-by-number layout props log dot-count dir)
2797 (number? number? number?)
2802 @cindex notes within text by log and dot-count
2804 Construct a note symbol, with stem. By using fractional values for
2805 @var{dir}, longer or shorter stems can be obtained.
2807 @lilypond[verbatim,quote]
2809 \\note-by-number #3 #0 #DOWN
2811 \\note-by-number #1 #2 #0.8
2814 (define (get-glyph-name-candidates dir log style)
2815 (map (lambda (dir-name)
2816 (format "noteheads.~a~a" dir-name
2817 (if (and (symbol? style)
2818 (not (equal? 'default style)))
2819 (select-head-glyph style (min log 2))
2821 (list (if (= dir UP) "u" "d")
2824 (define (get-glyph-name font cands)
2827 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2828 (get-glyph-name font (cdr cands))
2831 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2833 (size-factor (magstep font-size))
2834 (stem-length (* size-factor (max 3 (- log 1))))
2836 (let ((result (get-glyph-name font (get-glyph-name-candidates
2837 (sign dir) log style))))
2838 (if (string-null? result)
2839 ;; If no glyph name can be found, select default heads. Though
2840 ;; this usually means an unsupported style has been chosen, it
2841 ;; also prevents unrelated 'style settings from other grobs
2842 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2843 (get-glyph-name font (get-glyph-name-candidates
2844 (sign dir) log 'default))
2846 (head-glyph (ly:font-get-glyph font head-glyph-name))
2847 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2848 (stem-thickness (* size-factor 0.13))
2849 (stemy (* dir stem-length))
2850 (attach-off (cons (interval-index
2851 (ly:stencil-extent head-glyph X)
2852 (* (sign dir) (car attach-indices)))
2853 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2855 (ly:stencil-extent head-glyph Y)
2856 (cdr attach-indices)))))
2857 (stem-glyph (and (> log 0)
2858 (ly:round-filled-box
2859 (ordered-cons (car attach-off)
2861 (* (- (sign dir)) stem-thickness)))
2862 (cons (min stemy (cdr attach-off))
2863 (max stemy (cdr attach-off)))
2864 (/ stem-thickness 3))))
2866 (dot (ly:font-get-glyph font "dots.dot"))
2867 (dotwid (interval-length (ly:stencil-extent dot X)))
2868 (dots (and (> dot-count 0)
2869 (apply ly:stencil-add
2871 (ly:stencil-translate-axis
2872 dot (* 2 x dotwid) X))
2873 (iota dot-count)))))
2874 (flaggl (and (> log 2)
2875 (ly:stencil-translate
2876 (ly:font-get-glyph font
2877 (string-append "flags."
2878 (if (> dir 0) "u" "d")
2879 (number->string log)))
2880 (cons (+ (car attach-off) (if (< dir 0)
2884 ;; If there is a flag on an upstem and the stem is short, move the dots
2885 ;; to avoid the flag. 16th notes get a special case because their flags
2886 ;; hang lower than any other flags.
2887 (if (and dots (> dir 0) (> log 2)
2888 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2889 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2891 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2892 (if (ly:stencil? stem-glyph)
2893 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2894 (set! stem-glyph head-glyph))
2895 (if (ly:stencil? dots)
2898 (ly:stencil-translate-axis
2900 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2906 (let ((divisor (log 2)))
2907 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2909 (define (parse-simple-duration duration-string)
2910 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2911 and return a (log dots) list."
2912 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2914 (if (and match (string=? duration-string (match:substring match 0)))
2915 (let ((len (match:substring match 1))
2916 (dots (match:substring match 2)))
2917 (list (cond ((string=? len "breve") -1)
2918 ((string=? len "longa") -2)
2919 ((string=? len "maxima") -3)
2920 (else (log2 (string->number len))))
2921 (if dots (string-length dots) 0)))
2922 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2924 (define-builtin-markup-command (note layout props duration dir)
2927 (note-by-number-markup)
2929 @cindex notes within text by string
2931 This produces a note with a stem pointing in @var{dir} direction, with
2932 the @var{duration} for the note head type and augmentation dots. For
2933 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2934 a shortened down stem.
2936 @lilypond[verbatim,quote]
2938 \\override #'(style . cross) {
2942 \\note #\"breve\" #0
2945 (let ((parsed (parse-simple-duration duration)))
2946 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2948 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2950 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2952 (define-builtin-markup-command (lower layout props amount arg)
2957 @cindex lowering text
2959 Lower @var{arg} by the distance @var{amount}.
2960 A negative @var{amount} indicates raising; see also @code{\\raise}.
2962 @lilypond[verbatim,quote]
2970 (ly:stencil-translate-axis (interpret-markup layout props arg)
2973 (define-builtin-markup-command (translate-scaled layout props offset arg)
2974 (number-pair? markup?)
2978 @cindex translating text
2979 @cindex scaling text
2981 Translate @var{arg} by @var{offset}, scaling the offset by the
2984 @lilypond[verbatim,quote]
2987 * \\translate #'(2 . 3) translate
2989 * \\translate-scaled #'(2 . 3) translate-scaled
2993 (let* ((factor (magstep font-size))
2994 (scaled (cons (* factor (car offset))
2995 (* factor (cdr offset)))))
2996 (ly:stencil-translate (interpret-markup layout props arg)
2999 (define-builtin-markup-command (raise layout props amount arg)
3004 @cindex raising text
3006 Raise @var{arg} by the distance @var{amount}.
3007 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3009 The argument to @code{\\raise} is the vertical displacement amount,
3010 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3011 raise objects in relation to their surrounding markups.
3013 If the text object itself is positioned above or below the staff, then
3014 @code{\\raise} cannot be used to move it, since the mechanism that
3015 positions it next to the staff cancels any shift made with
3016 @code{\\raise}. For vertical positioning, use the @code{padding}
3017 and/or @code{extra-offset} properties.
3019 @lilypond[verbatim,quote]
3028 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3030 (define-builtin-markup-command (fraction layout props arg1 arg2)
3035 @cindex creating text fractions
3037 Make a fraction of two markups.
3038 @lilypond[verbatim,quote]
3044 (let* ((m1 (interpret-markup layout props arg1))
3045 (m2 (interpret-markup layout props arg2))
3046 (factor (magstep font-size))
3047 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3048 (padding (* factor 0.2))
3049 (baseline (* factor 0.6))
3050 (offset (* factor 0.75)))
3051 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3052 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3053 (let* ((x1 (ly:stencil-extent m1 X))
3054 (x2 (ly:stencil-extent m2 X))
3055 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3056 ;; should stack mols separately, to maintain LINE on baseline
3057 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3059 (ly:stencil-aligned-to stack Y CENTER))
3061 (ly:stencil-aligned-to stack X LEFT))
3062 ;; should have EX dimension
3064 (ly:stencil-translate-axis stack offset Y))))
3066 (define-builtin-markup-command (normal-size-super layout props arg)
3071 @cindex setting superscript in standard font size
3073 Set @var{arg} in superscript with a normal font size.
3075 @lilypond[verbatim,quote]
3078 \\normal-size-super {
3079 superscript in standard size
3083 (ly:stencil-translate-axis
3084 (interpret-markup layout props arg)
3085 (* 0.5 baseline-skip) Y))
3087 (define-builtin-markup-command (super layout props arg)
3093 @cindex superscript text
3095 Set @var{arg} in superscript.
3097 @lilypond[verbatim,quote]
3107 (ly:stencil-translate-axis
3110 (cons `((font-size . ,(- font-size 3))) props)
3112 (* 0.5 baseline-skip)
3115 (define-builtin-markup-command (translate layout props offset arg)
3116 (number-pair? markup?)
3120 @cindex translating text
3122 Translate @var{arg} relative to its surroundings. @var{offset}
3123 is a pair of numbers representing the displacement in the X and Y axis.
3125 @lilypond[verbatim,quote]
3128 \\translate #'(2 . 3)
3129 \\line { translated two spaces right, three up }
3132 (ly:stencil-translate (interpret-markup layout props arg)
3135 (define-builtin-markup-command (sub layout props arg)
3141 @cindex subscript text
3143 Set @var{arg} in subscript.
3145 @lilypond[verbatim,quote]
3156 (ly:stencil-translate-axis
3159 (cons `((font-size . ,(- font-size 3))) props)
3161 (* -0.5 baseline-skip)
3164 (define-builtin-markup-command (normal-size-sub layout props arg)
3169 @cindex setting subscript in standard font size
3171 Set @var{arg} in subscript with a normal font size.
3173 @lilypond[verbatim,quote]
3177 subscript in standard size
3181 (ly:stencil-translate-axis
3182 (interpret-markup layout props arg)
3183 (* -0.5 baseline-skip)
3186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3190 (define-builtin-markup-command (hbracket layout props arg)
3195 @cindex placing horizontal brackets around text
3197 Draw horizontal brackets around @var{arg}.
3199 @lilypond[verbatim,quote]
3208 (let ((th 0.1) ;; todo: take from GROB.
3209 (m (interpret-markup layout props arg)))
3210 (bracketify-stencil m X th (* 2.5 th) th)))
3212 (define-builtin-markup-command (bracket layout props arg)
3217 @cindex placing vertical brackets around text
3219 Draw vertical brackets around @var{arg}.
3221 @lilypond[verbatim,quote]
3228 (let ((th 0.1) ;; todo: take from GROB.
3229 (m (interpret-markup layout props arg)))
3230 (bracketify-stencil m Y th (* 2.5 th) th)))
3232 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3233 ;; Delayed markup evaluation
3234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3236 (define-builtin-markup-command (page-ref layout props label gauge default)
3237 (symbol? markup? markup?)
3241 @cindex referencing page numbers in text
3243 Reference to a page number. @var{label} is the label set on the referenced
3244 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3245 the maximum width of the page number, and @var{default} the value to display
3246 when @var{label} is not found."
3247 (let* ((gauge-stencil (interpret-markup layout props gauge))
3248 (x-ext (ly:stencil-extent gauge-stencil X))
3249 (y-ext (ly:stencil-extent gauge-stencil Y)))
3251 `(delay-stencil-evaluation
3252 ,(delay (ly:stencil-expr
3253 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3254 (page-number (if (list? table)
3255 (assoc-get label table)
3257 (page-markup (if page-number (format "~a" page-number) default))
3258 (page-stencil (interpret-markup layout props page-markup))
3259 (gap (- (interval-length x-ext)
3260 (interval-length (ly:stencil-extent page-stencil X)))))
3261 (interpret-markup layout props
3262 (markup #:concat (#:hspace gap page-markup)))))))
3266 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3267 ;; Markup list commands
3268 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3270 (define-public (space-lines baseline stils)
3271 (let space-stil ((stils stils)
3275 (let* ((stil (car stils))
3276 (dy-top (max (- (/ baseline 1.5)
3277 (interval-bound (ly:stencil-extent stil Y) UP))
3279 (dy-bottom (max (+ (/ baseline 3.0)
3280 (interval-bound (ly:stencil-extent stil Y) DOWN))
3282 (new-stil (ly:make-stencil
3283 (ly:stencil-expr stil)
3284 (ly:stencil-extent stil X)
3285 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3287 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3289 (space-stil (cdr stils) (cons new-stil result))))))
3291 (define-builtin-markup-list-command (justified-lines layout props args)
3294 wordwrap-internal-markup-list)
3296 @cindex justifying lines of text
3298 Like @code{\\justify}, but return a list of lines instead of a single markup.
3299 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3300 @var{X}@tie{}is the number of staff spaces."
3301 (space-lines baseline-skip
3302 (interpret-markup-list layout props
3303 (make-wordwrap-internal-markup-list #t args))))
3305 (define-builtin-markup-list-command (wordwrap-lines layout props args)
3308 wordwrap-internal-markup-list)
3309 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3310 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3311 where @var{X} is the number of staff spaces."
3312 (space-lines baseline-skip
3313 (interpret-markup-list layout props
3314 (make-wordwrap-internal-markup-list #f args))))
3316 (define-builtin-markup-list-command (column-lines layout props args)
3319 "Like @code{\\column}, but return a list of lines instead of a single markup.
3320 @code{baseline-skip} determines the space between each markup in @var{args}."
3321 (space-lines baseline-skip
3322 (interpret-markup-list layout props args)))
3324 (define-builtin-markup-list-command (override-lines layout props new-prop args)
3325 (pair? markup-list?)
3327 "Like @code{\\override}, for markup lists."
3328 (interpret-markup-list layout (cons (list new-prop) props) args))