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)
480 #:properties ((word-space))
482 @cindex creating horizontal spaces in text
484 Create an invisible object taking up horizontal space @var{amount}.
486 @lilypond[verbatim,quote]
495 (let ((corrected-space (- amount word-space)))
496 (if (> corrected-space 0)
497 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
498 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
500 ;; todo: fix negative space
501 (define-markup-command (vspace layout props amount)
505 @cindex creating vertical spaces in text
507 Create an invisible object taking up vertical space
508 of @var{amount} multiplied by 3.
510 @lilypond[verbatim,quote]
521 (let ((amount (* amount 3.0)))
523 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
524 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
528 ;; importing graphics.
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
531 (define-markup-command (stencil layout props stil)
535 @cindex importing stencils into text
537 Use a stencil as markup.
539 @lilypond[verbatim,quote]
541 \\stencil #(make-circle-stencil 2 0 #t)
547 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
549 (define (get-postscript-bbox string)
550 "Extract the bbox from STRING, or return #f if not present."
552 ((match (regexp-exec bbox-regexp string)))
556 (string->number (match:substring match x)))
561 (define-markup-command (epsfile layout props axis size file-name)
562 (number? number? string?)
565 @cindex inlining an Encapsulated PostScript image
567 Inline an EPS image. The image is scaled along @var{axis} to
570 @lilypond[verbatim,quote]
572 \\general-align #Y #DOWN {
573 \\epsfile #X #20 #\"context-example.eps\"
574 \\epsfile #Y #20 #\"context-example.eps\"
578 (if (ly:get-option 'safe)
579 (interpret-markup layout props "not allowed in safe")
580 (eps-file->stencil axis size file-name)
583 (define-markup-command (postscript layout props str)
587 @cindex inserting PostScript directly into text
588 This inserts @var{str} directly into the output as a PostScript
591 @lilypond[verbatim,quote]
595 0.4 0.6 0.5 0 361 arc
597 1.0 0.6 0.5 0 361 arc
602 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
603 \\postscript #ringsps
615 gsave currentpoint translate
623 (define-markup-command (score layout props score)
626 #:properties ((baseline-skip))
628 @cindex inserting music into text
630 Inline an image of music.
632 @lilypond[verbatim,quote]
636 \\new Staff \\relative c' {
639 \\mark \\markup { Allegro }
645 \\new Staff \\relative c {
659 \\override RehearsalMark #'break-align-symbols =
660 #'(time-signature key-signature)
661 \\override RehearsalMark #'self-alignment-X = #LEFT
665 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
671 (let ((output (ly:score-embedded-format score layout)))
673 (if (ly:music-output? output)
674 (stack-stencils Y DOWN baseline-skip
675 (map paper-system-stencil
677 (ly:paper-score-paper-systems output))))
679 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
682 (define-markup-command (null layout props)
686 @cindex creating empty text objects
688 An empty markup with extents of a single point.
690 @lilypond[verbatim,quote]
697 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
699 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
701 (define-markup-command (simple layout props str)
705 @cindex simple text strings
707 A simple text string; @code{\\markup @{ foo @}} is equivalent with
708 @code{\\markup @{ \\simple #\"foo\" @}}.
710 Note: for creating standard text markup or defining new markup commands,
711 the use of @code{\\simple} is unnecessary.
713 @lilypond[verbatim,quote]
717 \\simple #\"strings\"
720 (interpret-markup layout props str))
722 (define-markup-command (tied-lyric layout props str)
726 @cindex simple text strings with tie characters
728 Like simple-markup, but use tie characters for @q{~} tilde symbols.
730 @lilypond[verbatim,quote]
732 \\tied-lyric #\"Lasciate~i monti\"
735 (if (string-contains str "~")
737 ((parts (string-split str #\~))
738 (tie-str (ly:wide-char->utf-8 #x203f))
739 (joined (list-join parts tie-str))
740 (join-stencil (interpret-markup layout props tie-str))
743 (interpret-markup layout
746 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
748 (make-line-markup joined)))
749 ;(map (lambda (s) (interpret-markup layout props s)) parts))
750 (interpret-markup layout props str)))
752 (define-public empty-markup
753 (make-simple-markup ""))
755 ;; helper for justifying lines.
756 (define (get-fill-space word-count line-width text-widths)
757 "Calculate the necessary paddings between each two adjacent texts.
758 The lengths of all texts are stored in @var{text-widths}.
759 The normal formula for the padding between texts a and b is:
760 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
761 The first and last padding have to be calculated specially using the
762 whole length of the first or last text.
763 Return a list of paddings."
765 ((null? text-widths) '())
767 ;; special case first padding
768 ((= (length text-widths) word-count)
770 (- (- (/ line-width (1- word-count)) (car text-widths))
771 (/ (car (cdr text-widths)) 2))
772 (get-fill-space word-count line-width (cdr text-widths))))
773 ;; special case last padding
774 ((= (length text-widths) 2)
775 (list (- (/ line-width (1- word-count))
776 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
779 (- (/ line-width (1- word-count))
780 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
781 (get-fill-space word-count line-width (cdr text-widths))))))
783 (define-markup-command (fill-line layout props args)
786 #:properties ((text-direction RIGHT)
789 "Put @var{markups} in a horizontal line of width @var{line-width}.
790 The markups are spaced or flushed to fill the entire line.
791 If there are no arguments, return an empty stencil.
793 @lilypond[verbatim,quote]
797 Words evenly spaced across the page
801 \\line { Text markups }
803 \\italic { evenly spaced }
805 \\line { across the page }
810 (let* ((orig-stencils (interpret-markup-list layout props args))
813 (if (ly:stencil-empty? stc)
815 stc)) orig-stencils))
818 (if (ly:stencil-empty? stc)
820 (interval-length (ly:stencil-extent stc X))))
822 (text-width (apply + text-widths))
823 (word-count (length stencils))
824 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
829 (/ (- line-width text-width) 2)
830 (/ (- line-width text-width) 2)))
833 (- line-width text-width)))
835 (get-fill-space word-count line-width text-widths))))
843 (line-stencils (if (= word-count 1)
850 (if (= text-direction LEFT)
851 (set! line-stencils (reverse line-stencils)))
853 (if (null? (remove ly:stencil-empty? orig-stencils))
855 (ly:stencil-translate-axis
856 (stack-stencils-padding-list X
857 RIGHT fill-space-normal line-stencils)
858 (- (car (ly:stencil-extent (car stencils) X)))
861 (define-markup-command (line layout props args)
864 #:properties ((word-space)
865 (text-direction RIGHT))
866 "Put @var{args} in a horizontal line. The property @code{word-space}
867 determines the space between markups in @var{args}.
869 @lilypond[verbatim,quote]
876 (let ((stencils (interpret-markup-list layout props args)))
877 (if (= text-direction LEFT)
878 (set! stencils (reverse stencils)))
881 (remove ly:stencil-empty? stencils))))
883 (define-markup-command (concat layout props args)
887 @cindex concatenating text
888 @cindex ligatures in text
890 Concatenate @var{args} in a horizontal line, without spaces in between.
891 Strings and simple markups are concatenated on the input level, allowing
892 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
893 equivalent to @code{\"fi\"}.
895 @lilypond[verbatim,quote]
904 (define (concat-string-args arg-list)
905 (fold-right (lambda (arg result-list)
906 (let ((result (if (pair? result-list)
909 (if (and (pair? arg) (eqv? (car arg) simple-markup))
910 (set! arg (cadr arg)))
911 (if (and (string? result) (string? arg))
912 (cons (string-append arg result) (cdr result-list))
913 (cons arg result-list))))
917 (interpret-markup layout
918 (prepend-alist-chain 'word-space 0 props)
919 (make-line-markup (if (markup-command-list? args)
921 (concat-string-args args)))))
923 (define (wordwrap-stencils stencils
924 justify base-space line-width text-dir)
925 "Perform simple wordwrap, return stencil of each line."
926 (define space (if justify
927 ;; justify only stretches lines.
930 (define (take-list width space stencils
931 accumulator accumulated-width)
932 "Return (head-list . tail) pair, with head-list fitting into width"
934 (cons accumulator stencils)
935 (let* ((first (car stencils))
936 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
937 (newwid (+ space first-wid accumulated-width)))
938 (if (or (null? accumulator)
940 (take-list width space
942 (cons first accumulator)
944 (cons accumulator stencils)))))
945 (let loop ((lines '())
947 (let* ((line-break (take-list line-width space todo
949 (line-stencils (car line-break))
950 (space-left (- line-width
951 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
953 (line-word-space (cond ((not justify) space)
954 ;; don't stretch last line of paragraph.
955 ;; hmmm . bug - will overstretch the last line in some case.
956 ((null? (cdr line-break))
958 ((null? line-stencils) 0.0)
959 ((null? (cdr line-stencils)) 0.0)
960 (else (/ space-left (1- (length line-stencils))))))
961 (line (stack-stencil-line line-word-space
962 (if (= text-dir RIGHT)
963 (reverse line-stencils)
965 (if (pair? (cdr line-break))
966 (loop (cons line lines)
969 (if (= text-dir LEFT)
971 (ly:stencil-translate-axis
973 (- line-width (interval-end (ly:stencil-extent line X)))
975 (reverse (cons line lines)))))))
977 (define-markup-list-command (wordwrap-internal layout props justify args)
978 (boolean? markup-list?)
979 #:properties ((line-width #f)
981 (text-direction RIGHT))
982 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
983 (wordwrap-stencils (remove ly:stencil-empty?
984 (interpret-markup-list layout props args))
988 (ly:output-def-lookup layout 'line-width))
991 (define-markup-command (justify layout props args)
994 #:properties ((baseline-skip)
995 wordwrap-internal-markup-list)
997 @cindex justifying text
999 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1000 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1001 @var{X}@tie{}is the number of staff spaces.
1003 @lilypond[verbatim,quote]
1006 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1007 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1008 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1009 laboris nisi ut aliquip ex ea commodo consequat.
1013 (stack-lines DOWN 0.0 baseline-skip
1014 (wordwrap-internal-markup-list layout props #t args)))
1016 (define-markup-command (wordwrap layout props args)
1019 #:properties ((baseline-skip)
1020 wordwrap-internal-markup-list)
1021 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1022 the line width, where @var{X} is the number of staff spaces.
1024 @lilypond[verbatim,quote]
1027 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1028 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1029 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1030 laboris nisi ut aliquip ex ea commodo consequat.
1034 (stack-lines DOWN 0.0 baseline-skip
1035 (wordwrap-internal-markup-list layout props #f args)))
1037 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1039 #:properties ((line-width)
1041 (text-direction RIGHT))
1042 "Internal markup list command used to define @code{\\justify-string} and
1043 @code{\\wordwrap-string}."
1044 (let* ((para-strings (regexp-split
1045 (string-regexp-substitute
1047 (string-regexp-substitute "\r\n" "\n" arg))
1048 "\n[ \t\n]*\n[ \t\n]*"))
1049 (list-para-words (map (lambda (str)
1050 (regexp-split str "[ \t\n]+"))
1052 (para-lines (map (lambda (words)
1054 (remove ly:stencil-empty?
1056 (interpret-markup layout props x))
1058 (wordwrap-stencils stencils
1060 line-width text-direction)))
1062 (apply append para-lines)))
1064 (define-markup-command (wordwrap-string layout props arg)
1067 #:properties ((baseline-skip)
1068 wordwrap-string-internal-markup-list)
1069 "Wordwrap a string. Paragraphs may be separated with double newlines.
1071 @lilypond[verbatim,quote]
1073 \\override #'(line-width . 40)
1074 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1075 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1076 et dolore magna aliqua.
1079 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1080 laboris nisi ut aliquip ex ea commodo consequat.
1083 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1084 qui officia deserunt mollit anim id est laborum\"
1087 (stack-lines DOWN 0.0 baseline-skip
1088 (wordwrap-string-internal-markup-list layout props #f arg)))
1090 (define-markup-command (justify-string layout props arg)
1093 #:properties ((baseline-skip)
1094 wordwrap-string-internal-markup-list)
1095 "Justify a string. Paragraphs may be separated with double newlines
1097 @lilypond[verbatim,quote]
1099 \\override #'(line-width . 40)
1100 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1101 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1102 et dolore magna aliqua.
1105 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1106 laboris nisi ut aliquip ex ea commodo consequat.
1109 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1110 qui officia deserunt mollit anim id est laborum\"
1113 (stack-lines DOWN 0.0 baseline-skip
1114 (wordwrap-string-internal-markup-list layout props #t arg)))
1116 (define-markup-command (wordwrap-field layout props symbol)
1119 "Wordwrap the data which has been assigned to @var{symbol}.
1121 @lilypond[verbatim,quote]
1123 title = \"My title\"
1124 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1125 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1126 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1127 laboris nisi ut aliquip ex ea commodo consequat.\"
1131 bookTitleMarkup = \\markup {
1133 \\fill-line { \\fromproperty #'header:title }
1135 \\wordwrap-field #'header:myText
1144 (let* ((m (chain-assoc-get symbol props)))
1146 (wordwrap-string-markup layout props m)
1149 (define-markup-command (justify-field layout props symbol)
1152 "Justify the data which has been assigned to @var{symbol}.
1154 @lilypond[verbatim,quote]
1156 title = \"My title\"
1157 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1158 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1159 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1160 laboris nisi ut aliquip ex ea commodo consequat.\"
1164 bookTitleMarkup = \\markup {
1166 \\fill-line { \\fromproperty #'header:title }
1168 \\justify-field #'header:myText
1177 (let* ((m (chain-assoc-get symbol props)))
1179 (justify-string-markup layout props m)
1182 (define-markup-command (combine layout props arg1 arg2)
1186 @cindex merging text
1188 Print two markups on top of each other.
1190 Note: @code{\\combine} cannot take a list of markups enclosed in
1191 curly braces as an argument; the follow example will not compile:
1194 \\combine @{ a list @}
1197 @lilypond[verbatim,quote]
1200 \\override #'(thickness . 2)
1202 \\draw-line #'(0 . 4)
1203 \\arrow-head #Y #DOWN ##f
1206 (let* ((s1 (interpret-markup layout props arg1))
1207 (s2 (interpret-markup layout props arg2)))
1208 (ly:stencil-add s1 s2)))
1211 ;; TODO: should extract baseline-skip from each argument somehow..
1213 (define-markup-command (column layout props args)
1216 #:properties ((baseline-skip))
1218 @cindex stacking text in a column
1220 Stack the markups in @var{args} vertically. The property
1221 @code{baseline-skip} determines the space between markups
1224 @lilypond[verbatim,quote]
1233 (let ((arg-stencils (interpret-markup-list layout props args)))
1234 (stack-lines -1 0.0 baseline-skip
1235 (remove ly:stencil-empty? arg-stencils))))
1237 (define-markup-command (dir-column layout props args)
1240 #:properties ((direction)
1243 @cindex changing direction of text columns
1245 Make a column of @var{args}, going up or down, depending on the
1246 setting of the @code{direction} layout property.
1248 @lilypond[verbatim,quote]
1250 \\override #`(direction . ,UP) {
1260 \\override #'(direction . 1) {
1267 (stack-lines (if (number? direction) direction -1)
1270 (interpret-markup-list layout props args)))
1272 (define (general-column align-dir baseline mols)
1273 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1275 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1276 (stack-lines -1 0.0 baseline aligned-mols)))
1278 (define-markup-command (center-column layout props args)
1281 #:properties ((baseline-skip))
1283 @cindex centering a column of text
1285 Put @code{args} in a centered column.
1287 @lilypond[verbatim,quote]
1296 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1298 (define-markup-command (left-column layout props args)
1301 #:properties ((baseline-skip))
1303 @cindex text columns, left-aligned
1305 Put @code{args} in a left-aligned column.
1307 @lilypond[verbatim,quote]
1316 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1318 (define-markup-command (right-column layout props args)
1321 #:properties ((baseline-skip))
1323 @cindex text columns, right-aligned
1325 Put @code{args} in a right-aligned column.
1327 @lilypond[verbatim,quote]
1336 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1338 (define-markup-command (vcenter layout props arg)
1342 @cindex vertically centering text
1344 Align @code{arg} to its Y@tie{}center.
1346 @lilypond[verbatim,quote]
1354 (let* ((mol (interpret-markup layout props arg)))
1355 (ly:stencil-aligned-to mol Y CENTER)))
1357 (define-markup-command (center-align layout props arg)
1361 @cindex horizontally centering text
1363 Align @code{arg} to its X@tie{}center.
1365 @lilypond[verbatim,quote]
1375 (let* ((mol (interpret-markup layout props arg)))
1376 (ly:stencil-aligned-to mol X CENTER)))
1378 (define-markup-command (right-align layout props arg)
1382 @cindex right aligning text
1384 Align @var{arg} on its right edge.
1386 @lilypond[verbatim,quote]
1396 (let* ((m (interpret-markup layout props arg)))
1397 (ly:stencil-aligned-to m X RIGHT)))
1399 (define-markup-command (left-align layout props arg)
1403 @cindex left aligning text
1405 Align @var{arg} on its left edge.
1407 @lilypond[verbatim,quote]
1417 (let* ((m (interpret-markup layout props arg)))
1418 (ly:stencil-aligned-to m X LEFT)))
1420 (define-markup-command (general-align layout props axis dir arg)
1421 (integer? number? markup?)
1424 @cindex controlling general text alignment
1426 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1428 @lilypond[verbatim,quote]
1432 \\general-align #X #LEFT
1437 \\general-align #X #CENTER
1443 \\general-align #Y #UP
1450 \\general-align #Y #3.2
1457 (let* ((m (interpret-markup layout props arg)))
1458 (ly:stencil-aligned-to m axis dir)))
1460 (define-markup-command (halign layout props dir arg)
1464 @cindex setting horizontal text alignment
1466 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1467 left-aligned, while @code{+1} is right. Values in between interpolate
1468 alignment accordingly.
1470 @lilypond[verbatim,quote]
1495 (let* ((m (interpret-markup layout props arg)))
1496 (ly:stencil-aligned-to m X dir)))
1498 (define-markup-command (with-dimensions layout props x y arg)
1499 (number-pair? number-pair? markup?)
1502 @cindex setting extent of text objects
1504 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1505 (let* ((m (interpret-markup layout props arg)))
1506 (ly:make-stencil (ly:stencil-expr m) x y)))
1508 (define-markup-command (pad-around layout props amount arg)
1511 "Add padding @var{amount} all around @var{arg}.
1513 @lilypond[verbatim,quote]
1526 (let* ((m (interpret-markup layout props arg))
1527 (x (ly:stencil-extent m X))
1528 (y (ly:stencil-extent m Y)))
1529 (ly:make-stencil (ly:stencil-expr m)
1530 (interval-widen x amount)
1531 (interval-widen y amount))))
1533 (define-markup-command (pad-x layout props amount arg)
1537 @cindex padding text horizontally
1539 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1541 @lilypond[verbatim,quote]
1554 (let* ((m (interpret-markup layout props arg))
1555 (x (ly:stencil-extent m X))
1556 (y (ly:stencil-extent m Y)))
1557 (ly:make-stencil (ly:stencil-expr m)
1558 (interval-widen x amount)
1561 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1562 (integer? ly:dir? markup? markup?)
1564 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1565 (let ((m1 (interpret-markup layout props arg1))
1566 (m2 (interpret-markup layout props arg2)))
1567 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1569 (define-markup-command (transparent layout props arg)
1572 "Make @var{arg} transparent.
1574 @lilypond[verbatim,quote]
1581 (let* ((m (interpret-markup layout props arg))
1582 (x (ly:stencil-extent m X))
1583 (y (ly:stencil-extent m Y)))
1584 (ly:make-stencil "" x y)))
1586 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1587 (number-pair? number-pair? markup?)
1589 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1591 @lilypond[verbatim,quote]
1598 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1604 (let* ((m (interpret-markup layout props arg))
1605 (x (ly:stencil-extent m X))
1606 (y (ly:stencil-extent m Y)))
1607 (ly:make-stencil (ly:stencil-expr m)
1608 (interval-union x-ext x)
1609 (interval-union y-ext y))))
1611 (define-markup-command (hcenter-in layout props length arg)
1614 "Center @var{arg} horizontally within a box of extending
1615 @var{length}/2 to the left and right.
1617 @lilypond[quote,verbatim]
1620 \\set Staff.instrumentName = \\markup {
1627 \\set Staff.instrumentName = \\markup {
1636 (interpret-markup layout props
1637 (make-pad-to-box-markup
1638 (cons (/ length -2) (/ length 2))
1640 (make-center-align-markup arg))))
1642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1644 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1646 (define-markup-command (fromproperty layout props symbol)
1649 "Read the @var{symbol} from property settings, and produce a stencil
1650 from the markup contained within. If @var{symbol} is not defined, it
1651 returns an empty markup.
1653 @lilypond[verbatim,quote]
1655 myTitle = \"myTitle\"
1659 \\fromproperty #'header:myTitle
1666 (let ((m (chain-assoc-get symbol props)))
1668 (interpret-markup layout props m)
1671 (define-markup-command (on-the-fly layout props procedure arg)
1674 "Apply the @var{procedure} markup command to @var{arg}.
1675 @var{procedure} should take a single argument."
1676 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1677 (set-object-property! anonymous-with-signature
1680 (interpret-markup layout props (list anonymous-with-signature arg))))
1682 (define-markup-command (override layout props new-prop arg)
1686 @cindex overriding properties within text markup
1688 Add the argument @var{new-prop} to the property list. Properties
1689 may be any property supported by @rinternals{font-interface},
1690 @rinternals{text-interface} and
1691 @rinternals{instrument-specific-markup-interface}.
1693 @lilypond[verbatim,quote]
1701 \\override #'(baseline-skip . 4) {
1710 (interpret-markup layout (cons (list new-prop) props) arg))
1712 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1714 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1716 (define-markup-command (verbatim-file layout props name)
1719 "Read the contents of file @var{name}, and include it verbatim.
1721 @lilypond[verbatim,quote]
1723 \\verbatim-file #\"simple.ly\"
1726 (interpret-markup layout props
1727 (if (ly:get-option 'safe)
1728 "verbatim-file disabled in safe mode"
1729 (let* ((str (ly:gulp-file name))
1730 (lines (string-split str #\nl)))
1731 (make-typewriter-markup
1732 (make-column-markup lines))))))
1734 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1736 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1739 (define-markup-command (smaller layout props arg)
1742 "Decrease the font size relative to the current setting.
1744 @lilypond[verbatim,quote]
1757 (interpret-markup layout props
1758 `(,fontsize-markup -1 ,arg)))
1760 (define-markup-command (larger layout props arg)
1763 "Increase the font size relative to the current setting.
1765 @lilypond[verbatim,quote]
1773 (interpret-markup layout props
1774 `(,fontsize-markup 1 ,arg)))
1776 (define-markup-command (finger layout props arg)
1779 "Set @var{arg} as small numbers.
1781 @lilypond[verbatim,quote]
1788 (interpret-markup layout
1789 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1792 (define-markup-command (abs-fontsize layout props size arg)
1795 "Use @var{size} as the absolute font size to display @var{arg}.
1796 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1798 @lilypond[verbatim,quote]
1800 default text font size
1802 \\abs-fontsize #16 { text font size 16 }
1804 \\abs-fontsize #12 { text font size 12 }
1807 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1808 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1809 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1810 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1811 (magnification (/ size ref-size)))
1812 (interpret-markup layout
1813 (cons `((baseline-skip . ,(* magnification ref-baseline))
1814 (word-space . ,(* magnification ref-word-space))
1815 (font-size . ,(magnification->font-size magnification)))
1819 (define-markup-command (fontsize layout props increment arg)
1822 #:properties ((font-size 0)
1825 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1828 @lilypond[verbatim,quote]
1836 (let ((entries (list
1837 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1838 (cons 'word-space (* word-space (magstep increment)))
1839 (cons 'font-size (+ font-size increment)))))
1840 (interpret-markup layout (cons entries props) arg)))
1842 (define-markup-command (magnify layout props sz arg)
1846 @cindex magnifying text
1848 Set the font magnification for its argument. In the following
1849 example, the middle@tie{}A is 10% larger:
1852 A \\magnify #1.1 @{ A @} A
1855 Note: Magnification only works if a font name is explicitly selected.
1856 Use @code{\\fontsize} otherwise.
1858 @lilypond[verbatim,quote]
1869 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
1872 (define-markup-command (bold layout props arg)
1875 "Switch to bold font-series.
1877 @lilypond[verbatim,quote]
1885 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
1887 (define-markup-command (sans layout props arg)
1890 "Switch to the sans serif font family.
1892 @lilypond[verbatim,quote]
1901 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
1903 (define-markup-command (number layout props arg)
1906 "Set font family to @code{number}, which yields the font used for
1907 time signatures and fingerings. This font contains numbers and
1908 some punctuation; it has no letters.
1910 @lilypond[verbatim,quote]
1913 0 1 2 3 4 5 6 7 8 9 . ,
1917 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
1919 (define-markup-command (roman layout props arg)
1922 "Set font family to @code{roman}.
1924 @lilypond[verbatim,quote]
1930 text in roman font family
1937 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
1939 (define-markup-command (huge layout props arg)
1942 "Set font size to +2.
1944 @lilypond[verbatim,quote]
1952 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
1954 (define-markup-command (large layout props arg)
1957 "Set font size to +1.
1959 @lilypond[verbatim,quote]
1967 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
1969 (define-markup-command (normalsize layout props arg)
1972 "Set font size to default.
1974 @lilypond[verbatim,quote]
1987 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
1989 (define-markup-command (small layout props arg)
1992 "Set font size to -1.
1994 @lilypond[verbatim,quote]
2002 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2004 (define-markup-command (tiny layout props arg)
2007 "Set font size to -2.
2009 @lilypond[verbatim,quote]
2017 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2019 (define-markup-command (teeny layout props arg)
2022 "Set font size to -3.
2024 @lilypond[verbatim,quote]
2032 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2034 (define-markup-command (fontCaps layout props arg)
2037 "Set @code{font-shape} to @code{caps}
2039 Note: @code{\\fontCaps} requires the installation and selection of
2040 fonts which support the @code{caps} font shape."
2041 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2044 (define-markup-command (smallCaps layout props arg)
2047 "Emit @var{arg} as small caps.
2049 Note: @code{\\smallCaps} does not support accented characters.
2051 @lilypond[verbatim,quote]
2060 (define (char-list->markup chars lower)
2061 (let ((final-string (string-upcase (reverse-list->string chars))))
2063 (markup #:fontsize -2 final-string)
2065 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2066 (if (null? rest-chars)
2068 (reverse! (cons (char-list->markup currents current-is-lower)
2070 (let* ((ch (car rest-chars))
2071 (is-lower (char-lower-case? ch)))
2072 (if (or (and current-is-lower is-lower)
2073 (and (not current-is-lower) (not is-lower)))
2074 (make-small-caps (cdr rest-chars)
2078 (make-small-caps (cdr rest-chars)
2081 (if (null? currents)
2083 (cons (char-list->markup
2084 currents current-is-lower)
2086 (interpret-markup layout props
2088 (make-small-caps (string->list arg) (list) #f (list))
2091 (define-markup-command (caps layout props arg)
2094 "Copy of the @code{\\smallCaps} command.
2096 @lilypond[verbatim,quote]
2105 (interpret-markup layout props (make-smallCaps-markup arg)))
2107 (define-markup-command (dynamic layout props arg)
2110 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2111 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2112 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2113 done in a different font. The recommended font for this is bold and italic.
2114 @lilypond[verbatim,quote]
2122 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2124 (define-markup-command (text layout props arg)
2127 "Use a text font instead of music symbol or music alphabet font.
2129 @lilypond[verbatim,quote]
2142 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2145 (define-markup-command (italic layout props arg)
2148 "Use italic @code{font-shape} for @var{arg}.
2150 @lilypond[verbatim,quote]
2158 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2160 (define-markup-command (typewriter layout props arg)
2163 "Use @code{font-family} typewriter for @var{arg}.
2165 @lilypond[verbatim,quote]
2174 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2176 (define-markup-command (upright layout props arg)
2179 "Set @code{font-shape} to @code{upright}. This is the opposite
2182 @lilypond[verbatim,quote]
2196 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2198 (define-markup-command (medium layout props arg)
2201 "Switch to medium font-series (in contrast to bold).
2203 @lilypond[verbatim,quote]
2216 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2219 (define-markup-command (normal-text layout props arg)
2222 "Set all font related properties (except the size) to get the default
2223 normal text font, no matter what font was used earlier.
2225 @lilypond[verbatim,quote]
2227 \\huge \\bold \\sans \\caps {
2228 Some text with font overrides
2231 Default text, same font-size
2239 (interpret-markup layout
2240 (cons '((font-family . roman) (font-shape . upright)
2241 (font-series . medium) (font-encoding . latin1))
2245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2249 (define-markup-command (doublesharp layout props)
2252 "Draw a double sharp symbol.
2254 @lilypond[verbatim,quote]
2259 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2261 (define-markup-command (sesquisharp layout props)
2264 "Draw a 3/2 sharp symbol.
2266 @lilypond[verbatim,quote]
2271 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2273 (define-markup-command (sharp layout props)
2276 "Draw a sharp symbol.
2278 @lilypond[verbatim,quote]
2283 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2285 (define-markup-command (semisharp layout props)
2288 "Draw a semisharp symbol.
2290 @lilypond[verbatim,quote]
2295 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2297 (define-markup-command (natural layout props)
2300 "Draw a natural symbol.
2302 @lilypond[verbatim,quote]
2307 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2309 (define-markup-command (semiflat layout props)
2312 "Draw a semiflat symbol.
2314 @lilypond[verbatim,quote]
2319 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2321 (define-markup-command (flat layout props)
2324 "Draw a flat symbol.
2326 @lilypond[verbatim,quote]
2331 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2333 (define-markup-command (sesquiflat layout props)
2336 "Draw a 3/2 flat symbol.
2338 @lilypond[verbatim,quote]
2343 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2345 (define-markup-command (doubleflat layout props)
2348 "Draw a double flat symbol.
2350 @lilypond[verbatim,quote]
2355 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2357 (define-markup-command (with-color layout props color arg)
2361 @cindex coloring text
2363 Draw @var{arg} in color specified by @var{color}.
2365 @lilypond[verbatim,quote]
2377 (let ((stil (interpret-markup layout props arg)))
2378 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2379 (ly:stencil-extent stil X)
2380 (ly:stencil-extent stil Y))))
2382 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2386 (define-markup-command (arrow-head layout props axis dir filled)
2387 (integer? ly:dir? boolean?)
2389 "Produce an arrow head in specified direction and axis.
2390 Use the filled head if @var{filled} is specified.
2391 @lilypond[verbatim,quote]
2394 \\general-align #Y #DOWN {
2395 \\arrow-head #Y #UP ##t
2396 \\arrow-head #Y #DOWN ##f
2398 \\arrow-head #X #RIGHT ##f
2399 \\arrow-head #X #LEFT ##f
2405 ((name (format "arrowheads.~a.~a~a"
2412 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2416 (define-markup-command (musicglyph layout props glyph-name)
2419 "@var{glyph-name} is converted to a musical symbol; for example,
2420 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2421 the music font. See @ruser{The Feta font} for a complete listing of
2422 the possible glyphs.
2424 @lilypond[verbatim,quote]
2427 \\musicglyph #\"rests.2\"
2428 \\musicglyph #\"clefs.G_change\"
2431 (let* ((font (ly:paper-get-font layout
2432 (cons '((font-encoding . fetaMusic)
2436 (glyph (ly:font-get-glyph font glyph-name)))
2437 (if (null? (ly:stencil-expr glyph))
2438 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2443 (define-markup-command (lookup layout props glyph-name)
2446 "Lookup a glyph by name.
2448 @lilypond[verbatim,quote]
2450 \\override #'(font-encoding . fetaBraces) {
2451 \\lookup #\"brace200\"
2454 \\lookup #\"brace180\"
2458 (ly:font-get-glyph (ly:paper-get-font layout props)
2461 (define-markup-command (char layout props num)
2464 "Produce a single character. Characters encoded in hexadecimal
2465 format require the prefix @code{#x}.
2467 @lilypond[verbatim,quote]
2469 \\char #65 \\char ##x00a9
2472 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2474 (define number->mark-letter-vector (make-vector 25 #\A))
2479 (if (= i (- (char->integer #\I) (char->integer #\A)))
2481 (vector-set! number->mark-letter-vector j
2482 (integer->char (+ i (char->integer #\A)))))
2484 (define number->mark-alphabet-vector (list->vector
2485 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2487 (define (number->markletter-string vec n)
2488 "Double letters for big marks."
2489 (let* ((lst (vector-length vec)))
2492 (string-append (number->markletter-string vec (1- (quotient n lst)))
2493 (number->markletter-string vec (remainder n lst)))
2494 (make-string 1 (vector-ref vec n)))))
2496 (define-markup-command (markletter layout props num)
2499 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2500 (skipping letter@tie{}I), and continue with double letters.
2502 @lilypond[verbatim,quote]
2509 (ly:text-interface::interpret-markup layout props
2510 (number->markletter-string number->mark-letter-vector num)))
2512 (define-markup-command (markalphabet layout props num)
2515 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2516 and continue with double letters.
2518 @lilypond[verbatim,quote]
2525 (ly:text-interface::interpret-markup layout props
2526 (number->markletter-string number->mark-alphabet-vector num)))
2528 (define-public (horizontal-slash-interval num forward number-interval mag)
2530 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2531 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2532 (else (interval-widen number-interval (* mag 0.25))))
2533 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2534 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2535 (else (interval-widen number-interval (* mag 0.25))))
2538 (define-public (adjust-slash-stencil num forward stencil mag)
2541 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2543 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2545 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2547 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2550 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2552 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2557 (define (slashed-digit-internal layout props num forward font-size thickness)
2558 (let* ((mag (magstep font-size))
2560 (ly:output-def-lookup layout 'line-thickness)
2562 ; backward slashes might use slope and point in the other direction!
2563 (dy (* mag (if forward 0.4 -0.4)))
2564 (number-stencil (interpret-markup layout
2565 (prepend-alist-chain 'font-encoding 'fetaText props)
2566 (number->string num)))
2567 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2568 (center (interval-center (ly:stencil-extent number-stencil Y)))
2569 ; Use the real extents of the slash, not the whole number, because we
2570 ; might translate the slash later on!
2571 (num-y (interval-widen (cons center center) (abs dy)))
2572 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2573 (slash-stencil (if is-sane
2574 (make-line-stencil thickness
2575 (car num-x) (- (interval-center num-y) dy)
2576 (cdr num-x) (+ (interval-center num-y) dy))
2578 (if (ly:stencil? slash-stencil)
2580 ; for some numbers we need to shift the slash/backslash up or down to make
2581 ; the slashed digit look better
2582 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2583 (set! number-stencil
2584 (ly:stencil-add number-stencil slash-stencil)))
2585 (ly:warning "Unable to create slashed digit ~a" num))
2589 (define-markup-command (slashed-digit layout props num)
2592 #:properties ((font-size 0)
2595 @cindex slashed digits
2597 A feta number, with slash. This is for use in the context of
2598 figured bass notation.
2599 @lilypond[verbatim,quote]
2603 \\override #'(thickness . 3)
2607 (slashed-digit-internal layout props num #t font-size thickness))
2609 (define-markup-command (backslashed-digit layout props num)
2612 #:properties ((font-size 0)
2615 @cindex backslashed digits
2617 A feta number, with backslash. This is for use in the context of
2618 figured bass notation.
2619 @lilypond[verbatim,quote]
2621 \\backslashed-digit #5
2623 \\override #'(thickness . 3)
2624 \\backslashed-digit #7
2627 (slashed-digit-internal layout props num #f font-size thickness))
2630 (define eyeglassesps
2635 0.7 0.7 0.5 0 361 arc
2637 2.20 0.70 0.50 0 361 arc
2639 1.45 0.85 0.30 0 180 arc
2643 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2647 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2650 (define-markup-command (eyeglasses layout props)
2653 "Prints out eyeglasses, indicating strongly to look at the conductor.
2654 @lilypond[verbatim,quote]
2655 \\markup { \\eyeglasses }
2657 (interpret-markup layout props
2658 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2659 (make-postscript-markup eyeglassesps))))
2661 (define-markup-command (left-brace layout props size)
2665 A feta brace in point size @var{size}.
2667 @lilypond[verbatim,quote]
2674 (let* ((font (ly:paper-get-font layout
2675 (cons '((font-encoding . fetaBraces)
2678 (glyph-count (1- (ly:otf-glyph-count font)))
2679 (scale (ly:output-def-lookup layout 'output-scale))
2680 (scaled-size (/ (ly:pt size) scale))
2682 (ly:font-get-glyph font (string-append "brace"
2683 (number->string n)))))
2684 (get-y-from-brace (lambda (brace)
2686 (ly:stencil-extent (glyph brace) Y))))
2687 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2688 (glyph-found (glyph find-brace)))
2690 (if (or (null? (ly:stencil-expr glyph-found))
2691 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2692 (> scaled-size (interval-length
2693 (ly:stencil-extent (glyph glyph-count) Y))))
2695 (ly:warning (_ "no brace found for point size ~S ") size)
2696 (ly:warning (_ "defaulting to ~S pt")
2697 (/ (* scale (interval-length
2698 (ly:stencil-extent glyph-found Y)))
2702 (define-markup-command (right-brace layout props size)
2706 A feta brace in point size @var{size}, rotated 180 degrees.
2708 @lilypond[verbatim,quote]
2715 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2718 ;; the note command.
2719 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2721 ;; TODO: better syntax.
2723 (define-markup-command (note-by-number layout props log dot-count dir)
2724 (number? number? number?)
2726 #:properties ((font-size 0)
2729 @cindex notes within text by log and dot-count
2731 Construct a note symbol, with stem. By using fractional values for
2732 @var{dir}, longer or shorter stems can be obtained.
2734 @lilypond[verbatim,quote]
2736 \\note-by-number #3 #0 #DOWN
2738 \\note-by-number #1 #2 #0.8
2741 (define (get-glyph-name-candidates dir log style)
2742 (map (lambda (dir-name)
2743 (format "noteheads.~a~a" dir-name
2744 (if (and (symbol? style)
2745 (not (equal? 'default style)))
2746 (select-head-glyph style (min log 2))
2748 (list (if (= dir UP) "u" "d")
2751 (define (get-glyph-name font cands)
2754 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2755 (get-glyph-name font (cdr cands))
2758 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2760 (size-factor (magstep font-size))
2761 (stem-length (* size-factor (max 3 (- log 1))))
2763 (let ((result (get-glyph-name font (get-glyph-name-candidates
2764 (sign dir) log style))))
2765 (if (string-null? result)
2766 ;; If no glyph name can be found, select default heads. Though
2767 ;; this usually means an unsupported style has been chosen, it
2768 ;; also prevents unrelated 'style settings from other grobs
2769 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2770 (get-glyph-name font (get-glyph-name-candidates
2771 (sign dir) log 'default))
2773 (head-glyph (ly:font-get-glyph font head-glyph-name))
2774 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2775 (stem-thickness (* size-factor 0.13))
2776 (stemy (* dir stem-length))
2777 (attach-off (cons (interval-index
2778 (ly:stencil-extent head-glyph X)
2779 (* (sign dir) (car attach-indices)))
2780 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2782 (ly:stencil-extent head-glyph Y)
2783 (cdr attach-indices)))))
2784 (stem-glyph (and (> log 0)
2785 (ly:round-filled-box
2786 (ordered-cons (car attach-off)
2788 (* (- (sign dir)) stem-thickness)))
2789 (cons (min stemy (cdr attach-off))
2790 (max stemy (cdr attach-off)))
2791 (/ stem-thickness 3))))
2793 (dot (ly:font-get-glyph font "dots.dot"))
2794 (dotwid (interval-length (ly:stencil-extent dot X)))
2795 (dots (and (> dot-count 0)
2796 (apply ly:stencil-add
2798 (ly:stencil-translate-axis
2799 dot (* 2 x dotwid) X))
2800 (iota dot-count)))))
2801 (flaggl (and (> log 2)
2802 (ly:stencil-translate
2803 (ly:font-get-glyph font
2804 (string-append "flags."
2805 (if (> dir 0) "u" "d")
2806 (number->string log)))
2807 (cons (+ (car attach-off) (if (< dir 0)
2811 ;; If there is a flag on an upstem and the stem is short, move the dots
2812 ;; to avoid the flag. 16th notes get a special case because their flags
2813 ;; hang lower than any other flags.
2814 (if (and dots (> dir 0) (> log 2)
2815 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2816 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2818 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2819 (if (ly:stencil? stem-glyph)
2820 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2821 (set! stem-glyph head-glyph))
2822 (if (ly:stencil? dots)
2825 (ly:stencil-translate-axis
2827 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2833 (let ((divisor (log 2)))
2834 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2836 (define (parse-simple-duration duration-string)
2837 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2838 and return a (log dots) list."
2839 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2841 (if (and match (string=? duration-string (match:substring match 0)))
2842 (let ((len (match:substring match 1))
2843 (dots (match:substring match 2)))
2844 (list (cond ((string=? len "breve") -1)
2845 ((string=? len "longa") -2)
2846 ((string=? len "maxima") -3)
2847 (else (log2 (string->number len))))
2848 (if dots (string-length dots) 0)))
2849 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2851 (define-markup-command (note layout props duration dir)
2854 #:properties (note-by-number-markup)
2856 @cindex notes within text by string
2858 This produces a note with a stem pointing in @var{dir} direction, with
2859 the @var{duration} for the note head type and augmentation dots. For
2860 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2861 a shortened down stem.
2863 @lilypond[verbatim,quote]
2865 \\override #'(style . cross) {
2869 \\note #\"breve\" #0
2872 (let ((parsed (parse-simple-duration duration)))
2873 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
2875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2879 (define-markup-command (lower layout props amount arg)
2883 @cindex lowering text
2885 Lower @var{arg} by the distance @var{amount}.
2886 A negative @var{amount} indicates raising; see also @code{\\raise}.
2888 @lilypond[verbatim,quote]
2896 (ly:stencil-translate-axis (interpret-markup layout props arg)
2899 (define-markup-command (translate-scaled layout props offset arg)
2900 (number-pair? markup?)
2902 #:properties ((font-size 0))
2904 @cindex translating text
2905 @cindex scaling text
2907 Translate @var{arg} by @var{offset}, scaling the offset by the
2910 @lilypond[verbatim,quote]
2913 * \\translate #'(2 . 3) translate
2915 * \\translate-scaled #'(2 . 3) translate-scaled
2919 (let* ((factor (magstep font-size))
2920 (scaled (cons (* factor (car offset))
2921 (* factor (cdr offset)))))
2922 (ly:stencil-translate (interpret-markup layout props arg)
2925 (define-markup-command (raise layout props amount arg)
2929 @cindex raising text
2931 Raise @var{arg} by the distance @var{amount}.
2932 A negative @var{amount} indicates lowering, see also @code{\\lower}.
2934 The argument to @code{\\raise} is the vertical displacement amount,
2935 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
2936 raise objects in relation to their surrounding markups.
2938 If the text object itself is positioned above or below the staff, then
2939 @code{\\raise} cannot be used to move it, since the mechanism that
2940 positions it next to the staff cancels any shift made with
2941 @code{\\raise}. For vertical positioning, use the @code{padding}
2942 and/or @code{extra-offset} properties.
2944 @lilypond[verbatim,quote]
2953 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
2955 (define-markup-command (fraction layout props arg1 arg2)
2958 #:properties ((font-size 0))
2960 @cindex creating text fractions
2962 Make a fraction of two markups.
2963 @lilypond[verbatim,quote]
2969 (let* ((m1 (interpret-markup layout props arg1))
2970 (m2 (interpret-markup layout props arg2))
2971 (factor (magstep font-size))
2972 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
2973 (padding (* factor 0.2))
2974 (baseline (* factor 0.6))
2975 (offset (* factor 0.75)))
2976 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
2977 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
2978 (let* ((x1 (ly:stencil-extent m1 X))
2979 (x2 (ly:stencil-extent m2 X))
2980 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
2981 ;; should stack mols separately, to maintain LINE on baseline
2982 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
2984 (ly:stencil-aligned-to stack Y CENTER))
2986 (ly:stencil-aligned-to stack X LEFT))
2987 ;; should have EX dimension
2989 (ly:stencil-translate-axis stack offset Y))))
2991 (define-markup-command (normal-size-super layout props arg)
2994 #:properties ((baseline-skip))
2996 @cindex setting superscript in standard font size
2998 Set @var{arg} in superscript with a normal font size.
3000 @lilypond[verbatim,quote]
3003 \\normal-size-super {
3004 superscript in standard size
3008 (ly:stencil-translate-axis
3009 (interpret-markup layout props arg)
3010 (* 0.5 baseline-skip) Y))
3012 (define-markup-command (super layout props arg)
3015 #:properties ((font-size 0)
3018 @cindex superscript text
3020 Set @var{arg} in superscript.
3022 @lilypond[verbatim,quote]
3032 (ly:stencil-translate-axis
3035 (cons `((font-size . ,(- font-size 3))) props)
3037 (* 0.5 baseline-skip)
3040 (define-markup-command (translate layout props offset arg)
3041 (number-pair? markup?)
3044 @cindex translating text
3046 Translate @var{arg} relative to its surroundings. @var{offset}
3047 is a pair of numbers representing the displacement in the X and Y axis.
3049 @lilypond[verbatim,quote]
3052 \\translate #'(2 . 3)
3053 \\line { translated two spaces right, three up }
3056 (ly:stencil-translate (interpret-markup layout props arg)
3059 (define-markup-command (sub layout props arg)
3062 #:properties ((font-size 0)
3065 @cindex subscript text
3067 Set @var{arg} in subscript.
3069 @lilypond[verbatim,quote]
3080 (ly:stencil-translate-axis
3083 (cons `((font-size . ,(- font-size 3))) props)
3085 (* -0.5 baseline-skip)
3088 (define-markup-command (normal-size-sub layout props arg)
3091 #:properties ((baseline-skip))
3093 @cindex setting subscript in standard font size
3095 Set @var{arg} in subscript with a normal font size.
3097 @lilypond[verbatim,quote]
3101 subscript in standard size
3105 (ly:stencil-translate-axis
3106 (interpret-markup layout props arg)
3107 (* -0.5 baseline-skip)
3110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3114 (define-markup-command (hbracket layout props arg)
3118 @cindex placing horizontal brackets around text
3120 Draw horizontal brackets around @var{arg}.
3122 @lilypond[verbatim,quote]
3131 (let ((th 0.1) ;; todo: take from GROB.
3132 (m (interpret-markup layout props arg)))
3133 (bracketify-stencil m X th (* 2.5 th) th)))
3135 (define-markup-command (bracket layout props arg)
3139 @cindex placing vertical brackets around text
3141 Draw vertical brackets around @var{arg}.
3143 @lilypond[verbatim,quote]
3150 (let ((th 0.1) ;; todo: take from GROB.
3151 (m (interpret-markup layout props arg)))
3152 (bracketify-stencil m Y th (* 2.5 th) th)))
3154 (define-markup-command (parenthesize layout props arg)
3157 #:properties ((angularity 0)
3163 @cindex placing parentheses around text
3165 Draw parentheses around @var{arg}. This is useful for parenthesizing
3166 a column containing several lines of text.
3168 @lilypond[verbatim,quote]
3177 \\override #'(angularity . 2) {
3188 (let* ((markup (interpret-markup layout props arg))
3189 (scaled-width (* size width))
3191 (* (chain-assoc-get 'line-thickness props 0.1)
3194 (min (* size 0.5 scaled-thickness)
3195 (* (/ 4 3.0) scaled-width)))
3196 (padding (chain-assoc-get 'padding props half-thickness)))
3197 (parenthesize-stencil
3198 markup half-thickness scaled-width angularity padding)))
3201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3202 ;; Delayed markup evaluation
3203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3205 (define-markup-command (page-ref layout props label gauge default)
3206 (symbol? markup? markup?)
3209 @cindex referencing page numbers in text
3211 Reference to a page number. @var{label} is the label set on the referenced
3212 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3213 the maximum width of the page number, and @var{default} the value to display
3214 when @var{label} is not found."
3215 (let* ((gauge-stencil (interpret-markup layout props gauge))
3216 (x-ext (ly:stencil-extent gauge-stencil X))
3217 (y-ext (ly:stencil-extent gauge-stencil Y)))
3219 `(delay-stencil-evaluation
3220 ,(delay (ly:stencil-expr
3221 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3222 (page-number (if (list? table)
3223 (assoc-get label table)
3225 (page-markup (if page-number (format "~a" page-number) default))
3226 (page-stencil (interpret-markup layout props page-markup))
3227 (gap (- (interval-length x-ext)
3228 (interval-length (ly:stencil-extent page-stencil X)))))
3229 (interpret-markup layout props
3230 (markup #:concat (#:hspace gap page-markup)))))))
3234 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3235 ;; Markup list commands
3236 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3238 (define-public (space-lines baseline stils)
3239 (let space-stil ((stils stils)
3243 (let* ((stil (car stils))
3244 (dy-top (max (- (/ baseline 1.5)
3245 (interval-bound (ly:stencil-extent stil Y) UP))
3247 (dy-bottom (max (+ (/ baseline 3.0)
3248 (interval-bound (ly:stencil-extent stil Y) DOWN))
3250 (new-stil (ly:make-stencil
3251 (ly:stencil-expr stil)
3252 (ly:stencil-extent stil X)
3253 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3255 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3257 (space-stil (cdr stils) (cons new-stil result))))))
3259 (define-markup-list-command (justified-lines layout props args)
3261 #:properties ((baseline-skip)
3262 wordwrap-internal-markup-list)
3264 @cindex justifying lines of text
3266 Like @code{\\justify}, but return a list of lines instead of a single markup.
3267 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3268 @var{X}@tie{}is the number of staff spaces."
3269 (space-lines baseline-skip
3270 (interpret-markup-list layout props
3271 (make-wordwrap-internal-markup-list #t args))))
3273 (define-markup-list-command (wordwrap-lines layout props args)
3275 #:properties ((baseline-skip)
3276 wordwrap-internal-markup-list)
3277 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3278 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3279 where @var{X} is the number of staff spaces."
3280 (space-lines baseline-skip
3281 (interpret-markup-list layout props
3282 (make-wordwrap-internal-markup-list #f args))))
3284 (define-markup-list-command (column-lines layout props args)
3286 #:properties ((baseline-skip))
3287 "Like @code{\\column}, but return a list of lines instead of a single markup.
3288 @code{baseline-skip} determines the space between each markup in @var{args}."
3289 (space-lines baseline-skip
3290 (interpret-markup-list layout props args)))
3292 (define-markup-list-command (override-lines layout props new-prop args)
3293 (pair? markup-list?)
3294 "Like @code{\\override}, for markup lists."
3295 (interpret-markup-list layout (cons (list new-prop) props) args))