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
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\" {
301 \\italic { This links to the page containing the label... }
305 (let* ((arg-stencil (interpret-markup layout props arg))
306 (x-ext (ly:stencil-extent arg-stencil X))
307 (y-ext (ly:stencil-extent arg-stencil Y)))
309 `(delay-stencil-evaluation
310 ,(delay (ly:stencil-expr
311 (let* ((table (ly:output-def-lookup layout 'label-page-table))
312 (page-number (if (list? table)
313 (assoc-get label table)
315 (link-expr (list 'page-link page-number
316 `(quote ,x-ext) `(quote ,y-ext))))
317 (ly:stencil-add (ly:make-stencil link-expr x-ext y-ext)
323 (define-markup-command (beam layout props width slope thickness)
324 (number? number? number?)
327 @cindex drawing beams within text
329 Create a beam with the specified parameters.
330 @lilypond[verbatim,quote]
335 (let* ((y (* slope width))
336 (yext (cons (min 0 y) (max 0 y)))
337 (half (/ thickness 2)))
342 width (+ (* width slope) (/ thickness -2))
343 width (+ (* width slope) (/ thickness 2))
345 ,(ly:output-def-lookup layout 'blot-diameter)
348 (cons (+ (- half) (car yext))
349 (+ half (cdr yext))))))
351 (define-markup-command (underline layout props arg)
354 #:properties ((thickness 1) (offset 2))
356 @cindex underlining text
358 Underline @var{arg}. Looks at @code{thickness} to determine line
359 thickness, and @code{offset} to determine line y-offset.
361 @lilypond[verbatim,quote]
362 \\markup \\fill-line {
363 \\underline \"underlined\"
364 \\override #'(offset . 5)
365 \\override #'(thickness . 1)
366 \\underline \"underlined\"
367 \\override #'(offset . 1)
368 \\override #'(thickness . 5)
369 \\underline \"underlined\"
372 (let* ((thick (ly:output-def-lookup layout 'line-thickness))
373 (underline-thick (* thickness thick))
374 (markup (interpret-markup layout props arg))
375 (x1 (car (ly:stencil-extent markup X)))
376 (x2 (cdr (ly:stencil-extent markup X)))
377 (y (* thick (- offset)))
378 (line (make-line-stencil underline-thick x1 y x2 y)))
379 (ly:stencil-add markup line)))
381 (define-markup-command (box layout props arg)
384 #:properties ((thickness 1)
388 @cindex enclosing text within a box
390 Draw a box round @var{arg}. Looks at @code{thickness},
391 @code{box-padding} and @code{font-size} properties to determine line
392 thickness and padding around the markup.
394 @lilypond[verbatim,quote]
396 \\override #'(box-padding . 0.5)
401 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
403 (pad (* (magstep font-size) box-padding))
404 (m (interpret-markup layout props arg)))
405 (box-stencil m th pad)))
407 (define-markup-command (filled-box layout props xext yext blot)
408 (number-pair? number-pair? number?)
411 @cindex drawing solid boxes within text
412 @cindex drawing boxes with rounded corners
414 Draw a box with rounded corners of dimensions @var{xext} and
415 @var{yext}. For example,
417 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
419 creates a box extending horizontally from -0.3 to 1.8 and
420 vertically from -0.3 up to 1.8, with corners formed from a
421 circle of diameter@tie{}0 (i.e., sharp corners).
423 @lilypond[verbatim,quote]
425 \\filled-box #'(0 . 4) #'(0 . 4) #0
426 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
427 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
429 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
435 (define-markup-command (rounded-box layout props arg)
438 #:properties ((thickness 1)
442 "@cindex enclosing text in a box with rounded corners
443 @cindex drawing boxes with rounded corners around text
444 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
445 @code{box-padding} and @code{font-size} properties to determine line
446 thickness and padding around the markup; the @code{corner-radius} property
447 makes it possible to define another shape for the corners (default is 1).
449 @lilypond[quote,verbatim,relative=2]
457 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
459 (pad (* (magstep font-size) box-padding))
460 (m (interpret-markup layout props arg)))
461 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
464 (define-markup-command (rotate layout props ang arg)
468 @cindex rotating text
470 Rotate object with @var{ang} degrees around its center.
472 @lilypond[verbatim,quote]
482 (let* ((stil (interpret-markup layout props arg)))
483 (ly:stencil-rotate stil ang 0 0)))
485 (define-markup-command (whiteout layout props arg)
489 @cindex adding a white background to text
491 Provide a white background for @var{arg}.
493 @lilypond[verbatim,quote]
496 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
500 (stencil-whiteout (interpret-markup layout props arg)))
502 (define-markup-command (pad-markup layout props amount arg)
507 @cindex putting space around text
509 Add space around a markup object.
511 @lilypond[verbatim,quote]
525 ((stil (interpret-markup layout props arg))
526 (xext (ly:stencil-extent stil X))
527 (yext (ly:stencil-extent stil Y)))
530 (ly:stencil-expr stil)
531 (interval-widen xext amount)
532 (interval-widen yext amount))))
534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
536 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
538 (define-markup-command (strut layout props)
542 @cindex creating vertical spaces in text
544 Create a box of the same height as the space in the current font."
545 (let ((m (ly:text-interface::interpret-markup layout props " ")))
546 (ly:make-stencil (ly:stencil-expr m)
548 (ly:stencil-extent m X)
551 ;; todo: fix negative space
552 (define-markup-command (hspace layout props amount)
555 #:properties ((word-space))
557 @cindex creating horizontal spaces in text
559 Create an invisible object taking up horizontal space @var{amount}.
561 @lilypond[verbatim,quote]
570 (let ((corrected-space (- amount word-space)))
571 (if (> corrected-space 0)
572 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
573 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
575 ;; todo: fix negative space
576 (define-markup-command (vspace layout props amount)
580 @cindex creating vertical spaces in text
582 Create an invisible object taking up vertical space
583 of @var{amount} multiplied by 3.
585 @lilypond[verbatim,quote]
596 (let ((amount (* amount 3.0)))
598 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
599 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603 ;; importing graphics.
604 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
606 (define-markup-command (stencil layout props stil)
610 @cindex importing stencils into text
612 Use a stencil as markup.
614 @lilypond[verbatim,quote]
616 \\stencil #(make-circle-stencil 2 0 #t)
622 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
624 (define (get-postscript-bbox string)
625 "Extract the bbox from STRING, or return #f if not present."
627 ((match (regexp-exec bbox-regexp string)))
631 (string->number (match:substring match x)))
636 (define-markup-command (epsfile layout props axis size file-name)
637 (number? number? string?)
640 @cindex inlining an Encapsulated PostScript image
642 Inline an EPS image. The image is scaled along @var{axis} to
645 @lilypond[verbatim,quote]
647 \\general-align #Y #DOWN {
648 \\epsfile #X #20 #\"context-example.eps\"
649 \\epsfile #Y #20 #\"context-example.eps\"
653 (if (ly:get-option 'safe)
654 (interpret-markup layout props "not allowed in safe")
655 (eps-file->stencil axis size file-name)
658 (define-markup-command (postscript layout props str)
662 @cindex inserting PostScript directly into text
663 This inserts @var{str} directly into the output as a PostScript
666 @lilypond[verbatim,quote]
670 0.4 0.6 0.5 0 361 arc
672 1.0 0.6 0.5 0 361 arc
677 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
678 \\postscript #ringsps
690 gsave currentpoint translate
698 (define-markup-command (path layout props thickness commands) (number? list?)
700 #:properties ((line-cap-style 'round)
701 (line-join-style 'round)
704 @cindex paths, drawing
705 @cindex drawing paths
706 Draws a path with line thickness @var{thickness} according to the
707 directions given in @var{commands}. @var{commands} is a list of
708 lists where the @code{car} of each sublist is a drawing command and
709 the @code{cdr} comprises the associated arguments for each command.
711 Line-cap styles and line-join styles may be customized by
712 overriding the @code{line-cap-style} and @code{line-join-style}
713 properties, respectively. Available line-cap styles are
714 @code{'butt}, @code{'round}, and @code{'square}. Available
715 line-join styles are @code{'miter}, @code{'round}, and
718 The property @code{filled} specifies whether or not the path is
721 There are seven commands available to use in the list
722 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
723 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
724 @code{closepath}. Note that the commands that begin with @emph{r}
725 are the relative variants of the other three commands.
727 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
728 @code{rlineto} take 2 arguments; they are the X and Y coordinates
729 for the destination point.
731 The commands @code{curveto} and @code{rcurveto} create cubic
732 Bézier curves, and take 6 arguments; the first two are the X and Y
733 coordinates for the first control point, the second two are the X
734 and Y coordinates for the second control point, and the last two
735 are the X and Y coordinates for the destination point.
737 The @code{closepath} command takes zero arguments and closes the
738 current subpath in the active path.
740 Note that a sequence of commands @emph{must} begin with a
741 @code{moveto} or @code{rmoveto} to work with the SVG output.
743 @lilypond[verbatim,quote]
749 (curveto -5 -5 -5 5 -1 0)
753 \\path #0.25 #samplePath
756 (let* ((half-thickness (/ thickness 2))
757 (current-point '(0 . 0))
758 (set-point (lambda (lst) (set! current-point lst)))
759 (relative? (lambda (x)
760 (string-prefix? "r" (symbol->string (car x)))))
761 ;; For calculating extents, we want to modify the command
762 ;; list so that all coordinates are absolute.
763 (new-commands (map (lambda (x)
765 ;; for rmoveto, rlineto
766 ((and (relative? x) (eq? 3 (length x)))
768 (+ (car current-point)
770 (+ (cdr current-point)
776 ((and (relative? x) (eq? 7 (length x)))
777 (let* ((old-cp current-point)
784 (list (+ (car old-cp) (second x))
785 (+ (cdr old-cp) (third x))
786 (+ (car old-cp) (fourth x))
787 (+ (cdr old-cp) (fifth x))
790 ;; for moveto, lineto
792 (set-point (cons (second x)
797 (set-point (cons (sixth x)
800 ;; keep closepath for filtering;
801 ;; see `without-closepath'.
804 ;; path-min-max does not accept 0-arg lists,
805 ;; and since closepath does not affect extents, filter
806 ;; out those commands here.
807 (without-closepath (filter (lambda (x)
808 (not (equal? 'closepath (car x))))
810 (extents (path-min-max
811 ;; set the origin to the first moveto
812 (list (list-ref (car without-closepath) 0)
813 (list-ref (car without-closepath) 1))
815 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
816 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
817 (command-list (fold-right append '() commands)))
819 ;; account for line thickness
820 (set! X-extent (interval-widen X-extent half-thickness))
821 (set! Y-extent (interval-widen Y-extent half-thickness))
824 `(path ,thickness `(,@',command-list)
825 ',line-cap-style ',line-join-style ,filled)
829 (define-markup-command (score layout props score)
832 #:properties ((baseline-skip))
834 @cindex inserting music into text
836 Inline an image of music.
838 @lilypond[verbatim,quote]
842 \\new Staff \\relative c' {
845 \\mark \\markup { Allegro }
851 \\new Staff \\relative c {
865 \\override RehearsalMark
866 #'break-align-symbols = #'(time-signature key-signature)
867 \\override RehearsalMark
868 #'self-alignment-X = #LEFT
872 \\override TimeSignature
873 #'break-align-anchor-alignment = #LEFT
879 (let ((output (ly:score-embedded-format score layout)))
881 (if (ly:music-output? output)
882 (stack-stencils Y DOWN baseline-skip
883 (map paper-system-stencil
885 (ly:paper-score-paper-systems output))))
887 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
890 (define-markup-command (null layout props)
894 @cindex creating empty text objects
896 An empty markup with extents of a single point.
898 @lilypond[verbatim,quote]
905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
907 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
909 (define-markup-command (simple layout props str)
913 @cindex simple text strings
915 A simple text string; @code{\\markup @{ foo @}} is equivalent with
916 @code{\\markup @{ \\simple #\"foo\" @}}.
918 Note: for creating standard text markup or defining new markup commands,
919 the use of @code{\\simple} is unnecessary.
921 @lilypond[verbatim,quote]
925 \\simple #\"strings\"
928 (interpret-markup layout props str))
930 (define-markup-command (tied-lyric layout props str)
933 #:properties ((word-space))
935 @cindex simple text strings with tie characters
937 Like simple-markup, but use tie characters for @q{~} tilde symbols.
939 @lilypond[verbatim,quote]
941 \\tied-lyric #\"Lasciate~i monti\"
944 (if (string-contains str "~")
946 ((half-space (/ word-space 2))
947 (parts (string-split str #\~))
948 (tie-str (markup #:hspace half-space
949 #:musicglyph "ties.lyric"
950 #:hspace half-space))
951 (joined (list-join parts tie-str))
952 (join-stencil (interpret-markup layout props tie-str))
955 (interpret-markup layout
957 (make-concat-markup joined)))
958 (interpret-markup layout props str)))
960 (define-public empty-markup
961 (make-simple-markup ""))
963 ;; helper for justifying lines.
964 (define (get-fill-space word-count line-width word-space text-widths)
965 "Calculate the necessary paddings between each two adjacent texts.
966 The lengths of all texts are stored in @var{text-widths}.
967 The normal formula for the padding between texts a and b is:
968 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
969 The first and last padding have to be calculated specially using the
970 whole length of the first or last text.
971 All paddings are checked to be at least word-space, to ensure that
973 Return a list of paddings."
975 ((null? text-widths) '())
977 ;; special case first padding
978 ((= (length text-widths) word-count)
980 (- (- (/ line-width (1- word-count)) (car text-widths))
981 (/ (car (cdr text-widths)) 2))
982 (get-fill-space word-count line-width word-space (cdr text-widths))))
983 ;; special case last padding
984 ((= (length text-widths) 2)
985 (list (- (/ line-width (1- word-count))
986 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
988 (let ((default-padding
989 (- (/ line-width (1- word-count))
990 (/ (+ (car text-widths) (car (cdr text-widths))) 2))))
992 (if (> word-space default-padding)
995 (get-fill-space word-count line-width word-space (cdr text-widths)))))))
997 (define-markup-command (fill-line layout props args)
1000 #:properties ((text-direction RIGHT)
1003 "Put @var{markups} in a horizontal line of width @var{line-width}.
1004 The markups are spaced or flushed to fill the entire line.
1005 If there are no arguments, return an empty stencil.
1007 @lilypond[verbatim,quote]
1011 Words evenly spaced across the page
1015 \\line { Text markups }
1017 \\italic { evenly spaced }
1019 \\line { across the page }
1024 (let* ((orig-stencils (interpret-markup-list layout props args))
1027 (if (ly:stencil-empty? stc)
1029 stc)) orig-stencils))
1032 (if (ly:stencil-empty? stc)
1034 (interval-length (ly:stencil-extent stc X))))
1036 (text-width (apply + text-widths))
1037 (word-count (length stencils))
1038 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
1043 (/ (- line-width text-width) 2)
1044 (/ (- line-width text-width) 2)))
1047 (- line-width text-width)))
1049 (get-fill-space word-count line-width word-space text-widths))))
1051 (line-contents (if (= word-count 1)
1058 (if (null? (remove ly:stencil-empty? orig-stencils))
1061 (if (= text-direction LEFT)
1062 (set! line-contents (reverse line-contents)))
1064 (stack-stencils-padding-list
1065 X RIGHT fill-space line-contents))
1066 (if (> word-count 1)
1067 ;; shift s.t. stencils align on the left edge, even if
1068 ;; first stencil had negative X-extent (e.g. center-column)
1069 ;; (if word-count = 1, X-extents are already normalized in
1070 ;; the definition of line-contents)
1072 (ly:stencil-translate-axis
1074 (- (car (ly:stencil-extent (car stencils) X)))
1078 (define-markup-command (line layout props args)
1081 #:properties ((word-space)
1082 (text-direction RIGHT))
1083 "Put @var{args} in a horizontal line. The property @code{word-space}
1084 determines the space between markups in @var{args}.
1086 @lilypond[verbatim,quote]
1093 (let ((stencils (interpret-markup-list layout props args)))
1094 (if (= text-direction LEFT)
1095 (set! stencils (reverse stencils)))
1098 (remove ly:stencil-empty? stencils))))
1100 (define-markup-command (concat layout props args)
1104 @cindex concatenating text
1105 @cindex ligatures in text
1107 Concatenate @var{args} in a horizontal line, without spaces in between.
1108 Strings and simple markups are concatenated on the input level, allowing
1109 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1110 equivalent to @code{\"fi\"}.
1112 @lilypond[verbatim,quote]
1121 (define (concat-string-args arg-list)
1122 (fold-right (lambda (arg result-list)
1123 (let ((result (if (pair? result-list)
1126 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1127 (set! arg (cadr arg)))
1128 (if (and (string? result) (string? arg))
1129 (cons (string-append arg result) (cdr result-list))
1130 (cons arg result-list))))
1134 (interpret-markup layout
1135 (prepend-alist-chain 'word-space 0 props)
1136 (make-line-markup (if (markup-command-list? args)
1138 (concat-string-args args)))))
1140 (define (wordwrap-stencils stencils
1141 justify base-space line-width text-dir)
1142 "Perform simple wordwrap, return stencil of each line."
1143 (define space (if justify
1144 ;; justify only stretches lines.
1147 (define (take-list width space stencils
1148 accumulator accumulated-width)
1149 "Return (head-list . tail) pair, with head-list fitting into width"
1150 (if (null? stencils)
1151 (cons accumulator stencils)
1152 (let* ((first (car stencils))
1153 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1154 (newwid (+ space first-wid accumulated-width)))
1155 (if (or (null? accumulator)
1157 (take-list width space
1159 (cons first accumulator)
1161 (cons accumulator stencils)))))
1162 (let loop ((lines '())
1164 (let* ((line-break (take-list line-width space todo
1166 (line-stencils (car line-break))
1167 (space-left (- line-width
1168 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1170 (line-word-space (cond ((not justify) space)
1171 ;; don't stretch last line of paragraph.
1172 ;; hmmm . bug - will overstretch the last line in some case.
1173 ((null? (cdr line-break))
1175 ((null? line-stencils) 0.0)
1176 ((null? (cdr line-stencils)) 0.0)
1177 (else (/ space-left (1- (length line-stencils))))))
1178 (line (stack-stencil-line line-word-space
1179 (if (= text-dir RIGHT)
1180 (reverse line-stencils)
1182 (if (pair? (cdr line-break))
1183 (loop (cons line lines)
1186 (if (= text-dir LEFT)
1188 (ly:stencil-translate-axis
1190 (- line-width (interval-end (ly:stencil-extent line X)))
1192 (reverse (cons line lines)))))))
1194 (define-markup-list-command (wordwrap-internal layout props justify args)
1195 (boolean? markup-list?)
1196 #:properties ((line-width #f)
1198 (text-direction RIGHT))
1199 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1200 (wordwrap-stencils (remove ly:stencil-empty?
1201 (interpret-markup-list layout props args))
1205 (ly:output-def-lookup layout 'line-width))
1208 (define-markup-command (justify layout props args)
1211 #:properties ((baseline-skip)
1212 wordwrap-internal-markup-list)
1214 @cindex justifying text
1216 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1217 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1218 @var{X}@tie{}is the number of staff spaces.
1220 @lilypond[verbatim,quote]
1223 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1224 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1225 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1226 laboris nisi ut aliquip ex ea commodo consequat.
1230 (stack-lines DOWN 0.0 baseline-skip
1231 (wordwrap-internal-markup-list layout props #t args)))
1233 (define-markup-command (wordwrap layout props args)
1236 #:properties ((baseline-skip)
1237 wordwrap-internal-markup-list)
1238 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1239 the line width, where @var{X} is the number of staff spaces.
1241 @lilypond[verbatim,quote]
1244 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1245 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1246 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1247 laboris nisi ut aliquip ex ea commodo consequat.
1251 (stack-lines DOWN 0.0 baseline-skip
1252 (wordwrap-internal-markup-list layout props #f args)))
1254 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1256 #:properties ((line-width)
1258 (text-direction RIGHT))
1259 "Internal markup list command used to define @code{\\justify-string} and
1260 @code{\\wordwrap-string}."
1261 (let* ((para-strings (regexp-split
1262 (string-regexp-substitute
1264 (string-regexp-substitute "\r\n" "\n" arg))
1265 "\n[ \t\n]*\n[ \t\n]*"))
1266 (list-para-words (map (lambda (str)
1267 (regexp-split str "[ \t\n]+"))
1269 (para-lines (map (lambda (words)
1271 (remove ly:stencil-empty?
1273 (interpret-markup layout props x))
1275 (wordwrap-stencils stencils
1277 line-width text-direction)))
1279 (apply append para-lines)))
1281 (define-markup-command (wordwrap-string layout props arg)
1284 #:properties ((baseline-skip)
1285 wordwrap-string-internal-markup-list)
1286 "Wordwrap a string. Paragraphs may be separated with double newlines.
1288 @lilypond[verbatim,quote]
1290 \\override #'(line-width . 40)
1291 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1292 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1293 et dolore magna aliqua.
1296 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1297 laboris nisi ut aliquip ex ea commodo consequat.
1300 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1301 qui officia deserunt mollit anim id est laborum\"
1304 (stack-lines DOWN 0.0 baseline-skip
1305 (wordwrap-string-internal-markup-list layout props #f arg)))
1307 (define-markup-command (justify-string layout props arg)
1310 #:properties ((baseline-skip)
1311 wordwrap-string-internal-markup-list)
1312 "Justify a string. Paragraphs may be separated with double newlines
1314 @lilypond[verbatim,quote]
1316 \\override #'(line-width . 40)
1317 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1318 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1319 et dolore magna aliqua.
1322 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1323 laboris nisi ut aliquip ex ea commodo consequat.
1326 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1327 qui officia deserunt mollit anim id est laborum\"
1330 (stack-lines DOWN 0.0 baseline-skip
1331 (wordwrap-string-internal-markup-list layout props #t arg)))
1333 (define-markup-command (wordwrap-field layout props symbol)
1336 "Wordwrap the data which has been assigned to @var{symbol}.
1338 @lilypond[verbatim,quote]
1340 title = \"My title\"
1341 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1342 elit, sed do eiusmod tempor incididunt ut labore et dolore
1343 magna aliqua. Ut enim ad minim veniam, quis nostrud
1344 exercitation ullamco laboris nisi ut aliquip ex ea commodo
1349 bookTitleMarkup = \\markup {
1351 \\fill-line { \\fromproperty #'header:title }
1353 \\wordwrap-field #'header:myText
1362 (let* ((m (chain-assoc-get symbol props)))
1364 (wordwrap-string-markup layout props m)
1367 (define-markup-command (justify-field layout props symbol)
1370 "Justify the data which has been assigned to @var{symbol}.
1372 @lilypond[verbatim,quote]
1374 title = \"My title\"
1375 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1376 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1377 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1378 laboris nisi ut aliquip ex ea commodo consequat.\"
1382 bookTitleMarkup = \\markup {
1384 \\fill-line { \\fromproperty #'header:title }
1386 \\justify-field #'header:myText
1395 (let* ((m (chain-assoc-get symbol props)))
1397 (justify-string-markup layout props m)
1400 (define-markup-command (combine layout props arg1 arg2)
1404 @cindex merging text
1406 Print two markups on top of each other.
1408 Note: @code{\\combine} cannot take a list of markups enclosed in
1409 curly braces as an argument; the follow example will not compile:
1412 \\combine @{ a list @}
1415 @lilypond[verbatim,quote]
1418 \\override #'(thickness . 2)
1420 \\draw-line #'(0 . 4)
1421 \\arrow-head #Y #DOWN ##f
1424 (let* ((s1 (interpret-markup layout props arg1))
1425 (s2 (interpret-markup layout props arg2)))
1426 (ly:stencil-add s1 s2)))
1429 ;; TODO: should extract baseline-skip from each argument somehow..
1431 (define-markup-command (column layout props args)
1434 #:properties ((baseline-skip))
1436 @cindex stacking text in a column
1438 Stack the markups in @var{args} vertically. The property
1439 @code{baseline-skip} determines the space between markups
1442 @lilypond[verbatim,quote]
1451 (let ((arg-stencils (interpret-markup-list layout props args)))
1452 (stack-lines -1 0.0 baseline-skip
1453 (remove ly:stencil-empty? arg-stencils))))
1455 (define-markup-command (dir-column layout props args)
1458 #:properties ((direction)
1461 @cindex changing direction of text columns
1463 Make a column of @var{args}, going up or down, depending on the
1464 setting of the @code{direction} layout property.
1466 @lilypond[verbatim,quote]
1468 \\override #`(direction . ,UP) {
1478 \\override #'(direction . 1) {
1485 (stack-lines (if (number? direction) direction -1)
1488 (interpret-markup-list layout props args)))
1490 (define (general-column align-dir baseline mols)
1491 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1493 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols))
1494 (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
1495 (stacked-extent (ly:stencil-extent stacked-stencil X)))
1496 (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X )))
1498 (define-markup-command (center-column layout props args)
1501 #:properties ((baseline-skip))
1503 @cindex centering a column of text
1505 Put @code{args} in a centered column.
1507 @lilypond[verbatim,quote]
1516 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1518 (define-markup-command (left-column layout props args)
1521 #:properties ((baseline-skip))
1523 @cindex text columns, left-aligned
1525 Put @code{args} in a left-aligned column.
1527 @lilypond[verbatim,quote]
1536 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1538 (define-markup-command (right-column layout props args)
1541 #:properties ((baseline-skip))
1543 @cindex text columns, right-aligned
1545 Put @code{args} in a right-aligned column.
1547 @lilypond[verbatim,quote]
1556 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1558 (define-markup-command (vcenter layout props arg)
1562 @cindex vertically centering text
1564 Align @code{arg} to its Y@tie{}center.
1566 @lilypond[verbatim,quote]
1574 (let* ((mol (interpret-markup layout props arg)))
1575 (ly:stencil-aligned-to mol Y CENTER)))
1577 (define-markup-command (center-align layout props arg)
1581 @cindex horizontally centering text
1583 Align @code{arg} to its X@tie{}center.
1585 @lilypond[verbatim,quote]
1595 (let* ((mol (interpret-markup layout props arg)))
1596 (ly:stencil-aligned-to mol X CENTER)))
1598 (define-markup-command (right-align layout props arg)
1602 @cindex right aligning text
1604 Align @var{arg} on its right edge.
1606 @lilypond[verbatim,quote]
1616 (let* ((m (interpret-markup layout props arg)))
1617 (ly:stencil-aligned-to m X RIGHT)))
1619 (define-markup-command (left-align layout props arg)
1623 @cindex left aligning text
1625 Align @var{arg} on its left edge.
1627 @lilypond[verbatim,quote]
1637 (let* ((m (interpret-markup layout props arg)))
1638 (ly:stencil-aligned-to m X LEFT)))
1640 (define-markup-command (general-align layout props axis dir arg)
1641 (integer? number? markup?)
1644 @cindex controlling general text alignment
1646 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1648 @lilypond[verbatim,quote]
1652 \\general-align #X #LEFT
1657 \\general-align #X #CENTER
1663 \\general-align #Y #UP
1670 \\general-align #Y #3.2
1677 (let* ((m (interpret-markup layout props arg)))
1678 (ly:stencil-aligned-to m axis dir)))
1680 (define-markup-command (halign layout props dir arg)
1684 @cindex setting horizontal text alignment
1686 Set horizontal alignment. If @var{dir} is @w{@code{-1}}, then it is
1687 left-aligned, while @code{+1} is right. Values in between interpolate
1688 alignment accordingly.
1690 @lilypond[verbatim,quote]
1715 (let* ((m (interpret-markup layout props arg)))
1716 (ly:stencil-aligned-to m X dir)))
1718 (define-markup-command (with-dimensions layout props x y arg)
1719 (number-pair? number-pair? markup?)
1722 @cindex setting extent of text objects
1724 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1725 (let* ((m (interpret-markup layout props arg)))
1726 (ly:make-stencil (ly:stencil-expr m) x y)))
1728 (define-markup-command (pad-around layout props amount arg)
1731 "Add padding @var{amount} all around @var{arg}.
1733 @lilypond[verbatim,quote]
1746 (let* ((m (interpret-markup layout props arg))
1747 (x (ly:stencil-extent m X))
1748 (y (ly:stencil-extent m Y)))
1749 (ly:make-stencil (ly:stencil-expr m)
1750 (interval-widen x amount)
1751 (interval-widen y amount))))
1753 (define-markup-command (pad-x layout props amount arg)
1757 @cindex padding text horizontally
1759 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1761 @lilypond[verbatim,quote]
1774 (let* ((m (interpret-markup layout props arg))
1775 (x (ly:stencil-extent m X))
1776 (y (ly:stencil-extent m Y)))
1777 (ly:make-stencil (ly:stencil-expr m)
1778 (interval-widen x amount)
1781 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1782 (integer? ly:dir? markup? markup?)
1784 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1785 (let ((m1 (interpret-markup layout props arg1))
1786 (m2 (interpret-markup layout props arg2)))
1787 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1789 (define-markup-command (transparent layout props arg)
1792 "Make @var{arg} transparent.
1794 @lilypond[verbatim,quote]
1801 (let* ((m (interpret-markup layout props arg))
1802 (x (ly:stencil-extent m X))
1803 (y (ly:stencil-extent m Y)))
1804 (ly:make-stencil "" x y)))
1806 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1807 (number-pair? number-pair? markup?)
1809 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1811 @lilypond[verbatim,quote]
1818 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1824 (let* ((m (interpret-markup layout props arg))
1825 (x (ly:stencil-extent m X))
1826 (y (ly:stencil-extent m Y)))
1827 (ly:make-stencil (ly:stencil-expr m)
1828 (interval-union x-ext x)
1829 (interval-union y-ext y))))
1831 (define-markup-command (hcenter-in layout props length arg)
1834 "Center @var{arg} horizontally within a box of extending
1835 @var{length}/2 to the left and right.
1837 @lilypond[quote,verbatim]
1840 \\set Staff.instrumentName = \\markup {
1847 \\set Staff.instrumentName = \\markup {
1856 (interpret-markup layout props
1857 (make-pad-to-box-markup
1858 (cons (/ length -2) (/ length 2))
1860 (make-center-align-markup arg))))
1862 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1864 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1866 (define-markup-command (fromproperty layout props symbol)
1869 "Read the @var{symbol} from property settings, and produce a stencil
1870 from the markup contained within. If @var{symbol} is not defined, it
1871 returns an empty markup.
1873 @lilypond[verbatim,quote]
1875 myTitle = \"myTitle\"
1879 \\fromproperty #'header:myTitle
1886 (let ((m (chain-assoc-get symbol props)))
1888 (interpret-markup layout props m)
1891 (define-markup-command (on-the-fly layout props procedure arg)
1894 "Apply the @var{procedure} markup command to @var{arg}.
1895 @var{procedure} should take a single argument."
1896 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1897 (set-object-property! anonymous-with-signature
1900 (interpret-markup layout props (list anonymous-with-signature arg))))
1902 (define-markup-command (footnote layout props mkup note)
1905 #:properties ((raise 0.5)
1907 "Have footnote @var{note} act as an annotation to the markup @var{mkup}.
1909 @lilypond[verbatim,quote]
1912 \\override #'(padding . 0.2)
1916 (let* ((markup-stencil (interpret-markup layout props mkup))
1917 (auto-numbering (ly:output-def-lookup layout
1918 'footnote-auto-numbering))
1919 (footnote-hash (gensym "footnote"))
1921 (gauge-stencil (if auto-numbering
1925 ((ly:output-def-lookup
1927 'footnote-numbering-function)
1930 (x-ext (if auto-numbering
1931 (ly:stencil-extent gauge-stencil X)
1933 (y-ext (if auto-numbering
1934 (ly:stencil-extent gauge-stencil Y)
1938 `(delay-stencil-evaluation
1942 (ly:output-def-lookup layout
1943 'number-footnote-table))
1944 (footnote-stencil (if (list? table)
1945 (assoc-get footnote-hash
1948 (footnote-stencil (if (ly:stencil? footnote-stencil)
1951 (ly:programming-error
1952 "Cannot find correct footnote for a markup object.")
1954 (gap (- (interval-length x-ext)
1956 (ly:stencil-extent footnote-stencil X))))
1957 (y-trans (- (+ (cdr y-ext)
1959 (cdr (ly:stencil-extent footnote-stencil
1961 (ly:stencil-translate footnote-stencil
1962 (cons gap y-trans))))))
1964 (main-stencil (ly:stencil-combine-at-edge
1968 (ly:make-stencil footnote-number x-ext y-ext)
1973 `(footnote ,footnote-hash ,(interpret-markup layout props note))
1977 (define-markup-command (override layout props new-prop arg)
1981 @cindex overriding properties within text markup
1983 Add the argument @var{new-prop} to the property list. Properties
1984 may be any property supported by @rinternals{font-interface},
1985 @rinternals{text-interface} and
1986 @rinternals{instrument-specific-markup-interface}.
1988 @lilypond[verbatim,quote]
1996 \\override #'(baseline-skip . 4) {
2005 (interpret-markup layout (cons (list new-prop) props) arg))
2007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2011 (define-markup-command (verbatim-file layout props name)
2014 "Read the contents of file @var{name}, and include it verbatim.
2016 @lilypond[verbatim,quote]
2018 \\verbatim-file #\"simple.ly\"
2021 (interpret-markup layout props
2022 (if (ly:get-option 'safe)
2023 "verbatim-file disabled in safe mode"
2024 (let* ((str (ly:gulp-file name))
2025 (lines (string-split str #\nl)))
2026 (make-typewriter-markup
2027 (make-column-markup lines))))))
2029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034 (define-markup-command (smaller layout props arg)
2037 "Decrease the font size relative to the current setting.
2039 @lilypond[verbatim,quote]
2052 (interpret-markup layout props
2053 `(,fontsize-markup -1 ,arg)))
2055 (define-markup-command (larger layout props arg)
2058 "Increase the font size relative to the current setting.
2060 @lilypond[verbatim,quote]
2068 (interpret-markup layout props
2069 `(,fontsize-markup 1 ,arg)))
2071 (define-markup-command (finger layout props arg)
2074 "Set @var{arg} as small numbers.
2076 @lilypond[verbatim,quote]
2083 (interpret-markup layout
2084 (cons '((font-size . -5) (font-encoding . fetaText)) props)
2087 (define-markup-command (abs-fontsize layout props size arg)
2090 "Use @var{size} as the absolute font size to display @var{arg}.
2091 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
2093 @lilypond[verbatim,quote]
2095 default text font size
2097 \\abs-fontsize #16 { text font size 16 }
2099 \\abs-fontsize #12 { text font size 12 }
2102 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
2103 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
2104 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
2105 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
2106 (magnification (/ size ref-size)))
2107 (interpret-markup layout
2108 (cons `((baseline-skip . ,(* magnification ref-baseline))
2109 (word-space . ,(* magnification ref-word-space))
2110 (font-size . ,(magnification->font-size magnification)))
2114 (define-markup-command (fontsize layout props increment arg)
2117 #:properties ((font-size 0)
2120 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
2123 @lilypond[verbatim,quote]
2131 (let ((entries (list
2132 (cons 'baseline-skip (* baseline-skip (magstep increment)))
2133 (cons 'word-space (* word-space (magstep increment)))
2134 (cons 'font-size (+ font-size increment)))))
2135 (interpret-markup layout (cons entries props) arg)))
2137 (define-markup-command (magnify layout props sz arg)
2141 @cindex magnifying text
2143 Set the font magnification for its argument. In the following
2144 example, the middle@tie{}A is 10% larger:
2147 A \\magnify #1.1 @{ A @} A
2150 Note: Magnification only works if a font name is explicitly selected.
2151 Use @code{\\fontsize} otherwise.
2153 @lilypond[verbatim,quote]
2164 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2167 (define-markup-command (bold layout props arg)
2170 "Switch to bold font-series.
2172 @lilypond[verbatim,quote]
2180 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2182 (define-markup-command (sans layout props arg)
2185 "Switch to the sans serif font family.
2187 @lilypond[verbatim,quote]
2196 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2198 (define-markup-command (number layout props arg)
2201 "Set font family to @code{number}, which yields the font used for
2202 time signatures and fingerings. This font contains numbers and
2203 some punctuation; it has no letters.
2205 @lilypond[verbatim,quote]
2208 0 1 2 3 4 5 6 7 8 9 . ,
2212 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2214 (define-markup-command (roman layout props arg)
2217 "Set font family to @code{roman}.
2219 @lilypond[verbatim,quote]
2225 text in roman font family
2232 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2234 (define-markup-command (huge layout props arg)
2237 "Set font size to +2.
2239 @lilypond[verbatim,quote]
2247 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2249 (define-markup-command (large layout props arg)
2252 "Set font size to +1.
2254 @lilypond[verbatim,quote]
2262 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2264 (define-markup-command (normalsize layout props arg)
2267 "Set font size to default.
2269 @lilypond[verbatim,quote]
2282 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2284 (define-markup-command (small layout props arg)
2287 "Set font size to -1.
2289 @lilypond[verbatim,quote]
2297 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2299 (define-markup-command (tiny layout props arg)
2302 "Set font size to -2.
2304 @lilypond[verbatim,quote]
2312 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2314 (define-markup-command (teeny layout props arg)
2317 "Set font size to -3.
2319 @lilypond[verbatim,quote]
2327 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2329 (define-markup-command (fontCaps layout props arg)
2332 "Set @code{font-shape} to @code{caps}
2334 Note: @code{\\fontCaps} requires the installation and selection of
2335 fonts which support the @code{caps} font shape."
2336 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2339 (define-markup-command (smallCaps layout props arg)
2342 "Emit @var{arg} as small caps.
2344 Note: @code{\\smallCaps} does not support accented characters.
2346 @lilypond[verbatim,quote]
2355 (define (char-list->markup chars lower)
2356 (let ((final-string (string-upcase (reverse-list->string chars))))
2358 (markup #:fontsize -2 final-string)
2360 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2361 (if (null? rest-chars)
2363 (reverse! (cons (char-list->markup currents current-is-lower)
2365 (let* ((ch (car rest-chars))
2366 (is-lower (char-lower-case? ch)))
2367 (if (or (and current-is-lower is-lower)
2368 (and (not current-is-lower) (not is-lower)))
2369 (make-small-caps (cdr rest-chars)
2373 (make-small-caps (cdr rest-chars)
2376 (if (null? currents)
2378 (cons (char-list->markup
2379 currents current-is-lower)
2381 (interpret-markup layout props
2383 (make-small-caps (string->list arg) (list) #f (list))
2386 (define-markup-command (caps layout props arg)
2389 "Copy of the @code{\\smallCaps} command.
2391 @lilypond[verbatim,quote]
2400 (interpret-markup layout props (make-smallCaps-markup arg)))
2402 (define-markup-command (dynamic layout props arg)
2405 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2406 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2407 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2408 done in a different font. The recommended font for this is bold and italic.
2409 @lilypond[verbatim,quote]
2417 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2419 (define-markup-command (text layout props arg)
2422 "Use a text font instead of music symbol or music alphabet font.
2424 @lilypond[verbatim,quote]
2437 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2440 (define-markup-command (italic layout props arg)
2443 "Use italic @code{font-shape} for @var{arg}.
2445 @lilypond[verbatim,quote]
2453 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2455 (define-markup-command (typewriter layout props arg)
2458 "Use @code{font-family} typewriter for @var{arg}.
2460 @lilypond[verbatim,quote]
2469 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2471 (define-markup-command (upright layout props arg)
2474 "Set @code{font-shape} to @code{upright}. This is the opposite
2477 @lilypond[verbatim,quote]
2491 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2493 (define-markup-command (medium layout props arg)
2496 "Switch to medium font-series (in contrast to bold).
2498 @lilypond[verbatim,quote]
2511 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2514 (define-markup-command (normal-text layout props arg)
2517 "Set all font related properties (except the size) to get the default
2518 normal text font, no matter what font was used earlier.
2520 @lilypond[verbatim,quote]
2522 \\huge \\bold \\sans \\caps {
2534 (interpret-markup layout
2535 (cons '((font-family . roman) (font-shape . upright)
2536 (font-series . medium) (font-encoding . latin1))
2540 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2542 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2544 (define-markup-command (musicglyph layout props glyph-name)
2547 "@var{glyph-name} is converted to a musical symbol; for example,
2548 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2549 the music font. See @ruser{The Feta font} for a complete listing of
2550 the possible glyphs.
2552 @lilypond[verbatim,quote]
2555 \\musicglyph #\"rests.2\"
2556 \\musicglyph #\"clefs.G_change\"
2559 (let* ((font (ly:paper-get-font layout
2560 (cons '((font-encoding . fetaMusic)
2564 (glyph (ly:font-get-glyph font glyph-name)))
2565 (if (null? (ly:stencil-expr glyph))
2566 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2570 (define-markup-command (doublesharp layout props)
2573 "Draw a double sharp symbol.
2575 @lilypond[verbatim,quote]
2580 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2582 (define-markup-command (sesquisharp layout props)
2585 "Draw a 3/2 sharp symbol.
2587 @lilypond[verbatim,quote]
2592 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2594 (define-markup-command (sharp layout props)
2597 "Draw a sharp symbol.
2599 @lilypond[verbatim,quote]
2604 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2606 (define-markup-command (semisharp layout props)
2609 "Draw a semisharp symbol.
2611 @lilypond[verbatim,quote]
2616 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2618 (define-markup-command (natural layout props)
2621 "Draw a natural symbol.
2623 @lilypond[verbatim,quote]
2628 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2630 (define-markup-command (semiflat layout props)
2633 "Draw a semiflat symbol.
2635 @lilypond[verbatim,quote]
2640 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2642 (define-markup-command (flat layout props)
2645 "Draw a flat symbol.
2647 @lilypond[verbatim,quote]
2652 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2654 (define-markup-command (sesquiflat layout props)
2657 "Draw a 3/2 flat symbol.
2659 @lilypond[verbatim,quote]
2664 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2666 (define-markup-command (doubleflat layout props)
2669 "Draw a double flat symbol.
2671 @lilypond[verbatim,quote]
2676 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2678 (define-markup-command (with-color layout props color arg)
2682 @cindex coloring text
2684 Draw @var{arg} in color specified by @var{color}.
2686 @lilypond[verbatim,quote]
2698 (let ((stil (interpret-markup layout props arg)))
2699 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2700 (ly:stencil-extent stil X)
2701 (ly:stencil-extent stil Y))))
2703 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2705 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2707 (define-markup-command (arrow-head layout props axis dir filled)
2708 (integer? ly:dir? boolean?)
2710 "Produce an arrow head in specified direction and axis.
2711 Use the filled head if @var{filled} is specified.
2712 @lilypond[verbatim,quote]
2715 \\general-align #Y #DOWN {
2716 \\arrow-head #Y #UP ##t
2717 \\arrow-head #Y #DOWN ##f
2719 \\arrow-head #X #RIGHT ##f
2720 \\arrow-head #X #LEFT ##f
2726 ((name (format #f "arrowheads.~a.~a~a"
2733 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2737 (define-markup-command (lookup layout props glyph-name)
2740 "Lookup a glyph by name.
2742 @lilypond[verbatim,quote]
2744 \\override #'(font-encoding . fetaBraces) {
2745 \\lookup #\"brace200\"
2748 \\lookup #\"brace180\"
2752 (ly:font-get-glyph (ly:paper-get-font layout props)
2755 (define-markup-command (char layout props num)
2758 "Produce a single character. Characters encoded in hexadecimal
2759 format require the prefix @code{#x}.
2761 @lilypond[verbatim,quote]
2763 \\char #65 \\char ##x00a9
2766 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2768 (define number->mark-letter-vector (make-vector 25 #\A))
2773 (if (= i (- (char->integer #\I) (char->integer #\A)))
2775 (vector-set! number->mark-letter-vector j
2776 (integer->char (+ i (char->integer #\A)))))
2778 (define number->mark-alphabet-vector (list->vector
2779 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2781 (define (number->markletter-string vec n)
2782 "Double letters for big marks."
2783 (let* ((lst (vector-length vec)))
2786 (string-append (number->markletter-string vec (1- (quotient n lst)))
2787 (number->markletter-string vec (remainder n lst)))
2788 (make-string 1 (vector-ref vec n)))))
2790 (define-markup-command (markletter layout props num)
2793 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2794 (skipping letter@tie{}I), and continue with double letters.
2796 @lilypond[verbatim,quote]
2803 (ly:text-interface::interpret-markup layout props
2804 (number->markletter-string number->mark-letter-vector num)))
2806 (define-markup-command (markalphabet layout props num)
2809 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2810 and continue with double letters.
2812 @lilypond[verbatim,quote]
2819 (ly:text-interface::interpret-markup layout props
2820 (number->markletter-string number->mark-alphabet-vector num)))
2822 (define-public (horizontal-slash-interval num forward number-interval mag)
2824 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2825 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2826 (else (interval-widen number-interval (* mag 0.25))))
2827 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2828 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2829 (else (interval-widen number-interval (* mag 0.25))))
2832 (define-public (adjust-slash-stencil num forward stencil mag)
2835 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2837 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2839 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2841 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2844 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2846 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2851 (define (slashed-digit-internal layout props num forward font-size thickness)
2852 (let* ((mag (magstep font-size))
2854 (ly:output-def-lookup layout 'line-thickness)
2856 ; backward slashes might use slope and point in the other direction!
2857 (dy (* mag (if forward 0.4 -0.4)))
2858 (number-stencil (interpret-markup layout
2859 (prepend-alist-chain 'font-encoding 'fetaText props)
2860 (number->string num)))
2861 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2862 (center (interval-center (ly:stencil-extent number-stencil Y)))
2863 ; Use the real extents of the slash, not the whole number, because we
2864 ; might translate the slash later on!
2865 (num-y (interval-widen (cons center center) (abs dy)))
2866 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2867 (slash-stencil (if is-sane
2868 (make-line-stencil thickness
2869 (car num-x) (- (interval-center num-y) dy)
2870 (cdr num-x) (+ (interval-center num-y) dy))
2872 (if (ly:stencil? slash-stencil)
2874 ; for some numbers we need to shift the slash/backslash up or down to make
2875 ; the slashed digit look better
2876 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2877 (set! number-stencil
2878 (ly:stencil-add number-stencil slash-stencil)))
2879 (ly:warning "Unable to create slashed digit ~a" num))
2883 (define-markup-command (slashed-digit layout props num)
2886 #:properties ((font-size 0)
2889 @cindex slashed digits
2891 A feta number, with slash. This is for use in the context of
2892 figured bass notation.
2893 @lilypond[verbatim,quote]
2897 \\override #'(thickness . 3)
2901 (slashed-digit-internal layout props num #t font-size thickness))
2903 (define-markup-command (backslashed-digit layout props num)
2906 #:properties ((font-size 0)
2909 @cindex backslashed digits
2911 A feta number, with backslash. This is for use in the context of
2912 figured bass notation.
2913 @lilypond[verbatim,quote]
2915 \\backslashed-digit #5
2917 \\override #'(thickness . 3)
2918 \\backslashed-digit #7
2921 (slashed-digit-internal layout props num #f font-size thickness))
2924 (define eyeglassespath
2925 '((moveto 0.42 0.77)
2926 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2927 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2928 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2929 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2932 (rcurveto 0 0.304 -0.246 0.55 -0.55 0.55)
2933 (rcurveto -0.304 0 -0.55 -0.246 -0.55 -0.55)
2934 (rcurveto 0 -0.304 0.246 -0.55 0.55 -0.55)
2935 (rcurveto 0.304 0 0.55 0.246 0.55 0.55)
2937 (moveto 1.025 0.935)
2938 (rcurveto 0 0.182 -0.148 0.33 -0.33 0.33)
2939 (rcurveto -0.182 0 -0.33 -0.148 -0.33 -0.33)
2942 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)
2945 (rcurveto 0.132 0.286 0.55 0.44 0.385 -0.33)))
2947 (define-markup-command (eyeglasses layout props)
2950 "Prints out eyeglasses, indicating strongly to look at the conductor.
2951 @lilypond[verbatim,quote]
2952 \\markup { \\eyeglasses }
2954 (interpret-markup layout props
2955 (make-override-markup '(line-cap-style . butt)
2956 (make-path-markup 0.15 eyeglassespath))))
2958 (define-markup-command (left-brace layout props size)
2962 A feta brace in point size @var{size}.
2964 @lilypond[verbatim,quote]
2971 (let* ((font (ly:paper-get-font layout
2972 (cons '((font-encoding . fetaBraces)
2975 (glyph-count (1- (ly:otf-glyph-count font)))
2976 (scale (ly:output-def-lookup layout 'output-scale))
2977 (scaled-size (/ (ly:pt size) scale))
2979 (ly:font-get-glyph font (string-append "brace"
2980 (number->string n)))))
2981 (get-y-from-brace (lambda (brace)
2983 (ly:stencil-extent (glyph brace) Y))))
2984 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2985 (glyph-found (glyph find-brace)))
2987 (if (or (null? (ly:stencil-expr glyph-found))
2988 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2989 (> scaled-size (interval-length
2990 (ly:stencil-extent (glyph glyph-count) Y))))
2992 (ly:warning (_ "no brace found for point size ~S ") size)
2993 (ly:warning (_ "defaulting to ~S pt")
2994 (/ (* scale (interval-length
2995 (ly:stencil-extent glyph-found Y)))
2999 (define-markup-command (right-brace layout props size)
3003 A feta brace in point size @var{size}, rotated 180 degrees.
3005 @lilypond[verbatim,quote]
3012 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
3014 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3015 ;; the note command.
3016 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3018 ;; TODO: better syntax.
3020 (define-markup-command (note-by-number layout props log dot-count dir)
3021 (number? number? number?)
3023 #:properties ((font-size 0)
3026 @cindex notes within text by log and dot-count
3028 Construct a note symbol, with stem. By using fractional values for
3029 @var{dir}, longer or shorter stems can be obtained.
3031 @lilypond[verbatim,quote]
3033 \\note-by-number #3 #0 #DOWN
3035 \\note-by-number #1 #2 #0.8
3038 (define (get-glyph-name-candidates dir log style)
3039 (map (lambda (dir-name)
3040 (format #f "noteheads.~a~a" dir-name
3041 (if (and (symbol? style)
3042 (not (equal? 'default style)))
3043 (select-head-glyph style (min log 2))
3045 (list (if (= dir UP) "u" "d")
3048 (define (get-glyph-name font cands)
3051 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
3052 (get-glyph-name font (cdr cands))
3055 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
3057 (size-factor (magstep font-size))
3058 (stem-length (* size-factor (max 3 (- log 1))))
3060 (let ((result (get-glyph-name font (get-glyph-name-candidates
3061 (sign dir) log style))))
3062 (if (string-null? result)
3063 ;; If no glyph name can be found, select default heads. Though
3064 ;; this usually means an unsupported style has been chosen, it
3065 ;; also prevents unrelated 'style settings from other grobs
3066 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
3067 (get-glyph-name font (get-glyph-name-candidates
3068 (sign dir) log 'default))
3070 (head-glyph (ly:font-get-glyph font head-glyph-name))
3071 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
3072 (stem-thickness (* size-factor 0.13))
3073 (stemy (* dir stem-length))
3074 (attach-off (cons (interval-index
3075 (ly:stencil-extent head-glyph X)
3076 (* (sign dir) (car attach-indices)))
3077 (* (sign dir) ; fixme, this is inconsistent between X & Y.
3079 (ly:stencil-extent head-glyph Y)
3080 (cdr attach-indices)))))
3081 (stem-glyph (and (> log 0)
3082 (ly:round-filled-box
3083 (ordered-cons (car attach-off)
3085 (* (- (sign dir)) stem-thickness)))
3086 (cons (min stemy (cdr attach-off))
3087 (max stemy (cdr attach-off)))
3088 (/ stem-thickness 3))))
3090 (dot (ly:font-get-glyph font "dots.dot"))
3091 (dotwid (interval-length (ly:stencil-extent dot X)))
3092 (dots (and (> dot-count 0)
3093 (apply ly:stencil-add
3095 (ly:stencil-translate-axis
3096 dot (* 2 x dotwid) X))
3097 (iota dot-count)))))
3098 (flaggl (and (> log 2)
3099 (ly:stencil-translate
3100 (ly:font-get-glyph font
3101 (string-append "flags."
3102 (if (> dir 0) "u" "d")
3103 (number->string log)))
3104 (cons (+ (car attach-off) (if (< dir 0)
3108 ;; If there is a flag on an upstem and the stem is short, move the dots
3109 ;; to avoid the flag. 16th notes get a special case because their flags
3110 ;; hang lower than any other flags.
3111 (if (and dots (> dir 0) (> log 2)
3112 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
3113 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
3115 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
3116 (if (ly:stencil? stem-glyph)
3117 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
3118 (set! stem-glyph head-glyph))
3119 (if (ly:stencil? dots)
3122 (ly:stencil-translate-axis
3124 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
3130 (let ((divisor (log 2)))
3131 (lambda (z) (inexact->exact (/ (log z) divisor)))))
3133 (define (parse-simple-duration duration-string)
3134 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
3135 and return a (log dots) list."
3136 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
3138 (if (and match (string=? duration-string (match:substring match 0)))
3139 (let ((len (match:substring match 1))
3140 (dots (match:substring match 2)))
3141 (list (cond ((string=? len "breve") -1)
3142 ((string=? len "longa") -2)
3143 ((string=? len "maxima") -3)
3144 (else (log2 (string->number len))))
3145 (if dots (string-length dots) 0)))
3146 (ly:error (_ "not a valid duration string: ~a") duration-string))))
3148 (define-markup-command (note layout props duration dir)
3151 #:properties (note-by-number-markup)
3153 @cindex notes within text by string
3155 This produces a note with a stem pointing in @var{dir} direction, with
3156 the @var{duration} for the note head type and augmentation dots. For
3157 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
3158 a shortened down stem.
3160 @lilypond[verbatim,quote]
3162 \\override #'(style . cross) {
3166 \\note #\"breve\" #0
3169 (let ((parsed (parse-simple-duration duration)))
3170 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3174 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3176 (define-markup-command (lower layout props amount arg)
3180 @cindex lowering text
3182 Lower @var{arg} by the distance @var{amount}.
3183 A negative @var{amount} indicates raising; see also @code{\\raise}.
3185 @lilypond[verbatim,quote]
3193 (ly:stencil-translate-axis (interpret-markup layout props arg)
3196 (define-markup-command (translate-scaled layout props offset arg)
3197 (number-pair? markup?)
3199 #:properties ((font-size 0))
3201 @cindex translating text
3202 @cindex scaling text
3204 Translate @var{arg} by @var{offset}, scaling the offset by the
3207 @lilypond[verbatim,quote]
3210 * \\translate #'(2 . 3) translate
3212 * \\translate-scaled #'(2 . 3) translate-scaled
3216 (let* ((factor (magstep font-size))
3217 (scaled (cons (* factor (car offset))
3218 (* factor (cdr offset)))))
3219 (ly:stencil-translate (interpret-markup layout props arg)
3222 (define-markup-command (raise layout props amount arg)
3226 @cindex raising text
3228 Raise @var{arg} by the distance @var{amount}.
3229 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3231 The argument to @code{\\raise} is the vertical displacement amount,
3232 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3233 raise objects in relation to their surrounding markups.
3235 If the text object itself is positioned above or below the staff, then
3236 @code{\\raise} cannot be used to move it, since the mechanism that
3237 positions it next to the staff cancels any shift made with
3238 @code{\\raise}. For vertical positioning, use the @code{padding}
3239 and/or @code{extra-offset} properties.
3241 @lilypond[verbatim,quote]
3250 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3252 (define-markup-command (fraction layout props arg1 arg2)
3255 #:properties ((font-size 0))
3257 @cindex creating text fractions
3259 Make a fraction of two markups.
3260 @lilypond[verbatim,quote]
3266 (let* ((m1 (interpret-markup layout props arg1))
3267 (m2 (interpret-markup layout props arg2))
3268 (factor (magstep font-size))
3269 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3270 (padding (* factor 0.2))
3271 (baseline (* factor 0.6))
3272 (offset (* factor 0.75)))
3273 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3274 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3275 (let* ((x1 (ly:stencil-extent m1 X))
3276 (x2 (ly:stencil-extent m2 X))
3277 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3278 ;; should stack mols separately, to maintain LINE on baseline
3279 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3281 (ly:stencil-aligned-to stack Y CENTER))
3283 (ly:stencil-aligned-to stack X LEFT))
3284 ;; should have EX dimension
3286 (ly:stencil-translate-axis stack offset Y))))
3288 (define-markup-command (normal-size-super layout props arg)
3291 #:properties ((baseline-skip))
3293 @cindex setting superscript in standard font size
3295 Set @var{arg} in superscript with a normal font size.
3297 @lilypond[verbatim,quote]
3300 \\normal-size-super {
3301 superscript in standard size
3305 (ly:stencil-translate-axis
3306 (interpret-markup layout props arg)
3307 (* 0.5 baseline-skip) Y))
3309 (define-markup-command (super layout props arg)
3312 #:properties ((font-size 0)
3315 @cindex superscript text
3317 Set @var{arg} in superscript.
3319 @lilypond[verbatim,quote]
3329 (ly:stencil-translate-axis
3332 (cons `((font-size . ,(- font-size 3))) props)
3334 (* 0.5 baseline-skip)
3337 (define-markup-command (translate layout props offset arg)
3338 (number-pair? markup?)
3341 @cindex translating text
3343 Translate @var{arg} relative to its surroundings. @var{offset}
3344 is a pair of numbers representing the displacement in the X and Y axis.
3346 @lilypond[verbatim,quote]
3349 \\translate #'(2 . 3)
3350 \\line { translated two spaces right, three up }
3353 (ly:stencil-translate (interpret-markup layout props arg)
3356 (define-markup-command (sub layout props arg)
3359 #:properties ((font-size 0)
3362 @cindex subscript text
3364 Set @var{arg} in subscript.
3366 @lilypond[verbatim,quote]
3377 (ly:stencil-translate-axis
3380 (cons `((font-size . ,(- font-size 3))) props)
3382 (* -0.5 baseline-skip)
3385 (define-markup-command (normal-size-sub layout props arg)
3388 #:properties ((baseline-skip))
3390 @cindex setting subscript in standard font size
3392 Set @var{arg} in subscript with a normal font size.
3394 @lilypond[verbatim,quote]
3398 subscript in standard size
3402 (ly:stencil-translate-axis
3403 (interpret-markup layout props arg)
3404 (* -0.5 baseline-skip)
3407 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3411 (define-markup-command (hbracket layout props arg)
3415 @cindex placing horizontal brackets around text
3417 Draw horizontal brackets around @var{arg}.
3419 @lilypond[verbatim,quote]
3428 (let ((th 0.1) ;; todo: take from GROB.
3429 (m (interpret-markup layout props arg)))
3430 (bracketify-stencil m X th (* 2.5 th) th)))
3432 (define-markup-command (bracket layout props arg)
3436 @cindex placing vertical brackets around text
3438 Draw vertical brackets around @var{arg}.
3440 @lilypond[verbatim,quote]
3447 (let ((th 0.1) ;; todo: take from GROB.
3448 (m (interpret-markup layout props arg)))
3449 (bracketify-stencil m Y th (* 2.5 th) th)))
3451 (define-markup-command (parenthesize layout props arg)
3454 #:properties ((angularity 0)
3460 @cindex placing parentheses around text
3462 Draw parentheses around @var{arg}. This is useful for parenthesizing
3463 a column containing several lines of text.
3465 @lilypond[verbatim,quote]
3474 \\override #'(angularity . 2) {
3485 (let* ((markup (interpret-markup layout props arg))
3486 (scaled-width (* size width))
3488 (* (chain-assoc-get 'line-thickness props 0.1)
3491 (min (* size 0.5 scaled-thickness)
3492 (* (/ 4 3.0) scaled-width)))
3493 (padding (chain-assoc-get 'padding props half-thickness)))
3494 (parenthesize-stencil
3495 markup half-thickness scaled-width angularity padding)))
3498 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3499 ;; Delayed markup evaluation
3500 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3502 (define-markup-command (page-ref layout props label gauge default)
3503 (symbol? markup? markup?)
3506 @cindex referencing page numbers in text
3508 Reference to a page number. @var{label} is the label set on the referenced
3509 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3510 the maximum width of the page number, and @var{default} the value to display
3511 when @var{label} is not found."
3512 (let* ((gauge-stencil (interpret-markup layout props gauge))
3513 (x-ext (ly:stencil-extent gauge-stencil X))
3514 (y-ext (ly:stencil-extent gauge-stencil Y)))
3516 `(delay-stencil-evaluation
3517 ,(delay (ly:stencil-expr
3518 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3519 (page-number (if (list? table)
3520 (assoc-get label table)
3522 (page-markup (if page-number (format #f "~a" page-number) default))
3523 (page-stencil (interpret-markup layout props page-markup))
3524 (gap (- (interval-length x-ext)
3525 (interval-length (ly:stencil-extent page-stencil X)))))
3526 (interpret-markup layout props
3527 (markup #:concat (#:hspace gap page-markup)))))))
3531 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3533 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3535 (define-markup-command (scale layout props factor-pair arg)
3536 (number-pair? markup?)
3539 @cindex scaling markup
3540 @cindex mirroring markup
3542 Scale @var{arg}. @var{factor-pair} is a pair of numbers
3543 representing the scaling-factor in the X and Y axes.
3544 Negative values may be used to produce mirror images.
3546 @lilypond[verbatim,quote]
3556 (let ((stil (interpret-markup layout props arg))
3557 (sx (car factor-pair))
3558 (sy (cdr factor-pair)))
3559 (ly:stencil-scale stil sx sy)))
3561 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3563 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3565 (define-markup-command (pattern layout props count axis space pattern)
3566 (integer? integer? number? markup?)
3569 Prints @var{count} times a @var{pattern} markup.
3570 Patterns are spaced apart by @var{space}.
3571 Patterns are distributed on @var{axis}.
3573 @lilypond[verbatim, quote]
3575 \"Horizontally repeated :\"
3576 \\pattern #7 #X #2 \\flat
3578 \"Vertically repeated :\"
3579 \\pattern #3 #Y #0.5 \\flat
3582 (let ((pattern-width (interval-length
3583 (ly:stencil-extent (interpret-markup layout props pattern) X)))
3584 (new-props (prepend-alist-chain 'word-space 0 (prepend-alist-chain 'baseline-skip 0 props))))
3585 (let loop ((i (1- count)) (patterns (markup)))
3591 (markup patterns pattern)
3592 (markup #:column (patterns pattern))))
3595 (markup patterns pattern #:hspace space)
3596 (markup #:column (patterns pattern #:vspace space))))))))
3598 (define-markup-command (fill-with-pattern layout props space dir pattern left right)
3599 (number? ly:dir? markup? markup? markup?)
3601 #:properties ((word-space)
3604 Put @var{left} and @var{right} in a horizontal line of width @code{line-width}
3605 with a line of markups @var{pattern} in between.
3606 Patterns are spaced apart by @var{space}.
3607 Patterns are aligned to the @var{dir} markup.
3609 @lilypond[verbatim, quote]
3612 \\fill-with-pattern #1 #RIGHT . first right
3613 \\fill-with-pattern #1 #RIGHT . second right
3615 \"center-aligned :\"
3616 \\fill-with-pattern #1.5 #CENTER - left right
3619 \\override #'(line-width . 50)
3620 \\fill-with-pattern #2 #LEFT : left first
3621 \\override #'(line-width . 50)
3622 \\fill-with-pattern #2 #LEFT : left second
3625 (let* ((pattern-x-extent (ly:stencil-extent (interpret-markup layout props pattern) X))
3626 (pattern-width (interval-length pattern-x-extent))
3627 (left-width (interval-length (ly:stencil-extent (interpret-markup layout props left) X)))
3628 (right-width (interval-length (ly:stencil-extent (interpret-markup layout props right) X)))
3629 (middle-width (max 0 (- line-width (+ (+ left-width right-width) (* word-space 2)))))
3630 (period (+ space pattern-width))
3631 (count (truncate (/ (- middle-width pattern-width) period)))
3632 (x-offset (+ (* (- (- middle-width (* count period)) pattern-width) (/ (1+ dir) 2)) (abs (car pattern-x-extent)))))
3633 (interpret-markup layout props
3635 #:with-dimensions (cons 0 middle-width) '(0 . 0)
3636 #:translate (cons x-offset 0)
3637 #:pattern (1+ count) X space pattern
3640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3641 ;; Markup list commands
3642 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3644 (define-public (space-lines baseline stils)
3645 (let space-stil ((stils stils)
3649 (let* ((stil (car stils))
3650 (dy-top (max (- (/ baseline 1.5)
3651 (interval-bound (ly:stencil-extent stil Y) UP))
3653 (dy-bottom (max (+ (/ baseline 3.0)
3654 (interval-bound (ly:stencil-extent stil Y) DOWN))
3656 (new-stil (ly:make-stencil
3657 (ly:stencil-expr stil)
3658 (ly:stencil-extent stil X)
3659 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3661 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3663 (space-stil (cdr stils) (cons new-stil result))))))
3665 (define-markup-list-command (justified-lines layout props args)
3667 #:properties ((baseline-skip)
3668 wordwrap-internal-markup-list)
3670 @cindex justifying lines of text
3672 Like @code{\\justify}, but return a list of lines instead of a single markup.
3673 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3674 @var{X}@tie{}is the number of staff spaces."
3675 (space-lines baseline-skip
3676 (interpret-markup-list layout props
3677 (make-wordwrap-internal-markup-list #t args))))
3679 (define-markup-list-command (wordwrap-lines layout props args)
3681 #:properties ((baseline-skip)
3682 wordwrap-internal-markup-list)
3683 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3684 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3685 where @var{X} is the number of staff spaces."
3686 (space-lines baseline-skip
3687 (interpret-markup-list layout props
3688 (make-wordwrap-internal-markup-list #f args))))
3690 (define-markup-list-command (column-lines layout props args)
3692 #:properties ((baseline-skip))
3693 "Like @code{\\column}, but return a list of lines instead of a single markup.
3694 @code{baseline-skip} determines the space between each markup in @var{args}."
3695 (space-lines baseline-skip
3696 (interpret-markup-list layout props args)))
3698 (define-markup-list-command (override-lines layout props new-prop args)
3699 (pair? markup-list?)
3700 "Like @code{\\override}, for markup lists."
3701 (interpret-markup-list layout (cons (list new-prop) props) args))