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)
148 @cindex drawing a line across a page
150 Draws a line across a page.
151 @lilypond[verbatim,quote]
156 (interpret-markup layout props (make-draw-line-markup (cons line-width 0))))
158 (define-markup-command (draw-circle layout props radius thickness filled)
159 (number? number? boolean?)
162 @cindex drawing circles within text
164 A circle of radius @var{radius} and thickness @var{thickness},
167 @lilypond[verbatim,quote]
169 \\draw-circle #2 #0.5 ##f
171 \\draw-circle #2 #0 ##t
174 (make-circle-stencil radius thickness filled))
176 (define-markup-command (triangle layout props filled)
179 #:properties ((thickness 0.1)
183 @cindex drawing triangles within text
185 A triangle, either filled or empty.
187 @lilypond[verbatim,quote]
194 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
203 (cons 0 (* .86 ex)))))
205 (define-markup-command (circle layout props arg)
208 #:properties ((thickness 1)
210 (circle-padding 0.2))
212 @cindex circling text
214 Draw a circle around @var{arg}. Use @code{thickness},
215 @code{circle-padding} and @code{font-size} properties to determine line
216 thickness and padding around the markup.
218 @lilypond[verbatim,quote]
225 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
227 (pad (* (magstep font-size) circle-padding))
228 (m (interpret-markup layout props arg)))
229 (circle-stencil m th pad)))
231 (define-markup-command (with-url layout props url arg)
235 @cindex inserting URL links into text
237 Add a link to URL @var{url} around @var{arg}. This only works in
240 @lilypond[verbatim,quote]
242 \\with-url #\"http://lilypond.org/web/\" {
243 LilyPond ... \\italic {
244 music notation for everyone
249 (let* ((stil (interpret-markup layout props arg))
250 (xextent (ly:stencil-extent stil X))
251 (yextent (ly:stencil-extent stil Y))
252 (old-expr (ly:stencil-expr stil))
253 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
255 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
257 (define-markup-command (beam layout props width slope thickness)
258 (number? number? number?)
261 @cindex drawing beams within text
263 Create a beam with the specified parameters.
264 @lilypond[verbatim,quote]
269 (let* ((y (* slope width))
270 (yext (cons (min 0 y) (max 0 y)))
271 (half (/ thickness 2)))
276 width (+ (* width slope) (/ thickness -2))
277 width (+ (* width slope) (/ thickness 2))
279 ,(ly:output-def-lookup layout 'blot-diameter)
282 (cons (+ (- half) (car yext))
283 (+ half (cdr yext))))))
285 (define-markup-command (underline layout props arg)
288 #:properties ((thickness 1) (offset 2))
290 @cindex underlining text
292 Underline @var{arg}. Looks at @code{thickness} to determine line
293 thickness, and @code{offset} to determine line y-offset.
295 @lilypond[verbatim,quote]
296 \\markup \\fill-line {
297 \\underline \"underlined\"
298 \\override #'(offset . 5)
299 \\override #'(thickness . 1)
300 \\underline \"underlined\"
301 \\override #'(offset . 1)
302 \\override #'(thickness . 5)
303 \\underline \"underlined\"
306 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
307 (underline-thick (* thickness thick))
308 (markup (interpret-markup layout props arg))
309 (x1 (car (ly:stencil-extent markup X)))
310 (x2 (cdr (ly:stencil-extent markup X)))
311 (y (* thick (- offset)))
312 (line (make-line-stencil underline-thick x1 y x2 y)))
313 (ly:stencil-add markup line)))
315 (define-markup-command (box layout props arg)
318 #:properties ((thickness 1)
322 @cindex enclosing text within a box
324 Draw a box round @var{arg}. Looks at @code{thickness},
325 @code{box-padding} and @code{font-size} properties to determine line
326 thickness and padding around the markup.
328 @lilypond[verbatim,quote]
330 \\override #'(box-padding . 0.5)
335 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
337 (pad (* (magstep font-size) box-padding))
338 (m (interpret-markup layout props arg)))
339 (box-stencil m th pad)))
341 (define-markup-command (filled-box layout props xext yext blot)
342 (number-pair? number-pair? number?)
345 @cindex drawing solid boxes within text
346 @cindex drawing boxes with rounded corners
348 Draw a box with rounded corners of dimensions @var{xext} and
349 @var{yext}. For example,
351 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
353 creates a box extending horizontally from -0.3 to 1.8 and
354 vertically from -0.3 up to 1.8, with corners formed from a
355 circle of diameter@tie{}0 (i.e., sharp corners).
357 @lilypond[verbatim,quote]
359 \\filled-box #'(0 . 4) #'(0 . 4) #0
360 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
361 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
363 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
369 (define-markup-command (rounded-box layout props arg)
372 #:properties ((thickness 1)
376 "@cindex enclosing text in a box with rounded corners
377 @cindex drawing boxes with rounded corners around text
378 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
379 @code{box-padding} and @code{font-size} properties to determine line
380 thickness and padding around the markup; the @code{corner-radius} property
381 makes it possible to define another shape for the corners (default is 1).
383 @lilypond[quote,verbatim,relative=2]
391 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
393 (pad (* (magstep font-size) box-padding))
394 (m (interpret-markup layout props arg)))
395 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
398 (define-markup-command (rotate layout props ang arg)
402 @cindex rotating text
404 Rotate object with @var{ang} degrees around its center.
406 @lilypond[verbatim,quote]
416 (let* ((stil (interpret-markup layout props arg)))
417 (ly:stencil-rotate stil ang 0 0)))
419 (define-markup-command (whiteout layout props arg)
423 @cindex adding a white background to text
425 Provide a white background for @var{arg}.
427 @lilypond[verbatim,quote]
430 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
434 (stencil-whiteout (interpret-markup layout props arg)))
436 (define-markup-command (pad-markup layout props amount arg)
441 @cindex putting space around text
443 Add space around a markup object.
445 @lilypond[verbatim,quote]
459 ((stil (interpret-markup layout props arg))
460 (xext (ly:stencil-extent stil X))
461 (yext (ly:stencil-extent stil Y)))
464 (ly:stencil-expr stil)
465 (interval-widen xext amount)
466 (interval-widen yext amount))))
468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
470 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
472 (define-markup-command (strut layout props)
476 @cindex creating vertical spaces in text
478 Create a box of the same height as the space in the current font."
479 (let ((m (ly:text-interface::interpret-markup layout props " ")))
480 (ly:make-stencil (ly:stencil-expr m)
482 (ly:stencil-extent m X)
485 ;; todo: fix negative space
486 (define-markup-command (hspace layout props amount)
489 #:properties ((word-space))
491 @cindex creating horizontal spaces in text
493 Create an invisible object taking up horizontal space @var{amount}.
495 @lilypond[verbatim,quote]
504 (let ((corrected-space (- amount word-space)))
505 (if (> corrected-space 0)
506 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
507 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
509 ;; todo: fix negative space
510 (define-markup-command (vspace layout props amount)
514 @cindex creating vertical spaces in text
516 Create an invisible object taking up vertical space
517 of @var{amount} multiplied by 3.
519 @lilypond[verbatim,quote]
530 (let ((amount (* amount 3.0)))
532 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
533 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
537 ;; importing graphics.
538 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
540 (define-markup-command (stencil layout props stil)
544 @cindex importing stencils into text
546 Use a stencil as markup.
548 @lilypond[verbatim,quote]
550 \\stencil #(make-circle-stencil 2 0 #t)
556 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
558 (define (get-postscript-bbox string)
559 "Extract the bbox from STRING, or return #f if not present."
561 ((match (regexp-exec bbox-regexp string)))
565 (string->number (match:substring match x)))
570 (define-markup-command (epsfile layout props axis size file-name)
571 (number? number? string?)
574 @cindex inlining an Encapsulated PostScript image
576 Inline an EPS image. The image is scaled along @var{axis} to
579 @lilypond[verbatim,quote]
581 \\general-align #Y #DOWN {
582 \\epsfile #X #20 #\"context-example.eps\"
583 \\epsfile #Y #20 #\"context-example.eps\"
587 (if (ly:get-option 'safe)
588 (interpret-markup layout props "not allowed in safe")
589 (eps-file->stencil axis size file-name)
592 (define-markup-command (postscript layout props str)
596 @cindex inserting PostScript directly into text
597 This inserts @var{str} directly into the output as a PostScript
600 @lilypond[verbatim,quote]
604 0.4 0.6 0.5 0 361 arc
606 1.0 0.6 0.5 0 361 arc
611 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
612 \\postscript #ringsps
624 gsave currentpoint translate
632 (define-markup-command (path layout props thickness commands) (number? list?)
634 #:properties ((line-cap-style 'round)
635 (line-join-style 'round)
638 @cindex paths, drawing
639 @cindex drawing paths
640 Draws a path with line thickness @var{thickness} according to the
641 directions given in @var{commands}. @var{commands} is a list of
642 lists where the @code{car} of each sublist is a drawing command and
643 the @code{cdr} comprises the associated arguments for each command.
645 Line-cap styles and line-join styles may be customized by
646 overriding the @code{line-cap-style} and @code{line-join-style}
647 properties, respectively. Available line-cap styles are
648 @code{'butt}, @code{'round}, and @code{'square}. Available
649 line-join styles are @code{'miter}, @code{'round}, and
652 The property @code{filled} specifies whether or not the path is
655 There are seven commands available to use in the list
656 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
657 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
658 @code{closepath}. Note that the commands that begin with @emph{r}
659 are the relative variants of the other three commands.
661 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
662 @code{rlineto} take 2 arguments; they are the X and Y coordinates
663 for the destination point.
665 The commands @code{curveto} and @code{rcurveto} create cubic
666 Bézier curves, and take 6 arguments; the first two are the X and Y
667 coordinates for the first control point, the second two are the X
668 and Y coordinates for the second control point, and the last two
669 are the X and Y coordinates for the destination point.
671 The @code{closepath} command takes zero arguments and closes the
672 current subpath in the active path.
674 Note that a sequence of commands @emph{must} begin with a
675 @code{moveto} or @code{rmoveto} to work with the SVG output.
677 @lilypond[verbatim,quote]
683 (curveto -5 -5 -5 5 -1 0)
687 \\path #0.25 #samplePath
690 (let* ((half-thickness (/ thickness 2))
691 (current-point '(0 . 0))
692 (set-point (lambda (lst) (set! current-point lst)))
693 (relative? (lambda (x)
694 (string-prefix? "r" (symbol->string (car x)))))
695 ;; For calculating extents, we want to modify the command
696 ;; list so that all coordinates are absolute.
697 (new-commands (map (lambda (x)
699 ;; for rmoveto, rlineto
700 ((and (relative? x) (eq? 3 (length x)))
702 (+ (car current-point)
704 (+ (cdr current-point)
710 ((and (relative? x) (eq? 7 (length x)))
711 (let* ((old-cp current-point)
718 (list (+ (car old-cp) (second x))
719 (+ (cdr old-cp) (third x))
720 (+ (car old-cp) (fourth x))
721 (+ (cdr old-cp) (fifth x))
724 ;; for moveto, lineto
726 (set-point (cons (second x)
731 (set-point (cons (sixth x)
734 ;; keep closepath for filtering;
735 ;; see `without-closepath'.
738 ;; path-min-max does not accept 0-arg lists,
739 ;; and since closepath does not affect extents, filter
740 ;; out those commands here.
741 (without-closepath (filter (lambda (x)
742 (not (equal? 'closepath (car x))))
744 (extents (path-min-max
745 ;; set the origin to the first moveto
746 (list (list-ref (car without-closepath) 0)
747 (list-ref (car without-closepath) 1))
749 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
750 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
751 (command-list (fold-right append '() commands)))
753 ;; account for line thickness
754 (set! X-extent (interval-widen X-extent half-thickness))
755 (set! Y-extent (interval-widen Y-extent half-thickness))
758 `(path ,thickness `(,@',command-list)
759 ',line-cap-style ',line-join-style ,filled)
763 (define-markup-command (score layout props score)
766 #:properties ((baseline-skip))
768 @cindex inserting music into text
770 Inline an image of music.
772 @lilypond[verbatim,quote]
776 \\new Staff \\relative c' {
779 \\mark \\markup { Allegro }
785 \\new Staff \\relative c {
799 \\override RehearsalMark #'break-align-symbols =
800 #'(time-signature key-signature)
801 \\override RehearsalMark #'self-alignment-X = #LEFT
805 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
811 (let ((output (ly:score-embedded-format score layout)))
813 (if (ly:music-output? output)
814 (stack-stencils Y DOWN baseline-skip
815 (map paper-system-stencil
817 (ly:paper-score-paper-systems output))))
819 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
822 (define-markup-command (null layout props)
826 @cindex creating empty text objects
828 An empty markup with extents of a single point.
830 @lilypond[verbatim,quote]
837 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
839 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
841 (define-markup-command (simple layout props str)
845 @cindex simple text strings
847 A simple text string; @code{\\markup @{ foo @}} is equivalent with
848 @code{\\markup @{ \\simple #\"foo\" @}}.
850 Note: for creating standard text markup or defining new markup commands,
851 the use of @code{\\simple} is unnecessary.
853 @lilypond[verbatim,quote]
857 \\simple #\"strings\"
860 (interpret-markup layout props str))
862 (define-markup-command (tied-lyric layout props str)
866 @cindex simple text strings with tie characters
868 Like simple-markup, but use tie characters for @q{~} tilde symbols.
870 @lilypond[verbatim,quote]
872 \\tied-lyric #\"Lasciate~i monti\"
875 (if (string-contains str "~")
877 ((parts (string-split str #\~))
878 (tie-str (ly:wide-char->utf-8 #x203f))
879 (joined (list-join parts tie-str))
880 (join-stencil (interpret-markup layout props tie-str))
883 (interpret-markup layout
886 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
888 (make-line-markup joined)))
889 ;(map (lambda (s) (interpret-markup layout props s)) parts))
890 (interpret-markup layout props str)))
892 (define-public empty-markup
893 (make-simple-markup ""))
895 ;; helper for justifying lines.
896 (define (get-fill-space word-count line-width word-space text-widths)
897 "Calculate the necessary paddings between each two adjacent texts.
898 The lengths of all texts are stored in @var{text-widths}.
899 The normal formula for the padding between texts a and b is:
900 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
901 The first and last padding have to be calculated specially using the
902 whole length of the first or last text.
903 All paddings are checked to be at least word-space, to ensure that
905 Return a list of paddings."
907 ((null? text-widths) '())
909 ;; special case first padding
910 ((= (length text-widths) word-count)
912 (- (- (/ line-width (1- word-count)) (car text-widths))
913 (/ (car (cdr text-widths)) 2))
914 (get-fill-space word-count line-width word-space (cdr text-widths))))
915 ;; special case last padding
916 ((= (length text-widths) 2)
917 (list (- (/ line-width (1- word-count))
918 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
920 (let ((default-padding
921 (- (/ line-width (1- word-count))
922 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
924 (if (> word-space default-padding)
927 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
929 (define-markup-command (fill-line layout props args)
932 #:properties ((text-direction RIGHT)
935 "Put @var{markups} in a horizontal line of width @var{line-width}.
936 The markups are spaced or flushed to fill the entire line.
937 If there are no arguments, return an empty stencil.
939 @lilypond[verbatim,quote]
943 Words evenly spaced across the page
947 \\line { Text markups }
949 \\italic { evenly spaced }
951 \\line { across the page }
956 (let* ((orig-stencils (interpret-markup-list layout props args))
959 (if (ly:stencil-empty? stc)
961 stc)) orig-stencils))
964 (if (ly:stencil-empty? stc)
966 (interval-length (ly:stencil-extent stc X))))
968 (text-width (apply + text-widths))
969 (word-count (length stencils))
970 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
975 (/ (- line-width text-width) 2)
976 (/ (- line-width text-width) 2)))
979 (- line-width text-width)))
981 (get-fill-space word-count line-width word-space text-widths))))
983 (line-contents (if (= word-count 1)
990 (if (null? (remove ly:stencil-empty? orig-stencils))
993 (if (= text-direction LEFT)
994 (set! line-contents (reverse line-contents)))
996 (stack-stencils-padding-list
997 X RIGHT fill-space line-contents))
999 ;; shift s.t. stencils align on the left edge, even if
1000 ;; first stencil had negative X-extent (e.g. center-column)
1001 ;; (if word-count = 1, X-extents are already normalized in
1002 ;; the definition of line-contents)
1004 (ly:stencil-translate-axis
1006 (- (car (ly:stencil-extent (car stencils) X)))
1010 (define-markup-command (line layout props args)
1013 #:properties ((word-space)
1014 (text-direction RIGHT))
1015 "Put @var{args} in a horizontal line. The property @code{word-space}
1016 determines the space between markups in @var{args}.
1018 @lilypond[verbatim,quote]
1025 (let ((stencils (interpret-markup-list layout props args)))
1026 (if (= text-direction LEFT)
1027 (set! stencils (reverse stencils)))
1030 (remove ly:stencil-empty? stencils))))
1032 (define-markup-command (concat layout props args)
1036 @cindex concatenating text
1037 @cindex ligatures in text
1039 Concatenate @var{args} in a horizontal line, without spaces in between.
1040 Strings and simple markups are concatenated on the input level, allowing
1041 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1042 equivalent to @code{\"fi\"}.
1044 @lilypond[verbatim,quote]
1053 (define (concat-string-args arg-list)
1054 (fold-right (lambda (arg result-list)
1055 (let ((result (if (pair? result-list)
1058 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1059 (set! arg (cadr arg)))
1060 (if (and (string? result) (string? arg))
1061 (cons (string-append arg result) (cdr result-list))
1062 (cons arg result-list))))
1066 (interpret-markup layout
1067 (prepend-alist-chain 'word-space 0 props)
1068 (make-line-markup (if (markup-command-list? args)
1070 (concat-string-args args)))))
1072 (define (wordwrap-stencils stencils
1073 justify base-space line-width text-dir)
1074 "Perform simple wordwrap, return stencil of each line."
1075 (define space (if justify
1076 ;; justify only stretches lines.
1079 (define (take-list width space stencils
1080 accumulator accumulated-width)
1081 "Return (head-list . tail) pair, with head-list fitting into width"
1082 (if (null? stencils)
1083 (cons accumulator stencils)
1084 (let* ((first (car stencils))
1085 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1086 (newwid (+ space first-wid accumulated-width)))
1087 (if (or (null? accumulator)
1089 (take-list width space
1091 (cons first accumulator)
1093 (cons accumulator stencils)))))
1094 (let loop ((lines '())
1096 (let* ((line-break (take-list line-width space todo
1098 (line-stencils (car line-break))
1099 (space-left (- line-width
1100 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1102 (line-word-space (cond ((not justify) space)
1103 ;; don't stretch last line of paragraph.
1104 ;; hmmm . bug - will overstretch the last line in some case.
1105 ((null? (cdr line-break))
1107 ((null? line-stencils) 0.0)
1108 ((null? (cdr line-stencils)) 0.0)
1109 (else (/ space-left (1- (length line-stencils))))))
1110 (line (stack-stencil-line line-word-space
1111 (if (= text-dir RIGHT)
1112 (reverse line-stencils)
1114 (if (pair? (cdr line-break))
1115 (loop (cons line lines)
1118 (if (= text-dir LEFT)
1120 (ly:stencil-translate-axis
1122 (- line-width (interval-end (ly:stencil-extent line X)))
1124 (reverse (cons line lines)))))))
1126 (define-markup-list-command (wordwrap-internal layout props justify args)
1127 (boolean? markup-list?)
1128 #:properties ((line-width #f)
1130 (text-direction RIGHT))
1131 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1132 (wordwrap-stencils (remove ly:stencil-empty?
1133 (interpret-markup-list layout props args))
1137 (ly:output-def-lookup layout 'line-width))
1140 (define-markup-command (justify layout props args)
1143 #:properties ((baseline-skip)
1144 wordwrap-internal-markup-list)
1146 @cindex justifying text
1148 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1149 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1150 @var{X}@tie{}is the number of staff spaces.
1152 @lilypond[verbatim,quote]
1155 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1156 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1157 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1158 laboris nisi ut aliquip ex ea commodo consequat.
1162 (stack-lines DOWN 0.0 baseline-skip
1163 (wordwrap-internal-markup-list layout props #t args)))
1165 (define-markup-command (wordwrap layout props args)
1168 #:properties ((baseline-skip)
1169 wordwrap-internal-markup-list)
1170 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1171 the line width, where @var{X} is the number of staff spaces.
1173 @lilypond[verbatim,quote]
1176 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1177 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1178 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1179 laboris nisi ut aliquip ex ea commodo consequat.
1183 (stack-lines DOWN 0.0 baseline-skip
1184 (wordwrap-internal-markup-list layout props #f args)))
1186 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1188 #:properties ((line-width)
1190 (text-direction RIGHT))
1191 "Internal markup list command used to define @code{\\justify-string} and
1192 @code{\\wordwrap-string}."
1193 (let* ((para-strings (regexp-split
1194 (string-regexp-substitute
1196 (string-regexp-substitute "\r\n" "\n" arg))
1197 "\n[ \t\n]*\n[ \t\n]*"))
1198 (list-para-words (map (lambda (str)
1199 (regexp-split str "[ \t\n]+"))
1201 (para-lines (map (lambda (words)
1203 (remove ly:stencil-empty?
1205 (interpret-markup layout props x))
1207 (wordwrap-stencils stencils
1209 line-width text-direction)))
1211 (apply append para-lines)))
1213 (define-markup-command (wordwrap-string layout props arg)
1216 #:properties ((baseline-skip)
1217 wordwrap-string-internal-markup-list)
1218 "Wordwrap a string. Paragraphs may be separated with double newlines.
1220 @lilypond[verbatim,quote]
1222 \\override #'(line-width . 40)
1223 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1224 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1225 et dolore magna aliqua.
1228 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1229 laboris nisi ut aliquip ex ea commodo consequat.
1232 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1233 qui officia deserunt mollit anim id est laborum\"
1236 (stack-lines DOWN 0.0 baseline-skip
1237 (wordwrap-string-internal-markup-list layout props #f arg)))
1239 (define-markup-command (justify-string layout props arg)
1242 #:properties ((baseline-skip)
1243 wordwrap-string-internal-markup-list)
1244 "Justify a string. Paragraphs may be separated with double newlines
1246 @lilypond[verbatim,quote]
1248 \\override #'(line-width . 40)
1249 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1250 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1251 et dolore magna aliqua.
1254 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1255 laboris nisi ut aliquip ex ea commodo consequat.
1258 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1259 qui officia deserunt mollit anim id est laborum\"
1262 (stack-lines DOWN 0.0 baseline-skip
1263 (wordwrap-string-internal-markup-list layout props #t arg)))
1265 (define-markup-command (wordwrap-field layout props symbol)
1268 "Wordwrap the data which has been assigned to @var{symbol}.
1270 @lilypond[verbatim,quote]
1272 title = \"My title\"
1273 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1274 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1275 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1276 laboris nisi ut aliquip ex ea commodo consequat.\"
1280 bookTitleMarkup = \\markup {
1282 \\fill-line { \\fromproperty #'header:title }
1284 \\wordwrap-field #'header:myText
1293 (let* ((m (chain-assoc-get symbol props)))
1295 (wordwrap-string-markup layout props m)
1298 (define-markup-command (justify-field layout props symbol)
1301 "Justify the data which has been assigned to @var{symbol}.
1303 @lilypond[verbatim,quote]
1305 title = \"My title\"
1306 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1307 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1308 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1309 laboris nisi ut aliquip ex ea commodo consequat.\"
1313 bookTitleMarkup = \\markup {
1315 \\fill-line { \\fromproperty #'header:title }
1317 \\justify-field #'header:myText
1326 (let* ((m (chain-assoc-get symbol props)))
1328 (justify-string-markup layout props m)
1331 (define-markup-command (combine layout props arg1 arg2)
1335 @cindex merging text
1337 Print two markups on top of each other.
1339 Note: @code{\\combine} cannot take a list of markups enclosed in
1340 curly braces as an argument; the follow example will not compile:
1343 \\combine @{ a list @}
1346 @lilypond[verbatim,quote]
1349 \\override #'(thickness . 2)
1351 \\draw-line #'(0 . 4)
1352 \\arrow-head #Y #DOWN ##f
1355 (let* ((s1 (interpret-markup layout props arg1))
1356 (s2 (interpret-markup layout props arg2)))
1357 (ly:stencil-add s1 s2)))
1360 ;; TODO: should extract baseline-skip from each argument somehow..
1362 (define-markup-command (column layout props args)
1365 #:properties ((baseline-skip))
1367 @cindex stacking text in a column
1369 Stack the markups in @var{args} vertically. The property
1370 @code{baseline-skip} determines the space between markups
1373 @lilypond[verbatim,quote]
1382 (let ((arg-stencils (interpret-markup-list layout props args)))
1383 (stack-lines -1 0.0 baseline-skip
1384 (remove ly:stencil-empty? arg-stencils))))
1386 (define-markup-command (dir-column layout props args)
1389 #:properties ((direction)
1392 @cindex changing direction of text columns
1394 Make a column of @var{args}, going up or down, depending on the
1395 setting of the @code{direction} layout property.
1397 @lilypond[verbatim,quote]
1399 \\override #`(direction . ,UP) {
1409 \\override #'(direction . 1) {
1416 (stack-lines (if (number? direction) direction -1)
1419 (interpret-markup-list layout props args)))
1421 (define (general-column align-dir baseline mols)
1422 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1424 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1425 (stack-lines -1 0.0 baseline aligned-mols)))
1427 (define-markup-command (center-column layout props args)
1430 #:properties ((baseline-skip))
1432 @cindex centering a column of text
1434 Put @code{args} in a centered column.
1436 @lilypond[verbatim,quote]
1445 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1447 (define-markup-command (left-column layout props args)
1450 #:properties ((baseline-skip))
1452 @cindex text columns, left-aligned
1454 Put @code{args} in a left-aligned column.
1456 @lilypond[verbatim,quote]
1465 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1467 (define-markup-command (right-column layout props args)
1470 #:properties ((baseline-skip))
1472 @cindex text columns, right-aligned
1474 Put @code{args} in a right-aligned column.
1476 @lilypond[verbatim,quote]
1485 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1487 (define-markup-command (vcenter layout props arg)
1491 @cindex vertically centering text
1493 Align @code{arg} to its Y@tie{}center.
1495 @lilypond[verbatim,quote]
1503 (let* ((mol (interpret-markup layout props arg)))
1504 (ly:stencil-aligned-to mol Y CENTER)))
1506 (define-markup-command (center-align layout props arg)
1510 @cindex horizontally centering text
1512 Align @code{arg} to its X@tie{}center.
1514 @lilypond[verbatim,quote]
1524 (let* ((mol (interpret-markup layout props arg)))
1525 (ly:stencil-aligned-to mol X CENTER)))
1527 (define-markup-command (right-align layout props arg)
1531 @cindex right aligning text
1533 Align @var{arg} on its right edge.
1535 @lilypond[verbatim,quote]
1545 (let* ((m (interpret-markup layout props arg)))
1546 (ly:stencil-aligned-to m X RIGHT)))
1548 (define-markup-command (left-align layout props arg)
1552 @cindex left aligning text
1554 Align @var{arg} on its left edge.
1556 @lilypond[verbatim,quote]
1566 (let* ((m (interpret-markup layout props arg)))
1567 (ly:stencil-aligned-to m X LEFT)))
1569 (define-markup-command (general-align layout props axis dir arg)
1570 (integer? number? markup?)
1573 @cindex controlling general text alignment
1575 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1577 @lilypond[verbatim,quote]
1581 \\general-align #X #LEFT
1586 \\general-align #X #CENTER
1592 \\general-align #Y #UP
1599 \\general-align #Y #3.2
1606 (let* ((m (interpret-markup layout props arg)))
1607 (ly:stencil-aligned-to m axis dir)))
1609 (define-markup-command (halign layout props dir arg)
1613 @cindex setting horizontal text alignment
1615 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1616 left-aligned, while @code{+1} is right. Values in between interpolate
1617 alignment accordingly.
1619 @lilypond[verbatim,quote]
1644 (let* ((m (interpret-markup layout props arg)))
1645 (ly:stencil-aligned-to m X dir)))
1647 (define-markup-command (with-dimensions layout props x y arg)
1648 (number-pair? number-pair? markup?)
1651 @cindex setting extent of text objects
1653 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1654 (let* ((m (interpret-markup layout props arg)))
1655 (ly:make-stencil (ly:stencil-expr m) x y)))
1657 (define-markup-command (pad-around layout props amount arg)
1660 "Add padding @var{amount} all around @var{arg}.
1662 @lilypond[verbatim,quote]
1675 (let* ((m (interpret-markup layout props arg))
1676 (x (ly:stencil-extent m X))
1677 (y (ly:stencil-extent m Y)))
1678 (ly:make-stencil (ly:stencil-expr m)
1679 (interval-widen x amount)
1680 (interval-widen y amount))))
1682 (define-markup-command (pad-x layout props amount arg)
1686 @cindex padding text horizontally
1688 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1690 @lilypond[verbatim,quote]
1703 (let* ((m (interpret-markup layout props arg))
1704 (x (ly:stencil-extent m X))
1705 (y (ly:stencil-extent m Y)))
1706 (ly:make-stencil (ly:stencil-expr m)
1707 (interval-widen x amount)
1710 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1711 (integer? ly:dir? markup? markup?)
1713 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1714 (let ((m1 (interpret-markup layout props arg1))
1715 (m2 (interpret-markup layout props arg2)))
1716 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1718 (define-markup-command (transparent layout props arg)
1721 "Make @var{arg} transparent.
1723 @lilypond[verbatim,quote]
1730 (let* ((m (interpret-markup layout props arg))
1731 (x (ly:stencil-extent m X))
1732 (y (ly:stencil-extent m Y)))
1733 (ly:make-stencil "" x y)))
1735 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1736 (number-pair? number-pair? markup?)
1738 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1740 @lilypond[verbatim,quote]
1747 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1753 (let* ((m (interpret-markup layout props arg))
1754 (x (ly:stencil-extent m X))
1755 (y (ly:stencil-extent m Y)))
1756 (ly:make-stencil (ly:stencil-expr m)
1757 (interval-union x-ext x)
1758 (interval-union y-ext y))))
1760 (define-markup-command (hcenter-in layout props length arg)
1763 "Center @var{arg} horizontally within a box of extending
1764 @var{length}/2 to the left and right.
1766 @lilypond[quote,verbatim]
1769 \\set Staff.instrumentName = \\markup {
1776 \\set Staff.instrumentName = \\markup {
1785 (interpret-markup layout props
1786 (make-pad-to-box-markup
1787 (cons (/ length -2) (/ length 2))
1789 (make-center-align-markup arg))))
1791 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1793 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1795 (define-markup-command (fromproperty layout props symbol)
1798 "Read the @var{symbol} from property settings, and produce a stencil
1799 from the markup contained within. If @var{symbol} is not defined, it
1800 returns an empty markup.
1802 @lilypond[verbatim,quote]
1804 myTitle = \"myTitle\"
1808 \\fromproperty #'header:myTitle
1815 (let ((m (chain-assoc-get symbol props)))
1817 (interpret-markup layout props m)
1820 (define-markup-command (on-the-fly layout props procedure arg)
1823 "Apply the @var{procedure} markup command to @var{arg}.
1824 @var{procedure} should take a single argument."
1825 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1826 (set-object-property! anonymous-with-signature
1829 (interpret-markup layout props (list anonymous-with-signature arg))))
1831 (define-markup-command (footnote layout props mkup note)
1834 "Have footnote @var{note} act as an annotation to the markup @var{mkup}."
1835 (ly:stencil-combine-at-edge
1836 (interpret-markup layout props mkup)
1840 `(footnote ,(interpret-markup layout props note))
1845 (define-markup-command (override layout props new-prop arg)
1849 @cindex overriding properties within text markup
1851 Add the argument @var{new-prop} to the property list. Properties
1852 may be any property supported by @rinternals{font-interface},
1853 @rinternals{text-interface} and
1854 @rinternals{instrument-specific-markup-interface}.
1856 @lilypond[verbatim,quote]
1864 \\override #'(baseline-skip . 4) {
1873 (interpret-markup layout (cons (list new-prop) props) arg))
1875 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1877 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1879 (define-markup-command (verbatim-file layout props name)
1882 "Read the contents of file @var{name}, and include it verbatim.
1884 @lilypond[verbatim,quote]
1886 \\verbatim-file #\"simple.ly\"
1889 (interpret-markup layout props
1890 (if (ly:get-option 'safe)
1891 "verbatim-file disabled in safe mode"
1892 (let* ((str (ly:gulp-file name))
1893 (lines (string-split str #\nl)))
1894 (make-typewriter-markup
1895 (make-column-markup lines))))))
1897 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1899 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1902 (define-markup-command (smaller layout props arg)
1905 "Decrease the font size relative to the current setting.
1907 @lilypond[verbatim,quote]
1920 (interpret-markup layout props
1921 `(,fontsize-markup -1 ,arg)))
1923 (define-markup-command (larger layout props arg)
1926 "Increase the font size relative to the current setting.
1928 @lilypond[verbatim,quote]
1936 (interpret-markup layout props
1937 `(,fontsize-markup 1 ,arg)))
1939 (define-markup-command (finger layout props arg)
1942 "Set @var{arg} as small numbers.
1944 @lilypond[verbatim,quote]
1951 (interpret-markup layout
1952 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1955 (define-markup-command (abs-fontsize layout props size arg)
1958 "Use @var{size} as the absolute font size to display @var{arg}.
1959 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1961 @lilypond[verbatim,quote]
1963 default text font size
1965 \\abs-fontsize #16 { text font size 16 }
1967 \\abs-fontsize #12 { text font size 12 }
1970 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1971 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1972 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1973 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1974 (magnification (/ size ref-size)))
1975 (interpret-markup layout
1976 (cons `((baseline-skip . ,(* magnification ref-baseline))
1977 (word-space . ,(* magnification ref-word-space))
1978 (font-size . ,(magnification->font-size magnification)))
1982 (define-markup-command (fontsize layout props increment arg)
1985 #:properties ((font-size 0)
1988 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1991 @lilypond[verbatim,quote]
1999 (let ((entries (list
2000 (cons 'baseline-skip (* baseline-skip (magstep increment)))
2001 (cons 'word-space (* word-space (magstep increment)))
2002 (cons 'font-size (+ font-size increment)))))
2003 (interpret-markup layout (cons entries props) arg)))
2005 (define-markup-command (magnify layout props sz arg)
2009 @cindex magnifying text
2011 Set the font magnification for its argument. In the following
2012 example, the middle@tie{}A is 10% larger:
2015 A \\magnify #1.1 @{ A @} A
2018 Note: Magnification only works if a font name is explicitly selected.
2019 Use @code{\\fontsize} otherwise.
2021 @lilypond[verbatim,quote]
2032 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2035 (define-markup-command (bold layout props arg)
2038 "Switch to bold font-series.
2040 @lilypond[verbatim,quote]
2048 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2050 (define-markup-command (sans layout props arg)
2053 "Switch to the sans serif font family.
2055 @lilypond[verbatim,quote]
2064 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2066 (define-markup-command (number layout props arg)
2069 "Set font family to @code{number}, which yields the font used for
2070 time signatures and fingerings. This font contains numbers and
2071 some punctuation; it has no letters.
2073 @lilypond[verbatim,quote]
2076 0 1 2 3 4 5 6 7 8 9 . ,
2080 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2082 (define-markup-command (roman layout props arg)
2085 "Set font family to @code{roman}.
2087 @lilypond[verbatim,quote]
2093 text in roman font family
2100 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2102 (define-markup-command (huge layout props arg)
2105 "Set font size to +2.
2107 @lilypond[verbatim,quote]
2115 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2117 (define-markup-command (large layout props arg)
2120 "Set font size to +1.
2122 @lilypond[verbatim,quote]
2130 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2132 (define-markup-command (normalsize layout props arg)
2135 "Set font size to default.
2137 @lilypond[verbatim,quote]
2150 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2152 (define-markup-command (small layout props arg)
2155 "Set font size to -1.
2157 @lilypond[verbatim,quote]
2165 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2167 (define-markup-command (tiny layout props arg)
2170 "Set font size to -2.
2172 @lilypond[verbatim,quote]
2180 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2182 (define-markup-command (teeny layout props arg)
2185 "Set font size to -3.
2187 @lilypond[verbatim,quote]
2195 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2197 (define-markup-command (fontCaps layout props arg)
2200 "Set @code{font-shape} to @code{caps}
2202 Note: @code{\\fontCaps} requires the installation and selection of
2203 fonts which support the @code{caps} font shape."
2204 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2207 (define-markup-command (smallCaps layout props arg)
2210 "Emit @var{arg} as small caps.
2212 Note: @code{\\smallCaps} does not support accented characters.
2214 @lilypond[verbatim,quote]
2223 (define (char-list->markup chars lower)
2224 (let ((final-string (string-upcase (reverse-list->string chars))))
2226 (markup #:fontsize -2 final-string)
2228 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2229 (if (null? rest-chars)
2231 (reverse! (cons (char-list->markup currents current-is-lower)
2233 (let* ((ch (car rest-chars))
2234 (is-lower (char-lower-case? ch)))
2235 (if (or (and current-is-lower is-lower)
2236 (and (not current-is-lower) (not is-lower)))
2237 (make-small-caps (cdr rest-chars)
2241 (make-small-caps (cdr rest-chars)
2244 (if (null? currents)
2246 (cons (char-list->markup
2247 currents current-is-lower)
2249 (interpret-markup layout props
2251 (make-small-caps (string->list arg) (list) #f (list))
2254 (define-markup-command (caps layout props arg)
2257 "Copy of the @code{\\smallCaps} command.
2259 @lilypond[verbatim,quote]
2268 (interpret-markup layout props (make-smallCaps-markup arg)))
2270 (define-markup-command (dynamic layout props arg)
2273 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2274 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2275 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2276 done in a different font. The recommended font for this is bold and italic.
2277 @lilypond[verbatim,quote]
2285 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2287 (define-markup-command (text layout props arg)
2290 "Use a text font instead of music symbol or music alphabet font.
2292 @lilypond[verbatim,quote]
2305 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2308 (define-markup-command (italic layout props arg)
2311 "Use italic @code{font-shape} for @var{arg}.
2313 @lilypond[verbatim,quote]
2321 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2323 (define-markup-command (typewriter layout props arg)
2326 "Use @code{font-family} typewriter for @var{arg}.
2328 @lilypond[verbatim,quote]
2337 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2339 (define-markup-command (upright layout props arg)
2342 "Set @code{font-shape} to @code{upright}. This is the opposite
2345 @lilypond[verbatim,quote]
2359 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2361 (define-markup-command (medium layout props arg)
2364 "Switch to medium font-series (in contrast to bold).
2366 @lilypond[verbatim,quote]
2379 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2382 (define-markup-command (normal-text layout props arg)
2385 "Set all font related properties (except the size) to get the default
2386 normal text font, no matter what font was used earlier.
2388 @lilypond[verbatim,quote]
2390 \\huge \\bold \\sans \\caps {
2391 Some text with font overrides
2394 Default text, same font-size
2402 (interpret-markup layout
2403 (cons '((font-family . roman) (font-shape . upright)
2404 (font-series . medium) (font-encoding . latin1))
2408 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2412 (define-markup-command (musicglyph layout props glyph-name)
2415 "@var{glyph-name} is converted to a musical symbol; for example,
2416 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2417 the music font. See @ruser{The Feta font} for a complete listing of
2418 the possible glyphs.
2420 @lilypond[verbatim,quote]
2423 \\musicglyph #\"rests.2\"
2424 \\musicglyph #\"clefs.G_change\"
2427 (let* ((font (ly:paper-get-font layout
2428 (cons '((font-encoding . fetaMusic)
2432 (glyph (ly:font-get-glyph font glyph-name)))
2433 (if (null? (ly:stencil-expr glyph))
2434 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2438 (define-markup-command (doublesharp layout props)
2441 "Draw a double sharp symbol.
2443 @lilypond[verbatim,quote]
2448 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2450 (define-markup-command (sesquisharp layout props)
2453 "Draw a 3/2 sharp symbol.
2455 @lilypond[verbatim,quote]
2460 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2462 (define-markup-command (sharp layout props)
2465 "Draw a sharp symbol.
2467 @lilypond[verbatim,quote]
2472 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2474 (define-markup-command (semisharp layout props)
2477 "Draw a semisharp symbol.
2479 @lilypond[verbatim,quote]
2484 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2486 (define-markup-command (natural layout props)
2489 "Draw a natural symbol.
2491 @lilypond[verbatim,quote]
2496 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2498 (define-markup-command (semiflat layout props)
2501 "Draw a semiflat symbol.
2503 @lilypond[verbatim,quote]
2508 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2510 (define-markup-command (flat layout props)
2513 "Draw a flat symbol.
2515 @lilypond[verbatim,quote]
2520 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2522 (define-markup-command (sesquiflat layout props)
2525 "Draw a 3/2 flat symbol.
2527 @lilypond[verbatim,quote]
2532 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2534 (define-markup-command (doubleflat layout props)
2537 "Draw a double flat symbol.
2539 @lilypond[verbatim,quote]
2544 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2546 (define-markup-command (with-color layout props color arg)
2550 @cindex coloring text
2552 Draw @var{arg} in color specified by @var{color}.
2554 @lilypond[verbatim,quote]
2566 (let ((stil (interpret-markup layout props arg)))
2567 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2568 (ly:stencil-extent stil X)
2569 (ly:stencil-extent stil Y))))
2571 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2573 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2575 (define-markup-command (arrow-head layout props axis dir filled)
2576 (integer? ly:dir? boolean?)
2578 "Produce an arrow head in specified direction and axis.
2579 Use the filled head if @var{filled} is specified.
2580 @lilypond[verbatim,quote]
2583 \\general-align #Y #DOWN {
2584 \\arrow-head #Y #UP ##t
2585 \\arrow-head #Y #DOWN ##f
2587 \\arrow-head #X #RIGHT ##f
2588 \\arrow-head #X #LEFT ##f
2594 ((name (format "arrowheads.~a.~a~a"
2601 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2605 (define-markup-command (lookup layout props glyph-name)
2608 "Lookup a glyph by name.
2610 @lilypond[verbatim,quote]
2612 \\override #'(font-encoding . fetaBraces) {
2613 \\lookup #\"brace200\"
2616 \\lookup #\"brace180\"
2620 (ly:font-get-glyph (ly:paper-get-font layout props)
2623 (define-markup-command (char layout props num)
2626 "Produce a single character. Characters encoded in hexadecimal
2627 format require the prefix @code{#x}.
2629 @lilypond[verbatim,quote]
2631 \\char #65 \\char ##x00a9
2634 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2636 (define number->mark-letter-vector (make-vector 25 #\A))
2641 (if (= i (- (char->integer #\I) (char->integer #\A)))
2643 (vector-set! number->mark-letter-vector j
2644 (integer->char (+ i (char->integer #\A)))))
2646 (define number->mark-alphabet-vector (list->vector
2647 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2649 (define (number->markletter-string vec n)
2650 "Double letters for big marks."
2651 (let* ((lst (vector-length vec)))
2654 (string-append (number->markletter-string vec (1- (quotient n lst)))
2655 (number->markletter-string vec (remainder n lst)))
2656 (make-string 1 (vector-ref vec n)))))
2658 (define-markup-command (markletter layout props num)
2661 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2662 (skipping letter@tie{}I), and continue with double letters.
2664 @lilypond[verbatim,quote]
2671 (ly:text-interface::interpret-markup layout props
2672 (number->markletter-string number->mark-letter-vector num)))
2674 (define-markup-command (markalphabet layout props num)
2677 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2678 and continue with double letters.
2680 @lilypond[verbatim,quote]
2687 (ly:text-interface::interpret-markup layout props
2688 (number->markletter-string number->mark-alphabet-vector num)))
2690 (define-public (horizontal-slash-interval num forward number-interval mag)
2692 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2693 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2694 (else (interval-widen number-interval (* mag 0.25))))
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))))
2700 (define-public (adjust-slash-stencil num forward stencil mag)
2703 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2705 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2707 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2709 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2712 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2714 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2719 (define (slashed-digit-internal layout props num forward font-size thickness)
2720 (let* ((mag (magstep font-size))
2722 (ly:output-def-lookup layout 'line-thickness)
2724 ; backward slashes might use slope and point in the other direction!
2725 (dy (* mag (if forward 0.4 -0.4)))
2726 (number-stencil (interpret-markup layout
2727 (prepend-alist-chain 'font-encoding 'fetaText props)
2728 (number->string num)))
2729 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2730 (center (interval-center (ly:stencil-extent number-stencil Y)))
2731 ; Use the real extents of the slash, not the whole number, because we
2732 ; might translate the slash later on!
2733 (num-y (interval-widen (cons center center) (abs dy)))
2734 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2735 (slash-stencil (if is-sane
2736 (make-line-stencil thickness
2737 (car num-x) (- (interval-center num-y) dy)
2738 (cdr num-x) (+ (interval-center num-y) dy))
2740 (if (ly:stencil? slash-stencil)
2742 ; for some numbers we need to shift the slash/backslash up or down to make
2743 ; the slashed digit look better
2744 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2745 (set! number-stencil
2746 (ly:stencil-add number-stencil slash-stencil)))
2747 (ly:warning "Unable to create slashed digit ~a" num))
2751 (define-markup-command (slashed-digit layout props num)
2754 #:properties ((font-size 0)
2757 @cindex slashed digits
2759 A feta number, with slash. This is for use in the context of
2760 figured bass notation.
2761 @lilypond[verbatim,quote]
2765 \\override #'(thickness . 3)
2769 (slashed-digit-internal layout props num #t font-size thickness))
2771 (define-markup-command (backslashed-digit layout props num)
2774 #:properties ((font-size 0)
2777 @cindex backslashed digits
2779 A feta number, with backslash. This is for use in the context of
2780 figured bass notation.
2781 @lilypond[verbatim,quote]
2783 \\backslashed-digit #5
2785 \\override #'(thickness . 3)
2786 \\backslashed-digit #7
2789 (slashed-digit-internal layout props num #f font-size thickness))
2792 (define eyeglassespath
2793 '((moveto 0.42 0.77)
2794 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2795 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2796 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2797 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2800 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2801 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2802 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2803 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2805 (moveto 1.025 0.935)
2806 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2807 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2810 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2813 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2815 (define-markup-command (eyeglasses layout props)
2818 "Prints out eyeglasses, indicating strongly to look at the conductor.
2819 @lilypond[verbatim,quote]
2820 \\markup { \\eyeglasses }
2822 (interpret-markup layout props
2823 (make-override-markup '(line-cap-style . butt)
2824 (make-path-markup 0.15 eyeglassespath))))
2826 (define-markup-command (left-brace layout props size)
2830 A feta brace in point size @var{size}.
2832 @lilypond[verbatim,quote]
2839 (let* ((font (ly:paper-get-font layout
2840 (cons '((font-encoding . fetaBraces)
2843 (glyph-count (1- (ly:otf-glyph-count font)))
2844 (scale (ly:output-def-lookup layout 'output-scale))
2845 (scaled-size (/ (ly:pt size) scale))
2847 (ly:font-get-glyph font (string-append "brace"
2848 (number->string n)))))
2849 (get-y-from-brace (lambda (brace)
2851 (ly:stencil-extent (glyph brace) Y))))
2852 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2853 (glyph-found (glyph find-brace)))
2855 (if (or (null? (ly:stencil-expr glyph-found))
2856 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2857 (> scaled-size (interval-length
2858 (ly:stencil-extent (glyph glyph-count) Y))))
2860 (ly:warning (_ "no brace found for point size ~S ") size)
2861 (ly:warning (_ "defaulting to ~S pt")
2862 (/ (* scale (interval-length
2863 (ly:stencil-extent glyph-found Y)))
2867 (define-markup-command (right-brace layout props size)
2871 A feta brace in point size @var{size}, rotated 180 degrees.
2873 @lilypond[verbatim,quote]
2880 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2882 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2883 ;; the note command.
2884 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2886 ;; TODO: better syntax.
2888 (define-markup-command (note-by-number layout props log dot-count dir)
2889 (number? number? number?)
2891 #:properties ((font-size 0)
2894 @cindex notes within text by log and dot-count
2896 Construct a note symbol, with stem. By using fractional values for
2897 @var{dir}, longer or shorter stems can be obtained.
2899 @lilypond[verbatim,quote]
2901 \\note-by-number #3 #0 #DOWN
2903 \\note-by-number #1 #2 #0.8
2906 (define (get-glyph-name-candidates dir log style)
2907 (map (lambda (dir-name)
2908 (format "noteheads.~a~a" dir-name
2909 (if (and (symbol? style)
2910 (not (equal? 'default style)))
2911 (select-head-glyph style (min log 2))
2913 (list (if (= dir UP) "u" "d")
2916 (define (get-glyph-name font cands)
2919 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2920 (get-glyph-name font (cdr cands))
2923 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2925 (size-factor (magstep font-size))
2926 (stem-length (* size-factor (max 3 (- log 1))))
2928 (let ((result (get-glyph-name font (get-glyph-name-candidates
2929 (sign dir) log style))))
2930 (if (string-null? result)
2931 ;; If no glyph name can be found, select default heads. Though
2932 ;; this usually means an unsupported style has been chosen, it
2933 ;; also prevents unrelated 'style settings from other grobs
2934 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2935 (get-glyph-name font (get-glyph-name-candidates
2936 (sign dir) log 'default))
2938 (head-glyph (ly:font-get-glyph font head-glyph-name))
2939 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2940 (stem-thickness (* size-factor 0.13))
2941 (stemy (* dir stem-length))
2942 (attach-off (cons (interval-index
2943 (ly:stencil-extent head-glyph X)
2944 (* (sign dir) (car attach-indices)))
2945 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2947 (ly:stencil-extent head-glyph Y)
2948 (cdr attach-indices)))))
2949 (stem-glyph (and (> log 0)
2950 (ly:round-filled-box
2951 (ordered-cons (car attach-off)
2953 (* (- (sign dir)) stem-thickness)))
2954 (cons (min stemy (cdr attach-off))
2955 (max stemy (cdr attach-off)))
2956 (/ stem-thickness 3))))
2958 (dot (ly:font-get-glyph font "dots.dot"))
2959 (dotwid (interval-length (ly:stencil-extent dot X)))
2960 (dots (and (> dot-count 0)
2961 (apply ly:stencil-add
2963 (ly:stencil-translate-axis
2964 dot (* 2 x dotwid) X))
2965 (iota dot-count)))))
2966 (flaggl (and (> log 2)
2967 (ly:stencil-translate
2968 (ly:font-get-glyph font
2969 (string-append "flags."
2970 (if (> dir 0) "u" "d")
2971 (number->string log)))
2972 (cons (+ (car attach-off) (if (< dir 0)
2976 ;; If there is a flag on an upstem and the stem is short, move the dots
2977 ;; to avoid the flag. 16th notes get a special case because their flags
2978 ;; hang lower than any other flags.
2979 (if (and dots (> dir 0) (> log 2)
2980 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2981 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2983 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2984 (if (ly:stencil? stem-glyph)
2985 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2986 (set! stem-glyph head-glyph))
2987 (if (ly:stencil? dots)
2990 (ly:stencil-translate-axis
2992 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2998 (let ((divisor (log 2)))
2999 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3001 (define (parse-simple-duration duration-string)
3002 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3003 and return a (log dots) list."
3004 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3006 (if (and match (string=? duration-string (match:substring match 0)))
3007 (let ((len (match:substring match 1))
3008 (dots (match:substring match 2)))
3009 (list (cond ((string=? len "breve") -1)
3010 ((string=? len "longa") -2)
3011 ((string=? len "maxima") -3)
3012 (else (log2 (string->number len))))
3013 (if dots (string-length dots) 0)))
3014 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3016 (define-markup-command (note layout props duration dir)
3019 #:properties (note-by-number-markup)
3021 @cindex notes within text by string
3023 This produces a note with a stem pointing in @var{dir} direction, with
3024 the @var{duration} for the note head type and augmentation dots. For
3025 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3026 a shortened down stem.
3028 @lilypond[verbatim,quote]
3030 \\override #'(style . cross) {
3034 \\note #\"breve\" #0
3037 (let ((parsed (parse-simple-duration duration)))
3038 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3040 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3042 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3044 (define-markup-command (lower layout props amount arg)
3048 @cindex lowering text
3050 Lower @var{arg} by the distance @var{amount}.
3051 A negative @var{amount} indicates raising; see also @code{\\raise}.
3053 @lilypond[verbatim,quote]
3061 (ly:stencil-translate-axis (interpret-markup layout props arg)
3064 (define-markup-command (translate-scaled layout props offset arg)
3065 (number-pair? markup?)
3067 #:properties ((font-size 0))
3069 @cindex translating text
3070 @cindex scaling text
3072 Translate @var{arg} by @var{offset}, scaling the offset by the
3075 @lilypond[verbatim,quote]
3078 * \\translate #'(2 . 3) translate
3080 * \\translate-scaled #'(2 . 3) translate-scaled
3084 (let* ((factor (magstep font-size))
3085 (scaled (cons (* factor (car offset))
3086 (* factor (cdr offset)))))
3087 (ly:stencil-translate (interpret-markup layout props arg)
3090 (define-markup-command (raise layout props amount arg)
3094 @cindex raising text
3096 Raise @var{arg} by the distance @var{amount}.
3097 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3099 The argument to @code{\\raise} is the vertical displacement amount,
3100 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3101 raise objects in relation to their surrounding markups.
3103 If the text object itself is positioned above or below the staff, then
3104 @code{\\raise} cannot be used to move it, since the mechanism that
3105 positions it next to the staff cancels any shift made with
3106 @code{\\raise}. For vertical positioning, use the @code{padding}
3107 and/or @code{extra-offset} properties.
3109 @lilypond[verbatim,quote]
3118 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3120 (define-markup-command (fraction layout props arg1 arg2)
3123 #:properties ((font-size 0))
3125 @cindex creating text fractions
3127 Make a fraction of two markups.
3128 @lilypond[verbatim,quote]
3134 (let* ((m1 (interpret-markup layout props arg1))
3135 (m2 (interpret-markup layout props arg2))
3136 (factor (magstep font-size))
3137 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3138 (padding (* factor 0.2))
3139 (baseline (* factor 0.6))
3140 (offset (* factor 0.75)))
3141 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3142 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3143 (let* ((x1 (ly:stencil-extent m1 X))
3144 (x2 (ly:stencil-extent m2 X))
3145 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3146 ;; should stack mols separately, to maintain LINE on baseline
3147 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3149 (ly:stencil-aligned-to stack Y CENTER))
3151 (ly:stencil-aligned-to stack X LEFT))
3152 ;; should have EX dimension
3154 (ly:stencil-translate-axis stack offset Y))))
3156 (define-markup-command (normal-size-super layout props arg)
3159 #:properties ((baseline-skip))
3161 @cindex setting superscript in standard font size
3163 Set @var{arg} in superscript with a normal font size.
3165 @lilypond[verbatim,quote]
3168 \\normal-size-super {
3169 superscript in standard size
3173 (ly:stencil-translate-axis
3174 (interpret-markup layout props arg)
3175 (* 0.5 baseline-skip) Y))
3177 (define-markup-command (super layout props arg)
3180 #:properties ((font-size 0)
3183 @cindex superscript text
3185 Set @var{arg} in superscript.
3187 @lilypond[verbatim,quote]
3197 (ly:stencil-translate-axis
3200 (cons `((font-size . ,(- font-size 3))) props)
3202 (* 0.5 baseline-skip)
3205 (define-markup-command (translate layout props offset arg)
3206 (number-pair? markup?)
3209 @cindex translating text
3211 Translate @var{arg} relative to its surroundings. @var{offset}
3212 is a pair of numbers representing the displacement in the X and Y axis.
3214 @lilypond[verbatim,quote]
3217 \\translate #'(2 . 3)
3218 \\line { translated two spaces right, three up }
3221 (ly:stencil-translate (interpret-markup layout props arg)
3224 (define-markup-command (sub layout props arg)
3227 #:properties ((font-size 0)
3230 @cindex subscript text
3232 Set @var{arg} in subscript.
3234 @lilypond[verbatim,quote]
3245 (ly:stencil-translate-axis
3248 (cons `((font-size . ,(- font-size 3))) props)
3250 (* -0.5 baseline-skip)
3253 (define-markup-command (normal-size-sub layout props arg)
3256 #:properties ((baseline-skip))
3258 @cindex setting subscript in standard font size
3260 Set @var{arg} in subscript with a normal font size.
3262 @lilypond[verbatim,quote]
3266 subscript in standard size
3270 (ly:stencil-translate-axis
3271 (interpret-markup layout props arg)
3272 (* -0.5 baseline-skip)
3275 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3277 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3279 (define-markup-command (hbracket layout props arg)
3283 @cindex placing horizontal brackets around text
3285 Draw horizontal brackets around @var{arg}.
3287 @lilypond[verbatim,quote]
3296 (let ((th 0.1) ;; todo: take from GROB.
3297 (m (interpret-markup layout props arg)))
3298 (bracketify-stencil m X th (* 2.5 th) th)))
3300 (define-markup-command (bracket layout props arg)
3304 @cindex placing vertical brackets around text
3306 Draw vertical brackets around @var{arg}.
3308 @lilypond[verbatim,quote]
3315 (let ((th 0.1) ;; todo: take from GROB.
3316 (m (interpret-markup layout props arg)))
3317 (bracketify-stencil m Y th (* 2.5 th) th)))
3319 (define-markup-command (parenthesize layout props arg)
3322 #:properties ((angularity 0)
3328 @cindex placing parentheses around text
3330 Draw parentheses around @var{arg}. This is useful for parenthesizing
3331 a column containing several lines of text.
3333 @lilypond[verbatim,quote]
3342 \\override #'(angularity . 2) {
3353 (let* ((markup (interpret-markup layout props arg))
3354 (scaled-width (* size width))
3356 (* (chain-assoc-get 'line-thickness props 0.1)
3359 (min (* size 0.5 scaled-thickness)
3360 (* (/ 4 3.0) scaled-width)))
3361 (padding (chain-assoc-get 'padding props half-thickness)))
3362 (parenthesize-stencil
3363 markup half-thickness scaled-width angularity padding)))
3366 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3367 ;; Delayed markup evaluation
3368 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3370 (define-markup-command (page-ref layout props label gauge default)
3371 (symbol? markup? markup?)
3374 @cindex referencing page numbers in text
3376 Reference to a page number. @var{label} is the label set on the referenced
3377 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3378 the maximum width of the page number, and @var{default} the value to display
3379 when @var{label} is not found."
3380 (let* ((gauge-stencil (interpret-markup layout props gauge))
3381 (x-ext (ly:stencil-extent gauge-stencil X))
3382 (y-ext (ly:stencil-extent gauge-stencil Y)))
3384 `(delay-stencil-evaluation
3385 ,(delay (ly:stencil-expr
3386 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3387 (page-number (if (list? table)
3388 (assoc-get label table)
3390 (page-markup (if page-number (format "~a" page-number) default))
3391 (page-stencil (interpret-markup layout props page-markup))
3392 (gap (- (interval-length x-ext)
3393 (interval-length (ly:stencil-extent page-stencil X)))))
3394 (interpret-markup layout props
3395 (markup #:concat (#:hspace gap page-markup)))))))
3399 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3401 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3403 (define-markup-command (scale layout props factor-pair arg)
3404 (number-pair? markup?)
3407 @cindex scaling markup
3408 @cindex mirroring markup
3410 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3411 representing the scaling-factor in the X and Y axes.
3412 Negative values may be used to produce mirror images.
3414 @lilypond[verbatim,quote]
3424 (let ((stil (interpret-markup layout props arg))
3425 (sx (car factor-pair))
3426 (sy (cdr factor-pair)))
3427 (ly:stencil-scale stil sx sy)))
3429 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3431 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3433 (define-markup-command (pattern layout props count axis space pattern)
3434 (integer? integer? number? markup?)
3437 Prints @var{count} times a @var{pattern} markup.
3438 Patterns are spaced apart by @var{space}.
3439 Patterns are distributed on @var{axis}.
3441 @lilypond[verbatim, quote]
3443 \"Horizontally repeated :\"
3444 \\pattern #7 #X #2 \\flat
3446 \"Vertically repeated :\"
3447 \\pattern #3 #Y #0.5 \\flat
3450 (let ((pattern-width (interval-length
3451 (ly:stencil-extent (interpret-markup layout props pattern) X)))
3452 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3453 (let loop ((i (1- count)) (patterns (markup)))
3459 (markup patterns pattern)
3460 (markup #:column (patterns pattern))))
3463 (markup patterns pattern #:hspace space)
3464 (markup #:column (patterns pattern #:vspace space))))))))
3466 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3467 (number? ly:dir? markup? markup? markup?)
3469 #:properties ((word-space)
3472 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3473 with a line of markups @var{pattern} in between.
3474 Patterns are spaced apart by @var{space}.
3475 Patterns are aligned to the @var{dir} markup.
3477 @lilypond[verbatim, quote]
3480 \\fill-with-pattern #1 #RIGHT . first right
3481 \\fill-with-pattern #1 #RIGHT . second right
3483 \"center-aligned :\"
3484 \\fill-with-pattern #1.5 #CENTER - left right
3487 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left first
3488 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left second
3491 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3492 (pattern-width (interval-length pattern-x-extent))
3493 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3494 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3495 (middle-width (- line-width (+ (+ left-width right-width) (* word-space 2))))
3496 (period (+ space pattern-width))
3497 (count (truncate (/ (- middle-width pattern-width) period)))
3498 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3499 (interpret-markup layout props
3501 #:with-dimensions (cons 0 middle-width) '(0 . 0)
3502 #:translate (cons x-offset 0)
3503 #:pattern (1+ count) X space pattern
3506 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3507 ;; Markup list commands
3508 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3510 (define-public (space-lines baseline stils)
3511 (let space-stil ((stils stils)
3515 (let* ((stil (car stils))
3516 (dy-top (max (- (/ baseline 1.5)
3517 (interval-bound (ly:stencil-extent stil Y) UP))
3519 (dy-bottom (max (+ (/ baseline 3.0)
3520 (interval-bound (ly:stencil-extent stil Y) DOWN))
3522 (new-stil (ly:make-stencil
3523 (ly:stencil-expr stil)
3524 (ly:stencil-extent stil X)
3525 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3527 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3529 (space-stil (cdr stils) (cons new-stil result))))))
3531 (define-markup-list-command (justified-lines layout props args)
3533 #:properties ((baseline-skip)
3534 wordwrap-internal-markup-list)
3536 @cindex justifying lines of text
3538 Like @code{\\justify}, but return a list of lines instead of a single markup.
3539 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3540 @var{X}@tie{}is the number of staff spaces."
3541 (space-lines baseline-skip
3542 (interpret-markup-list layout props
3543 (make-wordwrap-internal-markup-list #t args))))
3545 (define-markup-list-command (wordwrap-lines layout props args)
3547 #:properties ((baseline-skip)
3548 wordwrap-internal-markup-list)
3549 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3550 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3551 where @var{X} is the number of staff spaces."
3552 (space-lines baseline-skip
3553 (interpret-markup-list layout props
3554 (make-wordwrap-internal-markup-list #f args))))
3556 (define-markup-list-command (column-lines layout props args)
3558 #:properties ((baseline-skip))
3559 "Like @code{\\column}, but return a list of lines instead of a single markup.
3560 @code{baseline-skip} determines the space between each markup in @var{args}."
3561 (space-lines baseline-skip
3562 (interpret-markup-list layout props args)))
3564 (define-markup-list-command (override-lines layout props new-prop args)
3565 (pair? markup-list?)
3566 "Like @code{\\override}, for markup lists."
3567 (interpret-markup-list layout (cons (list new-prop) props) args))