1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2010 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. There are restrictions on the
49 ;;; possible arguments for a markup command.
50 ;;; First, arguments are distinguished according to their type:
51 ;;; 1) a markup (or a string), corresponding to type predicate `markup?'
52 ;;; 2) a list of markups, corresponding to type predicate `markup-list?'
53 ;;; 3) any scheme object, corresponding to type predicates such as
54 ;;; `list?', 'number?', 'boolean?', etc.
55 ;;; The supported arrangements of arguments, according to their type, are:
63 ;;; - scheme, scheme, markup
64 ;;; - scheme, scheme, markup, markup
65 ;;; - scheme, markup, markup
66 ;;; - scheme, scheme, scheme
67 ;;; This combinations are hard-coded in the lexer and in the parser
68 ;;; (lily/lexer.ll and lily/parser.yy)
71 ;;; the arguments signature, i.e. a list of type predicates which
72 ;;; are used to type check the arguments, and also to define the general
73 ;;; argument types (markup, markup-list, scheme) that the command is
75 ;;; For instance, if a command expects a number, then a markup, the
76 ;;; signature would be: (number? markup?)
79 ;;; for documentation purpose, builtin markup commands are grouped by
80 ;;; category. This can be any symbol. When documentation is generated,
81 ;;; the symbol is converted to a capitalized string, where hyphens are
82 ;;; replaced by spaces.
85 ;;; this is used both for documentation generation, and to ease
86 ;;; programming the command itself. It is list of
87 ;;; (property-name default-value)
88 ;;; or (property-name)
89 ;;; elements. Each property is looked-up in the `props' argument, and
90 ;;; the symbol naming the property is bound to its value.
91 ;;; When the property is not found in `props', then the symbol is bound
92 ;;; to the given default value. When no default value is given, #f is
94 ;;; Thus, using the following property bindings:
97 ;;; is equivalent to writing:
98 ;;; (let ((thickness (chain-assoc-get 'thickness props 0.1))
99 ;;; (font-size (chain-assoc-get 'font-size props 0)))
101 ;;; When a command `B' internally calls an other command `A', it may
102 ;;; desirable to see in `B' documentation all the properties and
103 ;;; default values used by `A'. In that case, add `A-markup' to the
104 ;;; property-bindings of B. (This is used when generating
105 ;;; documentation, but won't create bindings.)
107 ;;; documentation-string
108 ;;; the command documentation string (used to generate manuals)
111 ;;; the command body. The function is supposed to return a stencil.
113 ;;; Each markup command definition shall have a documentation string
114 ;;; with description, syntax and example.
116 (use-modules (ice-9 regex))
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
122 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
123 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
129 (define-markup-command (draw-line layout props dest)
132 #:properties ((thickness 1))
134 @cindex drawing lines within text
137 @lilypond[verbatim,quote]
139 \\draw-line #'(4 . 4)
140 \\override #'(thickness . 5)
141 \\draw-line #'(-3 . 0)
144 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
148 (make-line-stencil th 0 0 x y)))
150 (define-markup-command (draw-circle layout props radius thickness filled)
151 (number? number? boolean?)
154 @cindex drawing circles within text
156 A circle of radius @var{radius} and thickness @var{thickness},
159 @lilypond[verbatim,quote]
161 \\draw-circle #2 #0.5 ##f
163 \\draw-circle #2 #0 ##t
166 (make-circle-stencil radius thickness filled))
168 (define-markup-command (triangle layout props filled)
171 #:properties ((thickness 0.1)
175 @cindex drawing triangles within text
177 A triangle, either filled or empty.
179 @lilypond[verbatim,quote]
186 (let ((ex (* (magstep font-size) 0.8 baseline-skip)))
195 (cons 0 (* .86 ex)))))
197 (define-markup-command (circle layout props arg)
200 #:properties ((thickness 1)
202 (circle-padding 0.2))
204 @cindex circling text
206 Draw a circle around @var{arg}. Use @code{thickness},
207 @code{circle-padding} and @code{font-size} properties to determine line
208 thickness and padding around the markup.
210 @lilypond[verbatim,quote]
217 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
219 (pad (* (magstep font-size) circle-padding))
220 (m (interpret-markup layout props arg)))
221 (circle-stencil m th pad)))
223 (define-markup-command (with-url layout props url arg)
227 @cindex inserting URL links into text
229 Add a link to URL @var{url} around @var{arg}. This only works in
232 @lilypond[verbatim,quote]
234 \\with-url #\"http://lilypond.org/web/\" {
235 LilyPond ... \\italic {
236 music notation for everyone
241 (let* ((stil (interpret-markup layout props arg))
242 (xextent (ly:stencil-extent stil X))
243 (yextent (ly:stencil-extent stil Y))
244 (old-expr (ly:stencil-expr stil))
245 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
247 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
249 (define-markup-command (beam layout props width slope thickness)
250 (number? number? number?)
253 @cindex drawing beams within text
255 Create a beam with the specified parameters.
256 @lilypond[verbatim,quote]
261 (let* ((y (* slope width))
262 (yext (cons (min 0 y) (max 0 y)))
263 (half (/ thickness 2)))
268 width (+ (* width slope) (/ thickness -2))
269 width (+ (* width slope) (/ thickness 2))
271 ,(ly:output-def-lookup layout 'blot-diameter)
274 (cons (+ (- half) (car yext))
275 (+ half (cdr yext))))))
277 (define-markup-command (underline layout props arg)
280 #:properties ((thickness 1))
282 @cindex underlining text
284 Underline @var{arg}. Looks at @code{thickness} to determine line
285 thickness and y-offset.
287 @lilypond[verbatim,quote]
291 \\override #'(thickness . 2)
297 (let* ((thick (* (ly:output-def-lookup layout 'line-thickness)
299 (markup (interpret-markup layout props arg))
300 (x1 (car (ly:stencil-extent markup X)))
301 (x2 (cdr (ly:stencil-extent markup X)))
303 (line (make-line-stencil thick x1 y x2 y)))
304 (ly:stencil-add markup line)))
306 (define-markup-command (box layout props arg)
309 #:properties ((thickness 1)
313 @cindex enclosing text within a box
315 Draw a box round @var{arg}. Looks at @code{thickness},
316 @code{box-padding} and @code{font-size} properties to determine line
317 thickness and padding around the markup.
319 @lilypond[verbatim,quote]
321 \\override #'(box-padding . 0.5)
326 (let* ((th (* (ly:output-def-lookup layout 'line-thickness)
328 (pad (* (magstep font-size) box-padding))
329 (m (interpret-markup layout props arg)))
330 (box-stencil m th pad)))
332 (define-markup-command (filled-box layout props xext yext blot)
333 (number-pair? number-pair? number?)
336 @cindex drawing solid boxes within text
337 @cindex drawing boxes with rounded corners
339 Draw a box with rounded corners of dimensions @var{xext} and
340 @var{yext}. For example,
342 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
344 creates a box extending horizontally from -0.3 to 1.8 and
345 vertically from -0.3 up to 1.8, with corners formed from a
346 circle of diameter@tie{}0 (i.e., sharp corners).
348 @lilypond[verbatim,quote]
350 \\filled-box #'(0 . 4) #'(0 . 4) #0
351 \\filled-box #'(0 . 2) #'(-4 . 2) #0.4
352 \\filled-box #'(1 . 8) #'(0 . 7) #0.2
354 \\filled-box #'(-4.5 . -2.5) #'(3.5 . 5.5) #0.7
360 (define-markup-command (rounded-box layout props arg)
363 #:properties ((thickness 1)
367 "@cindex enclosing text in a box with rounded corners
368 @cindex drawing boxes with rounded corners around text
369 Draw a box with rounded corners around @var{arg}. Looks at @code{thickness},
370 @code{box-padding} and @code{font-size} properties to determine line
371 thickness and padding around the markup; the @code{corner-radius} property
372 makes it possible to define another shape for the corners (default is 1).
374 @lilypond[quote,verbatim,relative=2]
382 (let ((th (* (ly:output-def-lookup layout 'line-thickness)
384 (pad (* (magstep font-size) box-padding))
385 (m (interpret-markup layout props arg)))
386 (ly:stencil-add (rounded-box-stencil m th pad corner-radius)
389 (define-markup-command (rotate layout props ang arg)
393 @cindex rotating text
395 Rotate object with @var{ang} degrees around its center.
397 @lilypond[verbatim,quote]
407 (let* ((stil (interpret-markup layout props arg)))
408 (ly:stencil-rotate stil ang 0 0)))
410 (define-markup-command (whiteout layout props arg)
414 @cindex adding a white background to text
416 Provide a white background for @var{arg}.
418 @lilypond[verbatim,quote]
421 \\filled-box #'(-1 . 10) #'(-3 . 4) #1
425 (stencil-whiteout (interpret-markup layout props arg)))
427 (define-markup-command (pad-markup layout props amount arg)
432 @cindex putting space around text
434 Add space around a markup object.
436 @lilypond[verbatim,quote]
450 ((stil (interpret-markup layout props arg))
451 (xext (ly:stencil-extent stil X))
452 (yext (ly:stencil-extent stil Y)))
455 (ly:stencil-expr stil)
456 (interval-widen xext amount)
457 (interval-widen yext amount))))
459 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
463 (define-markup-command (strut layout props)
467 @cindex creating vertical spaces in text
469 Create a box of the same height as the space in the current font."
470 (let ((m (ly:text-interface::interpret-markup layout props " ")))
471 (ly:make-stencil (ly:stencil-expr m)
473 (ly:stencil-extent m X)
476 ;; todo: fix negative space
477 (define-markup-command (hspace layout props amount)
480 #:properties ((word-space))
482 @cindex creating horizontal spaces in text
484 Create an invisible object taking up horizontal space @var{amount}.
486 @lilypond[verbatim,quote]
495 (let ((corrected-space (- amount word-space)))
496 (if (> corrected-space 0)
497 (ly:make-stencil "" (cons 0 corrected-space) '(0 . 0))
498 (ly:make-stencil "" (cons corrected-space corrected-space) '(0 . 0)))))
500 ;; todo: fix negative space
501 (define-markup-command (vspace layout props amount)
505 @cindex creating vertical spaces in text
507 Create an invisible object taking up vertical space
508 of @var{amount} multiplied by 3.
510 @lilypond[verbatim,quote]
521 (let ((amount (* amount 3.0)))
523 (ly:make-stencil "" (cons 0 0) (cons 0 amount))
524 (ly:make-stencil "" (cons 0 0) (cons amount amount)))))
527 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
528 ;; importing graphics.
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
531 (define-markup-command (stencil layout props stil)
535 @cindex importing stencils into text
537 Use a stencil as markup.
539 @lilypond[verbatim,quote]
541 \\stencil #(make-circle-stencil 2 0 #t)
547 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
549 (define (get-postscript-bbox string)
550 "Extract the bbox from STRING, or return #f if not present."
552 ((match (regexp-exec bbox-regexp string)))
556 (string->number (match:substring match x)))
561 (define-markup-command (epsfile layout props axis size file-name)
562 (number? number? string?)
565 @cindex inlining an Encapsulated PostScript image
567 Inline an EPS image. The image is scaled along @var{axis} to
570 @lilypond[verbatim,quote]
572 \\general-align #Y #DOWN {
573 \\epsfile #X #20 #\"context-example.eps\"
574 \\epsfile #Y #20 #\"context-example.eps\"
578 (if (ly:get-option 'safe)
579 (interpret-markup layout props "not allowed in safe")
580 (eps-file->stencil axis size file-name)
583 (define-markup-command (postscript layout props str)
587 @cindex inserting PostScript directly into text
588 This inserts @var{str} directly into the output as a PostScript
591 @lilypond[verbatim,quote]
595 0.4 0.6 0.5 0 361 arc
597 1.0 0.6 0.5 0 361 arc
602 \\with-dimensions #'(-0.2 . 1.6) #'(0 . 1.2)
603 \\postscript #ringsps
615 gsave currentpoint translate
623 (define-markup-command (path layout props thickness commands) (number? list?)
625 #:properties ((line-cap-style 'round)
626 (line-join-style 'round)
629 @cindex paths, drawing
630 @cindex drawing paths
631 Draws a path with line thickness @var{thickness} according to the
632 directions given in @var{commands}. @var{commands} is a list of
633 lists where the @code{car} of each sublist is a drawing command and
634 the @code{cdr} comprises the associated arguments for each command.
636 Line-cap styles and line-join styles may be customized by
637 overriding the @code{line-cap-style} and @code{line-join-style}
638 properties, respectively. Available line-cap styles are
639 @code{'butt}, @code{'round}, and @code{'square}. Available
640 line-join styles are @code{'miter}, @code{'round}, and
643 The property @code{filled} specifies whether or not the path is
646 There are seven commands available to use in the list
647 @code{commands}: @code{moveto}, @code{rmoveto}, @code{lineto},
648 @code{rlineto}, @code{curveto}, @code{rcurveto}, and
649 @code{closepath}. Note that the commands that begin with @emph{r}
650 are the relative variants of the other three commands.
652 The commands @code{moveto}, @code{rmoveto}, @code{lineto}, and
653 @code{rlineto} take 2 arguments; they are the X and Y coordinates
654 for the destination point.
656 The commands @code{curveto} and @code{rcurveto} create cubic
657 Bézier curves, and take 6 arguments; the first two are the X and Y
658 coordinates for the first control point, the second two are the X
659 and Y coordinates for the second control point, and the last two
660 are the X and Y coordinates for the destination point.
662 The @code{closepath} command takes zero arguments and closes the
663 current subpath in the active path.
665 Note that a sequence of commands @emph{must} begin with a
666 @code{moveto} or @code{rmoveto} to work with the SVG output.
668 @lilypond[verbatim,quote]
674 (curveto -5 -5 -5 5 -1 0)
678 \\path #0.25 #samplePath
681 (let* ((half-thickness (/ thickness 2))
682 (current-point '(0 . 0))
683 (set-point (lambda (lst) (set! current-point lst)))
684 (relative? (lambda (x)
685 (string-prefix? "r" (symbol->string (car x)))))
686 ;; For calculating extents, we want to modify the command
687 ;; list so that all coordinates are absolute.
688 (new-commands (map (lambda (x)
690 ;; for rmoveto, rlineto
691 ((and (relative? x) (eq? 3 (length x)))
693 (+ (car current-point)
695 (+ (cdr current-point)
701 ((and (relative? x) (eq? 7 (length x)))
702 (let* ((old-cp current-point)
709 (list (+ (car old-cp) (second x))
710 (+ (cdr old-cp) (third x))
711 (+ (car old-cp) (fourth x))
712 (+ (cdr old-cp) (fifth x))
715 ;; for moveto, lineto
717 (set-point (cons (second x)
722 (set-point (cons (sixth x)
725 ;; keep closepath for filtering;
726 ;; see `without-closepath'.
729 ;; connected-shape-min-max does not accept 0-arg lists,
730 ;; and since closepath does not affect extents, filter
731 ;; out those commands here.
732 (without-closepath (filter (lambda (x)
733 (not (equal? 'closepath (car x))))
735 (extents (connected-shape-min-max
736 ;; set the origin to the first moveto
737 (list (list-ref (car without-closepath) 0)
738 (list-ref (car without-closepath) 1))
740 (X-extent (cons (list-ref extents 0) (list-ref extents 1)))
741 (Y-extent (cons (list-ref extents 2) (list-ref extents 3)))
742 (command-list (fold-right append '() commands)))
744 ;; account for line thickness
745 (set! X-extent (interval-widen X-extent half-thickness))
746 (set! Y-extent (interval-widen Y-extent half-thickness))
749 `(path ,thickness `(,@',command-list)
750 ',line-cap-style ',line-join-style ,filled)
754 (define-markup-command (score layout props score)
757 #:properties ((baseline-skip))
759 @cindex inserting music into text
761 Inline an image of music.
763 @lilypond[verbatim,quote]
767 \\new Staff \\relative c' {
770 \\mark \\markup { Allegro }
776 \\new Staff \\relative c {
790 \\override RehearsalMark #'break-align-symbols =
791 #'(time-signature key-signature)
792 \\override RehearsalMark #'self-alignment-X = #LEFT
796 \\override TimeSignature #'break-align-anchor-alignment = #LEFT
802 (let ((output (ly:score-embedded-format score layout)))
804 (if (ly:music-output? output)
805 (stack-stencils Y DOWN baseline-skip
806 (map paper-system-stencil
808 (ly:paper-score-paper-systems output))))
810 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
813 (define-markup-command (null layout props)
817 @cindex creating empty text objects
819 An empty markup with extents of a single point.
821 @lilypond[verbatim,quote]
828 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
830 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
832 (define-markup-command (simple layout props str)
836 @cindex simple text strings
838 A simple text string; @code{\\markup @{ foo @}} is equivalent with
839 @code{\\markup @{ \\simple #\"foo\" @}}.
841 Note: for creating standard text markup or defining new markup commands,
842 the use of @code{\\simple} is unnecessary.
844 @lilypond[verbatim,quote]
848 \\simple #\"strings\"
851 (interpret-markup layout props str))
853 (define-markup-command (tied-lyric layout props str)
857 @cindex simple text strings with tie characters
859 Like simple-markup, but use tie characters for @q{~} tilde symbols.
861 @lilypond[verbatim,quote]
863 \\tied-lyric #\"Lasciate~i monti\"
866 (if (string-contains str "~")
868 ((parts (string-split str #\~))
869 (tie-str (ly:wide-char->utf-8 #x203f))
870 (joined (list-join parts tie-str))
871 (join-stencil (interpret-markup layout props tie-str))
874 (interpret-markup layout
877 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
879 (make-line-markup joined)))
880 ;(map (lambda (s) (interpret-markup layout props s)) parts))
881 (interpret-markup layout props str)))
883 (define-public empty-markup
884 (make-simple-markup ""))
886 ;; helper for justifying lines.
887 (define (get-fill-space word-count line-width text-widths)
888 "Calculate the necessary paddings between each two adjacent texts.
889 The lengths of all texts are stored in @var{text-widths}.
890 The normal formula for the padding between texts a and b is:
891 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
892 The first and last padding have to be calculated specially using the
893 whole length of the first or last text.
894 Return a list of paddings."
896 ((null? text-widths) '())
898 ;; special case first padding
899 ((= (length text-widths) word-count)
901 (- (- (/ line-width (1- word-count)) (car text-widths))
902 (/ (car (cdr text-widths)) 2))
903 (get-fill-space word-count line-width (cdr text-widths))))
904 ;; special case last padding
905 ((= (length text-widths) 2)
906 (list (- (/ line-width (1- word-count))
907 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
910 (- (/ line-width (1- word-count))
911 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
912 (get-fill-space word-count line-width (cdr text-widths))))))
914 (define-markup-command (fill-line layout props args)
917 #:properties ((text-direction RIGHT)
920 "Put @var{markups} in a horizontal line of width @var{line-width}.
921 The markups are spaced or flushed to fill the entire line.
922 If there are no arguments, return an empty stencil.
924 @lilypond[verbatim,quote]
928 Words evenly spaced across the page
932 \\line { Text markups }
934 \\italic { evenly spaced }
936 \\line { across the page }
941 (let* ((orig-stencils (interpret-markup-list layout props args))
944 (if (ly:stencil-empty? stc)
946 stc)) orig-stencils))
949 (if (ly:stencil-empty? stc)
951 (interval-length (ly:stencil-extent stc X))))
953 (text-width (apply + text-widths))
954 (word-count (length stencils))
955 (line-width (or line-width (ly:output-def-lookup layout 'line-width)))
960 (/ (- line-width text-width) 2)
961 (/ (- line-width text-width) 2)))
964 (- line-width text-width)))
966 (get-fill-space word-count line-width text-widths))))
974 (line-stencils (if (= word-count 1)
981 (if (= text-direction LEFT)
982 (set! line-stencils (reverse line-stencils)))
984 (if (null? (remove ly:stencil-empty? orig-stencils))
986 (ly:stencil-translate-axis
987 (stack-stencils-padding-list X
988 RIGHT fill-space-normal line-stencils)
989 (- (car (ly:stencil-extent (car stencils) X)))
992 (define-markup-command (line layout props args)
995 #:properties ((word-space)
996 (text-direction RIGHT))
997 "Put @var{args} in a horizontal line. The property @code{word-space}
998 determines the space between markups in @var{args}.
1000 @lilypond[verbatim,quote]
1007 (let ((stencils (interpret-markup-list layout props args)))
1008 (if (= text-direction LEFT)
1009 (set! stencils (reverse stencils)))
1012 (remove ly:stencil-empty? stencils))))
1014 (define-markup-command (concat layout props args)
1018 @cindex concatenating text
1019 @cindex ligatures in text
1021 Concatenate @var{args} in a horizontal line, without spaces in between.
1022 Strings and simple markups are concatenated on the input level, allowing
1023 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
1024 equivalent to @code{\"fi\"}.
1026 @lilypond[verbatim,quote]
1035 (define (concat-string-args arg-list)
1036 (fold-right (lambda (arg result-list)
1037 (let ((result (if (pair? result-list)
1040 (if (and (pair? arg) (eqv? (car arg) simple-markup))
1041 (set! arg (cadr arg)))
1042 (if (and (string? result) (string? arg))
1043 (cons (string-append arg result) (cdr result-list))
1044 (cons arg result-list))))
1048 (interpret-markup layout
1049 (prepend-alist-chain 'word-space 0 props)
1050 (make-line-markup (if (markup-command-list? args)
1052 (concat-string-args args)))))
1054 (define (wordwrap-stencils stencils
1055 justify base-space line-width text-dir)
1056 "Perform simple wordwrap, return stencil of each line."
1057 (define space (if justify
1058 ;; justify only stretches lines.
1061 (define (take-list width space stencils
1062 accumulator accumulated-width)
1063 "Return (head-list . tail) pair, with head-list fitting into width"
1064 (if (null? stencils)
1065 (cons accumulator stencils)
1066 (let* ((first (car stencils))
1067 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
1068 (newwid (+ space first-wid accumulated-width)))
1069 (if (or (null? accumulator)
1071 (take-list width space
1073 (cons first accumulator)
1075 (cons accumulator stencils)))))
1076 (let loop ((lines '())
1078 (let* ((line-break (take-list line-width space todo
1080 (line-stencils (car line-break))
1081 (space-left (- line-width
1082 (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
1084 (line-word-space (cond ((not justify) space)
1085 ;; don't stretch last line of paragraph.
1086 ;; hmmm . bug - will overstretch the last line in some case.
1087 ((null? (cdr line-break))
1089 ((null? line-stencils) 0.0)
1090 ((null? (cdr line-stencils)) 0.0)
1091 (else (/ space-left (1- (length line-stencils))))))
1092 (line (stack-stencil-line line-word-space
1093 (if (= text-dir RIGHT)
1094 (reverse line-stencils)
1096 (if (pair? (cdr line-break))
1097 (loop (cons line lines)
1100 (if (= text-dir LEFT)
1102 (ly:stencil-translate-axis
1104 (- line-width (interval-end (ly:stencil-extent line X)))
1106 (reverse (cons line lines)))))))
1108 (define-markup-list-command (wordwrap-internal layout props justify args)
1109 (boolean? markup-list?)
1110 #:properties ((line-width #f)
1112 (text-direction RIGHT))
1113 "Internal markup list command used to define @code{\\justify} and @code{\\wordwrap}."
1114 (wordwrap-stencils (remove ly:stencil-empty?
1115 (interpret-markup-list layout props args))
1119 (ly:output-def-lookup layout 'line-width))
1122 (define-markup-command (justify layout props args)
1125 #:properties ((baseline-skip)
1126 wordwrap-internal-markup-list)
1128 @cindex justifying text
1130 Like @code{\\wordwrap}, but with lines stretched to justify the margins.
1131 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1132 @var{X}@tie{}is the number of staff spaces.
1134 @lilypond[verbatim,quote]
1137 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1138 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1139 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1140 laboris nisi ut aliquip ex ea commodo consequat.
1144 (stack-lines DOWN 0.0 baseline-skip
1145 (wordwrap-internal-markup-list layout props #t args)))
1147 (define-markup-command (wordwrap layout props args)
1150 #:properties ((baseline-skip)
1151 wordwrap-internal-markup-list)
1152 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
1153 the line width, where @var{X} is the number of staff spaces.
1155 @lilypond[verbatim,quote]
1158 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
1159 do eiusmod tempor incididunt ut labore et dolore magna aliqua.
1160 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1161 laboris nisi ut aliquip ex ea commodo consequat.
1165 (stack-lines DOWN 0.0 baseline-skip
1166 (wordwrap-internal-markup-list layout props #f args)))
1168 (define-markup-list-command (wordwrap-string-internal layout props justify arg)
1170 #:properties ((line-width)
1172 (text-direction RIGHT))
1173 "Internal markup list command used to define @code{\\justify-string} and
1174 @code{\\wordwrap-string}."
1175 (let* ((para-strings (regexp-split
1176 (string-regexp-substitute
1178 (string-regexp-substitute "\r\n" "\n" arg))
1179 "\n[ \t\n]*\n[ \t\n]*"))
1180 (list-para-words (map (lambda (str)
1181 (regexp-split str "[ \t\n]+"))
1183 (para-lines (map (lambda (words)
1185 (remove ly:stencil-empty?
1187 (interpret-markup layout props x))
1189 (wordwrap-stencils stencils
1191 line-width text-direction)))
1193 (apply append para-lines)))
1195 (define-markup-command (wordwrap-string layout props arg)
1198 #:properties ((baseline-skip)
1199 wordwrap-string-internal-markup-list)
1200 "Wordwrap a string. Paragraphs may be separated with double newlines.
1202 @lilypond[verbatim,quote]
1204 \\override #'(line-width . 40)
1205 \\wordwrap-string #\"Lorem ipsum dolor sit amet, consectetur
1206 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1207 et dolore magna aliqua.
1210 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1211 laboris nisi ut aliquip ex ea commodo consequat.
1214 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1215 qui officia deserunt mollit anim id est laborum\"
1218 (stack-lines DOWN 0.0 baseline-skip
1219 (wordwrap-string-internal-markup-list layout props #f arg)))
1221 (define-markup-command (justify-string layout props arg)
1224 #:properties ((baseline-skip)
1225 wordwrap-string-internal-markup-list)
1226 "Justify a string. Paragraphs may be separated with double newlines
1228 @lilypond[verbatim,quote]
1230 \\override #'(line-width . 40)
1231 \\justify-string #\"Lorem ipsum dolor sit amet, consectetur
1232 adipisicing elit, sed do eiusmod tempor incididunt ut labore
1233 et dolore magna aliqua.
1236 Ut enim ad minim veniam, quis nostrud exercitation ullamco
1237 laboris nisi ut aliquip ex ea commodo consequat.
1240 Excepteur sint occaecat cupidatat non proident, sunt in culpa
1241 qui officia deserunt mollit anim id est laborum\"
1244 (stack-lines DOWN 0.0 baseline-skip
1245 (wordwrap-string-internal-markup-list layout props #t arg)))
1247 (define-markup-command (wordwrap-field layout props symbol)
1250 "Wordwrap the data which has been assigned to @var{symbol}.
1252 @lilypond[verbatim,quote]
1254 title = \"My title\"
1255 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1256 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1257 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1258 laboris nisi ut aliquip ex ea commodo consequat.\"
1262 bookTitleMarkup = \\markup {
1264 \\fill-line { \\fromproperty #'header:title }
1266 \\wordwrap-field #'header:myText
1275 (let* ((m (chain-assoc-get symbol props)))
1277 (wordwrap-string-markup layout props m)
1280 (define-markup-command (justify-field layout props symbol)
1283 "Justify the data which has been assigned to @var{symbol}.
1285 @lilypond[verbatim,quote]
1287 title = \"My title\"
1288 myText = \"Lorem ipsum dolor sit amet, consectetur adipisicing
1289 elit, sed do eiusmod tempor incididunt ut labore et dolore magna
1290 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
1291 laboris nisi ut aliquip ex ea commodo consequat.\"
1295 bookTitleMarkup = \\markup {
1297 \\fill-line { \\fromproperty #'header:title }
1299 \\justify-field #'header:myText
1308 (let* ((m (chain-assoc-get symbol props)))
1310 (justify-string-markup layout props m)
1313 (define-markup-command (combine layout props arg1 arg2)
1317 @cindex merging text
1319 Print two markups on top of each other.
1321 Note: @code{\\combine} cannot take a list of markups enclosed in
1322 curly braces as an argument; the follow example will not compile:
1325 \\combine @{ a list @}
1328 @lilypond[verbatim,quote]
1331 \\override #'(thickness . 2)
1333 \\draw-line #'(0 . 4)
1334 \\arrow-head #Y #DOWN ##f
1337 (let* ((s1 (interpret-markup layout props arg1))
1338 (s2 (interpret-markup layout props arg2)))
1339 (ly:stencil-add s1 s2)))
1342 ;; TODO: should extract baseline-skip from each argument somehow..
1344 (define-markup-command (column layout props args)
1347 #:properties ((baseline-skip))
1349 @cindex stacking text in a column
1351 Stack the markups in @var{args} vertically. The property
1352 @code{baseline-skip} determines the space between markups
1355 @lilypond[verbatim,quote]
1364 (let ((arg-stencils (interpret-markup-list layout props args)))
1365 (stack-lines -1 0.0 baseline-skip
1366 (remove ly:stencil-empty? arg-stencils))))
1368 (define-markup-command (dir-column layout props args)
1371 #:properties ((direction)
1374 @cindex changing direction of text columns
1376 Make a column of @var{args}, going up or down, depending on the
1377 setting of the @code{direction} layout property.
1379 @lilypond[verbatim,quote]
1381 \\override #`(direction . ,UP) {
1391 \\override #'(direction . 1) {
1398 (stack-lines (if (number? direction) direction -1)
1401 (interpret-markup-list layout props args)))
1403 (define (general-column align-dir baseline mols)
1404 "Stack @var{mols} vertically, aligned to @var{align-dir} horizontally."
1406 (let* ((aligned-mols (map (lambda (x) (ly:stencil-aligned-to x X align-dir)) mols)))
1407 (stack-lines -1 0.0 baseline aligned-mols)))
1409 (define-markup-command (center-column layout props args)
1412 #:properties ((baseline-skip))
1414 @cindex centering a column of text
1416 Put @code{args} in a centered column.
1418 @lilypond[verbatim,quote]
1427 (general-column CENTER baseline-skip (interpret-markup-list layout props args)))
1429 (define-markup-command (left-column layout props args)
1432 #:properties ((baseline-skip))
1434 @cindex text columns, left-aligned
1436 Put @code{args} in a left-aligned column.
1438 @lilypond[verbatim,quote]
1447 (general-column LEFT baseline-skip (interpret-markup-list layout props args)))
1449 (define-markup-command (right-column layout props args)
1452 #:properties ((baseline-skip))
1454 @cindex text columns, right-aligned
1456 Put @code{args} in a right-aligned column.
1458 @lilypond[verbatim,quote]
1467 (general-column RIGHT baseline-skip (interpret-markup-list layout props args)))
1469 (define-markup-command (vcenter layout props arg)
1473 @cindex vertically centering text
1475 Align @code{arg} to its Y@tie{}center.
1477 @lilypond[verbatim,quote]
1485 (let* ((mol (interpret-markup layout props arg)))
1486 (ly:stencil-aligned-to mol Y CENTER)))
1488 (define-markup-command (center-align layout props arg)
1492 @cindex horizontally centering text
1494 Align @code{arg} to its X@tie{}center.
1496 @lilypond[verbatim,quote]
1506 (let* ((mol (interpret-markup layout props arg)))
1507 (ly:stencil-aligned-to mol X CENTER)))
1509 (define-markup-command (right-align layout props arg)
1513 @cindex right aligning text
1515 Align @var{arg} on its right edge.
1517 @lilypond[verbatim,quote]
1527 (let* ((m (interpret-markup layout props arg)))
1528 (ly:stencil-aligned-to m X RIGHT)))
1530 (define-markup-command (left-align layout props arg)
1534 @cindex left aligning text
1536 Align @var{arg} on its left edge.
1538 @lilypond[verbatim,quote]
1548 (let* ((m (interpret-markup layout props arg)))
1549 (ly:stencil-aligned-to m X LEFT)))
1551 (define-markup-command (general-align layout props axis dir arg)
1552 (integer? number? markup?)
1555 @cindex controlling general text alignment
1557 Align @var{arg} in @var{axis} direction to the @var{dir} side.
1559 @lilypond[verbatim,quote]
1563 \\general-align #X #LEFT
1568 \\general-align #X #CENTER
1574 \\general-align #Y #UP
1581 \\general-align #Y #3.2
1588 (let* ((m (interpret-markup layout props arg)))
1589 (ly:stencil-aligned-to m axis dir)))
1591 (define-markup-command (halign layout props dir arg)
1595 @cindex setting horizontal text alignment
1597 Set horizontal alignment. If @var{dir} is @code{-1}, then it is
1598 left-aligned, while @code{+1} is right. Values in between interpolate
1599 alignment accordingly.
1601 @lilypond[verbatim,quote]
1626 (let* ((m (interpret-markup layout props arg)))
1627 (ly:stencil-aligned-to m X dir)))
1629 (define-markup-command (with-dimensions layout props x y arg)
1630 (number-pair? number-pair? markup?)
1633 @cindex setting extent of text objects
1635 Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
1636 (let* ((m (interpret-markup layout props arg)))
1637 (ly:make-stencil (ly:stencil-expr m) x y)))
1639 (define-markup-command (pad-around layout props amount arg)
1642 "Add padding @var{amount} all around @var{arg}.
1644 @lilypond[verbatim,quote]
1657 (let* ((m (interpret-markup layout props arg))
1658 (x (ly:stencil-extent m X))
1659 (y (ly:stencil-extent m Y)))
1660 (ly:make-stencil (ly:stencil-expr m)
1661 (interval-widen x amount)
1662 (interval-widen y amount))))
1664 (define-markup-command (pad-x layout props amount arg)
1668 @cindex padding text horizontally
1670 Add padding @var{amount} around @var{arg} in the X@tie{}direction.
1672 @lilypond[verbatim,quote]
1685 (let* ((m (interpret-markup layout props arg))
1686 (x (ly:stencil-extent m X))
1687 (y (ly:stencil-extent m Y)))
1688 (ly:make-stencil (ly:stencil-expr m)
1689 (interval-widen x amount)
1692 (define-markup-command (put-adjacent layout props axis dir arg1 arg2)
1693 (integer? ly:dir? markup? markup?)
1695 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
1696 (let ((m1 (interpret-markup layout props arg1))
1697 (m2 (interpret-markup layout props arg2)))
1698 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)))
1700 (define-markup-command (transparent layout props arg)
1703 "Make @var{arg} transparent.
1705 @lilypond[verbatim,quote]
1712 (let* ((m (interpret-markup layout props arg))
1713 (x (ly:stencil-extent m X))
1714 (y (ly:stencil-extent m Y)))
1715 (ly:make-stencil "" x y)))
1717 (define-markup-command (pad-to-box layout props x-ext y-ext arg)
1718 (number-pair? number-pair? markup?)
1720 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space.
1722 @lilypond[verbatim,quote]
1729 \\pad-to-box #'(0 . 10) #'(0 . 3) {
1735 (let* ((m (interpret-markup layout props arg))
1736 (x (ly:stencil-extent m X))
1737 (y (ly:stencil-extent m Y)))
1738 (ly:make-stencil (ly:stencil-expr m)
1739 (interval-union x-ext x)
1740 (interval-union y-ext y))))
1742 (define-markup-command (hcenter-in layout props length arg)
1745 "Center @var{arg} horizontally within a box of extending
1746 @var{length}/2 to the left and right.
1748 @lilypond[quote,verbatim]
1751 \\set Staff.instrumentName = \\markup {
1758 \\set Staff.instrumentName = \\markup {
1767 (interpret-markup layout props
1768 (make-pad-to-box-markup
1769 (cons (/ length -2) (/ length 2))
1771 (make-center-align-markup arg))))
1773 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1775 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1777 (define-markup-command (fromproperty layout props symbol)
1780 "Read the @var{symbol} from property settings, and produce a stencil
1781 from the markup contained within. If @var{symbol} is not defined, it
1782 returns an empty markup.
1784 @lilypond[verbatim,quote]
1786 myTitle = \"myTitle\"
1790 \\fromproperty #'header:myTitle
1797 (let ((m (chain-assoc-get symbol props)))
1799 (interpret-markup layout props m)
1802 (define-markup-command (on-the-fly layout props procedure arg)
1805 "Apply the @var{procedure} markup command to @var{arg}.
1806 @var{procedure} should take a single argument."
1807 (let ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
1808 (set-object-property! anonymous-with-signature
1811 (interpret-markup layout props (list anonymous-with-signature arg))))
1813 (define-markup-command (override layout props new-prop arg)
1817 @cindex overriding properties within text markup
1819 Add the argument @var{new-prop} to the property list. Properties
1820 may be any property supported by @rinternals{font-interface},
1821 @rinternals{text-interface} and
1822 @rinternals{instrument-specific-markup-interface}.
1824 @lilypond[verbatim,quote]
1832 \\override #'(baseline-skip . 4) {
1841 (interpret-markup layout (cons (list new-prop) props) arg))
1843 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1845 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1847 (define-markup-command (verbatim-file layout props name)
1850 "Read the contents of file @var{name}, and include it verbatim.
1852 @lilypond[verbatim,quote]
1854 \\verbatim-file #\"simple.ly\"
1857 (interpret-markup layout props
1858 (if (ly:get-option 'safe)
1859 "verbatim-file disabled in safe mode"
1860 (let* ((str (ly:gulp-file name))
1861 (lines (string-split str #\nl)))
1862 (make-typewriter-markup
1863 (make-column-markup lines))))))
1865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1867 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1870 (define-markup-command (smaller layout props arg)
1873 "Decrease the font size relative to the current setting.
1875 @lilypond[verbatim,quote]
1888 (interpret-markup layout props
1889 `(,fontsize-markup -1 ,arg)))
1891 (define-markup-command (larger layout props arg)
1894 "Increase the font size relative to the current setting.
1896 @lilypond[verbatim,quote]
1904 (interpret-markup layout props
1905 `(,fontsize-markup 1 ,arg)))
1907 (define-markup-command (finger layout props arg)
1910 "Set @var{arg} as small numbers.
1912 @lilypond[verbatim,quote]
1919 (interpret-markup layout
1920 (cons '((font-size . -5) (font-encoding . fetaText)) props)
1923 (define-markup-command (abs-fontsize layout props size arg)
1926 "Use @var{size} as the absolute font size to display @var{arg}.
1927 Adjusts @code{baseline-skip} and @code{word-space} accordingly.
1929 @lilypond[verbatim,quote]
1931 default text font size
1933 \\abs-fontsize #16 { text font size 16 }
1935 \\abs-fontsize #12 { text font size 12 }
1938 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
1939 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
1940 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
1941 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
1942 (magnification (/ size ref-size)))
1943 (interpret-markup layout
1944 (cons `((baseline-skip . ,(* magnification ref-baseline))
1945 (word-space . ,(* magnification ref-word-space))
1946 (font-size . ,(magnification->font-size magnification)))
1950 (define-markup-command (fontsize layout props increment arg)
1953 #:properties ((font-size 0)
1956 "Add @var{increment} to the font-size. Adjusts @code{baseline-skip}
1959 @lilypond[verbatim,quote]
1967 (let ((entries (list
1968 (cons 'baseline-skip (* baseline-skip (magstep increment)))
1969 (cons 'word-space (* word-space (magstep increment)))
1970 (cons 'font-size (+ font-size increment)))))
1971 (interpret-markup layout (cons entries props) arg)))
1973 (define-markup-command (magnify layout props sz arg)
1977 @cindex magnifying text
1979 Set the font magnification for its argument. In the following
1980 example, the middle@tie{}A is 10% larger:
1983 A \\magnify #1.1 @{ A @} A
1986 Note: Magnification only works if a font name is explicitly selected.
1987 Use @code{\\fontsize} otherwise.
1989 @lilypond[verbatim,quote]
2000 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
2003 (define-markup-command (bold layout props arg)
2006 "Switch to bold font-series.
2008 @lilypond[verbatim,quote]
2016 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
2018 (define-markup-command (sans layout props arg)
2021 "Switch to the sans serif font family.
2023 @lilypond[verbatim,quote]
2032 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
2034 (define-markup-command (number layout props arg)
2037 "Set font family to @code{number}, which yields the font used for
2038 time signatures and fingerings. This font contains numbers and
2039 some punctuation; it has no letters.
2041 @lilypond[verbatim,quote]
2044 0 1 2 3 4 5 6 7 8 9 . ,
2048 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2050 (define-markup-command (roman layout props arg)
2053 "Set font family to @code{roman}.
2055 @lilypond[verbatim,quote]
2061 text in roman font family
2068 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
2070 (define-markup-command (huge layout props arg)
2073 "Set font size to +2.
2075 @lilypond[verbatim,quote]
2083 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
2085 (define-markup-command (large layout props arg)
2088 "Set font size to +1.
2090 @lilypond[verbatim,quote]
2098 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
2100 (define-markup-command (normalsize layout props arg)
2103 "Set font size to default.
2105 @lilypond[verbatim,quote]
2118 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
2120 (define-markup-command (small layout props arg)
2123 "Set font size to -1.
2125 @lilypond[verbatim,quote]
2133 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
2135 (define-markup-command (tiny layout props arg)
2138 "Set font size to -2.
2140 @lilypond[verbatim,quote]
2148 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
2150 (define-markup-command (teeny layout props arg)
2153 "Set font size to -3.
2155 @lilypond[verbatim,quote]
2163 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
2165 (define-markup-command (fontCaps layout props arg)
2168 "Set @code{font-shape} to @code{caps}
2170 Note: @code{\\fontCaps} requires the installation and selection of
2171 fonts which support the @code{caps} font shape."
2172 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
2175 (define-markup-command (smallCaps layout props arg)
2178 "Emit @var{arg} as small caps.
2180 Note: @code{\\smallCaps} does not support accented characters.
2182 @lilypond[verbatim,quote]
2191 (define (char-list->markup chars lower)
2192 (let ((final-string (string-upcase (reverse-list->string chars))))
2194 (markup #:fontsize -2 final-string)
2196 (define (make-small-caps rest-chars currents current-is-lower prev-result)
2197 (if (null? rest-chars)
2199 (reverse! (cons (char-list->markup currents current-is-lower)
2201 (let* ((ch (car rest-chars))
2202 (is-lower (char-lower-case? ch)))
2203 (if (or (and current-is-lower is-lower)
2204 (and (not current-is-lower) (not is-lower)))
2205 (make-small-caps (cdr rest-chars)
2209 (make-small-caps (cdr rest-chars)
2212 (if (null? currents)
2214 (cons (char-list->markup
2215 currents current-is-lower)
2217 (interpret-markup layout props
2219 (make-small-caps (string->list arg) (list) #f (list))
2222 (define-markup-command (caps layout props arg)
2225 "Copy of the @code{\\smallCaps} command.
2227 @lilypond[verbatim,quote]
2236 (interpret-markup layout props (make-smallCaps-markup arg)))
2238 (define-markup-command (dynamic layout props arg)
2241 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
2242 @b{z}, @b{p}, and @b{r}. When producing phrases, like
2243 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
2244 done in a different font. The recommended font for this is bold and italic.
2245 @lilypond[verbatim,quote]
2253 layout (prepend-alist-chain 'font-encoding 'fetaText props) arg))
2255 (define-markup-command (text layout props arg)
2258 "Use a text font instead of music symbol or music alphabet font.
2260 @lilypond[verbatim,quote]
2273 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
2276 (define-markup-command (italic layout props arg)
2279 "Use italic @code{font-shape} for @var{arg}.
2281 @lilypond[verbatim,quote]
2289 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
2291 (define-markup-command (typewriter layout props arg)
2294 "Use @code{font-family} typewriter for @var{arg}.
2296 @lilypond[verbatim,quote]
2305 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
2307 (define-markup-command (upright layout props arg)
2310 "Set @code{font-shape} to @code{upright}. This is the opposite
2313 @lilypond[verbatim,quote]
2327 layout (prepend-alist-chain 'font-shape 'upright props) arg))
2329 (define-markup-command (medium layout props arg)
2332 "Switch to medium font-series (in contrast to bold).
2334 @lilypond[verbatim,quote]
2347 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
2350 (define-markup-command (normal-text layout props arg)
2353 "Set all font related properties (except the size) to get the default
2354 normal text font, no matter what font was used earlier.
2356 @lilypond[verbatim,quote]
2358 \\huge \\bold \\sans \\caps {
2359 Some text with font overrides
2362 Default text, same font-size
2370 (interpret-markup layout
2371 (cons '((font-family . roman) (font-shape . upright)
2372 (font-series . medium) (font-encoding . latin1))
2376 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2378 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2380 (define-markup-command (doublesharp layout props)
2383 "Draw a double sharp symbol.
2385 @lilypond[verbatim,quote]
2390 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
2392 (define-markup-command (sesquisharp layout props)
2395 "Draw a 3/2 sharp symbol.
2397 @lilypond[verbatim,quote]
2402 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
2404 (define-markup-command (sharp layout props)
2407 "Draw a sharp symbol.
2409 @lilypond[verbatim,quote]
2414 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
2416 (define-markup-command (semisharp layout props)
2419 "Draw a semisharp symbol.
2421 @lilypond[verbatim,quote]
2426 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
2428 (define-markup-command (natural layout props)
2431 "Draw a natural symbol.
2433 @lilypond[verbatim,quote]
2438 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
2440 (define-markup-command (semiflat layout props)
2443 "Draw a semiflat symbol.
2445 @lilypond[verbatim,quote]
2450 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
2452 (define-markup-command (flat layout props)
2455 "Draw a flat symbol.
2457 @lilypond[verbatim,quote]
2462 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
2464 (define-markup-command (sesquiflat layout props)
2467 "Draw a 3/2 flat symbol.
2469 @lilypond[verbatim,quote]
2474 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
2476 (define-markup-command (doubleflat layout props)
2479 "Draw a double flat symbol.
2481 @lilypond[verbatim,quote]
2486 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
2488 (define-markup-command (with-color layout props color arg)
2492 @cindex coloring text
2494 Draw @var{arg} in color specified by @var{color}.
2496 @lilypond[verbatim,quote]
2508 (let ((stil (interpret-markup layout props arg)))
2509 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
2510 (ly:stencil-extent stil X)
2511 (ly:stencil-extent stil Y))))
2513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2515 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2517 (define-markup-command (arrow-head layout props axis dir filled)
2518 (integer? ly:dir? boolean?)
2520 "Produce an arrow head in specified direction and axis.
2521 Use the filled head if @var{filled} is specified.
2522 @lilypond[verbatim,quote]
2525 \\general-align #Y #DOWN {
2526 \\arrow-head #Y #UP ##t
2527 \\arrow-head #Y #DOWN ##f
2529 \\arrow-head #X #RIGHT ##f
2530 \\arrow-head #X #LEFT ##f
2536 ((name (format "arrowheads.~a.~a~a"
2543 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2547 (define-markup-command (musicglyph layout props glyph-name)
2550 "@var{glyph-name} is converted to a musical symbol; for example,
2551 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
2552 the music font. See @ruser{The Feta font} for a complete listing of
2553 the possible glyphs.
2555 @lilypond[verbatim,quote]
2558 \\musicglyph #\"rests.2\"
2559 \\musicglyph #\"clefs.G_change\"
2562 (let* ((font (ly:paper-get-font layout
2563 (cons '((font-encoding . fetaMusic)
2567 (glyph (ly:font-get-glyph font glyph-name)))
2568 (if (null? (ly:stencil-expr glyph))
2569 (ly:warning (_ "Cannot find glyph ~a") glyph-name))
2574 (define-markup-command (lookup layout props glyph-name)
2577 "Lookup a glyph by name.
2579 @lilypond[verbatim,quote]
2581 \\override #'(font-encoding . fetaBraces) {
2582 \\lookup #\"brace200\"
2585 \\lookup #\"brace180\"
2589 (ly:font-get-glyph (ly:paper-get-font layout props)
2592 (define-markup-command (char layout props num)
2595 "Produce a single character. Characters encoded in hexadecimal
2596 format require the prefix @code{#x}.
2598 @lilypond[verbatim,quote]
2600 \\char #65 \\char ##x00a9
2603 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
2605 (define number->mark-letter-vector (make-vector 25 #\A))
2610 (if (= i (- (char->integer #\I) (char->integer #\A)))
2612 (vector-set! number->mark-letter-vector j
2613 (integer->char (+ i (char->integer #\A)))))
2615 (define number->mark-alphabet-vector (list->vector
2616 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
2618 (define (number->markletter-string vec n)
2619 "Double letters for big marks."
2620 (let* ((lst (vector-length vec)))
2623 (string-append (number->markletter-string vec (1- (quotient n lst)))
2624 (number->markletter-string vec (remainder n lst)))
2625 (make-string 1 (vector-ref vec n)))))
2627 (define-markup-command (markletter layout props num)
2630 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2631 (skipping letter@tie{}I), and continue with double letters.
2633 @lilypond[verbatim,quote]
2640 (ly:text-interface::interpret-markup layout props
2641 (number->markletter-string number->mark-letter-vector num)))
2643 (define-markup-command (markalphabet layout props num)
2646 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
2647 and continue with double letters.
2649 @lilypond[verbatim,quote]
2656 (ly:text-interface::interpret-markup layout props
2657 (number->markletter-string number->mark-alphabet-vector num)))
2659 (define-public (horizontal-slash-interval num forward number-interval mag)
2661 (cond ;((= num 6) (interval-widen number-interval (* mag 0.5)))
2662 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2663 (else (interval-widen number-interval (* mag 0.25))))
2664 (cond ((= num 6) (interval-widen number-interval (* mag 0.5)))
2665 ;((= num 5) (interval-widen number-interval (* mag 0.5)))
2666 (else (interval-widen number-interval (* mag 0.25))))
2669 (define-public (adjust-slash-stencil num forward stencil mag)
2672 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2674 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.2))))
2676 ;(ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.07))))
2678 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2681 (ly:stencil-translate stencil (cons (* mag -0.00) (* mag 0.15))))
2683 ; (ly:stencil-translate stencil (cons (* mag -0.00) (* mag -0.15))))
2688 (define (slashed-digit-internal layout props num forward font-size thickness)
2689 (let* ((mag (magstep font-size))
2691 (ly:output-def-lookup layout 'line-thickness)
2693 ; backward slashes might use slope and point in the other direction!
2694 (dy (* mag (if forward 0.4 -0.4)))
2695 (number-stencil (interpret-markup layout
2696 (prepend-alist-chain 'font-encoding 'fetaText props)
2697 (number->string num)))
2698 (num-x (horizontal-slash-interval num forward (ly:stencil-extent number-stencil X) mag))
2699 (center (interval-center (ly:stencil-extent number-stencil Y)))
2700 ; Use the real extents of the slash, not the whole number, because we
2701 ; might translate the slash later on!
2702 (num-y (interval-widen (cons center center) (abs dy)))
2703 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
2704 (slash-stencil (if is-sane
2705 (make-line-stencil thickness
2706 (car num-x) (- (interval-center num-y) dy)
2707 (cdr num-x) (+ (interval-center num-y) dy))
2709 (if (ly:stencil? slash-stencil)
2711 ; for some numbers we need to shift the slash/backslash up or down to make
2712 ; the slashed digit look better
2713 (set! slash-stencil (adjust-slash-stencil num forward slash-stencil mag))
2714 (set! number-stencil
2715 (ly:stencil-add number-stencil slash-stencil)))
2716 (ly:warning "Unable to create slashed digit ~a" num))
2720 (define-markup-command (slashed-digit layout props num)
2723 #:properties ((font-size 0)
2726 @cindex slashed digits
2728 A feta number, with slash. This is for use in the context of
2729 figured bass notation.
2730 @lilypond[verbatim,quote]
2734 \\override #'(thickness . 3)
2738 (slashed-digit-internal layout props num #t font-size thickness))
2740 (define-markup-command (backslashed-digit layout props num)
2743 #:properties ((font-size 0)
2746 @cindex backslashed digits
2748 A feta number, with backslash. This is for use in the context of
2749 figured bass notation.
2750 @lilypond[verbatim,quote]
2752 \\backslashed-digit #5
2754 \\override #'(thickness . 3)
2755 \\backslashed-digit #7
2758 (slashed-digit-internal layout props num #f font-size thickness))
2761 (define eyeglassesps
2766 0.7 0.7 0.5 0 361 arc
2768 2.20 0.70 0.50 0 361 arc
2770 1.45 0.85 0.30 0 180 arc
2774 0.92 2.26 1.30 2.40 1.15 1.70 curveto
2778 3.42 2.26 3.80 2.40 3.65 1.70 curveto
2781 (define-markup-command (eyeglasses layout props)
2784 "Prints out eyeglasses, indicating strongly to look at the conductor.
2785 @lilypond[verbatim,quote]
2786 \\markup { \\eyeglasses }
2788 (interpret-markup layout props
2789 (make-with-dimensions-markup '(-0.61 . 3.22) '(0.2 . 2.41)
2790 (make-postscript-markup eyeglassesps))))
2792 (define-markup-command (left-brace layout props size)
2796 A feta brace in point size @var{size}.
2798 @lilypond[verbatim,quote]
2805 (let* ((font (ly:paper-get-font layout
2806 (cons '((font-encoding . fetaBraces)
2809 (glyph-count (1- (ly:otf-glyph-count font)))
2810 (scale (ly:output-def-lookup layout 'output-scale))
2811 (scaled-size (/ (ly:pt size) scale))
2813 (ly:font-get-glyph font (string-append "brace"
2814 (number->string n)))))
2815 (get-y-from-brace (lambda (brace)
2817 (ly:stencil-extent (glyph brace) Y))))
2818 (find-brace (binary-search 0 glyph-count get-y-from-brace scaled-size))
2819 (glyph-found (glyph find-brace)))
2821 (if (or (null? (ly:stencil-expr glyph-found))
2822 (< scaled-size (interval-length (ly:stencil-extent (glyph 0) Y)))
2823 (> scaled-size (interval-length
2824 (ly:stencil-extent (glyph glyph-count) Y))))
2826 (ly:warning (_ "no brace found for point size ~S ") size)
2827 (ly:warning (_ "defaulting to ~S pt")
2828 (/ (* scale (interval-length
2829 (ly:stencil-extent glyph-found Y)))
2833 (define-markup-command (right-brace layout props size)
2837 A feta brace in point size @var{size}, rotated 180 degrees.
2839 @lilypond[verbatim,quote]
2846 (interpret-markup layout props (markup #:rotate 180 #:left-brace size)))
2848 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2849 ;; the note command.
2850 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2852 ;; TODO: better syntax.
2854 (define-markup-command (note-by-number layout props log dot-count dir)
2855 (number? number? number?)
2857 #:properties ((font-size 0)
2860 @cindex notes within text by log and dot-count
2862 Construct a note symbol, with stem. By using fractional values for
2863 @var{dir}, longer or shorter stems can be obtained.
2865 @lilypond[verbatim,quote]
2867 \\note-by-number #3 #0 #DOWN
2869 \\note-by-number #1 #2 #0.8
2872 (define (get-glyph-name-candidates dir log style)
2873 (map (lambda (dir-name)
2874 (format "noteheads.~a~a" dir-name
2875 (if (and (symbol? style)
2876 (not (equal? 'default style)))
2877 (select-head-glyph style (min log 2))
2879 (list (if (= dir UP) "u" "d")
2882 (define (get-glyph-name font cands)
2885 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
2886 (get-glyph-name font (cdr cands))
2889 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
2891 (size-factor (magstep font-size))
2892 (stem-length (* size-factor (max 3 (- log 1))))
2894 (let ((result (get-glyph-name font (get-glyph-name-candidates
2895 (sign dir) log style))))
2896 (if (string-null? result)
2897 ;; If no glyph name can be found, select default heads. Though
2898 ;; this usually means an unsupported style has been chosen, it
2899 ;; also prevents unrelated 'style settings from other grobs
2900 ;; (e.g., TextSpanner and TimeSignature) leaking into markup.
2901 (get-glyph-name font (get-glyph-name-candidates
2902 (sign dir) log 'default))
2904 (head-glyph (ly:font-get-glyph font head-glyph-name))
2905 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
2906 (stem-thickness (* size-factor 0.13))
2907 (stemy (* dir stem-length))
2908 (attach-off (cons (interval-index
2909 (ly:stencil-extent head-glyph X)
2910 (* (sign dir) (car attach-indices)))
2911 (* (sign dir) ; fixme, this is inconsistent between X & Y.
2913 (ly:stencil-extent head-glyph Y)
2914 (cdr attach-indices)))))
2915 (stem-glyph (and (> log 0)
2916 (ly:round-filled-box
2917 (ordered-cons (car attach-off)
2919 (* (- (sign dir)) stem-thickness)))
2920 (cons (min stemy (cdr attach-off))
2921 (max stemy (cdr attach-off)))
2922 (/ stem-thickness 3))))
2924 (dot (ly:font-get-glyph font "dots.dot"))
2925 (dotwid (interval-length (ly:stencil-extent dot X)))
2926 (dots (and (> dot-count 0)
2927 (apply ly:stencil-add
2929 (ly:stencil-translate-axis
2930 dot (* 2 x dotwid) X))
2931 (iota dot-count)))))
2932 (flaggl (and (> log 2)
2933 (ly:stencil-translate
2934 (ly:font-get-glyph font
2935 (string-append "flags."
2936 (if (> dir 0) "u" "d")
2937 (number->string log)))
2938 (cons (+ (car attach-off) (if (< dir 0)
2942 ;; If there is a flag on an upstem and the stem is short, move the dots
2943 ;; to avoid the flag. 16th notes get a special case because their flags
2944 ;; hang lower than any other flags.
2945 (if (and dots (> dir 0) (> log 2)
2946 (or (< dir 1.15) (and (= log 4) (< dir 1.3))))
2947 (set! dots (ly:stencil-translate-axis dots 0.5 X)))
2949 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
2950 (if (ly:stencil? stem-glyph)
2951 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
2952 (set! stem-glyph head-glyph))
2953 (if (ly:stencil? dots)
2956 (ly:stencil-translate-axis
2958 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
2964 (let ((divisor (log 2)))
2965 (lambda (z) (inexact->exact (/ (log z) divisor)))))
2967 (define (parse-simple-duration duration-string)
2968 "Parse the `duration-string', e.g. ''4..'' or ''breve.'',
2969 and return a (log dots) list."
2970 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)")
2972 (if (and match (string=? duration-string (match:substring match 0)))
2973 (let ((len (match:substring match 1))
2974 (dots (match:substring match 2)))
2975 (list (cond ((string=? len "breve") -1)
2976 ((string=? len "longa") -2)
2977 ((string=? len "maxima") -3)
2978 (else (log2 (string->number len))))
2979 (if dots (string-length dots) 0)))
2980 (ly:error (_ "not a valid duration string: ~a") duration-string))))
2982 (define-markup-command (note layout props duration dir)
2985 #:properties (note-by-number-markup)
2987 @cindex notes within text by string
2989 This produces a note with a stem pointing in @var{dir} direction, with
2990 the @var{duration} for the note head type and augmentation dots. For
2991 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
2992 a shortened down stem.
2994 @lilypond[verbatim,quote]
2996 \\override #'(style . cross) {
3000 \\note #\"breve\" #0
3003 (let ((parsed (parse-simple-duration duration)))
3004 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
3006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3010 (define-markup-command (lower layout props amount arg)
3014 @cindex lowering text
3016 Lower @var{arg} by the distance @var{amount}.
3017 A negative @var{amount} indicates raising; see also @code{\\raise}.
3019 @lilypond[verbatim,quote]
3027 (ly:stencil-translate-axis (interpret-markup layout props arg)
3030 (define-markup-command (translate-scaled layout props offset arg)
3031 (number-pair? markup?)
3033 #:properties ((font-size 0))
3035 @cindex translating text
3036 @cindex scaling text
3038 Translate @var{arg} by @var{offset}, scaling the offset by the
3041 @lilypond[verbatim,quote]
3044 * \\translate #'(2 . 3) translate
3046 * \\translate-scaled #'(2 . 3) translate-scaled
3050 (let* ((factor (magstep font-size))
3051 (scaled (cons (* factor (car offset))
3052 (* factor (cdr offset)))))
3053 (ly:stencil-translate (interpret-markup layout props arg)
3056 (define-markup-command (raise layout props amount arg)
3060 @cindex raising text
3062 Raise @var{arg} by the distance @var{amount}.
3063 A negative @var{amount} indicates lowering, see also @code{\\lower}.
3065 The argument to @code{\\raise} is the vertical displacement amount,
3066 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
3067 raise objects in relation to their surrounding markups.
3069 If the text object itself is positioned above or below the staff, then
3070 @code{\\raise} cannot be used to move it, since the mechanism that
3071 positions it next to the staff cancels any shift made with
3072 @code{\\raise}. For vertical positioning, use the @code{padding}
3073 and/or @code{extra-offset} properties.
3075 @lilypond[verbatim,quote]
3084 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
3086 (define-markup-command (fraction layout props arg1 arg2)
3089 #:properties ((font-size 0))
3091 @cindex creating text fractions
3093 Make a fraction of two markups.
3094 @lilypond[verbatim,quote]
3100 (let* ((m1 (interpret-markup layout props arg1))
3101 (m2 (interpret-markup layout props arg2))
3102 (factor (magstep font-size))
3103 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
3104 (padding (* factor 0.2))
3105 (baseline (* factor 0.6))
3106 (offset (* factor 0.75)))
3107 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
3108 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
3109 (let* ((x1 (ly:stencil-extent m1 X))
3110 (x2 (ly:stencil-extent m2 X))
3111 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
3112 ;; should stack mols separately, to maintain LINE on baseline
3113 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
3115 (ly:stencil-aligned-to stack Y CENTER))
3117 (ly:stencil-aligned-to stack X LEFT))
3118 ;; should have EX dimension
3120 (ly:stencil-translate-axis stack offset Y))))
3122 (define-markup-command (normal-size-super layout props arg)
3125 #:properties ((baseline-skip))
3127 @cindex setting superscript in standard font size
3129 Set @var{arg} in superscript with a normal font size.
3131 @lilypond[verbatim,quote]
3134 \\normal-size-super {
3135 superscript in standard size
3139 (ly:stencil-translate-axis
3140 (interpret-markup layout props arg)
3141 (* 0.5 baseline-skip) Y))
3143 (define-markup-command (super layout props arg)
3146 #:properties ((font-size 0)
3149 @cindex superscript text
3151 Set @var{arg} in superscript.
3153 @lilypond[verbatim,quote]
3163 (ly:stencil-translate-axis
3166 (cons `((font-size . ,(- font-size 3))) props)
3168 (* 0.5 baseline-skip)
3171 (define-markup-command (translate layout props offset arg)
3172 (number-pair? markup?)
3175 @cindex translating text
3177 Translate @var{arg} relative to its surroundings. @var{offset}
3178 is a pair of numbers representing the displacement in the X and Y axis.
3180 @lilypond[verbatim,quote]
3183 \\translate #'(2 . 3)
3184 \\line { translated two spaces right, three up }
3187 (ly:stencil-translate (interpret-markup layout props arg)
3190 (define-markup-command (sub layout props arg)
3193 #:properties ((font-size 0)
3196 @cindex subscript text
3198 Set @var{arg} in subscript.
3200 @lilypond[verbatim,quote]
3211 (ly:stencil-translate-axis
3214 (cons `((font-size . ,(- font-size 3))) props)
3216 (* -0.5 baseline-skip)
3219 (define-markup-command (normal-size-sub layout props arg)
3222 #:properties ((baseline-skip))
3224 @cindex setting subscript in standard font size
3226 Set @var{arg} in subscript with a normal font size.
3228 @lilypond[verbatim,quote]
3232 subscript in standard size
3236 (ly:stencil-translate-axis
3237 (interpret-markup layout props arg)
3238 (* -0.5 baseline-skip)
3241 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3243 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3245 (define-markup-command (hbracket layout props arg)
3249 @cindex placing horizontal brackets around text
3251 Draw horizontal brackets around @var{arg}.
3253 @lilypond[verbatim,quote]
3262 (let ((th 0.1) ;; todo: take from GROB.
3263 (m (interpret-markup layout props arg)))
3264 (bracketify-stencil m X th (* 2.5 th) th)))
3266 (define-markup-command (bracket layout props arg)
3270 @cindex placing vertical brackets around text
3272 Draw vertical brackets around @var{arg}.
3274 @lilypond[verbatim,quote]
3281 (let ((th 0.1) ;; todo: take from GROB.
3282 (m (interpret-markup layout props arg)))
3283 (bracketify-stencil m Y th (* 2.5 th) th)))
3285 (define-markup-command (parenthesize layout props arg)
3288 #:properties ((angularity 0)
3294 @cindex placing parentheses around text
3296 Draw parentheses around @var{arg}. This is useful for parenthesizing
3297 a column containing several lines of text.
3299 @lilypond[verbatim,quote]
3308 \\override #'(angularity . 2) {
3319 (let* ((markup (interpret-markup layout props arg))
3320 (scaled-width (* size width))
3322 (* (chain-assoc-get 'line-thickness props 0.1)
3325 (min (* size 0.5 scaled-thickness)
3326 (* (/ 4 3.0) scaled-width)))
3327 (padding (chain-assoc-get 'padding props half-thickness)))
3328 (parenthesize-stencil
3329 markup half-thickness scaled-width angularity padding)))
3332 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3333 ;; Delayed markup evaluation
3334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3336 (define-markup-command (page-ref layout props label gauge default)
3337 (symbol? markup? markup?)
3340 @cindex referencing page numbers in text
3342 Reference to a page number. @var{label} is the label set on the referenced
3343 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
3344 the maximum width of the page number, and @var{default} the value to display
3345 when @var{label} is not found."
3346 (let* ((gauge-stencil (interpret-markup layout props gauge))
3347 (x-ext (ly:stencil-extent gauge-stencil X))
3348 (y-ext (ly:stencil-extent gauge-stencil Y)))
3350 `(delay-stencil-evaluation
3351 ,(delay (ly:stencil-expr
3352 (let* ((table (ly:output-def-lookup layout 'label-page-table))
3353 (page-number (if (list? table)
3354 (assoc-get label table)
3356 (page-markup (if page-number (format "~a" page-number) default))
3357 (page-stencil (interpret-markup layout props page-markup))
3358 (gap (- (interval-length x-ext)
3359 (interval-length (ly:stencil-extent page-stencil X)))))
3360 (interpret-markup layout props
3361 (markup #:concat (#:hspace gap page-markup)))))))
3365 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3366 ;; Markup list commands
3367 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3369 (define-public (space-lines baseline stils)
3370 (let space-stil ((stils stils)
3374 (let* ((stil (car stils))
3375 (dy-top (max (- (/ baseline 1.5)
3376 (interval-bound (ly:stencil-extent stil Y) UP))
3378 (dy-bottom (max (+ (/ baseline 3.0)
3379 (interval-bound (ly:stencil-extent stil Y) DOWN))
3381 (new-stil (ly:make-stencil
3382 (ly:stencil-expr stil)
3383 (ly:stencil-extent stil X)
3384 (cons (- (interval-bound (ly:stencil-extent stil Y) DOWN)
3386 (+ (interval-bound (ly:stencil-extent stil Y) UP)
3388 (space-stil (cdr stils) (cons new-stil result))))))
3390 (define-markup-list-command (justified-lines layout props args)
3392 #:properties ((baseline-skip)
3393 wordwrap-internal-markup-list)
3395 @cindex justifying lines of text
3397 Like @code{\\justify}, but return a list of lines instead of a single markup.
3398 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
3399 @var{X}@tie{}is the number of staff spaces."
3400 (space-lines baseline-skip
3401 (interpret-markup-list layout props
3402 (make-wordwrap-internal-markup-list #t args))))
3404 (define-markup-list-command (wordwrap-lines layout props args)
3406 #:properties ((baseline-skip)
3407 wordwrap-internal-markup-list)
3408 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
3409 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
3410 where @var{X} is the number of staff spaces."
3411 (space-lines baseline-skip
3412 (interpret-markup-list layout props
3413 (make-wordwrap-internal-markup-list #f args))))
3415 (define-markup-list-command (column-lines layout props args)
3417 #:properties ((baseline-skip))
3418 "Like @code{\\column}, but return a list of lines instead of a single markup.
3419 @code{baseline-skip} determines the space between each markup in @var{args}."
3420 (space-lines baseline-skip
3421 (interpret-markup-list layout props args)))
3423 (define-markup-list-command (override-lines layout props new-prop args)
3424 (pair? markup-list?)
3425 "Like @code{\\override}, for markup lists."
3426 (interpret-markup-list layout (cons (list new-prop) props) args))