1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2007 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."
32 (ly:output-def-lookup layout 'line-thickness)
33 (chain-assoc-get 'thickness props 1)))
42 (cons (min x 0) (max x 0))
43 (cons (min y 0) (max y 0)))))
47 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
48 (number? number? boolean?)
49 "A circle of radius @var{radius}, thickness @var{thickness} and
51 (make-circle-stencil radius thickness fill))
53 (define-builtin-markup-command (triangle layout props filled) (boolean?)
54 "A triangle, either filled or empty."
56 ((th (chain-assoc-get 'thickness props 0.1))
57 (size (chain-assoc-get 'font-size props 0))
60 (chain-assoc-get 'baseline-skip props 2))))
74 (define-builtin-markup-command (circle layout props arg) (markup?)
75 "Draw a circle around @var{arg}. Use @code{thickness},
76 @code{circle-padding} and @code{font-size} properties to determine line
77 thickness and padding around the markup."
80 (* (ly:output-def-lookup layout 'line-thickness)
81 (chain-assoc-get 'thickness props 1)))
82 (size (chain-assoc-get 'font-size props 0))
85 (chain-assoc-get 'circle-padding props 0.2)))
86 (m (interpret-markup layout props arg)))
87 (circle-stencil m th pad)))
89 (define-builtin-markup-command (with-url layout props url arg) (string? markup?)
90 "Add a link to URL @var{url} around @var{arg}. This only works in
92 (let* ((stil (interpret-markup layout props arg))
93 (xextent (ly:stencil-extent stil X))
94 (yextent (ly:stencil-extent stil Y))
95 (old-expr (ly:stencil-expr stil))
96 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
98 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
101 (define-builtin-markup-command (beam layout props width slope thickness)
102 (number? number? number?)
103 "Create a beam with the specified parameters."
104 (let* ((y (* slope width))
105 (yext (cons (min 0 y) (max 0 y)))
106 (half (/ thickness 2)))
111 width (+ (* width slope) (/ thickness -2))
112 width (+ (* width slope) (/ thickness 2))
114 ,(ly:output-def-lookup layout 'blot-diameter)
117 (cons (+ (- half) (car yext))
118 (+ half (cdr yext))))))
120 (define-builtin-markup-command (underline layout props arg) (markup?)
121 "Underline @var{arg}. Looks at @code{thickness} to determine line
122 thickness and y offset."
124 (ly:output-def-lookup layout 'line-thickness)
125 (chain-assoc-get 'thickness props 1)))
126 (markup (interpret-markup layout props arg))
127 (x1 (car (ly:stencil-extent markup X)))
128 (x2 (cdr (ly:stencil-extent markup X)))
130 (line (ly:make-stencil
131 `(draw-line ,thick ,x1 ,y ,x2 ,y)
132 (cons (min x1 0) (max x2 0))
133 (cons thick thick))))
134 (ly:stencil-add markup line)))
136 (define-builtin-markup-command (box layout props arg) (markup?)
137 "Draw a box round @var{arg}. Looks at @code{thickness},
138 @code{box-padding} and @code{font-size} properties to determine line
139 thickness and padding around the markup."
142 (ly:output-def-lookup layout 'line-thickness)
143 (chain-assoc-get 'thickness props 1)))
144 (size (chain-assoc-get 'font-size props 0))
145 (pad (* (magstep size)
146 (chain-assoc-get 'box-padding props 0.2)))
147 (m (interpret-markup layout props arg)))
148 (box-stencil m th pad)))
150 (define-builtin-markup-command (filled-box layout props xext yext blot)
151 (number-pair? number-pair? number?)
152 "Draw a box with rounded corners of dimensions @var{xext} and
153 @var{yext}. For example,
155 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
157 creates a box extending horizontally from -0.3 to 1.8 and
158 vertically from -0.3 up to 1.8, with corners formed from a
159 circle of diameter@tie{}0 (i.e. sharp corners)."
163 (define-builtin-markup-command (rotate layout props ang arg) (number? markup?)
164 "Rotate object with @var{ang} degrees around its center."
165 (let* ((stil (interpret-markup layout props arg)))
166 (ly:stencil-rotate stil ang 0 0)))
169 (define-builtin-markup-command (whiteout layout props arg) (markup?)
170 "Provide a white underground for @var{arg}."
171 (stencil-whiteout (interpret-markup layout props arg)))
173 (define-builtin-markup-command (pad-markup layout props padding arg) (number? markup?)
174 "Add space around a markup object."
177 ((stil (interpret-markup layout props arg))
178 (xext (ly:stencil-extent stil X))
179 (yext (ly:stencil-extent stil Y)))
182 (ly:stencil-expr stil)
183 (interval-widen xext padding)
184 (interval-widen yext padding))))
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
190 ;;FIXME: is this working?
191 (define-builtin-markup-command (strut layout props) ()
192 "Create a box of the same height as the space in the current font."
193 (let ((m (ly:text-interface::interpret-markup layout props " ")))
194 (ly:make-stencil (ly:stencil-expr m)
196 (ly:stencil-extent m X)
200 ;; todo: fix negative space
201 (define-builtin-markup-command (hspace layout props amount) (number?)
202 "This produces a invisible object taking horizontal space. For example,
205 \\markup @{ A \\hspace #2.0 B @}
209 puts extra space between A and@tie{}B, on top of the space that is
210 normally inserted before elements on a line."
212 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
213 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
217 ;; importing graphics.
218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 (define-builtin-markup-command (stencil layout props stil) (ly:stencil?)
221 "Use a stencil as markup."
225 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
227 (define (get-postscript-bbox string)
228 "Extract the bbox from STRING, or return #f if not present."
230 ((match (regexp-exec bbox-regexp string)))
234 (string->number (match:substring match x)))
239 (define-builtin-markup-command (epsfile layout props axis size file-name) (number? number? string?)
240 "Inline an EPS image. The image is scaled along @var{axis} to
243 (if (ly:get-option 'safe)
244 (interpret-markup layout props "not allowed in safe")
245 (eps-file->stencil axis size file-name)
248 (define-builtin-markup-command (postscript layout props str) (string?)
249 "This inserts @var{str} directly into the output as a PostScript
250 command string. Due to technicalities of the output backends,
251 different scales should be used for the @TeX{} and PostScript backend,
252 selected with @code{-f}.
254 For the @TeX{} backend, the following string prints a rotated text
259 0 0 moveto /ecrm10 findfont
260 1.75 scalefont setfont 90 rotate (hello) show
264 The magical constant 1.75 scales from LilyPond units (staff spaces) to
267 For the postscript backend, use the following
270 gsave /ecrm10 findfont
271 10.0 output-scale div
272 scalefont setfont 90 rotate (hello) show grestore
279 gsave currentpoint translate
288 (define-builtin-markup-command (score layout props score) (ly:score?)
289 "Inline an image of music."
290 (let* ((output (ly:score-embedded-format score layout)))
292 (if (ly:music-output? output)
293 (paper-system-stencil
294 (vector-ref (ly:paper-score-paper-systems output) 0))
296 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
299 (define-builtin-markup-command (null layout props) ()
300 "An empty markup with extents of a single point."
304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310 (define-builtin-markup-command (simple layout props str) (string?)
311 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
312 @code{\\markup @{ \\simple #\"foo\" @}}."
313 (interpret-markup layout props str))
315 (define-builtin-markup-command (tied-lyric layout props str) (string?)
316 "Like simple-markup, but use tie characters for @q{~} tilde symbols."
317 (if (string-contains str "~")
319 ((parts (string-split str #\~))
320 (tie-str (ly:wide-char->utf-8 #x203f))
321 (joined (list-join parts tie-str))
322 (join-stencil (interpret-markup layout props tie-str))
325 (interpret-markup layout
328 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
330 (make-line-markup joined)))
331 ;(map (lambda (s) (interpret-markup layout props s)) parts))
332 (interpret-markup layout props str)))
334 (define-public empty-markup
335 (make-simple-markup ""))
337 ;; helper for justifying lines.
338 (define (get-fill-space word-count line-width text-widths)
339 "Calculate the necessary paddings between each two adjacent texts.
340 The lengths of all texts are stored in @var{text-widths}.
341 The normal formula for the padding between texts a and b is:
342 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
343 The first and last padding have to be calculated specially using the
344 whole length of the first or last text.
345 Return a list of paddings.
348 ((null? text-widths) '())
350 ;; special case first padding
351 ((= (length text-widths) word-count)
353 (- (- (/ line-width (1- word-count)) (car text-widths))
354 (/ (car (cdr text-widths)) 2))
355 (get-fill-space word-count line-width (cdr text-widths))))
356 ;; special case last padding
357 ((= (length text-widths) 2)
358 (list (- (/ line-width (1- word-count))
359 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
362 (- (/ line-width (1- word-count))
363 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
364 (get-fill-space word-count line-width (cdr text-widths))))))
366 (define-builtin-markup-command (fill-line layout props markups)
368 "Put @var{markups} in a horizontal line of width @var{line-width}.
369 The markups are spaced or flushed to fill the entire line.
370 If there are no arguments, return an empty stencil."
372 (let* ((orig-stencils (interpret-markup-list layout props markups))
375 (if (ly:stencil-empty? stc)
377 stc)) orig-stencils))
380 (if (ly:stencil-empty? stc)
382 (interval-length (ly:stencil-extent stc X))))
384 (text-width (apply + text-widths))
385 (text-dir (chain-assoc-get 'text-direction props RIGHT))
386 (word-count (length stencils))
387 (word-space (chain-assoc-get 'word-space props 1))
388 (prop-line-width (chain-assoc-get 'line-width props #f))
389 (line-width (if prop-line-width prop-line-width
390 (ly:output-def-lookup layout 'line-width)))
395 (/ (- line-width text-width) 2)
396 (/ (- line-width text-width) 2)))
399 (- line-width text-width)))
401 (get-fill-space word-count line-width text-widths))))
409 (line-stencils (if (= word-count 1)
416 (if (= text-dir LEFT)
417 (set! line-stencils (reverse line-stencils)))
419 (if (null? (remove ly:stencil-empty? orig-stencils))
421 (stack-stencils-padding-list X
422 RIGHT fill-space-normal line-stencils))))
424 (define-builtin-markup-command (line layout props args) (markup-list?)
425 "Put @var{args} in a horizontal line. The property @code{word-space}
426 determines the space between each markup in @var{args}."
428 ((stencils (interpret-markup-list layout props args))
429 (space (chain-assoc-get 'word-space props))
430 (text-dir (chain-assoc-get 'text-direction props RIGHT))
433 (if (= text-dir LEFT)
434 (set! stencils (reverse stencils)))
439 (remove ly:stencil-empty? stencils))))
441 (define-builtin-markup-command (concat layout props args) (markup-list?)
442 "Concatenate @var{args} in a horizontal line, without spaces inbetween.
443 Strings and simple markups are concatenated on the input level, allowing
444 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
445 equivalent to @code{\"fi\"}."
447 (define (concat-string-args arg-list)
448 (fold-right (lambda (arg result-list)
449 (let ((result (if (pair? result-list)
452 (if (and (pair? arg) (eqv? (car arg) simple-markup))
453 (set! arg (cadr arg)))
454 (if (and (string? result) (string? arg))
455 (cons (string-append arg result) (cdr result-list))
456 (cons arg result-list))))
460 (interpret-markup layout
461 (prepend-alist-chain 'word-space 0 props)
462 (make-line-markup (if (markup-command-list? args)
464 (concat-string-args args)))))
466 (define (wordwrap-stencils stencils
467 justify base-space line-width text-dir)
469 "Perform simple wordwrap, return stencil of each line."
471 (define space (if justify
473 ;; justify only stretches lines.
477 (define (take-list width space stencils
478 accumulator accumulated-width)
479 "Return (head-list . tail) pair, with head-list fitting into width"
481 (cons accumulator stencils)
483 ((first (car stencils))
484 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
485 (newwid (+ space first-wid accumulated-width))
489 (or (null? accumulator)
492 (take-list width space
494 (cons first accumulator)
496 (cons accumulator stencils))
504 ((line-break (take-list line-width space todo
506 (line-stencils (car line-break))
507 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
510 (line-word-space (cond
511 ((not justify) space)
513 ;; don't stretch last line of paragraph.
514 ;; hmmm . bug - will overstretch the last line in some case.
515 ((null? (cdr line-break))
517 ((null? line-stencils) 0.0)
518 ((null? (cdr line-stencils)) 0.0)
519 (else (/ space-left (1- (length line-stencils))))))
521 (line (stack-stencil-line
523 (if (= text-dir RIGHT)
524 (reverse line-stencils)
527 (if (pair? (cdr line-break))
528 (loop (cons line lines)
532 (if (= text-dir LEFT)
534 (ly:stencil-translate-axis line
535 (- line-width (interval-end (ly:stencil-extent line X)))
537 (reverse (cons line lines))
544 (define (wordwrap-markups layout props args justify)
546 ((prop-line-width (chain-assoc-get 'line-width props #f))
547 (line-width (if prop-line-width prop-line-width
548 (ly:output-def-lookup layout 'line-width)))
549 (word-space (chain-assoc-get 'word-space props))
550 (text-dir (chain-assoc-get 'text-direction props RIGHT)))
551 (wordwrap-stencils (remove ly:stencil-empty?
552 (interpret-markup-list layout props args))
553 justify word-space line-width
556 (define-builtin-markup-command (justify layout props args) (markup-list?)
557 "Like wordwrap, but with lines stretched to justify the margins.
558 Use @code{\\override #'(line-width . @var{X})} to set the line width;
559 @var{X}@tie{}is the number of staff spaces."
560 (stack-lines DOWN 0.0 (chain-assoc-get 'baseline-skip props)
561 (wordwrap-markups layout props args #t)))
563 (define-builtin-markup-command (wordwrap layout props args) (markup-list?)
564 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
565 the line width, where @var{X} is the number of staff spaces."
566 (stack-lines DOWN 0.0 (chain-assoc-get 'baseline-skip props)
567 (wordwrap-markups layout props args #f)))
569 (define (wordwrap-string layout props justify arg)
571 ((baseline-skip (chain-assoc-get 'baseline-skip props))
572 (line-width (chain-assoc-get 'line-width props))
573 (word-space (chain-assoc-get 'word-space props))
575 (para-strings (regexp-split
576 (string-regexp-substitute "\r" "\n"
577 (string-regexp-substitute "\r\n" "\n" arg))
578 "\n[ \t\n]*\n[ \t\n]*"))
580 (text-dir (chain-assoc-get 'text-direction props RIGHT))
581 (list-para-words (map (lambda (str)
582 (regexp-split str "[ \t\n]+"))
584 (para-lines (map (lambda (words)
588 ly:stencil-empty? (map
590 (interpret-markup layout props x))
592 (lines (wordwrap-stencils stencils
601 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
604 (define-builtin-markup-command (wordwrap-string layout props arg) (string?)
605 "Wordwrap a string. Paragraphs may be separated with double newlines."
606 (wordwrap-string layout props #f arg))
608 (define-builtin-markup-command (justify-string layout props arg) (string?)
609 "Justify a string. Paragraphs may be separated with double newlines"
610 (wordwrap-string layout props #t arg))
613 (define-builtin-markup-command (wordwrap-field layout props symbol) (symbol?)
614 "Wordwrap the data which has been assigned to @var{symbol}."
615 (let* ((m (chain-assoc-get symbol props)))
617 (interpret-markup layout props
618 (list wordwrap-string-markup m))
619 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
621 (define-builtin-markup-command (justify-field layout props symbol) (symbol?)
622 "Justify the data which has been assigned to @var{symbol}."
623 (let* ((m (chain-assoc-get symbol props)))
625 (interpret-markup layout props
626 (list justify-string-markup m))
627 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
631 (define-builtin-markup-command (combine layout props m1 m2) (markup? markup?)
632 "Print two markups on top of each other."
633 (let* ((s1 (interpret-markup layout props m1))
634 (s2 (interpret-markup layout props m2)))
635 (ly:stencil-add s1 s2)))
638 ;; TODO: should extract baseline-skip from each argument somehow..
640 (define-builtin-markup-command (column layout props args) (markup-list?)
641 "Stack the markups in @var{args} vertically. The property
642 @code{baseline-skip} determines the space between each markup in @var{args}."
645 ((arg-stencils (interpret-markup-list layout props args))
646 (skip (chain-assoc-get 'baseline-skip props)))
651 (remove ly:stencil-empty? arg-stencils))))
654 (define-builtin-markup-command (dir-column layout props args) (markup-list?)
655 "Make a column of args, going up or down, depending on the setting
656 of the @code{#'direction} layout property."
657 (let* ((dir (chain-assoc-get 'direction props)))
659 (if (number? dir) dir -1)
661 (chain-assoc-get 'baseline-skip props)
662 (interpret-markup-list layout props args))))
664 (define-builtin-markup-command (center-align layout props args) (markup-list?)
665 "Put @code{args} in a centered column."
666 (let* ((mols (interpret-markup-list layout props args))
667 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
669 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
671 (define-builtin-markup-command (vcenter layout props arg) (markup?)
672 "Align @code{arg} to its Y@tie{}center."
673 (let* ((mol (interpret-markup layout props arg)))
674 (ly:stencil-aligned-to mol Y CENTER)))
676 (define-builtin-markup-command (hcenter layout props arg) (markup?)
677 "Align @code{arg} to its X@tie{}center."
678 (let* ((mol (interpret-markup layout props arg)))
679 (ly:stencil-aligned-to mol X CENTER)))
681 (define-builtin-markup-command (right-align layout props arg) (markup?)
682 "Align @var{arg} on its right edge."
683 (let* ((m (interpret-markup layout props arg)))
684 (ly:stencil-aligned-to m X RIGHT)))
686 (define-builtin-markup-command (left-align layout props arg) (markup?)
687 "Align @var{arg} on its left edge."
688 (let* ((m (interpret-markup layout props arg)))
689 (ly:stencil-aligned-to m X LEFT)))
691 (define-builtin-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
692 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
693 (let* ((m (interpret-markup layout props arg)))
694 (ly:stencil-aligned-to m axis dir)))
696 (define-builtin-markup-command (halign layout props dir arg) (number? markup?)
697 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
698 left-aligned, while @code{+1} is right. Values inbetween interpolate
699 alignment accordingly."
700 (let* ((m (interpret-markup layout props arg)))
701 (ly:stencil-aligned-to m X dir)))
705 (define-builtin-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
706 "Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
708 (let* ((m (interpret-markup layout props arg)))
709 (ly:make-stencil (ly:stencil-expr m) x y)))
712 (define-builtin-markup-command (pad-around layout props amount arg) (number? markup?)
713 "Add padding @var{amount} all around @var{arg}."
716 ((m (interpret-markup layout props arg))
717 (x (ly:stencil-extent m X))
718 (y (ly:stencil-extent m Y)))
721 (ly:make-stencil (ly:stencil-expr m)
722 (interval-widen x amount)
723 (interval-widen y amount))
727 (define-builtin-markup-command (pad-x layout props amount arg) (number? markup?)
728 "Add padding @var{amount} around @var{arg} in the X@tie{}direction."
730 ((m (interpret-markup layout props arg))
731 (x (ly:stencil-extent m X))
732 (y (ly:stencil-extent m Y)))
735 (ly:make-stencil (ly:stencil-expr m)
736 (interval-widen x amount)
741 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
742 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
743 (let* ((m1 (interpret-markup layout props arg1))
744 (m2 (interpret-markup layout props arg2)))
746 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)
749 (define-builtin-markup-command (transparent layout props arg) (markup?)
750 "Make the argument transparent."
752 ((m (interpret-markup layout props arg))
753 (x (ly:stencil-extent m X))
754 (y (ly:stencil-extent m Y)))
762 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
763 (number-pair? number-pair? markup?)
764 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
767 ((m (interpret-markup layout props arg))
768 (x (ly:stencil-extent m X))
769 (y (ly:stencil-extent m Y)))
771 (ly:make-stencil (ly:stencil-expr m)
772 (interval-union x-ext x)
773 (interval-union y-ext y))))
776 (define-builtin-markup-command (hcenter-in layout props length arg)
778 "Center @var{arg} horizontally within a box of extending
779 @var{length}/2 to the left and right."
781 (interpret-markup layout props
782 (make-pad-to-box-markup
783 (cons (/ length -2) (/ length 2))
785 (make-hcenter-markup arg))))
788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792 (define-builtin-markup-command (fromproperty layout props symbol) (symbol?)
793 "Read the @var{symbol} from property settings, and produce a stencil
794 from the markup contained within. If @var{symbol} is not defined, it
795 returns an empty markup."
796 (let* ((m (chain-assoc-get symbol props)))
798 (interpret-markup layout props m)
799 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
802 (define-builtin-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
803 "Apply the @var{procedure} markup command to @var{arg}.
804 @var{procedure} should take a single argument."
805 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
806 (set-object-property! anonymous-with-signature
809 (interpret-markup layout props (list anonymous-with-signature arg))))
813 (define-builtin-markup-command (override layout props new-prop arg) (pair? markup?)
814 "Add the first argument in to the property list. Properties may be
815 any sort of property supported by @internalsref{font-interface} and
816 @internalsref{text-interface}, for example
819 \\override #'(font-family . married) \"bla\"
821 (interpret-markup layout (cons (list new-prop) props) arg))
823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
827 (define-builtin-markup-command (verbatim-file layout props name) (string?)
828 "Read the contents of a file, and include it verbatim."
832 (if (ly:get-option 'safe)
833 "verbatim-file disabled in safe mode"
835 ((str (ly:gulp-file name))
836 (lines (string-split str #\nl)))
838 (make-typewriter-markup
839 (make-column-markup lines)))
842 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
847 (define-builtin-markup-command (bigger layout props arg) (markup?)
848 "Increase the font size relative to current setting."
849 (interpret-markup layout props
850 `(,fontsize-markup 1 ,arg)))
852 (define-builtin-markup-command (smaller layout props arg) (markup?)
853 "Decrease the font size relative to current setting."
854 (interpret-markup layout props
855 `(,fontsize-markup -1 ,arg)))
857 (define-builtin-markup-command larger (markup?) bigger-markup)
859 (define-builtin-markup-command (finger layout props arg) (markup?)
860 "Set the argument as small numbers."
861 (interpret-markup layout
862 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
866 (define-builtin-markup-command (fontsize layout props increment arg) (number? markup?)
867 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
869 (let* ((fs (chain-assoc-get 'font-size props 0))
870 (bs (chain-assoc-get 'baseline-skip props 2))
872 (cons 'baseline-skip (* bs (magstep increment)))
873 (cons 'font-size (+ fs increment )))))
875 (interpret-markup layout (cons entries props) arg)))
877 (define-builtin-markup-command (magnify layout props sz arg) (number? markup?)
878 "Set the font magnification for its argument. In the following
879 example, the middle@tie{}A is 10% larger:
882 A \\magnify #1.1 @{ A @} A
885 Note: Magnification only works if a font name is explicitly selected.
886 Use @code{\\fontsize} otherwise."
889 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
892 (define-builtin-markup-command (bold layout props arg) (markup?)
893 "Switch to bold font-series."
894 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
896 (define-builtin-markup-command (sans layout props arg) (markup?)
897 "Switch to the sans serif family."
898 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
900 (define-builtin-markup-command (number layout props arg) (markup?)
901 "Set font family to @code{number}, which yields the font used for
902 time signatures and fingerings. This font only contains numbers and
903 some punctuation. It doesn't have any letters."
904 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
906 (define-builtin-markup-command (roman layout props arg) (markup?)
907 "Set font family to @code{roman}."
908 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
910 (define-builtin-markup-command (huge layout props arg) (markup?)
911 "Set font size to +2."
912 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
914 (define-builtin-markup-command (large layout props arg) (markup?)
915 "Set font size to +1."
916 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
918 (define-builtin-markup-command (normalsize layout props arg) (markup?)
919 "Set font size to default."
920 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
922 (define-builtin-markup-command (small layout props arg) (markup?)
923 "Set font size to -1."
924 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
926 (define-builtin-markup-command (tiny layout props arg) (markup?)
927 "Set font size to -2."
928 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
930 (define-builtin-markup-command (teeny layout props arg) (markup?)
931 "Set font size to -3."
932 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
934 (define-builtin-markup-command (fontCaps layout props arg) (markup?)
935 "Set @code{font-shape} to @code{caps}."
936 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
939 (define-builtin-markup-command (smallCaps layout props text) (markup?)
940 "Turn @code{text}, which should be a string, to small caps.
942 \\markup \\smallCaps \"Text between double quotes\"
945 Note: @code{\\smallCaps} does not support accented characters."
946 (define (char-list->markup chars lower)
947 (let ((final-string (string-upcase (reverse-list->string chars))))
949 (markup #:fontsize -2 final-string)
951 (define (make-small-caps rest-chars currents current-is-lower prev-result)
952 (if (null? rest-chars)
954 (reverse! (cons (char-list->markup currents current-is-lower)
956 (let* ((ch (car rest-chars))
957 (is-lower (char-lower-case? ch)))
958 (if (or (and current-is-lower is-lower)
959 (and (not current-is-lower) (not is-lower)))
960 (make-small-caps (cdr rest-chars)
964 (make-small-caps (cdr rest-chars)
969 (cons (char-list->markup
970 currents current-is-lower)
972 (interpret-markup layout props
974 (make-small-caps (string->list text) (list) #f (list))
978 (define-builtin-markup-command (caps layout props arg) (markup?)
979 "Emit @var{arg} as small caps."
980 (interpret-markup layout props (make-smallCaps-markup arg)))
982 (define-builtin-markup-command (dynamic layout props arg) (markup?)
983 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
984 @b{z}, @b{p}, and @b{r}. When producing phrases, like
985 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
986 done in a different font. The recommended font for this is bold and italic."
988 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
990 (define-builtin-markup-command (text layout props arg) (markup?)
991 "Use a text font instead of music symbol or music alphabet font."
994 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
998 (define-builtin-markup-command (italic layout props arg) (markup?)
999 "Use italic @code{font-shape} for @var{arg}."
1000 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1002 (define-builtin-markup-command (typewriter layout props arg) (markup?)
1003 "Use @code{font-family} typewriter for @var{arg}."
1005 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1007 (define-builtin-markup-command (upright layout props arg) (markup?)
1008 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1010 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1012 (define-builtin-markup-command (medium layout props arg) (markup?)
1013 "Switch to medium font series (in contrast to bold)."
1014 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1017 (define-builtin-markup-command (normal-text layout props arg) (markup?)
1018 "Set all font related properties (except the size) to get the default
1019 normal text font, no matter what font was used earlier."
1021 (interpret-markup layout
1022 (cons '((font-family . roman) (font-shape . upright)
1023 (font-series . medium) (font-encoding . latin1))
1027 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1029 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1031 (define-builtin-markup-command (doublesharp layout props) ()
1032 "Draw a double sharp symbol."
1034 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1036 (define-builtin-markup-command (sesquisharp layout props) ()
1037 "Draw a 3/2 sharp symbol."
1038 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1041 (define-builtin-markup-command (sharp layout props) ()
1042 "Draw a sharp symbol."
1043 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1045 (define-builtin-markup-command (semisharp layout props) ()
1046 "Draw a semi sharp symbol."
1047 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1049 (define-builtin-markup-command (natural layout props) ()
1050 "Draw a natural symbol."
1051 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1053 (define-builtin-markup-command (semiflat layout props) ()
1055 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1057 (define-builtin-markup-command (flat layout props) ()
1058 "Draw a flat symbol."
1059 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1061 (define-builtin-markup-command (sesquiflat layout props) ()
1062 "Draw a 3/2 flat symbol."
1063 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1065 (define-builtin-markup-command (doubleflat layout props) ()
1066 "Draw a double flat symbol."
1067 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1069 (define-builtin-markup-command (with-color layout props color arg) (color? markup?)
1070 "Draw @var{arg} in color specified by @var{color}."
1072 (let* ((stil (interpret-markup layout props arg)))
1074 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1075 (ly:stencil-extent stil X)
1076 (ly:stencil-extent stil Y))))
1079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1081 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1084 (define-builtin-markup-command (arrow-head layout props axis direction filled)
1085 (integer? ly:dir? boolean?)
1086 "Produce an arrow head in specified direction and axis.
1087 Use the filled head if @var{filled} is specified."
1089 ((name (format "arrowheads.~a.~a~a"
1096 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1100 (define-builtin-markup-command (musicglyph layout props glyph-name) (string?)
1101 "@var{glyph-name} is converted to a musical symbol; for example,
1102 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
1103 the music font. See @ruser{The Feta font} for a complete listing of
1104 the possible glyphs."
1106 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1110 (define-builtin-markup-command (lookup layout props glyph-name) (string?)
1111 "Lookup a glyph by name."
1112 (ly:font-get-glyph (ly:paper-get-font layout props)
1115 (define-builtin-markup-command (char layout props num) (integer?)
1116 "Produce a single character. For example, @code{\\char #65} produces the
1119 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1121 (define number->mark-letter-vector (make-vector 25 #\A))
1126 (if (= i (- (char->integer #\I) (char->integer #\A)))
1128 (vector-set! number->mark-letter-vector j
1129 (integer->char (+ i (char->integer #\A)))))
1131 (define number->mark-alphabet-vector (list->vector
1132 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1134 (define (number->markletter-string vec n)
1135 "Double letters for big marks."
1136 (let* ((lst (vector-length vec)))
1139 (string-append (number->markletter-string vec (1- (quotient n lst)))
1140 (number->markletter-string vec (remainder n lst)))
1141 (make-string 1 (vector-ref vec n)))))
1143 (define-builtin-markup-command (markletter layout props num) (integer?)
1144 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1145 (skipping letter@tie{}I), and continue with double letters."
1146 (ly:text-interface::interpret-markup layout props
1147 (number->markletter-string number->mark-letter-vector num)))
1149 (define-builtin-markup-command (markalphabet layout props num) (integer?)
1150 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1151 and continue with double letters."
1152 (ly:text-interface::interpret-markup layout props
1153 (number->markletter-string number->mark-alphabet-vector num)))
1157 (define-builtin-markup-command (slashed-digit layout props num) (integer?)
1158 "A feta number, with slash. This is for use in the context of
1159 figured bass notation."
1161 ((mag (magstep (chain-assoc-get 'font-size props 0)))
1164 (ly:output-def-lookup layout 'line-thickness)
1165 (chain-assoc-get 'thickness props 1.6)))
1167 (number-stencil (interpret-markup layout
1168 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1169 (number->string num)))
1170 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1172 (num-y (ly:stencil-extent number-stencil Y))
1173 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
1180 ,(car num-x) ,(- (interval-center num-y) dy)
1181 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1187 ((not (ly:stencil? slash-stencil)) #f)
1188 ((= num 5) (ly:stencil-translate slash-stencil
1189 ;;(cons (* mag -0.05) (* mag 0.42))
1190 (cons (* mag -0.00) (* mag -0.07))
1193 ((= num 7) (ly:stencil-translate slash-stencil
1194 ;;(cons (* mag -0.05) (* mag 0.42))
1195 (cons (* mag -0.00) (* mag -0.15))
1199 (else slash-stencil)))
1202 (set! number-stencil
1203 (ly:stencil-add number-stencil slash-stencil))
1205 (ly:warning "invalid number for slashed digit ~a" num))
1210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1211 ;; the note command.
1212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1215 ;; TODO: better syntax.
1217 (define-builtin-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1218 "Construct a note symbol, with stem. By using fractional values for
1219 @var{dir}, you can obtain longer or shorter stems."
1221 (define (get-glyph-name-candidates dir log style)
1222 (map (lambda (dir-name)
1223 (format "noteheads.~a~a~a" dir-name (min log 2)
1224 (if (and (symbol? style)
1225 (not (equal? 'default style)))
1226 (symbol->string style)
1228 (list (if (= dir UP) "u" "d")
1231 (define (get-glyph-name font cands)
1234 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1235 (get-glyph-name font (cdr cands))
1238 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1239 (size-factor (magstep (chain-assoc-get 'font-size props 0)))
1240 (style (chain-assoc-get 'style props '()))
1241 (stem-length (* size-factor (max 3 (- log 1))))
1242 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
1243 (head-glyph (ly:font-get-glyph font head-glyph-name))
1244 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1245 (stem-thickness (* size-factor 0.13))
1246 (stemy (* dir stem-length))
1247 (attach-off (cons (interval-index
1248 (ly:stencil-extent head-glyph X)
1249 (* (sign dir) (car attach-indices)))
1250 (* (sign dir) ; fixme, this is inconsistent between X & Y.
1252 (ly:stencil-extent head-glyph Y)
1253 (cdr attach-indices)))))
1254 (stem-glyph (and (> log 0)
1255 (ly:round-filled-box
1256 (ordered-cons (car attach-off)
1257 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
1258 (cons (min stemy (cdr attach-off))
1259 (max stemy (cdr attach-off)))
1260 (/ stem-thickness 3))))
1262 (dot (ly:font-get-glyph font "dots.dot"))
1263 (dotwid (interval-length (ly:stencil-extent dot X)))
1264 (dots (and (> dot-count 0)
1265 (apply ly:stencil-add
1267 (ly:stencil-translate-axis
1268 dot (* 2 x dotwid) X))
1269 (iota dot-count)))))
1270 (flaggl (and (> log 2)
1271 (ly:stencil-translate
1272 (ly:font-get-glyph font
1273 (string-append "flags."
1274 (if (> dir 0) "u" "d")
1275 (number->string log)))
1276 (cons (+ (car attach-off) (/ stem-thickness 2)) stemy)))))
1278 (if (and dots flaggl (> dir 0))
1279 (set! dots (ly:stencil-translate-axis dots 0.35 X)))
1281 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1282 (if (ly:stencil? stem-glyph)
1283 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1284 (set! stem-glyph head-glyph))
1285 (if (ly:stencil? dots)
1288 (ly:stencil-translate-axis
1290 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
1296 (let ((divisor (log 2)))
1297 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1299 (define (parse-simple-duration duration-string)
1300 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1301 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1302 (if (and match (string=? duration-string (match:substring match 0)))
1303 (let ((len (match:substring match 1))
1304 (dots (match:substring match 2)))
1305 (list (cond ((string=? len "breve") -1)
1306 ((string=? len "longa") -2)
1307 ((string=? len "maxima") -3)
1308 (else (log2 (string->number len))))
1309 (if dots (string-length dots) 0)))
1310 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1312 (define-builtin-markup-command (note layout props duration dir) (string? number?)
1313 "This produces a note with a stem pointing in @var{dir} direction, with
1314 the @var{duration} for the note head type and augmentation dots. For
1315 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1316 a shortened down stem."
1317 (let ((parsed (parse-simple-duration duration)))
1318 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1321 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1323 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1325 (define-builtin-markup-command (lower layout props amount arg) (number? markup?)
1326 "Lower @var{arg} by the distance @var{amount}.
1327 A negative @var{amount} indicates raising; see also @code{\\raise}."
1328 (ly:stencil-translate-axis (interpret-markup layout props arg)
1332 (define-builtin-markup-command (translate-scaled layout props offset arg) (number-pair? markup?)
1333 "Translate @var{arg} by @var{offset}, scaling the offset by the
1336 ((factor (magstep (chain-assoc-get 'font-size props 0)))
1337 (scaled (cons (* factor (car offset))
1338 (* factor (cdr offset)))))
1340 (ly:stencil-translate (interpret-markup layout props arg)
1343 (define-builtin-markup-command (raise layout props amount arg) (number? markup?)
1344 "Raise @var{arg} by the distance @var{amount}.
1345 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1347 @lilypond[verbatim,fragment,relative=1]
1348 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" } }
1350 The argument to @code{\\raise} is the vertical displacement amount,
1351 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1352 raise objects in relation to their surrounding markups.
1354 If the text object itself is positioned above or below the staff, then
1355 @code{\\raise} cannot be used to move it, since the mechanism that
1356 positions it next to the staff cancels any shift made with
1357 @code{\\raise}. For vertical positioning, use the @code{padding}
1358 and/or @code{extra-offset} properties."
1359 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1361 (define-builtin-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1362 "Make a fraction of two markups."
1363 (let* ((m1 (interpret-markup layout props arg1))
1364 (m2 (interpret-markup layout props arg2))
1365 (factor (magstep (chain-assoc-get 'font-size props 0)))
1366 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
1367 (padding (* factor 0.2))
1368 (baseline (* factor 0.6))
1369 (offset (* factor 0.75)))
1370 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1371 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1372 (let* ((x1 (ly:stencil-extent m1 X))
1373 (x2 (ly:stencil-extent m2 X))
1374 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
1375 ;; should stack mols separately, to maintain LINE on baseline
1376 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
1378 (ly:stencil-aligned-to stack Y CENTER))
1380 (ly:stencil-aligned-to stack X LEFT))
1381 ;; should have EX dimension
1383 (ly:stencil-translate-axis stack offset Y))))
1385 (define-builtin-markup-command (normal-size-super layout props arg) (markup?)
1386 "Set @var{arg} in superscript with a normal font size."
1387 (ly:stencil-translate-axis
1388 (interpret-markup layout props arg)
1389 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1391 (define-builtin-markup-command (super layout props arg) (markup?)
1393 @cindex raising text
1394 @cindex lowering text
1396 @cindex translating text
1398 @cindex @code{\\super}
1400 Raising and lowering texts can be done with @code{\\super} and
1403 @lilypond[verbatim,fragment,relative=1]
1404 c1^\\markup { E \"=\" \\concat { \"mc\" \\super \"2\" } }
1406 (ly:stencil-translate-axis
1409 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1411 (* 0.5 (chain-assoc-get 'baseline-skip props))
1414 (define-builtin-markup-command (translate layout props offset arg) (number-pair? markup?)
1415 "This translates an object. Its first argument is a cons of numbers.
1418 A \\translate #(cons 2 -3) @{ B C @} D
1421 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
1422 surroundings. This command cannot be used to move isolated scripts
1423 vertically, for the same reason that @code{\\raise} cannot be used for
1425 (ly:stencil-translate (interpret-markup layout props arg)
1428 (define-builtin-markup-command (sub layout props arg) (markup?)
1429 "Set @var{arg} in subscript."
1430 (ly:stencil-translate-axis
1433 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1435 (* -0.5 (chain-assoc-get 'baseline-skip props))
1438 (define-builtin-markup-command (normal-size-sub layout props arg) (markup?)
1439 "Set @var{arg} in subscript, in a normal font size."
1440 (ly:stencil-translate-axis
1441 (interpret-markup layout props arg)
1442 (* -0.5 (chain-assoc-get 'baseline-skip props))
1445 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1449 (define-builtin-markup-command (hbracket layout props arg) (markup?)
1450 "Draw horizontal brackets around @var{arg}."
1451 (let ((th 0.1) ;; todo: take from GROB.
1452 (m (interpret-markup layout props arg)))
1453 (bracketify-stencil m X th (* 2.5 th) th)))
1455 (define-builtin-markup-command (bracket layout props arg) (markup?)
1456 "Draw vertical brackets around @var{arg}."
1457 (let ((th 0.1) ;; todo: take from GROB.
1458 (m (interpret-markup layout props arg)))
1459 (bracketify-stencil m Y th (* 2.5 th) th)))
1461 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1462 ;; Delayed markup evaluation
1463 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1465 (define-builtin-markup-command (page-ref layout props label gauge default)
1466 (symbol? markup? markup?)
1467 "Reference to a page number. @var{label} is the label set on the referenced
1468 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
1469 the maximum width of the page number, and @var{default} the value to display
1470 when @var{label} is not found."
1471 (let* ((gauge-stencil (interpret-markup layout props gauge))
1472 (x-ext (ly:stencil-extent gauge-stencil X))
1473 (y-ext (ly:stencil-extent gauge-stencil Y)))
1475 `(delay-stencil-evaluation
1476 ,(delay (ly:stencil-expr
1477 (let* ((table (ly:output-def-lookup layout 'label-page-table))
1478 (label-page (and (list? table) (assoc label table)))
1479 (page-number (and label-page (cdr label-page)))
1480 (page-markup (if page-number (format "~a" page-number) default))
1481 (page-stencil (interpret-markup layout props page-markup))
1482 (gap (- (interval-length x-ext)
1483 (interval-length (ly:stencil-extent page-stencil X)))))
1484 (interpret-markup layout props
1485 (markup #:concat (#:hspace gap page-markup)))))))
1490 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1491 ;; Markup list commands
1492 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1494 (define-public (space-lines baseline-skip lines)
1496 (stack-lines DOWN 0.0 (/ baseline-skip 2.0)
1497 (list (ly:make-stencil "" (cons 0 0) (cons 0 0))
1499 (ly:make-stencil "" (cons 0 0) (cons 0 0)))))
1502 (define-builtin-markup-list-command (justified-lines layout props args) (markup-list?)
1503 "Like @code{\\justify}, but return a list of lines instead of a single markup.
1504 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width;
1505 @var{X}@tie{}is the number of staff spaces."
1506 (space-lines (chain-assoc-get 'baseline-skip props)
1507 (wordwrap-markups layout props args #t)))
1509 (define-builtin-markup-list-command (wordwrap-lines layout props args) (markup-list?)
1510 "Like @code{\\wordwrap}, but return a list of lines instead of a single markup.
1511 Use @code{\\override-lines #'(line-width . @var{X})} to set the line width,
1512 where @var{X} is the number of staff spaces."
1513 (space-lines (chain-assoc-get 'baseline-skip props)
1514 (wordwrap-markups layout props args #f)))
1516 (define-builtin-markup-list-command (column-lines layout props args) (markup-list?)
1517 "Like @code{\\column}, but return a list of lines instead of a single markup.
1518 @code{baseline-skip} determines the space between each markup in @var{args}."
1519 (space-lines (chain-assoc-get 'baseline-skip props)
1520 (interpret-markup-list layout props args)))
1522 (define-builtin-markup-list-command (override-lines layout props new-prop args)
1523 (pair? markup-list?)
1524 "Like @code{\\override}, for markup lists."
1525 (interpret-markup-list layout (cons (list new-prop) props) args))