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-hline layout props)
145 #:properties ((draw-line-markup)
149 @cindex drawing a line across a page
151 Draws a line across a page, where the property @code{span-factor}
152 controls what fraction of the page is taken up.
153 @lilypond[verbatim,quote]
157 \\override #'(span-factor . 1/3)
162 (interpret-markup layout
164 (markup #:draw-line (cons (* line-width
168 (define-markup-command (draw-circle layout props radius thickness filled)
169 (number? number? boolean?)
172 @cindex drawing circles within text
174 A circle of radius @var{radius} and thickness @var{thickness},
177 @lilypond[verbatim,quote]
179 \\draw-circle #2 #0.5 ##f
181 \\draw-circle #2 #0 ##t
184 (make-circle-stencil radius thickness filled))
186 (define-markup-command (triangle layout props filled)
189 #:properties ((thickness 0.1)
193 @cindex drawing triangles within text
195 A triangle, either filled or empty.
197 @lilypond[verbatim,quote]
204 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
213 (cons 0 (* .86 ex)))))
215 (define-markup-command (circle layout props arg)
218 #:properties ((thickness 1)
220 (circle-padding 0.2))
222 @cindex circling text
224 Draw a circle around @var{arg}. Use @code{thickness},
225 @code{circle-padding} and @code{font-size} properties to determine line
226 thickness and padding around the markup.
228 @lilypond[verbatim,quote]
235 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
237 (pad (* (magstep font-size) circle-padding))
238 (m (interpret-markup layout props arg)))
239 (circle-stencil m th pad)))
241 (define-markup-command (with-url layout props url arg)
245 @cindex inserting URL links into text
247 Add a link to URL @var{url} around @var{arg}. This only works in
250 @lilypond[verbatim,quote]
252 \\with-url #\"http://lilypond.org/web/\" {
253 LilyPond ... \\italic {
254 music notation for everyone
259 (let* ((stil (interpret-markup layout props arg))
260 (xextent (ly:stencil-extent stil X))
261 (yextent (ly:stencil-extent stil Y))
262 (old-expr (ly:stencil-expr stil))
263 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
265 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
267 (define-markup-command (beam layout props width slope thickness)
268 (number? number? number?)
271 @cindex drawing beams within text
273 Create a beam with the specified parameters.
274 @lilypond[verbatim,quote]
279 (let* ((y (* slope width))
280 (yext (cons (min 0 y) (max 0 y)))
281 (half (/ thickness 2)))
286 width (+ (* width slope) (/ thickness -2))
287 width (+ (* width slope) (/ thickness 2))
289 ,(ly:output-def-lookup layout 'blot-diameter)
292 (cons (+ (- half) (car yext))
293 (+ half (cdr yext))))))
295 (define-markup-command (underline layout props arg)
298 #:properties ((thickness 1) (offset 2))
300 @cindex underlining text
302 Underline @var{arg}. Looks at @code{thickness} to determine line
303 thickness, and @code{offset} to determine line y-offset.
305 @lilypond[verbatim,quote]
306 \\markup \\fill-line {
307 \\underline \"underlined\"
308 \\override #'(offset . 5)
309 \\override #'(thickness . 1)
310 \\underline \"underlined\"
311 \\override #'(offset . 1)
312 \\override #'(thickness . 5)
313 \\underline \"underlined\"
316 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
317 (underline-thick (* thickness thick))
318 (markup (interpret-markup layout props arg))
319 (x1 (car (ly:stencil-extent markup X)))
320 (x2 (cdr (ly:stencil-extent markup X)))
321 (y (* thick (- offset)))
322 (line (make-line-stencil underline-thick x1 y x2 y)))
323 (ly:stencil-add markup line)))
325 (define-markup-command (box layout props arg)
328 #:properties ((thickness 1)
332 @cindex enclosing text within a box
334 Draw a box round @var{arg}. Looks at @code{thickness},
335 @code{box-padding} and @code{font-size} properties to determine line
336 thickness and padding around the markup.
338 @lilypond[verbatim,quote]
340 \\override #'(box-padding . 0.5)
345 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
347 (pad (* (magstep font-size) box-padding))
348 (m (interpret-markup layout props arg)))
349 (box-stencil m th pad)))
351 (define-markup-command (filled-box layout props xext yext blot)
352 (number-pair? number-pair? number?)
355 @cindex drawing solid boxes within text
356 @cindex drawing boxes with rounded corners
358 Draw a box with rounded corners of dimensions @var{xext} and
359 @var{yext}. For example,
361 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
363 creates a box extending horizontally from -0.3 to 1.8 and
364 vertically from -0.3 up to 1.8, with corners formed from a
365 circle of diameter@tie{}0 (i.e., sharp corners).
367 @lilypond[verbatim,quote]
369 \\filled-box #'(0 . 4) #'(0 . 4) #0
370 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
371 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
373 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
379 (define-markup-command (rounded-box layout props arg)
382 #:properties ((thickness 1)
386 "@cindex enclosing text in a box with rounded corners
387 @cindex drawing boxes with rounded corners around text
388 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
389 @code{box-padding} and @code{font-size} properties to determine line
390 thickness and padding around the markup; the @code{corner-radius} property
391 makes it possible to define another shape for the corners (default is 1).
393 @lilypond[quote,verbatim,relative=2]
401 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
403 (pad (* (magstep font-size) box-padding))
404 (m (interpret-markup layout props arg)))
405 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
408 (define-markup-command (rotate layout props ang arg)
412 @cindex rotating text
414 Rotate object with @var{ang} degrees around its center.
416 @lilypond[verbatim,quote]
426 (let* ((stil (interpret-markup layout props arg)))
427 (ly:stencil-rotate stil ang 0 0)))
429 (define-markup-command (whiteout layout props arg)
433 @cindex adding a white background to text
435 Provide a white background for @var{arg}.
437 @lilypond[verbatim,quote]
440 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
444 (stencil-whiteout (interpret-markup layout props arg)))
446 (define-markup-command (pad-markup layout props amount arg)
451 @cindex putting space around text
453 Add space around a markup object.
455 @lilypond[verbatim,quote]
469 ((stil (interpret-markup layout props arg))
470 (xext (ly:stencil-extent stil X))
471 (yext (ly:stencil-extent stil Y)))
474 (ly:stencil-expr stil)
475 (interval-widen xext amount)
476 (interval-widen yext amount))))
478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
482 (define-markup-command (strut layout props)
486 @cindex creating vertical spaces in text
488 Create a box of the same height as the space in the current font."
489 (let ((m (ly:text-interface::interpret-markup layout props " ")))
490 (ly:make-stencil (ly:stencil-expr m)
492 (ly:stencil-extent m X)
495 ;; todo: fix negative space
496 (define-markup-command (hspace layout props amount)
499 #:properties ((word-space))
501 @cindex creating horizontal spaces in text
503 Create an invisible object taking up horizontal space @var{amount}.
505 @lilypond[verbatim,quote]
514 (let ((corrected-space (- amount word-space)))
515 (if (> corrected-space 0)
516 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
517 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
519 ;; todo: fix negative space
520 (define-markup-command (vspace layout props amount)
524 @cindex creating vertical spaces in text
526 Create an invisible object taking up vertical space
527 of @var{amount} multiplied by 3.
529 @lilypond[verbatim,quote]
540 (let ((amount (* amount 3.0)))
542 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
543 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
547 ;; importing graphics.
548 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
550 (define-markup-command (stencil layout props stil)
554 @cindex importing stencils into text
556 Use a stencil as markup.
558 @lilypond[verbatim,quote]
560 \\stencil #(make-circle-stencil 2 0 #t)
566 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
568 (define (get-postscript-bbox string)
569 "Extract the bbox from STRING, or return #f if not present."
571 ((match (regexp-exec bbox-regexp string)))
575 (string->number (match:substring match x)))
580 (define-markup-command (epsfile layout props axis size file-name)
581 (number? number? string?)
584 @cindex inlining an Encapsulated PostScript image
586 Inline an EPS image. The image is scaled along @var{axis} to
589 @lilypond[verbatim,quote]
591 \\general-align #Y #DOWN {
592 \\epsfile #X #20 #\"context-example.eps\"
593 \\epsfile #Y #20 #\"context-example.eps\"
597 (if (ly:get-option 'safe)
598 (interpret-markup layout props "not allowed in safe")
599 (eps-file->stencil axis size file-name)
602 (define-markup-command (postscript layout props str)
606 @cindex inserting PostScript directly into text
607 This inserts @var{str} directly into the output as a PostScript
610 @lilypond[verbatim,quote]
614 0.4 0.6 0.5 0 361 arc
616 1.0 0.6 0.5 0 361 arc
621 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
622 \\postscript #ringsps
634 gsave currentpoint translate
642 (define-markup-command (path layout props thickness commands) (number? list?)
644 #:properties ((line-cap-style 'round)
645 (line-join-style 'round)
648 @cindex paths, drawing
649 @cindex drawing paths
650 Draws a path with line thickness @var{thickness} according to the
651 directions given in @var{commands}. @var{commands} is a list of
652 lists where the @code{car} of each sublist is a drawing command and
653 the @code{cdr} comprises the associated arguments for each command.
655 Line-cap styles and line-join styles may be customized by
656 overriding the @code{line-cap-style} and @code{line-join-style}
657 properties, respectively. Available line-cap styles are
658 @code{'butt}, @code{'round}, and @code{'square}. Available
659 line-join styles are @code{'miter}, @code{'round}, and
662 The property @code{filled} specifies whether or not the path is
665 There are seven commands available to use in the list
666 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
667 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
668 @code{closepath}. Note that the commands that begin with @emph{r}
669 are the relative variants of the other three commands.
671 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
672 @code{rlineto} take 2 arguments; they are the X and Y coordinates
673 for the destination point.
675 The commands @code{curveto} and @code{rcurveto} create cubic
676 Bézier curves, and take 6 arguments; the first two are the X and Y
677 coordinates for the first control point, the second two are the X
678 and Y coordinates for the second control point, and the last two
679 are the X and Y coordinates for the destination point.
681 The @code{closepath} command takes zero arguments and closes the
682 current subpath in the active path.
684 Note that a sequence of commands @emph{must} begin with a
685 @code{moveto} or @code{rmoveto} to work with the SVG output.
687 @lilypond[verbatim,quote]
693 (curveto -5 -5 -5 5 -1 0)
697 \\path #0.25 #samplePath
700 (let* ((half-thickness (/ thickness 2))
701 (current-point '(0 . 0))
702 (set-point (lambda (lst) (set! current-point lst)))
703 (relative? (lambda (x)
704 (string-prefix? "r" (symbol->string (car x)))))
705 ;; For calculating extents, we want to modify the command
706 ;; list so that all coordinates are absolute.
707 (new-commands (map (lambda (x)
709 ;; for rmoveto, rlineto
710 ((and (relative? x) (eq? 3 (length x)))
712 (+ (car current-point)
714 (+ (cdr current-point)
720 ((and (relative? x) (eq? 7 (length x)))
721 (let* ((old-cp current-point)
728 (list (+ (car old-cp) (second x))
729 (+ (cdr old-cp) (third x))
730 (+ (car old-cp) (fourth x))
731 (+ (cdr old-cp) (fifth x))
734 ;; for moveto, lineto
736 (set-point (cons (second x)
741 (set-point (cons (sixth x)
744 ;; keep closepath for filtering;
745 ;; see `without-closepath'.
748 ;; path-min-max does not accept 0-arg lists,
749 ;; and since closepath does not affect extents, filter
750 ;; out those commands here.
751 (without-closepath (filter (lambda (x)
752 (not (equal? 'closepath (car x))))
754 (extents (path-min-max
755 ;; set the origin to the first moveto
756 (list (list-ref (car without-closepath) 0)
757 (list-ref (car without-closepath) 1))
759 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
760 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
761 (command-list (fold-right append '() commands)))
763 ;; account for line thickness
764 (set! X-extent (interval-widen X-extent half-thickness))
765 (set! Y-extent (interval-widen Y-extent half-thickness))
768 `(path ,thickness `(,@',command-list)
769 ',line-cap-style ',line-join-style ,filled)
773 (define-markup-command (score layout props score)
776 #:properties ((baseline-skip))
778 @cindex inserting music into text
780 Inline an image of music.
782 @lilypond[verbatim,quote]
786 \\new Staff \\relative c' {
789 \\mark \\markup { Allegro }
795 \\new Staff \\relative c {
809 \\override RehearsalMark #'break-align-symbols =
810 #'(time-signature key-signature)
811 \\override RehearsalMark #'self-alignment-X = #LEFT
815 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
821 (let ((output (ly:score-embedded-format score layout)))
823 (if (ly:music-output? output)
824 (stack-stencils Y DOWN baseline-skip
825 (map paper-system-stencil
827 (ly:paper-score-paper-systems output))))
829 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
832 (define-markup-command (null layout props)
836 @cindex creating empty text objects
838 An empty markup with extents of a single point.
840 @lilypond[verbatim,quote]
847 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
849 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
851 (define-markup-command (simple layout props str)
855 @cindex simple text strings
857 A simple text string; @code{\\markup @{ foo @}} is equivalent with
858 @code{\\markup @{ \\simple #\"foo\" @}}.
860 Note: for creating standard text markup or defining new markup commands,
861 the use of @code{\\simple} is unnecessary.
863 @lilypond[verbatim,quote]
867 \\simple #\"strings\"
870 (interpret-markup layout props str))
872 (define-markup-command (tied-lyric layout props str)
876 @cindex simple text strings with tie characters
878 Like simple-markup, but use tie characters for @q{~} tilde symbols.
880 @lilypond[verbatim,quote]
882 \\tied-lyric #\"Lasciate~i monti\"
885 (if (string-contains str "~")
887 ((parts (string-split str #\~))
888 (tie-str (ly:wide-char->utf-8 #x203f))
889 (joined (list-join parts tie-str))
890 (join-stencil (interpret-markup layout props tie-str))
893 (interpret-markup layout
896 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
898 (make-line-markup joined)))
899 ;(map (lambda (s) (interpret-markup layout props s)) parts))
900 (interpret-markup layout props str)))
902 (define-public empty-markup
903 (make-simple-markup ""))
905 ;; helper for justifying lines.
906 (define (get-fill-space word-count line-width word-space text-widths)
907 "Calculate the necessary paddings between each two adjacent texts.
908 The lengths of all texts are stored in @var{text-widths}.
909 The normal formula for the padding between texts a and b is:
910 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
911 The first and last padding have to be calculated specially using the
912 whole length of the first or last text.
913 All paddings are checked to be at least word-space, to ensure that
915 Return a list of paddings."
917 ((null? text-widths) '())
919 ;; special case first padding
920 ((= (length text-widths) word-count)
922 (- (- (/ line-width (1- word-count)) (car text-widths))
923 (/ (car (cdr text-widths)) 2))
924 (get-fill-space word-count line-width word-space (cdr text-widths))))
925 ;; special case last padding
926 ((= (length text-widths) 2)
927 (list (- (/ line-width (1- word-count))
928 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
930 (let ((default-padding
931 (- (/ line-width (1- word-count))
932 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
934 (if (> word-space default-padding)
937 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
939 (define-markup-command (fill-line layout props args)
942 #:properties ((text-direction RIGHT)
945 "Put @var{markups} in a horizontal line of width @var{line-width}.
946 The markups are spaced or flushed to fill the entire line.
947 If there are no arguments, return an empty stencil.
949 @lilypond[verbatim,quote]
953 Words evenly spaced across the page
957 \\line { Text markups }
959 \\italic { evenly spaced }
961 \\line { across the page }
966 (let* ((orig-stencils (interpret-markup-list layout props args))
969 (if (ly:stencil-empty? stc)
971 stc)) orig-stencils))
974 (if (ly:stencil-empty? stc)
976 (interval-length (ly:stencil-extent stc X))))
978 (text-width (apply + text-widths))
979 (word-count (length stencils))
980 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
985 (/ (- line-width text-width) 2)
986 (/ (- line-width text-width) 2)))
989 (- line-width text-width)))
991 (get-fill-space word-count line-width word-space text-widths))))
993 (line-contents (if (= word-count 1)
1000 (if (null? (remove ly:stencil-empty? orig-stencils))
1003 (if (= text-direction LEFT)
1004 (set! line-contents (reverse line-contents)))
1006 (stack-stencils-padding-list
1007 X RIGHT fill-space line-contents))
1008 (if (> word-count 1)
1009 ;; shift s.t. stencils align on the left edge, even if
1010 ;; first stencil had negative X-extent (e.g. center-column)
1011 ;; (if word-count = 1, X-extents are already normalized in
1012 ;; the definition of line-contents)
1014 (ly:stencil-translate-axis
1016 (- (car (ly:stencil-extent (car stencils) X)))
1020 (define-markup-command (line layout props args)
1023 #:properties ((word-space)
1024 (text-direction RIGHT))
1025 "Put @var{args} in a horizontal line. The property @code{word-space}
1026 determines the space between markups in @var{args}.
1028 @lilypond[verbatim,quote]
1035 (let ((stencils (interpret-markup-list layout props args)))
1036 (if (= text-direction LEFT)
1037 (set! stencils (reverse stencils)))
1040 (remove ly:stencil-empty? stencils))))
1042 (define-markup-command (concat layout props args)
1046 @cindex concatenating text
1047 @cindex ligatures in text
1049 Concatenate @var{args} in a horizontal line, without spaces in between.
1050 Strings and simple markups are concatenated on the input level, allowing
1051 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1052 equivalent to @code{\"fi\"}.
1054 @lilypond[verbatim,quote]
1063 (define (concat-string-args arg-list)
1064 (fold-right (lambda (arg result-list)
1065 (let ((result (if (pair? result-list)
1068 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1069 (set! arg (cadr arg)))
1070 (if (and (string? result) (string? arg))
1071 (cons (string-append arg result) (cdr result-list))
1072 (cons arg result-list))))
1076 (interpret-markup layout
1077 (prepend-alist-chain 'word-space 0 props)
1078 (make-line-markup (if (markup-command-list? args)
1080 (concat-string-args args)))))
1082 (define (wordwrap-stencils stencils
1083 justify base-space line-width text-dir)
1084 "Perform simple wordwrap, return stencil of each line."
1085 (define space (if justify
1086 ;; justify only stretches lines.
1089 (define (take-list width space stencils
1090 accumulator accumulated-width)
1091 "Return (head-list . tail) pair, with head-list fitting into width"
1092 (if (null? stencils)
1093 (cons accumulator stencils)
1094 (let* ((first (car stencils))
1095 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1096 (newwid (+ space first-wid accumulated-width)))
1097 (if (or (null? accumulator)
1099 (take-list width space
1101 (cons first accumulator)
1103 (cons accumulator stencils)))))
1104 (let loop ((lines '())
1106 (let* ((line-break (take-list line-width space todo
1108 (line-stencils (car line-break))
1109 (space-left (- line-width
1110 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1112 (line-word-space (cond ((not justify) space)
1113 ;; don't stretch last line of paragraph.
1114 ;; hmmm . bug - will overstretch the last line in some case.
1115 ((null? (cdr line-break))
1117 ((null? line-stencils) 0.0)
1118 ((null? (cdr line-stencils)) 0.0)
1119 (else (/ space-left (1- (length line-stencils))))))
1120 (line (stack-stencil-line line-word-space
1121 (if (= text-dir RIGHT)
1122 (reverse line-stencils)
1124 (if (pair? (cdr line-break))
1125 (loop (cons line lines)
1128 (if (= text-dir LEFT)
1130 (ly:stencil-translate-axis
1132 (- line-width (interval-end (ly:stencil-extent line X)))
1134 (reverse (cons line lines)))))))
1136 (define-markup-list-command (wordwrap-internal layout props justify args)
1137 (boolean? markup-list?)
1138 #:properties ((line-width #f)
1140 (text-direction RIGHT))
1141 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1142 (wordwrap-stencils (remove ly:stencil-empty?
1143 (interpret-markup-list layout props args))
1147 (ly:output-def-lookup layout 'line-width))
1150 (define-markup-command (justify layout props args)
1153 #:properties ((baseline-skip)
1154 wordwrap-internal-markup-list)
1156 @cindex justifying text
1158 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1159 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1160 @var{X}@tie{}is the number of staff spaces.
1162 @lilypond[verbatim,quote]
1165 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1166 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1167 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1168 laboris nisi ut aliquip ex ea commodo consequat.
1172 (stack-lines DOWN 0.0 baseline-skip
1173 (wordwrap-internal-markup-list layout props #t args)))
1175 (define-markup-command (wordwrap layout props args)
1178 #:properties ((baseline-skip)
1179 wordwrap-internal-markup-list)
1180 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1181 the line width, where @var{X} is the number of staff spaces.
1183 @lilypond[verbatim,quote]
1186 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1187 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1188 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1189 laboris nisi ut aliquip ex ea commodo consequat.
1193 (stack-lines DOWN 0.0 baseline-skip
1194 (wordwrap-internal-markup-list layout props #f args)))
1196 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1198 #:properties ((line-width)
1200 (text-direction RIGHT))
1201 "Internal markup list command used to define @code{\\justify-string} and
1202 @code{\\wordwrap-string}."
1203 (let* ((para-strings (regexp-split
1204 (string-regexp-substitute
1206 (string-regexp-substitute "\r\n" "\n" arg))
1207 "\n[ \t\n]*\n[ \t\n]*"))
1208 (list-para-words (map (lambda (str)
1209 (regexp-split str "[ \t\n]+"))
1211 (para-lines (map (lambda (words)
1213 (remove ly:stencil-empty?
1215 (interpret-markup layout props x))
1217 (wordwrap-stencils stencils
1219 line-width text-direction)))
1221 (apply append para-lines)))
1223 (define-markup-command (wordwrap-string layout props arg)
1226 #:properties ((baseline-skip)
1227 wordwrap-string-internal-markup-list)
1228 "Wordwrap a string. Paragraphs may be separated with double newlines.
1230 @lilypond[verbatim,quote]
1232 \\override #'(line-width . 40)
1233 \\wordwrap-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 #f arg)))
1249 (define-markup-command (justify-string layout props arg)
1252 #:properties ((baseline-skip)
1253 wordwrap-string-internal-markup-list)
1254 "Justify a string. Paragraphs may be separated with double newlines
1256 @lilypond[verbatim,quote]
1258 \\override #'(line-width . 40)
1259 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1260 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1261 et dolore magna aliqua.
1264 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1265 laboris nisi ut aliquip ex ea commodo consequat.
1268 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1269 qui officia deserunt mollit anim id est laborum\"
1272 (stack-lines DOWN 0.0 baseline-skip
1273 (wordwrap-string-internal-markup-list layout props #t arg)))
1275 (define-markup-command (wordwrap-field layout props symbol)
1278 "Wordwrap the data which has been assigned to @var{symbol}.
1280 @lilypond[verbatim,quote]
1282 title = \"My title\"
1283 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1284 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1285 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1286 laboris nisi ut aliquip ex ea commodo consequat.\"
1290 bookTitleMarkup = \\markup {
1292 \\fill-line { \\fromproperty #'header:title }
1294 \\wordwrap-field #'header:myText
1303 (let* ((m (chain-assoc-get symbol props)))
1305 (wordwrap-string-markup layout props m)
1308 (define-markup-command (justify-field layout props symbol)
1311 "Justify the data which has been assigned to @var{symbol}.
1313 @lilypond[verbatim,quote]
1315 title = \"My title\"
1316 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1317 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1318 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1319 laboris nisi ut aliquip ex ea commodo consequat.\"
1323 bookTitleMarkup = \\markup {
1325 \\fill-line { \\fromproperty #'header:title }
1327 \\justify-field #'header:myText
1336 (let* ((m (chain-assoc-get symbol props)))
1338 (justify-string-markup layout props m)
1341 (define-markup-command (combine layout props arg1 arg2)
1345 @cindex merging text
1347 Print two markups on top of each other.
1349 Note: @code{\\combine} cannot take a list of markups enclosed in
1350 curly braces as an argument; the follow example will not compile:
1353 \\combine @{ a list @}
1356 @lilypond[verbatim,quote]
1359 \\override #'(thickness . 2)
1361 \\draw-line #'(0 . 4)
1362 \\arrow-head #Y #DOWN ##f
1365 (let* ((s1 (interpret-markup layout props arg1))
1366 (s2 (interpret-markup layout props arg2)))
1367 (ly:stencil-add s1 s2)))
1370 ;; TODO: should extract baseline-skip from each argument somehow..
1372 (define-markup-command (column layout props args)
1375 #:properties ((baseline-skip))
1377 @cindex stacking text in a column
1379 Stack the markups in @var{args} vertically. The property
1380 @code{baseline-skip} determines the space between markups
1383 @lilypond[verbatim,quote]
1392 (let ((arg-stencils (interpret-markup-list layout props args)))
1393 (stack-lines -1 0.0 baseline-skip
1394 (remove ly:stencil-empty? arg-stencils))))
1396 (define-markup-command (dir-column layout props args)
1399 #:properties ((direction)
1402 @cindex changing direction of text columns
1404 Make a column of @var{args}, going up or down, depending on the
1405 setting of the @code{direction} layout property.
1407 @lilypond[verbatim,quote]
1409 \\override #`(direction . ,UP) {
1419 \\override #'(direction . 1) {
1426 (stack-lines (if (number? direction) direction -1)
1429 (interpret-markup-list layout props args)))
1431 (define (general-column align-dir baseline mols)
1432 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1434 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1435 (stack-lines -1 0.0 baseline aligned-mols)))
1437 (define-markup-command (center-column layout props args)
1440 #:properties ((baseline-skip))
1442 @cindex centering a column of text
1444 Put @code{args} in a centered column.
1446 @lilypond[verbatim,quote]
1455 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1457 (define-markup-command (left-column layout props args)
1460 #:properties ((baseline-skip))
1462 @cindex text columns, left-aligned
1464 Put @code{args} in a left-aligned column.
1466 @lilypond[verbatim,quote]
1475 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1477 (define-markup-command (right-column layout props args)
1480 #:properties ((baseline-skip))
1482 @cindex text columns, right-aligned
1484 Put @code{args} in a right-aligned column.
1486 @lilypond[verbatim,quote]
1495 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1497 (define-markup-command (vcenter layout props arg)
1501 @cindex vertically centering text
1503 Align @code{arg} to its Y@tie{}center.
1505 @lilypond[verbatim,quote]
1513 (let* ((mol (interpret-markup layout props arg)))
1514 (ly:stencil-aligned-to mol Y CENTER)))
1516 (define-markup-command (center-align layout props arg)
1520 @cindex horizontally centering text
1522 Align @code{arg} to its X@tie{}center.
1524 @lilypond[verbatim,quote]
1534 (let* ((mol (interpret-markup layout props arg)))
1535 (ly:stencil-aligned-to mol X CENTER)))
1537 (define-markup-command (right-align layout props arg)
1541 @cindex right aligning text
1543 Align @var{arg} on its right edge.
1545 @lilypond[verbatim,quote]
1555 (let* ((m (interpret-markup layout props arg)))
1556 (ly:stencil-aligned-to m X RIGHT)))
1558 (define-markup-command (left-align layout props arg)
1562 @cindex left aligning text
1564 Align @var{arg} on its left edge.
1566 @lilypond[verbatim,quote]
1576 (let* ((m (interpret-markup layout props arg)))
1577 (ly:stencil-aligned-to m X LEFT)))
1579 (define-markup-command (general-align layout props axis dir arg)
1580 (integer? number? markup?)
1583 @cindex controlling general text alignment
1585 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1587 @lilypond[verbatim,quote]
1591 \\general-align #X #LEFT
1596 \\general-align #X #CENTER
1602 \\general-align #Y #UP
1609 \\general-align #Y #3.2
1616 (let* ((m (interpret-markup layout props arg)))
1617 (ly:stencil-aligned-to m axis dir)))
1619 (define-markup-command (halign layout props dir arg)
1623 @cindex setting horizontal text alignment
1625 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1626 left-aligned, while @code{+1} is right. Values in between interpolate
1627 alignment accordingly.
1629 @lilypond[verbatim,quote]
1654 (let* ((m (interpret-markup layout props arg)))
1655 (ly:stencil-aligned-to m X dir)))
1657 (define-markup-command (with-dimensions layout props x y arg)
1658 (number-pair? number-pair? markup?)
1661 @cindex setting extent of text objects
1663 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1664 (let* ((m (interpret-markup layout props arg)))
1665 (ly:make-stencil (ly:stencil-expr m) x y)))
1667 (define-markup-command (pad-around layout props amount arg)
1670 "Add padding @var{amount} all around @var{arg}.
1672 @lilypond[verbatim,quote]
1685 (let* ((m (interpret-markup layout props arg))
1686 (x (ly:stencil-extent m X))
1687 (y (ly:stencil-extent m Y)))
1688 (ly:make-stencil (ly:stencil-expr m)
1689 (interval-widen x amount)
1690 (interval-widen y amount))))
1692 (define-markup-command (pad-x layout props amount arg)
1696 @cindex padding text horizontally
1698 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1700 @lilypond[verbatim,quote]
1713 (let* ((m (interpret-markup layout props arg))
1714 (x (ly:stencil-extent m X))
1715 (y (ly:stencil-extent m Y)))
1716 (ly:make-stencil (ly:stencil-expr m)
1717 (interval-widen x amount)
1720 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1721 (integer? ly:dir? markup? markup?)
1723 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1724 (let ((m1 (interpret-markup layout props arg1))
1725 (m2 (interpret-markup layout props arg2)))
1726 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1728 (define-markup-command (transparent layout props arg)
1731 "Make @var{arg} transparent.
1733 @lilypond[verbatim,quote]
1740 (let* ((m (interpret-markup layout props arg))
1741 (x (ly:stencil-extent m X))
1742 (y (ly:stencil-extent m Y)))
1743 (ly:make-stencil "" x y)))
1745 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1746 (number-pair? number-pair? markup?)
1748 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1750 @lilypond[verbatim,quote]
1757 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1763 (let* ((m (interpret-markup layout props arg))
1764 (x (ly:stencil-extent m X))
1765 (y (ly:stencil-extent m Y)))
1766 (ly:make-stencil (ly:stencil-expr m)
1767 (interval-union x-ext x)
1768 (interval-union y-ext y))))
1770 (define-markup-command (hcenter-in layout props length arg)
1773 "Center @var{arg} horizontally within a box of extending
1774 @var{length}/2 to the left and right.
1776 @lilypond[quote,verbatim]
1779 \\set Staff.instrumentName = \\markup {
1786 \\set Staff.instrumentName = \\markup {
1795 (interpret-markup layout props
1796 (make-pad-to-box-markup
1797 (cons (/ length -2) (/ length 2))
1799 (make-center-align-markup arg))))
1801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1805 (define-markup-command (fromproperty layout props symbol)
1808 "Read the @var{symbol} from property settings, and produce a stencil
1809 from the markup contained within. If @var{symbol} is not defined, it
1810 returns an empty markup.
1812 @lilypond[verbatim,quote]
1814 myTitle = \"myTitle\"
1818 \\fromproperty #'header:myTitle
1825 (let ((m (chain-assoc-get symbol props)))
1827 (interpret-markup layout props m)
1830 (define-markup-command (on-the-fly layout props procedure arg)
1833 "Apply the @var{procedure} markup command to @var{arg}.
1834 @var{procedure} should take a single argument."
1835 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1836 (set-object-property! anonymous-with-signature
1839 (interpret-markup layout props (list anonymous-with-signature arg))))
1841 (define-markup-command (footnote layout props mkup note)
1844 "Have footnote @var{note} act as an annotation to the markup @var{mkup}."
1845 (ly:stencil-combine-at-edge
1846 (interpret-markup layout props mkup)
1850 `(footnote ,(interpret-markup layout props note))
1855 (define-markup-command (override layout props new-prop arg)
1859 @cindex overriding properties within text markup
1861 Add the argument @var{new-prop} to the property list. Properties
1862 may be any property supported by @rinternals{font-interface},
1863 @rinternals{text-interface} and
1864 @rinternals{instrument-specific-markup-interface}.
1866 @lilypond[verbatim,quote]
1874 \\override #'(baseline-skip . 4) {
1883 (interpret-markup layout (cons (list new-prop) props) arg))
1885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1889 (define-markup-command (verbatim-file layout props name)
1892 "Read the contents of file @var{name}, and include it verbatim.
1894 @lilypond[verbatim,quote]
1896 \\verbatim-file #\"simple.ly\"
1899 (interpret-markup layout props
1900 (if (ly:get-option 'safe)
1901 "verbatim-file disabled in safe mode"
1902 (let* ((str (ly:gulp-file name))
1903 (lines (string-split str #\nl)))
1904 (make-typewriter-markup
1905 (make-column-markup lines))))))
1907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1909 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1912 (define-markup-command (smaller layout props arg)
1915 "Decrease the font size relative to the current setting.
1917 @lilypond[verbatim,quote]
1930 (interpret-markup layout props
1931 `(,fontsize-markup -1 ,arg)))
1933 (define-markup-command (larger layout props arg)
1936 "Increase the font size relative to the current setting.
1938 @lilypond[verbatim,quote]
1946 (interpret-markup layout props
1947 `(,fontsize-markup 1 ,arg)))
1949 (define-markup-command (finger layout props arg)
1952 "Set @var{arg} as small numbers.
1954 @lilypond[verbatim,quote]
1961 (interpret-markup layout
1962 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1965 (define-markup-command (abs-fontsize layout props size arg)
1968 "Use @var{size} as the absolute font size to display @var{arg}.
1969 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1971 @lilypond[verbatim,quote]
1973 default text font size
1975 \\abs-fontsize #16 { text font size 16 }
1977 \\abs-fontsize #12 { text font size 12 }
1980 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1981 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1982 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1983 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1984 (magnification (/ size ref-size)))
1985 (interpret-markup layout
1986 (cons `((baseline-skip . ,(* magnification ref-baseline))
1987 (word-space . ,(* magnification ref-word-space))
1988 (font-size . ,(magnification->font-size magnification)))
1992 (define-markup-command (fontsize layout props increment arg)
1995 #:properties ((font-size 0)
1998 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2001 @lilypond[verbatim,quote]
2009 (let ((entries (list
2010 (cons 'baseline-skip (* baseline-skip (magstep increment)))
2011 (cons 'word-space (* word-space (magstep increment)))
2012 (cons 'font-size (+ font-size increment)))))
2013 (interpret-markup layout (cons entries props) arg)))
2015 (define-markup-command (magnify layout props sz arg)
2019 @cindex magnifying text
2021 Set the font magnification for its argument. In the following
2022 example, the middle@tie{}A is 10% larger:
2025 A \\magnify #1.1 @{ A @} A
2028 Note: Magnification only works if a font name is explicitly selected.
2029 Use @code{\\fontsize} otherwise.
2031 @lilypond[verbatim,quote]
2042 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2045 (define-markup-command (bold layout props arg)
2048 "Switch to bold font-series.
2050 @lilypond[verbatim,quote]
2058 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2060 (define-markup-command (sans layout props arg)
2063 "Switch to the sans serif font family.
2065 @lilypond[verbatim,quote]
2074 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2076 (define-markup-command (number layout props arg)
2079 "Set font family to @code{number}, which yields the font used for
2080 time signatures and fingerings. This font contains numbers and
2081 some punctuation; it has no letters.
2083 @lilypond[verbatim,quote]
2086 0 1 2 3 4 5 6 7 8 9 . ,
2090 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2092 (define-markup-command (roman layout props arg)
2095 "Set font family to @code{roman}.
2097 @lilypond[verbatim,quote]
2103 text in roman font family
2110 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2112 (define-markup-command (huge layout props arg)
2115 "Set font size to +2.
2117 @lilypond[verbatim,quote]
2125 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2127 (define-markup-command (large layout props arg)
2130 "Set font size to +1.
2132 @lilypond[verbatim,quote]
2140 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2142 (define-markup-command (normalsize layout props arg)
2145 "Set font size to default.
2147 @lilypond[verbatim,quote]
2160 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2162 (define-markup-command (small layout props arg)
2165 "Set font size to -1.
2167 @lilypond[verbatim,quote]
2175 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2177 (define-markup-command (tiny layout props arg)
2180 "Set font size to -2.
2182 @lilypond[verbatim,quote]
2190 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2192 (define-markup-command (teeny layout props arg)
2195 "Set font size to -3.
2197 @lilypond[verbatim,quote]
2205 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2207 (define-markup-command (fontCaps layout props arg)
2210 "Set @code{font-shape} to @code{caps}
2212 Note: @code{\\fontCaps} requires the installation and selection of
2213 fonts which support the @code{caps} font shape."
2214 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2217 (define-markup-command (smallCaps layout props arg)
2220 "Emit @var{arg} as small caps.
2222 Note: @code{\\smallCaps} does not support accented characters.
2224 @lilypond[verbatim,quote]
2233 (define (char-list->markup chars lower)
2234 (let ((final-string (string-upcase (reverse-list->string chars))))
2236 (markup #:fontsize -2 final-string)
2238 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2239 (if (null? rest-chars)
2241 (reverse! (cons (char-list->markup currents current-is-lower)
2243 (let* ((ch (car rest-chars))
2244 (is-lower (char-lower-case? ch)))
2245 (if (or (and current-is-lower is-lower)
2246 (and (not current-is-lower) (not is-lower)))
2247 (make-small-caps (cdr rest-chars)
2251 (make-small-caps (cdr rest-chars)
2254 (if (null? currents)
2256 (cons (char-list->markup
2257 currents current-is-lower)
2259 (interpret-markup layout props
2261 (make-small-caps (string->list arg) (list) #f (list))
2264 (define-markup-command (caps layout props arg)
2267 "Copy of the @code{\\smallCaps} command.
2269 @lilypond[verbatim,quote]
2278 (interpret-markup layout props (make-smallCaps-markup arg)))
2280 (define-markup-command (dynamic layout props arg)
2283 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2284 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2285 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2286 done in a different font. The recommended font for this is bold and italic.
2287 @lilypond[verbatim,quote]
2295 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2297 (define-markup-command (text layout props arg)
2300 "Use a text font instead of music symbol or music alphabet font.
2302 @lilypond[verbatim,quote]
2315 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2318 (define-markup-command (italic layout props arg)
2321 "Use italic @code{font-shape} for @var{arg}.
2323 @lilypond[verbatim,quote]
2331 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2333 (define-markup-command (typewriter layout props arg)
2336 "Use @code{font-family} typewriter for @var{arg}.
2338 @lilypond[verbatim,quote]
2347 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2349 (define-markup-command (upright layout props arg)
2352 "Set @code{font-shape} to @code{upright}. This is the opposite
2355 @lilypond[verbatim,quote]
2369 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2371 (define-markup-command (medium layout props arg)
2374 "Switch to medium font-series (in contrast to bold).
2376 @lilypond[verbatim,quote]
2389 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2392 (define-markup-command (normal-text layout props arg)
2395 "Set all font related properties (except the size) to get the default
2396 normal text font, no matter what font was used earlier.
2398 @lilypond[verbatim,quote]
2400 \\huge \\bold \\sans \\caps {
2401 Some text with font overrides
2404 Default text, same font-size
2412 (interpret-markup layout
2413 (cons '((font-family . roman) (font-shape . upright)
2414 (font-series . medium) (font-encoding . latin1))
2418 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2420 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2422 (define-markup-command (musicglyph layout props glyph-name)
2425 "@var{glyph-name} is converted to a musical symbol; for example,
2426 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2427 the music font. See @ruser{The Feta font} for a complete listing of
2428 the possible glyphs.
2430 @lilypond[verbatim,quote]
2433 \\musicglyph #\"rests.2\"
2434 \\musicglyph #\"clefs.G_change\"
2437 (let* ((font (ly:paper-get-font layout
2438 (cons '((font-encoding . fetaMusic)
2442 (glyph (ly:font-get-glyph font glyph-name)))
2443 (if (null? (ly:stencil-expr glyph))
2444 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2448 (define-markup-command (doublesharp layout props)
2451 "Draw a double sharp symbol.
2453 @lilypond[verbatim,quote]
2458 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2460 (define-markup-command (sesquisharp layout props)
2463 "Draw a 3/2 sharp symbol.
2465 @lilypond[verbatim,quote]
2470 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2472 (define-markup-command (sharp layout props)
2475 "Draw a sharp symbol.
2477 @lilypond[verbatim,quote]
2482 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2484 (define-markup-command (semisharp layout props)
2487 "Draw a semisharp symbol.
2489 @lilypond[verbatim,quote]
2494 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2496 (define-markup-command (natural layout props)
2499 "Draw a natural symbol.
2501 @lilypond[verbatim,quote]
2506 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2508 (define-markup-command (semiflat layout props)
2511 "Draw a semiflat symbol.
2513 @lilypond[verbatim,quote]
2518 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2520 (define-markup-command (flat layout props)
2523 "Draw a flat symbol.
2525 @lilypond[verbatim,quote]
2530 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2532 (define-markup-command (sesquiflat layout props)
2535 "Draw a 3/2 flat symbol.
2537 @lilypond[verbatim,quote]
2542 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2544 (define-markup-command (doubleflat layout props)
2547 "Draw a double flat symbol.
2549 @lilypond[verbatim,quote]
2554 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2556 (define-markup-command (with-color layout props color arg)
2560 @cindex coloring text
2562 Draw @var{arg} in color specified by @var{color}.
2564 @lilypond[verbatim,quote]
2576 (let ((stil (interpret-markup layout props arg)))
2577 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2578 (ly:stencil-extent stil X)
2579 (ly:stencil-extent stil Y))))
2581 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2583 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2585 (define-markup-command (arrow-head layout props axis dir filled)
2586 (integer? ly:dir? boolean?)
2588 "Produce an arrow head in specified direction and axis.
2589 Use the filled head if @var{filled} is specified.
2590 @lilypond[verbatim,quote]
2593 \\general-align #Y #DOWN {
2594 \\arrow-head #Y #UP ##t
2595 \\arrow-head #Y #DOWN ##f
2597 \\arrow-head #X #RIGHT ##f
2598 \\arrow-head #X #LEFT ##f
2604 ((name (format "arrowheads.~a.~a~a"
2611 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2615 (define-markup-command (lookup layout props glyph-name)
2618 "Lookup a glyph by name.
2620 @lilypond[verbatim,quote]
2622 \\override #'(font-encoding . fetaBraces) {
2623 \\lookup #\"brace200\"
2626 \\lookup #\"brace180\"
2630 (ly:font-get-glyph (ly:paper-get-font layout props)
2633 (define-markup-command (char layout props num)
2636 "Produce a single character. Characters encoded in hexadecimal
2637 format require the prefix @code{#x}.
2639 @lilypond[verbatim,quote]
2641 \\char #65 \\char ##x00a9
2644 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2646 (define number->mark-letter-vector (make-vector 25 #\A))
2651 (if (= i (- (char->integer #\I) (char->integer #\A)))
2653 (vector-set! number->mark-letter-vector j
2654 (integer->char (+ i (char->integer #\A)))))
2656 (define number->mark-alphabet-vector (list->vector
2657 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2659 (define (number->markletter-string vec n)
2660 "Double letters for big marks."
2661 (let* ((lst (vector-length vec)))
2664 (string-append (number->markletter-string vec (1- (quotient n lst)))
2665 (number->markletter-string vec (remainder n lst)))
2666 (make-string 1 (vector-ref vec n)))))
2668 (define-markup-command (markletter layout props num)
2671 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2672 (skipping letter@tie{}I), and continue with double letters.
2674 @lilypond[verbatim,quote]
2681 (ly:text-interface::interpret-markup layout props
2682 (number->markletter-string number->mark-letter-vector num)))
2684 (define-markup-command (markalphabet layout props num)
2687 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2688 and continue with double letters.
2690 @lilypond[verbatim,quote]
2697 (ly:text-interface::interpret-markup layout props
2698 (number->markletter-string number->mark-alphabet-vector num)))
2700 (define-public (horizontal-slash-interval num forward number-interval mag)
2702 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2703 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2704 (else (interval-widen number-interval (* mag 0.25))))
2705 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2706 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2707 (else (interval-widen number-interval (* mag 0.25))))
2710 (define-public (adjust-slash-stencil num forward stencil mag)
2713 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2715 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2717 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2719 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2722 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2724 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2729 (define (slashed-digit-internal layout props num forward font-size thickness)
2730 (let* ((mag (magstep font-size))
2732 (ly:output-def-lookup layout 'line-thickness)
2734 ; backward slashes might use slope and point in the other direction!
2735 (dy (* mag (if forward 0.4 -0.4)))
2736 (number-stencil (interpret-markup layout
2737 (prepend-alist-chain 'font-encoding 'fetaText props)
2738 (number->string num)))
2739 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2740 (center (interval-center (ly:stencil-extent number-stencil Y)))
2741 ; Use the real extents of the slash, not the whole number, because we
2742 ; might translate the slash later on!
2743 (num-y (interval-widen (cons center center) (abs dy)))
2744 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2745 (slash-stencil (if is-sane
2746 (make-line-stencil thickness
2747 (car num-x) (- (interval-center num-y) dy)
2748 (cdr num-x) (+ (interval-center num-y) dy))
2750 (if (ly:stencil? slash-stencil)
2752 ; for some numbers we need to shift the slash/backslash up or down to make
2753 ; the slashed digit look better
2754 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2755 (set! number-stencil
2756 (ly:stencil-add number-stencil slash-stencil)))
2757 (ly:warning "Unable to create slashed digit ~a" num))
2761 (define-markup-command (slashed-digit layout props num)
2764 #:properties ((font-size 0)
2767 @cindex slashed digits
2769 A feta number, with slash. This is for use in the context of
2770 figured bass notation.
2771 @lilypond[verbatim,quote]
2775 \\override #'(thickness . 3)
2779 (slashed-digit-internal layout props num #t font-size thickness))
2781 (define-markup-command (backslashed-digit layout props num)
2784 #:properties ((font-size 0)
2787 @cindex backslashed digits
2789 A feta number, with backslash. This is for use in the context of
2790 figured bass notation.
2791 @lilypond[verbatim,quote]
2793 \\backslashed-digit #5
2795 \\override #'(thickness . 3)
2796 \\backslashed-digit #7
2799 (slashed-digit-internal layout props num #f font-size thickness))
2802 (define eyeglassespath
2803 '((moveto 0.42 0.77)
2804 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2805 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2806 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2807 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2810 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2811 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2812 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2813 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2815 (moveto 1.025 0.935)
2816 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2817 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2820 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2823 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2825 (define-markup-command (eyeglasses layout props)
2828 "Prints out eyeglasses, indicating strongly to look at the conductor.
2829 @lilypond[verbatim,quote]
2830 \\markup { \\eyeglasses }
2832 (interpret-markup layout props
2833 (make-override-markup '(line-cap-style . butt)
2834 (make-path-markup 0.15 eyeglassespath))))
2836 (define-markup-command (left-brace layout props size)
2840 A feta brace in point size @var{size}.
2842 @lilypond[verbatim,quote]
2849 (let* ((font (ly:paper-get-font layout
2850 (cons '((font-encoding . fetaBraces)
2853 (glyph-count (1- (ly:otf-glyph-count font)))
2854 (scale (ly:output-def-lookup layout 'output-scale))
2855 (scaled-size (/ (ly:pt size) scale))
2857 (ly:font-get-glyph font (string-append "brace"
2858 (number->string n)))))
2859 (get-y-from-brace (lambda (brace)
2861 (ly:stencil-extent (glyph brace) Y))))
2862 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2863 (glyph-found (glyph find-brace)))
2865 (if (or (null? (ly:stencil-expr glyph-found))
2866 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2867 (> scaled-size (interval-length
2868 (ly:stencil-extent (glyph glyph-count) Y))))
2870 (ly:warning (_ "no brace found for point size ~S ") size)
2871 (ly:warning (_ "defaulting to ~S pt")
2872 (/ (* scale (interval-length
2873 (ly:stencil-extent glyph-found Y)))
2877 (define-markup-command (right-brace layout props size)
2881 A feta brace in point size @var{size}, rotated 180 degrees.
2883 @lilypond[verbatim,quote]
2890 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2892 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2893 ;; the note command.
2894 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2896 ;; TODO: better syntax.
2898 (define-markup-command (note-by-number layout props log dot-count dir)
2899 (number? number? number?)
2901 #:properties ((font-size 0)
2904 @cindex notes within text by log and dot-count
2906 Construct a note symbol, with stem. By using fractional values for
2907 @var{dir}, longer or shorter stems can be obtained.
2909 @lilypond[verbatim,quote]
2911 \\note-by-number #3 #0 #DOWN
2913 \\note-by-number #1 #2 #0.8
2916 (define (get-glyph-name-candidates dir log style)
2917 (map (lambda (dir-name)
2918 (format "noteheads.~a~a" dir-name
2919 (if (and (symbol? style)
2920 (not (equal? 'default style)))
2921 (select-head-glyph style (min log 2))
2923 (list (if (= dir UP) "u" "d")
2926 (define (get-glyph-name font cands)
2929 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2930 (get-glyph-name font (cdr cands))
2933 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2935 (size-factor (magstep font-size))
2936 (stem-length (* size-factor (max 3 (- log 1))))
2938 (let ((result (get-glyph-name font (get-glyph-name-candidates
2939 (sign dir) log style))))
2940 (if (string-null? result)
2941 ;; If no glyph name can be found, select default heads. Though
2942 ;; this usually means an unsupported style has been chosen, it
2943 ;; also prevents unrelated 'style settings from other grobs
2944 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2945 (get-glyph-name font (get-glyph-name-candidates
2946 (sign dir) log 'default))
2948 (head-glyph (ly:font-get-glyph font head-glyph-name))
2949 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2950 (stem-thickness (* size-factor 0.13))
2951 (stemy (* dir stem-length))
2952 (attach-off (cons (interval-index
2953 (ly:stencil-extent head-glyph X)
2954 (* (sign dir) (car attach-indices)))
2955 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2957 (ly:stencil-extent head-glyph Y)
2958 (cdr attach-indices)))))
2959 (stem-glyph (and (> log 0)
2960 (ly:round-filled-box
2961 (ordered-cons (car attach-off)
2963 (* (- (sign dir)) stem-thickness)))
2964 (cons (min stemy (cdr attach-off))
2965 (max stemy (cdr attach-off)))
2966 (/ stem-thickness 3))))
2968 (dot (ly:font-get-glyph font "dots.dot"))
2969 (dotwid (interval-length (ly:stencil-extent dot X)))
2970 (dots (and (> dot-count 0)
2971 (apply ly:stencil-add
2973 (ly:stencil-translate-axis
2974 dot (* 2 x dotwid) X))
2975 (iota dot-count)))))
2976 (flaggl (and (> log 2)
2977 (ly:stencil-translate
2978 (ly:font-get-glyph font
2979 (string-append "flags."
2980 (if (> dir 0) "u" "d")
2981 (number->string log)))
2982 (cons (+ (car attach-off) (if (< dir 0)
2986 ;; If there is a flag on an upstem and the stem is short, move the dots
2987 ;; to avoid the flag. 16th notes get a special case because their flags
2988 ;; hang lower than any other flags.
2989 (if (and dots (> dir 0) (> log 2)
2990 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2991 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2993 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2994 (if (ly:stencil? stem-glyph)
2995 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2996 (set! stem-glyph head-glyph))
2997 (if (ly:stencil? dots)
3000 (ly:stencil-translate-axis
3002 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3008 (let ((divisor (log 2)))
3009 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3011 (define (parse-simple-duration duration-string)
3012 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3013 and return a (log dots) list."
3014 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3016 (if (and match (string=? duration-string (match:substring match 0)))
3017 (let ((len (match:substring match 1))
3018 (dots (match:substring match 2)))
3019 (list (cond ((string=? len "breve") -1)
3020 ((string=? len "longa") -2)
3021 ((string=? len "maxima") -3)
3022 (else (log2 (string->number len))))
3023 (if dots (string-length dots) 0)))
3024 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3026 (define-markup-command (note layout props duration dir)
3029 #:properties (note-by-number-markup)
3031 @cindex notes within text by string
3033 This produces a note with a stem pointing in @var{dir} direction, with
3034 the @var{duration} for the note head type and augmentation dots. For
3035 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3036 a shortened down stem.
3038 @lilypond[verbatim,quote]
3040 \\override #'(style . cross) {
3044 \\note #\"breve\" #0
3047 (let ((parsed (parse-simple-duration duration)))
3048 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3052 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3054 (define-markup-command (lower layout props amount arg)
3058 @cindex lowering text
3060 Lower @var{arg} by the distance @var{amount}.
3061 A negative @var{amount} indicates raising; see also @code{\\raise}.
3063 @lilypond[verbatim,quote]
3071 (ly:stencil-translate-axis (interpret-markup layout props arg)
3074 (define-markup-command (translate-scaled layout props offset arg)
3075 (number-pair? markup?)
3077 #:properties ((font-size 0))
3079 @cindex translating text
3080 @cindex scaling text
3082 Translate @var{arg} by @var{offset}, scaling the offset by the
3085 @lilypond[verbatim,quote]
3088 * \\translate #'(2 . 3) translate
3090 * \\translate-scaled #'(2 . 3) translate-scaled
3094 (let* ((factor (magstep font-size))
3095 (scaled (cons (* factor (car offset))
3096 (* factor (cdr offset)))))
3097 (ly:stencil-translate (interpret-markup layout props arg)
3100 (define-markup-command (raise layout props amount arg)
3104 @cindex raising text
3106 Raise @var{arg} by the distance @var{amount}.
3107 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3109 The argument to @code{\\raise} is the vertical displacement amount,
3110 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3111 raise objects in relation to their surrounding markups.
3113 If the text object itself is positioned above or below the staff, then
3114 @code{\\raise} cannot be used to move it, since the mechanism that
3115 positions it next to the staff cancels any shift made with
3116 @code{\\raise}. For vertical positioning, use the @code{padding}
3117 and/or @code{extra-offset} properties.
3119 @lilypond[verbatim,quote]
3128 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3130 (define-markup-command (fraction layout props arg1 arg2)
3133 #:properties ((font-size 0))
3135 @cindex creating text fractions
3137 Make a fraction of two markups.
3138 @lilypond[verbatim,quote]
3144 (let* ((m1 (interpret-markup layout props arg1))
3145 (m2 (interpret-markup layout props arg2))
3146 (factor (magstep font-size))
3147 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3148 (padding (* factor 0.2))
3149 (baseline (* factor 0.6))
3150 (offset (* factor 0.75)))
3151 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3152 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3153 (let* ((x1 (ly:stencil-extent m1 X))
3154 (x2 (ly:stencil-extent m2 X))
3155 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3156 ;; should stack mols separately, to maintain LINE on baseline
3157 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3159 (ly:stencil-aligned-to stack Y CENTER))
3161 (ly:stencil-aligned-to stack X LEFT))
3162 ;; should have EX dimension
3164 (ly:stencil-translate-axis stack offset Y))))
3166 (define-markup-command (normal-size-super layout props arg)
3169 #:properties ((baseline-skip))
3171 @cindex setting superscript in standard font size
3173 Set @var{arg} in superscript with a normal font size.
3175 @lilypond[verbatim,quote]
3178 \\normal-size-super {
3179 superscript in standard size
3183 (ly:stencil-translate-axis
3184 (interpret-markup layout props arg)
3185 (* 0.5 baseline-skip) Y))
3187 (define-markup-command (super layout props arg)
3190 #:properties ((font-size 0)
3193 @cindex superscript text
3195 Set @var{arg} in superscript.
3197 @lilypond[verbatim,quote]
3207 (ly:stencil-translate-axis
3210 (cons `((font-size . ,(- font-size 3))) props)
3212 (* 0.5 baseline-skip)
3215 (define-markup-command (translate layout props offset arg)
3216 (number-pair? markup?)
3219 @cindex translating text
3221 Translate @var{arg} relative to its surroundings. @var{offset}
3222 is a pair of numbers representing the displacement in the X and Y axis.
3224 @lilypond[verbatim,quote]
3227 \\translate #'(2 . 3)
3228 \\line { translated two spaces right, three up }
3231 (ly:stencil-translate (interpret-markup layout props arg)
3234 (define-markup-command (sub layout props arg)
3237 #:properties ((font-size 0)
3240 @cindex subscript text
3242 Set @var{arg} in subscript.
3244 @lilypond[verbatim,quote]
3255 (ly:stencil-translate-axis
3258 (cons `((font-size . ,(- font-size 3))) props)
3260 (* -0.5 baseline-skip)
3263 (define-markup-command (normal-size-sub layout props arg)
3266 #:properties ((baseline-skip))
3268 @cindex setting subscript in standard font size
3270 Set @var{arg} in subscript with a normal font size.
3272 @lilypond[verbatim,quote]
3276 subscript in standard size
3280 (ly:stencil-translate-axis
3281 (interpret-markup layout props arg)
3282 (* -0.5 baseline-skip)
3285 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3289 (define-markup-command (hbracket layout props arg)
3293 @cindex placing horizontal brackets around text
3295 Draw horizontal brackets around @var{arg}.
3297 @lilypond[verbatim,quote]
3306 (let ((th 0.1) ;; todo: take from GROB.
3307 (m (interpret-markup layout props arg)))
3308 (bracketify-stencil m X th (* 2.5 th) th)))
3310 (define-markup-command (bracket layout props arg)
3314 @cindex placing vertical brackets around text
3316 Draw vertical brackets around @var{arg}.
3318 @lilypond[verbatim,quote]
3325 (let ((th 0.1) ;; todo: take from GROB.
3326 (m (interpret-markup layout props arg)))
3327 (bracketify-stencil m Y th (* 2.5 th) th)))
3329 (define-markup-command (parenthesize layout props arg)
3332 #:properties ((angularity 0)
3338 @cindex placing parentheses around text
3340 Draw parentheses around @var{arg}. This is useful for parenthesizing
3341 a column containing several lines of text.
3343 @lilypond[verbatim,quote]
3352 \\override #'(angularity . 2) {
3363 (let* ((markup (interpret-markup layout props arg))
3364 (scaled-width (* size width))
3366 (* (chain-assoc-get 'line-thickness props 0.1)
3369 (min (* size 0.5 scaled-thickness)
3370 (* (/ 4 3.0) scaled-width)))
3371 (padding (chain-assoc-get 'padding props half-thickness)))
3372 (parenthesize-stencil
3373 markup half-thickness scaled-width angularity padding)))
3376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3377 ;; Delayed markup evaluation
3378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3380 (define-markup-command (page-ref layout props label gauge default)
3381 (symbol? markup? markup?)
3384 @cindex referencing page numbers in text
3386 Reference to a page number. @var{label} is the label set on the referenced
3387 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3388 the maximum width of the page number, and @var{default} the value to display
3389 when @var{label} is not found."
3390 (let* ((gauge-stencil (interpret-markup layout props gauge))
3391 (x-ext (ly:stencil-extent gauge-stencil X))
3392 (y-ext (ly:stencil-extent gauge-stencil Y)))
3394 `(delay-stencil-evaluation
3395 ,(delay (ly:stencil-expr
3396 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3397 (page-number (if (list? table)
3398 (assoc-get label table)
3400 (page-markup (if page-number (format "~a" page-number) default))
3401 (page-stencil (interpret-markup layout props page-markup))
3402 (gap (- (interval-length x-ext)
3403 (interval-length (ly:stencil-extent page-stencil X)))))
3404 (interpret-markup layout props
3405 (markup #:concat (#:hspace gap page-markup)))))))
3409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3413 (define-markup-command (scale layout props factor-pair arg)
3414 (number-pair? markup?)
3417 @cindex scaling markup
3418 @cindex mirroring markup
3420 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3421 representing the scaling-factor in the X and Y axes.
3422 Negative values may be used to produce mirror images.
3424 @lilypond[verbatim,quote]
3434 (let ((stil (interpret-markup layout props arg))
3435 (sx (car factor-pair))
3436 (sy (cdr factor-pair)))
3437 (ly:stencil-scale stil sx sy)))
3439 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3441 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3443 (define-markup-command (pattern layout props count axis space pattern)
3444 (integer? integer? number? markup?)
3447 Prints @var{count} times a @var{pattern} markup.
3448 Patterns are spaced apart by @var{space}.
3449 Patterns are distributed on @var{axis}.
3451 @lilypond[verbatim, quote]
3453 \"Horizontally repeated :\"
3454 \\pattern #7 #X #2 \\flat
3456 \"Vertically repeated :\"
3457 \\pattern #3 #Y #0.5 \\flat
3460 (let ((pattern-width (interval-length
3461 (ly:stencil-extent (interpret-markup layout props pattern) X)))
3462 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3463 (let loop ((i (1- count)) (patterns (markup)))
3469 (markup patterns pattern)
3470 (markup #:column (patterns pattern))))
3473 (markup patterns pattern #:hspace space)
3474 (markup #:column (patterns pattern #:vspace space))))))))
3476 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3477 (number? ly:dir? markup? markup? markup?)
3479 #:properties ((word-space)
3482 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3483 with a line of markups @var{pattern} in between.
3484 Patterns are spaced apart by @var{space}.
3485 Patterns are aligned to the @var{dir} markup.
3487 @lilypond[verbatim, quote]
3490 \\fill-with-pattern #1 #RIGHT . first right
3491 \\fill-with-pattern #1 #RIGHT . second right
3493 \"center-aligned :\"
3494 \\fill-with-pattern #1.5 #CENTER - left right
3497 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left first
3498 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left second
3501 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3502 (pattern-width (interval-length pattern-x-extent))
3503 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3504 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3505 (middle-width (- line-width (+ (+ left-width right-width) (* word-space 2))))
3506 (period (+ space pattern-width))
3507 (count (truncate (/ (- middle-width pattern-width) period)))
3508 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3509 (interpret-markup layout props
3511 #:with-dimensions (cons 0 middle-width) '(0 . 0)
3512 #:translate (cons x-offset 0)
3513 #:pattern (1+ count) X space pattern
3516 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3517 ;; Markup list commands
3518 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3520 (define-public (space-lines baseline stils)
3521 (let space-stil ((stils stils)
3525 (let* ((stil (car stils))
3526 (dy-top (max (- (/ baseline 1.5)
3527 (interval-bound (ly:stencil-extent stil Y) UP))
3529 (dy-bottom (max (+ (/ baseline 3.0)
3530 (interval-bound (ly:stencil-extent stil Y) DOWN))
3532 (new-stil (ly:make-stencil
3533 (ly:stencil-expr stil)
3534 (ly:stencil-extent stil X)
3535 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3537 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3539 (space-stil (cdr stils) (cons new-stil result))))))
3541 (define-markup-list-command (justified-lines layout props args)
3543 #:properties ((baseline-skip)
3544 wordwrap-internal-markup-list)
3546 @cindex justifying lines of text
3548 Like @code{\\justify}, but return a list of lines instead of a single markup.
3549 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3550 @var{X}@tie{}is the number of staff spaces."
3551 (space-lines baseline-skip
3552 (interpret-markup-list layout props
3553 (make-wordwrap-internal-markup-list #t args))))
3555 (define-markup-list-command (wordwrap-lines layout props args)
3557 #:properties ((baseline-skip)
3558 wordwrap-internal-markup-list)
3559 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3560 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3561 where @var{X} is the number of staff spaces."
3562 (space-lines baseline-skip
3563 (interpret-markup-list layout props
3564 (make-wordwrap-internal-markup-list #f args))))
3566 (define-markup-list-command (column-lines layout props args)
3568 #:properties ((baseline-skip))
3569 "Like @code{\\column}, but return a list of lines instead of a single markup.
3570 @code{baseline-skip} determines the space between each markup in @var{args}."
3571 (space-lines baseline-skip
3572 (interpret-markup-list layout props args)))
3574 (define-markup-list-command (override-lines layout props new-prop args)
3575 (pair? markup-list?)
3576 "Like @code{\\override}, for markup lists."
3577 (interpret-markup-list layout (cons (list new-prop) props) args))