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 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 Return a list of paddings."
897 ((null? text-widths) '())
899 ;; special case first padding
900 ((= (length text-widths) word-count)
902 (- (- (/ line-width (1- word-count)) (car text-widths))
903 (/ (car (cdr text-widths)) 2))
904 (get-fill-space word-count line-width (cdr text-widths))))
905 ;; special case last padding
906 ((= (length text-widths) 2)
907 (list (- (/ line-width (1- word-count))
908 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
911 (- (/ line-width (1- word-count))
912 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
913 (get-fill-space word-count line-width (cdr text-widths))))))
915 (define-markup-command (fill-line layout props args)
918 #:properties ((text-direction RIGHT)
921 "Put @var{markups} in a horizontal line of width @var{line-width}.
922 The markups are spaced or flushed to fill the entire line.
923 If there are no arguments, return an empty stencil.
925 @lilypond[verbatim,quote]
929 Words evenly spaced across the page
933 \\line { Text markups }
935 \\italic { evenly spaced }
937 \\line { across the page }
942 (let* ((orig-stencils (interpret-markup-list layout props args))
945 (if (ly:stencil-empty? stc)
947 stc)) orig-stencils))
950 (if (ly:stencil-empty? stc)
952 (interval-length (ly:stencil-extent stc X))))
954 (text-width (apply + text-widths))
955 (word-count (length stencils))
956 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
961 (/ (- line-width text-width) 2)
962 (/ (- line-width text-width) 2)))
965 (- line-width text-width)))
967 (get-fill-space word-count line-width text-widths))))
975 (line-stencils (if (= word-count 1)
982 (if (= text-direction LEFT)
983 (set! line-stencils (reverse line-stencils)))
985 (if (null? (remove ly:stencil-empty? orig-stencils))
987 (ly:stencil-translate-axis
988 (stack-stencils-padding-list X
989 RIGHT fill-space-normal line-stencils)
990 (- (car (ly:stencil-extent (car stencils) X)))
993 (define-markup-command (line layout props args)
996 #:properties ((word-space)
997 (text-direction RIGHT))
998 "Put @var{args} in a horizontal line. The property @code{word-space}
999 determines the space between markups in @var{args}.
1001 @lilypond[verbatim,quote]
1008 (let ((stencils (interpret-markup-list layout props args)))
1009 (if (= text-direction LEFT)
1010 (set! stencils (reverse stencils)))
1013 (remove ly:stencil-empty? stencils))))
1015 (define-markup-command (concat layout props args)
1019 @cindex concatenating text
1020 @cindex ligatures in text
1022 Concatenate @var{args} in a horizontal line, without spaces in between.
1023 Strings and simple markups are concatenated on the input level, allowing
1024 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1025 equivalent to @code{\"fi\"}.
1027 @lilypond[verbatim,quote]
1036 (define (concat-string-args arg-list)
1037 (fold-right (lambda (arg result-list)
1038 (let ((result (if (pair? result-list)
1041 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1042 (set! arg (cadr arg)))
1043 (if (and (string? result) (string? arg))
1044 (cons (string-append arg result) (cdr result-list))
1045 (cons arg result-list))))
1049 (interpret-markup layout
1050 (prepend-alist-chain 'word-space 0 props)
1051 (make-line-markup (if (markup-command-list? args)
1053 (concat-string-args args)))))
1055 (define (wordwrap-stencils stencils
1056 justify base-space line-width text-dir)
1057 "Perform simple wordwrap, return stencil of each line."
1058 (define space (if justify
1059 ;; justify only stretches lines.
1062 (define (take-list width space stencils
1063 accumulator accumulated-width)
1064 "Return (head-list . tail) pair, with head-list fitting into width"
1065 (if (null? stencils)
1066 (cons accumulator stencils)
1067 (let* ((first (car stencils))
1068 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1069 (newwid (+ space first-wid accumulated-width)))
1070 (if (or (null? accumulator)
1072 (take-list width space
1074 (cons first accumulator)
1076 (cons accumulator stencils)))))
1077 (let loop ((lines '())
1079 (let* ((line-break (take-list line-width space todo
1081 (line-stencils (car line-break))
1082 (space-left (- line-width
1083 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1085 (line-word-space (cond ((not justify) space)
1086 ;; don't stretch last line of paragraph.
1087 ;; hmmm . bug - will overstretch the last line in some case.
1088 ((null? (cdr line-break))
1090 ((null? line-stencils) 0.0)
1091 ((null? (cdr line-stencils)) 0.0)
1092 (else (/ space-left (1- (length line-stencils))))))
1093 (line (stack-stencil-line line-word-space
1094 (if (= text-dir RIGHT)
1095 (reverse line-stencils)
1097 (if (pair? (cdr line-break))
1098 (loop (cons line lines)
1101 (if (= text-dir LEFT)
1103 (ly:stencil-translate-axis
1105 (- line-width (interval-end (ly:stencil-extent line X)))
1107 (reverse (cons line lines)))))))
1109 (define-markup-list-command (wordwrap-internal layout props justify args)
1110 (boolean? markup-list?)
1111 #:properties ((line-width #f)
1113 (text-direction RIGHT))
1114 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1115 (wordwrap-stencils (remove ly:stencil-empty?
1116 (interpret-markup-list layout props args))
1120 (ly:output-def-lookup layout 'line-width))
1123 (define-markup-command (justify layout props args)
1126 #:properties ((baseline-skip)
1127 wordwrap-internal-markup-list)
1129 @cindex justifying text
1131 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1132 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1133 @var{X}@tie{}is the number of staff spaces.
1135 @lilypond[verbatim,quote]
1138 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1139 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1140 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1141 laboris nisi ut aliquip ex ea commodo consequat.
1145 (stack-lines DOWN 0.0 baseline-skip
1146 (wordwrap-internal-markup-list layout props #t args)))
1148 (define-markup-command (wordwrap layout props args)
1151 #:properties ((baseline-skip)
1152 wordwrap-internal-markup-list)
1153 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1154 the line width, where @var{X} is the number of staff spaces.
1156 @lilypond[verbatim,quote]
1159 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1160 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1161 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1162 laboris nisi ut aliquip ex ea commodo consequat.
1166 (stack-lines DOWN 0.0 baseline-skip
1167 (wordwrap-internal-markup-list layout props #f args)))
1169 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1171 #:properties ((line-width)
1173 (text-direction RIGHT))
1174 "Internal markup list command used to define @code{\\justify-string} and
1175 @code{\\wordwrap-string}."
1176 (let* ((para-strings (regexp-split
1177 (string-regexp-substitute
1179 (string-regexp-substitute "\r\n" "\n" arg))
1180 "\n[ \t\n]*\n[ \t\n]*"))
1181 (list-para-words (map (lambda (str)
1182 (regexp-split str "[ \t\n]+"))
1184 (para-lines (map (lambda (words)
1186 (remove ly:stencil-empty?
1188 (interpret-markup layout props x))
1190 (wordwrap-stencils stencils
1192 line-width text-direction)))
1194 (apply append para-lines)))
1196 (define-markup-command (wordwrap-string layout props arg)
1199 #:properties ((baseline-skip)
1200 wordwrap-string-internal-markup-list)
1201 "Wordwrap a string. Paragraphs may be separated with double newlines.
1203 @lilypond[verbatim,quote]
1205 \\override #'(line-width . 40)
1206 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1207 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1208 et dolore magna aliqua.
1211 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1212 laboris nisi ut aliquip ex ea commodo consequat.
1215 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1216 qui officia deserunt mollit anim id est laborum\"
1219 (stack-lines DOWN 0.0 baseline-skip
1220 (wordwrap-string-internal-markup-list layout props #f arg)))
1222 (define-markup-command (justify-string layout props arg)
1225 #:properties ((baseline-skip)
1226 wordwrap-string-internal-markup-list)
1227 "Justify a string. Paragraphs may be separated with double newlines
1229 @lilypond[verbatim,quote]
1231 \\override #'(line-width . 40)
1232 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1233 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1234 et dolore magna aliqua.
1237 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1238 laboris nisi ut aliquip ex ea commodo consequat.
1241 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1242 qui officia deserunt mollit anim id est laborum\"
1245 (stack-lines DOWN 0.0 baseline-skip
1246 (wordwrap-string-internal-markup-list layout props #t arg)))
1248 (define-markup-command (wordwrap-field layout props symbol)
1251 "Wordwrap the data which has been assigned to @var{symbol}.
1253 @lilypond[verbatim,quote]
1255 title = \"My title\"
1256 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1257 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1258 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1259 laboris nisi ut aliquip ex ea commodo consequat.\"
1263 bookTitleMarkup = \\markup {
1265 \\fill-line { \\fromproperty #'header:title }
1267 \\wordwrap-field #'header:myText
1276 (let* ((m (chain-assoc-get symbol props)))
1278 (wordwrap-string-markup layout props m)
1281 (define-markup-command (justify-field layout props symbol)
1284 "Justify the data which has been assigned to @var{symbol}.
1286 @lilypond[verbatim,quote]
1288 title = \"My title\"
1289 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1290 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1291 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1292 laboris nisi ut aliquip ex ea commodo consequat.\"
1296 bookTitleMarkup = \\markup {
1298 \\fill-line { \\fromproperty #'header:title }
1300 \\justify-field #'header:myText
1309 (let* ((m (chain-assoc-get symbol props)))
1311 (justify-string-markup layout props m)
1314 (define-markup-command (combine layout props arg1 arg2)
1318 @cindex merging text
1320 Print two markups on top of each other.
1322 Note: @code{\\combine} cannot take a list of markups enclosed in
1323 curly braces as an argument; the follow example will not compile:
1326 \\combine @{ a list @}
1329 @lilypond[verbatim,quote]
1332 \\override #'(thickness . 2)
1334 \\draw-line #'(0 . 4)
1335 \\arrow-head #Y #DOWN ##f
1338 (let* ((s1 (interpret-markup layout props arg1))
1339 (s2 (interpret-markup layout props arg2)))
1340 (ly:stencil-add s1 s2)))
1343 ;; TODO: should extract baseline-skip from each argument somehow..
1345 (define-markup-command (column layout props args)
1348 #:properties ((baseline-skip))
1350 @cindex stacking text in a column
1352 Stack the markups in @var{args} vertically. The property
1353 @code{baseline-skip} determines the space between markups
1356 @lilypond[verbatim,quote]
1365 (let ((arg-stencils (interpret-markup-list layout props args)))
1366 (stack-lines -1 0.0 baseline-skip
1367 (remove ly:stencil-empty? arg-stencils))))
1369 (define-markup-command (dir-column layout props args)
1372 #:properties ((direction)
1375 @cindex changing direction of text columns
1377 Make a column of @var{args}, going up or down, depending on the
1378 setting of the @code{direction} layout property.
1380 @lilypond[verbatim,quote]
1382 \\override #`(direction . ,UP) {
1392 \\override #'(direction . 1) {
1399 (stack-lines (if (number? direction) direction -1)
1402 (interpret-markup-list layout props args)))
1404 (define (general-column align-dir baseline mols)
1405 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1407 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1408 (stack-lines -1 0.0 baseline aligned-mols)))
1410 (define-markup-command (center-column layout props args)
1413 #:properties ((baseline-skip))
1415 @cindex centering a column of text
1417 Put @code{args} in a centered column.
1419 @lilypond[verbatim,quote]
1428 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1430 (define-markup-command (left-column layout props args)
1433 #:properties ((baseline-skip))
1435 @cindex text columns, left-aligned
1437 Put @code{args} in a left-aligned column.
1439 @lilypond[verbatim,quote]
1448 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1450 (define-markup-command (right-column layout props args)
1453 #:properties ((baseline-skip))
1455 @cindex text columns, right-aligned
1457 Put @code{args} in a right-aligned column.
1459 @lilypond[verbatim,quote]
1468 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1470 (define-markup-command (vcenter layout props arg)
1474 @cindex vertically centering text
1476 Align @code{arg} to its Y@tie{}center.
1478 @lilypond[verbatim,quote]
1486 (let* ((mol (interpret-markup layout props arg)))
1487 (ly:stencil-aligned-to mol Y CENTER)))
1489 (define-markup-command (center-align layout props arg)
1493 @cindex horizontally centering text
1495 Align @code{arg} to its X@tie{}center.
1497 @lilypond[verbatim,quote]
1507 (let* ((mol (interpret-markup layout props arg)))
1508 (ly:stencil-aligned-to mol X CENTER)))
1510 (define-markup-command (right-align layout props arg)
1514 @cindex right aligning text
1516 Align @var{arg} on its right edge.
1518 @lilypond[verbatim,quote]
1528 (let* ((m (interpret-markup layout props arg)))
1529 (ly:stencil-aligned-to m X RIGHT)))
1531 (define-markup-command (left-align layout props arg)
1535 @cindex left aligning text
1537 Align @var{arg} on its left edge.
1539 @lilypond[verbatim,quote]
1549 (let* ((m (interpret-markup layout props arg)))
1550 (ly:stencil-aligned-to m X LEFT)))
1552 (define-markup-command (general-align layout props axis dir arg)
1553 (integer? number? markup?)
1556 @cindex controlling general text alignment
1558 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1560 @lilypond[verbatim,quote]
1564 \\general-align #X #LEFT
1569 \\general-align #X #CENTER
1575 \\general-align #Y #UP
1582 \\general-align #Y #3.2
1589 (let* ((m (interpret-markup layout props arg)))
1590 (ly:stencil-aligned-to m axis dir)))
1592 (define-markup-command (halign layout props dir arg)
1596 @cindex setting horizontal text alignment
1598 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1599 left-aligned, while @code{+1} is right. Values in between interpolate
1600 alignment accordingly.
1602 @lilypond[verbatim,quote]
1627 (let* ((m (interpret-markup layout props arg)))
1628 (ly:stencil-aligned-to m X dir)))
1630 (define-markup-command (with-dimensions layout props x y arg)
1631 (number-pair? number-pair? markup?)
1634 @cindex setting extent of text objects
1636 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1637 (let* ((m (interpret-markup layout props arg)))
1638 (ly:make-stencil (ly:stencil-expr m) x y)))
1640 (define-markup-command (pad-around layout props amount arg)
1643 "Add padding @var{amount} all around @var{arg}.
1645 @lilypond[verbatim,quote]
1658 (let* ((m (interpret-markup layout props arg))
1659 (x (ly:stencil-extent m X))
1660 (y (ly:stencil-extent m Y)))
1661 (ly:make-stencil (ly:stencil-expr m)
1662 (interval-widen x amount)
1663 (interval-widen y amount))))
1665 (define-markup-command (pad-x layout props amount arg)
1669 @cindex padding text horizontally
1671 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1673 @lilypond[verbatim,quote]
1686 (let* ((m (interpret-markup layout props arg))
1687 (x (ly:stencil-extent m X))
1688 (y (ly:stencil-extent m Y)))
1689 (ly:make-stencil (ly:stencil-expr m)
1690 (interval-widen x amount)
1693 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1694 (integer? ly:dir? markup? markup?)
1696 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1697 (let ((m1 (interpret-markup layout props arg1))
1698 (m2 (interpret-markup layout props arg2)))
1699 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1701 (define-markup-command (transparent layout props arg)
1704 "Make @var{arg} transparent.
1706 @lilypond[verbatim,quote]
1713 (let* ((m (interpret-markup layout props arg))
1714 (x (ly:stencil-extent m X))
1715 (y (ly:stencil-extent m Y)))
1716 (ly:make-stencil "" x y)))
1718 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1719 (number-pair? number-pair? markup?)
1721 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1723 @lilypond[verbatim,quote]
1730 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1736 (let* ((m (interpret-markup layout props arg))
1737 (x (ly:stencil-extent m X))
1738 (y (ly:stencil-extent m Y)))
1739 (ly:make-stencil (ly:stencil-expr m)
1740 (interval-union x-ext x)
1741 (interval-union y-ext y))))
1743 (define-markup-command (hcenter-in layout props length arg)
1746 "Center @var{arg} horizontally within a box of extending
1747 @var{length}/2 to the left and right.
1749 @lilypond[quote,verbatim]
1752 \\set Staff.instrumentName = \\markup {
1759 \\set Staff.instrumentName = \\markup {
1768 (interpret-markup layout props
1769 (make-pad-to-box-markup
1770 (cons (/ length -2) (/ length 2))
1772 (make-center-align-markup arg))))
1774 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1778 (define-markup-command (fromproperty layout props symbol)
1781 "Read the @var{symbol} from property settings, and produce a stencil
1782 from the markup contained within. If @var{symbol} is not defined, it
1783 returns an empty markup.
1785 @lilypond[verbatim,quote]
1787 myTitle = \"myTitle\"
1791 \\fromproperty #'header:myTitle
1798 (let ((m (chain-assoc-get symbol props)))
1800 (interpret-markup layout props m)
1803 (define-markup-command (on-the-fly layout props procedure arg)
1806 "Apply the @var{procedure} markup command to @var{arg}.
1807 @var{procedure} should take a single argument."
1808 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1809 (set-object-property! anonymous-with-signature
1812 (interpret-markup layout props (list anonymous-with-signature arg))))
1814 (define-markup-command (override layout props new-prop arg)
1818 @cindex overriding properties within text markup
1820 Add the argument @var{new-prop} to the property list. Properties
1821 may be any property supported by @rinternals{font-interface},
1822 @rinternals{text-interface} and
1823 @rinternals{instrument-specific-markup-interface}.
1825 @lilypond[verbatim,quote]
1833 \\override #'(baseline-skip . 4) {
1842 (interpret-markup layout (cons (list new-prop) props) arg))
1844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1848 (define-markup-command (verbatim-file layout props name)
1851 "Read the contents of file @var{name}, and include it verbatim.
1853 @lilypond[verbatim,quote]
1855 \\verbatim-file #\"simple.ly\"
1858 (interpret-markup layout props
1859 (if (ly:get-option 'safe)
1860 "verbatim-file disabled in safe mode"
1861 (let* ((str (ly:gulp-file name))
1862 (lines (string-split str #\nl)))
1863 (make-typewriter-markup
1864 (make-column-markup lines))))))
1866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1868 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1871 (define-markup-command (smaller layout props arg)
1874 "Decrease the font size relative to the current setting.
1876 @lilypond[verbatim,quote]
1889 (interpret-markup layout props
1890 `(,fontsize-markup -1 ,arg)))
1892 (define-markup-command (larger layout props arg)
1895 "Increase the font size relative to the current setting.
1897 @lilypond[verbatim,quote]
1905 (interpret-markup layout props
1906 `(,fontsize-markup 1 ,arg)))
1908 (define-markup-command (finger layout props arg)
1911 "Set @var{arg} as small numbers.
1913 @lilypond[verbatim,quote]
1920 (interpret-markup layout
1921 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1924 (define-markup-command (abs-fontsize layout props size arg)
1927 "Use @var{size} as the absolute font size to display @var{arg}.
1928 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1930 @lilypond[verbatim,quote]
1932 default text font size
1934 \\abs-fontsize #16 { text font size 16 }
1936 \\abs-fontsize #12 { text font size 12 }
1939 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1940 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1941 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1942 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1943 (magnification (/ size ref-size)))
1944 (interpret-markup layout
1945 (cons `((baseline-skip . ,(* magnification ref-baseline))
1946 (word-space . ,(* magnification ref-word-space))
1947 (font-size . ,(magnification->font-size magnification)))
1951 (define-markup-command (fontsize layout props increment arg)
1954 #:properties ((font-size 0)
1957 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1960 @lilypond[verbatim,quote]
1968 (let ((entries (list
1969 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1970 (cons 'word-space (* word-space (magstep increment)))
1971 (cons 'font-size (+ font-size increment)))))
1972 (interpret-markup layout (cons entries props) arg)))
1974 (define-markup-command (magnify layout props sz arg)
1978 @cindex magnifying text
1980 Set the font magnification for its argument. In the following
1981 example, the middle@tie{}A is 10% larger:
1984 A \\magnify #1.1 @{ A @} A
1987 Note: Magnification only works if a font name is explicitly selected.
1988 Use @code{\\fontsize} otherwise.
1990 @lilypond[verbatim,quote]
2001 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2004 (define-markup-command (bold layout props arg)
2007 "Switch to bold font-series.
2009 @lilypond[verbatim,quote]
2017 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2019 (define-markup-command (sans layout props arg)
2022 "Switch to the sans serif font family.
2024 @lilypond[verbatim,quote]
2033 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2035 (define-markup-command (number layout props arg)
2038 "Set font family to @code{number}, which yields the font used for
2039 time signatures and fingerings. This font contains numbers and
2040 some punctuation; it has no letters.
2042 @lilypond[verbatim,quote]
2045 0 1 2 3 4 5 6 7 8 9 . ,
2049 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2051 (define-markup-command (roman layout props arg)
2054 "Set font family to @code{roman}.
2056 @lilypond[verbatim,quote]
2062 text in roman font family
2069 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2071 (define-markup-command (huge layout props arg)
2074 "Set font size to +2.
2076 @lilypond[verbatim,quote]
2084 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2086 (define-markup-command (large layout props arg)
2089 "Set font size to +1.
2091 @lilypond[verbatim,quote]
2099 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2101 (define-markup-command (normalsize layout props arg)
2104 "Set font size to default.
2106 @lilypond[verbatim,quote]
2119 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2121 (define-markup-command (small layout props arg)
2124 "Set font size to -1.
2126 @lilypond[verbatim,quote]
2134 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2136 (define-markup-command (tiny layout props arg)
2139 "Set font size to -2.
2141 @lilypond[verbatim,quote]
2149 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2151 (define-markup-command (teeny layout props arg)
2154 "Set font size to -3.
2156 @lilypond[verbatim,quote]
2164 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2166 (define-markup-command (fontCaps layout props arg)
2169 "Set @code{font-shape} to @code{caps}
2171 Note: @code{\\fontCaps} requires the installation and selection of
2172 fonts which support the @code{caps} font shape."
2173 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2176 (define-markup-command (smallCaps layout props arg)
2179 "Emit @var{arg} as small caps.
2181 Note: @code{\\smallCaps} does not support accented characters.
2183 @lilypond[verbatim,quote]
2192 (define (char-list->markup chars lower)
2193 (let ((final-string (string-upcase (reverse-list->string chars))))
2195 (markup #:fontsize -2 final-string)
2197 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2198 (if (null? rest-chars)
2200 (reverse! (cons (char-list->markup currents current-is-lower)
2202 (let* ((ch (car rest-chars))
2203 (is-lower (char-lower-case? ch)))
2204 (if (or (and current-is-lower is-lower)
2205 (and (not current-is-lower) (not is-lower)))
2206 (make-small-caps (cdr rest-chars)
2210 (make-small-caps (cdr rest-chars)
2213 (if (null? currents)
2215 (cons (char-list->markup
2216 currents current-is-lower)
2218 (interpret-markup layout props
2220 (make-small-caps (string->list arg) (list) #f (list))
2223 (define-markup-command (caps layout props arg)
2226 "Copy of the @code{\\smallCaps} command.
2228 @lilypond[verbatim,quote]
2237 (interpret-markup layout props (make-smallCaps-markup arg)))
2239 (define-markup-command (dynamic layout props arg)
2242 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2243 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2244 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2245 done in a different font. The recommended font for this is bold and italic.
2246 @lilypond[verbatim,quote]
2254 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2256 (define-markup-command (text layout props arg)
2259 "Use a text font instead of music symbol or music alphabet font.
2261 @lilypond[verbatim,quote]
2274 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2277 (define-markup-command (italic layout props arg)
2280 "Use italic @code{font-shape} for @var{arg}.
2282 @lilypond[verbatim,quote]
2290 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2292 (define-markup-command (typewriter layout props arg)
2295 "Use @code{font-family} typewriter for @var{arg}.
2297 @lilypond[verbatim,quote]
2306 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2308 (define-markup-command (upright layout props arg)
2311 "Set @code{font-shape} to @code{upright}. This is the opposite
2314 @lilypond[verbatim,quote]
2328 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2330 (define-markup-command (medium layout props arg)
2333 "Switch to medium font-series (in contrast to bold).
2335 @lilypond[verbatim,quote]
2348 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2351 (define-markup-command (normal-text layout props arg)
2354 "Set all font related properties (except the size) to get the default
2355 normal text font, no matter what font was used earlier.
2357 @lilypond[verbatim,quote]
2359 \\huge \\bold \\sans \\caps {
2360 Some text with font overrides
2363 Default text, same font-size
2371 (interpret-markup layout
2372 (cons '((font-family . roman) (font-shape . upright)
2373 (font-series . medium) (font-encoding . latin1))
2377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2381 (define-markup-command (doublesharp layout props)
2384 "Draw a double sharp symbol.
2386 @lilypond[verbatim,quote]
2391 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2393 (define-markup-command (sesquisharp layout props)
2396 "Draw a 3/2 sharp symbol.
2398 @lilypond[verbatim,quote]
2403 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2405 (define-markup-command (sharp layout props)
2408 "Draw a sharp symbol.
2410 @lilypond[verbatim,quote]
2415 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2417 (define-markup-command (semisharp layout props)
2420 "Draw a semisharp symbol.
2422 @lilypond[verbatim,quote]
2427 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2429 (define-markup-command (natural layout props)
2432 "Draw a natural symbol.
2434 @lilypond[verbatim,quote]
2439 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2441 (define-markup-command (semiflat layout props)
2444 "Draw a semiflat symbol.
2446 @lilypond[verbatim,quote]
2451 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2453 (define-markup-command (flat layout props)
2456 "Draw a flat symbol.
2458 @lilypond[verbatim,quote]
2463 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2465 (define-markup-command (sesquiflat layout props)
2468 "Draw a 3/2 flat symbol.
2470 @lilypond[verbatim,quote]
2475 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2477 (define-markup-command (doubleflat layout props)
2480 "Draw a double flat symbol.
2482 @lilypond[verbatim,quote]
2487 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2489 (define-markup-command (with-color layout props color arg)
2493 @cindex coloring text
2495 Draw @var{arg} in color specified by @var{color}.
2497 @lilypond[verbatim,quote]
2509 (let ((stil (interpret-markup layout props arg)))
2510 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2511 (ly:stencil-extent stil X)
2512 (ly:stencil-extent stil Y))))
2514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2518 (define-markup-command (arrow-head layout props axis dir filled)
2519 (integer? ly:dir? boolean?)
2521 "Produce an arrow head in specified direction and axis.
2522 Use the filled head if @var{filled} is specified.
2523 @lilypond[verbatim,quote]
2526 \\general-align #Y #DOWN {
2527 \\arrow-head #Y #UP ##t
2528 \\arrow-head #Y #DOWN ##f
2530 \\arrow-head #X #RIGHT ##f
2531 \\arrow-head #X #LEFT ##f
2537 ((name (format "arrowheads.~a.~a~a"
2544 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2548 (define-markup-command (musicglyph layout props glyph-name)
2551 "@var{glyph-name} is converted to a musical symbol; for example,
2552 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2553 the music font. See @ruser{The Feta font} for a complete listing of
2554 the possible glyphs.
2556 @lilypond[verbatim,quote]
2559 \\musicglyph #\"rests.2\"
2560 \\musicglyph #\"clefs.G_change\"
2563 (let* ((font (ly:paper-get-font layout
2564 (cons '((font-encoding . fetaMusic)
2568 (glyph (ly:font-get-glyph font glyph-name)))
2569 (if (null? (ly:stencil-expr glyph))
2570 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2575 (define-markup-command (lookup layout props glyph-name)
2578 "Lookup a glyph by name.
2580 @lilypond[verbatim,quote]
2582 \\override #'(font-encoding . fetaBraces) {
2583 \\lookup #\"brace200\"
2586 \\lookup #\"brace180\"
2590 (ly:font-get-glyph (ly:paper-get-font layout props)
2593 (define-markup-command (char layout props num)
2596 "Produce a single character. Characters encoded in hexadecimal
2597 format require the prefix @code{#x}.
2599 @lilypond[verbatim,quote]
2601 \\char #65 \\char ##x00a9
2604 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2606 (define number->mark-letter-vector (make-vector 25 #\A))
2611 (if (= i (- (char->integer #\I) (char->integer #\A)))
2613 (vector-set! number->mark-letter-vector j
2614 (integer->char (+ i (char->integer #\A)))))
2616 (define number->mark-alphabet-vector (list->vector
2617 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2619 (define (number->markletter-string vec n)
2620 "Double letters for big marks."
2621 (let* ((lst (vector-length vec)))
2624 (string-append (number->markletter-string vec (1- (quotient n lst)))
2625 (number->markletter-string vec (remainder n lst)))
2626 (make-string 1 (vector-ref vec n)))))
2628 (define-markup-command (markletter layout props num)
2631 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2632 (skipping letter@tie{}I), and continue with double letters.
2634 @lilypond[verbatim,quote]
2641 (ly:text-interface::interpret-markup layout props
2642 (number->markletter-string number->mark-letter-vector num)))
2644 (define-markup-command (markalphabet layout props num)
2647 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2648 and continue with double letters.
2650 @lilypond[verbatim,quote]
2657 (ly:text-interface::interpret-markup layout props
2658 (number->markletter-string number->mark-alphabet-vector num)))
2660 (define-public (horizontal-slash-interval num forward number-interval mag)
2662 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2663 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2664 (else (interval-widen number-interval (* mag 0.25))))
2665 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2666 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2667 (else (interval-widen number-interval (* mag 0.25))))
2670 (define-public (adjust-slash-stencil num forward stencil mag)
2673 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2675 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2677 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2679 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2682 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2684 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2689 (define (slashed-digit-internal layout props num forward font-size thickness)
2690 (let* ((mag (magstep font-size))
2692 (ly:output-def-lookup layout 'line-thickness)
2694 ; backward slashes might use slope and point in the other direction!
2695 (dy (* mag (if forward 0.4 -0.4)))
2696 (number-stencil (interpret-markup layout
2697 (prepend-alist-chain 'font-encoding 'fetaText props)
2698 (number->string num)))
2699 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2700 (center (interval-center (ly:stencil-extent number-stencil Y)))
2701 ; Use the real extents of the slash, not the whole number, because we
2702 ; might translate the slash later on!
2703 (num-y (interval-widen (cons center center) (abs dy)))
2704 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2705 (slash-stencil (if is-sane
2706 (make-line-stencil thickness
2707 (car num-x) (- (interval-center num-y) dy)
2708 (cdr num-x) (+ (interval-center num-y) dy))
2710 (if (ly:stencil? slash-stencil)
2712 ; for some numbers we need to shift the slash/backslash up or down to make
2713 ; the slashed digit look better
2714 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2715 (set! number-stencil
2716 (ly:stencil-add number-stencil slash-stencil)))
2717 (ly:warning "Unable to create slashed digit ~a" num))
2721 (define-markup-command (slashed-digit layout props num)
2724 #:properties ((font-size 0)
2727 @cindex slashed digits
2729 A feta number, with slash. This is for use in the context of
2730 figured bass notation.
2731 @lilypond[verbatim,quote]
2735 \\override #'(thickness . 3)
2739 (slashed-digit-internal layout props num #t font-size thickness))
2741 (define-markup-command (backslashed-digit layout props num)
2744 #:properties ((font-size 0)
2747 @cindex backslashed digits
2749 A feta number, with backslash. This is for use in the context of
2750 figured bass notation.
2751 @lilypond[verbatim,quote]
2753 \\backslashed-digit #5
2755 \\override #'(thickness . 3)
2756 \\backslashed-digit #7
2759 (slashed-digit-internal layout props num #f font-size thickness))
2762 (define eyeglassespath
2763 '((moveto 0.42 0.77)
2764 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2765 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2766 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2767 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2770 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2771 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2772 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2773 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2775 (moveto 1.025 0.935)
2776 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2777 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2780 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2783 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2785 (define-markup-command (eyeglasses layout props)
2788 "Prints out eyeglasses, indicating strongly to look at the conductor.
2789 @lilypond[verbatim,quote]
2790 \\markup { \\eyeglasses }
2792 (interpret-markup layout props
2793 (make-override-markup '(line-cap-style . butt)
2794 (make-path-markup 0.15 eyeglassespath))))
2796 (define-markup-command (left-brace layout props size)
2800 A feta brace in point size @var{size}.
2802 @lilypond[verbatim,quote]
2809 (let* ((font (ly:paper-get-font layout
2810 (cons '((font-encoding . fetaBraces)
2813 (glyph-count (1- (ly:otf-glyph-count font)))
2814 (scale (ly:output-def-lookup layout 'output-scale))
2815 (scaled-size (/ (ly:pt size) scale))
2817 (ly:font-get-glyph font (string-append "brace"
2818 (number->string n)))))
2819 (get-y-from-brace (lambda (brace)
2821 (ly:stencil-extent (glyph brace) Y))))
2822 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2823 (glyph-found (glyph find-brace)))
2825 (if (or (null? (ly:stencil-expr glyph-found))
2826 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2827 (> scaled-size (interval-length
2828 (ly:stencil-extent (glyph glyph-count) Y))))
2830 (ly:warning (_ "no brace found for point size ~S ") size)
2831 (ly:warning (_ "defaulting to ~S pt")
2832 (/ (* scale (interval-length
2833 (ly:stencil-extent glyph-found Y)))
2837 (define-markup-command (right-brace layout props size)
2841 A feta brace in point size @var{size}, rotated 180 degrees.
2843 @lilypond[verbatim,quote]
2850 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2853 ;; the note command.
2854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2856 ;; TODO: better syntax.
2858 (define-markup-command (note-by-number layout props log dot-count dir)
2859 (number? number? number?)
2861 #:properties ((font-size 0)
2864 @cindex notes within text by log and dot-count
2866 Construct a note symbol, with stem. By using fractional values for
2867 @var{dir}, longer or shorter stems can be obtained.
2869 @lilypond[verbatim,quote]
2871 \\note-by-number #3 #0 #DOWN
2873 \\note-by-number #1 #2 #0.8
2876 (define (get-glyph-name-candidates dir log style)
2877 (map (lambda (dir-name)
2878 (format "noteheads.~a~a" dir-name
2879 (if (and (symbol? style)
2880 (not (equal? 'default style)))
2881 (select-head-glyph style (min log 2))
2883 (list (if (= dir UP) "u" "d")
2886 (define (get-glyph-name font cands)
2889 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2890 (get-glyph-name font (cdr cands))
2893 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2895 (size-factor (magstep font-size))
2896 (stem-length (* size-factor (max 3 (- log 1))))
2898 (let ((result (get-glyph-name font (get-glyph-name-candidates
2899 (sign dir) log style))))
2900 (if (string-null? result)
2901 ;; If no glyph name can be found, select default heads. Though
2902 ;; this usually means an unsupported style has been chosen, it
2903 ;; also prevents unrelated 'style settings from other grobs
2904 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2905 (get-glyph-name font (get-glyph-name-candidates
2906 (sign dir) log 'default))
2908 (head-glyph (ly:font-get-glyph font head-glyph-name))
2909 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2910 (stem-thickness (* size-factor 0.13))
2911 (stemy (* dir stem-length))
2912 (attach-off (cons (interval-index
2913 (ly:stencil-extent head-glyph X)
2914 (* (sign dir) (car attach-indices)))
2915 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2917 (ly:stencil-extent head-glyph Y)
2918 (cdr attach-indices)))))
2919 (stem-glyph (and (> log 0)
2920 (ly:round-filled-box
2921 (ordered-cons (car attach-off)
2923 (* (- (sign dir)) stem-thickness)))
2924 (cons (min stemy (cdr attach-off))
2925 (max stemy (cdr attach-off)))
2926 (/ stem-thickness 3))))
2928 (dot (ly:font-get-glyph font "dots.dot"))
2929 (dotwid (interval-length (ly:stencil-extent dot X)))
2930 (dots (and (> dot-count 0)
2931 (apply ly:stencil-add
2933 (ly:stencil-translate-axis
2934 dot (* 2 x dotwid) X))
2935 (iota dot-count)))))
2936 (flaggl (and (> log 2)
2937 (ly:stencil-translate
2938 (ly:font-get-glyph font
2939 (string-append "flags."
2940 (if (> dir 0) "u" "d")
2941 (number->string log)))
2942 (cons (+ (car attach-off) (if (< dir 0)
2946 ;; If there is a flag on an upstem and the stem is short, move the dots
2947 ;; to avoid the flag. 16th notes get a special case because their flags
2948 ;; hang lower than any other flags.
2949 (if (and dots (> dir 0) (> log 2)
2950 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2951 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2953 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2954 (if (ly:stencil? stem-glyph)
2955 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2956 (set! stem-glyph head-glyph))
2957 (if (ly:stencil? dots)
2960 (ly:stencil-translate-axis
2962 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2968 (let ((divisor (log 2)))
2969 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2971 (define (parse-simple-duration duration-string)
2972 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2973 and return a (log dots) list."
2974 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2976 (if (and match (string=? duration-string (match:substring match 0)))
2977 (let ((len (match:substring match 1))
2978 (dots (match:substring match 2)))
2979 (list (cond ((string=? len "breve") -1)
2980 ((string=? len "longa") -2)
2981 ((string=? len "maxima") -3)
2982 (else (log2 (string->number len))))
2983 (if dots (string-length dots) 0)))
2984 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2986 (define-markup-command (note layout props duration dir)
2989 #:properties (note-by-number-markup)
2991 @cindex notes within text by string
2993 This produces a note with a stem pointing in @var{dir} direction, with
2994 the @var{duration} for the note head type and augmentation dots. For
2995 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2996 a shortened down stem.
2998 @lilypond[verbatim,quote]
3000 \\override #'(style . cross) {
3004 \\note #\"breve\" #0
3007 (let ((parsed (parse-simple-duration duration)))
3008 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3014 (define-markup-command (lower layout props amount arg)
3018 @cindex lowering text
3020 Lower @var{arg} by the distance @var{amount}.
3021 A negative @var{amount} indicates raising; see also @code{\\raise}.
3023 @lilypond[verbatim,quote]
3031 (ly:stencil-translate-axis (interpret-markup layout props arg)
3034 (define-markup-command (translate-scaled layout props offset arg)
3035 (number-pair? markup?)
3037 #:properties ((font-size 0))
3039 @cindex translating text
3040 @cindex scaling text
3042 Translate @var{arg} by @var{offset}, scaling the offset by the
3045 @lilypond[verbatim,quote]
3048 * \\translate #'(2 . 3) translate
3050 * \\translate-scaled #'(2 . 3) translate-scaled
3054 (let* ((factor (magstep font-size))
3055 (scaled (cons (* factor (car offset))
3056 (* factor (cdr offset)))))
3057 (ly:stencil-translate (interpret-markup layout props arg)
3060 (define-markup-command (raise layout props amount arg)
3064 @cindex raising text
3066 Raise @var{arg} by the distance @var{amount}.
3067 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3069 The argument to @code{\\raise} is the vertical displacement amount,
3070 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3071 raise objects in relation to their surrounding markups.
3073 If the text object itself is positioned above or below the staff, then
3074 @code{\\raise} cannot be used to move it, since the mechanism that
3075 positions it next to the staff cancels any shift made with
3076 @code{\\raise}. For vertical positioning, use the @code{padding}
3077 and/or @code{extra-offset} properties.
3079 @lilypond[verbatim,quote]
3088 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3090 (define-markup-command (fraction layout props arg1 arg2)
3093 #:properties ((font-size 0))
3095 @cindex creating text fractions
3097 Make a fraction of two markups.
3098 @lilypond[verbatim,quote]
3104 (let* ((m1 (interpret-markup layout props arg1))
3105 (m2 (interpret-markup layout props arg2))
3106 (factor (magstep font-size))
3107 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3108 (padding (* factor 0.2))
3109 (baseline (* factor 0.6))
3110 (offset (* factor 0.75)))
3111 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3112 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3113 (let* ((x1 (ly:stencil-extent m1 X))
3114 (x2 (ly:stencil-extent m2 X))
3115 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3116 ;; should stack mols separately, to maintain LINE on baseline
3117 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3119 (ly:stencil-aligned-to stack Y CENTER))
3121 (ly:stencil-aligned-to stack X LEFT))
3122 ;; should have EX dimension
3124 (ly:stencil-translate-axis stack offset Y))))
3126 (define-markup-command (normal-size-super layout props arg)
3129 #:properties ((baseline-skip))
3131 @cindex setting superscript in standard font size
3133 Set @var{arg} in superscript with a normal font size.
3135 @lilypond[verbatim,quote]
3138 \\normal-size-super {
3139 superscript in standard size
3143 (ly:stencil-translate-axis
3144 (interpret-markup layout props arg)
3145 (* 0.5 baseline-skip) Y))
3147 (define-markup-command (super layout props arg)
3150 #:properties ((font-size 0)
3153 @cindex superscript text
3155 Set @var{arg} in superscript.
3157 @lilypond[verbatim,quote]
3167 (ly:stencil-translate-axis
3170 (cons `((font-size . ,(- font-size 3))) props)
3172 (* 0.5 baseline-skip)
3175 (define-markup-command (translate layout props offset arg)
3176 (number-pair? markup?)
3179 @cindex translating text
3181 Translate @var{arg} relative to its surroundings. @var{offset}
3182 is a pair of numbers representing the displacement in the X and Y axis.
3184 @lilypond[verbatim,quote]
3187 \\translate #'(2 . 3)
3188 \\line { translated two spaces right, three up }
3191 (ly:stencil-translate (interpret-markup layout props arg)
3194 (define-markup-command (sub layout props arg)
3197 #:properties ((font-size 0)
3200 @cindex subscript text
3202 Set @var{arg} in subscript.
3204 @lilypond[verbatim,quote]
3215 (ly:stencil-translate-axis
3218 (cons `((font-size . ,(- font-size 3))) props)
3220 (* -0.5 baseline-skip)
3223 (define-markup-command (normal-size-sub layout props arg)
3226 #:properties ((baseline-skip))
3228 @cindex setting subscript in standard font size
3230 Set @var{arg} in subscript with a normal font size.
3232 @lilypond[verbatim,quote]
3236 subscript in standard size
3240 (ly:stencil-translate-axis
3241 (interpret-markup layout props arg)
3242 (* -0.5 baseline-skip)
3245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3249 (define-markup-command (hbracket layout props arg)
3253 @cindex placing horizontal brackets around text
3255 Draw horizontal brackets around @var{arg}.
3257 @lilypond[verbatim,quote]
3266 (let ((th 0.1) ;; todo: take from GROB.
3267 (m (interpret-markup layout props arg)))
3268 (bracketify-stencil m X th (* 2.5 th) th)))
3270 (define-markup-command (bracket layout props arg)
3274 @cindex placing vertical brackets around text
3276 Draw vertical brackets around @var{arg}.
3278 @lilypond[verbatim,quote]
3285 (let ((th 0.1) ;; todo: take from GROB.
3286 (m (interpret-markup layout props arg)))
3287 (bracketify-stencil m Y th (* 2.5 th) th)))
3289 (define-markup-command (parenthesize layout props arg)
3292 #:properties ((angularity 0)
3298 @cindex placing parentheses around text
3300 Draw parentheses around @var{arg}. This is useful for parenthesizing
3301 a column containing several lines of text.
3303 @lilypond[verbatim,quote]
3312 \\override #'(angularity . 2) {
3323 (let* ((markup (interpret-markup layout props arg))
3324 (scaled-width (* size width))
3326 (* (chain-assoc-get 'line-thickness props 0.1)
3329 (min (* size 0.5 scaled-thickness)
3330 (* (/ 4 3.0) scaled-width)))
3331 (padding (chain-assoc-get 'padding props half-thickness)))
3332 (parenthesize-stencil
3333 markup half-thickness scaled-width angularity padding)))
3336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3337 ;; Delayed markup evaluation
3338 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3340 (define-markup-command (page-ref layout props label gauge default)
3341 (symbol? markup? markup?)
3344 @cindex referencing page numbers in text
3346 Reference to a page number. @var{label} is the label set on the referenced
3347 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3348 the maximum width of the page number, and @var{default} the value to display
3349 when @var{label} is not found."
3350 (let* ((gauge-stencil (interpret-markup layout props gauge))
3351 (x-ext (ly:stencil-extent gauge-stencil X))
3352 (y-ext (ly:stencil-extent gauge-stencil Y)))
3354 `(delay-stencil-evaluation
3355 ,(delay (ly:stencil-expr
3356 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3357 (page-number (if (list? table)
3358 (assoc-get label table)
3360 (page-markup (if page-number (format "~a" page-number) default))
3361 (page-stencil (interpret-markup layout props page-markup))
3362 (gap (- (interval-length x-ext)
3363 (interval-length (ly:stencil-extent page-stencil X)))))
3364 (interpret-markup layout props
3365 (markup #:concat (#:hspace gap page-markup)))))))
3369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3370 ;; Markup list commands
3371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3373 (define-public (space-lines baseline stils)
3374 (let space-stil ((stils stils)
3378 (let* ((stil (car stils))
3379 (dy-top (max (- (/ baseline 1.5)
3380 (interval-bound (ly:stencil-extent stil Y) UP))
3382 (dy-bottom (max (+ (/ baseline 3.0)
3383 (interval-bound (ly:stencil-extent stil Y) DOWN))
3385 (new-stil (ly:make-stencil
3386 (ly:stencil-expr stil)
3387 (ly:stencil-extent stil X)
3388 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3390 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3392 (space-stil (cdr stils) (cons new-stil result))))))
3394 (define-markup-list-command (justified-lines layout props args)
3396 #:properties ((baseline-skip)
3397 wordwrap-internal-markup-list)
3399 @cindex justifying lines of text
3401 Like @code{\\justify}, but return a list of lines instead of a single markup.
3402 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3403 @var{X}@tie{}is the number of staff spaces."
3404 (space-lines baseline-skip
3405 (interpret-markup-list layout props
3406 (make-wordwrap-internal-markup-list #t args))))
3408 (define-markup-list-command (wordwrap-lines layout props args)
3410 #:properties ((baseline-skip)
3411 wordwrap-internal-markup-list)
3412 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3413 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3414 where @var{X} is the number of staff spaces."
3415 (space-lines baseline-skip
3416 (interpret-markup-list layout props
3417 (make-wordwrap-internal-markup-list #f args))))
3419 (define-markup-list-command (column-lines layout props args)
3421 #:properties ((baseline-skip))
3422 "Like @code{\\column}, but return a list of lines instead of a single markup.
3423 @code{baseline-skip} determines the space between each markup in @var{args}."
3424 (space-lines baseline-skip
3425 (interpret-markup-list layout props args)))
3427 (define-markup-list-command (override-lines layout props new-prop args)
3428 (pair? markup-list?)
3429 "Like @code{\\override}, for markup lists."
3430 (interpret-markup-list layout (cons (list new-prop) props) args))