1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2010 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 (ly:stencil-translate-axis
854 (stack-stencils-padding-list X
855 RIGHT fill-space-normal line-stencils)
856 (- (car (ly:stencil-extent (car stencils) X)))
859 (define-markup-command (line layout props args)
862 #:properties ((word-space)
863 (text-direction RIGHT))
864 "Put @var{args} in a horizontal line. The property @code{word-space}
865 determines the space between markups in @var{args}.
867 @lilypond[verbatim,quote]
874 (let ((stencils (interpret-markup-list layout props args)))
875 (if (= text-direction LEFT)
876 (set! stencils (reverse stencils)))
879 (remove ly:stencil-empty? stencils))))
881 (define-markup-command (concat layout props args)
885 @cindex concatenating text
886 @cindex ligatures in text
888 Concatenate @var{args} in a horizontal line, without spaces in between.
889 Strings and simple markups are concatenated on the input level, allowing
890 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
891 equivalent to @code{\"fi\"}.
893 @lilypond[verbatim,quote]
902 (define (concat-string-args arg-list)
903 (fold-right (lambda (arg result-list)
904 (let ((result (if (pair? result-list)
907 (if (and (pair? arg) (eqv? (car arg) simple-markup))
908 (set! arg (cadr arg)))
909 (if (and (string? result) (string? arg))
910 (cons (string-append arg result) (cdr result-list))
911 (cons arg result-list))))
915 (interpret-markup layout
916 (prepend-alist-chain 'word-space 0 props)
917 (make-line-markup (if (markup-command-list? args)
919 (concat-string-args args)))))
921 (define (wordwrap-stencils stencils
922 justify base-space line-width text-dir)
923 "Perform simple wordwrap, return stencil of each line."
924 (define space (if justify
925 ;; justify only stretches lines.
928 (define (take-list width space stencils
929 accumulator accumulated-width)
930 "Return (head-list . tail) pair, with head-list fitting into width"
932 (cons accumulator stencils)
933 (let* ((first (car stencils))
934 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
935 (newwid (+ space first-wid accumulated-width)))
936 (if (or (null? accumulator)
938 (take-list width space
940 (cons first accumulator)
942 (cons accumulator stencils)))))
943 (let loop ((lines '())
945 (let* ((line-break (take-list line-width space todo
947 (line-stencils (car line-break))
948 (space-left (- line-width
949 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
951 (line-word-space (cond ((not justify) space)
952 ;; don't stretch last line of paragraph.
953 ;; hmmm . bug - will overstretch the last line in some case.
954 ((null? (cdr line-break))
956 ((null? line-stencils) 0.0)
957 ((null? (cdr line-stencils)) 0.0)
958 (else (/ space-left (1- (length line-stencils))))))
959 (line (stack-stencil-line line-word-space
960 (if (= text-dir RIGHT)
961 (reverse line-stencils)
963 (if (pair? (cdr line-break))
964 (loop (cons line lines)
967 (if (= text-dir LEFT)
969 (ly:stencil-translate-axis
971 (- line-width (interval-end (ly:stencil-extent line X)))
973 (reverse (cons line lines)))))))
975 (define-markup-list-command (wordwrap-internal layout props justify args)
976 (boolean? markup-list?)
977 #:properties ((line-width #f)
979 (text-direction RIGHT))
980 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
981 (wordwrap-stencils (remove ly:stencil-empty?
982 (interpret-markup-list layout props args))
986 (ly:output-def-lookup layout 'line-width))
989 (define-markup-command (justify layout props args)
992 #:properties ((baseline-skip)
993 wordwrap-internal-markup-list)
995 @cindex justifying text
997 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
998 Use @code{\\override #'(line-width . @var{X})} to set the line width;
999 @var{X}@tie{}is the number of staff spaces.
1001 @lilypond[verbatim,quote]
1004 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1005 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1006 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1007 laboris nisi ut aliquip ex ea commodo consequat.
1011 (stack-lines DOWN 0.0 baseline-skip
1012 (wordwrap-internal-markup-list layout props #t args)))
1014 (define-markup-command (wordwrap layout props args)
1017 #:properties ((baseline-skip)
1018 wordwrap-internal-markup-list)
1019 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1020 the line width, where @var{X} is the number of staff spaces.
1022 @lilypond[verbatim,quote]
1025 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1026 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1027 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1028 laboris nisi ut aliquip ex ea commodo consequat.
1032 (stack-lines DOWN 0.0 baseline-skip
1033 (wordwrap-internal-markup-list layout props #f args)))
1035 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1037 #:properties ((line-width)
1039 (text-direction RIGHT))
1040 "Internal markup list command used to define @code{\\justify-string} and
1041 @code{\\wordwrap-string}."
1042 (let* ((para-strings (regexp-split
1043 (string-regexp-substitute
1045 (string-regexp-substitute "\r\n" "\n" arg))
1046 "\n[ \t\n]*\n[ \t\n]*"))
1047 (list-para-words (map (lambda (str)
1048 (regexp-split str "[ \t\n]+"))
1050 (para-lines (map (lambda (words)
1052 (remove ly:stencil-empty?
1054 (interpret-markup layout props x))
1056 (wordwrap-stencils stencils
1058 line-width text-direction)))
1060 (apply append para-lines)))
1062 (define-markup-command (wordwrap-string layout props arg)
1065 #:properties ((baseline-skip)
1066 wordwrap-string-internal-markup-list)
1067 "Wordwrap a string. Paragraphs may be separated with double newlines.
1069 @lilypond[verbatim,quote]
1071 \\override #'(line-width . 40)
1072 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1073 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1074 et dolore magna aliqua.
1077 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1078 laboris nisi ut aliquip ex ea commodo consequat.
1081 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1082 qui officia deserunt mollit anim id est laborum\"
1085 (stack-lines DOWN 0.0 baseline-skip
1086 (wordwrap-string-internal-markup-list layout props #f arg)))
1088 (define-markup-command (justify-string layout props arg)
1091 #:properties ((baseline-skip)
1092 wordwrap-string-internal-markup-list)
1093 "Justify a string. Paragraphs may be separated with double newlines
1095 @lilypond[verbatim,quote]
1097 \\override #'(line-width . 40)
1098 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1099 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1100 et dolore magna aliqua.
1103 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1104 laboris nisi ut aliquip ex ea commodo consequat.
1107 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1108 qui officia deserunt mollit anim id est laborum\"
1111 (stack-lines DOWN 0.0 baseline-skip
1112 (wordwrap-string-internal-markup-list layout props #t arg)))
1114 (define-markup-command (wordwrap-field layout props symbol)
1117 "Wordwrap the data which has been assigned to @var{symbol}.
1119 @lilypond[verbatim,quote]
1121 title = \"My title\"
1122 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1123 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1124 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1125 laboris nisi ut aliquip ex ea commodo consequat.\"
1129 bookTitleMarkup = \\markup {
1131 \\fill-line { \\fromproperty #'header:title }
1133 \\wordwrap-field #'header:myText
1142 (let* ((m (chain-assoc-get symbol props)))
1144 (wordwrap-string-markup layout props m)
1147 (define-markup-command (justify-field layout props symbol)
1150 "Justify the data which has been assigned to @var{symbol}.
1152 @lilypond[verbatim,quote]
1154 title = \"My title\"
1155 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1156 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1157 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1158 laboris nisi ut aliquip ex ea commodo consequat.\"
1162 bookTitleMarkup = \\markup {
1164 \\fill-line { \\fromproperty #'header:title }
1166 \\justify-field #'header:myText
1175 (let* ((m (chain-assoc-get symbol props)))
1177 (justify-string-markup layout props m)
1180 (define-markup-command (combine layout props arg1 arg2)
1184 @cindex merging text
1186 Print two markups on top of each other.
1188 Note: @code{\\combine} cannot take a list of markups enclosed in
1189 curly braces as an argument; the follow example will not compile:
1192 \\combine @{ a list @}
1195 @lilypond[verbatim,quote]
1198 \\override #'(thickness . 2)
1200 \\draw-line #'(0 . 4)
1201 \\arrow-head #Y #DOWN ##f
1204 (let* ((s1 (interpret-markup layout props arg1))
1205 (s2 (interpret-markup layout props arg2)))
1206 (ly:stencil-add s1 s2)))
1209 ;; TODO: should extract baseline-skip from each argument somehow..
1211 (define-markup-command (column layout props args)
1214 #:properties ((baseline-skip))
1216 @cindex stacking text in a column
1218 Stack the markups in @var{args} vertically. The property
1219 @code{baseline-skip} determines the space between markups
1222 @lilypond[verbatim,quote]
1231 (let ((arg-stencils (interpret-markup-list layout props args)))
1232 (stack-lines -1 0.0 baseline-skip
1233 (remove ly:stencil-empty? arg-stencils))))
1235 (define-markup-command (dir-column layout props args)
1238 #:properties ((direction)
1241 @cindex changing direction of text columns
1243 Make a column of @var{args}, going up or down, depending on the
1244 setting of the @code{direction} layout property.
1246 @lilypond[verbatim,quote]
1248 \\override #`(direction . ,UP) {
1258 \\override #'(direction . 1) {
1265 (stack-lines (if (number? direction) direction -1)
1268 (interpret-markup-list layout props args)))
1270 (define (general-column align-dir baseline mols)
1271 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1273 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1274 (stack-lines -1 0.0 baseline aligned-mols)))
1276 (define-markup-command (center-column layout props args)
1279 #:properties ((baseline-skip))
1281 @cindex centering a column of text
1283 Put @code{args} in a centered column.
1285 @lilypond[verbatim,quote]
1294 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1296 (define-markup-command (left-column layout props args)
1299 #:properties ((baseline-skip))
1301 @cindex text columns, left-aligned
1303 Put @code{args} in a left-aligned column.
1305 @lilypond[verbatim,quote]
1314 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1316 (define-markup-command (right-column layout props args)
1319 #:properties ((baseline-skip))
1321 @cindex text columns, right-aligned
1323 Put @code{args} in a right-aligned column.
1325 @lilypond[verbatim,quote]
1334 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1336 (define-markup-command (vcenter layout props arg)
1340 @cindex vertically centering text
1342 Align @code{arg} to its Y@tie{}center.
1344 @lilypond[verbatim,quote]
1352 (let* ((mol (interpret-markup layout props arg)))
1353 (ly:stencil-aligned-to mol Y CENTER)))
1355 (define-markup-command (center-align layout props arg)
1359 @cindex horizontally centering text
1361 Align @code{arg} to its X@tie{}center.
1363 @lilypond[verbatim,quote]
1373 (let* ((mol (interpret-markup layout props arg)))
1374 (ly:stencil-aligned-to mol X CENTER)))
1376 (define-markup-command (right-align layout props arg)
1380 @cindex right aligning text
1382 Align @var{arg} on its right edge.
1384 @lilypond[verbatim,quote]
1394 (let* ((m (interpret-markup layout props arg)))
1395 (ly:stencil-aligned-to m X RIGHT)))
1397 (define-markup-command (left-align layout props arg)
1401 @cindex left aligning text
1403 Align @var{arg} on its left edge.
1405 @lilypond[verbatim,quote]
1415 (let* ((m (interpret-markup layout props arg)))
1416 (ly:stencil-aligned-to m X LEFT)))
1418 (define-markup-command (general-align layout props axis dir arg)
1419 (integer? number? markup?)
1422 @cindex controlling general text alignment
1424 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1426 @lilypond[verbatim,quote]
1430 \\general-align #X #LEFT
1435 \\general-align #X #CENTER
1441 \\general-align #Y #UP
1448 \\general-align #Y #3.2
1455 (let* ((m (interpret-markup layout props arg)))
1456 (ly:stencil-aligned-to m axis dir)))
1458 (define-markup-command (halign layout props dir arg)
1462 @cindex setting horizontal text alignment
1464 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1465 left-aligned, while @code{+1} is right. Values in between interpolate
1466 alignment accordingly.
1468 @lilypond[verbatim,quote]
1493 (let* ((m (interpret-markup layout props arg)))
1494 (ly:stencil-aligned-to m X dir)))
1496 (define-markup-command (with-dimensions layout props x y arg)
1497 (number-pair? number-pair? markup?)
1500 @cindex setting extent of text objects
1502 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1503 (let* ((m (interpret-markup layout props arg)))
1504 (ly:make-stencil (ly:stencil-expr m) x y)))
1506 (define-markup-command (pad-around layout props amount arg)
1509 "Add padding @var{amount} all around @var{arg}.
1511 @lilypond[verbatim,quote]
1524 (let* ((m (interpret-markup layout props arg))
1525 (x (ly:stencil-extent m X))
1526 (y (ly:stencil-extent m Y)))
1527 (ly:make-stencil (ly:stencil-expr m)
1528 (interval-widen x amount)
1529 (interval-widen y amount))))
1531 (define-markup-command (pad-x layout props amount arg)
1535 @cindex padding text horizontally
1537 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1539 @lilypond[verbatim,quote]
1552 (let* ((m (interpret-markup layout props arg))
1553 (x (ly:stencil-extent m X))
1554 (y (ly:stencil-extent m Y)))
1555 (ly:make-stencil (ly:stencil-expr m)
1556 (interval-widen x amount)
1559 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1560 (integer? ly:dir? markup? markup?)
1562 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1563 (let ((m1 (interpret-markup layout props arg1))
1564 (m2 (interpret-markup layout props arg2)))
1565 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1567 (define-markup-command (transparent layout props arg)
1570 "Make @var{arg} transparent.
1572 @lilypond[verbatim,quote]
1579 (let* ((m (interpret-markup layout props arg))
1580 (x (ly:stencil-extent m X))
1581 (y (ly:stencil-extent m Y)))
1582 (ly:make-stencil "" x y)))
1584 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1585 (number-pair? number-pair? markup?)
1587 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1589 @lilypond[verbatim,quote]
1596 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1602 (let* ((m (interpret-markup layout props arg))
1603 (x (ly:stencil-extent m X))
1604 (y (ly:stencil-extent m Y)))
1605 (ly:make-stencil (ly:stencil-expr m)
1606 (interval-union x-ext x)
1607 (interval-union y-ext y))))
1609 (define-markup-command (hcenter-in layout props length arg)
1612 "Center @var{arg} horizontally within a box of extending
1613 @var{length}/2 to the left and right.
1615 @lilypond[quote,verbatim]
1618 \\set Staff.instrumentName = \\markup {
1625 \\set Staff.instrumentName = \\markup {
1634 (interpret-markup layout props
1635 (make-pad-to-box-markup
1636 (cons (/ length -2) (/ length 2))
1638 (make-center-align-markup arg))))
1640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 (define-markup-command (fromproperty layout props symbol)
1647 "Read the @var{symbol} from property settings, and produce a stencil
1648 from the markup contained within. If @var{symbol} is not defined, it
1649 returns an empty markup.
1651 @lilypond[verbatim,quote]
1653 myTitle = \"myTitle\"
1657 \\fromproperty #'header:myTitle
1664 (let ((m (chain-assoc-get symbol props)))
1666 (interpret-markup layout props m)
1669 (define-markup-command (on-the-fly layout props procedure arg)
1672 "Apply the @var{procedure} markup command to @var{arg}.
1673 @var{procedure} should take a single argument."
1674 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1675 (set-object-property! anonymous-with-signature
1678 (interpret-markup layout props (list anonymous-with-signature arg))))
1680 (define-markup-command (override layout props new-prop arg)
1684 @cindex overriding properties within text markup
1686 Add the argument @var{new-prop} to the property list. Properties
1687 may be any property supported by @rinternals{font-interface},
1688 @rinternals{text-interface} and
1689 @rinternals{instrument-specific-markup-interface}.
1691 @lilypond[verbatim,quote]
1699 \\override #'(baseline-skip . 4) {
1708 (interpret-markup layout (cons (list new-prop) props) arg))
1710 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1714 (define-markup-command (verbatim-file layout props name)
1717 "Read the contents of file @var{name}, and include it verbatim.
1719 @lilypond[verbatim,quote]
1721 \\verbatim-file #\"simple.ly\"
1724 (interpret-markup layout props
1725 (if (ly:get-option 'safe)
1726 "verbatim-file disabled in safe mode"
1727 (let* ((str (ly:gulp-file name))
1728 (lines (string-split str #\nl)))
1729 (make-typewriter-markup
1730 (make-column-markup lines))))))
1732 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1734 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1737 (define-markup-command (smaller layout props arg)
1740 "Decrease the font size relative to the current setting.
1742 @lilypond[verbatim,quote]
1755 (interpret-markup layout props
1756 `(,fontsize-markup -1 ,arg)))
1758 (define-markup-command (larger layout props arg)
1761 "Increase the font size relative to the current setting.
1763 @lilypond[verbatim,quote]
1771 (interpret-markup layout props
1772 `(,fontsize-markup 1 ,arg)))
1774 (define-markup-command (finger layout props arg)
1777 "Set @var{arg} as small numbers.
1779 @lilypond[verbatim,quote]
1786 (interpret-markup layout
1787 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
1790 (define-markup-command (abs-fontsize layout props size arg)
1793 "Use @var{size} as the absolute font size to display @var{arg}.
1794 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1796 @lilypond[verbatim,quote]
1798 default text font size
1800 \\abs-fontsize #16 { text font size 16 }
1802 \\abs-fontsize #12 { text font size 12 }
1805 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1806 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1807 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1808 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1809 (magnification (/ size ref-size)))
1810 (interpret-markup layout
1811 (cons `((baseline-skip . ,(* magnification ref-baseline))
1812 (word-space . ,(* magnification ref-word-space))
1813 (font-size . ,(magnification->font-size magnification)))
1817 (define-markup-command (fontsize layout props increment arg)
1820 #:properties ((font-size 0)
1823 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1826 @lilypond[verbatim,quote]
1834 (let ((entries (list
1835 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1836 (cons 'word-space (* word-space (magstep increment)))
1837 (cons 'font-size (+ font-size increment)))))
1838 (interpret-markup layout (cons entries props) arg)))
1840 (define-markup-command (magnify layout props sz arg)
1844 @cindex magnifying text
1846 Set the font magnification for its argument. In the following
1847 example, the middle@tie{}A is 10% larger:
1850 A \\magnify #1.1 @{ A @} A
1853 Note: Magnification only works if a font name is explicitly selected.
1854 Use @code{\\fontsize} otherwise.
1856 @lilypond[verbatim,quote]
1867 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1870 (define-markup-command (bold layout props arg)
1873 "Switch to bold font-series.
1875 @lilypond[verbatim,quote]
1883 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1885 (define-markup-command (sans layout props arg)
1888 "Switch to the sans serif font family.
1890 @lilypond[verbatim,quote]
1899 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1901 (define-markup-command (number layout props arg)
1904 "Set font family to @code{number}, which yields the font used for
1905 time signatures and fingerings. This font contains numbers and
1906 some punctuation; it has no letters.
1908 @lilypond[verbatim,quote]
1911 0 1 2 3 4 5 6 7 8 9 . ,
1915 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
1917 (define-markup-command (roman layout props arg)
1920 "Set font family to @code{roman}.
1922 @lilypond[verbatim,quote]
1928 text in roman font family
1935 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1937 (define-markup-command (huge layout props arg)
1940 "Set font size to +2.
1942 @lilypond[verbatim,quote]
1950 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1952 (define-markup-command (large layout props arg)
1955 "Set font size to +1.
1957 @lilypond[verbatim,quote]
1965 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1967 (define-markup-command (normalsize layout props arg)
1970 "Set font size to default.
1972 @lilypond[verbatim,quote]
1985 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1987 (define-markup-command (small layout props arg)
1990 "Set font size to -1.
1992 @lilypond[verbatim,quote]
2000 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2002 (define-markup-command (tiny layout props arg)
2005 "Set font size to -2.
2007 @lilypond[verbatim,quote]
2015 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2017 (define-markup-command (teeny layout props arg)
2020 "Set font size to -3.
2022 @lilypond[verbatim,quote]
2030 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2032 (define-markup-command (fontCaps layout props arg)
2035 "Set @code{font-shape} to @code{caps}
2037 Note: @code{\\fontCaps} requires the installation and selection of
2038 fonts which support the @code{caps} font shape."
2039 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2042 (define-markup-command (smallCaps layout props arg)
2045 "Emit @var{arg} as small caps.
2047 Note: @code{\\smallCaps} does not support accented characters.
2049 @lilypond[verbatim,quote]
2058 (define (char-list->markup chars lower)
2059 (let ((final-string (string-upcase (reverse-list->string chars))))
2061 (markup #:fontsize -2 final-string)
2063 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2064 (if (null? rest-chars)
2066 (reverse! (cons (char-list->markup currents current-is-lower)
2068 (let* ((ch (car rest-chars))
2069 (is-lower (char-lower-case? ch)))
2070 (if (or (and current-is-lower is-lower)
2071 (and (not current-is-lower) (not is-lower)))
2072 (make-small-caps (cdr rest-chars)
2076 (make-small-caps (cdr rest-chars)
2079 (if (null? currents)
2081 (cons (char-list->markup
2082 currents current-is-lower)
2084 (interpret-markup layout props
2086 (make-small-caps (string->list arg) (list) #f (list))
2089 (define-markup-command (caps layout props arg)
2092 "Copy of the @code{\\smallCaps} command.
2094 @lilypond[verbatim,quote]
2103 (interpret-markup layout props (make-smallCaps-markup arg)))
2105 (define-markup-command (dynamic layout props arg)
2108 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2109 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2110 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2111 done in a different font. The recommended font for this is bold and italic.
2112 @lilypond[verbatim,quote]
2120 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
2122 (define-markup-command (text layout props arg)
2125 "Use a text font instead of music symbol or music alphabet font.
2127 @lilypond[verbatim,quote]
2140 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2143 (define-markup-command (italic layout props arg)
2146 "Use italic @code{font-shape} for @var{arg}.
2148 @lilypond[verbatim,quote]
2156 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2158 (define-markup-command (typewriter layout props arg)
2161 "Use @code{font-family} typewriter for @var{arg}.
2163 @lilypond[verbatim,quote]
2172 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2174 (define-markup-command (upright layout props arg)
2177 "Set @code{font-shape} to @code{upright}. This is the opposite
2180 @lilypond[verbatim,quote]
2194 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2196 (define-markup-command (medium layout props arg)
2199 "Switch to medium font-series (in contrast to bold).
2201 @lilypond[verbatim,quote]
2214 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2217 (define-markup-command (normal-text layout props arg)
2220 "Set all font related properties (except the size) to get the default
2221 normal text font, no matter what font was used earlier.
2223 @lilypond[verbatim,quote]
2225 \\huge \\bold \\sans \\caps {
2226 Some text with font overrides
2229 Default text, same font-size
2237 (interpret-markup layout
2238 (cons '((font-family . roman) (font-shape . upright)
2239 (font-series . medium) (font-encoding . latin1))
2243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2247 (define-markup-command (doublesharp layout props)
2250 "Draw a double sharp symbol.
2252 @lilypond[verbatim,quote]
2257 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2259 (define-markup-command (sesquisharp layout props)
2262 "Draw a 3/2 sharp symbol.
2264 @lilypond[verbatim,quote]
2269 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2271 (define-markup-command (sharp layout props)
2274 "Draw a sharp symbol.
2276 @lilypond[verbatim,quote]
2281 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2283 (define-markup-command (semisharp layout props)
2286 "Draw a semisharp symbol.
2288 @lilypond[verbatim,quote]
2293 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2295 (define-markup-command (natural layout props)
2298 "Draw a natural symbol.
2300 @lilypond[verbatim,quote]
2305 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2307 (define-markup-command (semiflat layout props)
2310 "Draw a semiflat symbol.
2312 @lilypond[verbatim,quote]
2317 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2319 (define-markup-command (flat layout props)
2322 "Draw a flat symbol.
2324 @lilypond[verbatim,quote]
2329 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2331 (define-markup-command (sesquiflat layout props)
2334 "Draw a 3/2 flat symbol.
2336 @lilypond[verbatim,quote]
2341 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2343 (define-markup-command (doubleflat layout props)
2346 "Draw a double flat symbol.
2348 @lilypond[verbatim,quote]
2353 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2355 (define-markup-command (with-color layout props color arg)
2359 @cindex coloring text
2361 Draw @var{arg} in color specified by @var{color}.
2363 @lilypond[verbatim,quote]
2375 (let ((stil (interpret-markup layout props arg)))
2376 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2377 (ly:stencil-extent stil X)
2378 (ly:stencil-extent stil Y))))
2380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2384 (define-markup-command (arrow-head layout props axis dir filled)
2385 (integer? ly:dir? boolean?)
2387 "Produce an arrow head in specified direction and axis.
2388 Use the filled head if @var{filled} is specified.
2389 @lilypond[verbatim,quote]
2392 \\general-align #Y #DOWN {
2393 \\arrow-head #Y #UP ##t
2394 \\arrow-head #Y #DOWN ##f
2396 \\arrow-head #X #RIGHT ##f
2397 \\arrow-head #X #LEFT ##f
2403 ((name (format "arrowheads.~a.~a~a"
2410 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2414 (define-markup-command (musicglyph layout props glyph-name)
2417 "@var{glyph-name} is converted to a musical symbol; for example,
2418 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2419 the music font. See @ruser{The Feta font} for a complete listing of
2420 the possible glyphs.
2422 @lilypond[verbatim,quote]
2425 \\musicglyph #\"rests.2\"
2426 \\musicglyph #\"clefs.G_change\"
2429 (let* ((font (ly:paper-get-font layout
2430 (cons '((font-encoding . fetaMusic)
2434 (glyph (ly:font-get-glyph font glyph-name)))
2435 (if (null? (ly:stencil-expr glyph))
2436 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2441 (define-markup-command (lookup layout props glyph-name)
2444 "Lookup a glyph by name.
2446 @lilypond[verbatim,quote]
2448 \\override #'(font-encoding . fetaBraces) {
2449 \\lookup #\"brace200\"
2452 \\lookup #\"brace180\"
2456 (ly:font-get-glyph (ly:paper-get-font layout props)
2459 (define-markup-command (char layout props num)
2462 "Produce a single character. Characters encoded in hexadecimal
2463 format require the prefix @code{#x}.
2465 @lilypond[verbatim,quote]
2467 \\char #65 \\char ##x00a9
2470 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2472 (define number->mark-letter-vector (make-vector 25 #\A))
2477 (if (= i (- (char->integer #\I) (char->integer #\A)))
2479 (vector-set! number->mark-letter-vector j
2480 (integer->char (+ i (char->integer #\A)))))
2482 (define number->mark-alphabet-vector (list->vector
2483 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2485 (define (number->markletter-string vec n)
2486 "Double letters for big marks."
2487 (let* ((lst (vector-length vec)))
2490 (string-append (number->markletter-string vec (1- (quotient n lst)))
2491 (number->markletter-string vec (remainder n lst)))
2492 (make-string 1 (vector-ref vec n)))))
2494 (define-markup-command (markletter layout props num)
2497 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2498 (skipping letter@tie{}I), and continue with double letters.
2500 @lilypond[verbatim,quote]
2507 (ly:text-interface::interpret-markup layout props
2508 (number->markletter-string number->mark-letter-vector num)))
2510 (define-markup-command (markalphabet layout props num)
2513 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2514 and continue with double letters.
2516 @lilypond[verbatim,quote]
2523 (ly:text-interface::interpret-markup layout props
2524 (number->markletter-string number->mark-alphabet-vector num)))
2526 (define-public (horizontal-slash-interval num forward number-interval mag)
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))))
2531 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2532 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2533 (else (interval-widen number-interval (* mag 0.25))))
2536 (define-public (adjust-slash-stencil num forward stencil mag)
2539 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2541 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2543 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2545 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2548 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2550 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2555 (define (slashed-digit-internal layout props num forward font-size thickness)
2556 (let* ((mag (magstep font-size))
2558 (ly:output-def-lookup layout 'line-thickness)
2560 ; backward slashes might use slope and point in the other direction!
2561 (dy (* mag (if forward 0.4 -0.4)))
2562 (number-stencil (interpret-markup layout
2563 (prepend-alist-chain 'font-encoding 'fetaNumber props)
2564 (number->string num)))
2565 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2566 (center (interval-center (ly:stencil-extent number-stencil Y)))
2567 ; Use the real extents of the slash, not the whole number, because we
2568 ; might translate the slash later on!
2569 (num-y (interval-widen (cons center center) (abs dy)))
2570 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2571 (slash-stencil (if is-sane
2572 (make-line-stencil thickness
2573 (car num-x) (- (interval-center num-y) dy)
2574 (cdr num-x) (+ (interval-center num-y) dy))
2576 (if (ly:stencil? slash-stencil)
2578 ; for some numbers we need to shift the slash/backslash up or down to make
2579 ; the slashed digit look better
2580 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2581 (set! number-stencil
2582 (ly:stencil-add number-stencil slash-stencil)))
2583 (ly:warning "Unable to create slashed digit ~a" num))
2587 (define-markup-command (slashed-digit layout props num)
2590 #:properties ((font-size 0)
2593 @cindex slashed digits
2595 A feta number, with slash. This is for use in the context of
2596 figured bass notation.
2597 @lilypond[verbatim,quote]
2601 \\override #'(thickness . 3)
2605 (slashed-digit-internal layout props num #t font-size thickness))
2607 (define-markup-command (backslashed-digit layout props num)
2610 #:properties ((font-size 0)
2613 @cindex backslashed digits
2615 A feta number, with backslash. This is for use in the context of
2616 figured bass notation.
2617 @lilypond[verbatim,quote]
2619 \\backslashed-digit #5
2621 \\override #'(thickness . 3)
2622 \\backslashed-digit #7
2625 (slashed-digit-internal layout props num #f font-size thickness))
2628 (define eyeglassesps
2633 0.7 0.7 0.5 0 361 arc
2635 2.20 0.70 0.50 0 361 arc
2637 1.45 0.85 0.30 0 180 arc
2641 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2645 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2648 (define-markup-command (eyeglasses layout props)
2651 "Prints out eyeglasses, indicating strongly to look at the conductor.
2652 @lilypond[verbatim,quote]
2653 \\markup { \\eyeglasses }
2655 (interpret-markup layout props
2656 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2657 (make-postscript-markup eyeglassesps))))
2659 (define-markup-command (left-brace layout props size)
2663 A feta brace in point size @var{size}.
2665 @lilypond[verbatim,quote]
2672 (let* ((font (ly:paper-get-font layout
2673 (cons '((font-encoding . fetaBraces)
2676 (glyph-count (1- (ly:otf-glyph-count font)))
2677 (scale (ly:output-def-lookup layout 'output-scale))
2678 (scaled-size (/ (ly:pt size) scale))
2680 (ly:font-get-glyph font (string-append "brace"
2681 (number->string n)))))
2682 (get-y-from-brace (lambda (brace)
2684 (ly:stencil-extent (glyph brace) Y))))
2685 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2686 (glyph-found (glyph find-brace)))
2688 (if (or (null? (ly:stencil-expr glyph-found))
2689 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2690 (> scaled-size (interval-length
2691 (ly:stencil-extent (glyph glyph-count) Y))))
2693 (ly:warning (_ "no brace found for point size ~S ") size)
2694 (ly:warning (_ "defaulting to ~S pt")
2695 (/ (* scale (interval-length
2696 (ly:stencil-extent glyph-found Y)))
2700 (define-markup-command (right-brace layout props size)
2704 A feta brace in point size @var{size}, rotated 180 degrees.
2706 @lilypond[verbatim,quote]
2713 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2715 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2716 ;; the note command.
2717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2719 ;; TODO: better syntax.
2721 (define-markup-command (note-by-number layout props log dot-count dir)
2722 (number? number? number?)
2724 #:properties ((font-size 0)
2727 @cindex notes within text by log and dot-count
2729 Construct a note symbol, with stem. By using fractional values for
2730 @var{dir}, longer or shorter stems can be obtained.
2732 @lilypond[verbatim,quote]
2734 \\note-by-number #3 #0 #DOWN
2736 \\note-by-number #1 #2 #0.8
2739 (define (get-glyph-name-candidates dir log style)
2740 (map (lambda (dir-name)
2741 (format "noteheads.~a~a" dir-name
2742 (if (and (symbol? style)
2743 (not (equal? 'default style)))
2744 (select-head-glyph style (min log 2))
2746 (list (if (= dir UP) "u" "d")
2749 (define (get-glyph-name font cands)
2752 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2753 (get-glyph-name font (cdr cands))
2756 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2758 (size-factor (magstep font-size))
2759 (stem-length (* size-factor (max 3 (- log 1))))
2761 (let ((result (get-glyph-name font (get-glyph-name-candidates
2762 (sign dir) log style))))
2763 (if (string-null? result)
2764 ;; If no glyph name can be found, select default heads. Though
2765 ;; this usually means an unsupported style has been chosen, it
2766 ;; also prevents unrelated 'style settings from other grobs
2767 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2768 (get-glyph-name font (get-glyph-name-candidates
2769 (sign dir) log 'default))
2771 (head-glyph (ly:font-get-glyph font head-glyph-name))
2772 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2773 (stem-thickness (* size-factor 0.13))
2774 (stemy (* dir stem-length))
2775 (attach-off (cons (interval-index
2776 (ly:stencil-extent head-glyph X)
2777 (* (sign dir) (car attach-indices)))
2778 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2780 (ly:stencil-extent head-glyph Y)
2781 (cdr attach-indices)))))
2782 (stem-glyph (and (> log 0)
2783 (ly:round-filled-box
2784 (ordered-cons (car attach-off)
2786 (* (- (sign dir)) stem-thickness)))
2787 (cons (min stemy (cdr attach-off))
2788 (max stemy (cdr attach-off)))
2789 (/ stem-thickness 3))))
2791 (dot (ly:font-get-glyph font "dots.dot"))
2792 (dotwid (interval-length (ly:stencil-extent dot X)))
2793 (dots (and (> dot-count 0)
2794 (apply ly:stencil-add
2796 (ly:stencil-translate-axis
2797 dot (* 2 x dotwid) X))
2798 (iota dot-count)))))
2799 (flaggl (and (> log 2)
2800 (ly:stencil-translate
2801 (ly:font-get-glyph font
2802 (string-append "flags."
2803 (if (> dir 0) "u" "d")
2804 (number->string log)))
2805 (cons (+ (car attach-off) (if (< dir 0)
2809 ;; If there is a flag on an upstem and the stem is short, move the dots
2810 ;; to avoid the flag. 16th notes get a special case because their flags
2811 ;; hang lower than any other flags.
2812 (if (and dots (> dir 0) (> log 2)
2813 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2814 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2816 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2817 (if (ly:stencil? stem-glyph)
2818 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2819 (set! stem-glyph head-glyph))
2820 (if (ly:stencil? dots)
2823 (ly:stencil-translate-axis
2825 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2831 (let ((divisor (log 2)))
2832 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2834 (define (parse-simple-duration duration-string)
2835 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2836 and return a (log dots) list."
2837 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2839 (if (and match (string=? duration-string (match:substring match 0)))
2840 (let ((len (match:substring match 1))
2841 (dots (match:substring match 2)))
2842 (list (cond ((string=? len "breve") -1)
2843 ((string=? len "longa") -2)
2844 ((string=? len "maxima") -3)
2845 (else (log2 (string->number len))))
2846 (if dots (string-length dots) 0)))
2847 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2849 (define-markup-command (note layout props duration dir)
2852 #:properties (note-by-number-markup)
2854 @cindex notes within text by string
2856 This produces a note with a stem pointing in @var{dir} direction, with
2857 the @var{duration} for the note head type and augmentation dots. For
2858 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2859 a shortened down stem.
2861 @lilypond[verbatim,quote]
2863 \\override #'(style . cross) {
2867 \\note #\"breve\" #0
2870 (let ((parsed (parse-simple-duration duration)))
2871 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2873 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2877 (define-markup-command (lower layout props amount arg)
2881 @cindex lowering text
2883 Lower @var{arg} by the distance @var{amount}.
2884 A negative @var{amount} indicates raising; see also @code{\\raise}.
2886 @lilypond[verbatim,quote]
2894 (ly:stencil-translate-axis (interpret-markup layout props arg)
2897 (define-markup-command (translate-scaled layout props offset arg)
2898 (number-pair? markup?)
2900 #:properties ((font-size 0))
2902 @cindex translating text
2903 @cindex scaling text
2905 Translate @var{arg} by @var{offset}, scaling the offset by the
2908 @lilypond[verbatim,quote]
2911 * \\translate #'(2 . 3) translate
2913 * \\translate-scaled #'(2 . 3) translate-scaled
2917 (let* ((factor (magstep font-size))
2918 (scaled (cons (* factor (car offset))
2919 (* factor (cdr offset)))))
2920 (ly:stencil-translate (interpret-markup layout props arg)
2923 (define-markup-command (raise layout props amount arg)
2927 @cindex raising text
2929 Raise @var{arg} by the distance @var{amount}.
2930 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2932 The argument to @code{\\raise} is the vertical displacement amount,
2933 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2934 raise objects in relation to their surrounding markups.
2936 If the text object itself is positioned above or below the staff, then
2937 @code{\\raise} cannot be used to move it, since the mechanism that
2938 positions it next to the staff cancels any shift made with
2939 @code{\\raise}. For vertical positioning, use the @code{padding}
2940 and/or @code{extra-offset} properties.
2942 @lilypond[verbatim,quote]
2951 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2953 (define-markup-command (fraction layout props arg1 arg2)
2956 #:properties ((font-size 0))
2958 @cindex creating text fractions
2960 Make a fraction of two markups.
2961 @lilypond[verbatim,quote]
2967 (let* ((m1 (interpret-markup layout props arg1))
2968 (m2 (interpret-markup layout props arg2))
2969 (factor (magstep font-size))
2970 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2971 (padding (* factor 0.2))
2972 (baseline (* factor 0.6))
2973 (offset (* factor 0.75)))
2974 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2975 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2976 (let* ((x1 (ly:stencil-extent m1 X))
2977 (x2 (ly:stencil-extent m2 X))
2978 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2979 ;; should stack mols separately, to maintain LINE on baseline
2980 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2982 (ly:stencil-aligned-to stack Y CENTER))
2984 (ly:stencil-aligned-to stack X LEFT))
2985 ;; should have EX dimension
2987 (ly:stencil-translate-axis stack offset Y))))
2989 (define-markup-command (normal-size-super layout props arg)
2992 #:properties ((baseline-skip))
2994 @cindex setting superscript in standard font size
2996 Set @var{arg} in superscript with a normal font size.
2998 @lilypond[verbatim,quote]
3001 \\normal-size-super {
3002 superscript in standard size
3006 (ly:stencil-translate-axis
3007 (interpret-markup layout props arg)
3008 (* 0.5 baseline-skip) Y))
3010 (define-markup-command (super layout props arg)
3013 #:properties ((font-size 0)
3016 @cindex superscript text
3018 Set @var{arg} in superscript.
3020 @lilypond[verbatim,quote]
3030 (ly:stencil-translate-axis
3033 (cons `((font-size . ,(- font-size 3))) props)
3035 (* 0.5 baseline-skip)
3038 (define-markup-command (translate layout props offset arg)
3039 (number-pair? markup?)
3042 @cindex translating text
3044 Translate @var{arg} relative to its surroundings. @var{offset}
3045 is a pair of numbers representing the displacement in the X and Y axis.
3047 @lilypond[verbatim,quote]
3050 \\translate #'(2 . 3)
3051 \\line { translated two spaces right, three up }
3054 (ly:stencil-translate (interpret-markup layout props arg)
3057 (define-markup-command (sub layout props arg)
3060 #:properties ((font-size 0)
3063 @cindex subscript text
3065 Set @var{arg} in subscript.
3067 @lilypond[verbatim,quote]
3078 (ly:stencil-translate-axis
3081 (cons `((font-size . ,(- font-size 3))) props)
3083 (* -0.5 baseline-skip)
3086 (define-markup-command (normal-size-sub layout props arg)
3089 #:properties ((baseline-skip))
3091 @cindex setting subscript in standard font size
3093 Set @var{arg} in subscript with a normal font size.
3095 @lilypond[verbatim,quote]
3099 subscript in standard size
3103 (ly:stencil-translate-axis
3104 (interpret-markup layout props arg)
3105 (* -0.5 baseline-skip)
3108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3112 (define-markup-command (hbracket layout props arg)
3116 @cindex placing horizontal brackets around text
3118 Draw horizontal brackets around @var{arg}.
3120 @lilypond[verbatim,quote]
3129 (let ((th 0.1) ;; todo: take from GROB.
3130 (m (interpret-markup layout props arg)))
3131 (bracketify-stencil m X th (* 2.5 th) th)))
3133 (define-markup-command (bracket layout props arg)
3137 @cindex placing vertical brackets around text
3139 Draw vertical brackets around @var{arg}.
3141 @lilypond[verbatim,quote]
3148 (let ((th 0.1) ;; todo: take from GROB.
3149 (m (interpret-markup layout props arg)))
3150 (bracketify-stencil m Y th (* 2.5 th) th)))
3152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3153 ;; Delayed markup evaluation
3154 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3156 (define-markup-command (page-ref layout props label gauge default)
3157 (symbol? markup? markup?)
3160 @cindex referencing page numbers in text
3162 Reference to a page number. @var{label} is the label set on the referenced
3163 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3164 the maximum width of the page number, and @var{default} the value to display
3165 when @var{label} is not found."
3166 (let* ((gauge-stencil (interpret-markup layout props gauge))
3167 (x-ext (ly:stencil-extent gauge-stencil X))
3168 (y-ext (ly:stencil-extent gauge-stencil Y)))
3170 `(delay-stencil-evaluation
3171 ,(delay (ly:stencil-expr
3172 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3173 (page-number (if (list? table)
3174 (assoc-get label table)
3176 (page-markup (if page-number (format "~a" page-number) default))
3177 (page-stencil (interpret-markup layout props page-markup))
3178 (gap (- (interval-length x-ext)
3179 (interval-length (ly:stencil-extent page-stencil X)))))
3180 (interpret-markup layout props
3181 (markup #:concat (#:hspace gap page-markup)))))))
3185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3186 ;; Markup list commands
3187 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3189 (define-public (space-lines baseline stils)
3190 (let space-stil ((stils stils)
3194 (let* ((stil (car stils))
3195 (dy-top (max (- (/ baseline 1.5)
3196 (interval-bound (ly:stencil-extent stil Y) UP))
3198 (dy-bottom (max (+ (/ baseline 3.0)
3199 (interval-bound (ly:stencil-extent stil Y) DOWN))
3201 (new-stil (ly:make-stencil
3202 (ly:stencil-expr stil)
3203 (ly:stencil-extent stil X)
3204 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3206 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3208 (space-stil (cdr stils) (cons new-stil result))))))
3210 (define-markup-list-command (justified-lines layout props args)
3212 #:properties ((baseline-skip)
3213 wordwrap-internal-markup-list)
3215 @cindex justifying lines of text
3217 Like @code{\\justify}, but return a list of lines instead of a single markup.
3218 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3219 @var{X}@tie{}is the number of staff spaces."
3220 (space-lines baseline-skip
3221 (interpret-markup-list layout props
3222 (make-wordwrap-internal-markup-list #t args))))
3224 (define-markup-list-command (wordwrap-lines layout props args)
3226 #:properties ((baseline-skip)
3227 wordwrap-internal-markup-list)
3228 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3229 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3230 where @var{X} is the number of staff spaces."
3231 (space-lines baseline-skip
3232 (interpret-markup-list layout props
3233 (make-wordwrap-internal-markup-list #f args))))
3235 (define-markup-list-command (column-lines layout props args)
3237 #:properties ((baseline-skip))
3238 "Like @code{\\column}, but return a list of lines instead of a single markup.
3239 @code{baseline-skip} determines the space between each markup in @var{args}."
3240 (space-lines baseline-skip
3241 (interpret-markup-list layout props args)))
3243 (define-markup-list-command (override-lines layout props new-prop args)
3244 (pair? markup-list?)
3245 "Like @code{\\override}, for markup lists."
3246 (interpret-markup-list layout (cons (list new-prop) props) args))