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) \\override #'(thickness . 1) \\underline
292 \\override #'(offset . 1) \\override #'(thickness . 5) \\underline
296 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
297 (underline-thick (* thickness thick))
298 (markup (interpret-markup layout props arg))
299 (x1 (car (ly:stencil-extent markup X)))
300 (x2 (cdr (ly:stencil-extent markup X)))
301 (y (* thick (- offset)))
302 (line (make-line-stencil underline-thick x1 y x2 y)))
303 (ly:stencil-add markup line)))
305 (define-markup-command (box layout props arg)
308 #:properties ((thickness 1)
312 @cindex enclosing text within a box
314 Draw a box round @var{arg}. Looks at @code{thickness},
315 @code{box-padding} and @code{font-size} properties to determine line
316 thickness and padding around the markup.
318 @lilypond[verbatim,quote]
320 \\override #'(box-padding . 0.5)
325 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
327 (pad (* (magstep font-size) box-padding))
328 (m (interpret-markup layout props arg)))
329 (box-stencil m th pad)))
331 (define-markup-command (filled-box layout props xext yext blot)
332 (number-pair? number-pair? number?)
335 @cindex drawing solid boxes within text
336 @cindex drawing boxes with rounded corners
338 Draw a box with rounded corners of dimensions @var{xext} and
339 @var{yext}. For example,
341 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
343 creates a box extending horizontally from -0.3 to 1.8 and
344 vertically from -0.3 up to 1.8, with corners formed from a
345 circle of diameter@tie{}0 (i.e., sharp corners).
347 @lilypond[verbatim,quote]
349 \\filled-box #'(0 . 4) #'(0 . 4) #0
350 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
351 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
353 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
359 (define-markup-command (rounded-box layout props arg)
362 #:properties ((thickness 1)
366 "@cindex enclosing text in a box with rounded corners
367 @cindex drawing boxes with rounded corners around text
368 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
369 @code{box-padding} and @code{font-size} properties to determine line
370 thickness and padding around the markup; the @code{corner-radius} property
371 makes it possible to define another shape for the corners (default is 1).
373 @lilypond[quote,verbatim,relative=2]
381 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
383 (pad (* (magstep font-size) box-padding))
384 (m (interpret-markup layout props arg)))
385 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
388 (define-markup-command (rotate layout props ang arg)
392 @cindex rotating text
394 Rotate object with @var{ang} degrees around its center.
396 @lilypond[verbatim,quote]
406 (let* ((stil (interpret-markup layout props arg)))
407 (ly:stencil-rotate stil ang 0 0)))
409 (define-markup-command (whiteout layout props arg)
413 @cindex adding a white background to text
415 Provide a white background for @var{arg}.
417 @lilypond[verbatim,quote]
420 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
424 (stencil-whiteout (interpret-markup layout props arg)))
426 (define-markup-command (pad-markup layout props amount arg)
431 @cindex putting space around text
433 Add space around a markup object.
435 @lilypond[verbatim,quote]
449 ((stil (interpret-markup layout props arg))
450 (xext (ly:stencil-extent stil X))
451 (yext (ly:stencil-extent stil Y)))
454 (ly:stencil-expr stil)
455 (interval-widen xext amount)
456 (interval-widen yext amount))))
458 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
462 (define-markup-command (strut layout props)
466 @cindex creating vertical spaces in text
468 Create a box of the same height as the space in the current font."
469 (let ((m (ly:text-interface::interpret-markup layout props " ")))
470 (ly:make-stencil (ly:stencil-expr m)
472 (ly:stencil-extent m X)
475 ;; todo: fix negative space
476 (define-markup-command (hspace layout props amount)
479 #:properties ((word-space))
481 @cindex creating horizontal spaces in text
483 Create an invisible object taking up horizontal space @var{amount}.
485 @lilypond[verbatim,quote]
494 (let ((corrected-space (- amount word-space)))
495 (if (> corrected-space 0)
496 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
497 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
499 ;; todo: fix negative space
500 (define-markup-command (vspace layout props amount)
504 @cindex creating vertical spaces in text
506 Create an invisible object taking up vertical space
507 of @var{amount} multiplied by 3.
509 @lilypond[verbatim,quote]
520 (let ((amount (* amount 3.0)))
522 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
523 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
526 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
527 ;; importing graphics.
528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
530 (define-markup-command (stencil layout props stil)
534 @cindex importing stencils into text
536 Use a stencil as markup.
538 @lilypond[verbatim,quote]
540 \\stencil #(make-circle-stencil 2 0 #t)
546 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
548 (define (get-postscript-bbox string)
549 "Extract the bbox from STRING, or return #f if not present."
551 ((match (regexp-exec bbox-regexp string)))
555 (string->number (match:substring match x)))
560 (define-markup-command (epsfile layout props axis size file-name)
561 (number? number? string?)
564 @cindex inlining an Encapsulated PostScript image
566 Inline an EPS image. The image is scaled along @var{axis} to
569 @lilypond[verbatim,quote]
571 \\general-align #Y #DOWN {
572 \\epsfile #X #20 #\"context-example.eps\"
573 \\epsfile #Y #20 #\"context-example.eps\"
577 (if (ly:get-option 'safe)
578 (interpret-markup layout props "not allowed in safe")
579 (eps-file->stencil axis size file-name)
582 (define-markup-command (postscript layout props str)
586 @cindex inserting PostScript directly into text
587 This inserts @var{str} directly into the output as a PostScript
590 @lilypond[verbatim,quote]
594 0.4 0.6 0.5 0 361 arc
596 1.0 0.6 0.5 0 361 arc
601 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
602 \\postscript #ringsps
614 gsave currentpoint translate
622 (define-markup-command (path layout props thickness commands) (number? list?)
624 #:properties ((line-cap-style 'round)
625 (line-join-style 'round)
628 @cindex paths, drawing
629 @cindex drawing paths
630 Draws a path with line thickness @var{thickness} according to the
631 directions given in @var{commands}. @var{commands} is a list of
632 lists where the @code{car} of each sublist is a drawing command and
633 the @code{cdr} comprises the associated arguments for each command.
635 Line-cap styles and line-join styles may be customized by
636 overriding the @code{line-cap-style} and @code{line-join-style}
637 properties, respectively. Available line-cap styles are
638 @code{'butt}, @code{'round}, and @code{'square}. Available
639 line-join styles are @code{'miter}, @code{'round}, and
642 The property @code{filled} specifies whether or not the path is
645 There are seven commands available to use in the list
646 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
647 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
648 @code{closepath}. Note that the commands that begin with @emph{r}
649 are the relative variants of the other three commands.
651 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
652 @code{rlineto} take 2 arguments; they are the X and Y coordinates
653 for the destination point.
655 The commands @code{curveto} and @code{rcurveto} create cubic
656 Bézier curves, and take 6 arguments; the first two are the X and Y
657 coordinates for the first control point, the second two are the X
658 and Y coordinates for the second control point, and the last two
659 are the X and Y coordinates for the destination point.
661 The @code{closepath} command takes zero arguments and closes the
662 current subpath in the active path.
664 Note that a sequence of commands @emph{must} begin with a
665 @code{moveto} or @code{rmoveto} to work with the SVG output.
667 @lilypond[verbatim,quote]
673 (curveto -5 -5 -5 5 -1 0)
677 \\path #0.25 #samplePath
680 (let* ((half-thickness (/ thickness 2))
681 (current-point '(0 . 0))
682 (set-point (lambda (lst) (set! current-point lst)))
683 (relative? (lambda (x)
684 (string-prefix? "r" (symbol->string (car x)))))
685 ;; For calculating extents, we want to modify the command
686 ;; list so that all coordinates are absolute.
687 (new-commands (map (lambda (x)
689 ;; for rmoveto, rlineto
690 ((and (relative? x) (eq? 3 (length x)))
692 (+ (car current-point)
694 (+ (cdr current-point)
700 ((and (relative? x) (eq? 7 (length x)))
701 (let* ((old-cp current-point)
708 (list (+ (car old-cp) (second x))
709 (+ (cdr old-cp) (third x))
710 (+ (car old-cp) (fourth x))
711 (+ (cdr old-cp) (fifth x))
714 ;; for moveto, lineto
716 (set-point (cons (second x)
721 (set-point (cons (sixth x)
724 ;; keep closepath for filtering;
725 ;; see `without-closepath'.
728 ;; path-min-max does not accept 0-arg lists,
729 ;; and since closepath does not affect extents, filter
730 ;; out those commands here.
731 (without-closepath (filter (lambda (x)
732 (not (equal? 'closepath (car x))))
734 (extents (path-min-max
735 ;; set the origin to the first moveto
736 (list (list-ref (car without-closepath) 0)
737 (list-ref (car without-closepath) 1))
739 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
740 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
741 (command-list (fold-right append '() commands)))
743 ;; account for line thickness
744 (set! X-extent (interval-widen X-extent half-thickness))
745 (set! Y-extent (interval-widen Y-extent half-thickness))
748 `(path ,thickness `(,@',command-list)
749 ',line-cap-style ',line-join-style ,filled)
753 (define-markup-command (score layout props score)
756 #:properties ((baseline-skip))
758 @cindex inserting music into text
760 Inline an image of music.
762 @lilypond[verbatim,quote]
766 \\new Staff \\relative c' {
769 \\mark \\markup { Allegro }
775 \\new Staff \\relative c {
789 \\override RehearsalMark #'break-align-symbols =
790 #'(time-signature key-signature)
791 \\override RehearsalMark #'self-alignment-X = #LEFT
795 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
801 (let ((output (ly:score-embedded-format score layout)))
803 (if (ly:music-output? output)
804 (stack-stencils Y DOWN baseline-skip
805 (map paper-system-stencil
807 (ly:paper-score-paper-systems output))))
809 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
812 (define-markup-command (null layout props)
816 @cindex creating empty text objects
818 An empty markup with extents of a single point.
820 @lilypond[verbatim,quote]
827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
829 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
831 (define-markup-command (simple layout props str)
835 @cindex simple text strings
837 A simple text string; @code{\\markup @{ foo @}} is equivalent with
838 @code{\\markup @{ \\simple #\"foo\" @}}.
840 Note: for creating standard text markup or defining new markup commands,
841 the use of @code{\\simple} is unnecessary.
843 @lilypond[verbatim,quote]
847 \\simple #\"strings\"
850 (interpret-markup layout props str))
852 (define-markup-command (tied-lyric layout props str)
856 @cindex simple text strings with tie characters
858 Like simple-markup, but use tie characters for @q{~} tilde symbols.
860 @lilypond[verbatim,quote]
862 \\tied-lyric #\"Lasciate~i monti\"
865 (if (string-contains str "~")
867 ((parts (string-split str #\~))
868 (tie-str (ly:wide-char->utf-8 #x203f))
869 (joined (list-join parts tie-str))
870 (join-stencil (interpret-markup layout props tie-str))
873 (interpret-markup layout
876 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
878 (make-line-markup joined)))
879 ;(map (lambda (s) (interpret-markup layout props s)) parts))
880 (interpret-markup layout props str)))
882 (define-public empty-markup
883 (make-simple-markup ""))
885 ;; helper for justifying lines.
886 (define (get-fill-space word-count line-width text-widths)
887 "Calculate the necessary paddings between each two adjacent texts.
888 The lengths of all texts are stored in @var{text-widths}.
889 The normal formula for the padding between texts a and b is:
890 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
891 The first and last padding have to be calculated specially using the
892 whole length of the first or last text.
893 Return a list of paddings."
895 ((null? text-widths) '())
897 ;; special case first padding
898 ((= (length text-widths) word-count)
900 (- (- (/ line-width (1- word-count)) (car text-widths))
901 (/ (car (cdr text-widths)) 2))
902 (get-fill-space word-count line-width (cdr text-widths))))
903 ;; special case last padding
904 ((= (length text-widths) 2)
905 (list (- (/ line-width (1- word-count))
906 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
909 (- (/ line-width (1- word-count))
910 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
911 (get-fill-space word-count line-width (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 text-widths))))
973 (line-stencils (if (= word-count 1)
980 (if (= text-direction LEFT)
981 (set! line-stencils (reverse line-stencils)))
983 (if (null? (remove ly:stencil-empty? orig-stencils))
985 (ly:stencil-translate-axis
986 (stack-stencils-padding-list X
987 RIGHT fill-space-normal line-stencils)
988 (- (car (ly:stencil-extent (car stencils) X)))
991 (define-markup-command (line layout props args)
994 #:properties ((word-space)
995 (text-direction RIGHT))
996 "Put @var{args} in a horizontal line. The property @code{word-space}
997 determines the space between markups in @var{args}.
999 @lilypond[verbatim,quote]
1006 (let ((stencils (interpret-markup-list layout props args)))
1007 (if (= text-direction LEFT)
1008 (set! stencils (reverse stencils)))
1011 (remove ly:stencil-empty? stencils))))
1013 (define-markup-command (concat layout props args)
1017 @cindex concatenating text
1018 @cindex ligatures in text
1020 Concatenate @var{args} in a horizontal line, without spaces in between.
1021 Strings and simple markups are concatenated on the input level, allowing
1022 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1023 equivalent to @code{\"fi\"}.
1025 @lilypond[verbatim,quote]
1034 (define (concat-string-args arg-list)
1035 (fold-right (lambda (arg result-list)
1036 (let ((result (if (pair? result-list)
1039 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1040 (set! arg (cadr arg)))
1041 (if (and (string? result) (string? arg))
1042 (cons (string-append arg result) (cdr result-list))
1043 (cons arg result-list))))
1047 (interpret-markup layout
1048 (prepend-alist-chain 'word-space 0 props)
1049 (make-line-markup (if (markup-command-list? args)
1051 (concat-string-args args)))))
1053 (define (wordwrap-stencils stencils
1054 justify base-space line-width text-dir)
1055 "Perform simple wordwrap, return stencil of each line."
1056 (define space (if justify
1057 ;; justify only stretches lines.
1060 (define (take-list width space stencils
1061 accumulator accumulated-width)
1062 "Return (head-list . tail) pair, with head-list fitting into width"
1063 (if (null? stencils)
1064 (cons accumulator stencils)
1065 (let* ((first (car stencils))
1066 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1067 (newwid (+ space first-wid accumulated-width)))
1068 (if (or (null? accumulator)
1070 (take-list width space
1072 (cons first accumulator)
1074 (cons accumulator stencils)))))
1075 (let loop ((lines '())
1077 (let* ((line-break (take-list line-width space todo
1079 (line-stencils (car line-break))
1080 (space-left (- line-width
1081 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1083 (line-word-space (cond ((not justify) space)
1084 ;; don't stretch last line of paragraph.
1085 ;; hmmm . bug - will overstretch the last line in some case.
1086 ((null? (cdr line-break))
1088 ((null? line-stencils) 0.0)
1089 ((null? (cdr line-stencils)) 0.0)
1090 (else (/ space-left (1- (length line-stencils))))))
1091 (line (stack-stencil-line line-word-space
1092 (if (= text-dir RIGHT)
1093 (reverse line-stencils)
1095 (if (pair? (cdr line-break))
1096 (loop (cons line lines)
1099 (if (= text-dir LEFT)
1101 (ly:stencil-translate-axis
1103 (- line-width (interval-end (ly:stencil-extent line X)))
1105 (reverse (cons line lines)))))))
1107 (define-markup-list-command (wordwrap-internal layout props justify args)
1108 (boolean? markup-list?)
1109 #:properties ((line-width #f)
1111 (text-direction RIGHT))
1112 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1113 (wordwrap-stencils (remove ly:stencil-empty?
1114 (interpret-markup-list layout props args))
1118 (ly:output-def-lookup layout 'line-width))
1121 (define-markup-command (justify layout props args)
1124 #:properties ((baseline-skip)
1125 wordwrap-internal-markup-list)
1127 @cindex justifying text
1129 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1130 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1131 @var{X}@tie{}is the number of staff spaces.
1133 @lilypond[verbatim,quote]
1136 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1137 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1138 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1139 laboris nisi ut aliquip ex ea commodo consequat.
1143 (stack-lines DOWN 0.0 baseline-skip
1144 (wordwrap-internal-markup-list layout props #t args)))
1146 (define-markup-command (wordwrap layout props args)
1149 #:properties ((baseline-skip)
1150 wordwrap-internal-markup-list)
1151 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1152 the line width, where @var{X} is the number of staff spaces.
1154 @lilypond[verbatim,quote]
1157 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1158 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1159 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1160 laboris nisi ut aliquip ex ea commodo consequat.
1164 (stack-lines DOWN 0.0 baseline-skip
1165 (wordwrap-internal-markup-list layout props #f args)))
1167 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1169 #:properties ((line-width)
1171 (text-direction RIGHT))
1172 "Internal markup list command used to define @code{\\justify-string} and
1173 @code{\\wordwrap-string}."
1174 (let* ((para-strings (regexp-split
1175 (string-regexp-substitute
1177 (string-regexp-substitute "\r\n" "\n" arg))
1178 "\n[ \t\n]*\n[ \t\n]*"))
1179 (list-para-words (map (lambda (str)
1180 (regexp-split str "[ \t\n]+"))
1182 (para-lines (map (lambda (words)
1184 (remove ly:stencil-empty?
1186 (interpret-markup layout props x))
1188 (wordwrap-stencils stencils
1190 line-width text-direction)))
1192 (apply append para-lines)))
1194 (define-markup-command (wordwrap-string layout props arg)
1197 #:properties ((baseline-skip)
1198 wordwrap-string-internal-markup-list)
1199 "Wordwrap a string. Paragraphs may be separated with double newlines.
1201 @lilypond[verbatim,quote]
1203 \\override #'(line-width . 40)
1204 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1205 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1206 et dolore magna aliqua.
1209 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1210 laboris nisi ut aliquip ex ea commodo consequat.
1213 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1214 qui officia deserunt mollit anim id est laborum\"
1217 (stack-lines DOWN 0.0 baseline-skip
1218 (wordwrap-string-internal-markup-list layout props #f arg)))
1220 (define-markup-command (justify-string layout props arg)
1223 #:properties ((baseline-skip)
1224 wordwrap-string-internal-markup-list)
1225 "Justify a string. Paragraphs may be separated with double newlines
1227 @lilypond[verbatim,quote]
1229 \\override #'(line-width . 40)
1230 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1231 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1232 et dolore magna aliqua.
1235 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1236 laboris nisi ut aliquip ex ea commodo consequat.
1239 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1240 qui officia deserunt mollit anim id est laborum\"
1243 (stack-lines DOWN 0.0 baseline-skip
1244 (wordwrap-string-internal-markup-list layout props #t arg)))
1246 (define-markup-command (wordwrap-field layout props symbol)
1249 "Wordwrap the data which has been assigned to @var{symbol}.
1251 @lilypond[verbatim,quote]
1253 title = \"My title\"
1254 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1255 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1256 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1257 laboris nisi ut aliquip ex ea commodo consequat.\"
1261 bookTitleMarkup = \\markup {
1263 \\fill-line { \\fromproperty #'header:title }
1265 \\wordwrap-field #'header:myText
1274 (let* ((m (chain-assoc-get symbol props)))
1276 (wordwrap-string-markup layout props m)
1279 (define-markup-command (justify-field layout props symbol)
1282 "Justify the data which has been assigned to @var{symbol}.
1284 @lilypond[verbatim,quote]
1286 title = \"My title\"
1287 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1288 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1289 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1290 laboris nisi ut aliquip ex ea commodo consequat.\"
1294 bookTitleMarkup = \\markup {
1296 \\fill-line { \\fromproperty #'header:title }
1298 \\justify-field #'header:myText
1307 (let* ((m (chain-assoc-get symbol props)))
1309 (justify-string-markup layout props m)
1312 (define-markup-command (combine layout props arg1 arg2)
1316 @cindex merging text
1318 Print two markups on top of each other.
1320 Note: @code{\\combine} cannot take a list of markups enclosed in
1321 curly braces as an argument; the follow example will not compile:
1324 \\combine @{ a list @}
1327 @lilypond[verbatim,quote]
1330 \\override #'(thickness . 2)
1332 \\draw-line #'(0 . 4)
1333 \\arrow-head #Y #DOWN ##f
1336 (let* ((s1 (interpret-markup layout props arg1))
1337 (s2 (interpret-markup layout props arg2)))
1338 (ly:stencil-add s1 s2)))
1341 ;; TODO: should extract baseline-skip from each argument somehow..
1343 (define-markup-command (column layout props args)
1346 #:properties ((baseline-skip))
1348 @cindex stacking text in a column
1350 Stack the markups in @var{args} vertically. The property
1351 @code{baseline-skip} determines the space between markups
1354 @lilypond[verbatim,quote]
1363 (let ((arg-stencils (interpret-markup-list layout props args)))
1364 (stack-lines -1 0.0 baseline-skip
1365 (remove ly:stencil-empty? arg-stencils))))
1367 (define-markup-command (dir-column layout props args)
1370 #:properties ((direction)
1373 @cindex changing direction of text columns
1375 Make a column of @var{args}, going up or down, depending on the
1376 setting of the @code{direction} layout property.
1378 @lilypond[verbatim,quote]
1380 \\override #`(direction . ,UP) {
1390 \\override #'(direction . 1) {
1397 (stack-lines (if (number? direction) direction -1)
1400 (interpret-markup-list layout props args)))
1402 (define (general-column align-dir baseline mols)
1403 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1405 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1406 (stack-lines -1 0.0 baseline aligned-mols)))
1408 (define-markup-command (center-column layout props args)
1411 #:properties ((baseline-skip))
1413 @cindex centering a column of text
1415 Put @code{args} in a centered column.
1417 @lilypond[verbatim,quote]
1426 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1428 (define-markup-command (left-column layout props args)
1431 #:properties ((baseline-skip))
1433 @cindex text columns, left-aligned
1435 Put @code{args} in a left-aligned column.
1437 @lilypond[verbatim,quote]
1446 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1448 (define-markup-command (right-column layout props args)
1451 #:properties ((baseline-skip))
1453 @cindex text columns, right-aligned
1455 Put @code{args} in a right-aligned column.
1457 @lilypond[verbatim,quote]
1466 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1468 (define-markup-command (vcenter layout props arg)
1472 @cindex vertically centering text
1474 Align @code{arg} to its Y@tie{}center.
1476 @lilypond[verbatim,quote]
1484 (let* ((mol (interpret-markup layout props arg)))
1485 (ly:stencil-aligned-to mol Y CENTER)))
1487 (define-markup-command (center-align layout props arg)
1491 @cindex horizontally centering text
1493 Align @code{arg} to its X@tie{}center.
1495 @lilypond[verbatim,quote]
1505 (let* ((mol (interpret-markup layout props arg)))
1506 (ly:stencil-aligned-to mol X CENTER)))
1508 (define-markup-command (right-align layout props arg)
1512 @cindex right aligning text
1514 Align @var{arg} on its right edge.
1516 @lilypond[verbatim,quote]
1526 (let* ((m (interpret-markup layout props arg)))
1527 (ly:stencil-aligned-to m X RIGHT)))
1529 (define-markup-command (left-align layout props arg)
1533 @cindex left aligning text
1535 Align @var{arg} on its left edge.
1537 @lilypond[verbatim,quote]
1547 (let* ((m (interpret-markup layout props arg)))
1548 (ly:stencil-aligned-to m X LEFT)))
1550 (define-markup-command (general-align layout props axis dir arg)
1551 (integer? number? markup?)
1554 @cindex controlling general text alignment
1556 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1558 @lilypond[verbatim,quote]
1562 \\general-align #X #LEFT
1567 \\general-align #X #CENTER
1573 \\general-align #Y #UP
1580 \\general-align #Y #3.2
1587 (let* ((m (interpret-markup layout props arg)))
1588 (ly:stencil-aligned-to m axis dir)))
1590 (define-markup-command (halign layout props dir arg)
1594 @cindex setting horizontal text alignment
1596 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1597 left-aligned, while @code{+1} is right. Values in between interpolate
1598 alignment accordingly.
1600 @lilypond[verbatim,quote]
1625 (let* ((m (interpret-markup layout props arg)))
1626 (ly:stencil-aligned-to m X dir)))
1628 (define-markup-command (with-dimensions layout props x y arg)
1629 (number-pair? number-pair? markup?)
1632 @cindex setting extent of text objects
1634 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1635 (let* ((m (interpret-markup layout props arg)))
1636 (ly:make-stencil (ly:stencil-expr m) x y)))
1638 (define-markup-command (pad-around layout props amount arg)
1641 "Add padding @var{amount} all around @var{arg}.
1643 @lilypond[verbatim,quote]
1656 (let* ((m (interpret-markup layout props arg))
1657 (x (ly:stencil-extent m X))
1658 (y (ly:stencil-extent m Y)))
1659 (ly:make-stencil (ly:stencil-expr m)
1660 (interval-widen x amount)
1661 (interval-widen y amount))))
1663 (define-markup-command (pad-x layout props amount arg)
1667 @cindex padding text horizontally
1669 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1671 @lilypond[verbatim,quote]
1684 (let* ((m (interpret-markup layout props arg))
1685 (x (ly:stencil-extent m X))
1686 (y (ly:stencil-extent m Y)))
1687 (ly:make-stencil (ly:stencil-expr m)
1688 (interval-widen x amount)
1691 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1692 (integer? ly:dir? markup? markup?)
1694 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1695 (let ((m1 (interpret-markup layout props arg1))
1696 (m2 (interpret-markup layout props arg2)))
1697 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1699 (define-markup-command (transparent layout props arg)
1702 "Make @var{arg} transparent.
1704 @lilypond[verbatim,quote]
1711 (let* ((m (interpret-markup layout props arg))
1712 (x (ly:stencil-extent m X))
1713 (y (ly:stencil-extent m Y)))
1714 (ly:make-stencil "" x y)))
1716 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1717 (number-pair? number-pair? markup?)
1719 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1721 @lilypond[verbatim,quote]
1728 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1734 (let* ((m (interpret-markup layout props arg))
1735 (x (ly:stencil-extent m X))
1736 (y (ly:stencil-extent m Y)))
1737 (ly:make-stencil (ly:stencil-expr m)
1738 (interval-union x-ext x)
1739 (interval-union y-ext y))))
1741 (define-markup-command (hcenter-in layout props length arg)
1744 "Center @var{arg} horizontally within a box of extending
1745 @var{length}/2 to the left and right.
1747 @lilypond[quote,verbatim]
1750 \\set Staff.instrumentName = \\markup {
1757 \\set Staff.instrumentName = \\markup {
1766 (interpret-markup layout props
1767 (make-pad-to-box-markup
1768 (cons (/ length -2) (/ length 2))
1770 (make-center-align-markup arg))))
1772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1774 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1776 (define-markup-command (fromproperty layout props symbol)
1779 "Read the @var{symbol} from property settings, and produce a stencil
1780 from the markup contained within. If @var{symbol} is not defined, it
1781 returns an empty markup.
1783 @lilypond[verbatim,quote]
1785 myTitle = \"myTitle\"
1789 \\fromproperty #'header:myTitle
1796 (let ((m (chain-assoc-get symbol props)))
1798 (interpret-markup layout props m)
1801 (define-markup-command (on-the-fly layout props procedure arg)
1804 "Apply the @var{procedure} markup command to @var{arg}.
1805 @var{procedure} should take a single argument."
1806 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1807 (set-object-property! anonymous-with-signature
1810 (interpret-markup layout props (list anonymous-with-signature arg))))
1812 (define-markup-command (override layout props new-prop arg)
1816 @cindex overriding properties within text markup
1818 Add the argument @var{new-prop} to the property list. Properties
1819 may be any property supported by @rinternals{font-interface},
1820 @rinternals{text-interface} and
1821 @rinternals{instrument-specific-markup-interface}.
1823 @lilypond[verbatim,quote]
1831 \\override #'(baseline-skip . 4) {
1840 (interpret-markup layout (cons (list new-prop) props) arg))
1842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1846 (define-markup-command (verbatim-file layout props name)
1849 "Read the contents of file @var{name}, and include it verbatim.
1851 @lilypond[verbatim,quote]
1853 \\verbatim-file #\"simple.ly\"
1856 (interpret-markup layout props
1857 (if (ly:get-option 'safe)
1858 "verbatim-file disabled in safe mode"
1859 (let* ((str (ly:gulp-file name))
1860 (lines (string-split str #\nl)))
1861 (make-typewriter-markup
1862 (make-column-markup lines))))))
1864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1866 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1869 (define-markup-command (smaller layout props arg)
1872 "Decrease the font size relative to the current setting.
1874 @lilypond[verbatim,quote]
1887 (interpret-markup layout props
1888 `(,fontsize-markup -1 ,arg)))
1890 (define-markup-command (larger layout props arg)
1893 "Increase the font size relative to the current setting.
1895 @lilypond[verbatim,quote]
1903 (interpret-markup layout props
1904 `(,fontsize-markup 1 ,arg)))
1906 (define-markup-command (finger layout props arg)
1909 "Set @var{arg} as small numbers.
1911 @lilypond[verbatim,quote]
1918 (interpret-markup layout
1919 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1922 (define-markup-command (abs-fontsize layout props size arg)
1925 "Use @var{size} as the absolute font size to display @var{arg}.
1926 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1928 @lilypond[verbatim,quote]
1930 default text font size
1932 \\abs-fontsize #16 { text font size 16 }
1934 \\abs-fontsize #12 { text font size 12 }
1937 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1938 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1939 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1940 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1941 (magnification (/ size ref-size)))
1942 (interpret-markup layout
1943 (cons `((baseline-skip . ,(* magnification ref-baseline))
1944 (word-space . ,(* magnification ref-word-space))
1945 (font-size . ,(magnification->font-size magnification)))
1949 (define-markup-command (fontsize layout props increment arg)
1952 #:properties ((font-size 0)
1955 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1958 @lilypond[verbatim,quote]
1966 (let ((entries (list
1967 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1968 (cons 'word-space (* word-space (magstep increment)))
1969 (cons 'font-size (+ font-size increment)))))
1970 (interpret-markup layout (cons entries props) arg)))
1972 (define-markup-command (magnify layout props sz arg)
1976 @cindex magnifying text
1978 Set the font magnification for its argument. In the following
1979 example, the middle@tie{}A is 10% larger:
1982 A \\magnify #1.1 @{ A @} A
1985 Note: Magnification only works if a font name is explicitly selected.
1986 Use @code{\\fontsize} otherwise.
1988 @lilypond[verbatim,quote]
1999 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2002 (define-markup-command (bold layout props arg)
2005 "Switch to bold font-series.
2007 @lilypond[verbatim,quote]
2015 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2017 (define-markup-command (sans layout props arg)
2020 "Switch to the sans serif font family.
2022 @lilypond[verbatim,quote]
2031 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2033 (define-markup-command (number layout props arg)
2036 "Set font family to @code{number}, which yields the font used for
2037 time signatures and fingerings. This font contains numbers and
2038 some punctuation; it has no letters.
2040 @lilypond[verbatim,quote]
2043 0 1 2 3 4 5 6 7 8 9 . ,
2047 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2049 (define-markup-command (roman layout props arg)
2052 "Set font family to @code{roman}.
2054 @lilypond[verbatim,quote]
2060 text in roman font family
2067 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2069 (define-markup-command (huge layout props arg)
2072 "Set font size to +2.
2074 @lilypond[verbatim,quote]
2082 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2084 (define-markup-command (large layout props arg)
2087 "Set font size to +1.
2089 @lilypond[verbatim,quote]
2097 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2099 (define-markup-command (normalsize layout props arg)
2102 "Set font size to default.
2104 @lilypond[verbatim,quote]
2117 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2119 (define-markup-command (small layout props arg)
2122 "Set font size to -1.
2124 @lilypond[verbatim,quote]
2132 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2134 (define-markup-command (tiny layout props arg)
2137 "Set font size to -2.
2139 @lilypond[verbatim,quote]
2147 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2149 (define-markup-command (teeny layout props arg)
2152 "Set font size to -3.
2154 @lilypond[verbatim,quote]
2162 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2164 (define-markup-command (fontCaps layout props arg)
2167 "Set @code{font-shape} to @code{caps}
2169 Note: @code{\\fontCaps} requires the installation and selection of
2170 fonts which support the @code{caps} font shape."
2171 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2174 (define-markup-command (smallCaps layout props arg)
2177 "Emit @var{arg} as small caps.
2179 Note: @code{\\smallCaps} does not support accented characters.
2181 @lilypond[verbatim,quote]
2190 (define (char-list->markup chars lower)
2191 (let ((final-string (string-upcase (reverse-list->string chars))))
2193 (markup #:fontsize -2 final-string)
2195 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2196 (if (null? rest-chars)
2198 (reverse! (cons (char-list->markup currents current-is-lower)
2200 (let* ((ch (car rest-chars))
2201 (is-lower (char-lower-case? ch)))
2202 (if (or (and current-is-lower is-lower)
2203 (and (not current-is-lower) (not is-lower)))
2204 (make-small-caps (cdr rest-chars)
2208 (make-small-caps (cdr rest-chars)
2211 (if (null? currents)
2213 (cons (char-list->markup
2214 currents current-is-lower)
2216 (interpret-markup layout props
2218 (make-small-caps (string->list arg) (list) #f (list))
2221 (define-markup-command (caps layout props arg)
2224 "Copy of the @code{\\smallCaps} command.
2226 @lilypond[verbatim,quote]
2235 (interpret-markup layout props (make-smallCaps-markup arg)))
2237 (define-markup-command (dynamic layout props arg)
2240 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2241 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2242 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2243 done in a different font. The recommended font for this is bold and italic.
2244 @lilypond[verbatim,quote]
2252 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2254 (define-markup-command (text layout props arg)
2257 "Use a text font instead of music symbol or music alphabet font.
2259 @lilypond[verbatim,quote]
2272 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2275 (define-markup-command (italic layout props arg)
2278 "Use italic @code{font-shape} for @var{arg}.
2280 @lilypond[verbatim,quote]
2288 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2290 (define-markup-command (typewriter layout props arg)
2293 "Use @code{font-family} typewriter for @var{arg}.
2295 @lilypond[verbatim,quote]
2304 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2306 (define-markup-command (upright layout props arg)
2309 "Set @code{font-shape} to @code{upright}. This is the opposite
2312 @lilypond[verbatim,quote]
2326 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2328 (define-markup-command (medium layout props arg)
2331 "Switch to medium font-series (in contrast to bold).
2333 @lilypond[verbatim,quote]
2346 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2349 (define-markup-command (normal-text layout props arg)
2352 "Set all font related properties (except the size) to get the default
2353 normal text font, no matter what font was used earlier.
2355 @lilypond[verbatim,quote]
2357 \\huge \\bold \\sans \\caps {
2358 Some text with font overrides
2361 Default text, same font-size
2369 (interpret-markup layout
2370 (cons '((font-family . roman) (font-shape . upright)
2371 (font-series . medium) (font-encoding . latin1))
2375 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2377 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2379 (define-markup-command (doublesharp layout props)
2382 "Draw a double sharp symbol.
2384 @lilypond[verbatim,quote]
2389 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2391 (define-markup-command (sesquisharp layout props)
2394 "Draw a 3/2 sharp symbol.
2396 @lilypond[verbatim,quote]
2401 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2403 (define-markup-command (sharp layout props)
2406 "Draw a sharp symbol.
2408 @lilypond[verbatim,quote]
2413 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2415 (define-markup-command (semisharp layout props)
2418 "Draw a semisharp symbol.
2420 @lilypond[verbatim,quote]
2425 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2427 (define-markup-command (natural layout props)
2430 "Draw a natural symbol.
2432 @lilypond[verbatim,quote]
2437 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2439 (define-markup-command (semiflat layout props)
2442 "Draw a semiflat symbol.
2444 @lilypond[verbatim,quote]
2449 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2451 (define-markup-command (flat layout props)
2454 "Draw a flat symbol.
2456 @lilypond[verbatim,quote]
2461 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2463 (define-markup-command (sesquiflat layout props)
2466 "Draw a 3/2 flat symbol.
2468 @lilypond[verbatim,quote]
2473 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2475 (define-markup-command (doubleflat layout props)
2478 "Draw a double flat symbol.
2480 @lilypond[verbatim,quote]
2485 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2487 (define-markup-command (with-color layout props color arg)
2491 @cindex coloring text
2493 Draw @var{arg} in color specified by @var{color}.
2495 @lilypond[verbatim,quote]
2507 (let ((stil (interpret-markup layout props arg)))
2508 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2509 (ly:stencil-extent stil X)
2510 (ly:stencil-extent stil Y))))
2512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2514 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2516 (define-markup-command (arrow-head layout props axis dir filled)
2517 (integer? ly:dir? boolean?)
2519 "Produce an arrow head in specified direction and axis.
2520 Use the filled head if @var{filled} is specified.
2521 @lilypond[verbatim,quote]
2524 \\general-align #Y #DOWN {
2525 \\arrow-head #Y #UP ##t
2526 \\arrow-head #Y #DOWN ##f
2528 \\arrow-head #X #RIGHT ##f
2529 \\arrow-head #X #LEFT ##f
2535 ((name (format "arrowheads.~a.~a~a"
2542 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2546 (define-markup-command (musicglyph layout props glyph-name)
2549 "@var{glyph-name} is converted to a musical symbol; for example,
2550 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2551 the music font. See @ruser{The Feta font} for a complete listing of
2552 the possible glyphs.
2554 @lilypond[verbatim,quote]
2557 \\musicglyph #\"rests.2\"
2558 \\musicglyph #\"clefs.G_change\"
2561 (let* ((font (ly:paper-get-font layout
2562 (cons '((font-encoding . fetaMusic)
2566 (glyph (ly:font-get-glyph font glyph-name)))
2567 (if (null? (ly:stencil-expr glyph))
2568 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2573 (define-markup-command (lookup layout props glyph-name)
2576 "Lookup a glyph by name.
2578 @lilypond[verbatim,quote]
2580 \\override #'(font-encoding . fetaBraces) {
2581 \\lookup #\"brace200\"
2584 \\lookup #\"brace180\"
2588 (ly:font-get-glyph (ly:paper-get-font layout props)
2591 (define-markup-command (char layout props num)
2594 "Produce a single character. Characters encoded in hexadecimal
2595 format require the prefix @code{#x}.
2597 @lilypond[verbatim,quote]
2599 \\char #65 \\char ##x00a9
2602 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2604 (define number->mark-letter-vector (make-vector 25 #\A))
2609 (if (= i (- (char->integer #\I) (char->integer #\A)))
2611 (vector-set! number->mark-letter-vector j
2612 (integer->char (+ i (char->integer #\A)))))
2614 (define number->mark-alphabet-vector (list->vector
2615 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2617 (define (number->markletter-string vec n)
2618 "Double letters for big marks."
2619 (let* ((lst (vector-length vec)))
2622 (string-append (number->markletter-string vec (1- (quotient n lst)))
2623 (number->markletter-string vec (remainder n lst)))
2624 (make-string 1 (vector-ref vec n)))))
2626 (define-markup-command (markletter layout props num)
2629 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2630 (skipping letter@tie{}I), and continue with double letters.
2632 @lilypond[verbatim,quote]
2639 (ly:text-interface::interpret-markup layout props
2640 (number->markletter-string number->mark-letter-vector num)))
2642 (define-markup-command (markalphabet layout props num)
2645 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2646 and continue with double letters.
2648 @lilypond[verbatim,quote]
2655 (ly:text-interface::interpret-markup layout props
2656 (number->markletter-string number->mark-alphabet-vector num)))
2658 (define-public (horizontal-slash-interval num forward number-interval mag)
2660 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2661 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2662 (else (interval-widen number-interval (* mag 0.25))))
2663 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2664 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2665 (else (interval-widen number-interval (* mag 0.25))))
2668 (define-public (adjust-slash-stencil num forward stencil mag)
2671 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2673 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2675 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2677 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2680 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2682 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2687 (define (slashed-digit-internal layout props num forward font-size thickness)
2688 (let* ((mag (magstep font-size))
2690 (ly:output-def-lookup layout 'line-thickness)
2692 ; backward slashes might use slope and point in the other direction!
2693 (dy (* mag (if forward 0.4 -0.4)))
2694 (number-stencil (interpret-markup layout
2695 (prepend-alist-chain 'font-encoding 'fetaText props)
2696 (number->string num)))
2697 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2698 (center (interval-center (ly:stencil-extent number-stencil Y)))
2699 ; Use the real extents of the slash, not the whole number, because we
2700 ; might translate the slash later on!
2701 (num-y (interval-widen (cons center center) (abs dy)))
2702 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2703 (slash-stencil (if is-sane
2704 (make-line-stencil thickness
2705 (car num-x) (- (interval-center num-y) dy)
2706 (cdr num-x) (+ (interval-center num-y) dy))
2708 (if (ly:stencil? slash-stencil)
2710 ; for some numbers we need to shift the slash/backslash up or down to make
2711 ; the slashed digit look better
2712 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2713 (set! number-stencil
2714 (ly:stencil-add number-stencil slash-stencil)))
2715 (ly:warning "Unable to create slashed digit ~a" num))
2719 (define-markup-command (slashed-digit layout props num)
2722 #:properties ((font-size 0)
2725 @cindex slashed digits
2727 A feta number, with slash. This is for use in the context of
2728 figured bass notation.
2729 @lilypond[verbatim,quote]
2733 \\override #'(thickness . 3)
2737 (slashed-digit-internal layout props num #t font-size thickness))
2739 (define-markup-command (backslashed-digit layout props num)
2742 #:properties ((font-size 0)
2745 @cindex backslashed digits
2747 A feta number, with backslash. This is for use in the context of
2748 figured bass notation.
2749 @lilypond[verbatim,quote]
2751 \\backslashed-digit #5
2753 \\override #'(thickness . 3)
2754 \\backslashed-digit #7
2757 (slashed-digit-internal layout props num #f font-size thickness))
2760 (define eyeglassespath
2761 '((moveto 0.42 0.77)
2762 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2763 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
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)
2768 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2769 (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)
2773 (moveto 1.025 0.935)
2774 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2775 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2778 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2781 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2783 (define-markup-command (eyeglasses layout props)
2786 "Prints out eyeglasses, indicating strongly to look at the conductor.
2787 @lilypond[verbatim,quote]
2788 \\markup { \\eyeglasses }
2790 (interpret-markup layout props
2791 (make-override-markup '(line-cap-style . butt)
2792 (make-path-markup 0.15 eyeglassespath))))
2794 (define-markup-command (left-brace layout props size)
2798 A feta brace in point size @var{size}.
2800 @lilypond[verbatim,quote]
2807 (let* ((font (ly:paper-get-font layout
2808 (cons '((font-encoding . fetaBraces)
2811 (glyph-count (1- (ly:otf-glyph-count font)))
2812 (scale (ly:output-def-lookup layout 'output-scale))
2813 (scaled-size (/ (ly:pt size) scale))
2815 (ly:font-get-glyph font (string-append "brace"
2816 (number->string n)))))
2817 (get-y-from-brace (lambda (brace)
2819 (ly:stencil-extent (glyph brace) Y))))
2820 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2821 (glyph-found (glyph find-brace)))
2823 (if (or (null? (ly:stencil-expr glyph-found))
2824 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2825 (> scaled-size (interval-length
2826 (ly:stencil-extent (glyph glyph-count) Y))))
2828 (ly:warning (_ "no brace found for point size ~S ") size)
2829 (ly:warning (_ "defaulting to ~S pt")
2830 (/ (* scale (interval-length
2831 (ly:stencil-extent glyph-found Y)))
2835 (define-markup-command (right-brace layout props size)
2839 A feta brace in point size @var{size}, rotated 180 degrees.
2841 @lilypond[verbatim,quote]
2848 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2851 ;; the note command.
2852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2854 ;; TODO: better syntax.
2856 (define-markup-command (note-by-number layout props log dot-count dir)
2857 (number? number? number?)
2859 #:properties ((font-size 0)
2862 @cindex notes within text by log and dot-count
2864 Construct a note symbol, with stem. By using fractional values for
2865 @var{dir}, longer or shorter stems can be obtained.
2867 @lilypond[verbatim,quote]
2869 \\note-by-number #3 #0 #DOWN
2871 \\note-by-number #1 #2 #0.8
2874 (define (get-glyph-name-candidates dir log style)
2875 (map (lambda (dir-name)
2876 (format "noteheads.~a~a" dir-name
2877 (if (and (symbol? style)
2878 (not (equal? 'default style)))
2879 (select-head-glyph style (min log 2))
2881 (list (if (= dir UP) "u" "d")
2884 (define (get-glyph-name font cands)
2887 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2888 (get-glyph-name font (cdr cands))
2891 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2893 (size-factor (magstep font-size))
2894 (stem-length (* size-factor (max 3 (- log 1))))
2896 (let ((result (get-glyph-name font (get-glyph-name-candidates
2897 (sign dir) log style))))
2898 (if (string-null? result)
2899 ;; If no glyph name can be found, select default heads. Though
2900 ;; this usually means an unsupported style has been chosen, it
2901 ;; also prevents unrelated 'style settings from other grobs
2902 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2903 (get-glyph-name font (get-glyph-name-candidates
2904 (sign dir) log 'default))
2906 (head-glyph (ly:font-get-glyph font head-glyph-name))
2907 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2908 (stem-thickness (* size-factor 0.13))
2909 (stemy (* dir stem-length))
2910 (attach-off (cons (interval-index
2911 (ly:stencil-extent head-glyph X)
2912 (* (sign dir) (car attach-indices)))
2913 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2915 (ly:stencil-extent head-glyph Y)
2916 (cdr attach-indices)))))
2917 (stem-glyph (and (> log 0)
2918 (ly:round-filled-box
2919 (ordered-cons (car attach-off)
2921 (* (- (sign dir)) stem-thickness)))
2922 (cons (min stemy (cdr attach-off))
2923 (max stemy (cdr attach-off)))
2924 (/ stem-thickness 3))))
2926 (dot (ly:font-get-glyph font "dots.dot"))
2927 (dotwid (interval-length (ly:stencil-extent dot X)))
2928 (dots (and (> dot-count 0)
2929 (apply ly:stencil-add
2931 (ly:stencil-translate-axis
2932 dot (* 2 x dotwid) X))
2933 (iota dot-count)))))
2934 (flaggl (and (> log 2)
2935 (ly:stencil-translate
2936 (ly:font-get-glyph font
2937 (string-append "flags."
2938 (if (> dir 0) "u" "d")
2939 (number->string log)))
2940 (cons (+ (car attach-off) (if (< dir 0)
2944 ;; If there is a flag on an upstem and the stem is short, move the dots
2945 ;; to avoid the flag. 16th notes get a special case because their flags
2946 ;; hang lower than any other flags.
2947 (if (and dots (> dir 0) (> log 2)
2948 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2949 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2951 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2952 (if (ly:stencil? stem-glyph)
2953 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2954 (set! stem-glyph head-glyph))
2955 (if (ly:stencil? dots)
2958 (ly:stencil-translate-axis
2960 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2966 (let ((divisor (log 2)))
2967 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2969 (define (parse-simple-duration duration-string)
2970 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2971 and return a (log dots) list."
2972 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2974 (if (and match (string=? duration-string (match:substring match 0)))
2975 (let ((len (match:substring match 1))
2976 (dots (match:substring match 2)))
2977 (list (cond ((string=? len "breve") -1)
2978 ((string=? len "longa") -2)
2979 ((string=? len "maxima") -3)
2980 (else (log2 (string->number len))))
2981 (if dots (string-length dots) 0)))
2982 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2984 (define-markup-command (note layout props duration dir)
2987 #:properties (note-by-number-markup)
2989 @cindex notes within text by string
2991 This produces a note with a stem pointing in @var{dir} direction, with
2992 the @var{duration} for the note head type and augmentation dots. For
2993 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2994 a shortened down stem.
2996 @lilypond[verbatim,quote]
2998 \\override #'(style . cross) {
3002 \\note #\"breve\" #0
3005 (let ((parsed (parse-simple-duration duration)))
3006 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3010 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3012 (define-markup-command (lower layout props amount arg)
3016 @cindex lowering text
3018 Lower @var{arg} by the distance @var{amount}.
3019 A negative @var{amount} indicates raising; see also @code{\\raise}.
3021 @lilypond[verbatim,quote]
3029 (ly:stencil-translate-axis (interpret-markup layout props arg)
3032 (define-markup-command (translate-scaled layout props offset arg)
3033 (number-pair? markup?)
3035 #:properties ((font-size 0))
3037 @cindex translating text
3038 @cindex scaling text
3040 Translate @var{arg} by @var{offset}, scaling the offset by the
3043 @lilypond[verbatim,quote]
3046 * \\translate #'(2 . 3) translate
3048 * \\translate-scaled #'(2 . 3) translate-scaled
3052 (let* ((factor (magstep font-size))
3053 (scaled (cons (* factor (car offset))
3054 (* factor (cdr offset)))))
3055 (ly:stencil-translate (interpret-markup layout props arg)
3058 (define-markup-command (raise layout props amount arg)
3062 @cindex raising text
3064 Raise @var{arg} by the distance @var{amount}.
3065 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3067 The argument to @code{\\raise} is the vertical displacement amount,
3068 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3069 raise objects in relation to their surrounding markups.
3071 If the text object itself is positioned above or below the staff, then
3072 @code{\\raise} cannot be used to move it, since the mechanism that
3073 positions it next to the staff cancels any shift made with
3074 @code{\\raise}. For vertical positioning, use the @code{padding}
3075 and/or @code{extra-offset} properties.
3077 @lilypond[verbatim,quote]
3086 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3088 (define-markup-command (fraction layout props arg1 arg2)
3091 #:properties ((font-size 0))
3093 @cindex creating text fractions
3095 Make a fraction of two markups.
3096 @lilypond[verbatim,quote]
3102 (let* ((m1 (interpret-markup layout props arg1))
3103 (m2 (interpret-markup layout props arg2))
3104 (factor (magstep font-size))
3105 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3106 (padding (* factor 0.2))
3107 (baseline (* factor 0.6))
3108 (offset (* factor 0.75)))
3109 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3110 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3111 (let* ((x1 (ly:stencil-extent m1 X))
3112 (x2 (ly:stencil-extent m2 X))
3113 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3114 ;; should stack mols separately, to maintain LINE on baseline
3115 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3117 (ly:stencil-aligned-to stack Y CENTER))
3119 (ly:stencil-aligned-to stack X LEFT))
3120 ;; should have EX dimension
3122 (ly:stencil-translate-axis stack offset Y))))
3124 (define-markup-command (normal-size-super layout props arg)
3127 #:properties ((baseline-skip))
3129 @cindex setting superscript in standard font size
3131 Set @var{arg} in superscript with a normal font size.
3133 @lilypond[verbatim,quote]
3136 \\normal-size-super {
3137 superscript in standard size
3141 (ly:stencil-translate-axis
3142 (interpret-markup layout props arg)
3143 (* 0.5 baseline-skip) Y))
3145 (define-markup-command (super layout props arg)
3148 #:properties ((font-size 0)
3151 @cindex superscript text
3153 Set @var{arg} in superscript.
3155 @lilypond[verbatim,quote]
3165 (ly:stencil-translate-axis
3168 (cons `((font-size . ,(- font-size 3))) props)
3170 (* 0.5 baseline-skip)
3173 (define-markup-command (translate layout props offset arg)
3174 (number-pair? markup?)
3177 @cindex translating text
3179 Translate @var{arg} relative to its surroundings. @var{offset}
3180 is a pair of numbers representing the displacement in the X and Y axis.
3182 @lilypond[verbatim,quote]
3185 \\translate #'(2 . 3)
3186 \\line { translated two spaces right, three up }
3189 (ly:stencil-translate (interpret-markup layout props arg)
3192 (define-markup-command (sub layout props arg)
3195 #:properties ((font-size 0)
3198 @cindex subscript text
3200 Set @var{arg} in subscript.
3202 @lilypond[verbatim,quote]
3213 (ly:stencil-translate-axis
3216 (cons `((font-size . ,(- font-size 3))) props)
3218 (* -0.5 baseline-skip)
3221 (define-markup-command (normal-size-sub layout props arg)
3224 #:properties ((baseline-skip))
3226 @cindex setting subscript in standard font size
3228 Set @var{arg} in subscript with a normal font size.
3230 @lilypond[verbatim,quote]
3234 subscript in standard size
3238 (ly:stencil-translate-axis
3239 (interpret-markup layout props arg)
3240 (* -0.5 baseline-skip)
3243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3247 (define-markup-command (hbracket layout props arg)
3251 @cindex placing horizontal brackets around text
3253 Draw horizontal brackets around @var{arg}.
3255 @lilypond[verbatim,quote]
3264 (let ((th 0.1) ;; todo: take from GROB.
3265 (m (interpret-markup layout props arg)))
3266 (bracketify-stencil m X th (* 2.5 th) th)))
3268 (define-markup-command (bracket layout props arg)
3272 @cindex placing vertical brackets around text
3274 Draw vertical brackets around @var{arg}.
3276 @lilypond[verbatim,quote]
3283 (let ((th 0.1) ;; todo: take from GROB.
3284 (m (interpret-markup layout props arg)))
3285 (bracketify-stencil m Y th (* 2.5 th) th)))
3287 (define-markup-command (parenthesize layout props arg)
3290 #:properties ((angularity 0)
3296 @cindex placing parentheses around text
3298 Draw parentheses around @var{arg}. This is useful for parenthesizing
3299 a column containing several lines of text.
3301 @lilypond[verbatim,quote]
3310 \\override #'(angularity . 2) {
3321 (let* ((markup (interpret-markup layout props arg))
3322 (scaled-width (* size width))
3324 (* (chain-assoc-get 'line-thickness props 0.1)
3327 (min (* size 0.5 scaled-thickness)
3328 (* (/ 4 3.0) scaled-width)))
3329 (padding (chain-assoc-get 'padding props half-thickness)))
3330 (parenthesize-stencil
3331 markup half-thickness scaled-width angularity padding)))
3334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3335 ;; Delayed markup evaluation
3336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3338 (define-markup-command (page-ref layout props label gauge default)
3339 (symbol? markup? markup?)
3342 @cindex referencing page numbers in text
3344 Reference to a page number. @var{label} is the label set on the referenced
3345 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3346 the maximum width of the page number, and @var{default} the value to display
3347 when @var{label} is not found."
3348 (let* ((gauge-stencil (interpret-markup layout props gauge))
3349 (x-ext (ly:stencil-extent gauge-stencil X))
3350 (y-ext (ly:stencil-extent gauge-stencil Y)))
3352 `(delay-stencil-evaluation
3353 ,(delay (ly:stencil-expr
3354 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3355 (page-number (if (list? table)
3356 (assoc-get label table)
3358 (page-markup (if page-number (format "~a" page-number) default))
3359 (page-stencil (interpret-markup layout props page-markup))
3360 (gap (- (interval-length x-ext)
3361 (interval-length (ly:stencil-extent page-stencil X)))))
3362 (interpret-markup layout props
3363 (markup #:concat (#:hspace gap page-markup)))))))
3367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3368 ;; Markup list commands
3369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3371 (define-public (space-lines baseline stils)
3372 (let space-stil ((stils stils)
3376 (let* ((stil (car stils))
3377 (dy-top (max (- (/ baseline 1.5)
3378 (interval-bound (ly:stencil-extent stil Y) UP))
3380 (dy-bottom (max (+ (/ baseline 3.0)
3381 (interval-bound (ly:stencil-extent stil Y) DOWN))
3383 (new-stil (ly:make-stencil
3384 (ly:stencil-expr stil)
3385 (ly:stencil-extent stil X)
3386 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3388 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3390 (space-stil (cdr stils) (cons new-stil result))))))
3392 (define-markup-list-command (justified-lines layout props args)
3394 #:properties ((baseline-skip)
3395 wordwrap-internal-markup-list)
3397 @cindex justifying lines of text
3399 Like @code{\\justify}, but return a list of lines instead of a single markup.
3400 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3401 @var{X}@tie{}is the number of staff spaces."
3402 (space-lines baseline-skip
3403 (interpret-markup-list layout props
3404 (make-wordwrap-internal-markup-list #t args))))
3406 (define-markup-list-command (wordwrap-lines layout props args)
3408 #:properties ((baseline-skip)
3409 wordwrap-internal-markup-list)
3410 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3411 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3412 where @var{X} is the number of staff spaces."
3413 (space-lines baseline-skip
3414 (interpret-markup-list layout props
3415 (make-wordwrap-internal-markup-list #f args))))
3417 (define-markup-list-command (column-lines layout props args)
3419 #:properties ((baseline-skip))
3420 "Like @code{\\column}, but return a list of lines instead of a single markup.
3421 @code{baseline-skip} determines the space between each markup in @var{args}."
3422 (space-lines baseline-skip
3423 (interpret-markup-list layout props args)))
3425 (define-markup-list-command (override-lines layout props new-prop args)
3426 (pair? markup-list?)
3427 "Like @code{\\override}, for markup lists."
3428 (interpret-markup-list layout (cons (list new-prop) props) args))