1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;;; GNU General Public License for more details.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Markup commands and markup-list commands definitions.
22 ;;; Markup commands which are part of LilyPond, are defined
23 ;;; in the (lily) module, which is the current module in this file,
24 ;;; using the `define-markup-command' macro.
28 ;;; (define-markup-command (command-name layout props args...)
30 ;;; [ #:category category ]
31 ;;; [ #:properties property-bindings ]
32 ;;; documentation-string
37 ;;; the name of the markup command
40 ;;; arguments that are automatically passed to the command when it
42 ;;; `layout' is an output def, which properties can be accessed
43 ;;; using `ly:output-def-lookup'.
44 ;;; `props' is a list of property settings which can be accessed
45 ;;; using `chain-assoc-get' (more on that below)
48 ;;; the command arguments.
49 ;;; There is no limitation on the order of command arguments.
50 ;;; However, markup functions taking a markup as their last
51 ;;; argument are somewhat special as you can apply them to a
52 ;;; markup list, and the result is a markup list where the
53 ;;; markup function (with the specified leading arguments) has
54 ;;; been applied to every element of the original markup list.
56 ;;; Since replicating the leading arguments for applying a
57 ;;; markup function to a markup list is cheap mostly for
58 ;;; Scheme arguments, you avoid performance pitfalls by just
59 ;;; using Scheme arguments for the leading arguments of markup
60 ;;; functions that take a markup as their last argument.
63 ;;; the arguments signature, i.e. a list of type predicates which
64 ;;; are used to type check the arguments, and also to define the general
65 ;;; argument types (markup, markup-list, scheme) that the command is
67 ;;; For instance, if a command expects a number, then a markup, the
68 ;;; signature would be: (number? markup?)
71 ;;; for documentation purpose, builtin markup commands are grouped by
72 ;;; category. This can be any symbol. When documentation is generated,
73 ;;; the symbol is converted to a capitalized string, where hyphens are
74 ;;; replaced by spaces.
77 ;;; this is used both for documentation generation, and to ease
78 ;;; programming the command itself. It is list of
79 ;;; (property-name default-value)
80 ;;; or (property-name)
81 ;;; elements. Each property is looked-up in the `props' argument, and
82 ;;; the symbol naming the property is bound to its value.
83 ;;; When the property is not found in `props', then the symbol is bound
84 ;;; to the given default value. When no default value is given, #f is
86 ;;; Thus, using the following property bindings:
89 ;;; is equivalent to writing:
90 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
91 ;;; (font-size (chain-assoc-get 'font-size props 0)))
93 ;;; When a command `B' internally calls an other command `A', it may
94 ;;; desirable to see in `B' documentation all the properties and
95 ;;; default values used by `A'. In that case, add `A-markup' to the
96 ;;; property-bindings of B. (This is used when generating
97 ;;; documentation, but won't create bindings.)
99 ;;; documentation-string
100 ;;; the command documentation string (used to generate manuals)
103 ;;; the command body. The function is supposed to return a stencil.
105 ;;; Each markup command definition shall have a documentation string
106 ;;; with description, syntax and example.
108 (use-modules (ice-9 regex))
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
114 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
115 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 (define-markup-command (draw-line layout props dest)
124 #:properties ((thickness 1))
126 @cindex drawing lines within text
129 @lilypond[verbatim,quote]
131 \\draw-line #'(4 . 4)
132 \\override #'(thickness . 5)
133 \\draw-line #'(-3 . 0)
136 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
140 (make-line-stencil th 0 0 x y)))
142 (define-markup-command (draw-hline layout props)
145 #:properties ((draw-line-markup)
149 @cindex drawing a line across a page
151 Draws a line across a page, where the property @code{span-factor}
152 controls what fraction of the page is taken up.
153 @lilypond[verbatim,quote]
157 \\override #'(span-factor . 1/3)
162 (interpret-markup layout
164 (markup #:draw-line (cons (* line-width
168 (define-markup-command (draw-circle layout props radius thickness filled)
169 (number? number? boolean?)
172 @cindex drawing circles within text
174 A circle of radius @var{radius} and thickness @var{thickness},
177 @lilypond[verbatim,quote]
179 \\draw-circle #2 #0.5 ##f
181 \\draw-circle #2 #0 ##t
184 (make-circle-stencil radius thickness filled))
186 (define-markup-command (triangle layout props filled)
189 #:properties ((thickness 0.1)
193 @cindex drawing triangles within text
195 A triangle, either filled or empty.
197 @lilypond[verbatim,quote]
204 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
213 (cons 0 (* .86 ex)))))
215 (define-markup-command (circle layout props arg)
218 #:properties ((thickness 1)
220 (circle-padding 0.2))
222 @cindex circling text
224 Draw a circle around @var{arg}. Use @code{thickness},
225 @code{circle-padding} and @code{font-size} properties to determine line
226 thickness and padding around the markup.
228 @lilypond[verbatim,quote]
235 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
237 (pad (* (magstep font-size) circle-padding))
238 (m (interpret-markup layout props arg)))
239 (circle-stencil m th pad)))
241 (define-markup-command (with-url layout props url arg)
245 @cindex inserting URL links into text
247 Add a link to URL @var{url} around @var{arg}. This only works in
250 @lilypond[verbatim,quote]
252 \\with-url #\"http://lilypond.org/web/\" {
253 LilyPond ... \\italic {
254 music notation for everyone
259 (let* ((stil (interpret-markup layout props arg))
260 (xextent (ly:stencil-extent stil X))
261 (yextent (ly:stencil-extent stil Y))
262 (old-expr (ly:stencil-expr stil))
263 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
265 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
267 (define-markup-command (page-link layout props page-number arg)
271 @cindex referencing page numbers in text
273 Add a link to the page @var{page-number} around @var{arg}. This only works in
276 @lilypond[verbatim,quote]
278 \\page-link #2 { \\italic { This links to page 2... } }
281 (let* ((stil (interpret-markup layout props arg))
282 (xextent (ly:stencil-extent stil X))
283 (yextent (ly:stencil-extent stil Y))
284 (old-expr (ly:stencil-expr stil))
285 (link-expr (list 'page-link page-number `(quote ,xextent) `(quote ,yextent))))
287 (ly:stencil-add (ly:make-stencil link-expr xextent yextent) stil)))
289 (define-markup-command (with-link layout props label arg)
293 @cindex referencing page labels in text
295 Add a link to the page holding label @var{label} around @var{arg}. This
296 only works in the PDF backend.
298 @lilypond[verbatim,quote]
300 \\with-link #\"label\" { \\italic { This links to the page containing the label... } }
303 (let* ((arg-stencil (interpret-markup layout props arg))
304 (x-ext (ly:stencil-extent arg-stencil X))
305 (y-ext (ly:stencil-extent arg-stencil Y)))
307 `(delay-stencil-evaluation
308 ,(delay (ly:stencil-expr
309 (let* ((table (ly:output-def-lookup layout 'label-page-table))
310 (page-number (if (list? table)
311 (assoc-get label table)
313 (link-expr (list 'page-link page-number
314 `(quote ,x-ext) `(quote ,y-ext))))
315 (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
321 (define-markup-command (beam layout props width slope thickness)
322 (number? number? number?)
325 @cindex drawing beams within text
327 Create a beam with the specified parameters.
328 @lilypond[verbatim,quote]
333 (let* ((y (* slope width))
334 (yext (cons (min 0 y) (max 0 y)))
335 (half (/ thickness 2)))
340 width (+ (* width slope) (/ thickness -2))
341 width (+ (* width slope) (/ thickness 2))
343 ,(ly:output-def-lookup layout 'blot-diameter)
346 (cons (+ (- half) (car yext))
347 (+ half (cdr yext))))))
349 (define-markup-command (underline layout props arg)
352 #:properties ((thickness 1) (offset 2))
354 @cindex underlining text
356 Underline @var{arg}. Looks at @code{thickness} to determine line
357 thickness, and @code{offset} to determine line y-offset.
359 @lilypond[verbatim,quote]
360 \\markup \\fill-line {
361 \\underline \"underlined\"
362 \\override #'(offset . 5)
363 \\override #'(thickness . 1)
364 \\underline \"underlined\"
365 \\override #'(offset . 1)
366 \\override #'(thickness . 5)
367 \\underline \"underlined\"
370 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
371 (underline-thick (* thickness thick))
372 (markup (interpret-markup layout props arg))
373 (x1 (car (ly:stencil-extent markup X)))
374 (x2 (cdr (ly:stencil-extent markup X)))
375 (y (* thick (- offset)))
376 (line (make-line-stencil underline-thick x1 y x2 y)))
377 (ly:stencil-add markup line)))
379 (define-markup-command (box layout props arg)
382 #:properties ((thickness 1)
386 @cindex enclosing text within a box
388 Draw a box round @var{arg}. Looks at @code{thickness},
389 @code{box-padding} and @code{font-size} properties to determine line
390 thickness and padding around the markup.
392 @lilypond[verbatim,quote]
394 \\override #'(box-padding . 0.5)
399 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
401 (pad (* (magstep font-size) box-padding))
402 (m (interpret-markup layout props arg)))
403 (box-stencil m th pad)))
405 (define-markup-command (filled-box layout props xext yext blot)
406 (number-pair? number-pair? number?)
409 @cindex drawing solid boxes within text
410 @cindex drawing boxes with rounded corners
412 Draw a box with rounded corners of dimensions @var{xext} and
413 @var{yext}. For example,
415 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
417 creates a box extending horizontally from -0.3 to 1.8 and
418 vertically from -0.3 up to 1.8, with corners formed from a
419 circle of diameter@tie{}0 (i.e., sharp corners).
421 @lilypond[verbatim,quote]
423 \\filled-box #'(0 . 4) #'(0 . 4) #0
424 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
425 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
427 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
433 (define-markup-command (rounded-box layout props arg)
436 #:properties ((thickness 1)
440 "@cindex enclosing text in a box with rounded corners
441 @cindex drawing boxes with rounded corners around text
442 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
443 @code{box-padding} and @code{font-size} properties to determine line
444 thickness and padding around the markup; the @code{corner-radius} property
445 makes it possible to define another shape for the corners (default is 1).
447 @lilypond[quote,verbatim,relative=2]
455 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
457 (pad (* (magstep font-size) box-padding))
458 (m (interpret-markup layout props arg)))
459 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
462 (define-markup-command (rotate layout props ang arg)
466 @cindex rotating text
468 Rotate object with @var{ang} degrees around its center.
470 @lilypond[verbatim,quote]
480 (let* ((stil (interpret-markup layout props arg)))
481 (ly:stencil-rotate stil ang 0 0)))
483 (define-markup-command (whiteout layout props arg)
487 @cindex adding a white background to text
489 Provide a white background for @var{arg}.
491 @lilypond[verbatim,quote]
494 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
498 (stencil-whiteout (interpret-markup layout props arg)))
500 (define-markup-command (pad-markup layout props amount arg)
505 @cindex putting space around text
507 Add space around a markup object.
509 @lilypond[verbatim,quote]
523 ((stil (interpret-markup layout props arg))
524 (xext (ly:stencil-extent stil X))
525 (yext (ly:stencil-extent stil Y)))
528 (ly:stencil-expr stil)
529 (interval-widen xext amount)
530 (interval-widen yext amount))))
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 (define-markup-command (strut layout props)
540 @cindex creating vertical spaces in text
542 Create a box of the same height as the space in the current font."
543 (let ((m (ly:text-interface::interpret-markup layout props " ")))
544 (ly:make-stencil (ly:stencil-expr m)
546 (ly:stencil-extent m X)
549 ;; todo: fix negative space
550 (define-markup-command (hspace layout props amount)
553 #:properties ((word-space))
555 @cindex creating horizontal spaces in text
557 Create an invisible object taking up horizontal space @var{amount}.
559 @lilypond[verbatim,quote]
568 (let ((corrected-space (- amount word-space)))
569 (if (> corrected-space 0)
570 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
571 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
573 ;; todo: fix negative space
574 (define-markup-command (vspace layout props amount)
578 @cindex creating vertical spaces in text
580 Create an invisible object taking up vertical space
581 of @var{amount} multiplied by 3.
583 @lilypond[verbatim,quote]
594 (let ((amount (* amount 3.0)))
596 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
597 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
601 ;; importing graphics.
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
604 (define-markup-command (stencil layout props stil)
608 @cindex importing stencils into text
610 Use a stencil as markup.
612 @lilypond[verbatim,quote]
614 \\stencil #(make-circle-stencil 2 0 #t)
620 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
622 (define (get-postscript-bbox string)
623 "Extract the bbox from STRING, or return #f if not present."
625 ((match (regexp-exec bbox-regexp string)))
629 (string->number (match:substring match x)))
634 (define-markup-command (epsfile layout props axis size file-name)
635 (number? number? string?)
638 @cindex inlining an Encapsulated PostScript image
640 Inline an EPS image. The image is scaled along @var{axis} to
643 @lilypond[verbatim,quote]
645 \\general-align #Y #DOWN {
646 \\epsfile #X #20 #\"context-example.eps\"
647 \\epsfile #Y #20 #\"context-example.eps\"
651 (if (ly:get-option 'safe)
652 (interpret-markup layout props "not allowed in safe")
653 (eps-file->stencil axis size file-name)
656 (define-markup-command (postscript layout props str)
660 @cindex inserting PostScript directly into text
661 This inserts @var{str} directly into the output as a PostScript
664 @lilypond[verbatim,quote]
668 0.4 0.6 0.5 0 361 arc
670 1.0 0.6 0.5 0 361 arc
675 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
676 \\postscript #ringsps
688 gsave currentpoint translate
696 (define-markup-command (path layout props thickness commands) (number? list?)
698 #:properties ((line-cap-style 'round)
699 (line-join-style 'round)
702 @cindex paths, drawing
703 @cindex drawing paths
704 Draws a path with line thickness @var{thickness} according to the
705 directions given in @var{commands}. @var{commands} is a list of
706 lists where the @code{car} of each sublist is a drawing command and
707 the @code{cdr} comprises the associated arguments for each command.
709 Line-cap styles and line-join styles may be customized by
710 overriding the @code{line-cap-style} and @code{line-join-style}
711 properties, respectively. Available line-cap styles are
712 @code{'butt}, @code{'round}, and @code{'square}. Available
713 line-join styles are @code{'miter}, @code{'round}, and
716 The property @code{filled} specifies whether or not the path is
719 There are seven commands available to use in the list
720 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
721 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
722 @code{closepath}. Note that the commands that begin with @emph{r}
723 are the relative variants of the other three commands.
725 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
726 @code{rlineto} take 2 arguments; they are the X and Y coordinates
727 for the destination point.
729 The commands @code{curveto} and @code{rcurveto} create cubic
730 Bézier curves, and take 6 arguments; the first two are the X and Y
731 coordinates for the first control point, the second two are the X
732 and Y coordinates for the second control point, and the last two
733 are the X and Y coordinates for the destination point.
735 The @code{closepath} command takes zero arguments and closes the
736 current subpath in the active path.
738 Note that a sequence of commands @emph{must} begin with a
739 @code{moveto} or @code{rmoveto} to work with the SVG output.
741 @lilypond[verbatim,quote]
747 (curveto -5 -5 -5 5 -1 0)
751 \\path #0.25 #samplePath
754 (let* ((half-thickness (/ thickness 2))
755 (current-point '(0 . 0))
756 (set-point (lambda (lst) (set! current-point lst)))
757 (relative? (lambda (x)
758 (string-prefix? "r" (symbol->string (car x)))))
759 ;; For calculating extents, we want to modify the command
760 ;; list so that all coordinates are absolute.
761 (new-commands (map (lambda (x)
763 ;; for rmoveto, rlineto
764 ((and (relative? x) (eq? 3 (length x)))
766 (+ (car current-point)
768 (+ (cdr current-point)
774 ((and (relative? x) (eq? 7 (length x)))
775 (let* ((old-cp current-point)
782 (list (+ (car old-cp) (second x))
783 (+ (cdr old-cp) (third x))
784 (+ (car old-cp) (fourth x))
785 (+ (cdr old-cp) (fifth x))
788 ;; for moveto, lineto
790 (set-point (cons (second x)
795 (set-point (cons (sixth x)
798 ;; keep closepath for filtering;
799 ;; see `without-closepath'.
802 ;; path-min-max does not accept 0-arg lists,
803 ;; and since closepath does not affect extents, filter
804 ;; out those commands here.
805 (without-closepath (filter (lambda (x)
806 (not (equal? 'closepath (car x))))
808 (extents (path-min-max
809 ;; set the origin to the first moveto
810 (list (list-ref (car without-closepath) 0)
811 (list-ref (car without-closepath) 1))
813 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
814 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
815 (command-list (fold-right append '() commands)))
817 ;; account for line thickness
818 (set! X-extent (interval-widen X-extent half-thickness))
819 (set! Y-extent (interval-widen Y-extent half-thickness))
822 `(path ,thickness `(,@',command-list)
823 ',line-cap-style ',line-join-style ,filled)
827 (define-markup-command (score layout props score)
830 #:properties ((baseline-skip))
832 @cindex inserting music into text
834 Inline an image of music.
836 @lilypond[verbatim,quote]
840 \\new Staff \\relative c' {
843 \\mark \\markup { Allegro }
849 \\new Staff \\relative c {
863 \\override RehearsalMark #'break-align-symbols =
864 #'(time-signature key-signature)
865 \\override RehearsalMark #'self-alignment-X = #LEFT
869 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
875 (let ((output (ly:score-embedded-format score layout)))
877 (if (ly:music-output? output)
878 (stack-stencils Y DOWN baseline-skip
879 (map paper-system-stencil
881 (ly:paper-score-paper-systems output))))
883 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
886 (define-markup-command (null layout props)
890 @cindex creating empty text objects
892 An empty markup with extents of a single point.
894 @lilypond[verbatim,quote]
901 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
903 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
905 (define-markup-command (simple layout props str)
909 @cindex simple text strings
911 A simple text string; @code{\\markup @{ foo @}} is equivalent with
912 @code{\\markup @{ \\simple #\"foo\" @}}.
914 Note: for creating standard text markup or defining new markup commands,
915 the use of @code{\\simple} is unnecessary.
917 @lilypond[verbatim,quote]
921 \\simple #\"strings\"
924 (interpret-markup layout props str))
926 (define-markup-command (tied-lyric layout props str)
930 @cindex simple text strings with tie characters
932 Like simple-markup, but use tie characters for @q{~} tilde symbols.
934 @lilypond[verbatim,quote]
936 \\tied-lyric #\"Lasciate~i monti\"
939 (if (string-contains str "~")
941 ((parts (string-split str #\~))
942 (tie-str (ly:wide-char->utf-8 #x203f))
943 (joined (list-join parts tie-str))
944 (join-stencil (interpret-markup layout props tie-str))
947 (interpret-markup layout
950 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
952 (make-line-markup joined)))
953 ;(map (lambda (s) (interpret-markup layout props s)) parts))
954 (interpret-markup layout props str)))
956 (define-public empty-markup
957 (make-simple-markup ""))
959 ;; helper for justifying lines.
960 (define (get-fill-space word-count line-width word-space text-widths)
961 "Calculate the necessary paddings between each two adjacent texts.
962 The lengths of all texts are stored in @var{text-widths}.
963 The normal formula for the padding between texts a and b is:
964 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
965 The first and last padding have to be calculated specially using the
966 whole length of the first or last text.
967 All paddings are checked to be at least word-space, to ensure that
969 Return a list of paddings."
971 ((null? text-widths) '())
973 ;; special case first padding
974 ((= (length text-widths) word-count)
976 (- (- (/ line-width (1- word-count)) (car text-widths))
977 (/ (car (cdr text-widths)) 2))
978 (get-fill-space word-count line-width word-space (cdr text-widths))))
979 ;; special case last padding
980 ((= (length text-widths) 2)
981 (list (- (/ line-width (1- word-count))
982 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
984 (let ((default-padding
985 (- (/ line-width (1- word-count))
986 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
988 (if (> word-space default-padding)
991 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
993 (define-markup-command (fill-line layout props args)
996 #:properties ((text-direction RIGHT)
999 "Put @var{markups} in a horizontal line of width @var{line-width}.
1000 The markups are spaced or flushed to fill the entire line.
1001 If there are no arguments, return an empty stencil.
1003 @lilypond[verbatim,quote]
1007 Words evenly spaced across the page
1011 \\line { Text markups }
1013 \\italic { evenly spaced }
1015 \\line { across the page }
1020 (let* ((orig-stencils (interpret-markup-list layout props args))
1023 (if (ly:stencil-empty? stc)
1025 stc)) orig-stencils))
1028 (if (ly:stencil-empty? stc)
1030 (interval-length (ly:stencil-extent stc X))))
1032 (text-width (apply + text-widths))
1033 (word-count (length stencils))
1034 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1039 (/ (- line-width text-width) 2)
1040 (/ (- line-width text-width) 2)))
1043 (- line-width text-width)))
1045 (get-fill-space word-count line-width word-space text-widths))))
1047 (line-contents (if (= word-count 1)
1054 (if (null? (remove ly:stencil-empty? orig-stencils))
1057 (if (= text-direction LEFT)
1058 (set! line-contents (reverse line-contents)))
1060 (stack-stencils-padding-list
1061 X RIGHT fill-space line-contents))
1062 (if (> word-count 1)
1063 ;; shift s.t. stencils align on the left edge, even if
1064 ;; first stencil had negative X-extent (e.g. center-column)
1065 ;; (if word-count = 1, X-extents are already normalized in
1066 ;; the definition of line-contents)
1068 (ly:stencil-translate-axis
1070 (- (car (ly:stencil-extent (car stencils) X)))
1074 (define-markup-command (line layout props args)
1077 #:properties ((word-space)
1078 (text-direction RIGHT))
1079 "Put @var{args} in a horizontal line. The property @code{word-space}
1080 determines the space between markups in @var{args}.
1082 @lilypond[verbatim,quote]
1089 (let ((stencils (interpret-markup-list layout props args)))
1090 (if (= text-direction LEFT)
1091 (set! stencils (reverse stencils)))
1094 (remove ly:stencil-empty? stencils))))
1096 (define-markup-command (concat layout props args)
1100 @cindex concatenating text
1101 @cindex ligatures in text
1103 Concatenate @var{args} in a horizontal line, without spaces in between.
1104 Strings and simple markups are concatenated on the input level, allowing
1105 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1106 equivalent to @code{\"fi\"}.
1108 @lilypond[verbatim,quote]
1117 (define (concat-string-args arg-list)
1118 (fold-right (lambda (arg result-list)
1119 (let ((result (if (pair? result-list)
1122 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1123 (set! arg (cadr arg)))
1124 (if (and (string? result) (string? arg))
1125 (cons (string-append arg result) (cdr result-list))
1126 (cons arg result-list))))
1130 (interpret-markup layout
1131 (prepend-alist-chain 'word-space 0 props)
1132 (make-line-markup (if (markup-command-list? args)
1134 (concat-string-args args)))))
1136 (define (wordwrap-stencils stencils
1137 justify base-space line-width text-dir)
1138 "Perform simple wordwrap, return stencil of each line."
1139 (define space (if justify
1140 ;; justify only stretches lines.
1143 (define (take-list width space stencils
1144 accumulator accumulated-width)
1145 "Return (head-list . tail) pair, with head-list fitting into width"
1146 (if (null? stencils)
1147 (cons accumulator stencils)
1148 (let* ((first (car stencils))
1149 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1150 (newwid (+ space first-wid accumulated-width)))
1151 (if (or (null? accumulator)
1153 (take-list width space
1155 (cons first accumulator)
1157 (cons accumulator stencils)))))
1158 (let loop ((lines '())
1160 (let* ((line-break (take-list line-width space todo
1162 (line-stencils (car line-break))
1163 (space-left (- line-width
1164 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1166 (line-word-space (cond ((not justify) space)
1167 ;; don't stretch last line of paragraph.
1168 ;; hmmm . bug - will overstretch the last line in some case.
1169 ((null? (cdr line-break))
1171 ((null? line-stencils) 0.0)
1172 ((null? (cdr line-stencils)) 0.0)
1173 (else (/ space-left (1- (length line-stencils))))))
1174 (line (stack-stencil-line line-word-space
1175 (if (= text-dir RIGHT)
1176 (reverse line-stencils)
1178 (if (pair? (cdr line-break))
1179 (loop (cons line lines)
1182 (if (= text-dir LEFT)
1184 (ly:stencil-translate-axis
1186 (- line-width (interval-end (ly:stencil-extent line X)))
1188 (reverse (cons line lines)))))))
1190 (define-markup-list-command (wordwrap-internal layout props justify args)
1191 (boolean? markup-list?)
1192 #:properties ((line-width #f)
1194 (text-direction RIGHT))
1195 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1196 (wordwrap-stencils (remove ly:stencil-empty?
1197 (interpret-markup-list layout props args))
1201 (ly:output-def-lookup layout 'line-width))
1204 (define-markup-command (justify layout props args)
1207 #:properties ((baseline-skip)
1208 wordwrap-internal-markup-list)
1210 @cindex justifying text
1212 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1213 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1214 @var{X}@tie{}is the number of staff spaces.
1216 @lilypond[verbatim,quote]
1219 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1220 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1221 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1222 laboris nisi ut aliquip ex ea commodo consequat.
1226 (stack-lines DOWN 0.0 baseline-skip
1227 (wordwrap-internal-markup-list layout props #t args)))
1229 (define-markup-command (wordwrap layout props args)
1232 #:properties ((baseline-skip)
1233 wordwrap-internal-markup-list)
1234 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1235 the line width, where @var{X} is the number of staff spaces.
1237 @lilypond[verbatim,quote]
1240 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1241 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1242 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1243 laboris nisi ut aliquip ex ea commodo consequat.
1247 (stack-lines DOWN 0.0 baseline-skip
1248 (wordwrap-internal-markup-list layout props #f args)))
1250 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1252 #:properties ((line-width)
1254 (text-direction RIGHT))
1255 "Internal markup list command used to define @code{\\justify-string} and
1256 @code{\\wordwrap-string}."
1257 (let* ((para-strings (regexp-split
1258 (string-regexp-substitute
1260 (string-regexp-substitute "\r\n" "\n" arg))
1261 "\n[ \t\n]*\n[ \t\n]*"))
1262 (list-para-words (map (lambda (str)
1263 (regexp-split str "[ \t\n]+"))
1265 (para-lines (map (lambda (words)
1267 (remove ly:stencil-empty?
1269 (interpret-markup layout props x))
1271 (wordwrap-stencils stencils
1273 line-width text-direction)))
1275 (apply append para-lines)))
1277 (define-markup-command (wordwrap-string layout props arg)
1280 #:properties ((baseline-skip)
1281 wordwrap-string-internal-markup-list)
1282 "Wordwrap a string. Paragraphs may be separated with double newlines.
1284 @lilypond[verbatim,quote]
1286 \\override #'(line-width . 40)
1287 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1288 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1289 et dolore magna aliqua.
1292 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1293 laboris nisi ut aliquip ex ea commodo consequat.
1296 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1297 qui officia deserunt mollit anim id est laborum\"
1300 (stack-lines DOWN 0.0 baseline-skip
1301 (wordwrap-string-internal-markup-list layout props #f arg)))
1303 (define-markup-command (justify-string layout props arg)
1306 #:properties ((baseline-skip)
1307 wordwrap-string-internal-markup-list)
1308 "Justify a string. Paragraphs may be separated with double newlines
1310 @lilypond[verbatim,quote]
1312 \\override #'(line-width . 40)
1313 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1314 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1315 et dolore magna aliqua.
1318 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1319 laboris nisi ut aliquip ex ea commodo consequat.
1322 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1323 qui officia deserunt mollit anim id est laborum\"
1326 (stack-lines DOWN 0.0 baseline-skip
1327 (wordwrap-string-internal-markup-list layout props #t arg)))
1329 (define-markup-command (wordwrap-field layout props symbol)
1332 "Wordwrap the data which has been assigned to @var{symbol}.
1334 @lilypond[verbatim,quote]
1336 title = \"My title\"
1337 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1338 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1339 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1340 laboris nisi ut aliquip ex ea commodo consequat.\"
1344 bookTitleMarkup = \\markup {
1346 \\fill-line { \\fromproperty #'header:title }
1348 \\wordwrap-field #'header:myText
1357 (let* ((m (chain-assoc-get symbol props)))
1359 (wordwrap-string-markup layout props m)
1362 (define-markup-command (justify-field layout props symbol)
1365 "Justify the data which has been assigned to @var{symbol}.
1367 @lilypond[verbatim,quote]
1369 title = \"My title\"
1370 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1371 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1372 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1373 laboris nisi ut aliquip ex ea commodo consequat.\"
1377 bookTitleMarkup = \\markup {
1379 \\fill-line { \\fromproperty #'header:title }
1381 \\justify-field #'header:myText
1390 (let* ((m (chain-assoc-get symbol props)))
1392 (justify-string-markup layout props m)
1395 (define-markup-command (combine layout props arg1 arg2)
1399 @cindex merging text
1401 Print two markups on top of each other.
1403 Note: @code{\\combine} cannot take a list of markups enclosed in
1404 curly braces as an argument; the follow example will not compile:
1407 \\combine @{ a list @}
1410 @lilypond[verbatim,quote]
1413 \\override #'(thickness . 2)
1415 \\draw-line #'(0 . 4)
1416 \\arrow-head #Y #DOWN ##f
1419 (let* ((s1 (interpret-markup layout props arg1))
1420 (s2 (interpret-markup layout props arg2)))
1421 (ly:stencil-add s1 s2)))
1424 ;; TODO: should extract baseline-skip from each argument somehow..
1426 (define-markup-command (column layout props args)
1429 #:properties ((baseline-skip))
1431 @cindex stacking text in a column
1433 Stack the markups in @var{args} vertically. The property
1434 @code{baseline-skip} determines the space between markups
1437 @lilypond[verbatim,quote]
1446 (let ((arg-stencils (interpret-markup-list layout props args)))
1447 (stack-lines -1 0.0 baseline-skip
1448 (remove ly:stencil-empty? arg-stencils))))
1450 (define-markup-command (dir-column layout props args)
1453 #:properties ((direction)
1456 @cindex changing direction of text columns
1458 Make a column of @var{args}, going up or down, depending on the
1459 setting of the @code{direction} layout property.
1461 @lilypond[verbatim,quote]
1463 \\override #`(direction . ,UP) {
1473 \\override #'(direction . 1) {
1480 (stack-lines (if (number? direction) direction -1)
1483 (interpret-markup-list layout props args)))
1485 (define (general-column align-dir baseline mols)
1486 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1488 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1489 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1490 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1491 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1493 (define-markup-command (center-column layout props args)
1496 #:properties ((baseline-skip))
1498 @cindex centering a column of text
1500 Put @code{args} in a centered column.
1502 @lilypond[verbatim,quote]
1511 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1513 (define-markup-command (left-column layout props args)
1516 #:properties ((baseline-skip))
1518 @cindex text columns, left-aligned
1520 Put @code{args} in a left-aligned column.
1522 @lilypond[verbatim,quote]
1531 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1533 (define-markup-command (right-column layout props args)
1536 #:properties ((baseline-skip))
1538 @cindex text columns, right-aligned
1540 Put @code{args} in a right-aligned column.
1542 @lilypond[verbatim,quote]
1551 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1553 (define-markup-command (vcenter layout props arg)
1557 @cindex vertically centering text
1559 Align @code{arg} to its Y@tie{}center.
1561 @lilypond[verbatim,quote]
1569 (let* ((mol (interpret-markup layout props arg)))
1570 (ly:stencil-aligned-to mol Y CENTER)))
1572 (define-markup-command (center-align layout props arg)
1576 @cindex horizontally centering text
1578 Align @code{arg} to its X@tie{}center.
1580 @lilypond[verbatim,quote]
1590 (let* ((mol (interpret-markup layout props arg)))
1591 (ly:stencil-aligned-to mol X CENTER)))
1593 (define-markup-command (right-align layout props arg)
1597 @cindex right aligning text
1599 Align @var{arg} on its right edge.
1601 @lilypond[verbatim,quote]
1611 (let* ((m (interpret-markup layout props arg)))
1612 (ly:stencil-aligned-to m X RIGHT)))
1614 (define-markup-command (left-align layout props arg)
1618 @cindex left aligning text
1620 Align @var{arg} on its left edge.
1622 @lilypond[verbatim,quote]
1632 (let* ((m (interpret-markup layout props arg)))
1633 (ly:stencil-aligned-to m X LEFT)))
1635 (define-markup-command (general-align layout props axis dir arg)
1636 (integer? number? markup?)
1639 @cindex controlling general text alignment
1641 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1643 @lilypond[verbatim,quote]
1647 \\general-align #X #LEFT
1652 \\general-align #X #CENTER
1658 \\general-align #Y #UP
1665 \\general-align #Y #3.2
1672 (let* ((m (interpret-markup layout props arg)))
1673 (ly:stencil-aligned-to m axis dir)))
1675 (define-markup-command (halign layout props dir arg)
1679 @cindex setting horizontal text alignment
1681 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1682 left-aligned, while @code{+1} is right. Values in between interpolate
1683 alignment accordingly.
1685 @lilypond[verbatim,quote]
1710 (let* ((m (interpret-markup layout props arg)))
1711 (ly:stencil-aligned-to m X dir)))
1713 (define-markup-command (with-dimensions layout props x y arg)
1714 (number-pair? number-pair? markup?)
1717 @cindex setting extent of text objects
1719 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1720 (let* ((m (interpret-markup layout props arg)))
1721 (ly:make-stencil (ly:stencil-expr m) x y)))
1723 (define-markup-command (pad-around layout props amount arg)
1726 "Add padding @var{amount} all around @var{arg}.
1728 @lilypond[verbatim,quote]
1741 (let* ((m (interpret-markup layout props arg))
1742 (x (ly:stencil-extent m X))
1743 (y (ly:stencil-extent m Y)))
1744 (ly:make-stencil (ly:stencil-expr m)
1745 (interval-widen x amount)
1746 (interval-widen y amount))))
1748 (define-markup-command (pad-x layout props amount arg)
1752 @cindex padding text horizontally
1754 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1756 @lilypond[verbatim,quote]
1769 (let* ((m (interpret-markup layout props arg))
1770 (x (ly:stencil-extent m X))
1771 (y (ly:stencil-extent m Y)))
1772 (ly:make-stencil (ly:stencil-expr m)
1773 (interval-widen x amount)
1776 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1777 (integer? ly:dir? markup? markup?)
1779 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1780 (let ((m1 (interpret-markup layout props arg1))
1781 (m2 (interpret-markup layout props arg2)))
1782 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1784 (define-markup-command (transparent layout props arg)
1787 "Make @var{arg} transparent.
1789 @lilypond[verbatim,quote]
1796 (let* ((m (interpret-markup layout props arg))
1797 (x (ly:stencil-extent m X))
1798 (y (ly:stencil-extent m Y)))
1799 (ly:make-stencil "" x y)))
1801 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1802 (number-pair? number-pair? markup?)
1804 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1806 @lilypond[verbatim,quote]
1813 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1819 (let* ((m (interpret-markup layout props arg))
1820 (x (ly:stencil-extent m X))
1821 (y (ly:stencil-extent m Y)))
1822 (ly:make-stencil (ly:stencil-expr m)
1823 (interval-union x-ext x)
1824 (interval-union y-ext y))))
1826 (define-markup-command (hcenter-in layout props length arg)
1829 "Center @var{arg} horizontally within a box of extending
1830 @var{length}/2 to the left and right.
1832 @lilypond[quote,verbatim]
1835 \\set Staff.instrumentName = \\markup {
1842 \\set Staff.instrumentName = \\markup {
1851 (interpret-markup layout props
1852 (make-pad-to-box-markup
1853 (cons (/ length -2) (/ length 2))
1855 (make-center-align-markup arg))))
1857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1859 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1861 (define-markup-command (fromproperty layout props symbol)
1864 "Read the @var{symbol} from property settings, and produce a stencil
1865 from the markup contained within. If @var{symbol} is not defined, it
1866 returns an empty markup.
1868 @lilypond[verbatim,quote]
1870 myTitle = \"myTitle\"
1874 \\fromproperty #'header:myTitle
1881 (let ((m (chain-assoc-get symbol props)))
1883 (interpret-markup layout props m)
1886 (define-markup-command (on-the-fly layout props procedure arg)
1889 "Apply the @var{procedure} markup command to @var{arg}.
1890 @var{procedure} should take a single argument."
1891 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1892 (set-object-property! anonymous-with-signature
1895 (interpret-markup layout props (list anonymous-with-signature arg))))
1897 (define-markup-command (footnote layout props mkup note)
1900 #:properties ((raise 0.5)
1902 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
1904 @lilypond[verbatim,quote]
1907 \\override #'(padding . 0.2)
1911 (let* ((markup-stencil (interpret-markup layout props mkup))
1912 (auto-numbering (ly:output-def-lookup layout
1913 'footnote-auto-numbering))
1914 (footnote-hash (gensym "footnote"))
1916 (gauge-stencil (if auto-numbering
1920 ((ly:output-def-lookup
1922 'footnote-numbering-function)
1925 (x-ext (if auto-numbering
1926 (ly:stencil-extent gauge-stencil X)
1928 (y-ext (if auto-numbering
1929 (ly:stencil-extent gauge-stencil Y)
1933 `(delay-stencil-evaluation
1937 (ly:output-def-lookup layout
1938 'number-footnote-table))
1939 (footnote-stencil (if (list? table)
1940 (assoc-get footnote-hash
1943 (footnote-stencil (if (ly:stencil? footnote-stencil)
1946 (ly:programming-error
1947 "Cannot find correct footnote for a markup object.")
1949 (gap (- (interval-length x-ext)
1951 (ly:stencil-extent footnote-stencil X))))
1952 (y-trans (- (+ (cdr y-ext)
1954 (cdr (ly:stencil-extent footnote-stencil
1956 (ly:stencil-translate footnote-stencil
1957 (cons gap y-trans))))))
1959 (main-stencil (ly:stencil-combine-at-edge
1963 (ly:make-stencil footnote-number x-ext y-ext)
1968 `(footnote ,footnote-hash ,(interpret-markup layout props note))
1972 (define-markup-command (override layout props new-prop arg)
1976 @cindex overriding properties within text markup
1978 Add the argument @var{new-prop} to the property list. Properties
1979 may be any property supported by @rinternals{font-interface},
1980 @rinternals{text-interface} and
1981 @rinternals{instrument-specific-markup-interface}.
1983 @lilypond[verbatim,quote]
1991 \\override #'(baseline-skip . 4) {
2000 (interpret-markup layout (cons (list new-prop) props) arg))
2002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2006 (define-markup-command (verbatim-file layout props name)
2009 "Read the contents of file @var{name}, and include it verbatim.
2011 @lilypond[verbatim,quote]
2013 \\verbatim-file #\"simple.ly\"
2016 (interpret-markup layout props
2017 (if (ly:get-option 'safe)
2018 "verbatim-file disabled in safe mode"
2019 (let* ((str (ly:gulp-file name))
2020 (lines (string-split str #\nl)))
2021 (make-typewriter-markup
2022 (make-column-markup lines))))))
2024 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2026 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2029 (define-markup-command (smaller layout props arg)
2032 "Decrease the font size relative to the current setting.
2034 @lilypond[verbatim,quote]
2047 (interpret-markup layout props
2048 `(,fontsize-markup -1 ,arg)))
2050 (define-markup-command (larger layout props arg)
2053 "Increase the font size relative to the current setting.
2055 @lilypond[verbatim,quote]
2063 (interpret-markup layout props
2064 `(,fontsize-markup 1 ,arg)))
2066 (define-markup-command (finger layout props arg)
2069 "Set @var{arg} as small numbers.
2071 @lilypond[verbatim,quote]
2078 (interpret-markup layout
2079 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2082 (define-markup-command (abs-fontsize layout props size arg)
2085 "Use @var{size} as the absolute font size to display @var{arg}.
2086 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2088 @lilypond[verbatim,quote]
2090 default text font size
2092 \\abs-fontsize #16 { text font size 16 }
2094 \\abs-fontsize #12 { text font size 12 }
2097 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2098 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2099 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2100 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2101 (magnification (/ size ref-size)))
2102 (interpret-markup layout
2103 (cons `((baseline-skip . ,(* magnification ref-baseline))
2104 (word-space . ,(* magnification ref-word-space))
2105 (font-size . ,(magnification->font-size magnification)))
2109 (define-markup-command (fontsize layout props increment arg)
2112 #:properties ((font-size 0)
2115 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2118 @lilypond[verbatim,quote]
2126 (let ((entries (list
2127 (cons 'baseline-skip (* baseline-skip (magstep increment)))
2128 (cons 'word-space (* word-space (magstep increment)))
2129 (cons 'font-size (+ font-size increment)))))
2130 (interpret-markup layout (cons entries props) arg)))
2132 (define-markup-command (magnify layout props sz arg)
2136 @cindex magnifying text
2138 Set the font magnification for its argument. In the following
2139 example, the middle@tie{}A is 10% larger:
2142 A \\magnify #1.1 @{ A @} A
2145 Note: Magnification only works if a font name is explicitly selected.
2146 Use @code{\\fontsize} otherwise.
2148 @lilypond[verbatim,quote]
2159 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2162 (define-markup-command (bold layout props arg)
2165 "Switch to bold font-series.
2167 @lilypond[verbatim,quote]
2175 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2177 (define-markup-command (sans layout props arg)
2180 "Switch to the sans serif font family.
2182 @lilypond[verbatim,quote]
2191 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2193 (define-markup-command (number layout props arg)
2196 "Set font family to @code{number}, which yields the font used for
2197 time signatures and fingerings. This font contains numbers and
2198 some punctuation; it has no letters.
2200 @lilypond[verbatim,quote]
2203 0 1 2 3 4 5 6 7 8 9 . ,
2207 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2209 (define-markup-command (roman layout props arg)
2212 "Set font family to @code{roman}.
2214 @lilypond[verbatim,quote]
2220 text in roman font family
2227 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2229 (define-markup-command (huge layout props arg)
2232 "Set font size to +2.
2234 @lilypond[verbatim,quote]
2242 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2244 (define-markup-command (large layout props arg)
2247 "Set font size to +1.
2249 @lilypond[verbatim,quote]
2257 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2259 (define-markup-command (normalsize layout props arg)
2262 "Set font size to default.
2264 @lilypond[verbatim,quote]
2277 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2279 (define-markup-command (small layout props arg)
2282 "Set font size to -1.
2284 @lilypond[verbatim,quote]
2292 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2294 (define-markup-command (tiny layout props arg)
2297 "Set font size to -2.
2299 @lilypond[verbatim,quote]
2307 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2309 (define-markup-command (teeny layout props arg)
2312 "Set font size to -3.
2314 @lilypond[verbatim,quote]
2322 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2324 (define-markup-command (fontCaps layout props arg)
2327 "Set @code{font-shape} to @code{caps}
2329 Note: @code{\\fontCaps} requires the installation and selection of
2330 fonts which support the @code{caps} font shape."
2331 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2334 (define-markup-command (smallCaps layout props arg)
2337 "Emit @var{arg} as small caps.
2339 Note: @code{\\smallCaps} does not support accented characters.
2341 @lilypond[verbatim,quote]
2350 (define (char-list->markup chars lower)
2351 (let ((final-string (string-upcase (reverse-list->string chars))))
2353 (markup #:fontsize -2 final-string)
2355 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2356 (if (null? rest-chars)
2358 (reverse! (cons (char-list->markup currents current-is-lower)
2360 (let* ((ch (car rest-chars))
2361 (is-lower (char-lower-case? ch)))
2362 (if (or (and current-is-lower is-lower)
2363 (and (not current-is-lower) (not is-lower)))
2364 (make-small-caps (cdr rest-chars)
2368 (make-small-caps (cdr rest-chars)
2371 (if (null? currents)
2373 (cons (char-list->markup
2374 currents current-is-lower)
2376 (interpret-markup layout props
2378 (make-small-caps (string->list arg) (list) #f (list))
2381 (define-markup-command (caps layout props arg)
2384 "Copy of the @code{\\smallCaps} command.
2386 @lilypond[verbatim,quote]
2395 (interpret-markup layout props (make-smallCaps-markup arg)))
2397 (define-markup-command (dynamic layout props arg)
2400 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2401 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2402 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2403 done in a different font. The recommended font for this is bold and italic.
2404 @lilypond[verbatim,quote]
2412 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2414 (define-markup-command (text layout props arg)
2417 "Use a text font instead of music symbol or music alphabet font.
2419 @lilypond[verbatim,quote]
2432 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2435 (define-markup-command (italic layout props arg)
2438 "Use italic @code{font-shape} for @var{arg}.
2440 @lilypond[verbatim,quote]
2448 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2450 (define-markup-command (typewriter layout props arg)
2453 "Use @code{font-family} typewriter for @var{arg}.
2455 @lilypond[verbatim,quote]
2464 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2466 (define-markup-command (upright layout props arg)
2469 "Set @code{font-shape} to @code{upright}. This is the opposite
2472 @lilypond[verbatim,quote]
2486 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2488 (define-markup-command (medium layout props arg)
2491 "Switch to medium font-series (in contrast to bold).
2493 @lilypond[verbatim,quote]
2506 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2509 (define-markup-command (normal-text layout props arg)
2512 "Set all font related properties (except the size) to get the default
2513 normal text font, no matter what font was used earlier.
2515 @lilypond[verbatim,quote]
2517 \\huge \\bold \\sans \\caps {
2518 Some text with font overrides
2521 Default text, same font-size
2529 (interpret-markup layout
2530 (cons '((font-family . roman) (font-shape . upright)
2531 (font-series . medium) (font-encoding . latin1))
2535 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2537 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2539 (define-markup-command (musicglyph layout props glyph-name)
2542 "@var{glyph-name} is converted to a musical symbol; for example,
2543 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2544 the music font. See @ruser{The Feta font} for a complete listing of
2545 the possible glyphs.
2547 @lilypond[verbatim,quote]
2550 \\musicglyph #\"rests.2\"
2551 \\musicglyph #\"clefs.G_change\"
2554 (let* ((font (ly:paper-get-font layout
2555 (cons '((font-encoding . fetaMusic)
2559 (glyph (ly:font-get-glyph font glyph-name)))
2560 (if (null? (ly:stencil-expr glyph))
2561 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2565 (define-markup-command (doublesharp layout props)
2568 "Draw a double sharp symbol.
2570 @lilypond[verbatim,quote]
2575 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2577 (define-markup-command (sesquisharp layout props)
2580 "Draw a 3/2 sharp symbol.
2582 @lilypond[verbatim,quote]
2587 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2589 (define-markup-command (sharp layout props)
2592 "Draw a sharp symbol.
2594 @lilypond[verbatim,quote]
2599 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2601 (define-markup-command (semisharp layout props)
2604 "Draw a semisharp symbol.
2606 @lilypond[verbatim,quote]
2611 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2613 (define-markup-command (natural layout props)
2616 "Draw a natural symbol.
2618 @lilypond[verbatim,quote]
2623 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2625 (define-markup-command (semiflat layout props)
2628 "Draw a semiflat symbol.
2630 @lilypond[verbatim,quote]
2635 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2637 (define-markup-command (flat layout props)
2640 "Draw a flat symbol.
2642 @lilypond[verbatim,quote]
2647 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2649 (define-markup-command (sesquiflat layout props)
2652 "Draw a 3/2 flat symbol.
2654 @lilypond[verbatim,quote]
2659 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2661 (define-markup-command (doubleflat layout props)
2664 "Draw a double flat symbol.
2666 @lilypond[verbatim,quote]
2671 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2673 (define-markup-command (with-color layout props color arg)
2677 @cindex coloring text
2679 Draw @var{arg} in color specified by @var{color}.
2681 @lilypond[verbatim,quote]
2693 (let ((stil (interpret-markup layout props arg)))
2694 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2695 (ly:stencil-extent stil X)
2696 (ly:stencil-extent stil Y))))
2698 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2700 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2702 (define-markup-command (arrow-head layout props axis dir filled)
2703 (integer? ly:dir? boolean?)
2705 "Produce an arrow head in specified direction and axis.
2706 Use the filled head if @var{filled} is specified.
2707 @lilypond[verbatim,quote]
2710 \\general-align #Y #DOWN {
2711 \\arrow-head #Y #UP ##t
2712 \\arrow-head #Y #DOWN ##f
2714 \\arrow-head #X #RIGHT ##f
2715 \\arrow-head #X #LEFT ##f
2721 ((name (format #f "arrowheads.~a.~a~a"
2728 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2732 (define-markup-command (lookup layout props glyph-name)
2735 "Lookup a glyph by name.
2737 @lilypond[verbatim,quote]
2739 \\override #'(font-encoding . fetaBraces) {
2740 \\lookup #\"brace200\"
2743 \\lookup #\"brace180\"
2747 (ly:font-get-glyph (ly:paper-get-font layout props)
2750 (define-markup-command (char layout props num)
2753 "Produce a single character. Characters encoded in hexadecimal
2754 format require the prefix @code{#x}.
2756 @lilypond[verbatim,quote]
2758 \\char #65 \\char ##x00a9
2761 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2763 (define number->mark-letter-vector (make-vector 25 #\A))
2768 (if (= i (- (char->integer #\I) (char->integer #\A)))
2770 (vector-set! number->mark-letter-vector j
2771 (integer->char (+ i (char->integer #\A)))))
2773 (define number->mark-alphabet-vector (list->vector
2774 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2776 (define (number->markletter-string vec n)
2777 "Double letters for big marks."
2778 (let* ((lst (vector-length vec)))
2781 (string-append (number->markletter-string vec (1- (quotient n lst)))
2782 (number->markletter-string vec (remainder n lst)))
2783 (make-string 1 (vector-ref vec n)))))
2785 (define-markup-command (markletter layout props num)
2788 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2789 (skipping letter@tie{}I), and continue with double letters.
2791 @lilypond[verbatim,quote]
2798 (ly:text-interface::interpret-markup layout props
2799 (number->markletter-string number->mark-letter-vector num)))
2801 (define-markup-command (markalphabet layout props num)
2804 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2805 and continue with double letters.
2807 @lilypond[verbatim,quote]
2814 (ly:text-interface::interpret-markup layout props
2815 (number->markletter-string number->mark-alphabet-vector num)))
2817 (define-public (horizontal-slash-interval num forward number-interval mag)
2819 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2820 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2821 (else (interval-widen number-interval (* mag 0.25))))
2822 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2823 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2824 (else (interval-widen number-interval (* mag 0.25))))
2827 (define-public (adjust-slash-stencil num forward stencil mag)
2830 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2832 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2834 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2836 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2839 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2841 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2846 (define (slashed-digit-internal layout props num forward font-size thickness)
2847 (let* ((mag (magstep font-size))
2849 (ly:output-def-lookup layout 'line-thickness)
2851 ; backward slashes might use slope and point in the other direction!
2852 (dy (* mag (if forward 0.4 -0.4)))
2853 (number-stencil (interpret-markup layout
2854 (prepend-alist-chain 'font-encoding 'fetaText props)
2855 (number->string num)))
2856 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2857 (center (interval-center (ly:stencil-extent number-stencil Y)))
2858 ; Use the real extents of the slash, not the whole number, because we
2859 ; might translate the slash later on!
2860 (num-y (interval-widen (cons center center) (abs dy)))
2861 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2862 (slash-stencil (if is-sane
2863 (make-line-stencil thickness
2864 (car num-x) (- (interval-center num-y) dy)
2865 (cdr num-x) (+ (interval-center num-y) dy))
2867 (if (ly:stencil? slash-stencil)
2869 ; for some numbers we need to shift the slash/backslash up or down to make
2870 ; the slashed digit look better
2871 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2872 (set! number-stencil
2873 (ly:stencil-add number-stencil slash-stencil)))
2874 (ly:warning "Unable to create slashed digit ~a" num))
2878 (define-markup-command (slashed-digit layout props num)
2881 #:properties ((font-size 0)
2884 @cindex slashed digits
2886 A feta number, with slash. This is for use in the context of
2887 figured bass notation.
2888 @lilypond[verbatim,quote]
2892 \\override #'(thickness . 3)
2896 (slashed-digit-internal layout props num #t font-size thickness))
2898 (define-markup-command (backslashed-digit layout props num)
2901 #:properties ((font-size 0)
2904 @cindex backslashed digits
2906 A feta number, with backslash. This is for use in the context of
2907 figured bass notation.
2908 @lilypond[verbatim,quote]
2910 \\backslashed-digit #5
2912 \\override #'(thickness . 3)
2913 \\backslashed-digit #7
2916 (slashed-digit-internal layout props num #f font-size thickness))
2919 (define eyeglassespath
2920 '((moveto 0.42 0.77)
2921 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2922 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2923 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2924 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2927 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2928 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2929 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2930 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2932 (moveto 1.025 0.935)
2933 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2934 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2937 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2940 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2942 (define-markup-command (eyeglasses layout props)
2945 "Prints out eyeglasses, indicating strongly to look at the conductor.
2946 @lilypond[verbatim,quote]
2947 \\markup { \\eyeglasses }
2949 (interpret-markup layout props
2950 (make-override-markup '(line-cap-style . butt)
2951 (make-path-markup 0.15 eyeglassespath))))
2953 (define-markup-command (left-brace layout props size)
2957 A feta brace in point size @var{size}.
2959 @lilypond[verbatim,quote]
2966 (let* ((font (ly:paper-get-font layout
2967 (cons '((font-encoding . fetaBraces)
2970 (glyph-count (1- (ly:otf-glyph-count font)))
2971 (scale (ly:output-def-lookup layout 'output-scale))
2972 (scaled-size (/ (ly:pt size) scale))
2974 (ly:font-get-glyph font (string-append "brace"
2975 (number->string n)))))
2976 (get-y-from-brace (lambda (brace)
2978 (ly:stencil-extent (glyph brace) Y))))
2979 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2980 (glyph-found (glyph find-brace)))
2982 (if (or (null? (ly:stencil-expr glyph-found))
2983 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2984 (> scaled-size (interval-length
2985 (ly:stencil-extent (glyph glyph-count) Y))))
2987 (ly:warning (_ "no brace found for point size ~S ") size)
2988 (ly:warning (_ "defaulting to ~S pt")
2989 (/ (* scale (interval-length
2990 (ly:stencil-extent glyph-found Y)))
2994 (define-markup-command (right-brace layout props size)
2998 A feta brace in point size @var{size}, rotated 180 degrees.
3000 @lilypond[verbatim,quote]
3007 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3010 ;; the note command.
3011 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3013 ;; TODO: better syntax.
3015 (define-markup-command (note-by-number layout props log dot-count dir)
3016 (number? number? number?)
3018 #:properties ((font-size 0)
3021 @cindex notes within text by log and dot-count
3023 Construct a note symbol, with stem. By using fractional values for
3024 @var{dir}, longer or shorter stems can be obtained.
3026 @lilypond[verbatim,quote]
3028 \\note-by-number #3 #0 #DOWN
3030 \\note-by-number #1 #2 #0.8
3033 (define (get-glyph-name-candidates dir log style)
3034 (map (lambda (dir-name)
3035 (format #f "noteheads.~a~a" dir-name
3036 (if (and (symbol? style)
3037 (not (equal? 'default style)))
3038 (select-head-glyph style (min log 2))
3040 (list (if (= dir UP) "u" "d")
3043 (define (get-glyph-name font cands)
3046 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3047 (get-glyph-name font (cdr cands))
3050 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3052 (size-factor (magstep font-size))
3053 (stem-length (* size-factor (max 3 (- log 1))))
3055 (let ((result (get-glyph-name font (get-glyph-name-candidates
3056 (sign dir) log style))))
3057 (if (string-null? result)
3058 ;; If no glyph name can be found, select default heads. Though
3059 ;; this usually means an unsupported style has been chosen, it
3060 ;; also prevents unrelated 'style settings from other grobs
3061 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3062 (get-glyph-name font (get-glyph-name-candidates
3063 (sign dir) log 'default))
3065 (head-glyph (ly:font-get-glyph font head-glyph-name))
3066 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3067 (stem-thickness (* size-factor 0.13))
3068 (stemy (* dir stem-length))
3069 (attach-off (cons (interval-index
3070 (ly:stencil-extent head-glyph X)
3071 (* (sign dir) (car attach-indices)))
3072 (* (sign dir) ; fixme, this is inconsistent between X & Y.
3074 (ly:stencil-extent head-glyph Y)
3075 (cdr attach-indices)))))
3076 (stem-glyph (and (> log 0)
3077 (ly:round-filled-box
3078 (ordered-cons (car attach-off)
3080 (* (- (sign dir)) stem-thickness)))
3081 (cons (min stemy (cdr attach-off))
3082 (max stemy (cdr attach-off)))
3083 (/ stem-thickness 3))))
3085 (dot (ly:font-get-glyph font "dots.dot"))
3086 (dotwid (interval-length (ly:stencil-extent dot X)))
3087 (dots (and (> dot-count 0)
3088 (apply ly:stencil-add
3090 (ly:stencil-translate-axis
3091 dot (* 2 x dotwid) X))
3092 (iota dot-count)))))
3093 (flaggl (and (> log 2)
3094 (ly:stencil-translate
3095 (ly:font-get-glyph font
3096 (string-append "flags."
3097 (if (> dir 0) "u" "d")
3098 (number->string log)))
3099 (cons (+ (car attach-off) (if (< dir 0)
3103 ;; If there is a flag on an upstem and the stem is short, move the dots
3104 ;; to avoid the flag. 16th notes get a special case because their flags
3105 ;; hang lower than any other flags.
3106 (if (and dots (> dir 0) (> log 2)
3107 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3108 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3110 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3111 (if (ly:stencil? stem-glyph)
3112 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3113 (set! stem-glyph head-glyph))
3114 (if (ly:stencil? dots)
3117 (ly:stencil-translate-axis
3119 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3125 (let ((divisor (log 2)))
3126 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3128 (define (parse-simple-duration duration-string)
3129 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3130 and return a (log dots) list."
3131 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3133 (if (and match (string=? duration-string (match:substring match 0)))
3134 (let ((len (match:substring match 1))
3135 (dots (match:substring match 2)))
3136 (list (cond ((string=? len "breve") -1)
3137 ((string=? len "longa") -2)
3138 ((string=? len "maxima") -3)
3139 (else (log2 (string->number len))))
3140 (if dots (string-length dots) 0)))
3141 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3143 (define-markup-command (note layout props duration dir)
3146 #:properties (note-by-number-markup)
3148 @cindex notes within text by string
3150 This produces a note with a stem pointing in @var{dir} direction, with
3151 the @var{duration} for the note head type and augmentation dots. For
3152 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3153 a shortened down stem.
3155 @lilypond[verbatim,quote]
3157 \\override #'(style . cross) {
3161 \\note #\"breve\" #0
3164 (let ((parsed (parse-simple-duration duration)))
3165 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3167 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3171 (define-markup-command (lower layout props amount arg)
3175 @cindex lowering text
3177 Lower @var{arg} by the distance @var{amount}.
3178 A negative @var{amount} indicates raising; see also @code{\\raise}.
3180 @lilypond[verbatim,quote]
3188 (ly:stencil-translate-axis (interpret-markup layout props arg)
3191 (define-markup-command (translate-scaled layout props offset arg)
3192 (number-pair? markup?)
3194 #:properties ((font-size 0))
3196 @cindex translating text
3197 @cindex scaling text
3199 Translate @var{arg} by @var{offset}, scaling the offset by the
3202 @lilypond[verbatim,quote]
3205 * \\translate #'(2 . 3) translate
3207 * \\translate-scaled #'(2 . 3) translate-scaled
3211 (let* ((factor (magstep font-size))
3212 (scaled (cons (* factor (car offset))
3213 (* factor (cdr offset)))))
3214 (ly:stencil-translate (interpret-markup layout props arg)
3217 (define-markup-command (raise layout props amount arg)
3221 @cindex raising text
3223 Raise @var{arg} by the distance @var{amount}.
3224 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3226 The argument to @code{\\raise} is the vertical displacement amount,
3227 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3228 raise objects in relation to their surrounding markups.
3230 If the text object itself is positioned above or below the staff, then
3231 @code{\\raise} cannot be used to move it, since the mechanism that
3232 positions it next to the staff cancels any shift made with
3233 @code{\\raise}. For vertical positioning, use the @code{padding}
3234 and/or @code{extra-offset} properties.
3236 @lilypond[verbatim,quote]
3245 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3247 (define-markup-command (fraction layout props arg1 arg2)
3250 #:properties ((font-size 0))
3252 @cindex creating text fractions
3254 Make a fraction of two markups.
3255 @lilypond[verbatim,quote]
3261 (let* ((m1 (interpret-markup layout props arg1))
3262 (m2 (interpret-markup layout props arg2))
3263 (factor (magstep font-size))
3264 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3265 (padding (* factor 0.2))
3266 (baseline (* factor 0.6))
3267 (offset (* factor 0.75)))
3268 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3269 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3270 (let* ((x1 (ly:stencil-extent m1 X))
3271 (x2 (ly:stencil-extent m2 X))
3272 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3273 ;; should stack mols separately, to maintain LINE on baseline
3274 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3276 (ly:stencil-aligned-to stack Y CENTER))
3278 (ly:stencil-aligned-to stack X LEFT))
3279 ;; should have EX dimension
3281 (ly:stencil-translate-axis stack offset Y))))
3283 (define-markup-command (normal-size-super layout props arg)
3286 #:properties ((baseline-skip))
3288 @cindex setting superscript in standard font size
3290 Set @var{arg} in superscript with a normal font size.
3292 @lilypond[verbatim,quote]
3295 \\normal-size-super {
3296 superscript in standard size
3300 (ly:stencil-translate-axis
3301 (interpret-markup layout props arg)
3302 (* 0.5 baseline-skip) Y))
3304 (define-markup-command (super layout props arg)
3307 #:properties ((font-size 0)
3310 @cindex superscript text
3312 Set @var{arg} in superscript.
3314 @lilypond[verbatim,quote]
3324 (ly:stencil-translate-axis
3327 (cons `((font-size . ,(- font-size 3))) props)
3329 (* 0.5 baseline-skip)
3332 (define-markup-command (translate layout props offset arg)
3333 (number-pair? markup?)
3336 @cindex translating text
3338 Translate @var{arg} relative to its surroundings. @var{offset}
3339 is a pair of numbers representing the displacement in the X and Y axis.
3341 @lilypond[verbatim,quote]
3344 \\translate #'(2 . 3)
3345 \\line { translated two spaces right, three up }
3348 (ly:stencil-translate (interpret-markup layout props arg)
3351 (define-markup-command (sub layout props arg)
3354 #:properties ((font-size 0)
3357 @cindex subscript text
3359 Set @var{arg} in subscript.
3361 @lilypond[verbatim,quote]
3372 (ly:stencil-translate-axis
3375 (cons `((font-size . ,(- font-size 3))) props)
3377 (* -0.5 baseline-skip)
3380 (define-markup-command (normal-size-sub layout props arg)
3383 #:properties ((baseline-skip))
3385 @cindex setting subscript in standard font size
3387 Set @var{arg} in subscript with a normal font size.
3389 @lilypond[verbatim,quote]
3393 subscript in standard size
3397 (ly:stencil-translate-axis
3398 (interpret-markup layout props arg)
3399 (* -0.5 baseline-skip)
3402 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3404 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3406 (define-markup-command (hbracket layout props arg)
3410 @cindex placing horizontal brackets around text
3412 Draw horizontal brackets around @var{arg}.
3414 @lilypond[verbatim,quote]
3423 (let ((th 0.1) ;; todo: take from GROB.
3424 (m (interpret-markup layout props arg)))
3425 (bracketify-stencil m X th (* 2.5 th) th)))
3427 (define-markup-command (bracket layout props arg)
3431 @cindex placing vertical brackets around text
3433 Draw vertical brackets around @var{arg}.
3435 @lilypond[verbatim,quote]
3442 (let ((th 0.1) ;; todo: take from GROB.
3443 (m (interpret-markup layout props arg)))
3444 (bracketify-stencil m Y th (* 2.5 th) th)))
3446 (define-markup-command (parenthesize layout props arg)
3449 #:properties ((angularity 0)
3455 @cindex placing parentheses around text
3457 Draw parentheses around @var{arg}. This is useful for parenthesizing
3458 a column containing several lines of text.
3460 @lilypond[verbatim,quote]
3469 \\override #'(angularity . 2) {
3480 (let* ((markup (interpret-markup layout props arg))
3481 (scaled-width (* size width))
3483 (* (chain-assoc-get 'line-thickness props 0.1)
3486 (min (* size 0.5 scaled-thickness)
3487 (* (/ 4 3.0) scaled-width)))
3488 (padding (chain-assoc-get 'padding props half-thickness)))
3489 (parenthesize-stencil
3490 markup half-thickness scaled-width angularity padding)))
3493 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3494 ;; Delayed markup evaluation
3495 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3497 (define-markup-command (page-ref layout props label gauge default)
3498 (symbol? markup? markup?)
3501 @cindex referencing page numbers in text
3503 Reference to a page number. @var{label} is the label set on the referenced
3504 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3505 the maximum width of the page number, and @var{default} the value to display
3506 when @var{label} is not found."
3507 (let* ((gauge-stencil (interpret-markup layout props gauge))
3508 (x-ext (ly:stencil-extent gauge-stencil X))
3509 (y-ext (ly:stencil-extent gauge-stencil Y)))
3511 `(delay-stencil-evaluation
3512 ,(delay (ly:stencil-expr
3513 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3514 (page-number (if (list? table)
3515 (assoc-get label table)
3517 (page-markup (if page-number (format #f "~a" page-number) default))
3518 (page-stencil (interpret-markup layout props page-markup))
3519 (gap (- (interval-length x-ext)
3520 (interval-length (ly:stencil-extent page-stencil X)))))
3521 (interpret-markup layout props
3522 (markup #:concat (#:hspace gap page-markup)))))))
3526 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3528 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3530 (define-markup-command (scale layout props factor-pair arg)
3531 (number-pair? markup?)
3534 @cindex scaling markup
3535 @cindex mirroring markup
3537 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3538 representing the scaling-factor in the X and Y axes.
3539 Negative values may be used to produce mirror images.
3541 @lilypond[verbatim,quote]
3551 (let ((stil (interpret-markup layout props arg))
3552 (sx (car factor-pair))
3553 (sy (cdr factor-pair)))
3554 (ly:stencil-scale stil sx sy)))
3556 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3558 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3560 (define-markup-command (pattern layout props count axis space pattern)
3561 (integer? integer? number? markup?)
3564 Prints @var{count} times a @var{pattern} markup.
3565 Patterns are spaced apart by @var{space}.
3566 Patterns are distributed on @var{axis}.
3568 @lilypond[verbatim, quote]
3570 \"Horizontally repeated :\"
3571 \\pattern #7 #X #2 \\flat
3573 \"Vertically repeated :\"
3574 \\pattern #3 #Y #0.5 \\flat
3577 (let ((pattern-width (interval-length
3578 (ly:stencil-extent (interpret-markup layout props pattern) X)))
3579 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3580 (let loop ((i (1- count)) (patterns (markup)))
3586 (markup patterns pattern)
3587 (markup #:column (patterns pattern))))
3590 (markup patterns pattern #:hspace space)
3591 (markup #:column (patterns pattern #:vspace space))))))))
3593 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3594 (number? ly:dir? markup? markup? markup?)
3596 #:properties ((word-space)
3599 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3600 with a line of markups @var{pattern} in between.
3601 Patterns are spaced apart by @var{space}.
3602 Patterns are aligned to the @var{dir} markup.
3604 @lilypond[verbatim, quote]
3607 \\fill-with-pattern #1 #RIGHT . first right
3608 \\fill-with-pattern #1 #RIGHT . second right
3610 \"center-aligned :\"
3611 \\fill-with-pattern #1.5 #CENTER - left right
3614 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left first
3615 \\override #'(line-width . 50) \\fill-with-pattern #2 #LEFT : left second
3618 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3619 (pattern-width (interval-length pattern-x-extent))
3620 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3621 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3622 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
3623 (period (+ space pattern-width))
3624 (count (truncate (/ (- middle-width pattern-width) period)))
3625 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3626 (interpret-markup layout props
3628 #:with-dimensions (cons 0 middle-width) '(0 . 0)
3629 #:translate (cons x-offset 0)
3630 #:pattern (1+ count) X space pattern
3633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3634 ;; Markup list commands
3635 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3637 (define-public (space-lines baseline stils)
3638 (let space-stil ((stils stils)
3642 (let* ((stil (car stils))
3643 (dy-top (max (- (/ baseline 1.5)
3644 (interval-bound (ly:stencil-extent stil Y) UP))
3646 (dy-bottom (max (+ (/ baseline 3.0)
3647 (interval-bound (ly:stencil-extent stil Y) DOWN))
3649 (new-stil (ly:make-stencil
3650 (ly:stencil-expr stil)
3651 (ly:stencil-extent stil X)
3652 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3654 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3656 (space-stil (cdr stils) (cons new-stil result))))))
3658 (define-markup-list-command (justified-lines layout props args)
3660 #:properties ((baseline-skip)
3661 wordwrap-internal-markup-list)
3663 @cindex justifying lines of text
3665 Like @code{\\justify}, but return a list of lines instead of a single markup.
3666 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3667 @var{X}@tie{}is the number of staff spaces."
3668 (space-lines baseline-skip
3669 (interpret-markup-list layout props
3670 (make-wordwrap-internal-markup-list #t args))))
3672 (define-markup-list-command (wordwrap-lines layout props args)
3674 #:properties ((baseline-skip)
3675 wordwrap-internal-markup-list)
3676 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3677 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3678 where @var{X} is the number of staff spaces."
3679 (space-lines baseline-skip
3680 (interpret-markup-list layout props
3681 (make-wordwrap-internal-markup-list #f args))))
3683 (define-markup-list-command (column-lines layout props args)
3685 #:properties ((baseline-skip))
3686 "Like @code{\\column}, but return a list of lines instead of a single markup.
3687 @code{baseline-skip} determines the space between each markup in @var{args}."
3688 (space-lines baseline-skip
3689 (interpret-markup-list layout props args)))
3691 (define-markup-list-command (override-lines layout props new-prop args)
3692 (pair? markup-list?)
3693 "Like @code{\\override}, for markup lists."
3694 (interpret-markup-list layout (cons (list new-prop) props) args))