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) (offset 2))
282 @cindex underlining text
284 Underline @var{arg}. Looks at @code{thickness} to determine line
285 thickness, and @code{offset} to determine line y-offset.
287 @lilypond[verbatim,quote]
288 \\markup \\fill-line {
289 \\underline \"underlined\"
290 \\override #'(offset . 5)
291 \\override #'(thickness . 1)
292 \\underline \"underlined\"
293 \\override #'(offset . 1)
294 \\override #'(thickness . 5)
295 \\underline \"underlined\"
298 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
299 (underline-thick (* thickness thick))
300 (markup (interpret-markup layout props arg))
301 (x1 (car (ly:stencil-extent markup X)))
302 (x2 (cdr (ly:stencil-extent markup X)))
303 (y (* thick (- offset)))
304 (line (make-line-stencil underline-thick x1 y x2 y)))
305 (ly:stencil-add markup line)))
307 (define-markup-command (box layout props arg)
310 #:properties ((thickness 1)
314 @cindex enclosing text within a box
316 Draw a box round @var{arg}. Looks at @code{thickness},
317 @code{box-padding} and @code{font-size} properties to determine line
318 thickness and padding around the markup.
320 @lilypond[verbatim,quote]
322 \\override #'(box-padding . 0.5)
327 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
329 (pad (* (magstep font-size) box-padding))
330 (m (interpret-markup layout props arg)))
331 (box-stencil m th pad)))
333 (define-markup-command (filled-box layout props xext yext blot)
334 (number-pair? number-pair? number?)
337 @cindex drawing solid boxes within text
338 @cindex drawing boxes with rounded corners
340 Draw a box with rounded corners of dimensions @var{xext} and
341 @var{yext}. For example,
343 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
345 creates a box extending horizontally from -0.3 to 1.8 and
346 vertically from -0.3 up to 1.8, with corners formed from a
347 circle of diameter@tie{}0 (i.e., sharp corners).
349 @lilypond[verbatim,quote]
351 \\filled-box #'(0 . 4) #'(0 . 4) #0
352 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
353 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
355 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
361 (define-markup-command (rounded-box layout props arg)
364 #:properties ((thickness 1)
368 "@cindex enclosing text in a box with rounded corners
369 @cindex drawing boxes with rounded corners around text
370 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
371 @code{box-padding} and @code{font-size} properties to determine line
372 thickness and padding around the markup; the @code{corner-radius} property
373 makes it possible to define another shape for the corners (default is 1).
375 @lilypond[quote,verbatim,relative=2]
383 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
385 (pad (* (magstep font-size) box-padding))
386 (m (interpret-markup layout props arg)))
387 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
390 (define-markup-command (rotate layout props ang arg)
394 @cindex rotating text
396 Rotate object with @var{ang} degrees around its center.
398 @lilypond[verbatim,quote]
408 (let* ((stil (interpret-markup layout props arg)))
409 (ly:stencil-rotate stil ang 0 0)))
411 (define-markup-command (whiteout layout props arg)
415 @cindex adding a white background to text
417 Provide a white background for @var{arg}.
419 @lilypond[verbatim,quote]
422 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
426 (stencil-whiteout (interpret-markup layout props arg)))
428 (define-markup-command (pad-markup layout props amount arg)
433 @cindex putting space around text
435 Add space around a markup object.
437 @lilypond[verbatim,quote]
451 ((stil (interpret-markup layout props arg))
452 (xext (ly:stencil-extent stil X))
453 (yext (ly:stencil-extent stil Y)))
456 (ly:stencil-expr stil)
457 (interval-widen xext amount)
458 (interval-widen yext amount))))
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
464 (define-markup-command (strut layout props)
468 @cindex creating vertical spaces in text
470 Create a box of the same height as the space in the current font."
471 (let ((m (ly:text-interface::interpret-markup layout props " ")))
472 (ly:make-stencil (ly:stencil-expr m)
474 (ly:stencil-extent m X)
477 ;; todo: fix negative space
478 (define-markup-command (hspace layout props amount)
481 #:properties ((word-space))
483 @cindex creating horizontal spaces in text
485 Create an invisible object taking up horizontal space @var{amount}.
487 @lilypond[verbatim,quote]
496 (let ((corrected-space (- amount word-space)))
497 (if (> corrected-space 0)
498 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
499 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
501 ;; todo: fix negative space
502 (define-markup-command (vspace layout props amount)
506 @cindex creating vertical spaces in text
508 Create an invisible object taking up vertical space
509 of @var{amount} multiplied by 3.
511 @lilypond[verbatim,quote]
522 (let ((amount (* amount 3.0)))
524 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
525 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
529 ;; importing graphics.
530 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
532 (define-markup-command (stencil layout props stil)
536 @cindex importing stencils into text
538 Use a stencil as markup.
540 @lilypond[verbatim,quote]
542 \\stencil #(make-circle-stencil 2 0 #t)
548 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
550 (define (get-postscript-bbox string)
551 "Extract the bbox from STRING, or return #f if not present."
553 ((match (regexp-exec bbox-regexp string)))
557 (string->number (match:substring match x)))
562 (define-markup-command (epsfile layout props axis size file-name)
563 (number? number? string?)
566 @cindex inlining an Encapsulated PostScript image
568 Inline an EPS image. The image is scaled along @var{axis} to
571 @lilypond[verbatim,quote]
573 \\general-align #Y #DOWN {
574 \\epsfile #X #20 #\"context-example.eps\"
575 \\epsfile #Y #20 #\"context-example.eps\"
579 (if (ly:get-option 'safe)
580 (interpret-markup layout props "not allowed in safe")
581 (eps-file->stencil axis size file-name)
584 (define-markup-command (postscript layout props str)
588 @cindex inserting PostScript directly into text
589 This inserts @var{str} directly into the output as a PostScript
592 @lilypond[verbatim,quote]
596 0.4 0.6 0.5 0 361 arc
598 1.0 0.6 0.5 0 361 arc
603 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
604 \\postscript #ringsps
616 gsave currentpoint translate
624 (define-markup-command (path layout props thickness commands) (number? list?)
626 #:properties ((line-cap-style 'round)
627 (line-join-style 'round)
630 @cindex paths, drawing
631 @cindex drawing paths
632 Draws a path with line thickness @var{thickness} according to the
633 directions given in @var{commands}. @var{commands} is a list of
634 lists where the @code{car} of each sublist is a drawing command and
635 the @code{cdr} comprises the associated arguments for each command.
637 Line-cap styles and line-join styles may be customized by
638 overriding the @code{line-cap-style} and @code{line-join-style}
639 properties, respectively. Available line-cap styles are
640 @code{'butt}, @code{'round}, and @code{'square}. Available
641 line-join styles are @code{'miter}, @code{'round}, and
644 The property @code{filled} specifies whether or not the path is
647 There are seven commands available to use in the list
648 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
649 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
650 @code{closepath}. Note that the commands that begin with @emph{r}
651 are the relative variants of the other three commands.
653 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
654 @code{rlineto} take 2 arguments; they are the X and Y coordinates
655 for the destination point.
657 The commands @code{curveto} and @code{rcurveto} create cubic
658 Bézier curves, and take 6 arguments; the first two are the X and Y
659 coordinates for the first control point, the second two are the X
660 and Y coordinates for the second control point, and the last two
661 are the X and Y coordinates for the destination point.
663 The @code{closepath} command takes zero arguments and closes the
664 current subpath in the active path.
666 Note that a sequence of commands @emph{must} begin with a
667 @code{moveto} or @code{rmoveto} to work with the SVG output.
669 @lilypond[verbatim,quote]
675 (curveto -5 -5 -5 5 -1 0)
679 \\path #0.25 #samplePath
682 (let* ((half-thickness (/ thickness 2))
683 (current-point '(0 . 0))
684 (set-point (lambda (lst) (set! current-point lst)))
685 (relative? (lambda (x)
686 (string-prefix? "r" (symbol->string (car x)))))
687 ;; For calculating extents, we want to modify the command
688 ;; list so that all coordinates are absolute.
689 (new-commands (map (lambda (x)
691 ;; for rmoveto, rlineto
692 ((and (relative? x) (eq? 3 (length x)))
694 (+ (car current-point)
696 (+ (cdr current-point)
702 ((and (relative? x) (eq? 7 (length x)))
703 (let* ((old-cp current-point)
710 (list (+ (car old-cp) (second x))
711 (+ (cdr old-cp) (third x))
712 (+ (car old-cp) (fourth x))
713 (+ (cdr old-cp) (fifth x))
716 ;; for moveto, lineto
718 (set-point (cons (second x)
723 (set-point (cons (sixth x)
726 ;; keep closepath for filtering;
727 ;; see `without-closepath'.
730 ;; path-min-max does not accept 0-arg lists,
731 ;; and since closepath does not affect extents, filter
732 ;; out those commands here.
733 (without-closepath (filter (lambda (x)
734 (not (equal? 'closepath (car x))))
736 (extents (path-min-max
737 ;; set the origin to the first moveto
738 (list (list-ref (car without-closepath) 0)
739 (list-ref (car without-closepath) 1))
741 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
742 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
743 (command-list (fold-right append '() commands)))
745 ;; account for line thickness
746 (set! X-extent (interval-widen X-extent half-thickness))
747 (set! Y-extent (interval-widen Y-extent half-thickness))
750 `(path ,thickness `(,@',command-list)
751 ',line-cap-style ',line-join-style ,filled)
755 (define-markup-command (score layout props score)
758 #:properties ((baseline-skip))
760 @cindex inserting music into text
762 Inline an image of music.
764 @lilypond[verbatim,quote]
768 \\new Staff \\relative c' {
771 \\mark \\markup { Allegro }
777 \\new Staff \\relative c {
791 \\override RehearsalMark #'break-align-symbols =
792 #'(time-signature key-signature)
793 \\override RehearsalMark #'self-alignment-X = #LEFT
797 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
803 (let ((output (ly:score-embedded-format score layout)))
805 (if (ly:music-output? output)
806 (stack-stencils Y DOWN baseline-skip
807 (map paper-system-stencil
809 (ly:paper-score-paper-systems output))))
811 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
814 (define-markup-command (null layout props)
818 @cindex creating empty text objects
820 An empty markup with extents of a single point.
822 @lilypond[verbatim,quote]
829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
833 (define-markup-command (simple layout props str)
837 @cindex simple text strings
839 A simple text string; @code{\\markup @{ foo @}} is equivalent with
840 @code{\\markup @{ \\simple #\"foo\" @}}.
842 Note: for creating standard text markup or defining new markup commands,
843 the use of @code{\\simple} is unnecessary.
845 @lilypond[verbatim,quote]
849 \\simple #\"strings\"
852 (interpret-markup layout props str))
854 (define-markup-command (tied-lyric layout props str)
858 @cindex simple text strings with tie characters
860 Like simple-markup, but use tie characters for @q{~} tilde symbols.
862 @lilypond[verbatim,quote]
864 \\tied-lyric #\"Lasciate~i monti\"
867 (if (string-contains str "~")
869 ((parts (string-split str #\~))
870 (tie-str (ly:wide-char->utf-8 #x203f))
871 (joined (list-join parts tie-str))
872 (join-stencil (interpret-markup layout props tie-str))
875 (interpret-markup layout
878 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
880 (make-line-markup joined)))
881 ;(map (lambda (s) (interpret-markup layout props s)) parts))
882 (interpret-markup layout props str)))
884 (define-public empty-markup
885 (make-simple-markup ""))
887 ;; helper for justifying lines.
888 (define (get-fill-space word-count line-width word-space text-widths)
889 "Calculate the necessary paddings between each two adjacent texts.
890 The lengths of all texts are stored in @var{text-widths}.
891 The normal formula for the padding between texts a and b is:
892 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
893 The first and last padding have to be calculated specially using the
894 whole length of the first or last text.
895 All paddings are checked to be at least word-space, to ensure that
897 Return a list of paddings."
899 ((null? text-widths) '())
901 ;; special case first padding
902 ((= (length text-widths) word-count)
904 (- (- (/ line-width (1- word-count)) (car text-widths))
905 (/ (car (cdr text-widths)) 2))
906 (get-fill-space word-count line-width word-space (cdr text-widths))))
907 ;; special case last padding
908 ((= (length text-widths) 2)
909 (list (- (/ line-width (1- word-count))
910 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
912 (let ((default-padding
913 (- (/ line-width (1- word-count))
914 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
916 (if (> word-space default-padding)
919 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
921 (define-markup-command (fill-line layout props args)
924 #:properties ((text-direction RIGHT)
927 "Put @var{markups} in a horizontal line of width @var{line-width}.
928 The markups are spaced or flushed to fill the entire line.
929 If there are no arguments, return an empty stencil.
931 @lilypond[verbatim,quote]
935 Words evenly spaced across the page
939 \\line { Text markups }
941 \\italic { evenly spaced }
943 \\line { across the page }
948 (let* ((orig-stencils (interpret-markup-list layout props args))
951 (if (ly:stencil-empty? stc)
953 stc)) orig-stencils))
956 (if (ly:stencil-empty? stc)
958 (interval-length (ly:stencil-extent stc X))))
960 (text-width (apply + text-widths))
961 (word-count (length stencils))
962 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
967 (/ (- line-width text-width) 2)
968 (/ (- line-width text-width) 2)))
971 (- line-width text-width)))
973 (get-fill-space word-count line-width word-space text-widths))))
975 (line-contents (if (= word-count 1)
982 (if (null? (remove ly:stencil-empty? orig-stencils))
985 (if (= text-direction LEFT)
986 (set! line-contents (reverse line-contents)))
988 (stack-stencils-padding-list
989 X RIGHT fill-space line-contents))
991 ;; shift s.t. stencils align on the left edge, even if
992 ;; first stencil had negative X-extent (e.g. center-column)
993 ;; (if word-count = 1, X-extents are already normalized in
994 ;; the definition of line-contents)
996 (ly:stencil-translate-axis
998 (- (car (ly:stencil-extent (car stencils) X)))
1002 (define-markup-command (line layout props args)
1005 #:properties ((word-space)
1006 (text-direction RIGHT))
1007 "Put @var{args} in a horizontal line. The property @code{word-space}
1008 determines the space between markups in @var{args}.
1010 @lilypond[verbatim,quote]
1017 (let ((stencils (interpret-markup-list layout props args)))
1018 (if (= text-direction LEFT)
1019 (set! stencils (reverse stencils)))
1022 (remove ly:stencil-empty? stencils))))
1024 (define-markup-command (concat layout props args)
1028 @cindex concatenating text
1029 @cindex ligatures in text
1031 Concatenate @var{args} in a horizontal line, without spaces in between.
1032 Strings and simple markups are concatenated on the input level, allowing
1033 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1034 equivalent to @code{\"fi\"}.
1036 @lilypond[verbatim,quote]
1045 (define (concat-string-args arg-list)
1046 (fold-right (lambda (arg result-list)
1047 (let ((result (if (pair? result-list)
1050 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1051 (set! arg (cadr arg)))
1052 (if (and (string? result) (string? arg))
1053 (cons (string-append arg result) (cdr result-list))
1054 (cons arg result-list))))
1058 (interpret-markup layout
1059 (prepend-alist-chain 'word-space 0 props)
1060 (make-line-markup (if (markup-command-list? args)
1062 (concat-string-args args)))))
1064 (define (wordwrap-stencils stencils
1065 justify base-space line-width text-dir)
1066 "Perform simple wordwrap, return stencil of each line."
1067 (define space (if justify
1068 ;; justify only stretches lines.
1071 (define (take-list width space stencils
1072 accumulator accumulated-width)
1073 "Return (head-list . tail) pair, with head-list fitting into width"
1074 (if (null? stencils)
1075 (cons accumulator stencils)
1076 (let* ((first (car stencils))
1077 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1078 (newwid (+ space first-wid accumulated-width)))
1079 (if (or (null? accumulator)
1081 (take-list width space
1083 (cons first accumulator)
1085 (cons accumulator stencils)))))
1086 (let loop ((lines '())
1088 (let* ((line-break (take-list line-width space todo
1090 (line-stencils (car line-break))
1091 (space-left (- line-width
1092 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1094 (line-word-space (cond ((not justify) space)
1095 ;; don't stretch last line of paragraph.
1096 ;; hmmm . bug - will overstretch the last line in some case.
1097 ((null? (cdr line-break))
1099 ((null? line-stencils) 0.0)
1100 ((null? (cdr line-stencils)) 0.0)
1101 (else (/ space-left (1- (length line-stencils))))))
1102 (line (stack-stencil-line line-word-space
1103 (if (= text-dir RIGHT)
1104 (reverse line-stencils)
1106 (if (pair? (cdr line-break))
1107 (loop (cons line lines)
1110 (if (= text-dir LEFT)
1112 (ly:stencil-translate-axis
1114 (- line-width (interval-end (ly:stencil-extent line X)))
1116 (reverse (cons line lines)))))))
1118 (define-markup-list-command (wordwrap-internal layout props justify args)
1119 (boolean? markup-list?)
1120 #:properties ((line-width #f)
1122 (text-direction RIGHT))
1123 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1124 (wordwrap-stencils (remove ly:stencil-empty?
1125 (interpret-markup-list layout props args))
1129 (ly:output-def-lookup layout 'line-width))
1132 (define-markup-command (justify layout props args)
1135 #:properties ((baseline-skip)
1136 wordwrap-internal-markup-list)
1138 @cindex justifying text
1140 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1141 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1142 @var{X}@tie{}is the number of staff spaces.
1144 @lilypond[verbatim,quote]
1147 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1148 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1149 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1150 laboris nisi ut aliquip ex ea commodo consequat.
1154 (stack-lines DOWN 0.0 baseline-skip
1155 (wordwrap-internal-markup-list layout props #t args)))
1157 (define-markup-command (wordwrap layout props args)
1160 #:properties ((baseline-skip)
1161 wordwrap-internal-markup-list)
1162 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1163 the line width, where @var{X} is the number of staff spaces.
1165 @lilypond[verbatim,quote]
1168 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1169 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1170 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1171 laboris nisi ut aliquip ex ea commodo consequat.
1175 (stack-lines DOWN 0.0 baseline-skip
1176 (wordwrap-internal-markup-list layout props #f args)))
1178 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1180 #:properties ((line-width)
1182 (text-direction RIGHT))
1183 "Internal markup list command used to define @code{\\justify-string} and
1184 @code{\\wordwrap-string}."
1185 (let* ((para-strings (regexp-split
1186 (string-regexp-substitute
1188 (string-regexp-substitute "\r\n" "\n" arg))
1189 "\n[ \t\n]*\n[ \t\n]*"))
1190 (list-para-words (map (lambda (str)
1191 (regexp-split str "[ \t\n]+"))
1193 (para-lines (map (lambda (words)
1195 (remove ly:stencil-empty?
1197 (interpret-markup layout props x))
1199 (wordwrap-stencils stencils
1201 line-width text-direction)))
1203 (apply append para-lines)))
1205 (define-markup-command (wordwrap-string layout props arg)
1208 #:properties ((baseline-skip)
1209 wordwrap-string-internal-markup-list)
1210 "Wordwrap a string. Paragraphs may be separated with double newlines.
1212 @lilypond[verbatim,quote]
1214 \\override #'(line-width . 40)
1215 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1216 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1217 et dolore magna aliqua.
1220 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1221 laboris nisi ut aliquip ex ea commodo consequat.
1224 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1225 qui officia deserunt mollit anim id est laborum\"
1228 (stack-lines DOWN 0.0 baseline-skip
1229 (wordwrap-string-internal-markup-list layout props #f arg)))
1231 (define-markup-command (justify-string layout props arg)
1234 #:properties ((baseline-skip)
1235 wordwrap-string-internal-markup-list)
1236 "Justify a string. Paragraphs may be separated with double newlines
1238 @lilypond[verbatim,quote]
1240 \\override #'(line-width . 40)
1241 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1242 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1243 et dolore magna aliqua.
1246 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1247 laboris nisi ut aliquip ex ea commodo consequat.
1250 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1251 qui officia deserunt mollit anim id est laborum\"
1254 (stack-lines DOWN 0.0 baseline-skip
1255 (wordwrap-string-internal-markup-list layout props #t arg)))
1257 (define-markup-command (wordwrap-field layout props symbol)
1260 "Wordwrap the data which has been assigned to @var{symbol}.
1262 @lilypond[verbatim,quote]
1264 title = \"My title\"
1265 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1266 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1267 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1268 laboris nisi ut aliquip ex ea commodo consequat.\"
1272 bookTitleMarkup = \\markup {
1274 \\fill-line { \\fromproperty #'header:title }
1276 \\wordwrap-field #'header:myText
1285 (let* ((m (chain-assoc-get symbol props)))
1287 (wordwrap-string-markup layout props m)
1290 (define-markup-command (justify-field layout props symbol)
1293 "Justify the data which has been assigned to @var{symbol}.
1295 @lilypond[verbatim,quote]
1297 title = \"My title\"
1298 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1299 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1300 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1301 laboris nisi ut aliquip ex ea commodo consequat.\"
1305 bookTitleMarkup = \\markup {
1307 \\fill-line { \\fromproperty #'header:title }
1309 \\justify-field #'header:myText
1318 (let* ((m (chain-assoc-get symbol props)))
1320 (justify-string-markup layout props m)
1323 (define-markup-command (combine layout props arg1 arg2)
1327 @cindex merging text
1329 Print two markups on top of each other.
1331 Note: @code{\\combine} cannot take a list of markups enclosed in
1332 curly braces as an argument; the follow example will not compile:
1335 \\combine @{ a list @}
1338 @lilypond[verbatim,quote]
1341 \\override #'(thickness . 2)
1343 \\draw-line #'(0 . 4)
1344 \\arrow-head #Y #DOWN ##f
1347 (let* ((s1 (interpret-markup layout props arg1))
1348 (s2 (interpret-markup layout props arg2)))
1349 (ly:stencil-add s1 s2)))
1352 ;; TODO: should extract baseline-skip from each argument somehow..
1354 (define-markup-command (column layout props args)
1357 #:properties ((baseline-skip))
1359 @cindex stacking text in a column
1361 Stack the markups in @var{args} vertically. The property
1362 @code{baseline-skip} determines the space between markups
1365 @lilypond[verbatim,quote]
1374 (let ((arg-stencils (interpret-markup-list layout props args)))
1375 (stack-lines -1 0.0 baseline-skip
1376 (remove ly:stencil-empty? arg-stencils))))
1378 (define-markup-command (dir-column layout props args)
1381 #:properties ((direction)
1384 @cindex changing direction of text columns
1386 Make a column of @var{args}, going up or down, depending on the
1387 setting of the @code{direction} layout property.
1389 @lilypond[verbatim,quote]
1391 \\override #`(direction . ,UP) {
1401 \\override #'(direction . 1) {
1408 (stack-lines (if (number? direction) direction -1)
1411 (interpret-markup-list layout props args)))
1413 (define (general-column align-dir baseline mols)
1414 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1416 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1417 (stack-lines -1 0.0 baseline aligned-mols)))
1419 (define-markup-command (center-column layout props args)
1422 #:properties ((baseline-skip))
1424 @cindex centering a column of text
1426 Put @code{args} in a centered column.
1428 @lilypond[verbatim,quote]
1437 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1439 (define-markup-command (left-column layout props args)
1442 #:properties ((baseline-skip))
1444 @cindex text columns, left-aligned
1446 Put @code{args} in a left-aligned column.
1448 @lilypond[verbatim,quote]
1457 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1459 (define-markup-command (right-column layout props args)
1462 #:properties ((baseline-skip))
1464 @cindex text columns, right-aligned
1466 Put @code{args} in a right-aligned column.
1468 @lilypond[verbatim,quote]
1477 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1479 (define-markup-command (vcenter layout props arg)
1483 @cindex vertically centering text
1485 Align @code{arg} to its Y@tie{}center.
1487 @lilypond[verbatim,quote]
1495 (let* ((mol (interpret-markup layout props arg)))
1496 (ly:stencil-aligned-to mol Y CENTER)))
1498 (define-markup-command (center-align layout props arg)
1502 @cindex horizontally centering text
1504 Align @code{arg} to its X@tie{}center.
1506 @lilypond[verbatim,quote]
1516 (let* ((mol (interpret-markup layout props arg)))
1517 (ly:stencil-aligned-to mol X CENTER)))
1519 (define-markup-command (right-align layout props arg)
1523 @cindex right aligning text
1525 Align @var{arg} on its right edge.
1527 @lilypond[verbatim,quote]
1537 (let* ((m (interpret-markup layout props arg)))
1538 (ly:stencil-aligned-to m X RIGHT)))
1540 (define-markup-command (left-align layout props arg)
1544 @cindex left aligning text
1546 Align @var{arg} on its left edge.
1548 @lilypond[verbatim,quote]
1558 (let* ((m (interpret-markup layout props arg)))
1559 (ly:stencil-aligned-to m X LEFT)))
1561 (define-markup-command (general-align layout props axis dir arg)
1562 (integer? number? markup?)
1565 @cindex controlling general text alignment
1567 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1569 @lilypond[verbatim,quote]
1573 \\general-align #X #LEFT
1578 \\general-align #X #CENTER
1584 \\general-align #Y #UP
1591 \\general-align #Y #3.2
1598 (let* ((m (interpret-markup layout props arg)))
1599 (ly:stencil-aligned-to m axis dir)))
1601 (define-markup-command (halign layout props dir arg)
1605 @cindex setting horizontal text alignment
1607 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1608 left-aligned, while @code{+1} is right. Values in between interpolate
1609 alignment accordingly.
1611 @lilypond[verbatim,quote]
1636 (let* ((m (interpret-markup layout props arg)))
1637 (ly:stencil-aligned-to m X dir)))
1639 (define-markup-command (with-dimensions layout props x y arg)
1640 (number-pair? number-pair? markup?)
1643 @cindex setting extent of text objects
1645 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1646 (let* ((m (interpret-markup layout props arg)))
1647 (ly:make-stencil (ly:stencil-expr m) x y)))
1649 (define-markup-command (pad-around layout props amount arg)
1652 "Add padding @var{amount} all around @var{arg}.
1654 @lilypond[verbatim,quote]
1667 (let* ((m (interpret-markup layout props arg))
1668 (x (ly:stencil-extent m X))
1669 (y (ly:stencil-extent m Y)))
1670 (ly:make-stencil (ly:stencil-expr m)
1671 (interval-widen x amount)
1672 (interval-widen y amount))))
1674 (define-markup-command (pad-x layout props amount arg)
1678 @cindex padding text horizontally
1680 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1682 @lilypond[verbatim,quote]
1695 (let* ((m (interpret-markup layout props arg))
1696 (x (ly:stencil-extent m X))
1697 (y (ly:stencil-extent m Y)))
1698 (ly:make-stencil (ly:stencil-expr m)
1699 (interval-widen x amount)
1702 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1703 (integer? ly:dir? markup? markup?)
1705 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1706 (let ((m1 (interpret-markup layout props arg1))
1707 (m2 (interpret-markup layout props arg2)))
1708 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1710 (define-markup-command (transparent layout props arg)
1713 "Make @var{arg} transparent.
1715 @lilypond[verbatim,quote]
1722 (let* ((m (interpret-markup layout props arg))
1723 (x (ly:stencil-extent m X))
1724 (y (ly:stencil-extent m Y)))
1725 (ly:make-stencil "" x y)))
1727 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1728 (number-pair? number-pair? markup?)
1730 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1732 @lilypond[verbatim,quote]
1739 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1745 (let* ((m (interpret-markup layout props arg))
1746 (x (ly:stencil-extent m X))
1747 (y (ly:stencil-extent m Y)))
1748 (ly:make-stencil (ly:stencil-expr m)
1749 (interval-union x-ext x)
1750 (interval-union y-ext y))))
1752 (define-markup-command (hcenter-in layout props length arg)
1755 "Center @var{arg} horizontally within a box of extending
1756 @var{length}/2 to the left and right.
1758 @lilypond[quote,verbatim]
1761 \\set Staff.instrumentName = \\markup {
1768 \\set Staff.instrumentName = \\markup {
1777 (interpret-markup layout props
1778 (make-pad-to-box-markup
1779 (cons (/ length -2) (/ length 2))
1781 (make-center-align-markup arg))))
1783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1785 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1787 (define-markup-command (fromproperty layout props symbol)
1790 "Read the @var{symbol} from property settings, and produce a stencil
1791 from the markup contained within. If @var{symbol} is not defined, it
1792 returns an empty markup.
1794 @lilypond[verbatim,quote]
1796 myTitle = \"myTitle\"
1800 \\fromproperty #'header:myTitle
1807 (let ((m (chain-assoc-get symbol props)))
1809 (interpret-markup layout props m)
1812 (define-markup-command (on-the-fly layout props procedure arg)
1815 "Apply the @var{procedure} markup command to @var{arg}.
1816 @var{procedure} should take a single argument."
1817 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1818 (set-object-property! anonymous-with-signature
1821 (interpret-markup layout props (list anonymous-with-signature arg))))
1823 (define-markup-command (override layout props new-prop arg)
1827 @cindex overriding properties within text markup
1829 Add the argument @var{new-prop} to the property list. Properties
1830 may be any property supported by @rinternals{font-interface},
1831 @rinternals{text-interface} and
1832 @rinternals{instrument-specific-markup-interface}.
1834 @lilypond[verbatim,quote]
1842 \\override #'(baseline-skip . 4) {
1851 (interpret-markup layout (cons (list new-prop) props) arg))
1853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1857 (define-markup-command (verbatim-file layout props name)
1860 "Read the contents of file @var{name}, and include it verbatim.
1862 @lilypond[verbatim,quote]
1864 \\verbatim-file #\"simple.ly\"
1867 (interpret-markup layout props
1868 (if (ly:get-option 'safe)
1869 "verbatim-file disabled in safe mode"
1870 (let* ((str (ly:gulp-file name))
1871 (lines (string-split str #\nl)))
1872 (make-typewriter-markup
1873 (make-column-markup lines))))))
1875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1880 (define-markup-command (smaller layout props arg)
1883 "Decrease the font size relative to the current setting.
1885 @lilypond[verbatim,quote]
1898 (interpret-markup layout props
1899 `(,fontsize-markup -1 ,arg)))
1901 (define-markup-command (larger layout props arg)
1904 "Increase the font size relative to the current setting.
1906 @lilypond[verbatim,quote]
1914 (interpret-markup layout props
1915 `(,fontsize-markup 1 ,arg)))
1917 (define-markup-command (finger layout props arg)
1920 "Set @var{arg} as small numbers.
1922 @lilypond[verbatim,quote]
1929 (interpret-markup layout
1930 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1933 (define-markup-command (abs-fontsize layout props size arg)
1936 "Use @var{size} as the absolute font size to display @var{arg}.
1937 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1939 @lilypond[verbatim,quote]
1941 default text font size
1943 \\abs-fontsize #16 { text font size 16 }
1945 \\abs-fontsize #12 { text font size 12 }
1948 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1949 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1950 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1951 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1952 (magnification (/ size ref-size)))
1953 (interpret-markup layout
1954 (cons `((baseline-skip . ,(* magnification ref-baseline))
1955 (word-space . ,(* magnification ref-word-space))
1956 (font-size . ,(magnification->font-size magnification)))
1960 (define-markup-command (fontsize layout props increment arg)
1963 #:properties ((font-size 0)
1966 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1969 @lilypond[verbatim,quote]
1977 (let ((entries (list
1978 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1979 (cons 'word-space (* word-space (magstep increment)))
1980 (cons 'font-size (+ font-size increment)))))
1981 (interpret-markup layout (cons entries props) arg)))
1983 (define-markup-command (magnify layout props sz arg)
1987 @cindex magnifying text
1989 Set the font magnification for its argument. In the following
1990 example, the middle@tie{}A is 10% larger:
1993 A \\magnify #1.1 @{ A @} A
1996 Note: Magnification only works if a font name is explicitly selected.
1997 Use @code{\\fontsize} otherwise.
1999 @lilypond[verbatim,quote]
2010 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2013 (define-markup-command (bold layout props arg)
2016 "Switch to bold font-series.
2018 @lilypond[verbatim,quote]
2026 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2028 (define-markup-command (sans layout props arg)
2031 "Switch to the sans serif font family.
2033 @lilypond[verbatim,quote]
2042 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2044 (define-markup-command (number layout props arg)
2047 "Set font family to @code{number}, which yields the font used for
2048 time signatures and fingerings. This font contains numbers and
2049 some punctuation; it has no letters.
2051 @lilypond[verbatim,quote]
2054 0 1 2 3 4 5 6 7 8 9 . ,
2058 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2060 (define-markup-command (roman layout props arg)
2063 "Set font family to @code{roman}.
2065 @lilypond[verbatim,quote]
2071 text in roman font family
2078 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2080 (define-markup-command (huge layout props arg)
2083 "Set font size to +2.
2085 @lilypond[verbatim,quote]
2093 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2095 (define-markup-command (large layout props arg)
2098 "Set font size to +1.
2100 @lilypond[verbatim,quote]
2108 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2110 (define-markup-command (normalsize layout props arg)
2113 "Set font size to default.
2115 @lilypond[verbatim,quote]
2128 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2130 (define-markup-command (small layout props arg)
2133 "Set font size to -1.
2135 @lilypond[verbatim,quote]
2143 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2145 (define-markup-command (tiny layout props arg)
2148 "Set font size to -2.
2150 @lilypond[verbatim,quote]
2158 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2160 (define-markup-command (teeny layout props arg)
2163 "Set font size to -3.
2165 @lilypond[verbatim,quote]
2173 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2175 (define-markup-command (fontCaps layout props arg)
2178 "Set @code{font-shape} to @code{caps}
2180 Note: @code{\\fontCaps} requires the installation and selection of
2181 fonts which support the @code{caps} font shape."
2182 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2185 (define-markup-command (smallCaps layout props arg)
2188 "Emit @var{arg} as small caps.
2190 Note: @code{\\smallCaps} does not support accented characters.
2192 @lilypond[verbatim,quote]
2201 (define (char-list->markup chars lower)
2202 (let ((final-string (string-upcase (reverse-list->string chars))))
2204 (markup #:fontsize -2 final-string)
2206 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2207 (if (null? rest-chars)
2209 (reverse! (cons (char-list->markup currents current-is-lower)
2211 (let* ((ch (car rest-chars))
2212 (is-lower (char-lower-case? ch)))
2213 (if (or (and current-is-lower is-lower)
2214 (and (not current-is-lower) (not is-lower)))
2215 (make-small-caps (cdr rest-chars)
2219 (make-small-caps (cdr rest-chars)
2222 (if (null? currents)
2224 (cons (char-list->markup
2225 currents current-is-lower)
2227 (interpret-markup layout props
2229 (make-small-caps (string->list arg) (list) #f (list))
2232 (define-markup-command (caps layout props arg)
2235 "Copy of the @code{\\smallCaps} command.
2237 @lilypond[verbatim,quote]
2246 (interpret-markup layout props (make-smallCaps-markup arg)))
2248 (define-markup-command (dynamic layout props arg)
2251 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2252 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2253 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2254 done in a different font. The recommended font for this is bold and italic.
2255 @lilypond[verbatim,quote]
2263 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2265 (define-markup-command (text layout props arg)
2268 "Use a text font instead of music symbol or music alphabet font.
2270 @lilypond[verbatim,quote]
2283 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2286 (define-markup-command (italic layout props arg)
2289 "Use italic @code{font-shape} for @var{arg}.
2291 @lilypond[verbatim,quote]
2299 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2301 (define-markup-command (typewriter layout props arg)
2304 "Use @code{font-family} typewriter for @var{arg}.
2306 @lilypond[verbatim,quote]
2315 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2317 (define-markup-command (upright layout props arg)
2320 "Set @code{font-shape} to @code{upright}. This is the opposite
2323 @lilypond[verbatim,quote]
2337 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2339 (define-markup-command (medium layout props arg)
2342 "Switch to medium font-series (in contrast to bold).
2344 @lilypond[verbatim,quote]
2357 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2360 (define-markup-command (normal-text layout props arg)
2363 "Set all font related properties (except the size) to get the default
2364 normal text font, no matter what font was used earlier.
2366 @lilypond[verbatim,quote]
2368 \\huge \\bold \\sans \\caps {
2369 Some text with font overrides
2372 Default text, same font-size
2380 (interpret-markup layout
2381 (cons '((font-family . roman) (font-shape . upright)
2382 (font-series . medium) (font-encoding . latin1))
2386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2390 (define-markup-command (doublesharp layout props)
2393 "Draw a double sharp symbol.
2395 @lilypond[verbatim,quote]
2400 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2402 (define-markup-command (sesquisharp layout props)
2405 "Draw a 3/2 sharp symbol.
2407 @lilypond[verbatim,quote]
2412 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2414 (define-markup-command (sharp layout props)
2417 "Draw a sharp symbol.
2419 @lilypond[verbatim,quote]
2424 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2426 (define-markup-command (semisharp layout props)
2429 "Draw a semisharp symbol.
2431 @lilypond[verbatim,quote]
2436 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2438 (define-markup-command (natural layout props)
2441 "Draw a natural symbol.
2443 @lilypond[verbatim,quote]
2448 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2450 (define-markup-command (semiflat layout props)
2453 "Draw a semiflat symbol.
2455 @lilypond[verbatim,quote]
2460 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2462 (define-markup-command (flat layout props)
2465 "Draw a flat symbol.
2467 @lilypond[verbatim,quote]
2472 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2474 (define-markup-command (sesquiflat layout props)
2477 "Draw a 3/2 flat symbol.
2479 @lilypond[verbatim,quote]
2484 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2486 (define-markup-command (doubleflat layout props)
2489 "Draw a double flat symbol.
2491 @lilypond[verbatim,quote]
2496 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2498 (define-markup-command (with-color layout props color arg)
2502 @cindex coloring text
2504 Draw @var{arg} in color specified by @var{color}.
2506 @lilypond[verbatim,quote]
2518 (let ((stil (interpret-markup layout props arg)))
2519 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2520 (ly:stencil-extent stil X)
2521 (ly:stencil-extent stil Y))))
2523 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2525 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2527 (define-markup-command (arrow-head layout props axis dir filled)
2528 (integer? ly:dir? boolean?)
2530 "Produce an arrow head in specified direction and axis.
2531 Use the filled head if @var{filled} is specified.
2532 @lilypond[verbatim,quote]
2535 \\general-align #Y #DOWN {
2536 \\arrow-head #Y #UP ##t
2537 \\arrow-head #Y #DOWN ##f
2539 \\arrow-head #X #RIGHT ##f
2540 \\arrow-head #X #LEFT ##f
2546 ((name (format "arrowheads.~a.~a~a"
2553 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2557 (define-markup-command (musicglyph layout props glyph-name)
2560 "@var{glyph-name} is converted to a musical symbol; for example,
2561 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2562 the music font. See @ruser{The Feta font} for a complete listing of
2563 the possible glyphs.
2565 @lilypond[verbatim,quote]
2568 \\musicglyph #\"rests.2\"
2569 \\musicglyph #\"clefs.G_change\"
2572 (let* ((font (ly:paper-get-font layout
2573 (cons '((font-encoding . fetaMusic)
2577 (glyph (ly:font-get-glyph font glyph-name)))
2578 (if (null? (ly:stencil-expr glyph))
2579 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2584 (define-markup-command (lookup layout props glyph-name)
2587 "Lookup a glyph by name.
2589 @lilypond[verbatim,quote]
2591 \\override #'(font-encoding . fetaBraces) {
2592 \\lookup #\"brace200\"
2595 \\lookup #\"brace180\"
2599 (ly:font-get-glyph (ly:paper-get-font layout props)
2602 (define-markup-command (char layout props num)
2605 "Produce a single character. Characters encoded in hexadecimal
2606 format require the prefix @code{#x}.
2608 @lilypond[verbatim,quote]
2610 \\char #65 \\char ##x00a9
2613 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2615 (define number->mark-letter-vector (make-vector 25 #\A))
2620 (if (= i (- (char->integer #\I) (char->integer #\A)))
2622 (vector-set! number->mark-letter-vector j
2623 (integer->char (+ i (char->integer #\A)))))
2625 (define number->mark-alphabet-vector (list->vector
2626 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2628 (define (number->markletter-string vec n)
2629 "Double letters for big marks."
2630 (let* ((lst (vector-length vec)))
2633 (string-append (number->markletter-string vec (1- (quotient n lst)))
2634 (number->markletter-string vec (remainder n lst)))
2635 (make-string 1 (vector-ref vec n)))))
2637 (define-markup-command (markletter layout props num)
2640 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2641 (skipping letter@tie{}I), and continue with double letters.
2643 @lilypond[verbatim,quote]
2650 (ly:text-interface::interpret-markup layout props
2651 (number->markletter-string number->mark-letter-vector num)))
2653 (define-markup-command (markalphabet layout props num)
2656 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2657 and continue with double letters.
2659 @lilypond[verbatim,quote]
2666 (ly:text-interface::interpret-markup layout props
2667 (number->markletter-string number->mark-alphabet-vector num)))
2669 (define-public (horizontal-slash-interval num forward number-interval mag)
2671 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2672 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2673 (else (interval-widen number-interval (* mag 0.25))))
2674 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2675 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2676 (else (interval-widen number-interval (* mag 0.25))))
2679 (define-public (adjust-slash-stencil num forward stencil mag)
2682 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2684 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2686 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2688 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2691 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2693 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2698 (define (slashed-digit-internal layout props num forward font-size thickness)
2699 (let* ((mag (magstep font-size))
2701 (ly:output-def-lookup layout 'line-thickness)
2703 ; backward slashes might use slope and point in the other direction!
2704 (dy (* mag (if forward 0.4 -0.4)))
2705 (number-stencil (interpret-markup layout
2706 (prepend-alist-chain 'font-encoding 'fetaText props)
2707 (number->string num)))
2708 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2709 (center (interval-center (ly:stencil-extent number-stencil Y)))
2710 ; Use the real extents of the slash, not the whole number, because we
2711 ; might translate the slash later on!
2712 (num-y (interval-widen (cons center center) (abs dy)))
2713 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2714 (slash-stencil (if is-sane
2715 (make-line-stencil thickness
2716 (car num-x) (- (interval-center num-y) dy)
2717 (cdr num-x) (+ (interval-center num-y) dy))
2719 (if (ly:stencil? slash-stencil)
2721 ; for some numbers we need to shift the slash/backslash up or down to make
2722 ; the slashed digit look better
2723 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2724 (set! number-stencil
2725 (ly:stencil-add number-stencil slash-stencil)))
2726 (ly:warning "Unable to create slashed digit ~a" num))
2730 (define-markup-command (slashed-digit layout props num)
2733 #:properties ((font-size 0)
2736 @cindex slashed digits
2738 A feta number, with slash. This is for use in the context of
2739 figured bass notation.
2740 @lilypond[verbatim,quote]
2744 \\override #'(thickness . 3)
2748 (slashed-digit-internal layout props num #t font-size thickness))
2750 (define-markup-command (backslashed-digit layout props num)
2753 #:properties ((font-size 0)
2756 @cindex backslashed digits
2758 A feta number, with backslash. This is for use in the context of
2759 figured bass notation.
2760 @lilypond[verbatim,quote]
2762 \\backslashed-digit #5
2764 \\override #'(thickness . 3)
2765 \\backslashed-digit #7
2768 (slashed-digit-internal layout props num #f font-size thickness))
2771 (define eyeglassespath
2772 '((moveto 0.42 0.77)
2773 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2774 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2775 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2776 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2779 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2780 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2781 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2782 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2784 (moveto 1.025 0.935)
2785 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2786 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2789 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2792 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2794 (define-markup-command (eyeglasses layout props)
2797 "Prints out eyeglasses, indicating strongly to look at the conductor.
2798 @lilypond[verbatim,quote]
2799 \\markup { \\eyeglasses }
2801 (interpret-markup layout props
2802 (make-override-markup '(line-cap-style . butt)
2803 (make-path-markup 0.15 eyeglassespath))))
2805 (define-markup-command (left-brace layout props size)
2809 A feta brace in point size @var{size}.
2811 @lilypond[verbatim,quote]
2818 (let* ((font (ly:paper-get-font layout
2819 (cons '((font-encoding . fetaBraces)
2822 (glyph-count (1- (ly:otf-glyph-count font)))
2823 (scale (ly:output-def-lookup layout 'output-scale))
2824 (scaled-size (/ (ly:pt size) scale))
2826 (ly:font-get-glyph font (string-append "brace"
2827 (number->string n)))))
2828 (get-y-from-brace (lambda (brace)
2830 (ly:stencil-extent (glyph brace) Y))))
2831 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2832 (glyph-found (glyph find-brace)))
2834 (if (or (null? (ly:stencil-expr glyph-found))
2835 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2836 (> scaled-size (interval-length
2837 (ly:stencil-extent (glyph glyph-count) Y))))
2839 (ly:warning (_ "no brace found for point size ~S ") size)
2840 (ly:warning (_ "defaulting to ~S pt")
2841 (/ (* scale (interval-length
2842 (ly:stencil-extent glyph-found Y)))
2846 (define-markup-command (right-brace layout props size)
2850 A feta brace in point size @var{size}, rotated 180 degrees.
2852 @lilypond[verbatim,quote]
2859 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2861 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2862 ;; the note command.
2863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2865 ;; TODO: better syntax.
2867 (define-markup-command (note-by-number layout props log dot-count dir)
2868 (number? number? number?)
2870 #:properties ((font-size 0)
2873 @cindex notes within text by log and dot-count
2875 Construct a note symbol, with stem. By using fractional values for
2876 @var{dir}, longer or shorter stems can be obtained.
2878 @lilypond[verbatim,quote]
2880 \\note-by-number #3 #0 #DOWN
2882 \\note-by-number #1 #2 #0.8
2885 (define (get-glyph-name-candidates dir log style)
2886 (map (lambda (dir-name)
2887 (format "noteheads.~a~a" dir-name
2888 (if (and (symbol? style)
2889 (not (equal? 'default style)))
2890 (select-head-glyph style (min log 2))
2892 (list (if (= dir UP) "u" "d")
2895 (define (get-glyph-name font cands)
2898 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2899 (get-glyph-name font (cdr cands))
2902 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2904 (size-factor (magstep font-size))
2905 (stem-length (* size-factor (max 3 (- log 1))))
2907 (let ((result (get-glyph-name font (get-glyph-name-candidates
2908 (sign dir) log style))))
2909 (if (string-null? result)
2910 ;; If no glyph name can be found, select default heads. Though
2911 ;; this usually means an unsupported style has been chosen, it
2912 ;; also prevents unrelated 'style settings from other grobs
2913 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2914 (get-glyph-name font (get-glyph-name-candidates
2915 (sign dir) log 'default))
2917 (head-glyph (ly:font-get-glyph font head-glyph-name))
2918 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2919 (stem-thickness (* size-factor 0.13))
2920 (stemy (* dir stem-length))
2921 (attach-off (cons (interval-index
2922 (ly:stencil-extent head-glyph X)
2923 (* (sign dir) (car attach-indices)))
2924 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2926 (ly:stencil-extent head-glyph Y)
2927 (cdr attach-indices)))))
2928 (stem-glyph (and (> log 0)
2929 (ly:round-filled-box
2930 (ordered-cons (car attach-off)
2932 (* (- (sign dir)) stem-thickness)))
2933 (cons (min stemy (cdr attach-off))
2934 (max stemy (cdr attach-off)))
2935 (/ stem-thickness 3))))
2937 (dot (ly:font-get-glyph font "dots.dot"))
2938 (dotwid (interval-length (ly:stencil-extent dot X)))
2939 (dots (and (> dot-count 0)
2940 (apply ly:stencil-add
2942 (ly:stencil-translate-axis
2943 dot (* 2 x dotwid) X))
2944 (iota dot-count)))))
2945 (flaggl (and (> log 2)
2946 (ly:stencil-translate
2947 (ly:font-get-glyph font
2948 (string-append "flags."
2949 (if (> dir 0) "u" "d")
2950 (number->string log)))
2951 (cons (+ (car attach-off) (if (< dir 0)
2955 ;; If there is a flag on an upstem and the stem is short, move the dots
2956 ;; to avoid the flag. 16th notes get a special case because their flags
2957 ;; hang lower than any other flags.
2958 (if (and dots (> dir 0) (> log 2)
2959 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2960 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2962 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2963 (if (ly:stencil? stem-glyph)
2964 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2965 (set! stem-glyph head-glyph))
2966 (if (ly:stencil? dots)
2969 (ly:stencil-translate-axis
2971 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2977 (let ((divisor (log 2)))
2978 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2980 (define (parse-simple-duration duration-string)
2981 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2982 and return a (log dots) list."
2983 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2985 (if (and match (string=? duration-string (match:substring match 0)))
2986 (let ((len (match:substring match 1))
2987 (dots (match:substring match 2)))
2988 (list (cond ((string=? len "breve") -1)
2989 ((string=? len "longa") -2)
2990 ((string=? len "maxima") -3)
2991 (else (log2 (string->number len))))
2992 (if dots (string-length dots) 0)))
2993 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2995 (define-markup-command (note layout props duration dir)
2998 #:properties (note-by-number-markup)
3000 @cindex notes within text by string
3002 This produces a note with a stem pointing in @var{dir} direction, with
3003 the @var{duration} for the note head type and augmentation dots. For
3004 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3005 a shortened down stem.
3007 @lilypond[verbatim,quote]
3009 \\override #'(style . cross) {
3013 \\note #\"breve\" #0
3016 (let ((parsed (parse-simple-duration duration)))
3017 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3019 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3021 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3023 (define-markup-command (lower layout props amount arg)
3027 @cindex lowering text
3029 Lower @var{arg} by the distance @var{amount}.
3030 A negative @var{amount} indicates raising; see also @code{\\raise}.
3032 @lilypond[verbatim,quote]
3040 (ly:stencil-translate-axis (interpret-markup layout props arg)
3043 (define-markup-command (translate-scaled layout props offset arg)
3044 (number-pair? markup?)
3046 #:properties ((font-size 0))
3048 @cindex translating text
3049 @cindex scaling text
3051 Translate @var{arg} by @var{offset}, scaling the offset by the
3054 @lilypond[verbatim,quote]
3057 * \\translate #'(2 . 3) translate
3059 * \\translate-scaled #'(2 . 3) translate-scaled
3063 (let* ((factor (magstep font-size))
3064 (scaled (cons (* factor (car offset))
3065 (* factor (cdr offset)))))
3066 (ly:stencil-translate (interpret-markup layout props arg)
3069 (define-markup-command (raise layout props amount arg)
3073 @cindex raising text
3075 Raise @var{arg} by the distance @var{amount}.
3076 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3078 The argument to @code{\\raise} is the vertical displacement amount,
3079 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3080 raise objects in relation to their surrounding markups.
3082 If the text object itself is positioned above or below the staff, then
3083 @code{\\raise} cannot be used to move it, since the mechanism that
3084 positions it next to the staff cancels any shift made with
3085 @code{\\raise}. For vertical positioning, use the @code{padding}
3086 and/or @code{extra-offset} properties.
3088 @lilypond[verbatim,quote]
3097 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3099 (define-markup-command (fraction layout props arg1 arg2)
3102 #:properties ((font-size 0))
3104 @cindex creating text fractions
3106 Make a fraction of two markups.
3107 @lilypond[verbatim,quote]
3113 (let* ((m1 (interpret-markup layout props arg1))
3114 (m2 (interpret-markup layout props arg2))
3115 (factor (magstep font-size))
3116 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3117 (padding (* factor 0.2))
3118 (baseline (* factor 0.6))
3119 (offset (* factor 0.75)))
3120 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3121 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3122 (let* ((x1 (ly:stencil-extent m1 X))
3123 (x2 (ly:stencil-extent m2 X))
3124 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3125 ;; should stack mols separately, to maintain LINE on baseline
3126 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3128 (ly:stencil-aligned-to stack Y CENTER))
3130 (ly:stencil-aligned-to stack X LEFT))
3131 ;; should have EX dimension
3133 (ly:stencil-translate-axis stack offset Y))))
3135 (define-markup-command (normal-size-super layout props arg)
3138 #:properties ((baseline-skip))
3140 @cindex setting superscript in standard font size
3142 Set @var{arg} in superscript with a normal font size.
3144 @lilypond[verbatim,quote]
3147 \\normal-size-super {
3148 superscript in standard size
3152 (ly:stencil-translate-axis
3153 (interpret-markup layout props arg)
3154 (* 0.5 baseline-skip) Y))
3156 (define-markup-command (super layout props arg)
3159 #:properties ((font-size 0)
3162 @cindex superscript text
3164 Set @var{arg} in superscript.
3166 @lilypond[verbatim,quote]
3176 (ly:stencil-translate-axis
3179 (cons `((font-size . ,(- font-size 3))) props)
3181 (* 0.5 baseline-skip)
3184 (define-markup-command (translate layout props offset arg)
3185 (number-pair? markup?)
3188 @cindex translating text
3190 Translate @var{arg} relative to its surroundings. @var{offset}
3191 is a pair of numbers representing the displacement in the X and Y axis.
3193 @lilypond[verbatim,quote]
3196 \\translate #'(2 . 3)
3197 \\line { translated two spaces right, three up }
3200 (ly:stencil-translate (interpret-markup layout props arg)
3203 (define-markup-command (sub layout props arg)
3206 #:properties ((font-size 0)
3209 @cindex subscript text
3211 Set @var{arg} in subscript.
3213 @lilypond[verbatim,quote]
3224 (ly:stencil-translate-axis
3227 (cons `((font-size . ,(- font-size 3))) props)
3229 (* -0.5 baseline-skip)
3232 (define-markup-command (normal-size-sub layout props arg)
3235 #:properties ((baseline-skip))
3237 @cindex setting subscript in standard font size
3239 Set @var{arg} in subscript with a normal font size.
3241 @lilypond[verbatim,quote]
3245 subscript in standard size
3249 (ly:stencil-translate-axis
3250 (interpret-markup layout props arg)
3251 (* -0.5 baseline-skip)
3254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3256 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3258 (define-markup-command (hbracket layout props arg)
3262 @cindex placing horizontal brackets around text
3264 Draw horizontal brackets around @var{arg}.
3266 @lilypond[verbatim,quote]
3275 (let ((th 0.1) ;; todo: take from GROB.
3276 (m (interpret-markup layout props arg)))
3277 (bracketify-stencil m X th (* 2.5 th) th)))
3279 (define-markup-command (bracket layout props arg)
3283 @cindex placing vertical brackets around text
3285 Draw vertical brackets around @var{arg}.
3287 @lilypond[verbatim,quote]
3294 (let ((th 0.1) ;; todo: take from GROB.
3295 (m (interpret-markup layout props arg)))
3296 (bracketify-stencil m Y th (* 2.5 th) th)))
3298 (define-markup-command (parenthesize layout props arg)
3301 #:properties ((angularity 0)
3307 @cindex placing parentheses around text
3309 Draw parentheses around @var{arg}. This is useful for parenthesizing
3310 a column containing several lines of text.
3312 @lilypond[verbatim,quote]
3321 \\override #'(angularity . 2) {
3332 (let* ((markup (interpret-markup layout props arg))
3333 (scaled-width (* size width))
3335 (* (chain-assoc-get 'line-thickness props 0.1)
3338 (min (* size 0.5 scaled-thickness)
3339 (* (/ 4 3.0) scaled-width)))
3340 (padding (chain-assoc-get 'padding props half-thickness)))
3341 (parenthesize-stencil
3342 markup half-thickness scaled-width angularity padding)))
3345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3346 ;; Delayed markup evaluation
3347 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3349 (define-markup-command (page-ref layout props label gauge default)
3350 (symbol? markup? markup?)
3353 @cindex referencing page numbers in text
3355 Reference to a page number. @var{label} is the label set on the referenced
3356 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3357 the maximum width of the page number, and @var{default} the value to display
3358 when @var{label} is not found."
3359 (let* ((gauge-stencil (interpret-markup layout props gauge))
3360 (x-ext (ly:stencil-extent gauge-stencil X))
3361 (y-ext (ly:stencil-extent gauge-stencil Y)))
3363 `(delay-stencil-evaluation
3364 ,(delay (ly:stencil-expr
3365 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3366 (page-number (if (list? table)
3367 (assoc-get label table)
3369 (page-markup (if page-number (format "~a" page-number) default))
3370 (page-stencil (interpret-markup layout props page-markup))
3371 (gap (- (interval-length x-ext)
3372 (interval-length (ly:stencil-extent page-stencil X)))))
3373 (interpret-markup layout props
3374 (markup #:concat (#:hspace gap page-markup)))))))
3378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3379 ;; Markup list commands
3380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3382 (define-public (space-lines baseline stils)
3383 (let space-stil ((stils stils)
3387 (let* ((stil (car stils))
3388 (dy-top (max (- (/ baseline 1.5)
3389 (interval-bound (ly:stencil-extent stil Y) UP))
3391 (dy-bottom (max (+ (/ baseline 3.0)
3392 (interval-bound (ly:stencil-extent stil Y) DOWN))
3394 (new-stil (ly:make-stencil
3395 (ly:stencil-expr stil)
3396 (ly:stencil-extent stil X)
3397 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3399 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3401 (space-stil (cdr stils) (cons new-stil result))))))
3403 (define-markup-list-command (justified-lines layout props args)
3405 #:properties ((baseline-skip)
3406 wordwrap-internal-markup-list)
3408 @cindex justifying lines of text
3410 Like @code{\\justify}, but return a list of lines instead of a single markup.
3411 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3412 @var{X}@tie{}is the number of staff spaces."
3413 (space-lines baseline-skip
3414 (interpret-markup-list layout props
3415 (make-wordwrap-internal-markup-list #t args))))
3417 (define-markup-list-command (wordwrap-lines layout props args)
3419 #:properties ((baseline-skip)
3420 wordwrap-internal-markup-list)
3421 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3422 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3423 where @var{X} is the number of staff spaces."
3424 (space-lines baseline-skip
3425 (interpret-markup-list layout props
3426 (make-wordwrap-internal-markup-list #f args))))
3428 (define-markup-list-command (column-lines layout props args)
3430 #:properties ((baseline-skip))
3431 "Like @code{\\column}, but return a list of lines instead of a single markup.
3432 @code{baseline-skip} determines the space between each markup in @var{args}."
3433 (space-lines baseline-skip
3434 (interpret-markup-list layout props args)))
3436 (define-markup-list-command (override-lines layout props new-prop args)
3437 (pair? markup-list?)
3438 "Like @code{\\override}, for markup lists."
3439 (interpret-markup-list layout (cons (list new-prop) props) args))