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-markup-command' macro.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
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 distinguished 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-markup-command (draw-line layout props dest)
132 #:properties ((thickness 1))
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-markup-command (draw-circle layout props radius thickness filled)
151 (number? number? boolean?)
154 @cindex drawing circles within text
156 A circle of radius @var{radius} and thickness @var{thickness},
159 @lilypond[verbatim,quote]
161 \\draw-circle #2 #0.5 ##f
163 \\draw-circle #2 #0 ##t
166 (make-circle-stencil radius thickness filled))
168 (define-markup-command (triangle layout props filled)
171 #:properties ((thickness 0.1)
175 @cindex drawing triangles within text
177 A triangle, either filled or empty.
179 @lilypond[verbatim,quote]
186 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
195 (cons 0 (* .86 ex)))))
197 (define-markup-command (circle layout props arg)
200 #:properties ((thickness 1)
202 (circle-padding 0.2))
204 @cindex circling text
206 Draw a circle around @var{arg}. Use @code{thickness},
207 @code{circle-padding} and @code{font-size} properties to determine line
208 thickness and padding around the markup.
210 @lilypond[verbatim,quote]
217 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
219 (pad (* (magstep font-size) circle-padding))
220 (m (interpret-markup layout props arg)))
221 (circle-stencil m th pad)))
223 (define-markup-command (with-url layout props url arg)
227 @cindex inserting URL links into text
229 Add a link to URL @var{url} around @var{arg}. This only works in
232 @lilypond[verbatim,quote]
234 \\with-url #\"http://lilypond.org/web/\" {
235 LilyPond ... \\italic {
236 music notation for everyone
241 (let* ((stil (interpret-markup layout props arg))
242 (xextent (ly:stencil-extent stil X))
243 (yextent (ly:stencil-extent stil Y))
244 (old-expr (ly:stencil-expr stil))
245 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
247 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
249 (define-markup-command (beam layout props width slope thickness)
250 (number? number? number?)
253 @cindex drawing beams within text
255 Create a beam with the specified parameters.
256 @lilypond[verbatim,quote]
261 (let* ((y (* slope width))
262 (yext (cons (min 0 y) (max 0 y)))
263 (half (/ thickness 2)))
268 width (+ (* width slope) (/ thickness -2))
269 width (+ (* width slope) (/ thickness 2))
271 ,(ly:output-def-lookup layout 'blot-diameter)
274 (cons (+ (- half) (car yext))
275 (+ half (cdr yext))))))
277 (define-markup-command (underline layout props arg)
280 #:properties ((thickness 1))
282 @cindex underlining text
284 Underline @var{arg}. Looks at @code{thickness} to determine line
285 thickness and y-offset.
287 @lilypond[verbatim,quote]
291 \\override #'(thickness . 2)
297 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
299 (markup (interpret-markup layout props arg))
300 (x1 (car (ly:stencil-extent markup X)))
301 (x2 (cdr (ly:stencil-extent markup X)))
303 (line (make-line-stencil thick x1 y x2 y)))
304 (ly:stencil-add markup line)))
306 (define-markup-command (box layout props arg)
309 #:properties ((thickness 1)
313 @cindex enclosing text within a box
315 Draw a box round @var{arg}. Looks at @code{thickness},
316 @code{box-padding} and @code{font-size} properties to determine line
317 thickness and padding around the markup.
319 @lilypond[verbatim,quote]
321 \\override #'(box-padding . 0.5)
326 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
328 (pad (* (magstep font-size) box-padding))
329 (m (interpret-markup layout props arg)))
330 (box-stencil m th pad)))
332 (define-markup-command (filled-box layout props xext yext blot)
333 (number-pair? number-pair? number?)
336 @cindex drawing solid boxes within text
337 @cindex drawing boxes with rounded corners
339 Draw a box with rounded corners of dimensions @var{xext} and
340 @var{yext}. For example,
342 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
344 creates a box extending horizontally from -0.3 to 1.8 and
345 vertically from -0.3 up to 1.8, with corners formed from a
346 circle of diameter@tie{}0 (i.e., sharp corners).
348 @lilypond[verbatim,quote]
350 \\filled-box #'(0 . 4) #'(0 . 4) #0
351 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
352 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
354 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
360 (define-markup-command (rounded-box layout props arg)
363 #:properties ((thickness 1)
367 "@cindex enclosing text in a box with rounded corners
368 @cindex drawing boxes with rounded corners around text
369 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
370 @code{box-padding} and @code{font-size} properties to determine line
371 thickness and padding around the markup; the @code{corner-radius} property
372 makes it possible to define another shape for the corners (default is 1).
374 @lilypond[quote,verbatim,relative=2]
382 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
384 (pad (* (magstep font-size) box-padding))
385 (m (interpret-markup layout props arg)))
386 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
389 (define-markup-command (rotate layout props ang arg)
393 @cindex rotating text
395 Rotate object with @var{ang} degrees around its center.
397 @lilypond[verbatim,quote]
407 (let* ((stil (interpret-markup layout props arg)))
408 (ly:stencil-rotate stil ang 0 0)))
410 (define-markup-command (whiteout layout props arg)
414 @cindex adding a white background to text
416 Provide a white background for @var{arg}.
418 @lilypond[verbatim,quote]
421 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
425 (stencil-whiteout (interpret-markup layout props arg)))
427 (define-markup-command (pad-markup layout props amount arg)
432 @cindex putting space around text
434 Add space around a markup object.
436 @lilypond[verbatim,quote]
450 ((stil (interpret-markup layout props arg))
451 (xext (ly:stencil-extent stil X))
452 (yext (ly:stencil-extent stil Y)))
455 (ly:stencil-expr stil)
456 (interval-widen xext amount)
457 (interval-widen yext amount))))
459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
463 (define-markup-command (strut layout props)
467 @cindex creating vertical spaces in text
469 Create a box of the same height as the space in the current font."
470 (let ((m (ly:text-interface::interpret-markup layout props " ")))
471 (ly:make-stencil (ly:stencil-expr m)
473 (ly:stencil-extent m X)
476 ;; todo: fix negative space
477 (define-markup-command (hspace layout props amount)
481 @cindex creating horizontal spaces in text
483 Create an invisible object taking up horizontal space @var{amount}.
485 @lilypond[verbatim,quote]
495 (ly:make-stencil "" (cons 0 amount) '(0 . 0))
496 (ly:make-stencil "" (cons amount amount) '(0 . 0))))
498 ;; todo: fix negative space
499 (define-markup-command (vspace layout props amount)
503 @cindex creating vertical spaces in text
505 Create an invisible object taking up vertical space
506 of @var{amount} multiplied by 3.
508 @lilypond[verbatim,quote]
519 (let ((amount (* amount 3.0)))
521 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
522 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
525 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
526 ;; importing graphics.
527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
529 (define-markup-command (stencil layout props stil)
533 @cindex importing stencils into text
535 Use a stencil as markup.
537 @lilypond[verbatim,quote]
539 \\stencil #(make-circle-stencil 2 0 #t)
545 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
547 (define (get-postscript-bbox string)
548 "Extract the bbox from STRING, or return #f if not present."
550 ((match (regexp-exec bbox-regexp string)))
554 (string->number (match:substring match x)))
559 (define-markup-command (epsfile layout props axis size file-name)
560 (number? number? string?)
563 @cindex inlining an Encapsulated PostScript image
565 Inline an EPS image. The image is scaled along @var{axis} to
568 @lilypond[verbatim,quote]
570 \\general-align #Y #DOWN {
571 \\epsfile #X #20 #\"context-example.eps\"
572 \\epsfile #Y #20 #\"context-example.eps\"
576 (if (ly:get-option 'safe)
577 (interpret-markup layout props "not allowed in safe")
578 (eps-file->stencil axis size file-name)
581 (define-markup-command (postscript layout props str)
585 @cindex inserting PostScript directly into text
586 This inserts @var{str} directly into the output as a PostScript
589 @lilypond[verbatim,quote]
593 0.4 0.6 0.5 0 361 arc
595 1.0 0.6 0.5 0 361 arc
600 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
601 \\postscript #ringsps
613 gsave currentpoint translate
621 (define-markup-command (score layout props score)
624 #:properties ((baseline-skip))
626 @cindex inserting music into text
628 Inline an image of music.
630 @lilypond[verbatim,quote]
634 \\new Staff \\relative c' {
637 \\mark \\markup { Allegro }
643 \\new Staff \\relative c {
657 \\override RehearsalMark #'break-align-symbols =
658 #'(time-signature key-signature)
659 \\override RehearsalMark #'self-alignment-X = #LEFT
663 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
669 (let ((output (ly:score-embedded-format score layout)))
671 (if (ly:music-output? output)
672 (stack-stencils Y DOWN baseline-skip
673 (map paper-system-stencil
675 (ly:paper-score-paper-systems output))))
677 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
680 (define-markup-command (null layout props)
684 @cindex creating empty text objects
686 An empty markup with extents of a single point.
688 @lilypond[verbatim,quote]
695 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 (define-markup-command (simple layout props str)
703 @cindex simple text strings
705 A simple text string; @code{\\markup @{ foo @}} is equivalent with
706 @code{\\markup @{ \\simple #\"foo\" @}}.
708 Note: for creating standard text markup or defining new markup commands,
709 the use of @code{\\simple} is unnecessary.
711 @lilypond[verbatim,quote]
715 \\simple #\"strings\"
718 (interpret-markup layout props str))
720 (define-markup-command (tied-lyric layout props str)
724 @cindex simple text strings with tie characters
726 Like simple-markup, but use tie characters for @q{~} tilde symbols.
728 @lilypond[verbatim,quote]
730 \\tied-lyric #\"Lasciate~i monti\"
733 (if (string-contains str "~")
735 ((parts (string-split str #\~))
736 (tie-str (ly:wide-char->utf-8 #x203f))
737 (joined (list-join parts tie-str))
738 (join-stencil (interpret-markup layout props tie-str))
741 (interpret-markup layout
744 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
746 (make-line-markup joined)))
747 ;(map (lambda (s) (interpret-markup layout props s)) parts))
748 (interpret-markup layout props str)))
750 (define-public empty-markup
751 (make-simple-markup ""))
753 ;; helper for justifying lines.
754 (define (get-fill-space word-count line-width text-widths)
755 "Calculate the necessary paddings between each two adjacent texts.
756 The lengths of all texts are stored in @var{text-widths}.
757 The normal formula for the padding between texts a and b is:
758 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
759 The first and last padding have to be calculated specially using the
760 whole length of the first or last text.
761 Return a list of paddings."
763 ((null? text-widths) '())
765 ;; special case first padding
766 ((= (length text-widths) word-count)
768 (- (- (/ line-width (1- word-count)) (car text-widths))
769 (/ (car (cdr text-widths)) 2))
770 (get-fill-space word-count line-width (cdr text-widths))))
771 ;; special case last padding
772 ((= (length text-widths) 2)
773 (list (- (/ line-width (1- word-count))
774 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
777 (- (/ line-width (1- word-count))
778 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
779 (get-fill-space word-count line-width (cdr text-widths))))))
781 (define-markup-command (fill-line layout props args)
784 #:properties ((text-direction RIGHT)
787 "Put @var{markups} in a horizontal line of width @var{line-width}.
788 The markups are spaced or flushed to fill the entire line.
789 If there are no arguments, return an empty stencil.
791 @lilypond[verbatim,quote]
795 Words evenly spaced across the page
799 \\line { Text markups }
801 \\italic { evenly spaced }
803 \\line { across the page }
808 (let* ((orig-stencils (interpret-markup-list layout props args))
811 (if (ly:stencil-empty? stc)
813 stc)) orig-stencils))
816 (if (ly:stencil-empty? stc)
818 (interval-length (ly:stencil-extent stc X))))
820 (text-width (apply + text-widths))
821 (word-count (length stencils))
822 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
827 (/ (- line-width text-width) 2)
828 (/ (- line-width text-width) 2)))
831 (- line-width text-width)))
833 (get-fill-space word-count line-width text-widths))))
841 (line-stencils (if (= word-count 1)
848 (if (= text-direction LEFT)
849 (set! line-stencils (reverse line-stencils)))
851 (if (null? (remove ly:stencil-empty? orig-stencils))
853 (stack-stencils-padding-list X
854 RIGHT fill-space-normal line-stencils))))
856 (define-markup-command (line layout props args)
859 #:properties ((word-space)
860 (text-direction RIGHT))
861 "Put @var{args} in a horizontal line. The property @code{word-space}
862 determines the space between markups in @var{args}.
864 @lilypond[verbatim,quote]
871 (let ((stencils (interpret-markup-list layout props args)))
872 (if (= text-direction LEFT)
873 (set! stencils (reverse stencils)))
876 (remove ly:stencil-empty? stencils))))
878 (define-markup-command (concat layout props args)
882 @cindex concatenating text
883 @cindex ligatures in text
885 Concatenate @var{args} in a horizontal line, without spaces in between.
886 Strings and simple markups are concatenated on the input level, allowing
887 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
888 equivalent to @code{\"fi\"}.
890 @lilypond[verbatim,quote]
899 (define (concat-string-args arg-list)
900 (fold-right (lambda (arg result-list)
901 (let ((result (if (pair? result-list)
904 (if (and (pair? arg) (eqv? (car arg) simple-markup))
905 (set! arg (cadr arg)))
906 (if (and (string? result) (string? arg))
907 (cons (string-append arg result) (cdr result-list))
908 (cons arg result-list))))
912 (interpret-markup layout
913 (prepend-alist-chain 'word-space 0 props)
914 (make-line-markup (if (markup-command-list? args)
916 (concat-string-args args)))))
918 (define (wordwrap-stencils stencils
919 justify base-space line-width text-dir)
920 "Perform simple wordwrap, return stencil of each line."
921 (define space (if justify
922 ;; justify only stretches lines.
925 (define (take-list width space stencils
926 accumulator accumulated-width)
927 "Return (head-list . tail) pair, with head-list fitting into width"
929 (cons accumulator stencils)
930 (let* ((first (car stencils))
931 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
932 (newwid (+ space first-wid accumulated-width)))
933 (if (or (null? accumulator)
935 (take-list width space
937 (cons first accumulator)
939 (cons accumulator stencils)))))
940 (let loop ((lines '())
942 (let* ((line-break (take-list line-width space todo
944 (line-stencils (car line-break))
945 (space-left (- line-width
946 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
948 (line-word-space (cond ((not justify) space)
949 ;; don't stretch last line of paragraph.
950 ;; hmmm . bug - will overstretch the last line in some case.
951 ((null? (cdr line-break))
953 ((null? line-stencils) 0.0)
954 ((null? (cdr line-stencils)) 0.0)
955 (else (/ space-left (1- (length line-stencils))))))
956 (line (stack-stencil-line line-word-space
957 (if (= text-dir RIGHT)
958 (reverse line-stencils)
960 (if (pair? (cdr line-break))
961 (loop (cons line lines)
964 (if (= text-dir LEFT)
966 (ly:stencil-translate-axis
968 (- line-width (interval-end (ly:stencil-extent line X)))
970 (reverse (cons line lines)))))))
972 (define-markup-list-command (wordwrap-internal layout props justify args)
973 (boolean? markup-list?)
974 #:properties ((line-width #f)
976 (text-direction RIGHT))
977 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
978 (wordwrap-stencils (remove ly:stencil-empty?
979 (interpret-markup-list layout props args))
983 (ly:output-def-lookup layout 'line-width))
986 (define-markup-command (justify layout props args)
989 #:properties ((baseline-skip)
990 wordwrap-internal-markup-list)
992 @cindex justifying text
994 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
995 Use @code{\\override #'(line-width . @var{X})} to set the line width;
996 @var{X}@tie{}is the number of staff spaces.
998 @lilypond[verbatim,quote]
1001 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1002 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1003 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1004 laboris nisi ut aliquip ex ea commodo consequat.
1008 (stack-lines DOWN 0.0 baseline-skip
1009 (wordwrap-internal-markup-list layout props #t args)))
1011 (define-markup-command (wordwrap layout props args)
1014 #:properties ((baseline-skip)
1015 wordwrap-internal-markup-list)
1016 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1017 the line width, where @var{X} is the number of staff spaces.
1019 @lilypond[verbatim,quote]
1022 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1023 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1024 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1025 laboris nisi ut aliquip ex ea commodo consequat.
1029 (stack-lines DOWN 0.0 baseline-skip
1030 (wordwrap-internal-markup-list layout props #f args)))
1032 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1034 #:properties ((line-width)
1036 (text-direction RIGHT))
1037 "Internal markup list command used to define @code{\\justify-string} and
1038 @code{\\wordwrap-string}."
1039 (let* ((para-strings (regexp-split
1040 (string-regexp-substitute
1042 (string-regexp-substitute "\r\n" "\n" arg))
1043 "\n[ \t\n]*\n[ \t\n]*"))
1044 (list-para-words (map (lambda (str)
1045 (regexp-split str "[ \t\n]+"))
1047 (para-lines (map (lambda (words)
1049 (remove ly:stencil-empty?
1051 (interpret-markup layout props x))
1053 (wordwrap-stencils stencils
1055 line-width text-direction)))
1057 (apply append para-lines)))
1059 (define-markup-command (wordwrap-string layout props arg)
1062 #:properties ((baseline-skip)
1063 wordwrap-string-internal-markup-list)
1064 "Wordwrap a string. Paragraphs may be separated with double newlines.
1066 @lilypond[verbatim,quote]
1068 \\override #'(line-width . 40)
1069 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1070 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1071 et dolore magna aliqua.
1074 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1075 laboris nisi ut aliquip ex ea commodo consequat.
1078 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1079 qui officia deserunt mollit anim id est laborum\"
1082 (stack-lines DOWN 0.0 baseline-skip
1083 (wordwrap-string-internal-markup-list layout props #f arg)))
1085 (define-markup-command (justify-string layout props arg)
1088 #:properties ((baseline-skip)
1089 wordwrap-string-internal-markup-list)
1090 "Justify a string. Paragraphs may be separated with double newlines
1092 @lilypond[verbatim,quote]
1094 \\override #'(line-width . 40)
1095 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1096 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1097 et dolore magna aliqua.
1100 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1101 laboris nisi ut aliquip ex ea commodo consequat.
1104 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1105 qui officia deserunt mollit anim id est laborum\"
1108 (stack-lines DOWN 0.0 baseline-skip
1109 (wordwrap-string-internal-markup-list layout props #t arg)))
1111 (define-markup-command (wordwrap-field layout props symbol)
1114 "Wordwrap the data which has been assigned to @var{symbol}.
1116 @lilypond[verbatim,quote]
1118 title = \"My title\"
1119 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1120 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1121 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1122 laboris nisi ut aliquip ex ea commodo consequat.\"
1126 bookTitleMarkup = \\markup {
1128 \\fill-line { \\fromproperty #'header:title }
1130 \\wordwrap-field #'header:myText
1139 (let* ((m (chain-assoc-get symbol props)))
1141 (wordwrap-string-markup layout props m)
1144 (define-markup-command (justify-field layout props symbol)
1147 "Justify the data which has been assigned to @var{symbol}.
1149 @lilypond[verbatim,quote]
1151 title = \"My title\"
1152 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1153 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1154 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1155 laboris nisi ut aliquip ex ea commodo consequat.\"
1159 bookTitleMarkup = \\markup {
1161 \\fill-line { \\fromproperty #'header:title }
1163 \\justify-field #'header:myText
1172 (let* ((m (chain-assoc-get symbol props)))
1174 (justify-string-markup layout props m)
1177 (define-markup-command (combine layout props arg1 arg2)
1181 @cindex merging text
1183 Print two markups on top of each other.
1185 Note: @code{\\combine} cannot take a list of markups enclosed in
1186 curly braces as an argument; the follow example will not compile:
1189 \\combine @{ a list @}
1192 @lilypond[verbatim,quote]
1195 \\override #'(thickness . 2)
1197 \\draw-line #'(0 . 4)
1198 \\arrow-head #Y #DOWN ##f
1201 (let* ((s1 (interpret-markup layout props arg1))
1202 (s2 (interpret-markup layout props arg2)))
1203 (ly:stencil-add s1 s2)))
1206 ;; TODO: should extract baseline-skip from each argument somehow..
1208 (define-markup-command (column layout props args)
1211 #:properties ((baseline-skip))
1213 @cindex stacking text in a column
1215 Stack the markups in @var{args} vertically. The property
1216 @code{baseline-skip} determines the space between markups
1219 @lilypond[verbatim,quote]
1228 (let ((arg-stencils (interpret-markup-list layout props args)))
1229 (stack-lines -1 0.0 baseline-skip
1230 (remove ly:stencil-empty? arg-stencils))))
1232 (define-markup-command (dir-column layout props args)
1235 #:properties ((direction)
1238 @cindex changing direction of text columns
1240 Make a column of @var{args}, going up or down, depending on the
1241 setting of the @code{direction} layout property.
1243 @lilypond[verbatim,quote]
1245 \\override #`(direction . ,UP) {
1255 \\override #'(direction . 1) {
1262 (stack-lines (if (number? direction) direction -1)
1265 (interpret-markup-list layout props args)))
1267 (define (general-column align-dir baseline mols)
1268 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1270 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1271 (stack-lines -1 0.0 baseline aligned-mols)))
1273 (define-markup-command (center-column layout props args)
1276 #:properties ((baseline-skip))
1278 @cindex centering a column of text
1280 Put @code{args} in a centered column.
1282 @lilypond[verbatim,quote]
1291 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1293 (define-markup-command (left-column layout props args)
1296 #:properties ((baseline-skip))
1298 @cindex text columns, left-aligned
1300 Put @code{args} in a left-aligned column.
1302 @lilypond[verbatim,quote]
1311 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1313 (define-markup-command (right-column layout props args)
1316 #:properties ((baseline-skip))
1318 @cindex text columns, right-aligned
1320 Put @code{args} in a right-aligned column.
1322 @lilypond[verbatim,quote]
1331 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1333 (define-markup-command (vcenter layout props arg)
1337 @cindex vertically centering text
1339 Align @code{arg} to its Y@tie{}center.
1341 @lilypond[verbatim,quote]
1349 (let* ((mol (interpret-markup layout props arg)))
1350 (ly:stencil-aligned-to mol Y CENTER)))
1352 (define-markup-command (center-align layout props arg)
1356 @cindex horizontally centering text
1358 Align @code{arg} to its X@tie{}center.
1360 @lilypond[verbatim,quote]
1370 (let* ((mol (interpret-markup layout props arg)))
1371 (ly:stencil-aligned-to mol X CENTER)))
1373 (define-markup-command (right-align layout props arg)
1377 @cindex right aligning text
1379 Align @var{arg} on its right edge.
1381 @lilypond[verbatim,quote]
1391 (let* ((m (interpret-markup layout props arg)))
1392 (ly:stencil-aligned-to m X RIGHT)))
1394 (define-markup-command (left-align layout props arg)
1398 @cindex left aligning text
1400 Align @var{arg} on its left edge.
1402 @lilypond[verbatim,quote]
1412 (let* ((m (interpret-markup layout props arg)))
1413 (ly:stencil-aligned-to m X LEFT)))
1415 (define-markup-command (general-align layout props axis dir arg)
1416 (integer? number? markup?)
1419 @cindex controlling general text alignment
1421 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1423 @lilypond[verbatim,quote]
1427 \\general-align #X #LEFT
1432 \\general-align #X #CENTER
1438 \\general-align #Y #UP
1445 \\general-align #Y #3.2
1452 (let* ((m (interpret-markup layout props arg)))
1453 (ly:stencil-aligned-to m axis dir)))
1455 (define-markup-command (halign layout props dir arg)
1459 @cindex setting horizontal text alignment
1461 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1462 left-aligned, while @code{+1} is right. Values in between interpolate
1463 alignment accordingly.
1465 @lilypond[verbatim,quote]
1490 (let* ((m (interpret-markup layout props arg)))
1491 (ly:stencil-aligned-to m X dir)))
1493 (define-markup-command (with-dimensions layout props x y arg)
1494 (number-pair? number-pair? markup?)
1497 @cindex setting extent of text objects
1499 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1500 (let* ((m (interpret-markup layout props arg)))
1501 (ly:make-stencil (ly:stencil-expr m) x y)))
1503 (define-markup-command (pad-around layout props amount arg)
1506 "Add padding @var{amount} all around @var{arg}.
1508 @lilypond[verbatim,quote]
1521 (let* ((m (interpret-markup layout props arg))
1522 (x (ly:stencil-extent m X))
1523 (y (ly:stencil-extent m Y)))
1524 (ly:make-stencil (ly:stencil-expr m)
1525 (interval-widen x amount)
1526 (interval-widen y amount))))
1528 (define-markup-command (pad-x layout props amount arg)
1532 @cindex padding text horizontally
1534 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
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)
1556 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1557 (integer? ly:dir? markup? markup?)
1559 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1560 (let ((m1 (interpret-markup layout props arg1))
1561 (m2 (interpret-markup layout props arg2)))
1562 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1564 (define-markup-command (transparent layout props arg)
1567 "Make @var{arg} transparent.
1569 @lilypond[verbatim,quote]
1576 (let* ((m (interpret-markup layout props arg))
1577 (x (ly:stencil-extent m X))
1578 (y (ly:stencil-extent m Y)))
1579 (ly:make-stencil "" x y)))
1581 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1582 (number-pair? number-pair? markup?)
1584 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1586 @lilypond[verbatim,quote]
1593 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1599 (let* ((m (interpret-markup layout props arg))
1600 (x (ly:stencil-extent m X))
1601 (y (ly:stencil-extent m Y)))
1602 (ly:make-stencil (ly:stencil-expr m)
1603 (interval-union x-ext x)
1604 (interval-union y-ext y))))
1606 (define-markup-command (hcenter-in layout props length arg)
1609 "Center @var{arg} horizontally within a box of extending
1610 @var{length}/2 to the left and right.
1612 @lilypond[quote,verbatim]
1615 \\set Staff.instrumentName = \\markup {
1622 \\set Staff.instrumentName = \\markup {
1631 (interpret-markup layout props
1632 (make-pad-to-box-markup
1633 (cons (/ length -2) (/ length 2))
1635 (make-center-align-markup arg))))
1637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1641 (define-markup-command (fromproperty layout props symbol)
1644 "Read the @var{symbol} from property settings, and produce a stencil
1645 from the markup contained within. If @var{symbol} is not defined, it
1646 returns an empty markup.
1648 @lilypond[verbatim,quote]
1650 myTitle = \"myTitle\"
1654 \\fromproperty #'header:myTitle
1661 (let ((m (chain-assoc-get symbol props)))
1663 (interpret-markup layout props m)
1666 (define-markup-command (on-the-fly layout props procedure arg)
1669 "Apply the @var{procedure} markup command to @var{arg}.
1670 @var{procedure} should take a single argument."
1671 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1672 (set-object-property! anonymous-with-signature
1675 (interpret-markup layout props (list anonymous-with-signature arg))))
1677 (define-markup-command (override layout props new-prop arg)
1681 @cindex overriding properties within text markup
1683 Add the argument @var{new-prop} to the property list. Properties
1684 may be any property supported by @rinternals{font-interface},
1685 @rinternals{text-interface} and
1686 @rinternals{instrument-specific-markup-interface}.
1688 @lilypond[verbatim,quote]
1696 \\override #'(baseline-skip . 4) {
1705 (interpret-markup layout (cons (list new-prop) props) arg))
1707 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1709 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1711 (define-markup-command (verbatim-file layout props name)
1714 "Read the contents of file @var{name}, and include it verbatim.
1716 @lilypond[verbatim,quote]
1718 \\verbatim-file #\"simple.ly\"
1721 (interpret-markup layout props
1722 (if (ly:get-option 'safe)
1723 "verbatim-file disabled in safe mode"
1724 (let* ((str (ly:gulp-file name))
1725 (lines (string-split str #\nl)))
1726 (make-typewriter-markup
1727 (make-column-markup lines))))))
1729 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1734 (define-markup-command (smaller layout props arg)
1737 "Decrease the font size relative to the current setting.
1739 @lilypond[verbatim,quote]
1752 (interpret-markup layout props
1753 `(,fontsize-markup -1 ,arg)))
1755 (define-markup-command (larger layout props arg)
1758 "Increase the font size relative to the current setting.
1760 @lilypond[verbatim,quote]
1768 (interpret-markup layout props
1769 `(,fontsize-markup 1 ,arg)))
1771 (define-markup-command (finger layout props arg)
1774 "Set @var{arg} as small numbers.
1776 @lilypond[verbatim,quote]
1783 (interpret-markup layout
1784 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1787 (define-markup-command (abs-fontsize layout props size arg)
1790 "Use @var{size} as the absolute font size to display @var{arg}.
1791 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1793 @lilypond[verbatim,quote]
1795 default text font size
1797 \\abs-fontsize #16 { text font size 16 }
1799 \\abs-fontsize #12 { text font size 12 }
1802 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1803 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1804 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1805 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1806 (magnification (/ size ref-size)))
1807 (interpret-markup layout
1808 (cons `((baseline-skip . ,(* magnification ref-baseline))
1809 (word-space . ,(* magnification ref-word-space))
1810 (font-size . ,(magnification->font-size magnification)))
1814 (define-markup-command (fontsize layout props increment arg)
1817 #:properties ((font-size 0)
1820 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1823 @lilypond[verbatim,quote]
1831 (let ((entries (list
1832 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1833 (cons 'word-space (* word-space (magstep increment)))
1834 (cons 'font-size (+ font-size increment)))))
1835 (interpret-markup layout (cons entries props) arg)))
1837 (define-markup-command (magnify layout props sz arg)
1841 @cindex magnifying text
1843 Set the font magnification for its argument. In the following
1844 example, the middle@tie{}A is 10% larger:
1847 A \\magnify #1.1 @{ A @} A
1850 Note: Magnification only works if a font name is explicitly selected.
1851 Use @code{\\fontsize} otherwise.
1853 @lilypond[verbatim,quote]
1864 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1867 (define-markup-command (bold layout props arg)
1870 "Switch to bold font-series.
1872 @lilypond[verbatim,quote]
1880 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1882 (define-markup-command (sans layout props arg)
1885 "Switch to the sans serif font family.
1887 @lilypond[verbatim,quote]
1896 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1898 (define-markup-command (number layout props arg)
1901 "Set font family to @code{number}, which yields the font used for
1902 time signatures and fingerings. This font contains numbers and
1903 some punctuation; it has no letters.
1905 @lilypond[verbatim,quote]
1908 0 1 2 3 4 5 6 7 8 9 . ,
1912 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1914 (define-markup-command (roman layout props arg)
1917 "Set font family to @code{roman}.
1919 @lilypond[verbatim,quote]
1925 text in roman font family
1932 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1934 (define-markup-command (huge layout props arg)
1937 "Set font size to +2.
1939 @lilypond[verbatim,quote]
1947 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1949 (define-markup-command (large layout props arg)
1952 "Set font size to +1.
1954 @lilypond[verbatim,quote]
1962 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1964 (define-markup-command (normalsize layout props arg)
1967 "Set font size to default.
1969 @lilypond[verbatim,quote]
1982 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1984 (define-markup-command (small layout props arg)
1987 "Set font size to -1.
1989 @lilypond[verbatim,quote]
1997 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
1999 (define-markup-command (tiny layout props arg)
2002 "Set font size to -2.
2004 @lilypond[verbatim,quote]
2012 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2014 (define-markup-command (teeny layout props arg)
2017 "Set font size to -3.
2019 @lilypond[verbatim,quote]
2027 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2029 (define-markup-command (fontCaps layout props arg)
2032 "Set @code{font-shape} to @code{caps}
2034 Note: @code{\\fontCaps} requires the installation and selection of
2035 fonts which support the @code{caps} font shape."
2036 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2039 (define-markup-command (smallCaps layout props arg)
2042 "Emit @var{arg} as small caps.
2044 Note: @code{\\smallCaps} does not support accented characters.
2046 @lilypond[verbatim,quote]
2055 (define (char-list->markup chars lower)
2056 (let ((final-string (string-upcase (reverse-list->string chars))))
2058 (markup #:fontsize -2 final-string)
2060 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2061 (if (null? rest-chars)
2063 (reverse! (cons (char-list->markup currents current-is-lower)
2065 (let* ((ch (car rest-chars))
2066 (is-lower (char-lower-case? ch)))
2067 (if (or (and current-is-lower is-lower)
2068 (and (not current-is-lower) (not is-lower)))
2069 (make-small-caps (cdr rest-chars)
2073 (make-small-caps (cdr rest-chars)
2076 (if (null? currents)
2078 (cons (char-list->markup
2079 currents current-is-lower)
2081 (interpret-markup layout props
2083 (make-small-caps (string->list arg) (list) #f (list))
2086 (define-markup-command (caps layout props arg)
2089 "Copy of the @code{\\smallCaps} command.
2091 @lilypond[verbatim,quote]
2100 (interpret-markup layout props (make-smallCaps-markup arg)))
2102 (define-markup-command (dynamic layout props arg)
2105 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2106 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2107 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2108 done in a different font. The recommended font for this is bold and italic.
2109 @lilypond[verbatim,quote]
2117 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2119 (define-markup-command (text layout props arg)
2122 "Use a text font instead of music symbol or music alphabet font.
2124 @lilypond[verbatim,quote]
2137 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2140 (define-markup-command (italic layout props arg)
2143 "Use italic @code{font-shape} for @var{arg}.
2145 @lilypond[verbatim,quote]
2153 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2155 (define-markup-command (typewriter layout props arg)
2158 "Use @code{font-family} typewriter for @var{arg}.
2160 @lilypond[verbatim,quote]
2169 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2171 (define-markup-command (upright layout props arg)
2174 "Set @code{font-shape} to @code{upright}. This is the opposite
2177 @lilypond[verbatim,quote]
2191 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2193 (define-markup-command (medium layout props arg)
2196 "Switch to medium font-series (in contrast to bold).
2198 @lilypond[verbatim,quote]
2211 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2214 (define-markup-command (normal-text layout props arg)
2217 "Set all font related properties (except the size) to get the default
2218 normal text font, no matter what font was used earlier.
2220 @lilypond[verbatim,quote]
2222 \\huge \\bold \\sans \\caps {
2223 Some text with font overrides
2226 Default text, same font-size
2234 (interpret-markup layout
2235 (cons '((font-family . roman) (font-shape . upright)
2236 (font-series . medium) (font-encoding . latin1))
2240 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2244 (define-markup-command (doublesharp layout props)
2247 "Draw a double sharp symbol.
2249 @lilypond[verbatim,quote]
2254 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2256 (define-markup-command (sesquisharp layout props)
2259 "Draw a 3/2 sharp symbol.
2261 @lilypond[verbatim,quote]
2266 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2268 (define-markup-command (sharp layout props)
2271 "Draw a sharp symbol.
2273 @lilypond[verbatim,quote]
2278 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2280 (define-markup-command (semisharp layout props)
2283 "Draw a semisharp symbol.
2285 @lilypond[verbatim,quote]
2290 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2292 (define-markup-command (natural layout props)
2295 "Draw a natural symbol.
2297 @lilypond[verbatim,quote]
2302 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2304 (define-markup-command (semiflat layout props)
2307 "Draw a semiflat symbol.
2309 @lilypond[verbatim,quote]
2314 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2316 (define-markup-command (flat layout props)
2319 "Draw a flat symbol.
2321 @lilypond[verbatim,quote]
2326 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2328 (define-markup-command (sesquiflat layout props)
2331 "Draw a 3/2 flat symbol.
2333 @lilypond[verbatim,quote]
2338 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2340 (define-markup-command (doubleflat layout props)
2343 "Draw a double flat symbol.
2345 @lilypond[verbatim,quote]
2350 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2352 (define-markup-command (with-color layout props color arg)
2356 @cindex coloring text
2358 Draw @var{arg} in color specified by @var{color}.
2360 @lilypond[verbatim,quote]
2372 (let ((stil (interpret-markup layout props arg)))
2373 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2374 (ly:stencil-extent stil X)
2375 (ly:stencil-extent stil Y))))
2377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2381 (define-markup-command (arrow-head layout props axis dir filled)
2382 (integer? ly:dir? boolean?)
2384 "Produce an arrow head in specified direction and axis.
2385 Use the filled head if @var{filled} is specified.
2386 @lilypond[verbatim,quote]
2389 \\general-align #Y #DOWN {
2390 \\arrow-head #Y #UP ##t
2391 \\arrow-head #Y #DOWN ##f
2393 \\arrow-head #X #RIGHT ##f
2394 \\arrow-head #X #LEFT ##f
2400 ((name (format "arrowheads.~a.~a~a"
2407 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2411 (define-markup-command (musicglyph layout props glyph-name)
2414 "@var{glyph-name} is converted to a musical symbol; for example,
2415 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2416 the music font. See @ruser{The Feta font} for a complete listing of
2417 the possible glyphs.
2419 @lilypond[verbatim,quote]
2422 \\musicglyph #\"rests.2\"
2423 \\musicglyph #\"clefs.G_change\"
2426 (let* ((font (ly:paper-get-font layout
2427 (cons '((font-encoding . fetaMusic)
2431 (glyph (ly:font-get-glyph font glyph-name)))
2432 (if (null? (ly:stencil-expr glyph))
2433 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2438 (define-markup-command (lookup layout props glyph-name)
2441 "Lookup a glyph by name.
2443 @lilypond[verbatim,quote]
2445 \\override #'(font-encoding . fetaBraces) {
2446 \\lookup #\"brace200\"
2449 \\lookup #\"brace180\"
2453 (ly:font-get-glyph (ly:paper-get-font layout props)
2456 (define-markup-command (char layout props num)
2459 "Produce a single character. Characters encoded in hexadecimal
2460 format require the prefix @code{#x}.
2462 @lilypond[verbatim,quote]
2464 \\char #65 \\char ##x00a9
2467 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2469 (define number->mark-letter-vector (make-vector 25 #\A))
2474 (if (= i (- (char->integer #\I) (char->integer #\A)))
2476 (vector-set! number->mark-letter-vector j
2477 (integer->char (+ i (char->integer #\A)))))
2479 (define number->mark-alphabet-vector (list->vector
2480 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2482 (define (number->markletter-string vec n)
2483 "Double letters for big marks."
2484 (let* ((lst (vector-length vec)))
2487 (string-append (number->markletter-string vec (1- (quotient n lst)))
2488 (number->markletter-string vec (remainder n lst)))
2489 (make-string 1 (vector-ref vec n)))))
2491 (define-markup-command (markletter layout props num)
2494 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2495 (skipping letter@tie{}I), and continue with double letters.
2497 @lilypond[verbatim,quote]
2504 (ly:text-interface::interpret-markup layout props
2505 (number->markletter-string number->mark-letter-vector num)))
2507 (define-markup-command (markalphabet layout props num)
2510 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2511 and continue with double letters.
2513 @lilypond[verbatim,quote]
2520 (ly:text-interface::interpret-markup layout props
2521 (number->markletter-string number->mark-alphabet-vector num)))
2523 (define-public (horizontal-slash-interval num forward number-interval mag)
2525 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2526 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2527 (else (interval-widen number-interval (* mag 0.25))))
2528 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2529 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2530 (else (interval-widen number-interval (* mag 0.25))))
2533 (define-public (adjust-slash-stencil num forward stencil mag)
2536 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2538 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2540 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2542 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2545 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2547 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2552 (define (slashed-digit-internal layout props num forward font-size thickness)
2553 (let* ((mag (magstep font-size))
2555 (ly:output-def-lookup layout 'line-thickness)
2557 ; backward slashes might use slope and point in the other direction!
2558 (dy (* mag (if forward 0.4 -0.4)))
2559 (number-stencil (interpret-markup layout
2560 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2561 (number->string num)))
2562 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2563 (center (interval-center (ly:stencil-extent number-stencil Y)))
2564 ; Use the real extents of the slash, not the whole number, because we
2565 ; might translate the slash later on!
2566 (num-y (interval-widen (cons center center) (abs dy)))
2567 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2568 (slash-stencil (if is-sane
2569 (make-line-stencil thickness
2570 (car num-x) (- (interval-center num-y) dy)
2571 (cdr num-x) (+ (interval-center num-y) dy))
2573 (if (ly:stencil? slash-stencil)
2575 ; for some numbers we need to shift the slash/backslash up or down to make
2576 ; the slashed digit look better
2577 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2578 (set! number-stencil
2579 (ly:stencil-add number-stencil slash-stencil)))
2580 (ly:warning "Unable to create slashed digit ~a" num))
2584 (define-markup-command (slashed-digit layout props num)
2587 #:properties ((font-size 0)
2590 @cindex slashed digits
2592 A feta number, with slash. This is for use in the context of
2593 figured bass notation.
2594 @lilypond[verbatim,quote]
2598 \\override #'(thickness . 3)
2602 (slashed-digit-internal layout props num #t font-size thickness))
2604 (define-markup-command (backslashed-digit layout props num)
2607 #:properties ((font-size 0)
2610 @cindex backslashed digits
2612 A feta number, with backslash. This is for use in the context of
2613 figured bass notation.
2614 @lilypond[verbatim,quote]
2616 \\backslashed-digit #5
2618 \\override #'(thickness . 3)
2619 \\backslashed-digit #7
2622 (slashed-digit-internal layout props num #f font-size thickness))
2625 (define eyeglassesps
2630 0.7 0.7 0.5 0 361 arc
2632 2.20 0.70 0.50 0 361 arc
2634 1.45 0.85 0.30 0 180 arc
2638 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2642 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2645 (define-markup-command (eyeglasses layout props)
2648 "Prints out eyeglasses, indicating strongly to look at the conductor.
2649 @lilypond[verbatim,quote]
2650 \\markup { \\eyeglasses }
2652 (interpret-markup layout props
2653 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2654 (make-postscript-markup eyeglassesps))))
2656 (define-markup-command (left-brace layout props size)
2660 A feta brace in point size @var{size}.
2662 @lilypond[verbatim,quote]
2669 (let* ((font (ly:paper-get-font layout
2670 (cons '((font-encoding . fetaBraces)
2673 (glyph-count (1- (ly:otf-glyph-count font)))
2674 (scale (ly:output-def-lookup layout 'output-scale))
2675 (scaled-size (/ (ly:pt size) scale))
2677 (ly:font-get-glyph font (string-append "brace"
2678 (number->string n)))))
2679 (get-y-from-brace (lambda (brace)
2681 (ly:stencil-extent (glyph brace) Y))))
2682 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2683 (glyph-found (glyph find-brace)))
2685 (if (or (null? (ly:stencil-expr glyph-found))
2686 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2687 (> scaled-size (interval-length
2688 (ly:stencil-extent (glyph glyph-count) Y))))
2690 (ly:warning (_ "no brace found for point size ~S ") size)
2691 (ly:warning (_ "defaulting to ~S pt")
2692 (/ (* scale (interval-length
2693 (ly:stencil-extent glyph-found Y)))
2697 (define-markup-command (right-brace layout props size)
2701 A feta brace in point size @var{size}, rotated 180 degrees.
2703 @lilypond[verbatim,quote]
2710 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2713 ;; the note command.
2714 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2716 ;; TODO: better syntax.
2718 (define-markup-command (note-by-number layout props log dot-count dir)
2719 (number? number? number?)
2721 #:properties ((font-size 0)
2724 @cindex notes within text by log and dot-count
2726 Construct a note symbol, with stem. By using fractional values for
2727 @var{dir}, longer or shorter stems can be obtained.
2729 @lilypond[verbatim,quote]
2731 \\note-by-number #3 #0 #DOWN
2733 \\note-by-number #1 #2 #0.8
2736 (define (get-glyph-name-candidates dir log style)
2737 (map (lambda (dir-name)
2738 (format "noteheads.~a~a" dir-name
2739 (if (and (symbol? style)
2740 (not (equal? 'default style)))
2741 (select-head-glyph style (min log 2))
2743 (list (if (= dir UP) "u" "d")
2746 (define (get-glyph-name font cands)
2749 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2750 (get-glyph-name font (cdr cands))
2753 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2755 (size-factor (magstep font-size))
2756 (stem-length (* size-factor (max 3 (- log 1))))
2758 (let ((result (get-glyph-name font (get-glyph-name-candidates
2759 (sign dir) log style))))
2760 (if (string-null? result)
2761 ;; If no glyph name can be found, select default heads. Though
2762 ;; this usually means an unsupported style has been chosen, it
2763 ;; also prevents unrelated 'style settings from other grobs
2764 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2765 (get-glyph-name font (get-glyph-name-candidates
2766 (sign dir) log 'default))
2768 (head-glyph (ly:font-get-glyph font head-glyph-name))
2769 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2770 (stem-thickness (* size-factor 0.13))
2771 (stemy (* dir stem-length))
2772 (attach-off (cons (interval-index
2773 (ly:stencil-extent head-glyph X)
2774 (* (sign dir) (car attach-indices)))
2775 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2777 (ly:stencil-extent head-glyph Y)
2778 (cdr attach-indices)))))
2779 (stem-glyph (and (> log 0)
2780 (ly:round-filled-box
2781 (ordered-cons (car attach-off)
2783 (* (- (sign dir)) stem-thickness)))
2784 (cons (min stemy (cdr attach-off))
2785 (max stemy (cdr attach-off)))
2786 (/ stem-thickness 3))))
2788 (dot (ly:font-get-glyph font "dots.dot"))
2789 (dotwid (interval-length (ly:stencil-extent dot X)))
2790 (dots (and (> dot-count 0)
2791 (apply ly:stencil-add
2793 (ly:stencil-translate-axis
2794 dot (* 2 x dotwid) X))
2795 (iota dot-count)))))
2796 (flaggl (and (> log 2)
2797 (ly:stencil-translate
2798 (ly:font-get-glyph font
2799 (string-append "flags."
2800 (if (> dir 0) "u" "d")
2801 (number->string log)))
2802 (cons (+ (car attach-off) (if (< dir 0)
2806 ;; If there is a flag on an upstem and the stem is short, move the dots
2807 ;; to avoid the flag. 16th notes get a special case because their flags
2808 ;; hang lower than any other flags.
2809 (if (and dots (> dir 0) (> log 2)
2810 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2811 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2813 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2814 (if (ly:stencil? stem-glyph)
2815 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2816 (set! stem-glyph head-glyph))
2817 (if (ly:stencil? dots)
2820 (ly:stencil-translate-axis
2822 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2828 (let ((divisor (log 2)))
2829 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2831 (define (parse-simple-duration duration-string)
2832 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2833 and return a (log dots) list."
2834 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2836 (if (and match (string=? duration-string (match:substring match 0)))
2837 (let ((len (match:substring match 1))
2838 (dots (match:substring match 2)))
2839 (list (cond ((string=? len "breve") -1)
2840 ((string=? len "longa") -2)
2841 ((string=? len "maxima") -3)
2842 (else (log2 (string->number len))))
2843 (if dots (string-length dots) 0)))
2844 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2846 (define-markup-command (note layout props duration dir)
2849 #:properties (note-by-number-markup)
2851 @cindex notes within text by string
2853 This produces a note with a stem pointing in @var{dir} direction, with
2854 the @var{duration} for the note head type and augmentation dots. For
2855 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2856 a shortened down stem.
2858 @lilypond[verbatim,quote]
2860 \\override #'(style . cross) {
2864 \\note #\"breve\" #0
2867 (let ((parsed (parse-simple-duration duration)))
2868 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2870 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2872 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2874 (define-markup-command (lower layout props amount arg)
2878 @cindex lowering text
2880 Lower @var{arg} by the distance @var{amount}.
2881 A negative @var{amount} indicates raising; see also @code{\\raise}.
2883 @lilypond[verbatim,quote]
2891 (ly:stencil-translate-axis (interpret-markup layout props arg)
2894 (define-markup-command (translate-scaled layout props offset arg)
2895 (number-pair? markup?)
2897 #:properties ((font-size 0))
2899 @cindex translating text
2900 @cindex scaling text
2902 Translate @var{arg} by @var{offset}, scaling the offset by the
2905 @lilypond[verbatim,quote]
2908 * \\translate #'(2 . 3) translate
2910 * \\translate-scaled #'(2 . 3) translate-scaled
2914 (let* ((factor (magstep font-size))
2915 (scaled (cons (* factor (car offset))
2916 (* factor (cdr offset)))))
2917 (ly:stencil-translate (interpret-markup layout props arg)
2920 (define-markup-command (raise layout props amount arg)
2924 @cindex raising text
2926 Raise @var{arg} by the distance @var{amount}.
2927 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2929 The argument to @code{\\raise} is the vertical displacement amount,
2930 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2931 raise objects in relation to their surrounding markups.
2933 If the text object itself is positioned above or below the staff, then
2934 @code{\\raise} cannot be used to move it, since the mechanism that
2935 positions it next to the staff cancels any shift made with
2936 @code{\\raise}. For vertical positioning, use the @code{padding}
2937 and/or @code{extra-offset} properties.
2939 @lilypond[verbatim,quote]
2948 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2950 (define-markup-command (fraction layout props arg1 arg2)
2953 #:properties ((font-size 0))
2955 @cindex creating text fractions
2957 Make a fraction of two markups.
2958 @lilypond[verbatim,quote]
2964 (let* ((m1 (interpret-markup layout props arg1))
2965 (m2 (interpret-markup layout props arg2))
2966 (factor (magstep font-size))
2967 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2968 (padding (* factor 0.2))
2969 (baseline (* factor 0.6))
2970 (offset (* factor 0.75)))
2971 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2972 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2973 (let* ((x1 (ly:stencil-extent m1 X))
2974 (x2 (ly:stencil-extent m2 X))
2975 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2976 ;; should stack mols separately, to maintain LINE on baseline
2977 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2979 (ly:stencil-aligned-to stack Y CENTER))
2981 (ly:stencil-aligned-to stack X LEFT))
2982 ;; should have EX dimension
2984 (ly:stencil-translate-axis stack offset Y))))
2986 (define-markup-command (normal-size-super layout props arg)
2989 #:properties ((baseline-skip))
2991 @cindex setting superscript in standard font size
2993 Set @var{arg} in superscript with a normal font size.
2995 @lilypond[verbatim,quote]
2998 \\normal-size-super {
2999 superscript in standard size
3003 (ly:stencil-translate-axis
3004 (interpret-markup layout props arg)
3005 (* 0.5 baseline-skip) Y))
3007 (define-markup-command (super layout props arg)
3010 #:properties ((font-size 0)
3013 @cindex superscript text
3015 Set @var{arg} in superscript.
3017 @lilypond[verbatim,quote]
3027 (ly:stencil-translate-axis
3030 (cons `((font-size . ,(- font-size 3))) props)
3032 (* 0.5 baseline-skip)
3035 (define-markup-command (translate layout props offset arg)
3036 (number-pair? markup?)
3039 @cindex translating text
3041 Translate @var{arg} relative to its surroundings. @var{offset}
3042 is a pair of numbers representing the displacement in the X and Y axis.
3044 @lilypond[verbatim,quote]
3047 \\translate #'(2 . 3)
3048 \\line { translated two spaces right, three up }
3051 (ly:stencil-translate (interpret-markup layout props arg)
3054 (define-markup-command (sub layout props arg)
3057 #:properties ((font-size 0)
3060 @cindex subscript text
3062 Set @var{arg} in subscript.
3064 @lilypond[verbatim,quote]
3075 (ly:stencil-translate-axis
3078 (cons `((font-size . ,(- font-size 3))) props)
3080 (* -0.5 baseline-skip)
3083 (define-markup-command (normal-size-sub layout props arg)
3086 #:properties ((baseline-skip))
3088 @cindex setting subscript in standard font size
3090 Set @var{arg} in subscript with a normal font size.
3092 @lilypond[verbatim,quote]
3096 subscript in standard size
3100 (ly:stencil-translate-axis
3101 (interpret-markup layout props arg)
3102 (* -0.5 baseline-skip)
3105 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3109 (define-markup-command (hbracket layout props arg)
3113 @cindex placing horizontal brackets around text
3115 Draw horizontal brackets around @var{arg}.
3117 @lilypond[verbatim,quote]
3126 (let ((th 0.1) ;; todo: take from GROB.
3127 (m (interpret-markup layout props arg)))
3128 (bracketify-stencil m X th (* 2.5 th) th)))
3130 (define-markup-command (bracket layout props arg)
3134 @cindex placing vertical brackets around text
3136 Draw vertical brackets around @var{arg}.
3138 @lilypond[verbatim,quote]
3145 (let ((th 0.1) ;; todo: take from GROB.
3146 (m (interpret-markup layout props arg)))
3147 (bracketify-stencil m Y th (* 2.5 th) th)))
3149 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3150 ;; Delayed markup evaluation
3151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3153 (define-markup-command (page-ref layout props label gauge default)
3154 (symbol? markup? markup?)
3157 @cindex referencing page numbers in text
3159 Reference to a page number. @var{label} is the label set on the referenced
3160 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3161 the maximum width of the page number, and @var{default} the value to display
3162 when @var{label} is not found."
3163 (let* ((gauge-stencil (interpret-markup layout props gauge))
3164 (x-ext (ly:stencil-extent gauge-stencil X))
3165 (y-ext (ly:stencil-extent gauge-stencil Y)))
3167 `(delay-stencil-evaluation
3168 ,(delay (ly:stencil-expr
3169 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3170 (page-number (if (list? table)
3171 (assoc-get label table)
3173 (page-markup (if page-number (format "~a" page-number) default))
3174 (page-stencil (interpret-markup layout props page-markup))
3175 (gap (- (interval-length x-ext)
3176 (interval-length (ly:stencil-extent page-stencil X)))))
3177 (interpret-markup layout props
3178 (markup #:concat (#:hspace gap page-markup)))))))
3182 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3183 ;; Markup list commands
3184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3186 (define-public (space-lines baseline stils)
3187 (let space-stil ((stils stils)
3191 (let* ((stil (car stils))
3192 (dy-top (max (- (/ baseline 1.5)
3193 (interval-bound (ly:stencil-extent stil Y) UP))
3195 (dy-bottom (max (+ (/ baseline 3.0)
3196 (interval-bound (ly:stencil-extent stil Y) DOWN))
3198 (new-stil (ly:make-stencil
3199 (ly:stencil-expr stil)
3200 (ly:stencil-extent stil X)
3201 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3203 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3205 (space-stil (cdr stils) (cons new-stil result))))))
3207 (define-markup-list-command (justified-lines layout props args)
3209 #:properties ((baseline-skip)
3210 wordwrap-internal-markup-list)
3212 @cindex justifying lines of text
3214 Like @code{\\justify}, but return a list of lines instead of a single markup.
3215 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3216 @var{X}@tie{}is the number of staff spaces."
3217 (space-lines baseline-skip
3218 (interpret-markup-list layout props
3219 (make-wordwrap-internal-markup-list #t args))))
3221 (define-markup-list-command (wordwrap-lines layout props args)
3223 #:properties ((baseline-skip)
3224 wordwrap-internal-markup-list)
3225 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3226 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3227 where @var{X} is the number of staff spaces."
3228 (space-lines baseline-skip
3229 (interpret-markup-list layout props
3230 (make-wordwrap-internal-markup-list #f args))))
3232 (define-markup-list-command (column-lines layout props args)
3234 #:properties ((baseline-skip))
3235 "Like @code{\\column}, but return a list of lines instead of a single markup.
3236 @code{baseline-skip} determines the space between each markup in @var{args}."
3237 (space-lines baseline-skip
3238 (interpret-markup-list layout props args)))
3240 (define-markup-list-command (override-lines layout props new-prop args)
3241 (pair? markup-list?)
3242 "Like @code{\\override}, for markup lists."
3243 (interpret-markup-list layout (cons (list new-prop) props) args))