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 ((thickness 1))
147 @cindex drawing a line across a page
149 Draws a line across a page.
150 @lilypond[verbatim,quote]
155 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
157 (x (ly:output-def-lookup layout 'line-width))
159 (make-line-stencil th 0 0 x y)))
161 (define-markup-command (draw-circle layout props radius thickness filled)
162 (number? number? boolean?)
165 @cindex drawing circles within text
167 A circle of radius @var{radius} and thickness @var{thickness},
170 @lilypond[verbatim,quote]
172 \\draw-circle #2 #0.5 ##f
174 \\draw-circle #2 #0 ##t
177 (make-circle-stencil radius thickness filled))
179 (define-markup-command (triangle layout props filled)
182 #:properties ((thickness 0.1)
186 @cindex drawing triangles within text
188 A triangle, either filled or empty.
190 @lilypond[verbatim,quote]
197 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
206 (cons 0 (* .86 ex)))))
208 (define-markup-command (circle layout props arg)
211 #:properties ((thickness 1)
213 (circle-padding 0.2))
215 @cindex circling text
217 Draw a circle around @var{arg}. Use @code{thickness},
218 @code{circle-padding} and @code{font-size} properties to determine line
219 thickness and padding around the markup.
221 @lilypond[verbatim,quote]
228 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
230 (pad (* (magstep font-size) circle-padding))
231 (m (interpret-markup layout props arg)))
232 (circle-stencil m th pad)))
234 (define-markup-command (with-url layout props url arg)
238 @cindex inserting URL links into text
240 Add a link to URL @var{url} around @var{arg}. This only works in
243 @lilypond[verbatim,quote]
245 \\with-url #\"http://lilypond.org/web/\" {
246 LilyPond ... \\italic {
247 music notation for everyone
252 (let* ((stil (interpret-markup layout props arg))
253 (xextent (ly:stencil-extent stil X))
254 (yextent (ly:stencil-extent stil Y))
255 (old-expr (ly:stencil-expr stil))
256 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
258 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
260 (define-markup-command (beam layout props width slope thickness)
261 (number? number? number?)
264 @cindex drawing beams within text
266 Create a beam with the specified parameters.
267 @lilypond[verbatim,quote]
272 (let* ((y (* slope width))
273 (yext (cons (min 0 y) (max 0 y)))
274 (half (/ thickness 2)))
279 width (+ (* width slope) (/ thickness -2))
280 width (+ (* width slope) (/ thickness 2))
282 ,(ly:output-def-lookup layout 'blot-diameter)
285 (cons (+ (- half) (car yext))
286 (+ half (cdr yext))))))
288 (define-markup-command (underline layout props arg)
291 #:properties ((thickness 1) (offset 2))
293 @cindex underlining text
295 Underline @var{arg}. Looks at @code{thickness} to determine line
296 thickness, and @code{offset} to determine line y-offset.
298 @lilypond[verbatim,quote]
299 \\markup \\fill-line {
300 \\underline \"underlined\"
301 \\override #'(offset . 5)
302 \\override #'(thickness . 1)
303 \\underline \"underlined\"
304 \\override #'(offset . 1)
305 \\override #'(thickness . 5)
306 \\underline \"underlined\"
309 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
310 (underline-thick (* thickness thick))
311 (markup (interpret-markup layout props arg))
312 (x1 (car (ly:stencil-extent markup X)))
313 (x2 (cdr (ly:stencil-extent markup X)))
314 (y (* thick (- offset)))
315 (line (make-line-stencil underline-thick x1 y x2 y)))
316 (ly:stencil-add markup line)))
318 (define-markup-command (box layout props arg)
321 #:properties ((thickness 1)
325 @cindex enclosing text within a box
327 Draw a box round @var{arg}. Looks at @code{thickness},
328 @code{box-padding} and @code{font-size} properties to determine line
329 thickness and padding around the markup.
331 @lilypond[verbatim,quote]
333 \\override #'(box-padding . 0.5)
338 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
340 (pad (* (magstep font-size) box-padding))
341 (m (interpret-markup layout props arg)))
342 (box-stencil m th pad)))
344 (define-markup-command (filled-box layout props xext yext blot)
345 (number-pair? number-pair? number?)
348 @cindex drawing solid boxes within text
349 @cindex drawing boxes with rounded corners
351 Draw a box with rounded corners of dimensions @var{xext} and
352 @var{yext}. For example,
354 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
356 creates a box extending horizontally from -0.3 to 1.8 and
357 vertically from -0.3 up to 1.8, with corners formed from a
358 circle of diameter@tie{}0 (i.e., sharp corners).
360 @lilypond[verbatim,quote]
362 \\filled-box #'(0 . 4) #'(0 . 4) #0
363 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
364 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
366 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
372 (define-markup-command (rounded-box layout props arg)
375 #:properties ((thickness 1)
379 "@cindex enclosing text in a box with rounded corners
380 @cindex drawing boxes with rounded corners around text
381 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
382 @code{box-padding} and @code{font-size} properties to determine line
383 thickness and padding around the markup; the @code{corner-radius} property
384 makes it possible to define another shape for the corners (default is 1).
386 @lilypond[quote,verbatim,relative=2]
394 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
396 (pad (* (magstep font-size) box-padding))
397 (m (interpret-markup layout props arg)))
398 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
401 (define-markup-command (rotate layout props ang arg)
405 @cindex rotating text
407 Rotate object with @var{ang} degrees around its center.
409 @lilypond[verbatim,quote]
419 (let* ((stil (interpret-markup layout props arg)))
420 (ly:stencil-rotate stil ang 0 0)))
422 (define-markup-command (whiteout layout props arg)
426 @cindex adding a white background to text
428 Provide a white background for @var{arg}.
430 @lilypond[verbatim,quote]
433 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
437 (stencil-whiteout (interpret-markup layout props arg)))
439 (define-markup-command (pad-markup layout props amount arg)
444 @cindex putting space around text
446 Add space around a markup object.
448 @lilypond[verbatim,quote]
462 ((stil (interpret-markup layout props arg))
463 (xext (ly:stencil-extent stil X))
464 (yext (ly:stencil-extent stil Y)))
467 (ly:stencil-expr stil)
468 (interval-widen xext amount)
469 (interval-widen yext amount))))
471 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
473 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
475 (define-markup-command (strut layout props)
479 @cindex creating vertical spaces in text
481 Create a box of the same height as the space in the current font."
482 (let ((m (ly:text-interface::interpret-markup layout props " ")))
483 (ly:make-stencil (ly:stencil-expr m)
485 (ly:stencil-extent m X)
488 ;; todo: fix negative space
489 (define-markup-command (hspace layout props amount)
492 #:properties ((word-space))
494 @cindex creating horizontal spaces in text
496 Create an invisible object taking up horizontal space @var{amount}.
498 @lilypond[verbatim,quote]
507 (let ((corrected-space (- amount word-space)))
508 (if (> corrected-space 0)
509 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
510 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
512 ;; todo: fix negative space
513 (define-markup-command (vspace layout props amount)
517 @cindex creating vertical spaces in text
519 Create an invisible object taking up vertical space
520 of @var{amount} multiplied by 3.
522 @lilypond[verbatim,quote]
533 (let ((amount (* amount 3.0)))
535 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
536 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
539 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
540 ;; importing graphics.
541 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
543 (define-markup-command (stencil layout props stil)
547 @cindex importing stencils into text
549 Use a stencil as markup.
551 @lilypond[verbatim,quote]
553 \\stencil #(make-circle-stencil 2 0 #t)
559 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
561 (define (get-postscript-bbox string)
562 "Extract the bbox from STRING, or return #f if not present."
564 ((match (regexp-exec bbox-regexp string)))
568 (string->number (match:substring match x)))
573 (define-markup-command (epsfile layout props axis size file-name)
574 (number? number? string?)
577 @cindex inlining an Encapsulated PostScript image
579 Inline an EPS image. The image is scaled along @var{axis} to
582 @lilypond[verbatim,quote]
584 \\general-align #Y #DOWN {
585 \\epsfile #X #20 #\"context-example.eps\"
586 \\epsfile #Y #20 #\"context-example.eps\"
590 (if (ly:get-option 'safe)
591 (interpret-markup layout props "not allowed in safe")
592 (eps-file->stencil axis size file-name)
595 (define-markup-command (postscript layout props str)
599 @cindex inserting PostScript directly into text
600 This inserts @var{str} directly into the output as a PostScript
603 @lilypond[verbatim,quote]
607 0.4 0.6 0.5 0 361 arc
609 1.0 0.6 0.5 0 361 arc
614 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
615 \\postscript #ringsps
627 gsave currentpoint translate
635 (define-markup-command (path layout props thickness commands) (number? list?)
637 #:properties ((line-cap-style 'round)
638 (line-join-style 'round)
641 @cindex paths, drawing
642 @cindex drawing paths
643 Draws a path with line thickness @var{thickness} according to the
644 directions given in @var{commands}. @var{commands} is a list of
645 lists where the @code{car} of each sublist is a drawing command and
646 the @code{cdr} comprises the associated arguments for each command.
648 Line-cap styles and line-join styles may be customized by
649 overriding the @code{line-cap-style} and @code{line-join-style}
650 properties, respectively. Available line-cap styles are
651 @code{'butt}, @code{'round}, and @code{'square}. Available
652 line-join styles are @code{'miter}, @code{'round}, and
655 The property @code{filled} specifies whether or not the path is
658 There are seven commands available to use in the list
659 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
660 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
661 @code{closepath}. Note that the commands that begin with @emph{r}
662 are the relative variants of the other three commands.
664 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
665 @code{rlineto} take 2 arguments; they are the X and Y coordinates
666 for the destination point.
668 The commands @code{curveto} and @code{rcurveto} create cubic
669 Bézier curves, and take 6 arguments; the first two are the X and Y
670 coordinates for the first control point, the second two are the X
671 and Y coordinates for the second control point, and the last two
672 are the X and Y coordinates for the destination point.
674 The @code{closepath} command takes zero arguments and closes the
675 current subpath in the active path.
677 Note that a sequence of commands @emph{must} begin with a
678 @code{moveto} or @code{rmoveto} to work with the SVG output.
680 @lilypond[verbatim,quote]
686 (curveto -5 -5 -5 5 -1 0)
690 \\path #0.25 #samplePath
693 (let* ((half-thickness (/ thickness 2))
694 (current-point '(0 . 0))
695 (set-point (lambda (lst) (set! current-point lst)))
696 (relative? (lambda (x)
697 (string-prefix? "r" (symbol->string (car x)))))
698 ;; For calculating extents, we want to modify the command
699 ;; list so that all coordinates are absolute.
700 (new-commands (map (lambda (x)
702 ;; for rmoveto, rlineto
703 ((and (relative? x) (eq? 3 (length x)))
705 (+ (car current-point)
707 (+ (cdr current-point)
713 ((and (relative? x) (eq? 7 (length x)))
714 (let* ((old-cp current-point)
721 (list (+ (car old-cp) (second x))
722 (+ (cdr old-cp) (third x))
723 (+ (car old-cp) (fourth x))
724 (+ (cdr old-cp) (fifth x))
727 ;; for moveto, lineto
729 (set-point (cons (second x)
734 (set-point (cons (sixth x)
737 ;; keep closepath for filtering;
738 ;; see `without-closepath'.
741 ;; path-min-max does not accept 0-arg lists,
742 ;; and since closepath does not affect extents, filter
743 ;; out those commands here.
744 (without-closepath (filter (lambda (x)
745 (not (equal? 'closepath (car x))))
747 (extents (path-min-max
748 ;; set the origin to the first moveto
749 (list (list-ref (car without-closepath) 0)
750 (list-ref (car without-closepath) 1))
752 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
753 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
754 (command-list (fold-right append '() commands)))
756 ;; account for line thickness
757 (set! X-extent (interval-widen X-extent half-thickness))
758 (set! Y-extent (interval-widen Y-extent half-thickness))
761 `(path ,thickness `(,@',command-list)
762 ',line-cap-style ',line-join-style ,filled)
766 (define-markup-command (score layout props score)
769 #:properties ((baseline-skip))
771 @cindex inserting music into text
773 Inline an image of music.
775 @lilypond[verbatim,quote]
779 \\new Staff \\relative c' {
782 \\mark \\markup { Allegro }
788 \\new Staff \\relative c {
802 \\override RehearsalMark #'break-align-symbols =
803 #'(time-signature key-signature)
804 \\override RehearsalMark #'self-alignment-X = #LEFT
808 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
814 (let ((output (ly:score-embedded-format score layout)))
816 (if (ly:music-output? output)
817 (stack-stencils Y DOWN baseline-skip
818 (map paper-system-stencil
820 (ly:paper-score-paper-systems output))))
822 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
825 (define-markup-command (null layout props)
829 @cindex creating empty text objects
831 An empty markup with extents of a single point.
833 @lilypond[verbatim,quote]
840 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
844 (define-markup-command (simple layout props str)
848 @cindex simple text strings
850 A simple text string; @code{\\markup @{ foo @}} is equivalent with
851 @code{\\markup @{ \\simple #\"foo\" @}}.
853 Note: for creating standard text markup or defining new markup commands,
854 the use of @code{\\simple} is unnecessary.
856 @lilypond[verbatim,quote]
860 \\simple #\"strings\"
863 (interpret-markup layout props str))
865 (define-markup-command (tied-lyric layout props str)
869 @cindex simple text strings with tie characters
871 Like simple-markup, but use tie characters for @q{~} tilde symbols.
873 @lilypond[verbatim,quote]
875 \\tied-lyric #\"Lasciate~i monti\"
878 (if (string-contains str "~")
880 ((parts (string-split str #\~))
881 (tie-str (ly:wide-char->utf-8 #x203f))
882 (joined (list-join parts tie-str))
883 (join-stencil (interpret-markup layout props tie-str))
886 (interpret-markup layout
889 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
891 (make-line-markup joined)))
892 ;(map (lambda (s) (interpret-markup layout props s)) parts))
893 (interpret-markup layout props str)))
895 (define-public empty-markup
896 (make-simple-markup ""))
898 ;; helper for justifying lines.
899 (define (get-fill-space word-count line-width word-space text-widths)
900 "Calculate the necessary paddings between each two adjacent texts.
901 The lengths of all texts are stored in @var{text-widths}.
902 The normal formula for the padding between texts a and b is:
903 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
904 The first and last padding have to be calculated specially using the
905 whole length of the first or last text.
906 All paddings are checked to be at least word-space, to ensure that
908 Return a list of paddings."
910 ((null? text-widths) '())
912 ;; special case first padding
913 ((= (length text-widths) word-count)
915 (- (- (/ line-width (1- word-count)) (car text-widths))
916 (/ (car (cdr text-widths)) 2))
917 (get-fill-space word-count line-width word-space (cdr text-widths))))
918 ;; special case last padding
919 ((= (length text-widths) 2)
920 (list (- (/ line-width (1- word-count))
921 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
923 (let ((default-padding
924 (- (/ line-width (1- word-count))
925 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
927 (if (> word-space default-padding)
930 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
932 (define-markup-command (fill-line layout props args)
935 #:properties ((text-direction RIGHT)
938 "Put @var{markups} in a horizontal line of width @var{line-width}.
939 The markups are spaced or flushed to fill the entire line.
940 If there are no arguments, return an empty stencil.
942 @lilypond[verbatim,quote]
946 Words evenly spaced across the page
950 \\line { Text markups }
952 \\italic { evenly spaced }
954 \\line { across the page }
959 (let* ((orig-stencils (interpret-markup-list layout props args))
962 (if (ly:stencil-empty? stc)
964 stc)) orig-stencils))
967 (if (ly:stencil-empty? stc)
969 (interval-length (ly:stencil-extent stc X))))
971 (text-width (apply + text-widths))
972 (word-count (length stencils))
973 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
978 (/ (- line-width text-width) 2)
979 (/ (- line-width text-width) 2)))
982 (- line-width text-width)))
984 (get-fill-space word-count line-width word-space text-widths))))
986 (line-contents (if (= word-count 1)
993 (if (null? (remove ly:stencil-empty? orig-stencils))
996 (if (= text-direction LEFT)
997 (set! line-contents (reverse line-contents)))
999 (stack-stencils-padding-list
1000 X RIGHT fill-space line-contents))
1001 (if (> word-count 1)
1002 ;; shift s.t. stencils align on the left edge, even if
1003 ;; first stencil had negative X-extent (e.g. center-column)
1004 ;; (if word-count = 1, X-extents are already normalized in
1005 ;; the definition of line-contents)
1007 (ly:stencil-translate-axis
1009 (- (car (ly:stencil-extent (car stencils) X)))
1013 (define-markup-command (line layout props args)
1016 #:properties ((word-space)
1017 (text-direction RIGHT))
1018 "Put @var{args} in a horizontal line. The property @code{word-space}
1019 determines the space between markups in @var{args}.
1021 @lilypond[verbatim,quote]
1028 (let ((stencils (interpret-markup-list layout props args)))
1029 (if (= text-direction LEFT)
1030 (set! stencils (reverse stencils)))
1033 (remove ly:stencil-empty? stencils))))
1035 (define-markup-command (concat layout props args)
1039 @cindex concatenating text
1040 @cindex ligatures in text
1042 Concatenate @var{args} in a horizontal line, without spaces in between.
1043 Strings and simple markups are concatenated on the input level, allowing
1044 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1045 equivalent to @code{\"fi\"}.
1047 @lilypond[verbatim,quote]
1056 (define (concat-string-args arg-list)
1057 (fold-right (lambda (arg result-list)
1058 (let ((result (if (pair? result-list)
1061 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1062 (set! arg (cadr arg)))
1063 (if (and (string? result) (string? arg))
1064 (cons (string-append arg result) (cdr result-list))
1065 (cons arg result-list))))
1069 (interpret-markup layout
1070 (prepend-alist-chain 'word-space 0 props)
1071 (make-line-markup (if (markup-command-list? args)
1073 (concat-string-args args)))))
1075 (define (wordwrap-stencils stencils
1076 justify base-space line-width text-dir)
1077 "Perform simple wordwrap, return stencil of each line."
1078 (define space (if justify
1079 ;; justify only stretches lines.
1082 (define (take-list width space stencils
1083 accumulator accumulated-width)
1084 "Return (head-list . tail) pair, with head-list fitting into width"
1085 (if (null? stencils)
1086 (cons accumulator stencils)
1087 (let* ((first (car stencils))
1088 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1089 (newwid (+ space first-wid accumulated-width)))
1090 (if (or (null? accumulator)
1092 (take-list width space
1094 (cons first accumulator)
1096 (cons accumulator stencils)))))
1097 (let loop ((lines '())
1099 (let* ((line-break (take-list line-width space todo
1101 (line-stencils (car line-break))
1102 (space-left (- line-width
1103 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1105 (line-word-space (cond ((not justify) space)
1106 ;; don't stretch last line of paragraph.
1107 ;; hmmm . bug - will overstretch the last line in some case.
1108 ((null? (cdr line-break))
1110 ((null? line-stencils) 0.0)
1111 ((null? (cdr line-stencils)) 0.0)
1112 (else (/ space-left (1- (length line-stencils))))))
1113 (line (stack-stencil-line line-word-space
1114 (if (= text-dir RIGHT)
1115 (reverse line-stencils)
1117 (if (pair? (cdr line-break))
1118 (loop (cons line lines)
1121 (if (= text-dir LEFT)
1123 (ly:stencil-translate-axis
1125 (- line-width (interval-end (ly:stencil-extent line X)))
1127 (reverse (cons line lines)))))))
1129 (define-markup-list-command (wordwrap-internal layout props justify args)
1130 (boolean? markup-list?)
1131 #:properties ((line-width #f)
1133 (text-direction RIGHT))
1134 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1135 (wordwrap-stencils (remove ly:stencil-empty?
1136 (interpret-markup-list layout props args))
1140 (ly:output-def-lookup layout 'line-width))
1143 (define-markup-command (justify layout props args)
1146 #:properties ((baseline-skip)
1147 wordwrap-internal-markup-list)
1149 @cindex justifying text
1151 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1152 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1153 @var{X}@tie{}is the number of staff spaces.
1155 @lilypond[verbatim,quote]
1158 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1159 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1160 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1161 laboris nisi ut aliquip ex ea commodo consequat.
1165 (stack-lines DOWN 0.0 baseline-skip
1166 (wordwrap-internal-markup-list layout props #t args)))
1168 (define-markup-command (wordwrap layout props args)
1171 #:properties ((baseline-skip)
1172 wordwrap-internal-markup-list)
1173 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1174 the line width, where @var{X} is the number of staff spaces.
1176 @lilypond[verbatim,quote]
1179 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1180 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1181 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1182 laboris nisi ut aliquip ex ea commodo consequat.
1186 (stack-lines DOWN 0.0 baseline-skip
1187 (wordwrap-internal-markup-list layout props #f args)))
1189 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1191 #:properties ((line-width)
1193 (text-direction RIGHT))
1194 "Internal markup list command used to define @code{\\justify-string} and
1195 @code{\\wordwrap-string}."
1196 (let* ((para-strings (regexp-split
1197 (string-regexp-substitute
1199 (string-regexp-substitute "\r\n" "\n" arg))
1200 "\n[ \t\n]*\n[ \t\n]*"))
1201 (list-para-words (map (lambda (str)
1202 (regexp-split str "[ \t\n]+"))
1204 (para-lines (map (lambda (words)
1206 (remove ly:stencil-empty?
1208 (interpret-markup layout props x))
1210 (wordwrap-stencils stencils
1212 line-width text-direction)))
1214 (apply append para-lines)))
1216 (define-markup-command (wordwrap-string layout props arg)
1219 #:properties ((baseline-skip)
1220 wordwrap-string-internal-markup-list)
1221 "Wordwrap a string. Paragraphs may be separated with double newlines.
1223 @lilypond[verbatim,quote]
1225 \\override #'(line-width . 40)
1226 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1227 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1228 et dolore magna aliqua.
1231 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1232 laboris nisi ut aliquip ex ea commodo consequat.
1235 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1236 qui officia deserunt mollit anim id est laborum\"
1239 (stack-lines DOWN 0.0 baseline-skip
1240 (wordwrap-string-internal-markup-list layout props #f arg)))
1242 (define-markup-command (justify-string layout props arg)
1245 #:properties ((baseline-skip)
1246 wordwrap-string-internal-markup-list)
1247 "Justify a string. Paragraphs may be separated with double newlines
1249 @lilypond[verbatim,quote]
1251 \\override #'(line-width . 40)
1252 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1253 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1254 et dolore magna aliqua.
1257 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1258 laboris nisi ut aliquip ex ea commodo consequat.
1261 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1262 qui officia deserunt mollit anim id est laborum\"
1265 (stack-lines DOWN 0.0 baseline-skip
1266 (wordwrap-string-internal-markup-list layout props #t arg)))
1268 (define-markup-command (wordwrap-field layout props symbol)
1271 "Wordwrap the data which has been assigned to @var{symbol}.
1273 @lilypond[verbatim,quote]
1275 title = \"My title\"
1276 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1277 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1278 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1279 laboris nisi ut aliquip ex ea commodo consequat.\"
1283 bookTitleMarkup = \\markup {
1285 \\fill-line { \\fromproperty #'header:title }
1287 \\wordwrap-field #'header:myText
1296 (let* ((m (chain-assoc-get symbol props)))
1298 (wordwrap-string-markup layout props m)
1301 (define-markup-command (justify-field layout props symbol)
1304 "Justify the data which has been assigned to @var{symbol}.
1306 @lilypond[verbatim,quote]
1308 title = \"My title\"
1309 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1310 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1311 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1312 laboris nisi ut aliquip ex ea commodo consequat.\"
1316 bookTitleMarkup = \\markup {
1318 \\fill-line { \\fromproperty #'header:title }
1320 \\justify-field #'header:myText
1329 (let* ((m (chain-assoc-get symbol props)))
1331 (justify-string-markup layout props m)
1334 (define-markup-command (combine layout props arg1 arg2)
1338 @cindex merging text
1340 Print two markups on top of each other.
1342 Note: @code{\\combine} cannot take a list of markups enclosed in
1343 curly braces as an argument; the follow example will not compile:
1346 \\combine @{ a list @}
1349 @lilypond[verbatim,quote]
1352 \\override #'(thickness . 2)
1354 \\draw-line #'(0 . 4)
1355 \\arrow-head #Y #DOWN ##f
1358 (let* ((s1 (interpret-markup layout props arg1))
1359 (s2 (interpret-markup layout props arg2)))
1360 (ly:stencil-add s1 s2)))
1363 ;; TODO: should extract baseline-skip from each argument somehow..
1365 (define-markup-command (column layout props args)
1368 #:properties ((baseline-skip))
1370 @cindex stacking text in a column
1372 Stack the markups in @var{args} vertically. The property
1373 @code{baseline-skip} determines the space between markups
1376 @lilypond[verbatim,quote]
1385 (let ((arg-stencils (interpret-markup-list layout props args)))
1386 (stack-lines -1 0.0 baseline-skip
1387 (remove ly:stencil-empty? arg-stencils))))
1389 (define-markup-command (dir-column layout props args)
1392 #:properties ((direction)
1395 @cindex changing direction of text columns
1397 Make a column of @var{args}, going up or down, depending on the
1398 setting of the @code{direction} layout property.
1400 @lilypond[verbatim,quote]
1402 \\override #`(direction . ,UP) {
1412 \\override #'(direction . 1) {
1419 (stack-lines (if (number? direction) direction -1)
1422 (interpret-markup-list layout props args)))
1424 (define (general-column align-dir baseline mols)
1425 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1427 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1428 (stack-lines -1 0.0 baseline aligned-mols)))
1430 (define-markup-command (center-column layout props args)
1433 #:properties ((baseline-skip))
1435 @cindex centering a column of text
1437 Put @code{args} in a centered column.
1439 @lilypond[verbatim,quote]
1448 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1450 (define-markup-command (left-column layout props args)
1453 #:properties ((baseline-skip))
1455 @cindex text columns, left-aligned
1457 Put @code{args} in a left-aligned column.
1459 @lilypond[verbatim,quote]
1468 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1470 (define-markup-command (right-column layout props args)
1473 #:properties ((baseline-skip))
1475 @cindex text columns, right-aligned
1477 Put @code{args} in a right-aligned column.
1479 @lilypond[verbatim,quote]
1488 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1490 (define-markup-command (vcenter layout props arg)
1494 @cindex vertically centering text
1496 Align @code{arg} to its Y@tie{}center.
1498 @lilypond[verbatim,quote]
1506 (let* ((mol (interpret-markup layout props arg)))
1507 (ly:stencil-aligned-to mol Y CENTER)))
1509 (define-markup-command (center-align layout props arg)
1513 @cindex horizontally centering text
1515 Align @code{arg} to its X@tie{}center.
1517 @lilypond[verbatim,quote]
1527 (let* ((mol (interpret-markup layout props arg)))
1528 (ly:stencil-aligned-to mol X CENTER)))
1530 (define-markup-command (right-align layout props arg)
1534 @cindex right aligning text
1536 Align @var{arg} on its right edge.
1538 @lilypond[verbatim,quote]
1548 (let* ((m (interpret-markup layout props arg)))
1549 (ly:stencil-aligned-to m X RIGHT)))
1551 (define-markup-command (left-align layout props arg)
1555 @cindex left aligning text
1557 Align @var{arg} on its left edge.
1559 @lilypond[verbatim,quote]
1569 (let* ((m (interpret-markup layout props arg)))
1570 (ly:stencil-aligned-to m X LEFT)))
1572 (define-markup-command (general-align layout props axis dir arg)
1573 (integer? number? markup?)
1576 @cindex controlling general text alignment
1578 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1580 @lilypond[verbatim,quote]
1584 \\general-align #X #LEFT
1589 \\general-align #X #CENTER
1595 \\general-align #Y #UP
1602 \\general-align #Y #3.2
1609 (let* ((m (interpret-markup layout props arg)))
1610 (ly:stencil-aligned-to m axis dir)))
1612 (define-markup-command (halign layout props dir arg)
1616 @cindex setting horizontal text alignment
1618 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1619 left-aligned, while @code{+1} is right. Values in between interpolate
1620 alignment accordingly.
1622 @lilypond[verbatim,quote]
1647 (let* ((m (interpret-markup layout props arg)))
1648 (ly:stencil-aligned-to m X dir)))
1650 (define-markup-command (with-dimensions layout props x y arg)
1651 (number-pair? number-pair? markup?)
1654 @cindex setting extent of text objects
1656 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1657 (let* ((m (interpret-markup layout props arg)))
1658 (ly:make-stencil (ly:stencil-expr m) x y)))
1660 (define-markup-command (pad-around layout props amount arg)
1663 "Add padding @var{amount} all around @var{arg}.
1665 @lilypond[verbatim,quote]
1678 (let* ((m (interpret-markup layout props arg))
1679 (x (ly:stencil-extent m X))
1680 (y (ly:stencil-extent m Y)))
1681 (ly:make-stencil (ly:stencil-expr m)
1682 (interval-widen x amount)
1683 (interval-widen y amount))))
1685 (define-markup-command (pad-x layout props amount arg)
1689 @cindex padding text horizontally
1691 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1693 @lilypond[verbatim,quote]
1706 (let* ((m (interpret-markup layout props arg))
1707 (x (ly:stencil-extent m X))
1708 (y (ly:stencil-extent m Y)))
1709 (ly:make-stencil (ly:stencil-expr m)
1710 (interval-widen x amount)
1713 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1714 (integer? ly:dir? markup? markup?)
1716 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1717 (let ((m1 (interpret-markup layout props arg1))
1718 (m2 (interpret-markup layout props arg2)))
1719 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1721 (define-markup-command (transparent layout props arg)
1724 "Make @var{arg} transparent.
1726 @lilypond[verbatim,quote]
1733 (let* ((m (interpret-markup layout props arg))
1734 (x (ly:stencil-extent m X))
1735 (y (ly:stencil-extent m Y)))
1736 (ly:make-stencil "" x y)))
1738 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1739 (number-pair? number-pair? markup?)
1741 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1743 @lilypond[verbatim,quote]
1750 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1756 (let* ((m (interpret-markup layout props arg))
1757 (x (ly:stencil-extent m X))
1758 (y (ly:stencil-extent m Y)))
1759 (ly:make-stencil (ly:stencil-expr m)
1760 (interval-union x-ext x)
1761 (interval-union y-ext y))))
1763 (define-markup-command (hcenter-in layout props length arg)
1766 "Center @var{arg} horizontally within a box of extending
1767 @var{length}/2 to the left and right.
1769 @lilypond[quote,verbatim]
1772 \\set Staff.instrumentName = \\markup {
1779 \\set Staff.instrumentName = \\markup {
1788 (interpret-markup layout props
1789 (make-pad-to-box-markup
1790 (cons (/ length -2) (/ length 2))
1792 (make-center-align-markup arg))))
1794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1798 (define-markup-command (fromproperty layout props symbol)
1801 "Read the @var{symbol} from property settings, and produce a stencil
1802 from the markup contained within. If @var{symbol} is not defined, it
1803 returns an empty markup.
1805 @lilypond[verbatim,quote]
1807 myTitle = \"myTitle\"
1811 \\fromproperty #'header:myTitle
1818 (let ((m (chain-assoc-get symbol props)))
1820 (interpret-markup layout props m)
1823 (define-markup-command (on-the-fly layout props procedure arg)
1826 "Apply the @var{procedure} markup command to @var{arg}.
1827 @var{procedure} should take a single argument."
1828 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1829 (set-object-property! anonymous-with-signature
1832 (interpret-markup layout props (list anonymous-with-signature arg))))
1834 (define-markup-command (footnote layout props arg1 arg2)
1837 "Apply the footnote @var{arg2} to @var{arg1}."
1838 (ly:stencil-combine-at-edge
1839 (interpret-markup layout props arg1)
1843 `(footnote ,(interpret-markup layout props arg2))
1848 (define-markup-command (override layout props new-prop arg)
1852 @cindex overriding properties within text markup
1854 Add the argument @var{new-prop} to the property list. Properties
1855 may be any property supported by @rinternals{font-interface},
1856 @rinternals{text-interface} and
1857 @rinternals{instrument-specific-markup-interface}.
1859 @lilypond[verbatim,quote]
1867 \\override #'(baseline-skip . 4) {
1876 (interpret-markup layout (cons (list new-prop) props) arg))
1878 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1880 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1882 (define-markup-command (verbatim-file layout props name)
1885 "Read the contents of file @var{name}, and include it verbatim.
1887 @lilypond[verbatim,quote]
1889 \\verbatim-file #\"simple.ly\"
1892 (interpret-markup layout props
1893 (if (ly:get-option 'safe)
1894 "verbatim-file disabled in safe mode"
1895 (let* ((str (ly:gulp-file name))
1896 (lines (string-split str #\nl)))
1897 (make-typewriter-markup
1898 (make-column-markup lines))))))
1900 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1902 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1905 (define-markup-command (smaller layout props arg)
1908 "Decrease the font size relative to the current setting.
1910 @lilypond[verbatim,quote]
1923 (interpret-markup layout props
1924 `(,fontsize-markup -1 ,arg)))
1926 (define-markup-command (larger layout props arg)
1929 "Increase the font size relative to the current setting.
1931 @lilypond[verbatim,quote]
1939 (interpret-markup layout props
1940 `(,fontsize-markup 1 ,arg)))
1942 (define-markup-command (finger layout props arg)
1945 "Set @var{arg} as small numbers.
1947 @lilypond[verbatim,quote]
1954 (interpret-markup layout
1955 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1958 (define-markup-command (abs-fontsize layout props size arg)
1961 "Use @var{size} as the absolute font size to display @var{arg}.
1962 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1964 @lilypond[verbatim,quote]
1966 default text font size
1968 \\abs-fontsize #16 { text font size 16 }
1970 \\abs-fontsize #12 { text font size 12 }
1973 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1974 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1975 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1976 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1977 (magnification (/ size ref-size)))
1978 (interpret-markup layout
1979 (cons `((baseline-skip . ,(* magnification ref-baseline))
1980 (word-space . ,(* magnification ref-word-space))
1981 (font-size . ,(magnification->font-size magnification)))
1985 (define-markup-command (fontsize layout props increment arg)
1988 #:properties ((font-size 0)
1991 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1994 @lilypond[verbatim,quote]
2002 (let ((entries (list
2003 (cons 'baseline-skip (* baseline-skip (magstep increment)))
2004 (cons 'word-space (* word-space (magstep increment)))
2005 (cons 'font-size (+ font-size increment)))))
2006 (interpret-markup layout (cons entries props) arg)))
2008 (define-markup-command (magnify layout props sz arg)
2012 @cindex magnifying text
2014 Set the font magnification for its argument. In the following
2015 example, the middle@tie{}A is 10% larger:
2018 A \\magnify #1.1 @{ A @} A
2021 Note: Magnification only works if a font name is explicitly selected.
2022 Use @code{\\fontsize} otherwise.
2024 @lilypond[verbatim,quote]
2035 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2038 (define-markup-command (bold layout props arg)
2041 "Switch to bold font-series.
2043 @lilypond[verbatim,quote]
2051 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2053 (define-markup-command (sans layout props arg)
2056 "Switch to the sans serif font family.
2058 @lilypond[verbatim,quote]
2067 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2069 (define-markup-command (number layout props arg)
2072 "Set font family to @code{number}, which yields the font used for
2073 time signatures and fingerings. This font contains numbers and
2074 some punctuation; it has no letters.
2076 @lilypond[verbatim,quote]
2079 0 1 2 3 4 5 6 7 8 9 . ,
2083 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2085 (define-markup-command (roman layout props arg)
2088 "Set font family to @code{roman}.
2090 @lilypond[verbatim,quote]
2096 text in roman font family
2103 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2105 (define-markup-command (huge layout props arg)
2108 "Set font size to +2.
2110 @lilypond[verbatim,quote]
2118 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2120 (define-markup-command (large layout props arg)
2123 "Set font size to +1.
2125 @lilypond[verbatim,quote]
2133 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2135 (define-markup-command (normalsize layout props arg)
2138 "Set font size to default.
2140 @lilypond[verbatim,quote]
2153 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2155 (define-markup-command (small layout props arg)
2158 "Set font size to -1.
2160 @lilypond[verbatim,quote]
2168 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2170 (define-markup-command (tiny layout props arg)
2173 "Set font size to -2.
2175 @lilypond[verbatim,quote]
2183 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2185 (define-markup-command (teeny layout props arg)
2188 "Set font size to -3.
2190 @lilypond[verbatim,quote]
2198 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2200 (define-markup-command (fontCaps layout props arg)
2203 "Set @code{font-shape} to @code{caps}
2205 Note: @code{\\fontCaps} requires the installation and selection of
2206 fonts which support the @code{caps} font shape."
2207 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2210 (define-markup-command (smallCaps layout props arg)
2213 "Emit @var{arg} as small caps.
2215 Note: @code{\\smallCaps} does not support accented characters.
2217 @lilypond[verbatim,quote]
2226 (define (char-list->markup chars lower)
2227 (let ((final-string (string-upcase (reverse-list->string chars))))
2229 (markup #:fontsize -2 final-string)
2231 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2232 (if (null? rest-chars)
2234 (reverse! (cons (char-list->markup currents current-is-lower)
2236 (let* ((ch (car rest-chars))
2237 (is-lower (char-lower-case? ch)))
2238 (if (or (and current-is-lower is-lower)
2239 (and (not current-is-lower) (not is-lower)))
2240 (make-small-caps (cdr rest-chars)
2244 (make-small-caps (cdr rest-chars)
2247 (if (null? currents)
2249 (cons (char-list->markup
2250 currents current-is-lower)
2252 (interpret-markup layout props
2254 (make-small-caps (string->list arg) (list) #f (list))
2257 (define-markup-command (caps layout props arg)
2260 "Copy of the @code{\\smallCaps} command.
2262 @lilypond[verbatim,quote]
2271 (interpret-markup layout props (make-smallCaps-markup arg)))
2273 (define-markup-command (dynamic layout props arg)
2276 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2277 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2278 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2279 done in a different font. The recommended font for this is bold and italic.
2280 @lilypond[verbatim,quote]
2288 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2290 (define-markup-command (text layout props arg)
2293 "Use a text font instead of music symbol or music alphabet font.
2295 @lilypond[verbatim,quote]
2308 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2311 (define-markup-command (italic layout props arg)
2314 "Use italic @code{font-shape} for @var{arg}.
2316 @lilypond[verbatim,quote]
2324 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2326 (define-markup-command (typewriter layout props arg)
2329 "Use @code{font-family} typewriter for @var{arg}.
2331 @lilypond[verbatim,quote]
2340 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2342 (define-markup-command (upright layout props arg)
2345 "Set @code{font-shape} to @code{upright}. This is the opposite
2348 @lilypond[verbatim,quote]
2362 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2364 (define-markup-command (medium layout props arg)
2367 "Switch to medium font-series (in contrast to bold).
2369 @lilypond[verbatim,quote]
2382 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2385 (define-markup-command (normal-text layout props arg)
2388 "Set all font related properties (except the size) to get the default
2389 normal text font, no matter what font was used earlier.
2391 @lilypond[verbatim,quote]
2393 \\huge \\bold \\sans \\caps {
2394 Some text with font overrides
2397 Default text, same font-size
2405 (interpret-markup layout
2406 (cons '((font-family . roman) (font-shape . upright)
2407 (font-series . medium) (font-encoding . latin1))
2411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2415 (define-markup-command (musicglyph layout props glyph-name)
2418 "@var{glyph-name} is converted to a musical symbol; for example,
2419 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2420 the music font. See @ruser{The Feta font} for a complete listing of
2421 the possible glyphs.
2423 @lilypond[verbatim,quote]
2426 \\musicglyph #\"rests.2\"
2427 \\musicglyph #\"clefs.G_change\"
2430 (let* ((font (ly:paper-get-font layout
2431 (cons '((font-encoding . fetaMusic)
2435 (glyph (ly:font-get-glyph font glyph-name)))
2436 (if (null? (ly:stencil-expr glyph))
2437 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2441 (define-markup-command (doublesharp layout props)
2444 "Draw a double sharp symbol.
2446 @lilypond[verbatim,quote]
2451 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2453 (define-markup-command (sesquisharp layout props)
2456 "Draw a 3/2 sharp symbol.
2458 @lilypond[verbatim,quote]
2463 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2465 (define-markup-command (sharp layout props)
2468 "Draw a sharp symbol.
2470 @lilypond[verbatim,quote]
2475 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2477 (define-markup-command (semisharp layout props)
2480 "Draw a semisharp symbol.
2482 @lilypond[verbatim,quote]
2487 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2489 (define-markup-command (natural layout props)
2492 "Draw a natural symbol.
2494 @lilypond[verbatim,quote]
2499 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2501 (define-markup-command (semiflat layout props)
2504 "Draw a semiflat symbol.
2506 @lilypond[verbatim,quote]
2511 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2513 (define-markup-command (flat layout props)
2516 "Draw a flat symbol.
2518 @lilypond[verbatim,quote]
2523 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2525 (define-markup-command (sesquiflat layout props)
2528 "Draw a 3/2 flat symbol.
2530 @lilypond[verbatim,quote]
2535 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2537 (define-markup-command (doubleflat layout props)
2540 "Draw a double flat symbol.
2542 @lilypond[verbatim,quote]
2547 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2549 (define-markup-command (with-color layout props color arg)
2553 @cindex coloring text
2555 Draw @var{arg} in color specified by @var{color}.
2557 @lilypond[verbatim,quote]
2569 (let ((stil (interpret-markup layout props arg)))
2570 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2571 (ly:stencil-extent stil X)
2572 (ly:stencil-extent stil Y))))
2574 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2576 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2578 (define-markup-command (arrow-head layout props axis dir filled)
2579 (integer? ly:dir? boolean?)
2581 "Produce an arrow head in specified direction and axis.
2582 Use the filled head if @var{filled} is specified.
2583 @lilypond[verbatim,quote]
2586 \\general-align #Y #DOWN {
2587 \\arrow-head #Y #UP ##t
2588 \\arrow-head #Y #DOWN ##f
2590 \\arrow-head #X #RIGHT ##f
2591 \\arrow-head #X #LEFT ##f
2597 ((name (format "arrowheads.~a.~a~a"
2604 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2608 (define-markup-command (lookup layout props glyph-name)
2611 "Lookup a glyph by name.
2613 @lilypond[verbatim,quote]
2615 \\override #'(font-encoding . fetaBraces) {
2616 \\lookup #\"brace200\"
2619 \\lookup #\"brace180\"
2623 (ly:font-get-glyph (ly:paper-get-font layout props)
2626 (define-markup-command (char layout props num)
2629 "Produce a single character. Characters encoded in hexadecimal
2630 format require the prefix @code{#x}.
2632 @lilypond[verbatim,quote]
2634 \\char #65 \\char ##x00a9
2637 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2639 (define number->mark-letter-vector (make-vector 25 #\A))
2644 (if (= i (- (char->integer #\I) (char->integer #\A)))
2646 (vector-set! number->mark-letter-vector j
2647 (integer->char (+ i (char->integer #\A)))))
2649 (define number->mark-alphabet-vector (list->vector
2650 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2652 (define (number->markletter-string vec n)
2653 "Double letters for big marks."
2654 (let* ((lst (vector-length vec)))
2657 (string-append (number->markletter-string vec (1- (quotient n lst)))
2658 (number->markletter-string vec (remainder n lst)))
2659 (make-string 1 (vector-ref vec n)))))
2661 (define-markup-command (markletter layout props num)
2664 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2665 (skipping letter@tie{}I), and continue with double letters.
2667 @lilypond[verbatim,quote]
2674 (ly:text-interface::interpret-markup layout props
2675 (number->markletter-string number->mark-letter-vector num)))
2677 (define-markup-command (markalphabet layout props num)
2680 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2681 and continue with double letters.
2683 @lilypond[verbatim,quote]
2690 (ly:text-interface::interpret-markup layout props
2691 (number->markletter-string number->mark-alphabet-vector num)))
2693 (define-public (horizontal-slash-interval num forward number-interval mag)
2695 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2696 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2697 (else (interval-widen number-interval (* mag 0.25))))
2698 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2699 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2700 (else (interval-widen number-interval (* mag 0.25))))
2703 (define-public (adjust-slash-stencil num forward stencil mag)
2706 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2708 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2710 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2712 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2715 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2717 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2722 (define (slashed-digit-internal layout props num forward font-size thickness)
2723 (let* ((mag (magstep font-size))
2725 (ly:output-def-lookup layout 'line-thickness)
2727 ; backward slashes might use slope and point in the other direction!
2728 (dy (* mag (if forward 0.4 -0.4)))
2729 (number-stencil (interpret-markup layout
2730 (prepend-alist-chain 'font-encoding 'fetaText props)
2731 (number->string num)))
2732 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2733 (center (interval-center (ly:stencil-extent number-stencil Y)))
2734 ; Use the real extents of the slash, not the whole number, because we
2735 ; might translate the slash later on!
2736 (num-y (interval-widen (cons center center) (abs dy)))
2737 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2738 (slash-stencil (if is-sane
2739 (make-line-stencil thickness
2740 (car num-x) (- (interval-center num-y) dy)
2741 (cdr num-x) (+ (interval-center num-y) dy))
2743 (if (ly:stencil? slash-stencil)
2745 ; for some numbers we need to shift the slash/backslash up or down to make
2746 ; the slashed digit look better
2747 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2748 (set! number-stencil
2749 (ly:stencil-add number-stencil slash-stencil)))
2750 (ly:warning "Unable to create slashed digit ~a" num))
2754 (define-markup-command (slashed-digit layout props num)
2757 #:properties ((font-size 0)
2760 @cindex slashed digits
2762 A feta number, with slash. This is for use in the context of
2763 figured bass notation.
2764 @lilypond[verbatim,quote]
2768 \\override #'(thickness . 3)
2772 (slashed-digit-internal layout props num #t font-size thickness))
2774 (define-markup-command (backslashed-digit layout props num)
2777 #:properties ((font-size 0)
2780 @cindex backslashed digits
2782 A feta number, with backslash. This is for use in the context of
2783 figured bass notation.
2784 @lilypond[verbatim,quote]
2786 \\backslashed-digit #5
2788 \\override #'(thickness . 3)
2789 \\backslashed-digit #7
2792 (slashed-digit-internal layout props num #f font-size thickness))
2795 (define eyeglassespath
2796 '((moveto 0.42 0.77)
2797 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2798 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2799 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2800 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2803 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2804 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2805 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2806 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2808 (moveto 1.025 0.935)
2809 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2810 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2813 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2816 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2818 (define-markup-command (eyeglasses layout props)
2821 "Prints out eyeglasses, indicating strongly to look at the conductor.
2822 @lilypond[verbatim,quote]
2823 \\markup { \\eyeglasses }
2825 (interpret-markup layout props
2826 (make-override-markup '(line-cap-style . butt)
2827 (make-path-markup 0.15 eyeglassespath))))
2829 (define-markup-command (left-brace layout props size)
2833 A feta brace in point size @var{size}.
2835 @lilypond[verbatim,quote]
2842 (let* ((font (ly:paper-get-font layout
2843 (cons '((font-encoding . fetaBraces)
2846 (glyph-count (1- (ly:otf-glyph-count font)))
2847 (scale (ly:output-def-lookup layout 'output-scale))
2848 (scaled-size (/ (ly:pt size) scale))
2850 (ly:font-get-glyph font (string-append "brace"
2851 (number->string n)))))
2852 (get-y-from-brace (lambda (brace)
2854 (ly:stencil-extent (glyph brace) Y))))
2855 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2856 (glyph-found (glyph find-brace)))
2858 (if (or (null? (ly:stencil-expr glyph-found))
2859 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2860 (> scaled-size (interval-length
2861 (ly:stencil-extent (glyph glyph-count) Y))))
2863 (ly:warning (_ "no brace found for point size ~S ") size)
2864 (ly:warning (_ "defaulting to ~S pt")
2865 (/ (* scale (interval-length
2866 (ly:stencil-extent glyph-found Y)))
2870 (define-markup-command (right-brace layout props size)
2874 A feta brace in point size @var{size}, rotated 180 degrees.
2876 @lilypond[verbatim,quote]
2883 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2886 ;; the note command.
2887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2889 ;; TODO: better syntax.
2891 (define-markup-command (note-by-number layout props log dot-count dir)
2892 (number? number? number?)
2894 #:properties ((font-size 0)
2897 @cindex notes within text by log and dot-count
2899 Construct a note symbol, with stem. By using fractional values for
2900 @var{dir}, longer or shorter stems can be obtained.
2902 @lilypond[verbatim,quote]
2904 \\note-by-number #3 #0 #DOWN
2906 \\note-by-number #1 #2 #0.8
2909 (define (get-glyph-name-candidates dir log style)
2910 (map (lambda (dir-name)
2911 (format "noteheads.~a~a" dir-name
2912 (if (and (symbol? style)
2913 (not (equal? 'default style)))
2914 (select-head-glyph style (min log 2))
2916 (list (if (= dir UP) "u" "d")
2919 (define (get-glyph-name font cands)
2922 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2923 (get-glyph-name font (cdr cands))
2926 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2928 (size-factor (magstep font-size))
2929 (stem-length (* size-factor (max 3 (- log 1))))
2931 (let ((result (get-glyph-name font (get-glyph-name-candidates
2932 (sign dir) log style))))
2933 (if (string-null? result)
2934 ;; If no glyph name can be found, select default heads. Though
2935 ;; this usually means an unsupported style has been chosen, it
2936 ;; also prevents unrelated 'style settings from other grobs
2937 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2938 (get-glyph-name font (get-glyph-name-candidates
2939 (sign dir) log 'default))
2941 (head-glyph (ly:font-get-glyph font head-glyph-name))
2942 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2943 (stem-thickness (* size-factor 0.13))
2944 (stemy (* dir stem-length))
2945 (attach-off (cons (interval-index
2946 (ly:stencil-extent head-glyph X)
2947 (* (sign dir) (car attach-indices)))
2948 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2950 (ly:stencil-extent head-glyph Y)
2951 (cdr attach-indices)))))
2952 (stem-glyph (and (> log 0)
2953 (ly:round-filled-box
2954 (ordered-cons (car attach-off)
2956 (* (- (sign dir)) stem-thickness)))
2957 (cons (min stemy (cdr attach-off))
2958 (max stemy (cdr attach-off)))
2959 (/ stem-thickness 3))))
2961 (dot (ly:font-get-glyph font "dots.dot"))
2962 (dotwid (interval-length (ly:stencil-extent dot X)))
2963 (dots (and (> dot-count 0)
2964 (apply ly:stencil-add
2966 (ly:stencil-translate-axis
2967 dot (* 2 x dotwid) X))
2968 (iota dot-count)))))
2969 (flaggl (and (> log 2)
2970 (ly:stencil-translate
2971 (ly:font-get-glyph font
2972 (string-append "flags."
2973 (if (> dir 0) "u" "d")
2974 (number->string log)))
2975 (cons (+ (car attach-off) (if (< dir 0)
2979 ;; If there is a flag on an upstem and the stem is short, move the dots
2980 ;; to avoid the flag. 16th notes get a special case because their flags
2981 ;; hang lower than any other flags.
2982 (if (and dots (> dir 0) (> log 2)
2983 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2984 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2986 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2987 (if (ly:stencil? stem-glyph)
2988 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2989 (set! stem-glyph head-glyph))
2990 (if (ly:stencil? dots)
2993 (ly:stencil-translate-axis
2995 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3001 (let ((divisor (log 2)))
3002 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3004 (define (parse-simple-duration duration-string)
3005 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3006 and return a (log dots) list."
3007 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3009 (if (and match (string=? duration-string (match:substring match 0)))
3010 (let ((len (match:substring match 1))
3011 (dots (match:substring match 2)))
3012 (list (cond ((string=? len "breve") -1)
3013 ((string=? len "longa") -2)
3014 ((string=? len "maxima") -3)
3015 (else (log2 (string->number len))))
3016 (if dots (string-length dots) 0)))
3017 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3019 (define-markup-command (note layout props duration dir)
3022 #:properties (note-by-number-markup)
3024 @cindex notes within text by string
3026 This produces a note with a stem pointing in @var{dir} direction, with
3027 the @var{duration} for the note head type and augmentation dots. For
3028 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3029 a shortened down stem.
3031 @lilypond[verbatim,quote]
3033 \\override #'(style . cross) {
3037 \\note #\"breve\" #0
3040 (let ((parsed (parse-simple-duration duration)))
3041 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3043 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3045 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3047 (define-markup-command (lower layout props amount arg)
3051 @cindex lowering text
3053 Lower @var{arg} by the distance @var{amount}.
3054 A negative @var{amount} indicates raising; see also @code{\\raise}.
3056 @lilypond[verbatim,quote]
3064 (ly:stencil-translate-axis (interpret-markup layout props arg)
3067 (define-markup-command (translate-scaled layout props offset arg)
3068 (number-pair? markup?)
3070 #:properties ((font-size 0))
3072 @cindex translating text
3073 @cindex scaling text
3075 Translate @var{arg} by @var{offset}, scaling the offset by the
3078 @lilypond[verbatim,quote]
3081 * \\translate #'(2 . 3) translate
3083 * \\translate-scaled #'(2 . 3) translate-scaled
3087 (let* ((factor (magstep font-size))
3088 (scaled (cons (* factor (car offset))
3089 (* factor (cdr offset)))))
3090 (ly:stencil-translate (interpret-markup layout props arg)
3093 (define-markup-command (raise layout props amount arg)
3097 @cindex raising text
3099 Raise @var{arg} by the distance @var{amount}.
3100 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3102 The argument to @code{\\raise} is the vertical displacement amount,
3103 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3104 raise objects in relation to their surrounding markups.
3106 If the text object itself is positioned above or below the staff, then
3107 @code{\\raise} cannot be used to move it, since the mechanism that
3108 positions it next to the staff cancels any shift made with
3109 @code{\\raise}. For vertical positioning, use the @code{padding}
3110 and/or @code{extra-offset} properties.
3112 @lilypond[verbatim,quote]
3121 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3123 (define-markup-command (fraction layout props arg1 arg2)
3126 #:properties ((font-size 0))
3128 @cindex creating text fractions
3130 Make a fraction of two markups.
3131 @lilypond[verbatim,quote]
3137 (let* ((m1 (interpret-markup layout props arg1))
3138 (m2 (interpret-markup layout props arg2))
3139 (factor (magstep font-size))
3140 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3141 (padding (* factor 0.2))
3142 (baseline (* factor 0.6))
3143 (offset (* factor 0.75)))
3144 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3145 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3146 (let* ((x1 (ly:stencil-extent m1 X))
3147 (x2 (ly:stencil-extent m2 X))
3148 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3149 ;; should stack mols separately, to maintain LINE on baseline
3150 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3152 (ly:stencil-aligned-to stack Y CENTER))
3154 (ly:stencil-aligned-to stack X LEFT))
3155 ;; should have EX dimension
3157 (ly:stencil-translate-axis stack offset Y))))
3159 (define-markup-command (normal-size-super layout props arg)
3162 #:properties ((baseline-skip))
3164 @cindex setting superscript in standard font size
3166 Set @var{arg} in superscript with a normal font size.
3168 @lilypond[verbatim,quote]
3171 \\normal-size-super {
3172 superscript in standard size
3176 (ly:stencil-translate-axis
3177 (interpret-markup layout props arg)
3178 (* 0.5 baseline-skip) Y))
3180 (define-markup-command (super layout props arg)
3183 #:properties ((font-size 0)
3186 @cindex superscript text
3188 Set @var{arg} in superscript.
3190 @lilypond[verbatim,quote]
3200 (ly:stencil-translate-axis
3203 (cons `((font-size . ,(- font-size 3))) props)
3205 (* 0.5 baseline-skip)
3208 (define-markup-command (translate layout props offset arg)
3209 (number-pair? markup?)
3212 @cindex translating text
3214 Translate @var{arg} relative to its surroundings. @var{offset}
3215 is a pair of numbers representing the displacement in the X and Y axis.
3217 @lilypond[verbatim,quote]
3220 \\translate #'(2 . 3)
3221 \\line { translated two spaces right, three up }
3224 (ly:stencil-translate (interpret-markup layout props arg)
3227 (define-markup-command (sub layout props arg)
3230 #:properties ((font-size 0)
3233 @cindex subscript text
3235 Set @var{arg} in subscript.
3237 @lilypond[verbatim,quote]
3248 (ly:stencil-translate-axis
3251 (cons `((font-size . ,(- font-size 3))) props)
3253 (* -0.5 baseline-skip)
3256 (define-markup-command (normal-size-sub layout props arg)
3259 #:properties ((baseline-skip))
3261 @cindex setting subscript in standard font size
3263 Set @var{arg} in subscript with a normal font size.
3265 @lilypond[verbatim,quote]
3269 subscript in standard size
3273 (ly:stencil-translate-axis
3274 (interpret-markup layout props arg)
3275 (* -0.5 baseline-skip)
3278 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3280 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3282 (define-markup-command (hbracket layout props arg)
3286 @cindex placing horizontal brackets around text
3288 Draw horizontal brackets around @var{arg}.
3290 @lilypond[verbatim,quote]
3299 (let ((th 0.1) ;; todo: take from GROB.
3300 (m (interpret-markup layout props arg)))
3301 (bracketify-stencil m X th (* 2.5 th) th)))
3303 (define-markup-command (bracket layout props arg)
3307 @cindex placing vertical brackets around text
3309 Draw vertical brackets around @var{arg}.
3311 @lilypond[verbatim,quote]
3318 (let ((th 0.1) ;; todo: take from GROB.
3319 (m (interpret-markup layout props arg)))
3320 (bracketify-stencil m Y th (* 2.5 th) th)))
3322 (define-markup-command (parenthesize layout props arg)
3325 #:properties ((angularity 0)
3331 @cindex placing parentheses around text
3333 Draw parentheses around @var{arg}. This is useful for parenthesizing
3334 a column containing several lines of text.
3336 @lilypond[verbatim,quote]
3345 \\override #'(angularity . 2) {
3356 (let* ((markup (interpret-markup layout props arg))
3357 (scaled-width (* size width))
3359 (* (chain-assoc-get 'line-thickness props 0.1)
3362 (min (* size 0.5 scaled-thickness)
3363 (* (/ 4 3.0) scaled-width)))
3364 (padding (chain-assoc-get 'padding props half-thickness)))
3365 (parenthesize-stencil
3366 markup half-thickness scaled-width angularity padding)))
3369 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3370 ;; Delayed markup evaluation
3371 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3373 (define-markup-command (page-ref layout props label gauge default)
3374 (symbol? markup? markup?)
3377 @cindex referencing page numbers in text
3379 Reference to a page number. @var{label} is the label set on the referenced
3380 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3381 the maximum width of the page number, and @var{default} the value to display
3382 when @var{label} is not found."
3383 (let* ((gauge-stencil (interpret-markup layout props gauge))
3384 (x-ext (ly:stencil-extent gauge-stencil X))
3385 (y-ext (ly:stencil-extent gauge-stencil Y)))
3387 `(delay-stencil-evaluation
3388 ,(delay (ly:stencil-expr
3389 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3390 (page-number (if (list? table)
3391 (assoc-get label table)
3393 (page-markup (if page-number (format "~a" page-number) default))
3394 (page-stencil (interpret-markup layout props page-markup))
3395 (gap (- (interval-length x-ext)
3396 (interval-length (ly:stencil-extent page-stencil X)))))
3397 (interpret-markup layout props
3398 (markup #:concat (#:hspace gap page-markup)))))))
3402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3406 (define-markup-command (scale layout props factor-pair arg)
3407 (number-pair? markup?)
3410 @cindex scaling markup
3411 @cindex mirroring markup
3413 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3414 representing the scaling-factor in the X and Y axes.
3415 Negative values may be used to produce mirror images.
3417 @lilypond[verbatim,quote]
3427 (let ((stil (interpret-markup layout props arg))
3428 (sx (car factor-pair))
3429 (sy (cdr factor-pair)))
3430 (ly:stencil-scale stil sx sy)))
3432 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3433 ;; Markup list commands
3434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3436 (define-public (space-lines baseline stils)
3437 (let space-stil ((stils stils)
3441 (let* ((stil (car stils))
3442 (dy-top (max (- (/ baseline 1.5)
3443 (interval-bound (ly:stencil-extent stil Y) UP))
3445 (dy-bottom (max (+ (/ baseline 3.0)
3446 (interval-bound (ly:stencil-extent stil Y) DOWN))
3448 (new-stil (ly:make-stencil
3449 (ly:stencil-expr stil)
3450 (ly:stencil-extent stil X)
3451 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3453 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3455 (space-stil (cdr stils) (cons new-stil result))))))
3457 (define-markup-list-command (justified-lines layout props args)
3459 #:properties ((baseline-skip)
3460 wordwrap-internal-markup-list)
3462 @cindex justifying lines of text
3464 Like @code{\\justify}, but return a list of lines instead of a single markup.
3465 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3466 @var{X}@tie{}is the number of staff spaces."
3467 (space-lines baseline-skip
3468 (interpret-markup-list layout props
3469 (make-wordwrap-internal-markup-list #t args))))
3471 (define-markup-list-command (wordwrap-lines layout props args)
3473 #:properties ((baseline-skip)
3474 wordwrap-internal-markup-list)
3475 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3476 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3477 where @var{X} is the number of staff spaces."
3478 (space-lines baseline-skip
3479 (interpret-markup-list layout props
3480 (make-wordwrap-internal-markup-list #f args))))
3482 (define-markup-list-command (column-lines layout props args)
3484 #:properties ((baseline-skip))
3485 "Like @code{\\column}, but return a list of lines instead of a single markup.
3486 @code{baseline-skip} determines the space between each markup in @var{args}."
3487 (space-lines baseline-skip
3488 (interpret-markup-list layout props args)))
3490 (define-markup-list-command (override-lines layout props new-prop args)
3491 (pair? markup-list?)
3492 "Like @code{\\override}, for markup lists."
3493 (interpret-markup-list layout (cons (list new-prop) props) args))