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))
41 (cons (min x 0) (min y 0))
42 (cons (max x 0) (max y 0)))))
44 (define-builtin-markup-command (draw-circle layout props radius thickness fill)
45 (number? number? boolean?)
46 "A circle of radius @var{radius}, thickness @var{thickness} and
48 (make-circle-stencil radius thickness fill))
50 (define-builtin-markup-command (triangle layout props filled) (boolean?)
51 "A triangle, either filled or empty."
53 ((th (chain-assoc-get 'thickness props 0.1))
54 (size (chain-assoc-get 'font-size props 0))
57 (chain-assoc-get 'baseline-skip props 2))))
71 (define-builtin-markup-command (circle layout props arg) (markup?)
72 "Draw a circle around @var{arg}. Use @code{thickness},
73 @code{circle-padding} and @code{font-size} properties to determine line
74 thickness and padding around the markup."
76 (let* ((th (chain-assoc-get 'thickness props 0.1))
77 (size (chain-assoc-get 'font-size props 0))
80 (chain-assoc-get 'circle-padding props 0.2)))
81 (m (interpret-markup layout props arg)))
82 (circle-stencil m th pad)))
84 (define-builtin-markup-command (with-url layout props url arg) (string? markup?)
85 "Add a link to URL @var{url} around @var{arg}. This only works in
87 (let* ((stil (interpret-markup layout props arg))
88 (xextent (ly:stencil-extent stil X))
89 (yextent (ly:stencil-extent stil Y))
90 (old-expr (ly:stencil-expr stil))
91 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
93 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
96 (define-builtin-markup-command (beam layout props width slope thickness)
97 (number? number? number?)
98 "Create a beam with the specified parameters."
99 (let* ((y (* slope width))
100 (yext (cons (min 0 y) (max 0 y)))
101 (half (/ thickness 2)))
106 width (+ (* width slope) (/ thickness -2))
107 width (+ (* width slope) (/ thickness 2))
109 ,(ly:output-def-lookup layout 'blot-diameter)
112 (cons (+ (- half) (car yext))
113 (+ half (cdr yext))))))
115 (define-builtin-markup-command (box layout props arg) (markup?)
116 "Draw a box round @var{arg}. Looks at @code{thickness},
117 @code{box-padding} and @code{font-size} properties to determine line
118 thickness and padding around the markup."
120 (let* ((th (chain-assoc-get 'thickness props 0.1))
121 (size (chain-assoc-get 'font-size props 0))
122 (pad (* (magstep size)
123 (chain-assoc-get 'box-padding props 0.2)))
124 (m (interpret-markup layout props arg)))
125 (box-stencil m th pad)))
127 (define-builtin-markup-command (filled-box layout props xext yext blot)
128 (number-pair? number-pair? number?)
129 "Draw a box with rounded corners of dimensions @var{xext} and
130 @var{yext}. For example,
132 \\filled-box #'(-.3 . 1.8) #'(-.3 . 1.8) #0
134 creates a box extending horizontally from -0.3 to 1.8 and
135 vertically from -0.3 up to 1.8, with corners formed from a
136 circle of diameter@tie{}0 (i.e. sharp corners)."
140 (define-builtin-markup-command (rotate layout props ang arg) (number? markup?)
141 "Rotate object with @var{ang} degrees around its center."
142 (let* ((stil (interpret-markup layout props arg)))
143 (ly:stencil-rotate stil ang 0 0)))
146 (define-builtin-markup-command (whiteout layout props arg) (markup?)
147 "Provide a white underground for @var{arg}."
148 (stencil-whiteout (interpret-markup layout props arg)))
150 (define-builtin-markup-command (pad-markup layout props padding arg) (number? markup?)
151 "Add space around a markup object."
154 ((stil (interpret-markup layout props arg))
155 (xext (ly:stencil-extent stil X))
156 (yext (ly:stencil-extent stil Y)))
159 (ly:stencil-expr stil)
160 (interval-widen xext padding)
161 (interval-widen yext padding))))
163 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
167 ;;FIXME: is this working?
168 (define-builtin-markup-command (strut layout props) ()
169 "Create a box of the same height as the space in the current font."
170 (let ((m (ly:text-interface::interpret-markup layout props " ")))
171 (ly:make-stencil (ly:stencil-expr m)
173 (ly:stencil-extent m X)
177 ;; todo: fix negative space
178 (define-builtin-markup-command (hspace layout props amount) (number?)
179 "This produces a invisible object taking horizontal space. For example,
182 \\markup @{ A \\hspace #2.0 B @}
186 puts extra space between A and@tie{}B, on top of the space that is
187 normally inserted before elements on a line."
189 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
190 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
194 ;; importing graphics.
195 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
197 (define-builtin-markup-command (stencil layout props stil) (ly:stencil?)
198 "Use a stencil as markup."
202 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
204 (define (get-postscript-bbox string)
205 "Extract the bbox from STRING, or return #f if not present."
207 ((match (regexp-exec bbox-regexp string)))
211 (string->number (match:substring match x)))
216 (define-builtin-markup-command (epsfile layout props axis size file-name) (number? number? string?)
217 "Inline an EPS image. The image is scaled along @var{axis} to
220 (if (ly:get-option 'safe)
221 (interpret-markup layout props "not allowed in safe")
222 (eps-file->stencil axis size file-name)
225 (define-builtin-markup-command (postscript layout props str) (string?)
226 "This inserts @var{str} directly into the output as a PostScript
227 command string. Due to technicalities of the output backends,
228 different scales should be used for the @TeX{} and PostScript backend,
229 selected with @code{-f}.
231 For the @TeX{} backend, the following string prints a rotated text
236 0 0 moveto /ecrm10 findfont
237 1.75 scalefont setfont 90 rotate (hello) show
241 The magical constant 1.75 scales from LilyPond units (staff spaces) to
244 For the postscript backend, use the following
247 gsave /ecrm10 findfont
248 10.0 output-scale div
249 scalefont setfont 90 rotate (hello) show grestore
256 gsave currentpoint translate
265 (define-builtin-markup-command (score layout props score) (ly:score?)
266 "Inline an image of music."
267 (let* ((output (ly:score-embedded-format score layout)))
269 (if (ly:music-output? output)
270 (paper-system-stencil
271 (vector-ref (ly:paper-score-paper-systems output) 0))
273 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
276 (define-builtin-markup-command (null layout props) ()
277 "An empty markup with extents of a single point."
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
287 (define-builtin-markup-command (simple layout props str) (string?)
288 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
289 @code{\\markup @{ \\simple #\"foo\" @}}."
290 (interpret-markup layout props str))
292 (define-builtin-markup-command (tied-lyric layout props str) (string?)
293 "Like simple-markup, but use tie characters for @q{~} tilde symbols."
294 (if (string-contains str "~")
296 ((parts (string-split str #\~))
297 (tie-str (ly:wide-char->utf-8 #x203f))
298 (joined (list-join parts tie-str))
299 (join-stencil (interpret-markup layout props tie-str))
302 (interpret-markup layout
305 (/ (interval-length (ly:stencil-extent join-stencil X)) -3.5)
307 (make-line-markup joined)))
308 ;(map (lambda (s) (interpret-markup layout props s)) parts))
309 (interpret-markup layout props str)))
311 (define-public empty-markup
312 (make-simple-markup ""))
314 ;; helper for justifying lines.
315 (define (get-fill-space word-count line-width text-widths)
316 "Calculate the necessary paddings between each two adjacent texts.
317 The lengths of all texts are stored in @var{text-widths}.
318 The normal formula for the padding between texts a and b is:
319 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
320 The first and last padding have to be calculated specially using the
321 whole length of the first or last text.
322 Return a list of paddings.
325 ((null? text-widths) '())
327 ;; special case first padding
328 ((= (length text-widths) word-count)
330 (- (- (/ line-width (1- word-count)) (car text-widths))
331 (/ (car (cdr text-widths)) 2))
332 (get-fill-space word-count line-width (cdr text-widths))))
333 ;; special case last padding
334 ((= (length text-widths) 2)
335 (list (- (/ line-width (1- word-count))
336 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
339 (- (/ line-width (1- word-count))
340 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
341 (get-fill-space word-count line-width (cdr text-widths))))))
343 (define-builtin-markup-command (fill-line layout props markups)
345 "Put @var{markups} in a horizontal line of width @var{line-width}.
346 The markups are spaced or flushed to fill the entire line.
347 If there are no arguments, return an empty stencil."
349 (let* ((orig-stencils
350 (map (lambda (x) (interpret-markup layout props x))
354 (if (ly:stencil-empty? stc)
356 stc)) orig-stencils))
359 (if (ly:stencil-empty? stc)
361 (interval-length (ly:stencil-extent stc X))))
363 (text-width (apply + text-widths))
364 (text-dir (chain-assoc-get 'text-direction props RIGHT))
365 (word-count (length stencils))
366 (word-space (chain-assoc-get 'word-space props 1))
367 (prop-line-width (chain-assoc-get 'line-width props #f))
368 (line-width (if prop-line-width prop-line-width
369 (ly:output-def-lookup layout 'line-width)))
374 (/ (- line-width text-width) 2)
375 (/ (- line-width text-width) 2)))
378 (- line-width text-width)))
380 (get-fill-space word-count line-width text-widths))))
388 (line-stencils (if (= word-count 1)
395 (if (= text-dir LEFT)
396 (set! line-stencils (reverse line-stencils)))
398 (if (null? (remove ly:stencil-empty? orig-stencils))
400 (stack-stencils-padding-list X
401 RIGHT fill-space-normal line-stencils))))
403 (define-builtin-markup-command (line layout props args) (markup-list?)
404 "Put @var{args} in a horizontal line. The property @code{word-space}
405 determines the space between each markup in @var{args}."
407 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
408 (space (chain-assoc-get 'word-space props))
409 (text-dir (chain-assoc-get 'text-direction props RIGHT))
412 (if (= text-dir LEFT)
413 (set! stencils (reverse stencils)))
418 (remove ly:stencil-empty? stencils))))
420 (define-builtin-markup-command (concat layout props args) (markup-list?)
421 "Concatenate @var{args} in a horizontal line, without spaces inbetween.
422 Strings and simple markups are concatenated on the input level, allowing
423 ligatures. For example, @code{\\concat @{ \"f\" \\simple #\"i\" @}} is
424 equivalent to @code{\"fi\"}."
426 (define (concat-string-args arg-list)
427 (fold-right (lambda (arg result-list)
428 (let ((result (if (pair? result-list)
431 (if (and (pair? arg) (eqv? (car arg) simple-markup))
432 (set! arg (cadr arg)))
433 (if (and (string? result) (string? arg))
434 (cons (string-append arg result) (cdr result-list))
435 (cons arg result-list))))
439 (interpret-markup layout
440 (prepend-alist-chain 'word-space 0 props)
441 (make-line-markup (concat-string-args args))))
443 (define (wordwrap-stencils stencils
444 justify base-space line-width text-dir)
446 "Perform simple wordwrap, return stencil of each line."
448 (define space (if justify
450 ;; justify only stretches lines.
454 (define (take-list width space stencils
455 accumulator accumulated-width)
456 "Return (head-list . tail) pair, with head-list fitting into width"
458 (cons accumulator stencils)
460 ((first (car stencils))
461 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
462 (newwid (+ space first-wid accumulated-width))
466 (or (null? accumulator)
469 (take-list width space
471 (cons first accumulator)
473 (cons accumulator stencils))
481 ((line-break (take-list line-width space todo
483 (line-stencils (car line-break))
484 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
487 (line-word-space (cond
488 ((not justify) space)
490 ;; don't stretch last line of paragraph.
491 ;; hmmm . bug - will overstretch the last line in some case.
492 ((null? (cdr line-break))
494 ((null? line-stencils) 0.0)
495 ((null? (cdr line-stencils)) 0.0)
496 (else (/ space-left (1- (length line-stencils))))))
498 (line (stack-stencil-line
500 (if (= text-dir RIGHT)
501 (reverse line-stencils)
504 (if (pair? (cdr line-break))
505 (loop (cons line lines)
509 (if (= text-dir LEFT)
511 (ly:stencil-translate-axis line
512 (- line-width (interval-end (ly:stencil-extent line X)))
514 (reverse (cons line lines))
521 (define (wordwrap-markups layout props args justify)
523 ((baseline-skip (chain-assoc-get 'baseline-skip props))
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 (lines (wordwrap-stencils
530 (remove ly:stencil-empty?
531 (map (lambda (m) (interpret-markup layout props m)) args))
532 justify word-space line-width
536 (stack-lines DOWN 0.0 baseline-skip lines)))
538 (define-builtin-markup-command (justify layout props args) (markup-list?)
539 "Like wordwrap, but with lines stretched to justify the margins.
540 Use @code{\\override #'(line-width . @var{X})} to set the line width;
541 @var{X}@tie{}is the number of staff spaces."
542 (wordwrap-markups layout props args #t))
544 (define-builtin-markup-command (wordwrap layout props args) (markup-list?)
545 "Simple wordwrap. Use @code{\\override #'(line-width . @var{X})} to set
546 the line width, where @var{X} is the number of staff spaces."
548 (wordwrap-markups layout props args #f))
550 (define (wordwrap-string layout props justify arg)
552 ((baseline-skip (chain-assoc-get 'baseline-skip props))
553 (line-width (chain-assoc-get 'line-width props))
554 (word-space (chain-assoc-get 'word-space props))
556 (para-strings (regexp-split
557 (string-regexp-substitute "\r" "\n"
558 (string-regexp-substitute "\r\n" "\n" arg))
559 "\n[ \t\n]*\n[ \t\n]*"))
561 (text-dir (chain-assoc-get 'text-direction props RIGHT))
562 (list-para-words (map (lambda (str)
563 (regexp-split str "[ \t\n]+"))
565 (para-lines (map (lambda (words)
569 ly:stencil-empty? (map
571 (interpret-markup layout props x))
573 (lines (wordwrap-stencils stencils
582 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
585 (define-builtin-markup-command (wordwrap-string layout props arg) (string?)
586 "Wordwrap a string. Paragraphs may be separated with double newlines."
587 (wordwrap-string layout props #f arg))
589 (define-builtin-markup-command (justify-string layout props arg) (string?)
590 "Justify a string. Paragraphs may be separated with double newlines"
591 (wordwrap-string layout props #t arg))
594 (define-builtin-markup-command (wordwrap-field layout props symbol) (symbol?)
595 "Wordwrap the data which has been assigned to @var{symbol}."
596 (let* ((m (chain-assoc-get symbol props)))
598 (interpret-markup layout props
599 (list wordwrap-string-markup m))
600 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
602 (define-builtin-markup-command (justify-field layout props symbol) (symbol?)
603 "Justify the data which has been assigned to @var{symbol}."
604 (let* ((m (chain-assoc-get symbol props)))
606 (interpret-markup layout props
607 (list justify-string-markup m))
608 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
612 (define-builtin-markup-command (combine layout props m1 m2) (markup? markup?)
613 "Print two markups on top of each other."
614 (let* ((s1 (interpret-markup layout props m1))
615 (s2 (interpret-markup layout props m2)))
616 (ly:stencil-add s1 s2)))
619 ;; TODO: should extract baseline-skip from each argument somehow..
621 (define-builtin-markup-command (column layout props args) (markup-list?)
622 "Stack the markups in @var{args} vertically. The property
623 @code{baseline-skip} determines the space between each markup in @var{args}."
626 ((arg-stencils (map (lambda (m) (interpret-markup layout props m)) args))
627 (skip (chain-assoc-get 'baseline-skip props)))
632 (remove ly:stencil-empty? arg-stencils))))
635 (define-builtin-markup-command (dir-column layout props args) (markup-list?)
636 "Make a column of args, going up or down, depending on the setting
637 of the @code{#'direction} layout property."
638 (let* ((dir (chain-assoc-get 'direction props)))
640 (if (number? dir) dir -1)
642 (chain-assoc-get 'baseline-skip props)
643 (map (lambda (x) (interpret-markup layout props x)) args))))
645 (define-builtin-markup-command (center-align layout props args) (markup-list?)
646 "Put @code{args} in a centered column."
647 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
648 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
650 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
652 (define-builtin-markup-command (vcenter layout props arg) (markup?)
653 "Align @code{arg} to its Y@tie{}center."
654 (let* ((mol (interpret-markup layout props arg)))
655 (ly:stencil-aligned-to mol Y CENTER)))
657 (define-builtin-markup-command (hcenter layout props arg) (markup?)
658 "Align @code{arg} to its X@tie{}center."
659 (let* ((mol (interpret-markup layout props arg)))
660 (ly:stencil-aligned-to mol X CENTER)))
662 (define-builtin-markup-command (right-align layout props arg) (markup?)
663 "Align @var{arg} on its right edge."
664 (let* ((m (interpret-markup layout props arg)))
665 (ly:stencil-aligned-to m X RIGHT)))
667 (define-builtin-markup-command (left-align layout props arg) (markup?)
668 "Align @var{arg} on its left edge."
669 (let* ((m (interpret-markup layout props arg)))
670 (ly:stencil-aligned-to m X LEFT)))
672 (define-builtin-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
673 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
674 (let* ((m (interpret-markup layout props arg)))
675 (ly:stencil-aligned-to m axis dir)))
677 (define-builtin-markup-command (halign layout props dir arg) (number? markup?)
678 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
679 left-aligned, while @code{+1} is right. Values inbetween interpolate
680 alignment accordingly."
681 (let* ((m (interpret-markup layout props arg)))
682 (ly:stencil-aligned-to m X dir)))
686 (define-builtin-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
687 "Set the dimensions of @var{arg} to @var{x} and@tie{}@var{y}."
689 (let* ((m (interpret-markup layout props arg)))
690 (ly:make-stencil (ly:stencil-expr m) x y)))
693 (define-builtin-markup-command (pad-around layout props amount arg) (number? markup?)
694 "Add padding @var{amount} all around @var{arg}."
697 ((m (interpret-markup layout props arg))
698 (x (ly:stencil-extent m X))
699 (y (ly:stencil-extent m Y)))
702 (ly:make-stencil (ly:stencil-expr m)
703 (interval-widen x amount)
704 (interval-widen y amount))
708 (define-builtin-markup-command (pad-x layout props amount arg) (number? markup?)
709 "Add padding @var{amount} around @var{arg} in the X@tie{}direction."
711 ((m (interpret-markup layout props arg))
712 (x (ly:stencil-extent m X))
713 (y (ly:stencil-extent m Y)))
716 (ly:make-stencil (ly:stencil-expr m)
717 (interval-widen x amount)
722 (define-builtin-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
723 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}."
724 (let* ((m1 (interpret-markup layout props arg1))
725 (m2 (interpret-markup layout props arg2)))
727 (ly:stencil-combine-at-edge m1 axis dir m2 0.0)
730 (define-builtin-markup-command (transparent layout props arg) (markup?)
731 "Make the argument transparent."
733 ((m (interpret-markup layout props arg))
734 (x (ly:stencil-extent m X))
735 (y (ly:stencil-extent m Y)))
743 (define-builtin-markup-command (pad-to-box layout props x-ext y-ext arg)
744 (number-pair? number-pair? markup?)
745 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space."
748 ((m (interpret-markup layout props arg))
749 (x (ly:stencil-extent m X))
750 (y (ly:stencil-extent m Y)))
752 (ly:make-stencil (ly:stencil-expr m)
753 (interval-union x-ext x)
754 (interval-union y-ext y))))
757 (define-builtin-markup-command (hcenter-in layout props length arg)
759 "Center @var{arg} horizontally within a box of extending
760 @var{length}/2 to the left and right."
762 (interpret-markup layout props
763 (make-pad-to-box-markup
764 (cons (/ length -2) (/ length 2))
766 (make-hcenter-markup arg))))
769 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
771 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
773 (define-builtin-markup-command (fromproperty layout props symbol) (symbol?)
774 "Read the @var{symbol} from property settings, and produce a stencil
775 from the markup contained within. If @var{symbol} is not defined, it
776 returns an empty markup."
777 (let* ((m (chain-assoc-get symbol props)))
779 (interpret-markup layout props m)
780 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
783 (define-builtin-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
784 "Apply the @var{procedure} markup command to @var{arg}.
785 @var{procedure} should take a single argument."
786 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
787 (set-object-property! anonymous-with-signature
790 (interpret-markup layout props (list anonymous-with-signature arg))))
794 (define-builtin-markup-command (override layout props new-prop arg) (pair? markup?)
795 "Add the first argument in to the property list. Properties may be
796 any sort of property supported by @internalsref{font-interface} and
797 @internalsref{text-interface}, for example
800 \\override #'(font-family . married) \"bla\"
802 (interpret-markup layout (cons (list new-prop) props) arg))
804 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
806 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
808 (define-builtin-markup-command (verbatim-file layout props name) (string?)
809 "Read the contents of a file, and include it verbatim."
813 (if (ly:get-option 'safe)
814 "verbatim-file disabled in safe mode"
816 ((str (ly:gulp-file name))
817 (lines (string-split str #\nl)))
819 (make-typewriter-markup
820 (make-column-markup lines)))
823 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
828 (define-builtin-markup-command (bigger layout props arg) (markup?)
829 "Increase the font size relative to current setting."
830 (interpret-markup layout props
831 `(,fontsize-markup 1 ,arg)))
833 (define-builtin-markup-command (smaller layout props arg) (markup?)
834 "Decrease the font size relative to current setting."
835 (interpret-markup layout props
836 `(,fontsize-markup -1 ,arg)))
838 (define-builtin-markup-command larger (markup?) bigger-markup)
840 (define-builtin-markup-command (finger layout props arg) (markup?)
841 "Set the argument as small numbers."
842 (interpret-markup layout
843 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
847 (define-builtin-markup-command (fontsize layout props increment arg) (number? markup?)
848 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
850 (let* ((fs (chain-assoc-get 'font-size props 0))
851 (bs (chain-assoc-get 'baseline-skip props 2))
853 (cons 'baseline-skip (* bs (magstep increment)))
854 (cons 'font-size (+ fs increment )))))
856 (interpret-markup layout (cons entries props) arg)))
858 (define-builtin-markup-command (magnify layout props sz arg) (number? markup?)
859 "Set the font magnification for its argument. In the following
860 example, the middle@tie{}A is 10% larger:
863 A \\magnify #1.1 @{ A @} A
866 Note: Magnification only works if a font name is explicitly selected.
867 Use @code{\\fontsize} otherwise."
870 (prepend-alist-chain 'font-size (magnification->font-size sz) props)
873 (define-builtin-markup-command (bold layout props arg) (markup?)
874 "Switch to bold font-series."
875 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
877 (define-builtin-markup-command (sans layout props arg) (markup?)
878 "Switch to the sans serif family."
879 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
881 (define-builtin-markup-command (number layout props arg) (markup?)
882 "Set font family to @code{number}, which yields the font used for
883 time signatures and fingerings. This font only contains numbers and
884 some punctuation. It doesn't have any letters."
885 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
887 (define-builtin-markup-command (roman layout props arg) (markup?)
888 "Set font family to @code{roman}."
889 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
891 (define-builtin-markup-command (huge layout props arg) (markup?)
892 "Set font size to +2."
893 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
895 (define-builtin-markup-command (large layout props arg) (markup?)
896 "Set font size to +1."
897 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
899 (define-builtin-markup-command (normalsize layout props arg) (markup?)
900 "Set font size to default."
901 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
903 (define-builtin-markup-command (small layout props arg) (markup?)
904 "Set font size to -1."
905 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
907 (define-builtin-markup-command (tiny layout props arg) (markup?)
908 "Set font size to -2."
909 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
911 (define-builtin-markup-command (teeny layout props arg) (markup?)
912 "Set font size to -3."
913 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
915 (define-builtin-markup-command (fontCaps layout props arg) (markup?)
916 "Set @code{font-shape} to @code{caps}."
917 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
920 (define-builtin-markup-command (smallCaps layout props text) (markup?)
921 "Turn @code{text}, which should be a string, to small caps.
923 \\markup \\smallCaps \"Text between double quotes\"
925 (define (make-small-caps-markup chars)
928 ((char-whitespace? (car chars))
929 (markup #:fontsize -2 #:simple (string-upcase (list->string (cdr chars)))))
932 #:fontsize -2 #:simple (string-upcase (list->string chars))))))
933 (define (make-not-small-caps-markup chars)
936 ((char-whitespace? (car chars))
937 (markup #:simple (list->string (cdr chars))))
940 #:simple (list->string chars)))))
941 (define (small-caps-aux done-markups current-chars rest-chars small? after-space?)
942 (cond ((null? rest-chars)
943 ;; the end of the string: build the markup
944 (make-line-markup (reverse! (cons ((if small?
945 make-small-caps-markup
946 make-not-small-caps-markup)
947 (reverse! current-chars))
949 ((char-whitespace? (car rest-chars))
951 (small-caps-aux done-markups current-chars (cdr rest-chars) small? #t))
952 ((or (and small? (char-lower-case? (car rest-chars)))
953 (and (not small?) (not (char-lower-case? (car rest-chars)))))
955 ;; add the char to the current char list
956 (small-caps-aux done-markups
957 (cons (car rest-chars)
959 (cons #\space current-chars)
966 ;; make a markup with current chars, and start a new list with new char
967 (small-caps-aux (cons ((if small?
968 make-small-caps-markup
969 make-not-small-caps-markup)
970 (reverse! current-chars))
973 (list (car rest-chars) #\space)
974 (list (car rest-chars)))
978 (interpret-markup layout props (small-caps-aux (list)
980 (cons #\space (string->list text))
984 (define-builtin-markup-command (caps layout props arg) (markup?)
985 "Emit @var{arg} as small caps."
986 (interpret-markup layout props (make-smallCaps-markup arg)))
988 (define-builtin-markup-command (dynamic layout props arg) (markup?)
989 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
990 @b{z}, @b{p}, and @b{r}. When producing phrases, like
991 @q{pi@`{u}@tie{}@b{f}}, the normal words (like @q{pi@`{u}}) should be
992 done in a different font. The recommended font for this is bold and italic."
994 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
996 (define-builtin-markup-command (text layout props arg) (markup?)
997 "Use a text font instead of music symbol or music alphabet font."
1000 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
1004 (define-builtin-markup-command (italic layout props arg) (markup?)
1005 "Use italic @code{font-shape} for @var{arg}."
1006 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
1008 (define-builtin-markup-command (typewriter layout props arg) (markup?)
1009 "Use @code{font-family} typewriter for @var{arg}."
1011 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
1013 (define-builtin-markup-command (upright layout props arg) (markup?)
1014 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
1016 layout (prepend-alist-chain 'font-shape 'upright props) arg))
1018 (define-builtin-markup-command (medium layout props arg) (markup?)
1019 "Switch to medium font series (in contrast to bold)."
1020 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
1023 (define-builtin-markup-command (normal-text layout props arg) (markup?)
1024 "Set all font related properties (except the size) to get the default
1025 normal text font, no matter what font was used earlier."
1027 (interpret-markup layout
1028 (cons '((font-family . roman) (font-shape . upright)
1029 (font-series . medium) (font-encoding . latin1))
1033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1037 (define-builtin-markup-command (doublesharp layout props) ()
1038 "Draw a double sharp symbol."
1040 (interpret-markup layout props (markup #:musicglyph (assoc-get 1 standard-alteration-glyph-name-alist ""))))
1042 (define-builtin-markup-command (sesquisharp layout props) ()
1043 "Draw a 3/2 sharp symbol."
1044 (interpret-markup layout props (markup #:musicglyph (assoc-get 3/4 standard-alteration-glyph-name-alist ""))))
1047 (define-builtin-markup-command (sharp layout props) ()
1048 "Draw a sharp symbol."
1049 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/2 standard-alteration-glyph-name-alist ""))))
1051 (define-builtin-markup-command (semisharp layout props) ()
1052 "Draw a semi sharp symbol."
1053 (interpret-markup layout props (markup #:musicglyph (assoc-get 1/4 standard-alteration-glyph-name-alist ""))))
1055 (define-builtin-markup-command (natural layout props) ()
1056 "Draw a natural symbol."
1057 (interpret-markup layout props (markup #:musicglyph (assoc-get 0 standard-alteration-glyph-name-alist ""))))
1059 (define-builtin-markup-command (semiflat layout props) ()
1061 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/4 standard-alteration-glyph-name-alist ""))))
1063 (define-builtin-markup-command (flat layout props) ()
1064 "Draw a flat symbol."
1065 (interpret-markup layout props (markup #:musicglyph (assoc-get -1/2 standard-alteration-glyph-name-alist ""))))
1067 (define-builtin-markup-command (sesquiflat layout props) ()
1068 "Draw a 3/2 flat symbol."
1069 (interpret-markup layout props (markup #:musicglyph (assoc-get -3/4 standard-alteration-glyph-name-alist ""))))
1071 (define-builtin-markup-command (doubleflat layout props) ()
1072 "Draw a double flat symbol."
1073 (interpret-markup layout props (markup #:musicglyph (assoc-get -1 standard-alteration-glyph-name-alist ""))))
1075 (define-builtin-markup-command (with-color layout props color arg) (color? markup?)
1076 "Draw @var{arg} in color specified by @var{color}."
1078 (let* ((stil (interpret-markup layout props arg)))
1080 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
1081 (ly:stencil-extent stil X)
1082 (ly:stencil-extent stil Y))))
1085 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1087 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1090 (define-builtin-markup-command (arrow-head layout props axis direction filled)
1091 (integer? ly:dir? boolean?)
1092 "Produce an arrow head in specified direction and axis.
1093 Use the filled head if @var{filled} is specified."
1095 ((name (format "arrowheads.~a.~a~a"
1102 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1106 (define-builtin-markup-command (musicglyph layout props glyph-name) (string?)
1107 "@var{glyph0name} is converted to a musical symbol; for example,
1108 @code{\\musicglyph #\"accidentals.natural\"} selects the natural sign from
1109 the music font. See @usermanref{The Feta font} for a complete listing of
1110 the possible glyphs."
1112 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
1116 (define-builtin-markup-command (lookup layout props glyph-name) (string?)
1117 "Lookup a glyph by name."
1118 (ly:font-get-glyph (ly:paper-get-font layout props)
1121 (define-builtin-markup-command (char layout props num) (integer?)
1122 "Produce a single character. For example, @code{\\char #65} produces the
1125 (ly:text-interface::interpret-markup layout props (ly:wide-char->utf-8 num)))
1127 (define number->mark-letter-vector (make-vector 25 #\A))
1132 (if (= i (- (char->integer #\I) (char->integer #\A)))
1134 (vector-set! number->mark-letter-vector j
1135 (integer->char (+ i (char->integer #\A)))))
1137 (define number->mark-alphabet-vector (list->vector
1138 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
1140 (define (number->markletter-string vec n)
1141 "Double letters for big marks."
1142 (let* ((lst (vector-length vec)))
1145 (string-append (number->markletter-string vec (1- (quotient n lst)))
1146 (number->markletter-string vec (remainder n lst)))
1147 (make-string 1 (vector-ref vec n)))))
1149 (define-builtin-markup-command (markletter layout props num) (integer?)
1150 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1151 (skipping letter@tie{}I), and continue with double letters."
1152 (ly:text-interface::interpret-markup layout props
1153 (number->markletter-string number->mark-letter-vector num)))
1155 (define-builtin-markup-command (markalphabet layout props num) (integer?)
1156 "Make a markup letter for @var{num}. The letters start with A to@tie{}Z
1157 and continue with double letters."
1158 (ly:text-interface::interpret-markup layout props
1159 (number->markletter-string number->mark-alphabet-vector num)))
1163 (define-builtin-markup-command (slashed-digit layout props num) (integer?)
1164 "A feta number, with slash. This is for use in the context of
1165 figured bass notation."
1167 ((mag (magstep (chain-assoc-get 'font-size props 0)))
1170 (chain-assoc-get 'thickness props 0.16)))
1172 (number-stencil (interpret-markup layout
1173 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1174 (number->string num)))
1175 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1177 (num-y (ly:stencil-extent number-stencil Y))
1178 (is-sane (and (interval-sane? num-x) (interval-sane? num-y)))
1185 ,(car num-x) ,(- (interval-center num-y) dy)
1186 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1192 ((not (ly:stencil? slash-stencil)) #f)
1193 ((= num 5) (ly:stencil-translate slash-stencil
1194 ;;(cons (* mag -0.05) (* mag 0.42))
1195 (cons (* mag -0.00) (* mag -0.07))
1198 ((= num 7) (ly:stencil-translate slash-stencil
1199 ;;(cons (* mag -0.05) (* mag 0.42))
1200 (cons (* mag -0.00) (* mag -0.15))
1204 (else slash-stencil)))
1207 (set! number-stencil
1208 (ly:stencil-add number-stencil slash-stencil))
1210 (ly:warning "invalid number for slashed digit ~a" num))
1215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1216 ;; the note command.
1217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1220 ;; TODO: better syntax.
1222 (define-builtin-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1223 "Construct a note symbol, with stem. By using fractional values for
1224 @var{dir}, you can obtain longer or shorter stems."
1226 (define (get-glyph-name-candidates dir log style)
1227 (map (lambda (dir-name)
1228 (format "noteheads.~a~a~a" dir-name (min log 2)
1229 (if (and (symbol? style)
1230 (not (equal? 'default style)))
1231 (symbol->string style)
1233 (list (if (= dir UP) "u" "d")
1236 (define (get-glyph-name font cands)
1239 (if (ly:stencil-empty? (ly:font-get-glyph font (car cands)))
1240 (get-glyph-name font (cdr cands))
1243 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1244 (size-factor (magstep (chain-assoc-get 'font-size props 0)))
1245 (style (chain-assoc-get 'style props '()))
1246 (stem-length (* size-factor (max 3 (- log 1))))
1247 (head-glyph-name (get-glyph-name font (get-glyph-name-candidates (sign dir) log style)))
1248 (head-glyph (ly:font-get-glyph font head-glyph-name))
1249 (attach-indices (ly:note-head::stem-attachment font head-glyph-name))
1250 (stem-thickness (* size-factor 0.13))
1251 (stemy (* dir stem-length))
1252 (attach-off (cons (interval-index
1253 (ly:stencil-extent head-glyph X)
1254 (* (sign dir) (car attach-indices)))
1255 (* (sign dir) ; fixme, this is inconsistent between X & Y.
1257 (ly:stencil-extent head-glyph Y)
1258 (cdr attach-indices)))))
1259 (stem-glyph (and (> log 0)
1260 (ly:round-filled-box
1261 (ordered-cons (car attach-off)
1262 (+ (car attach-off) (* (- (sign dir)) stem-thickness)))
1263 (cons (min stemy (cdr attach-off))
1264 (max stemy (cdr attach-off)))
1265 (/ stem-thickness 3))))
1267 (dot (ly:font-get-glyph font "dots.dot"))
1268 (dotwid (interval-length (ly:stencil-extent dot X)))
1269 (dots (and (> dot-count 0)
1270 (apply ly:stencil-add
1272 (ly:stencil-translate-axis
1273 dot (* 2 x dotwid) X))
1274 (iota dot-count)))))
1275 (flaggl (and (> log 2)
1276 (ly:stencil-translate
1277 (ly:font-get-glyph font
1278 (string-append "flags."
1279 (if (> dir 0) "u" "d")
1280 (number->string log)))
1281 (cons (+ (car attach-off) (/ stem-thickness 2)) stemy)))))
1283 (if (and dots flaggl (> dir 0))
1284 (set! dots (ly:stencil-translate-axis dots 0.35 X)))
1286 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1287 (if (ly:stencil? stem-glyph)
1288 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1289 (set! stem-glyph head-glyph))
1290 (if (ly:stencil? dots)
1293 (ly:stencil-translate-axis
1295 (+ (cdr (ly:stencil-extent head-glyph X)) dotwid)
1301 (let ((divisor (log 2)))
1302 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1304 (define (parse-simple-duration duration-string)
1305 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1306 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1307 (if (and match (string=? duration-string (match:substring match 0)))
1308 (let ((len (match:substring match 1))
1309 (dots (match:substring match 2)))
1310 (list (cond ((string=? len "breve") -1)
1311 ((string=? len "longa") -2)
1312 ((string=? len "maxima") -3)
1313 (else (log2 (string->number len))))
1314 (if dots (string-length dots) 0)))
1315 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1317 (define-builtin-markup-command (note layout props duration dir) (string? number?)
1318 "This produces a note with a stem pointing in @var{dir} direction, with
1319 the @var{duration} for the note head type and augmentation dots. For
1320 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1321 a shortened down stem."
1322 (let ((parsed (parse-simple-duration duration)))
1323 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1328 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1330 (define-builtin-markup-command (lower layout props amount arg) (number? markup?)
1331 "Lower @var{arg} by the distance @var{amount}.
1332 A negative @var{amount} indicates raising; see also @code{\\raise}."
1333 (ly:stencil-translate-axis (interpret-markup layout props arg)
1337 (define-builtin-markup-command (translate-scaled layout props offset arg) (number-pair? markup?)
1338 "Translate @var{arg} by @var{offset}, scaling the offset by the
1341 ((factor (magstep (chain-assoc-get 'font-size props 0)))
1342 (scaled (cons (* factor (car offset))
1343 (* factor (cdr offset)))))
1345 (ly:stencil-translate (interpret-markup layout props arg)
1348 (define-builtin-markup-command (raise layout props amount arg) (number? markup?)
1349 "Raise @var{arg} by the distance @var{amount}.
1350 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1352 @lilypond[verbatim,fragment,relative=1]
1353 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" } }
1355 The argument to @code{\\raise} is the vertical displacement amount,
1356 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1357 raise objects in relation to their surrounding markups.
1359 If the text object itself is positioned above or below the staff, then
1360 @code{\\raise} cannot be used to move it, since the mechanism that
1361 positions it next to the staff cancels any shift made with
1362 @code{\\raise}. For vertical positioning, use the @code{padding}
1363 and/or @code{extra-offset} properties."
1364 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1366 (define-builtin-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1367 "Make a fraction of two markups."
1368 (let* ((m1 (interpret-markup layout props arg1))
1369 (m2 (interpret-markup layout props arg2))
1370 (factor (magstep (chain-assoc-get 'font-size props 0)))
1371 (boxdimen (cons (* factor -0.05) (* factor 0.05)))
1372 (padding (* factor 0.2))
1373 (baseline (* factor 0.6))
1374 (offset (* factor 0.75)))
1375 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1376 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1377 (let* ((x1 (ly:stencil-extent m1 X))
1378 (x2 (ly:stencil-extent m2 X))
1379 (line (ly:round-filled-box (interval-union x1 x2) boxdimen 0.0))
1380 ;; should stack mols separately, to maintain LINE on baseline
1381 (stack (stack-lines DOWN padding baseline (list m1 line m2))))
1383 (ly:stencil-aligned-to stack Y CENTER))
1385 (ly:stencil-aligned-to stack X LEFT))
1386 ;; should have EX dimension
1388 (ly:stencil-translate-axis stack offset Y))))
1390 (define-builtin-markup-command (normal-size-super layout props arg) (markup?)
1391 "Set @var{arg} in superscript with a normal font size."
1392 (ly:stencil-translate-axis
1393 (interpret-markup layout props arg)
1394 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1396 (define-builtin-markup-command (super layout props arg) (markup?)
1398 @cindex raising text
1399 @cindex lowering text
1401 @cindex translating text
1403 @cindex @code{\\super}
1405 Raising and lowering texts can be done with @code{\\super} and
1408 @lilypond[verbatim,fragment,relative=1]
1409 c1^\\markup { E \"=\" \\concat { \"mc\" \\super \"2\" } }
1411 (ly:stencil-translate-axis
1414 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1416 (* 0.5 (chain-assoc-get 'baseline-skip props))
1419 (define-builtin-markup-command (translate layout props offset arg) (number-pair? markup?)
1420 "This translates an object. Its first argument is a cons of numbers.
1423 A \\translate #(cons 2 -3) @{ B C @} D
1426 This moves @q{B C} 2@tie{}spaces to the right, and 3 down, relative to its
1427 surroundings. This command cannot be used to move isolated scripts
1428 vertically, for the same reason that @code{\\raise} cannot be used for
1430 (ly:stencil-translate (interpret-markup layout props arg)
1433 (define-builtin-markup-command (sub layout props arg) (markup?)
1434 "Set @var{arg} in subscript."
1435 (ly:stencil-translate-axis
1438 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1440 (* -0.5 (chain-assoc-get 'baseline-skip props))
1443 (define-builtin-markup-command (normal-size-sub layout props arg) (markup?)
1444 "Set @var{arg} in subscript, in a normal font size."
1445 (ly:stencil-translate-axis
1446 (interpret-markup layout props arg)
1447 (* -0.5 (chain-assoc-get 'baseline-skip props))
1450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1454 (define-builtin-markup-command (hbracket layout props arg) (markup?)
1455 "Draw horizontal brackets around @var{arg}."
1456 (let ((th 0.1) ;; todo: take from GROB.
1457 (m (interpret-markup layout props arg)))
1458 (bracketify-stencil m X th (* 2.5 th) th)))
1460 (define-builtin-markup-command (bracket layout props arg) (markup?)
1461 "Draw vertical brackets around @var{arg}."
1462 (let ((th 0.1) ;; todo: take from GROB.
1463 (m (interpret-markup layout props arg)))
1464 (bracketify-stencil m Y th (* 2.5 th) th)))
1466 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1467 ;; Delayed markup evaluation
1468 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1470 (define-builtin-markup-command (page-ref layout props label gauge default)
1471 (symbol? markup? markup?)
1472 "Reference to a page number. @var{label} is the label set on the referenced
1473 page (using the @code{\\label} command), @var{gauge} a markup used to estimate
1474 the maximum width of the page number, and @var{default} the value to display
1475 when @var{label} is not found."
1476 (let* ((gauge-stencil (interpret-markup layout props gauge))
1477 (x-ext (ly:stencil-extent gauge-stencil X))
1478 (y-ext (ly:stencil-extent gauge-stencil Y)))
1480 `(delay-stencil-evaluation
1481 ,(delay (ly:stencil-expr
1482 (let* ((table (ly:output-def-lookup layout 'label-page-table))
1483 (label-page (and (list? table) (assoc label table)))
1484 (page-number (and label-page (cdr label-page)))
1485 (page-markup (if page-number (format "~a" page-number) default))
1486 (page-stencil (interpret-markup layout props page-markup))
1487 (gap (- (interval-length x-ext)
1488 (interval-length (ly:stencil-extent page-stencil X)))))
1489 (interpret-markup layout props
1490 (markup #:concat (#:hspace gap page-markup)))))))