1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
10 ;;; * each markup function should have a doc string with
11 ;; syntax, description and example.
13 (use-modules (ice-9 regex))
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
20 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 (define-builtin-markup-command (draw-line layout props dest)
29 "A simple line. Uses the @code{thickness} property."
31 ((th (chain-assoc-get 'thickness props 0.1))
40 (cons (min x 0) (max x 0))
41 (cons (min y 0) (max y 0)))))
45 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
46 (number? number? boolean?)
47 "A circle of radius @var{radius}, thickness @var{thickness} and
49 (make-circle-stencil radius thickness fill))
51 (define-builtin-markup-command (triangle layout props filled) (boolean?)
52 "A triangle, either filled or empty."
54 ((th (chain-assoc-get 'thickness props 0.1))
55 (size (chain-assoc-get 'font-size props 0))
58 (chain-assoc-get 'baseline-skip props 2))))
72 (define-builtin-markup-command (circle layout props arg) (markup?)
73 "Draw a circle around @var{arg}. Use @code{thickness},
74 @code{circle-padding} and @code{font-size} properties to determine line
75 thickness and padding around the markup."
77 (let* ((th (chain-assoc-get 'thickness props 0.1))
78 (size (chain-assoc-get 'font-size props 0))
81 (chain-assoc-get 'circle-padding props 0.2)))
82 (m (interpret-markup layout props arg)))
83 (circle-stencil m th pad)))
85 (define-builtin-markup-command (with-url layout props url arg) (string? markup?)
86 "Add a link to URL @var{url} around @var{arg}. This only works in
88 (let* ((stil (interpret-markup layout props arg))
89 (xextent (ly:stencil-extent stil X))
90 (yextent (ly:stencil-extent stil Y))
91 (old-expr (ly:stencil-expr stil))
92 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
94 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
97 (define-builtin-markup-command (beam layout props width slope thickness)
98 (number? number? number?)
99 "Create a beam with the specified parameters."
100 (let* ((y (* slope width))
101 (yext (cons (min 0 y) (max 0 y)))
102 (half (/ thickness 2)))
107 width (+ (* width slope) (/ thickness -2))
108 width (+ (* width slope) (/ thickness 2))
110 ,(ly:output-def-lookup layout 'blot-diameter)
113 (cons (+ (- half) (car yext))
114 (+ half (cdr yext))))))
116 (define-builtin-markup-command (box layout props arg) (markup?)
117 "Draw a box round @var{arg}. Looks at @code{thickness},
118 @code{box-padding} and @code{font-size} properties to determine line
119 thickness and padding around the markup."
121 (let* ((th (chain-assoc-get 'thickness props 0.1))
122 (size (chain-assoc-get 'font-size props 0))
123 (pad (* (magstep size)
124 (chain-assoc-get 'box-padding props 0.2)))
125 (m (interpret-markup layout props arg)))
126 (box-stencil m th pad)))
128 (define-builtin-markup-command (filled-box layout props xext yext blot)
129 (number-pair? number-pair? number?)
130 "Draw a box with rounded corners of dimensions @var{xext} and
131 @var{yext}. For example,
133 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
135 creates a box extending horizontally from -0.3 to 1.8 and
136 vertically from -0.3 up to 1.8, with corners formed from a
137 circle of diameter@tie{}0 (i.e. sharp corners)."
141 (define-builtin-markup-command (rotate layout props ang arg) (number? markup?)
142 "Rotate object with @var{ang} degrees around its center."
143 (let* ((stil (interpret-markup layout props arg)))
144 (ly:stencil-rotate stil ang 0 0)))
147 (define-builtin-markup-command (whiteout layout props arg) (markup?)
148 "Provide a white underground for @var{arg}."
149 (stencil-whiteout (interpret-markup layout props arg)))
151 (define-builtin-markup-command (pad-markup layout props padding arg) (number? markup?)
152 "Add space around a markup object."
155 ((stil (interpret-markup layout props arg))
156 (xext (ly:stencil-extent stil X))
157 (yext (ly:stencil-extent stil Y)))
160 (ly:stencil-expr stil)
161 (interval-widen xext padding)
162 (interval-widen yext padding))))
164 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
168 ;;FIXME: is this working?
169 (define-builtin-markup-command (strut layout props) ()
170 "Create a box of the same height as the space in the current font."
171 (let ((m (ly:text-interface::interpret-markup layout props " ")))
172 (ly:make-stencil (ly:stencil-expr m)
174 (ly:stencil-extent m X)
178 ;; todo: fix negative space
179 (define-builtin-markup-command (hspace layout props amount) (number?)
180 "This produces a invisible object taking horizontal space. For example,
183 \\markup @{ A \\hspace #2.0 B @}
187 puts extra space between A and@tie{}B, on top of the space that is
188 normally inserted before elements on a line."
190 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
191 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
194 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
195 ;; importing graphics.
196 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
198 (define-builtin-markup-command (stencil layout props stil) (ly:stencil?)
199 "Use a stencil as markup."
203 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
205 (define (get-postscript-bbox string)
206 "Extract the bbox from STRING, or return #f if not present."
208 ((match (regexp-exec bbox-regexp string)))
212 (string->number (match:substring match x)))
217 (define-builtin-markup-command (epsfile layout props axis size file-name) (number? number? string?)
218 "Inline an EPS image. The image is scaled along @var{axis} to
221 (if (ly:get-option 'safe)
222 (interpret-markup layout props "not allowed in safe")
223 (eps-file->stencil axis size file-name)
226 (define-builtin-markup-command (postscript layout props str) (string?)
227 "This inserts @var{str} directly into the output as a PostScript
228 command string. Due to technicalities of the output backends,
229 different scales should be used for the @TeX{} and PostScript backend,
230 selected with @code{-f}.
232 For the @TeX{} backend, the following string prints a rotated text
237 0 0 moveto /ecrm10 findfont
238 1.75 scalefont setfont 90 rotate (hello) show
242 The magical constant 1.75 scales from LilyPond units (staff spaces) to
245 For the postscript backend, use the following
248 gsave /ecrm10 findfont
249 10.0 output-scale div
250 scalefont setfont 90 rotate (hello) show grestore
257 gsave currentpoint translate
266 (define-builtin-markup-command (score layout props score) (ly:score?)
267 "Inline an image of music."
268 (let* ((output (ly:score-embedded-format score layout)))
270 (if (ly:music-output? output)
271 (paper-system-stencil
272 (vector-ref (ly:paper-score-paper-systems output) 0))
274 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
277 (define-builtin-markup-command (null layout props) ()
278 "An empty markup with extents of a single point."
282 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
284 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
288 (define-builtin-markup-command (simple layout props str) (string?)
289 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
290 @code{\\markup @{ \\simple #\"foo\" @}}."
291 (interpret-markup layout props str))
293 (define-builtin-markup-command (tied-lyric layout props str) (string?)
294 "Like simple-markup, but use tie characters for @q{~} tilde symbols."
295 (if (string-contains str "~")
297 ((parts (string-split str #\~))
298 (tie-str (ly:wide-char->utf-8 #x203f))
299 (joined (list-join parts tie-str))
300 (join-stencil (interpret-markup layout props tie-str))
303 (interpret-markup layout
306 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
308 (make-line-markup joined)))
309 ;(map (lambda (s) (interpret-markup layout props s)) parts))
310 (interpret-markup layout props str)))
312 (define-public empty-markup
313 (make-simple-markup ""))
315 ;; helper for justifying lines.
316 (define (get-fill-space word-count line-width text-widths)
317 "Calculate the necessary paddings between each two adjacent texts.
318 The lengths of all texts are stored in @var{text-widths}.
319 The normal formula for the padding between texts a and b is:
320 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
321 The first and last padding have to be calculated specially using the
322 whole length of the first or last text.
323 Return a list of paddings.
326 ((null? text-widths) '())
328 ;; special case first padding
329 ((= (length text-widths) word-count)
331 (- (- (/ line-width (1- word-count)) (car text-widths))
332 (/ (car (cdr text-widths)) 2))
333 (get-fill-space word-count line-width (cdr text-widths))))
334 ;; special case last padding
335 ((= (length text-widths) 2)
336 (list (- (/ line-width (1- word-count))
337 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
340 (- (/ line-width (1- word-count))
341 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
342 (get-fill-space word-count line-width (cdr text-widths))))))
344 (define-builtin-markup-command (fill-line layout props markups)
346 "Put @var{markups} in a horizontal line of width @var{line-width}.
347 The markups are spaced or flushed to fill the entire line.
348 If there are no arguments, return an empty stencil."
350 (let* ((orig-stencils (interpret-markup-list layout props markups))
353 (if (ly:stencil-empty? stc)
355 stc)) orig-stencils))
358 (if (ly:stencil-empty? stc)
360 (interval-length (ly:stencil-extent stc X))))
362 (text-width (apply + text-widths))
363 (text-dir (chain-assoc-get 'text-direction props RIGHT))
364 (word-count (length stencils))
365 (word-space (chain-assoc-get 'word-space props 1))
366 (prop-line-width (chain-assoc-get 'line-width props #f))
367 (line-width (if prop-line-width prop-line-width
368 (ly:output-def-lookup layout 'line-width)))
373 (/ (- line-width text-width) 2)
374 (/ (- line-width text-width) 2)))
377 (- line-width text-width)))
379 (get-fill-space word-count line-width text-widths))))
387 (line-stencils (if (= word-count 1)
394 (if (= text-dir LEFT)
395 (set! line-stencils (reverse line-stencils)))
397 (if (null? (remove ly:stencil-empty? orig-stencils))
399 (stack-stencils-padding-list X
400 RIGHT fill-space-normal line-stencils))))
402 (define-builtin-markup-command (line layout props args) (markup-list?)
403 "Put @var{args} in a horizontal line. The property @code{word-space}
404 determines the space between each markup in @var{args}."
406 ((stencils (interpret-markup-list layout props args))
407 (space (chain-assoc-get 'word-space props))
408 (text-dir (chain-assoc-get 'text-direction props RIGHT))
411 (if (= text-dir LEFT)
412 (set! stencils (reverse stencils)))
417 (remove ly:stencil-empty? stencils))))
419 (define-builtin-markup-command (concat layout props args) (markup-list?)
420 "Concatenate @var{args} in a horizontal line, without spaces inbetween.
421 Strings and simple markups are concatenated on the input level, allowing
422 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
423 equivalent to @code{\"fi\"}."
425 (define (concat-string-args arg-list)
426 (fold-right (lambda (arg result-list)
427 (let ((result (if (pair? result-list)
430 (if (and (pair? arg) (eqv? (car arg) simple-markup))
431 (set! arg (cadr arg)))
432 (if (and (string? result) (string? arg))
433 (cons (string-append arg result) (cdr result-list))
434 (cons arg result-list))))
438 (interpret-markup layout
439 (prepend-alist-chain 'word-space 0 props)
440 (make-line-markup (if (markup-command-list? args)
442 (concat-string-args args)))))
444 (define (wordwrap-stencils stencils
445 justify base-space line-width text-dir)
447 "Perform simple wordwrap, return stencil of each line."
449 (define space (if justify
451 ;; justify only stretches lines.
455 (define (take-list width space stencils
456 accumulator accumulated-width)
457 "Return (head-list . tail) pair, with head-list fitting into width"
459 (cons accumulator stencils)
461 ((first (car stencils))
462 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
463 (newwid (+ space first-wid accumulated-width))
467 (or (null? accumulator)
470 (take-list width space
472 (cons first accumulator)
474 (cons accumulator stencils))
482 ((line-break (take-list line-width space todo
484 (line-stencils (car line-break))
485 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
488 (line-word-space (cond
489 ((not justify) space)
491 ;; don't stretch last line of paragraph.
492 ;; hmmm . bug - will overstretch the last line in some case.
493 ((null? (cdr line-break))
495 ((null? line-stencils) 0.0)
496 ((null? (cdr line-stencils)) 0.0)
497 (else (/ space-left (1- (length line-stencils))))))
499 (line (stack-stencil-line
501 (if (= text-dir RIGHT)
502 (reverse line-stencils)
505 (if (pair? (cdr line-break))
506 (loop (cons line lines)
510 (if (= text-dir LEFT)
512 (ly:stencil-translate-axis line
513 (- line-width (interval-end (ly:stencil-extent line X)))
515 (reverse (cons line lines))
522 (define (wordwrap-markups layout props args justify)
524 ((prop-line-width (chain-assoc-get 'line-width props #f))
525 (line-width (if prop-line-width prop-line-width
526 (ly:output-def-lookup layout 'line-width)))
527 (word-space (chain-assoc-get 'word-space props))
528 (text-dir (chain-assoc-get 'text-direction props RIGHT)))
529 (wordwrap-stencils (remove ly:stencil-empty?
530 (interpret-markup-list layout props args))
531 justify word-space line-width
534 (define-builtin-markup-command (justify layout props args) (markup-list?)
535 "Like wordwrap, but with lines stretched to justify the margins.
536 Use @code{\\override #'(line-width . @var{X})} to set the line width;
537 @var{X}@tie{}is the number of staff spaces."
538 (stack-lines DOWN 0.0 (chain-assoc-get 'baseline-skip props)
539 (wordwrap-markups layout props args #t)))
541 (define-builtin-markup-command (wordwrap layout props args) (markup-list?)
542 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
543 the line width, where @var{X} is the number of staff spaces."
544 (stack-lines DOWN 0.0 (chain-assoc-get 'baseline-skip props)
545 (wordwrap-markups layout props args #f)))
547 (define (wordwrap-string layout props justify arg)
549 ((baseline-skip (chain-assoc-get 'baseline-skip props))
550 (line-width (chain-assoc-get 'line-width props))
551 (word-space (chain-assoc-get 'word-space props))
553 (para-strings (regexp-split
554 (string-regexp-substitute "\r" "\n"
555 (string-regexp-substitute "\r\n" "\n" arg))
556 "\n[ \t\n]*\n[ \t\n]*"))
558 (text-dir (chain-assoc-get 'text-direction props RIGHT))
559 (list-para-words (map (lambda (str)
560 (regexp-split str "[ \t\n]+"))
562 (para-lines (map (lambda (words)
566 ly:stencil-empty? (map
568 (interpret-markup layout props x))
570 (lines (wordwrap-stencils stencils
579 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
582 (define-builtin-markup-command (wordwrap-string layout props arg) (string?)
583 "Wordwrap a string. Paragraphs may be separated with double newlines."
584 (wordwrap-string layout props #f arg))
586 (define-builtin-markup-command (justify-string layout props arg) (string?)
587 "Justify a string. Paragraphs may be separated with double newlines"
588 (wordwrap-string layout props #t arg))
591 (define-builtin-markup-command (wordwrap-field layout props symbol) (symbol?)
592 "Wordwrap the data which has been assigned to @var{symbol}."
593 (let* ((m (chain-assoc-get symbol props)))
595 (interpret-markup layout props
596 (list wordwrap-string-markup m))
597 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
599 (define-builtin-markup-command (justify-field layout props symbol) (symbol?)
600 "Justify the data which has been assigned to @var{symbol}."
601 (let* ((m (chain-assoc-get symbol props)))
603 (interpret-markup layout props
604 (list justify-string-markup m))
605 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
609 (define-builtin-markup-command (combine layout props m1 m2) (markup? markup?)
610 "Print two markups on top of each other."
611 (let* ((s1 (interpret-markup layout props m1))
612 (s2 (interpret-markup layout props m2)))
613 (ly:stencil-add s1 s2)))
616 ;; TODO: should extract baseline-skip from each argument somehow..
618 (define-builtin-markup-command (column layout props args) (markup-list?)
619 "Stack the markups in @var{args} vertically. The property
620 @code{baseline-skip} determines the space between each markup in @var{args}."
623 ((arg-stencils (interpret-markup-list layout props args))
624 (skip (chain-assoc-get 'baseline-skip props)))
629 (remove ly:stencil-empty? arg-stencils))))
632 (define-builtin-markup-command (dir-column layout props args) (markup-list?)
633 "Make a column of args, going up or down, depending on the setting
634 of the @code{#'direction} layout property."
635 (let* ((dir (chain-assoc-get 'direction props)))
637 (if (number? dir) dir -1)
639 (chain-assoc-get 'baseline-skip props)
640 (interpret-markup-list layout props args))))
642 (define-builtin-markup-command (center-align layout props args) (markup-list?)
643 "Put @code{args} in a centered column."
644 (let* ((mols (interpret-markup-list layout props args))
645 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
647 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
649 (define-builtin-markup-command (vcenter layout props arg) (markup?)
650 "Align @code{arg} to its Y@tie{}center."
651 (let* ((mol (interpret-markup layout props arg)))
652 (ly:stencil-aligned-to mol Y CENTER)))
654 (define-builtin-markup-command (hcenter layout props arg) (markup?)
655 "Align @code{arg} to its X@tie{}center."
656 (let* ((mol (interpret-markup layout props arg)))
657 (ly:stencil-aligned-to mol X CENTER)))
659 (define-builtin-markup-command (right-align layout props arg) (markup?)
660 "Align @var{arg} on its right edge."
661 (let* ((m (interpret-markup layout props arg)))
662 (ly:stencil-aligned-to m X RIGHT)))
664 (define-builtin-markup-command (left-align layout props arg) (markup?)
665 "Align @var{arg} on its left edge."
666 (let* ((m (interpret-markup layout props arg)))
667 (ly:stencil-aligned-to m X LEFT)))
669 (define-builtin-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
670 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
671 (let* ((m (interpret-markup layout props arg)))
672 (ly:stencil-aligned-to m axis dir)))
674 (define-builtin-markup-command (halign layout props dir arg) (number? markup?)
675 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
676 left-aligned, while @code{+1} is right. Values inbetween interpolate
677 alignment accordingly."
678 (let* ((m (interpret-markup layout props arg)))
679 (ly:stencil-aligned-to m X dir)))
683 (define-builtin-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
684 "Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
686 (let* ((m (interpret-markup layout props arg)))
687 (ly:make-stencil (ly:stencil-expr m) x y)))
690 (define-builtin-markup-command (pad-around layout props amount arg) (number? markup?)
691 "Add padding @var{amount} all around @var{arg}."
694 ((m (interpret-markup layout props arg))
695 (x (ly:stencil-extent m X))
696 (y (ly:stencil-extent m Y)))
699 (ly:make-stencil (ly:stencil-expr m)
700 (interval-widen x amount)
701 (interval-widen y amount))
705 (define-builtin-markup-command (pad-x layout props amount arg) (number? markup?)
706 "Add padding @var{amount} around @var{arg} in the X@tie{}direction."
708 ((m (interpret-markup layout props arg))
709 (x (ly:stencil-extent m X))
710 (y (ly:stencil-extent m Y)))
713 (ly:make-stencil (ly:stencil-expr m)
714 (interval-widen x amount)
719 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
720 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
721 (let* ((m1 (interpret-markup layout props arg1))
722 (m2 (interpret-markup layout props arg2)))
724 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)
727 (define-builtin-markup-command (transparent layout props arg) (markup?)
728 "Make the argument transparent."
730 ((m (interpret-markup layout props arg))
731 (x (ly:stencil-extent m X))
732 (y (ly:stencil-extent m Y)))
740 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
741 (number-pair? number-pair? markup?)
742 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
745 ((m (interpret-markup layout props arg))
746 (x (ly:stencil-extent m X))
747 (y (ly:stencil-extent m Y)))
749 (ly:make-stencil (ly:stencil-expr m)
750 (interval-union x-ext x)
751 (interval-union y-ext y))))
754 (define-builtin-markup-command (hcenter-in layout props length arg)
756 "Center @var{arg} horizontally within a box of extending
757 @var{length}/2 to the left and right."
759 (interpret-markup layout props
760 (make-pad-to-box-markup
761 (cons (/ length -2) (/ length 2))
763 (make-hcenter-markup arg))))
766 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
768 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
770 (define-builtin-markup-command (fromproperty layout props symbol) (symbol?)
771 "Read the @var{symbol} from property settings, and produce a stencil
772 from the markup contained within. If @var{symbol} is not defined, it
773 returns an empty markup."
774 (let* ((m (chain-assoc-get symbol props)))
776 (interpret-markup layout props m)
777 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
780 (define-builtin-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
781 "Apply the @var{procedure} markup command to @var{arg}.
782 @var{procedure} should take a single argument."
783 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
784 (set-object-property! anonymous-with-signature
787 (interpret-markup layout props (list anonymous-with-signature arg))))
791 (define-builtin-markup-command (override layout props new-prop arg) (pair? markup?)
792 "Add the first argument in to the property list. Properties may be
793 any sort of property supported by @internalsref{font-interface} and
794 @internalsref{text-interface}, for example
797 \\override #'(font-family . married) \"bla\"
799 (interpret-markup layout (cons (list new-prop) props) arg))
801 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
803 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
805 (define-builtin-markup-command (verbatim-file layout props name) (string?)
806 "Read the contents of a file, and include it verbatim."
810 (if (ly:get-option 'safe)
811 "verbatim-file disabled in safe mode"
813 ((str (ly:gulp-file name))
814 (lines (string-split str #\nl)))
816 (make-typewriter-markup
817 (make-column-markup lines)))
820 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
822 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
825 (define-builtin-markup-command (bigger layout props arg) (markup?)
826 "Increase the font size relative to current setting."
827 (interpret-markup layout props
828 `(,fontsize-markup 1 ,arg)))
830 (define-builtin-markup-command (smaller layout props arg) (markup?)
831 "Decrease the font size relative to current setting."
832 (interpret-markup layout props
833 `(,fontsize-markup -1 ,arg)))
835 (define-builtin-markup-command larger (markup?) bigger-markup)
837 (define-builtin-markup-command (finger layout props arg) (markup?)
838 "Set the argument as small numbers."
839 (interpret-markup layout
840 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
844 (define-builtin-markup-command (fontsize layout props increment arg) (number? markup?)
845 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
847 (let* ((fs (chain-assoc-get 'font-size props 0))
848 (bs (chain-assoc-get 'baseline-skip props 2))
850 (cons 'baseline-skip (* bs (magstep increment)))
851 (cons 'font-size (+ fs increment )))))
853 (interpret-markup layout (cons entries props) arg)))
855 (define-builtin-markup-command (magnify layout props sz arg) (number? markup?)
856 "Set the font magnification for its argument. In the following
857 example, the middle@tie{}A is 10% larger:
860 A \\magnify #1.1 @{ A @} A
863 Note: Magnification only works if a font name is explicitly selected.
864 Use @code{\\fontsize} otherwise."
867 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
870 (define-builtin-markup-command (bold layout props arg) (markup?)
871 "Switch to bold font-series."
872 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
874 (define-builtin-markup-command (sans layout props arg) (markup?)
875 "Switch to the sans serif family."
876 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
878 (define-builtin-markup-command (number layout props arg) (markup?)
879 "Set font family to @code{number}, which yields the font used for
880 time signatures and fingerings. This font only contains numbers and
881 some punctuation. It doesn't have any letters."
882 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
884 (define-builtin-markup-command (roman layout props arg) (markup?)
885 "Set font family to @code{roman}."
886 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
888 (define-builtin-markup-command (huge layout props arg) (markup?)
889 "Set font size to +2."
890 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
892 (define-builtin-markup-command (large layout props arg) (markup?)
893 "Set font size to +1."
894 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
896 (define-builtin-markup-command (normalsize layout props arg) (markup?)
897 "Set font size to default."
898 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
900 (define-builtin-markup-command (small layout props arg) (markup?)
901 "Set font size to -1."
902 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
904 (define-builtin-markup-command (tiny layout props arg) (markup?)
905 "Set font size to -2."
906 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
908 (define-builtin-markup-command (teeny layout props arg) (markup?)
909 "Set font size to -3."
910 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
912 (define-builtin-markup-command (fontCaps layout props arg) (markup?)
913 "Set @code{font-shape} to @code{caps}."
914 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
917 (define-builtin-markup-command (smallCaps layout props text) (markup?)
918 "Turn @code{text}, which should be a string, to small caps.
920 \\markup \\smallCaps \"Text between double quotes\"
922 (define (make-small-caps-markup chars)
925 ((char-whitespace? (car chars))
926 (markup #:fontsize -2 #:simple (string-upcase (list->string (cdr chars)))))
929 #:fontsize -2 #:simple (string-upcase (list->string chars))))))
930 (define (make-not-small-caps-markup chars)
933 ((char-whitespace? (car chars))
934 (markup #:simple (list->string (cdr chars))))
937 #:simple (list->string chars)))))
938 (define (small-caps-aux done-markups current-chars rest-chars small? after-space?)
939 (cond ((null? rest-chars)
940 ;; the end of the string: build the markup
941 (make-line-markup (reverse! (cons ((if small?
942 make-small-caps-markup
943 make-not-small-caps-markup)
944 (reverse! current-chars))
946 ((char-whitespace? (car rest-chars))
948 (small-caps-aux done-markups current-chars (cdr rest-chars) small? #t))
949 ((or (and small? (char-lower-case? (car rest-chars)))
950 (and (not small?) (not (char-lower-case? (car rest-chars)))))
952 ;; add the char to the current char list
953 (small-caps-aux done-markups
954 (cons (car rest-chars)
956 (cons #\space current-chars)
963 ;; make a markup with current chars, and start a new list with new char
964 (small-caps-aux (cons ((if small?
965 make-small-caps-markup
966 make-not-small-caps-markup)
967 (reverse! current-chars))
970 (list (car rest-chars) #\space)
971 (list (car rest-chars)))
975 (interpret-markup layout props (small-caps-aux (list)
977 (cons #\space (string->list text))
981 (define-builtin-markup-command (caps layout props arg) (markup?)
982 "Emit @var{arg} as small caps."
983 (interpret-markup layout props (make-smallCaps-markup arg)))
985 (define-builtin-markup-command (dynamic layout props arg) (markup?)
986 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
987 @b{z}, @b{p}, and @b{r}. When producing phrases, like
988 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
989 done in a different font. The recommended font for this is bold and italic."
991 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
993 (define-builtin-markup-command (text layout props arg) (markup?)
994 "Use a text font instead of music symbol or music alphabet font."
997 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1001 (define-builtin-markup-command (italic layout props arg) (markup?)
1002 "Use italic @code{font-shape} for @var{arg}."
1003 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1005 (define-builtin-markup-command (typewriter layout props arg) (markup?)
1006 "Use @code{font-family} typewriter for @var{arg}."
1008 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1010 (define-builtin-markup-command (upright layout props arg) (markup?)
1011 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1013 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1015 (define-builtin-markup-command (medium layout props arg) (markup?)
1016 "Switch to medium font series (in contrast to bold)."
1017 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1020 (define-builtin-markup-command (normal-text layout props arg) (markup?)
1021 "Set all font related properties (except the size) to get the default
1022 normal text font, no matter what font was used earlier."
1024 (interpret-markup layout
1025 (cons '((font-family . roman) (font-shape . upright)
1026 (font-series . medium) (font-encoding . latin1))
1030 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1032 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1034 (define-builtin-markup-command (doublesharp layout props) ()
1035 "Draw a double sharp symbol."
1037 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1039 (define-builtin-markup-command (sesquisharp layout props) ()
1040 "Draw a 3/2 sharp symbol."
1041 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1044 (define-builtin-markup-command (sharp layout props) ()
1045 "Draw a sharp symbol."
1046 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1048 (define-builtin-markup-command (semisharp layout props) ()
1049 "Draw a semi sharp symbol."
1050 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1052 (define-builtin-markup-command (natural layout props) ()
1053 "Draw a natural symbol."
1054 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1056 (define-builtin-markup-command (semiflat layout props) ()
1058 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1060 (define-builtin-markup-command (flat layout props) ()
1061 "Draw a flat symbol."
1062 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1064 (define-builtin-markup-command (sesquiflat layout props) ()
1065 "Draw a 3/2 flat symbol."
1066 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1068 (define-builtin-markup-command (doubleflat layout props) ()
1069 "Draw a double flat symbol."
1070 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1072 (define-builtin-markup-command (with-color layout props color arg) (color? markup?)
1073 "Draw @var{arg} in color specified by @var{color}."
1075 (let* ((stil (interpret-markup layout props arg)))
1077 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1078 (ly:stencil-extent stil X)
1079 (ly:stencil-extent stil Y))))
1082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087 (define-builtin-markup-command (arrow-head layout props axis direction filled)
1088 (integer? ly:dir? boolean?)
1089 "Produce an arrow head in specified direction and axis.
1090 Use the filled head if @var{filled} is specified."
1092 ((name (format "arrowheads.~a.~a~a"
1099 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1103 (define-builtin-markup-command (musicglyph layout props glyph-name) (string?)
1104 "@var{glyph0name} is converted to a musical symbol; for example,
1105 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
1106 the music font. See @usermanref{The Feta font} for a complete listing of
1107 the possible glyphs."
1109 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1113 (define-builtin-markup-command (lookup layout props glyph-name) (string?)
1114 "Lookup a glyph by name."
1115 (ly:font-get-glyph (ly:paper-get-font layout props)
1118 (define-builtin-markup-command (char layout props num) (integer?)
1119 "Produce a single character. For example, @code{\\char #65} produces the
1122 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1124 (define number->mark-letter-vector (make-vector 25 #\A))
1129 (if (= i (- (char->integer #\I) (char->integer #\A)))
1131 (vector-set! number->mark-letter-vector j
1132 (integer->char (+ i (char->integer #\A)))))
1134 (define number->mark-alphabet-vector (list->vector
1135 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1137 (define (number->markletter-string vec n)
1138 "Double letters for big marks."
1139 (let* ((lst (vector-length vec)))
1142 (string-append (number->markletter-string vec (1- (quotient n lst)))
1143 (number->markletter-string vec (remainder n lst)))
1144 (make-string 1 (vector-ref vec n)))))
1146 (define-builtin-markup-command (markletter layout props num) (integer?)
1147 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1148 (skipping letter@tie{}I), and continue with double letters."
1149 (ly:text-interface::interpret-markup layout props
1150 (number->markletter-string number->mark-letter-vector num)))
1152 (define-builtin-markup-command (markalphabet layout props num) (integer?)
1153 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1154 and continue with double letters."
1155 (ly:text-interface::interpret-markup layout props
1156 (number->markletter-string number->mark-alphabet-vector num)))
1160 (define-builtin-markup-command (slashed-digit layout props num) (integer?)
1161 "A feta number, with slash. This is for use in the context of
1162 figured bass notation."
1164 ((mag (magstep (chain-assoc-get 'font-size props 0)))
1167 (chain-assoc-get 'thickness props 0.16)))
1169 (number-stencil (interpret-markup layout
1170 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1171 (number->string num)))
1172 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1174 (num-y (ly:stencil-extent number-stencil Y))
1175 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
1182 ,(car num-x) ,(- (interval-center num-y) dy)
1183 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1189 ((not (ly:stencil? slash-stencil)) #f)
1190 ((= num 5) (ly:stencil-translate slash-stencil
1191 ;;(cons (* mag -0.05) (* mag 0.42))
1192 (cons (* mag -0.00) (* mag -0.07))
1195 ((= num 7) (ly:stencil-translate slash-stencil
1196 ;;(cons (* mag -0.05) (* mag 0.42))
1197 (cons (* mag -0.00) (* mag -0.15))
1201 (else slash-stencil)))
1204 (set! number-stencil
1205 (ly:stencil-add number-stencil slash-stencil))
1207 (ly:warning "invalid number for slashed digit ~a" num))
1212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1213 ;; the note command.
1214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1217 ;; TODO: better syntax.
1219 (define-builtin-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1220 "Construct a note symbol, with stem. By using fractional values for
1221 @var{dir}, you can obtain longer or shorter stems."
1223 (define (get-glyph-name-candidates dir log style)
1224 (map (lambda (dir-name)
1225 (format "noteheads.~a~a~a" dir-name (min log 2)
1226 (if (and (symbol? style)
1227 (not (equal? 'default style)))
1228 (symbol->string style)
1230 (list (if (= dir UP) "u" "d")
1233 (define (get-glyph-name font cands)
1236 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1237 (get-glyph-name font (cdr cands))
1240 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1241 (size-factor (magstep (chain-assoc-get 'font-size props 0)))
1242 (style (chain-assoc-get 'style props '()))
1243 (stem-length (* size-factor (max 3 (- log 1))))
1244 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
1245 (head-glyph (ly:font-get-glyph font head-glyph-name))
1246 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1247 (stem-thickness (* size-factor 0.13))
1248 (stemy (* dir stem-length))
1249 (attach-off (cons (interval-index
1250 (ly:stencil-extent head-glyph X)
1251 (* (sign dir) (car attach-indices)))
1252 (* (sign dir) ; fixme, this is inconsistent between X & Y.
1254 (ly:stencil-extent head-glyph Y)
1255 (cdr attach-indices)))))
1256 (stem-glyph (and (> log 0)
1257 (ly:round-filled-box
1258 (ordered-cons (car attach-off)
1259 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
1260 (cons (min stemy (cdr attach-off))
1261 (max stemy (cdr attach-off)))
1262 (/ stem-thickness 3))))
1264 (dot (ly:font-get-glyph font "dots.dot"))
1265 (dotwid (interval-length (ly:stencil-extent dot X)))
1266 (dots (and (> dot-count 0)
1267 (apply ly:stencil-add
1269 (ly:stencil-translate-axis
1270 dot (* 2 x dotwid) X))
1271 (iota dot-count)))))
1272 (flaggl (and (> log 2)
1273 (ly:stencil-translate
1274 (ly:font-get-glyph font
1275 (string-append "flags."
1276 (if (> dir 0) "u" "d")
1277 (number->string log)))
1278 (cons (+ (car attach-off) (/ stem-thickness 2)) stemy)))))
1280 (if (and dots flaggl (> dir 0))
1281 (set! dots (ly:stencil-translate-axis dots 0.35 X)))
1283 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1284 (if (ly:stencil? stem-glyph)
1285 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1286 (set! stem-glyph head-glyph))
1287 (if (ly:stencil? dots)
1290 (ly:stencil-translate-axis
1292 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
1298 (let ((divisor (log 2)))
1299 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1301 (define (parse-simple-duration duration-string)
1302 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1303 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1304 (if (and match (string=? duration-string (match:substring match 0)))
1305 (let ((len (match:substring match 1))
1306 (dots (match:substring match 2)))
1307 (list (cond ((string=? len "breve") -1)
1308 ((string=? len "longa") -2)
1309 ((string=? len "maxima") -3)
1310 (else (log2 (string->number len))))
1311 (if dots (string-length dots) 0)))
1312 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1314 (define-builtin-markup-command (note layout props duration dir) (string? number?)
1315 "This produces a note with a stem pointing in @var{dir} direction, with
1316 the @var{duration} for the note head type and augmentation dots. For
1317 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1318 a shortened down stem."
1319 (let ((parsed (parse-simple-duration duration)))
1320 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1327 (define-builtin-markup-command (lower layout props amount arg) (number? markup?)
1328 "Lower @var{arg} by the distance @var{amount}.
1329 A negative @var{amount} indicates raising; see also @code{\\raise}."
1330 (ly:stencil-translate-axis (interpret-markup layout props arg)
1334 (define-builtin-markup-command (translate-scaled layout props offset arg) (number-pair? markup?)
1335 "Translate @var{arg} by @var{offset}, scaling the offset by the
1338 ((factor (magstep (chain-assoc-get 'font-size props 0)))
1339 (scaled (cons (* factor (car offset))
1340 (* factor (cdr offset)))))
1342 (ly:stencil-translate (interpret-markup layout props arg)
1345 (define-builtin-markup-command (raise layout props amount arg) (number? markup?)
1346 "Raise @var{arg} by the distance @var{amount}.
1347 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1349 @lilypond[verbatim,fragment,relative=1]
1350 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" } }
1352 The argument to @code{\\raise} is the vertical displacement amount,
1353 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1354 raise objects in relation to their surrounding markups.
1356 If the text object itself is positioned above or below the staff, then
1357 @code{\\raise} cannot be used to move it, since the mechanism that
1358 positions it next to the staff cancels any shift made with
1359 @code{\\raise}. For vertical positioning, use the @code{padding}
1360 and/or @code{extra-offset} properties."
1361 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1363 (define-builtin-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1364 "Make a fraction of two markups."
1365 (let* ((m1 (interpret-markup layout props arg1))
1366 (m2 (interpret-markup layout props arg2))
1367 (factor (magstep (chain-assoc-get 'font-size props 0)))
1368 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
1369 (padding (* factor 0.2))
1370 (baseline (* factor 0.6))
1371 (offset (* factor 0.75)))
1372 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1373 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1374 (let* ((x1 (ly:stencil-extent m1 X))
1375 (x2 (ly:stencil-extent m2 X))
1376 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
1377 ;; should stack mols separately, to maintain LINE on baseline
1378 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
1380 (ly:stencil-aligned-to stack Y CENTER))
1382 (ly:stencil-aligned-to stack X LEFT))
1383 ;; should have EX dimension
1385 (ly:stencil-translate-axis stack offset Y))))
1387 (define-builtin-markup-command (normal-size-super layout props arg) (markup?)
1388 "Set @var{arg} in superscript with a normal font size."
1389 (ly:stencil-translate-axis
1390 (interpret-markup layout props arg)
1391 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1393 (define-builtin-markup-command (super layout props arg) (markup?)
1395 @cindex raising text
1396 @cindex lowering text
1398 @cindex translating text
1400 @cindex @code{\\super}
1402 Raising and lowering texts can be done with @code{\\super} and
1405 @lilypond[verbatim,fragment,relative=1]
1406 c1^\\markup { E \"=\" \\concat { \"mc\" \\super \"2\" } }
1408 (ly:stencil-translate-axis
1411 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1413 (* 0.5 (chain-assoc-get 'baseline-skip props))
1416 (define-builtin-markup-command (translate layout props offset arg) (number-pair? markup?)
1417 "This translates an object. Its first argument is a cons of numbers.
1420 A \\translate #(cons 2 -3) @{ B C @} D
1423 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
1424 surroundings. This command cannot be used to move isolated scripts
1425 vertically, for the same reason that @code{\\raise} cannot be used for
1427 (ly:stencil-translate (interpret-markup layout props arg)
1430 (define-builtin-markup-command (sub layout props arg) (markup?)
1431 "Set @var{arg} in subscript."
1432 (ly:stencil-translate-axis
1435 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1437 (* -0.5 (chain-assoc-get 'baseline-skip props))
1440 (define-builtin-markup-command (normal-size-sub layout props arg) (markup?)
1441 "Set @var{arg} in subscript, in a normal font size."
1442 (ly:stencil-translate-axis
1443 (interpret-markup layout props arg)
1444 (* -0.5 (chain-assoc-get 'baseline-skip props))
1447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1451 (define-builtin-markup-command (hbracket layout props arg) (markup?)
1452 "Draw horizontal brackets around @var{arg}."
1453 (let ((th 0.1) ;; todo: take from GROB.
1454 (m (interpret-markup layout props arg)))
1455 (bracketify-stencil m X th (* 2.5 th) th)))
1457 (define-builtin-markup-command (bracket layout props arg) (markup?)
1458 "Draw vertical brackets around @var{arg}."
1459 (let ((th 0.1) ;; todo: take from GROB.
1460 (m (interpret-markup layout props arg)))
1461 (bracketify-stencil m Y th (* 2.5 th) th)))
1463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1464 ;; Delayed markup evaluation
1465 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1467 (define-builtin-markup-command (page-ref layout props label gauge default)
1468 (symbol? markup? markup?)
1469 "Reference to a page number. @var{label} is the label set on the referenced
1470 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
1471 the maximum width of the page number, and @var{default} the value to display
1472 when @var{label} is not found."
1473 (let* ((gauge-stencil (interpret-markup layout props gauge))
1474 (x-ext (ly:stencil-extent gauge-stencil X))
1475 (y-ext (ly:stencil-extent gauge-stencil Y)))
1477 `(delay-stencil-evaluation
1478 ,(delay (ly:stencil-expr
1479 (let* ((table (ly:output-def-lookup layout 'label-page-table))
1480 (label-page (and (list? table) (assoc label table)))
1481 (page-number (and label-page (cdr label-page)))
1482 (page-markup (if page-number (format "~a" page-number) default))
1483 (page-stencil (interpret-markup layout props page-markup))
1484 (gap (- (interval-length x-ext)
1485 (interval-length (ly:stencil-extent page-stencil X)))))
1486 (interpret-markup layout props
1487 (markup #:concat (#:hspace gap page-markup)))))))
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1493 ;; Markup list commands
1494 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1496 (define-public (space-lines baseline-skip lines)
1498 (stack-lines DOWN 0.0 (/ baseline-skip 2.0)
1499 (list (ly:make-stencil "" (cons 0 0) (cons 0 0))
1501 (ly:make-stencil "" (cons 0 0) (cons 0 0)))))
1504 (define-builtin-markup-list-command (justified-lines layout props args) (markup-list?)
1505 "Like @code{\\justify}, but return a list of lines instead of a single markup.
1506 Use @code{\\override #'(line-width . @var{X})} to set the line width;
1507 @var{X}@tie{}is the number of staff spaces."
1508 (space-lines (chain-assoc-get 'baseline-skip props)
1509 (wordwrap-markups layout props args #t)))
1511 (define-builtin-markup-list-command (wordwrap-lines layout props args) (markup-list?)
1512 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
1513 Use @code{\\override #'(line-width . @var{X})} to set the line width,
1514 where @var{X} is the number of staff spaces."
1515 (space-lines (chain-assoc-get 'baseline-skip props)
1516 (wordwrap-markups layout props args #f)))
1518 (define-builtin-markup-list-command (column-lines layout props args) (markup-list?)
1519 "Like @code{\\column}, but return a list of lines instead of a single markup.
1520 @code{baseline-skip} determines the space between each markup in @var{args}."
1521 (space-lines (chain-assoc-get 'baseline-skip props)
1522 (interpret-markup-list layout props args)))
1524 (define-builtin-markup-list-command (override-lines layout props new-prop args)
1525 (pair? markup-list?)
1526 "Like @code{\\override}, for markup lists."
1527 (interpret-markup-list layout (cons (list new-prop) props) args))