1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2011 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.
49 ;;; There is no limitation on the order of command arguments.
50 ;;; However, markup functions taking a markup as their last
51 ;;; argument are somewhat special as you can apply them to a
52 ;;; markup list, and the result is a markup list where the
53 ;;; markup function (with the specified leading arguments) has
54 ;;; been applied to every element of the original markup list.
56 ;;; Since replicating the leading arguments for applying a
57 ;;; markup function to a markup list is cheap mostly for
58 ;;; Scheme arguments, you avoid performance pitfalls by just
59 ;;; using Scheme arguments for the leading arguments of markup
60 ;;; functions that take a markup as their last argument.
63 ;;; the arguments signature, i.e. a list of type predicates which
64 ;;; are used to type check the arguments, and also to define the general
65 ;;; argument types (markup, markup-list, scheme) that the command is
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
71 ;;; for documentation purpose, builtin markup commands are grouped by
72 ;;; category. This can be any symbol. When documentation is generated,
73 ;;; the symbol is converted to a capitalized string, where hyphens are
74 ;;; replaced by spaces.
77 ;;; this is used both for documentation generation, and to ease
78 ;;; programming the command itself. It is list of
79 ;;; (property-name default-value)
80 ;;; or (property-name)
81 ;;; elements. Each property is looked-up in the `props' argument, and
82 ;;; the symbol naming the property is bound to its value.
83 ;;; When the property is not found in `props', then the symbol is bound
84 ;;; to the given default value. When no default value is given, #f is
86 ;;; Thus, using the following property bindings:
89 ;;; is equivalent to writing:
90 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;; (font-size (chain-assoc-get 'font-size props 0)))
93 ;;; When a command `B' internally calls an other command `A', it may
94 ;;; desirable to see in `B' documentation all the properties and
95 ;;; default values used by `A'. In that case, add `A-markup' to the
96 ;;; property-bindings of B. (This is used when generating
97 ;;; documentation, but won't create bindings.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
115 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 (define-markup-command (draw-line layout props dest)
124 #:properties ((thickness 1))
126 @cindex drawing lines within text
129 @lilypond[verbatim,quote]
131 \\draw-line #'(4 . 4)
132 \\override #'(thickness . 5)
133 \\draw-line #'(-3 . 0)
136 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
140 (make-line-stencil th 0 0 x y)))
142 (define-markup-command (draw-circle layout props radius thickness filled)
143 (number? number? boolean?)
146 @cindex drawing circles within text
148 A circle of radius @var{radius} and thickness @var{thickness},
151 @lilypond[verbatim,quote]
153 \\draw-circle #2 #0.5 ##f
155 \\draw-circle #2 #0 ##t
158 (make-circle-stencil radius thickness filled))
160 (define-markup-command (triangle layout props filled)
163 #:properties ((thickness 0.1)
167 @cindex drawing triangles within text
169 A triangle, either filled or empty.
171 @lilypond[verbatim,quote]
178 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
187 (cons 0 (* .86 ex)))))
189 (define-markup-command (circle layout props arg)
192 #:properties ((thickness 1)
194 (circle-padding 0.2))
196 @cindex circling text
198 Draw a circle around @var{arg}. Use @code{thickness},
199 @code{circle-padding} and @code{font-size} properties to determine line
200 thickness and padding around the markup.
202 @lilypond[verbatim,quote]
209 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
211 (pad (* (magstep font-size) circle-padding))
212 (m (interpret-markup layout props arg)))
213 (circle-stencil m th pad)))
215 (define-markup-command (with-url layout props url arg)
219 @cindex inserting URL links into text
221 Add a link to URL @var{url} around @var{arg}. This only works in
224 @lilypond[verbatim,quote]
226 \\with-url #\"http://lilypond.org/web/\" {
227 LilyPond ... \\italic {
228 music notation for everyone
233 (let* ((stil (interpret-markup layout props arg))
234 (xextent (ly:stencil-extent stil X))
235 (yextent (ly:stencil-extent stil Y))
236 (old-expr (ly:stencil-expr stil))
237 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
239 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
241 (define-markup-command (beam layout props width slope thickness)
242 (number? number? number?)
245 @cindex drawing beams within text
247 Create a beam with the specified parameters.
248 @lilypond[verbatim,quote]
253 (let* ((y (* slope width))
254 (yext (cons (min 0 y) (max 0 y)))
255 (half (/ thickness 2)))
260 width (+ (* width slope) (/ thickness -2))
261 width (+ (* width slope) (/ thickness 2))
263 ,(ly:output-def-lookup layout 'blot-diameter)
266 (cons (+ (- half) (car yext))
267 (+ half (cdr yext))))))
269 (define-markup-command (underline layout props arg)
272 #:properties ((thickness 1) (offset 2))
274 @cindex underlining text
276 Underline @var{arg}. Looks at @code{thickness} to determine line
277 thickness, and @code{offset} to determine line y-offset.
279 @lilypond[verbatim,quote]
280 \\markup \\fill-line {
281 \\underline \"underlined\"
282 \\override #'(offset . 5)
283 \\override #'(thickness . 1)
284 \\underline \"underlined\"
285 \\override #'(offset . 1)
286 \\override #'(thickness . 5)
287 \\underline \"underlined\"
290 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
291 (underline-thick (* thickness thick))
292 (markup (interpret-markup layout props arg))
293 (x1 (car (ly:stencil-extent markup X)))
294 (x2 (cdr (ly:stencil-extent markup X)))
295 (y (* thick (- offset)))
296 (line (make-line-stencil underline-thick x1 y x2 y)))
297 (ly:stencil-add markup line)))
299 (define-markup-command (box layout props arg)
302 #:properties ((thickness 1)
306 @cindex enclosing text within a box
308 Draw a box round @var{arg}. Looks at @code{thickness},
309 @code{box-padding} and @code{font-size} properties to determine line
310 thickness and padding around the markup.
312 @lilypond[verbatim,quote]
314 \\override #'(box-padding . 0.5)
319 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
321 (pad (* (magstep font-size) box-padding))
322 (m (interpret-markup layout props arg)))
323 (box-stencil m th pad)))
325 (define-markup-command (filled-box layout props xext yext blot)
326 (number-pair? number-pair? number?)
329 @cindex drawing solid boxes within text
330 @cindex drawing boxes with rounded corners
332 Draw a box with rounded corners of dimensions @var{xext} and
333 @var{yext}. For example,
335 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
337 creates a box extending horizontally from -0.3 to 1.8 and
338 vertically from -0.3 up to 1.8, with corners formed from a
339 circle of diameter@tie{}0 (i.e., sharp corners).
341 @lilypond[verbatim,quote]
343 \\filled-box #'(0 . 4) #'(0 . 4) #0
344 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
345 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
347 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
353 (define-markup-command (rounded-box layout props arg)
356 #:properties ((thickness 1)
360 "@cindex enclosing text in a box with rounded corners
361 @cindex drawing boxes with rounded corners around text
362 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
363 @code{box-padding} and @code{font-size} properties to determine line
364 thickness and padding around the markup; the @code{corner-radius} property
365 makes it possible to define another shape for the corners (default is 1).
367 @lilypond[quote,verbatim,relative=2]
375 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
377 (pad (* (magstep font-size) box-padding))
378 (m (interpret-markup layout props arg)))
379 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
382 (define-markup-command (rotate layout props ang arg)
386 @cindex rotating text
388 Rotate object with @var{ang} degrees around its center.
390 @lilypond[verbatim,quote]
400 (let* ((stil (interpret-markup layout props arg)))
401 (ly:stencil-rotate stil ang 0 0)))
403 (define-markup-command (whiteout layout props arg)
407 @cindex adding a white background to text
409 Provide a white background for @var{arg}.
411 @lilypond[verbatim,quote]
414 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
418 (stencil-whiteout (interpret-markup layout props arg)))
420 (define-markup-command (pad-markup layout props amount arg)
425 @cindex putting space around text
427 Add space around a markup object.
429 @lilypond[verbatim,quote]
443 ((stil (interpret-markup layout props arg))
444 (xext (ly:stencil-extent stil X))
445 (yext (ly:stencil-extent stil Y)))
448 (ly:stencil-expr stil)
449 (interval-widen xext amount)
450 (interval-widen yext amount))))
452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
454 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
456 (define-markup-command (strut layout props)
460 @cindex creating vertical spaces in text
462 Create a box of the same height as the space in the current font."
463 (let ((m (ly:text-interface::interpret-markup layout props " ")))
464 (ly:make-stencil (ly:stencil-expr m)
466 (ly:stencil-extent m X)
469 ;; todo: fix negative space
470 (define-markup-command (hspace layout props amount)
473 #:properties ((word-space))
475 @cindex creating horizontal spaces in text
477 Create an invisible object taking up horizontal space @var{amount}.
479 @lilypond[verbatim,quote]
488 (let ((corrected-space (- amount word-space)))
489 (if (> corrected-space 0)
490 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
491 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
493 ;; todo: fix negative space
494 (define-markup-command (vspace layout props amount)
498 @cindex creating vertical spaces in text
500 Create an invisible object taking up vertical space
501 of @var{amount} multiplied by 3.
503 @lilypond[verbatim,quote]
514 (let ((amount (* amount 3.0)))
516 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
517 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
520 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
521 ;; importing graphics.
522 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
524 (define-markup-command (stencil layout props stil)
528 @cindex importing stencils into text
530 Use a stencil as markup.
532 @lilypond[verbatim,quote]
534 \\stencil #(make-circle-stencil 2 0 #t)
540 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
542 (define (get-postscript-bbox string)
543 "Extract the bbox from STRING, or return #f if not present."
545 ((match (regexp-exec bbox-regexp string)))
549 (string->number (match:substring match x)))
554 (define-markup-command (epsfile layout props axis size file-name)
555 (number? number? string?)
558 @cindex inlining an Encapsulated PostScript image
560 Inline an EPS image. The image is scaled along @var{axis} to
563 @lilypond[verbatim,quote]
565 \\general-align #Y #DOWN {
566 \\epsfile #X #20 #\"context-example.eps\"
567 \\epsfile #Y #20 #\"context-example.eps\"
571 (if (ly:get-option 'safe)
572 (interpret-markup layout props "not allowed in safe")
573 (eps-file->stencil axis size file-name)
576 (define-markup-command (postscript layout props str)
580 @cindex inserting PostScript directly into text
581 This inserts @var{str} directly into the output as a PostScript
584 @lilypond[verbatim,quote]
588 0.4 0.6 0.5 0 361 arc
590 1.0 0.6 0.5 0 361 arc
595 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
596 \\postscript #ringsps
608 gsave currentpoint translate
616 (define-markup-command (path layout props thickness commands) (number? list?)
618 #:properties ((line-cap-style 'round)
619 (line-join-style 'round)
622 @cindex paths, drawing
623 @cindex drawing paths
624 Draws a path with line thickness @var{thickness} according to the
625 directions given in @var{commands}. @var{commands} is a list of
626 lists where the @code{car} of each sublist is a drawing command and
627 the @code{cdr} comprises the associated arguments for each command.
629 Line-cap styles and line-join styles may be customized by
630 overriding the @code{line-cap-style} and @code{line-join-style}
631 properties, respectively. Available line-cap styles are
632 @code{'butt}, @code{'round}, and @code{'square}. Available
633 line-join styles are @code{'miter}, @code{'round}, and
636 The property @code{filled} specifies whether or not the path is
639 There are seven commands available to use in the list
640 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
641 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
642 @code{closepath}. Note that the commands that begin with @emph{r}
643 are the relative variants of the other three commands.
645 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
646 @code{rlineto} take 2 arguments; they are the X and Y coordinates
647 for the destination point.
649 The commands @code{curveto} and @code{rcurveto} create cubic
650 Bézier curves, and take 6 arguments; the first two are the X and Y
651 coordinates for the first control point, the second two are the X
652 and Y coordinates for the second control point, and the last two
653 are the X and Y coordinates for the destination point.
655 The @code{closepath} command takes zero arguments and closes the
656 current subpath in the active path.
658 Note that a sequence of commands @emph{must} begin with a
659 @code{moveto} or @code{rmoveto} to work with the SVG output.
661 @lilypond[verbatim,quote]
667 (curveto -5 -5 -5 5 -1 0)
671 \\path #0.25 #samplePath
674 (let* ((half-thickness (/ thickness 2))
675 (current-point '(0 . 0))
676 (set-point (lambda (lst) (set! current-point lst)))
677 (relative? (lambda (x)
678 (string-prefix? "r" (symbol->string (car x)))))
679 ;; For calculating extents, we want to modify the command
680 ;; list so that all coordinates are absolute.
681 (new-commands (map (lambda (x)
683 ;; for rmoveto, rlineto
684 ((and (relative? x) (eq? 3 (length x)))
686 (+ (car current-point)
688 (+ (cdr current-point)
694 ((and (relative? x) (eq? 7 (length x)))
695 (let* ((old-cp current-point)
702 (list (+ (car old-cp) (second x))
703 (+ (cdr old-cp) (third x))
704 (+ (car old-cp) (fourth x))
705 (+ (cdr old-cp) (fifth x))
708 ;; for moveto, lineto
710 (set-point (cons (second x)
715 (set-point (cons (sixth x)
718 ;; keep closepath for filtering;
719 ;; see `without-closepath'.
722 ;; path-min-max does not accept 0-arg lists,
723 ;; and since closepath does not affect extents, filter
724 ;; out those commands here.
725 (without-closepath (filter (lambda (x)
726 (not (equal? 'closepath (car x))))
728 (extents (path-min-max
729 ;; set the origin to the first moveto
730 (list (list-ref (car without-closepath) 0)
731 (list-ref (car without-closepath) 1))
733 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
734 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
735 (command-list (fold-right append '() commands)))
737 ;; account for line thickness
738 (set! X-extent (interval-widen X-extent half-thickness))
739 (set! Y-extent (interval-widen Y-extent half-thickness))
742 `(path ,thickness `(,@',command-list)
743 ',line-cap-style ',line-join-style ,filled)
747 (define-markup-command (score layout props score)
750 #:properties ((baseline-skip))
752 @cindex inserting music into text
754 Inline an image of music.
756 @lilypond[verbatim,quote]
760 \\new Staff \\relative c' {
763 \\mark \\markup { Allegro }
769 \\new Staff \\relative c {
783 \\override RehearsalMark #'break-align-symbols =
784 #'(time-signature key-signature)
785 \\override RehearsalMark #'self-alignment-X = #LEFT
789 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
795 (let ((output (ly:score-embedded-format score layout)))
797 (if (ly:music-output? output)
798 (stack-stencils Y DOWN baseline-skip
799 (map paper-system-stencil
801 (ly:paper-score-paper-systems output))))
803 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
806 (define-markup-command (null layout props)
810 @cindex creating empty text objects
812 An empty markup with extents of a single point.
814 @lilypond[verbatim,quote]
821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
825 (define-markup-command (simple layout props str)
829 @cindex simple text strings
831 A simple text string; @code{\\markup @{ foo @}} is equivalent with
832 @code{\\markup @{ \\simple #\"foo\" @}}.
834 Note: for creating standard text markup or defining new markup commands,
835 the use of @code{\\simple} is unnecessary.
837 @lilypond[verbatim,quote]
841 \\simple #\"strings\"
844 (interpret-markup layout props str))
846 (define-markup-command (tied-lyric layout props str)
850 @cindex simple text strings with tie characters
852 Like simple-markup, but use tie characters for @q{~} tilde symbols.
854 @lilypond[verbatim,quote]
856 \\tied-lyric #\"Lasciate~i monti\"
859 (if (string-contains str "~")
861 ((parts (string-split str #\~))
862 (tie-str (ly:wide-char->utf-8 #x203f))
863 (joined (list-join parts tie-str))
864 (join-stencil (interpret-markup layout props tie-str))
867 (interpret-markup layout
870 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
872 (make-line-markup joined)))
873 ;(map (lambda (s) (interpret-markup layout props s)) parts))
874 (interpret-markup layout props str)))
876 (define-public empty-markup
877 (make-simple-markup ""))
879 ;; helper for justifying lines.
880 (define (get-fill-space word-count line-width word-space text-widths)
881 "Calculate the necessary paddings between each two adjacent texts.
882 The lengths of all texts are stored in @var{text-widths}.
883 The normal formula for the padding between texts a and b is:
884 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
885 The first and last padding have to be calculated specially using the
886 whole length of the first or last text.
887 All paddings are checked to be at least word-space, to ensure that
889 Return a list of paddings."
891 ((null? text-widths) '())
893 ;; special case first padding
894 ((= (length text-widths) word-count)
896 (- (- (/ line-width (1- word-count)) (car text-widths))
897 (/ (car (cdr text-widths)) 2))
898 (get-fill-space word-count line-width word-space (cdr text-widths))))
899 ;; special case last padding
900 ((= (length text-widths) 2)
901 (list (- (/ line-width (1- word-count))
902 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
904 (let ((default-padding
905 (- (/ line-width (1- word-count))
906 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
908 (if (> word-space default-padding)
911 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
913 (define-markup-command (fill-line layout props args)
916 #:properties ((text-direction RIGHT)
919 "Put @var{markups} in a horizontal line of width @var{line-width}.
920 The markups are spaced or flushed to fill the entire line.
921 If there are no arguments, return an empty stencil.
923 @lilypond[verbatim,quote]
927 Words evenly spaced across the page
931 \\line { Text markups }
933 \\italic { evenly spaced }
935 \\line { across the page }
940 (let* ((orig-stencils (interpret-markup-list layout props args))
943 (if (ly:stencil-empty? stc)
945 stc)) orig-stencils))
948 (if (ly:stencil-empty? stc)
950 (interval-length (ly:stencil-extent stc X))))
952 (text-width (apply + text-widths))
953 (word-count (length stencils))
954 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
959 (/ (- line-width text-width) 2)
960 (/ (- line-width text-width) 2)))
963 (- line-width text-width)))
965 (get-fill-space word-count line-width word-space text-widths))))
967 (line-contents (if (= word-count 1)
974 (if (null? (remove ly:stencil-empty? orig-stencils))
977 (if (= text-direction LEFT)
978 (set! line-contents (reverse line-contents)))
980 (stack-stencils-padding-list
981 X RIGHT fill-space line-contents))
983 ;; shift s.t. stencils align on the left edge, even if
984 ;; first stencil had negative X-extent (e.g. center-column)
985 ;; (if word-count = 1, X-extents are already normalized in
986 ;; the definition of line-contents)
988 (ly:stencil-translate-axis
990 (- (car (ly:stencil-extent (car stencils) X)))
994 (define-markup-command (line layout props args)
997 #:properties ((word-space)
998 (text-direction RIGHT))
999 "Put @var{args} in a horizontal line. The property @code{word-space}
1000 determines the space between markups in @var{args}.
1002 @lilypond[verbatim,quote]
1009 (let ((stencils (interpret-markup-list layout props args)))
1010 (if (= text-direction LEFT)
1011 (set! stencils (reverse stencils)))
1014 (remove ly:stencil-empty? stencils))))
1016 (define-markup-command (concat layout props args)
1020 @cindex concatenating text
1021 @cindex ligatures in text
1023 Concatenate @var{args} in a horizontal line, without spaces in between.
1024 Strings and simple markups are concatenated on the input level, allowing
1025 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1026 equivalent to @code{\"fi\"}.
1028 @lilypond[verbatim,quote]
1037 (define (concat-string-args arg-list)
1038 (fold-right (lambda (arg result-list)
1039 (let ((result (if (pair? result-list)
1042 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1043 (set! arg (cadr arg)))
1044 (if (and (string? result) (string? arg))
1045 (cons (string-append arg result) (cdr result-list))
1046 (cons arg result-list))))
1050 (interpret-markup layout
1051 (prepend-alist-chain 'word-space 0 props)
1052 (make-line-markup (if (markup-command-list? args)
1054 (concat-string-args args)))))
1056 (define (wordwrap-stencils stencils
1057 justify base-space line-width text-dir)
1058 "Perform simple wordwrap, return stencil of each line."
1059 (define space (if justify
1060 ;; justify only stretches lines.
1063 (define (take-list width space stencils
1064 accumulator accumulated-width)
1065 "Return (head-list . tail) pair, with head-list fitting into width"
1066 (if (null? stencils)
1067 (cons accumulator stencils)
1068 (let* ((first (car stencils))
1069 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1070 (newwid (+ space first-wid accumulated-width)))
1071 (if (or (null? accumulator)
1073 (take-list width space
1075 (cons first accumulator)
1077 (cons accumulator stencils)))))
1078 (let loop ((lines '())
1080 (let* ((line-break (take-list line-width space todo
1082 (line-stencils (car line-break))
1083 (space-left (- line-width
1084 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1086 (line-word-space (cond ((not justify) space)
1087 ;; don't stretch last line of paragraph.
1088 ;; hmmm . bug - will overstretch the last line in some case.
1089 ((null? (cdr line-break))
1091 ((null? line-stencils) 0.0)
1092 ((null? (cdr line-stencils)) 0.0)
1093 (else (/ space-left (1- (length line-stencils))))))
1094 (line (stack-stencil-line line-word-space
1095 (if (= text-dir RIGHT)
1096 (reverse line-stencils)
1098 (if (pair? (cdr line-break))
1099 (loop (cons line lines)
1102 (if (= text-dir LEFT)
1104 (ly:stencil-translate-axis
1106 (- line-width (interval-end (ly:stencil-extent line X)))
1108 (reverse (cons line lines)))))))
1110 (define-markup-list-command (wordwrap-internal layout props justify args)
1111 (boolean? markup-list?)
1112 #:properties ((line-width #f)
1114 (text-direction RIGHT))
1115 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1116 (wordwrap-stencils (remove ly:stencil-empty?
1117 (interpret-markup-list layout props args))
1121 (ly:output-def-lookup layout 'line-width))
1124 (define-markup-command (justify layout props args)
1127 #:properties ((baseline-skip)
1128 wordwrap-internal-markup-list)
1130 @cindex justifying text
1132 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1133 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1134 @var{X}@tie{}is the number of staff spaces.
1136 @lilypond[verbatim,quote]
1139 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1140 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1141 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1142 laboris nisi ut aliquip ex ea commodo consequat.
1146 (stack-lines DOWN 0.0 baseline-skip
1147 (wordwrap-internal-markup-list layout props #t args)))
1149 (define-markup-command (wordwrap layout props args)
1152 #:properties ((baseline-skip)
1153 wordwrap-internal-markup-list)
1154 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1155 the line width, where @var{X} is the number of staff spaces.
1157 @lilypond[verbatim,quote]
1160 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1161 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1162 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1163 laboris nisi ut aliquip ex ea commodo consequat.
1167 (stack-lines DOWN 0.0 baseline-skip
1168 (wordwrap-internal-markup-list layout props #f args)))
1170 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1172 #:properties ((line-width)
1174 (text-direction RIGHT))
1175 "Internal markup list command used to define @code{\\justify-string} and
1176 @code{\\wordwrap-string}."
1177 (let* ((para-strings (regexp-split
1178 (string-regexp-substitute
1180 (string-regexp-substitute "\r\n" "\n" arg))
1181 "\n[ \t\n]*\n[ \t\n]*"))
1182 (list-para-words (map (lambda (str)
1183 (regexp-split str "[ \t\n]+"))
1185 (para-lines (map (lambda (words)
1187 (remove ly:stencil-empty?
1189 (interpret-markup layout props x))
1191 (wordwrap-stencils stencils
1193 line-width text-direction)))
1195 (apply append para-lines)))
1197 (define-markup-command (wordwrap-string layout props arg)
1200 #:properties ((baseline-skip)
1201 wordwrap-string-internal-markup-list)
1202 "Wordwrap a string. Paragraphs may be separated with double newlines.
1204 @lilypond[verbatim,quote]
1206 \\override #'(line-width . 40)
1207 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1208 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1209 et dolore magna aliqua.
1212 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1213 laboris nisi ut aliquip ex ea commodo consequat.
1216 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1217 qui officia deserunt mollit anim id est laborum\"
1220 (stack-lines DOWN 0.0 baseline-skip
1221 (wordwrap-string-internal-markup-list layout props #f arg)))
1223 (define-markup-command (justify-string layout props arg)
1226 #:properties ((baseline-skip)
1227 wordwrap-string-internal-markup-list)
1228 "Justify a string. Paragraphs may be separated with double newlines
1230 @lilypond[verbatim,quote]
1232 \\override #'(line-width . 40)
1233 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1234 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1235 et dolore magna aliqua.
1238 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1239 laboris nisi ut aliquip ex ea commodo consequat.
1242 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1243 qui officia deserunt mollit anim id est laborum\"
1246 (stack-lines DOWN 0.0 baseline-skip
1247 (wordwrap-string-internal-markup-list layout props #t arg)))
1249 (define-markup-command (wordwrap-field layout props symbol)
1252 "Wordwrap the data which has been assigned to @var{symbol}.
1254 @lilypond[verbatim,quote]
1256 title = \"My title\"
1257 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1258 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1259 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1260 laboris nisi ut aliquip ex ea commodo consequat.\"
1264 bookTitleMarkup = \\markup {
1266 \\fill-line { \\fromproperty #'header:title }
1268 \\wordwrap-field #'header:myText
1277 (let* ((m (chain-assoc-get symbol props)))
1279 (wordwrap-string-markup layout props m)
1282 (define-markup-command (justify-field layout props symbol)
1285 "Justify the data which has been assigned to @var{symbol}.
1287 @lilypond[verbatim,quote]
1289 title = \"My title\"
1290 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1291 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1292 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1293 laboris nisi ut aliquip ex ea commodo consequat.\"
1297 bookTitleMarkup = \\markup {
1299 \\fill-line { \\fromproperty #'header:title }
1301 \\justify-field #'header:myText
1310 (let* ((m (chain-assoc-get symbol props)))
1312 (justify-string-markup layout props m)
1315 (define-markup-command (combine layout props arg1 arg2)
1319 @cindex merging text
1321 Print two markups on top of each other.
1323 Note: @code{\\combine} cannot take a list of markups enclosed in
1324 curly braces as an argument; the follow example will not compile:
1327 \\combine @{ a list @}
1330 @lilypond[verbatim,quote]
1333 \\override #'(thickness . 2)
1335 \\draw-line #'(0 . 4)
1336 \\arrow-head #Y #DOWN ##f
1339 (let* ((s1 (interpret-markup layout props arg1))
1340 (s2 (interpret-markup layout props arg2)))
1341 (ly:stencil-add s1 s2)))
1344 ;; TODO: should extract baseline-skip from each argument somehow..
1346 (define-markup-command (column layout props args)
1349 #:properties ((baseline-skip))
1351 @cindex stacking text in a column
1353 Stack the markups in @var{args} vertically. The property
1354 @code{baseline-skip} determines the space between markups
1357 @lilypond[verbatim,quote]
1366 (let ((arg-stencils (interpret-markup-list layout props args)))
1367 (stack-lines -1 0.0 baseline-skip
1368 (remove ly:stencil-empty? arg-stencils))))
1370 (define-markup-command (dir-column layout props args)
1373 #:properties ((direction)
1376 @cindex changing direction of text columns
1378 Make a column of @var{args}, going up or down, depending on the
1379 setting of the @code{direction} layout property.
1381 @lilypond[verbatim,quote]
1383 \\override #`(direction . ,UP) {
1393 \\override #'(direction . 1) {
1400 (stack-lines (if (number? direction) direction -1)
1403 (interpret-markup-list layout props args)))
1405 (define (general-column align-dir baseline mols)
1406 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1408 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1409 (stack-lines -1 0.0 baseline aligned-mols)))
1411 (define-markup-command (center-column layout props args)
1414 #:properties ((baseline-skip))
1416 @cindex centering a column of text
1418 Put @code{args} in a centered column.
1420 @lilypond[verbatim,quote]
1429 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1431 (define-markup-command (left-column layout props args)
1434 #:properties ((baseline-skip))
1436 @cindex text columns, left-aligned
1438 Put @code{args} in a left-aligned column.
1440 @lilypond[verbatim,quote]
1449 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1451 (define-markup-command (right-column layout props args)
1454 #:properties ((baseline-skip))
1456 @cindex text columns, right-aligned
1458 Put @code{args} in a right-aligned column.
1460 @lilypond[verbatim,quote]
1469 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1471 (define-markup-command (vcenter layout props arg)
1475 @cindex vertically centering text
1477 Align @code{arg} to its Y@tie{}center.
1479 @lilypond[verbatim,quote]
1487 (let* ((mol (interpret-markup layout props arg)))
1488 (ly:stencil-aligned-to mol Y CENTER)))
1490 (define-markup-command (center-align layout props arg)
1494 @cindex horizontally centering text
1496 Align @code{arg} to its X@tie{}center.
1498 @lilypond[verbatim,quote]
1508 (let* ((mol (interpret-markup layout props arg)))
1509 (ly:stencil-aligned-to mol X CENTER)))
1511 (define-markup-command (right-align layout props arg)
1515 @cindex right aligning text
1517 Align @var{arg} on its right edge.
1519 @lilypond[verbatim,quote]
1529 (let* ((m (interpret-markup layout props arg)))
1530 (ly:stencil-aligned-to m X RIGHT)))
1532 (define-markup-command (left-align layout props arg)
1536 @cindex left aligning text
1538 Align @var{arg} on its left edge.
1540 @lilypond[verbatim,quote]
1550 (let* ((m (interpret-markup layout props arg)))
1551 (ly:stencil-aligned-to m X LEFT)))
1553 (define-markup-command (general-align layout props axis dir arg)
1554 (integer? number? markup?)
1557 @cindex controlling general text alignment
1559 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1561 @lilypond[verbatim,quote]
1565 \\general-align #X #LEFT
1570 \\general-align #X #CENTER
1576 \\general-align #Y #UP
1583 \\general-align #Y #3.2
1590 (let* ((m (interpret-markup layout props arg)))
1591 (ly:stencil-aligned-to m axis dir)))
1593 (define-markup-command (halign layout props dir arg)
1597 @cindex setting horizontal text alignment
1599 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1600 left-aligned, while @code{+1} is right. Values in between interpolate
1601 alignment accordingly.
1603 @lilypond[verbatim,quote]
1628 (let* ((m (interpret-markup layout props arg)))
1629 (ly:stencil-aligned-to m X dir)))
1631 (define-markup-command (with-dimensions layout props x y arg)
1632 (number-pair? number-pair? markup?)
1635 @cindex setting extent of text objects
1637 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1638 (let* ((m (interpret-markup layout props arg)))
1639 (ly:make-stencil (ly:stencil-expr m) x y)))
1641 (define-markup-command (pad-around layout props amount arg)
1644 "Add padding @var{amount} all around @var{arg}.
1646 @lilypond[verbatim,quote]
1659 (let* ((m (interpret-markup layout props arg))
1660 (x (ly:stencil-extent m X))
1661 (y (ly:stencil-extent m Y)))
1662 (ly:make-stencil (ly:stencil-expr m)
1663 (interval-widen x amount)
1664 (interval-widen y amount))))
1666 (define-markup-command (pad-x layout props amount arg)
1670 @cindex padding text horizontally
1672 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1674 @lilypond[verbatim,quote]
1687 (let* ((m (interpret-markup layout props arg))
1688 (x (ly:stencil-extent m X))
1689 (y (ly:stencil-extent m Y)))
1690 (ly:make-stencil (ly:stencil-expr m)
1691 (interval-widen x amount)
1694 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1695 (integer? ly:dir? markup? markup?)
1697 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1698 (let ((m1 (interpret-markup layout props arg1))
1699 (m2 (interpret-markup layout props arg2)))
1700 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1702 (define-markup-command (transparent layout props arg)
1705 "Make @var{arg} transparent.
1707 @lilypond[verbatim,quote]
1714 (let* ((m (interpret-markup layout props arg))
1715 (x (ly:stencil-extent m X))
1716 (y (ly:stencil-extent m Y)))
1717 (ly:make-stencil "" x y)))
1719 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1720 (number-pair? number-pair? markup?)
1722 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1724 @lilypond[verbatim,quote]
1731 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1737 (let* ((m (interpret-markup layout props arg))
1738 (x (ly:stencil-extent m X))
1739 (y (ly:stencil-extent m Y)))
1740 (ly:make-stencil (ly:stencil-expr m)
1741 (interval-union x-ext x)
1742 (interval-union y-ext y))))
1744 (define-markup-command (hcenter-in layout props length arg)
1747 "Center @var{arg} horizontally within a box of extending
1748 @var{length}/2 to the left and right.
1750 @lilypond[quote,verbatim]
1753 \\set Staff.instrumentName = \\markup {
1760 \\set Staff.instrumentName = \\markup {
1769 (interpret-markup layout props
1770 (make-pad-to-box-markup
1771 (cons (/ length -2) (/ length 2))
1773 (make-center-align-markup arg))))
1775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1779 (define-markup-command (fromproperty layout props symbol)
1782 "Read the @var{symbol} from property settings, and produce a stencil
1783 from the markup contained within. If @var{symbol} is not defined, it
1784 returns an empty markup.
1786 @lilypond[verbatim,quote]
1788 myTitle = \"myTitle\"
1792 \\fromproperty #'header:myTitle
1799 (let ((m (chain-assoc-get symbol props)))
1801 (interpret-markup layout props m)
1804 (define-markup-command (on-the-fly layout props procedure arg)
1807 "Apply the @var{procedure} markup command to @var{arg}.
1808 @var{procedure} should take a single argument."
1809 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1810 (set-object-property! anonymous-with-signature
1813 (interpret-markup layout props (list anonymous-with-signature arg))))
1815 (define-markup-command (override layout props new-prop arg)
1819 @cindex overriding properties within text markup
1821 Add the argument @var{new-prop} to the property list. Properties
1822 may be any property supported by @rinternals{font-interface},
1823 @rinternals{text-interface} and
1824 @rinternals{instrument-specific-markup-interface}.
1826 @lilypond[verbatim,quote]
1834 \\override #'(baseline-skip . 4) {
1843 (interpret-markup layout (cons (list new-prop) props) arg))
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1849 (define-markup-command (verbatim-file layout props name)
1852 "Read the contents of file @var{name}, and include it verbatim.
1854 @lilypond[verbatim,quote]
1856 \\verbatim-file #\"simple.ly\"
1859 (interpret-markup layout props
1860 (if (ly:get-option 'safe)
1861 "verbatim-file disabled in safe mode"
1862 (let* ((str (ly:gulp-file name))
1863 (lines (string-split str #\nl)))
1864 (make-typewriter-markup
1865 (make-column-markup lines))))))
1867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1872 (define-markup-command (smaller layout props arg)
1875 "Decrease the font size relative to the current setting.
1877 @lilypond[verbatim,quote]
1890 (interpret-markup layout props
1891 `(,fontsize-markup -1 ,arg)))
1893 (define-markup-command (larger layout props arg)
1896 "Increase the font size relative to the current setting.
1898 @lilypond[verbatim,quote]
1906 (interpret-markup layout props
1907 `(,fontsize-markup 1 ,arg)))
1909 (define-markup-command (finger layout props arg)
1912 "Set @var{arg} as small numbers.
1914 @lilypond[verbatim,quote]
1921 (interpret-markup layout
1922 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1925 (define-markup-command (abs-fontsize layout props size arg)
1928 "Use @var{size} as the absolute font size to display @var{arg}.
1929 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1931 @lilypond[verbatim,quote]
1933 default text font size
1935 \\abs-fontsize #16 { text font size 16 }
1937 \\abs-fontsize #12 { text font size 12 }
1940 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1941 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1942 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1943 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1944 (magnification (/ size ref-size)))
1945 (interpret-markup layout
1946 (cons `((baseline-skip . ,(* magnification ref-baseline))
1947 (word-space . ,(* magnification ref-word-space))
1948 (font-size . ,(magnification->font-size magnification)))
1952 (define-markup-command (fontsize layout props increment arg)
1955 #:properties ((font-size 0)
1958 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1961 @lilypond[verbatim,quote]
1969 (let ((entries (list
1970 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1971 (cons 'word-space (* word-space (magstep increment)))
1972 (cons 'font-size (+ font-size increment)))))
1973 (interpret-markup layout (cons entries props) arg)))
1975 (define-markup-command (magnify layout props sz arg)
1979 @cindex magnifying text
1981 Set the font magnification for its argument. In the following
1982 example, the middle@tie{}A is 10% larger:
1985 A \\magnify #1.1 @{ A @} A
1988 Note: Magnification only works if a font name is explicitly selected.
1989 Use @code{\\fontsize} otherwise.
1991 @lilypond[verbatim,quote]
2002 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2005 (define-markup-command (bold layout props arg)
2008 "Switch to bold font-series.
2010 @lilypond[verbatim,quote]
2018 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2020 (define-markup-command (sans layout props arg)
2023 "Switch to the sans serif font family.
2025 @lilypond[verbatim,quote]
2034 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2036 (define-markup-command (number layout props arg)
2039 "Set font family to @code{number}, which yields the font used for
2040 time signatures and fingerings. This font contains numbers and
2041 some punctuation; it has no letters.
2043 @lilypond[verbatim,quote]
2046 0 1 2 3 4 5 6 7 8 9 . ,
2050 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2052 (define-markup-command (roman layout props arg)
2055 "Set font family to @code{roman}.
2057 @lilypond[verbatim,quote]
2063 text in roman font family
2070 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2072 (define-markup-command (huge layout props arg)
2075 "Set font size to +2.
2077 @lilypond[verbatim,quote]
2085 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2087 (define-markup-command (large layout props arg)
2090 "Set font size to +1.
2092 @lilypond[verbatim,quote]
2100 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2102 (define-markup-command (normalsize layout props arg)
2105 "Set font size to default.
2107 @lilypond[verbatim,quote]
2120 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2122 (define-markup-command (small layout props arg)
2125 "Set font size to -1.
2127 @lilypond[verbatim,quote]
2135 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2137 (define-markup-command (tiny layout props arg)
2140 "Set font size to -2.
2142 @lilypond[verbatim,quote]
2150 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2152 (define-markup-command (teeny layout props arg)
2155 "Set font size to -3.
2157 @lilypond[verbatim,quote]
2165 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2167 (define-markup-command (fontCaps layout props arg)
2170 "Set @code{font-shape} to @code{caps}
2172 Note: @code{\\fontCaps} requires the installation and selection of
2173 fonts which support the @code{caps} font shape."
2174 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2177 (define-markup-command (smallCaps layout props arg)
2180 "Emit @var{arg} as small caps.
2182 Note: @code{\\smallCaps} does not support accented characters.
2184 @lilypond[verbatim,quote]
2193 (define (char-list->markup chars lower)
2194 (let ((final-string (string-upcase (reverse-list->string chars))))
2196 (markup #:fontsize -2 final-string)
2198 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2199 (if (null? rest-chars)
2201 (reverse! (cons (char-list->markup currents current-is-lower)
2203 (let* ((ch (car rest-chars))
2204 (is-lower (char-lower-case? ch)))
2205 (if (or (and current-is-lower is-lower)
2206 (and (not current-is-lower) (not is-lower)))
2207 (make-small-caps (cdr rest-chars)
2211 (make-small-caps (cdr rest-chars)
2214 (if (null? currents)
2216 (cons (char-list->markup
2217 currents current-is-lower)
2219 (interpret-markup layout props
2221 (make-small-caps (string->list arg) (list) #f (list))
2224 (define-markup-command (caps layout props arg)
2227 "Copy of the @code{\\smallCaps} command.
2229 @lilypond[verbatim,quote]
2238 (interpret-markup layout props (make-smallCaps-markup arg)))
2240 (define-markup-command (dynamic layout props arg)
2243 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2244 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2245 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2246 done in a different font. The recommended font for this is bold and italic.
2247 @lilypond[verbatim,quote]
2255 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2257 (define-markup-command (text layout props arg)
2260 "Use a text font instead of music symbol or music alphabet font.
2262 @lilypond[verbatim,quote]
2275 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2278 (define-markup-command (italic layout props arg)
2281 "Use italic @code{font-shape} for @var{arg}.
2283 @lilypond[verbatim,quote]
2291 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2293 (define-markup-command (typewriter layout props arg)
2296 "Use @code{font-family} typewriter for @var{arg}.
2298 @lilypond[verbatim,quote]
2307 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2309 (define-markup-command (upright layout props arg)
2312 "Set @code{font-shape} to @code{upright}. This is the opposite
2315 @lilypond[verbatim,quote]
2329 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2331 (define-markup-command (medium layout props arg)
2334 "Switch to medium font-series (in contrast to bold).
2336 @lilypond[verbatim,quote]
2349 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2352 (define-markup-command (normal-text layout props arg)
2355 "Set all font related properties (except the size) to get the default
2356 normal text font, no matter what font was used earlier.
2358 @lilypond[verbatim,quote]
2360 \\huge \\bold \\sans \\caps {
2361 Some text with font overrides
2364 Default text, same font-size
2372 (interpret-markup layout
2373 (cons '((font-family . roman) (font-shape . upright)
2374 (font-series . medium) (font-encoding . latin1))
2378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2380 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2382 (define-markup-command (musicglyph layout props glyph-name)
2385 "@var{glyph-name} is converted to a musical symbol; for example,
2386 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2387 the music font. See @ruser{The Feta font} for a complete listing of
2388 the possible glyphs.
2390 @lilypond[verbatim,quote]
2393 \\musicglyph #\"rests.2\"
2394 \\musicglyph #\"clefs.G_change\"
2397 (let* ((font (ly:paper-get-font layout
2398 (cons '((font-encoding . fetaMusic)
2402 (glyph (ly:font-get-glyph font glyph-name)))
2403 (if (null? (ly:stencil-expr glyph))
2404 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2408 (define-markup-command (doublesharp layout props)
2411 "Draw a double sharp symbol.
2413 @lilypond[verbatim,quote]
2418 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2420 (define-markup-command (sesquisharp layout props)
2423 "Draw a 3/2 sharp symbol.
2425 @lilypond[verbatim,quote]
2430 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2432 (define-markup-command (sharp layout props)
2435 "Draw a sharp symbol.
2437 @lilypond[verbatim,quote]
2442 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2444 (define-markup-command (semisharp layout props)
2447 "Draw a semisharp symbol.
2449 @lilypond[verbatim,quote]
2454 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2456 (define-markup-command (natural layout props)
2459 "Draw a natural symbol.
2461 @lilypond[verbatim,quote]
2466 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2468 (define-markup-command (semiflat layout props)
2471 "Draw a semiflat symbol.
2473 @lilypond[verbatim,quote]
2478 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2480 (define-markup-command (flat layout props)
2483 "Draw a flat symbol.
2485 @lilypond[verbatim,quote]
2490 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2492 (define-markup-command (sesquiflat layout props)
2495 "Draw a 3/2 flat symbol.
2497 @lilypond[verbatim,quote]
2502 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2504 (define-markup-command (doubleflat layout props)
2507 "Draw a double flat symbol.
2509 @lilypond[verbatim,quote]
2514 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2516 (define-markup-command (with-color layout props color arg)
2520 @cindex coloring text
2522 Draw @var{arg} in color specified by @var{color}.
2524 @lilypond[verbatim,quote]
2536 (let ((stil (interpret-markup layout props arg)))
2537 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2538 (ly:stencil-extent stil X)
2539 (ly:stencil-extent stil Y))))
2541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2543 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2545 (define-markup-command (arrow-head layout props axis dir filled)
2546 (integer? ly:dir? boolean?)
2548 "Produce an arrow head in specified direction and axis.
2549 Use the filled head if @var{filled} is specified.
2550 @lilypond[verbatim,quote]
2553 \\general-align #Y #DOWN {
2554 \\arrow-head #Y #UP ##t
2555 \\arrow-head #Y #DOWN ##f
2557 \\arrow-head #X #RIGHT ##f
2558 \\arrow-head #X #LEFT ##f
2564 ((name (format "arrowheads.~a.~a~a"
2571 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3373 (define-markup-command (scale layout props factor-pair arg)
3374 (number-pair? markup?)
3377 @cindex scaling markup
3378 @cindex mirroring markup
3380 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3381 representing the scaling-factor in the X and Y axes.
3382 Negative values may be used to produce mirror images.
3384 @lilypond[verbatim,quote]
3394 (let ((stil (interpret-markup layout props arg))
3395 (sx (car factor-pair))
3396 (sy (cdr factor-pair)))
3397 (ly:stencil-scale stil sx sy)))
3399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3400 ;; Markup list commands
3401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3403 (define-public (space-lines baseline stils)
3404 (let space-stil ((stils stils)
3408 (let* ((stil (car stils))
3409 (dy-top (max (- (/ baseline 1.5)
3410 (interval-bound (ly:stencil-extent stil Y) UP))
3412 (dy-bottom (max (+ (/ baseline 3.0)
3413 (interval-bound (ly:stencil-extent stil Y) DOWN))
3415 (new-stil (ly:make-stencil
3416 (ly:stencil-expr stil)
3417 (ly:stencil-extent stil X)
3418 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3420 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3422 (space-stil (cdr stils) (cons new-stil result))))))
3424 (define-markup-list-command (justified-lines layout props args)
3426 #:properties ((baseline-skip)
3427 wordwrap-internal-markup-list)
3429 @cindex justifying lines of text
3431 Like @code{\\justify}, but return a list of lines instead of a single markup.
3432 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3433 @var{X}@tie{}is the number of staff spaces."
3434 (space-lines baseline-skip
3435 (interpret-markup-list layout props
3436 (make-wordwrap-internal-markup-list #t args))))
3438 (define-markup-list-command (wordwrap-lines layout props args)
3440 #:properties ((baseline-skip)
3441 wordwrap-internal-markup-list)
3442 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3443 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3444 where @var{X} is the number of staff spaces."
3445 (space-lines baseline-skip
3446 (interpret-markup-list layout props
3447 (make-wordwrap-internal-markup-list #f args))))
3449 (define-markup-list-command (column-lines layout props args)
3451 #:properties ((baseline-skip))
3452 "Like @code{\\column}, but return a list of lines instead of a single markup.
3453 @code{baseline-skip} determines the space between each markup in @var{args}."
3454 (space-lines baseline-skip
3455 (interpret-markup-list layout props args)))
3457 (define-markup-list-command (override-lines layout props new-prop args)
3458 (pair? markup-list?)
3459 "Like @code{\\override}, for markup lists."
3460 (interpret-markup-list layout (cons (list new-prop) props) args))