1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.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 (define-public empty-stencil (ly:make-stencil '() '(1 . -1) '(1 . -1)))
16 (define-public point-stencil (ly:make-stencil "" '(0 . 0) '(0 . 0)))
18 (def-markup-command (stencil layout props stil) (ly:stencil?)
22 (def-markup-command (draw-circle layout props radius thickness fill)
23 (number? number? boolean?)
24 "A circle of radius @var{radius}, thickness @var{thickness} and
26 (make-circle-stencil radius thickness fill))
28 (def-markup-command (triangle layout props filled) (boolean?)
29 "A triangle, filled or not"
31 ((th (chain-assoc-get 'thickness props 0.1))
32 (size (chain-assoc-get 'font-size props 0))
35 (chain-assoc-get 'baseline-skip props 2))))
49 (def-markup-command (circle layout props arg) (markup?)
50 "Draw a circle around @var{arg}. Use @code{thickness},
51 @code{circle-padding} and @code{font-size} properties to determine line
52 thickness and padding around the markup."
53 (let* ((th (chain-assoc-get 'thickness props 0.1))
54 (size (chain-assoc-get 'font-size props 0))
57 (chain-assoc-get 'circle-padding props 0.2)))
58 (m (interpret-markup layout props arg)))
59 (circle-stencil m th pad)))
61 (def-markup-command (with-url layout props url arg) (string? markup?)
62 "Add a link to URL @var{url} around @var{arg}. This only works in
64 (let* ((stil (interpret-markup layout props arg))
65 (xextent (ly:stencil-extent stil X))
66 (yextent (ly:stencil-extent stil Y))
67 (old-expr (ly:stencil-expr stil))
68 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
69 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
73 (make-regexp "%%BoundingBox: ([0-9-]+) ([0-9-]+) ([0-9-]+) ([0-9-]+)"))
75 (define (get-postscript-bbox string)
76 "Extract the bbox from STRING, or return #f if not present."
78 ((match (regexp-exec bbox-regexp string)))
82 (string->number (match:substring match x)))
87 (def-markup-command (epsfile layout props file-name) (string?)
88 "Inline an EPS image. The image is scaled such that 10 PS units is
91 (if (ly:get-option 'safe)
92 (interpret-markup layout props "not allowed in safe")
94 ((contents (ly:gulp-file file-name))
95 (bbox (get-postscript-bbox contents))
98 (map (lambda (x) (/ x 10)) bbox)
100 (ly:warn (_ "can't find bounding box of `~a'")
115 (format "\n%%BeginDocument: ~a\n" file-name)
120 (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
121 (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
123 (ly:make-stencil "" '(0 . 0) '(0 . 0))))))
125 (def-markup-command (score layout props score) (ly:score?)
126 "Inline an image of music."
127 (let* ((output (ly:score-embedded-format score layout)))
129 (if (ly:music-output? output)
130 (ly:paper-system-stencil
131 (vector-ref (ly:paper-score-paper-systems output) 0))
133 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
136 (def-markup-command (simple layout props str) (string?)
137 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
138 @code{\\markup @{ \\simple #\"foo\" @}}."
139 (interpret-markup layout props str))
141 (def-markup-command (encoded-simple layout props sym str) (symbol? string?)
142 "A text string, encoded with encoding @var{sym}. See
143 @usermanref{Text encoding} for more information."
144 (Text_interface::interpret_string layout props sym str))
147 ;; TODO: use font recoding.
149 ;; (map make-word-markup (string-tokenize str)))))
151 (define-public empty-markup
152 (make-simple-markup ""))
155 (def-markup-command (postscript layout props str) (string?)
156 "This inserts @var{str} directly into the output as a PostScript
157 command string. Due to technicalities of the output backends,
158 different scales should be used for the @TeX{} and PostScript backend,
159 selected with @code{-f}.
162 For the TeX backend, the following string prints a rotated text
167 0 0 moveto /ecrm10 findfont
168 1.75 scalefont setfont 90 rotate (hello) show
172 The magical constant 1.75 scales from LilyPond units (staff spaces) to
175 For the postscript backend, use the following
178 gsave /ecrm10 findfont
179 10.0 output-scale div
180 scalefont setfont 90 rotate (hello) show grestore
185 (list 'embedded-ps str)
188 ;;(def-markup-command (fill-line layout props line-width markups)
189 ;; (number? markup-list?)
190 ;; no parser tag -- should make number? markuk-list? thingy
191 (def-markup-command (fill-line layout props markups)
193 "Put @var{markups} in a horizontal line of width @var{line-width}.
194 The markups are spaced/flushed to fill the entire line.
195 If there are no arguments, return an empty stencil.
197 (let* ((orig-stencils
198 (map (lambda (x) (interpret-markup layout props x))
202 (if (ly:stencil-empty? stc)
204 stc)) orig-stencils))
207 (if (ly:stencil-empty? stc)
209 (interval-length (ly:stencil-extent stc X))))
211 (text-width (apply + text-widths))
212 (word-count (length stencils))
213 (word-space (chain-assoc-get 'word-space props))
214 (line-width (chain-assoc-get 'linewidth props))
219 (/ (- line-width text-width) 2)
220 (/ (- line-width text-width) 2)))
223 (- line-width text-width)))
225 (get-fill-space word-count line-width text-widths))))
233 (line-stencils (if (= word-count 1)
240 (if (null? (remove ly:stencil-empty? orig-stencils))
242 (stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
244 (define (get-fill-space word-count line-width text-widths)
245 "Calculate the necessary paddings between each two adjacent texts.
246 The lengths of all texts are stored in @var{text-widths}.
247 The normal formula for the padding between texts a and b is:
248 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
249 The first and last padding have to be calculated specially using the
250 whole length of the first or last text.
251 Return a list of paddings.
254 ;; special case first padding
255 ((= (length text-widths) word-count)
257 (- (- (/ line-width (1- word-count)) (car text-widths))
258 (/ (car (cdr text-widths)) 2))
259 (get-fill-space word-count line-width (cdr text-widths))))
260 ;; special case last padding
261 ((= (length text-widths) 2)
262 (list (- (/ line-width (1- word-count))
263 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
266 (- (/ line-width (1- word-count))
267 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
268 (get-fill-space word-count line-width (cdr text-widths))))))
270 (define (font-markup qualifier value)
271 (lambda (layout props arg)
272 (interpret-markup layout (prepend-alist-chain qualifier value props) arg)))
274 (def-markup-command (line layout props args) (markup-list?)
275 "Put @var{args} in a horizontal line. The property @code{word-space}
276 determines the space between each markup in @var{args}."
278 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
279 (space (chain-assoc-get 'word-space props)))
283 (remove ly:stencil-empty? stencils))))
285 (def-markup-command (fromproperty layout props symbol) (symbol?)
286 "Read the @var{symbol} from property settings, and produce a stencil
287 from the markup contained within. If @var{symbol} is not defined, it
288 returns an empty markup"
289 (let* ((m (chain-assoc-get symbol props)))
291 (interpret-markup layout props m)
292 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
295 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
296 "Apply the @var{procedure} markup command to
297 @var{arg}. @var{procedure} should take a single argument."
298 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
299 (set-object-property! anonymous-with-signature
302 (interpret-markup layout props (list anonymous-with-signature arg))))
305 (def-markup-command (combine layout props m1 m2) (markup? markup?)
306 "Print two markups on top of each other."
307 (let* ((s1 (interpret-markup layout props m1))
308 (s2 (interpret-markup layout props m2)))
309 (ly:stencil-add s1 s2)))
311 (def-markup-command (finger layout props arg) (markup?)
312 "Set the argument as small numbers."
313 (interpret-markup layout
314 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
317 (def-markup-command (fontsize layout props mag arg) (number? markup?)
318 "Set the relative font size, e.g.
320 A \\fontsize #2 @{ B C @} D
324 This will enlarge the B and the C by two steps.
328 (prepend-alist-chain 'font-size mag props)
332 ;; FIXME -> should convert to font-size.
333 (def-markup-command (magnify layout props sz arg) (number? markup?)
334 "Set the font magnification for the its argument. In the following
335 example, the middle A will be 10% larger:
337 A \\magnify #1.1 @{ A @} A
340 Note: magnification only works if a font-name is explicitly selected.
341 Use @code{\\fontsize} otherwise."
344 (prepend-alist-chain 'font-magnification sz props)
347 (def-markup-command (bold layout props arg) (markup?)
348 "Switch to bold font-series"
349 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
351 (def-markup-command (sans layout props arg) (markup?)
352 "Switch to the sans serif family"
353 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
355 (def-markup-command (number layout props arg) (markup?)
356 "Set font family to @code{number}, which yields the font used for
357 time signatures and fingerings. This font only contains numbers and
358 some punctuation. It doesn't have any letters. "
359 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
361 (def-markup-command (roman layout props arg) (markup?)
362 "Set font family to @code{roman}."
363 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
365 (def-markup-command (huge layout props arg) (markup?)
366 "Set font size to +2."
367 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
369 (def-markup-command (large layout props arg) (markup?)
370 "Set font size to +1."
371 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
373 (def-markup-command (normalsize layout props arg) (markup?)
374 "Set font size to default."
375 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
377 (def-markup-command (small layout props arg) (markup?)
378 "Set font size to -1."
379 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
381 (def-markup-command (tiny layout props arg) (markup?)
382 "Set font size to -2."
383 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
385 (def-markup-command (teeny layout props arg) (markup?)
386 "Set font size to -3."
387 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
389 (def-markup-command (caps layout props arg) (markup?)
390 "Set @code{font-shape} to @code{caps}."
391 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
393 ;(def-markup-command (latin-i layout props arg) (markup?)
394 ; "TEST latin1 encoding."
395 ; (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
397 (def-markup-command (dynamic layout props arg) (markup?)
398 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
399 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
400 normal words (like ``pi@`{u}'') should be done in a different font. The
401 recommend font for this is bold and italic"
403 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
405 (def-markup-command (italic layout props arg) (markup?)
406 "Use italic @code{font-shape} for @var{arg}. "
407 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
409 (def-markup-command (typewriter layout props arg) (markup?)
410 "Use @code{font-family} typewriter for @var{arg}."
412 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
414 (def-markup-command (upright layout props arg) (markup?)
415 "Set font shape to @code{upright}."
417 layout (prepend-alist-chain 'font-shape 'upright props) arg))
419 (def-markup-command (doublesharp layout props) ()
420 "Draw a double sharp symbol."
422 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
423 (def-markup-command (sesquisharp layout props) ()
424 "Draw a 3/2 sharp symbol."
425 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
427 (def-markup-command (sharp layout props) ()
428 "Draw a sharp symbol."
429 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
431 (def-markup-command (semisharp layout props) ()
432 "Draw a semi sharp symbol."
433 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
435 (def-markup-command (natural layout props) ()
436 "Draw a natural symbol."
437 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
439 (def-markup-command (semiflat layout props) ()
441 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
443 (def-markup-command (flat layout props) ()
444 "Draw a flat symbol."
445 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
447 (def-markup-command (sesquiflat layout props) ()
448 "Draw a 3/2 flat symbol."
449 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
451 (def-markup-command (doubleflat layout props) ()
452 "Draw a double flat symbol."
453 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
455 (def-markup-command (with-color layout props color arg) (color? markup?)
456 "Draw @var{arg} in color specified by @var{color}"
458 (let* ((stil (interpret-markup layout props arg)))
460 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
461 (ly:stencil-extent stil X)
462 (ly:stencil-extent stil Y))))
465 ;; TODO: should extract baseline-skip from each argument somehow..
467 (def-markup-command (column layout props args) (markup-list?)
468 "Stack the markups in @var{args} vertically. The property
469 @code{baseline-skip} determines the space between each markup in @var{args}."
471 -1 0.0 (chain-assoc-get 'baseline-skip props)
472 (remove ly:stencil-empty?
473 (map (lambda (m) (interpret-markup layout props m)) args))))
475 (def-markup-command (dir-column layout props args) (markup-list?)
476 "Make a column of args, going up or down, depending on the setting
477 of the @code{#'direction} layout property."
478 (let* ((dir (chain-assoc-get 'direction props)))
480 (if (number? dir) dir -1)
482 (chain-assoc-get 'baseline-skip props)
483 (map (lambda (x) (interpret-markup layout props x)) args))))
485 (def-markup-command (center-align layout props args) (markup-list?)
486 "Put @code{args} in a centered column. "
487 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
488 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
489 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
491 (def-markup-command (vcenter layout props arg) (markup?)
492 "Align @code{arg} to its Y center. "
493 (let* ((mol (interpret-markup layout props arg)))
494 (ly:stencil-aligned-to mol Y CENTER)))
496 (def-markup-command (hcenter layout props arg) (markup?)
497 "Align @code{arg} to its X center. "
498 (let* ((mol (interpret-markup layout props arg)))
499 (ly:stencil-aligned-to mol X CENTER)))
501 (def-markup-command (right-align layout props arg) (markup?)
502 "Align @var{arg} on its right edge. "
503 (let* ((m (interpret-markup layout props arg)))
504 (ly:stencil-aligned-to m X RIGHT)))
506 (def-markup-command (left-align layout props arg) (markup?)
507 "Align @var{arg} on its left edge. "
508 (let* ((m (interpret-markup layout props arg)))
509 (ly:stencil-aligned-to m X LEFT)))
511 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
512 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
513 (let* ((m (interpret-markup layout props arg)))
514 (ly:stencil-aligned-to m axis dir)))
516 (def-markup-command (halign layout props dir arg) (number? markup?)
517 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
518 left-aligned, while @code{+1} is right. Values in between interpolate
519 alignment accordingly."
520 (let* ((m (interpret-markup layout props arg)))
521 (ly:stencil-aligned-to m X dir)))
523 (def-markup-command (musicglyph layout props glyph-name) (string?)
524 "This is converted to a musical symbol, e.g. @code{\\musicglyph
525 #\"accidentals.0\"} will select the natural sign from the music font.
526 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
528 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
532 (def-markup-command (lookup layout props glyph-name) (string?)
533 "Lookup a glyph by name."
534 (ly:font-get-glyph (ly:paper-get-font layout props)
537 (def-markup-command (char layout props num) (integer?)
538 "Produce a single character, e.g. @code{\\char #65} produces the
540 (ly:get-glyph (ly:paper-get-font layout props) num))
542 (def-markup-command (lower layout props amount arg) (number? markup?)
544 Lower @var{arg}, by the distance @var{amount}.
545 A negative @var{amount} indicates raising, see also @code{\raise}.
547 (ly:stencil-translate-axis (interpret-markup layout props arg)
550 (def-markup-command (raise layout props amount arg) (number? markup?)
552 Raise @var{arg}, by the distance @var{amount}.
553 A negative @var{amount} indicates lowering, see also @code{\\lower}.
555 @lilypond[verbatim,fragment,relative=1]
556 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
558 The argument to @code{\\raise} is the vertical displacement amount,
559 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
560 raise objects in relation to their surrounding markups.
562 If the text object itself is positioned above or below the staff, then
563 @code{\\raise} cannot be used to move it, since the mechanism that
564 positions it next to the staff cancels any shift made with
565 @code{\\raise}. For vertical positioning, use the @code{padding}
566 and/or @code{extra-offset} properties. "
567 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
569 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
570 "Make a fraction of two markups."
571 (let* ((m1 (interpret-markup layout props arg1))
572 (m2 (interpret-markup layout props arg2)))
573 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
574 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
575 (let* ((x1 (ly:stencil-extent m1 X))
576 (x2 (ly:stencil-extent m2 X))
577 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
578 ;; should stack mols separately, to maintain LINE on baseline
579 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
581 (ly:stencil-aligned-to stack Y CENTER))
583 (ly:stencil-aligned-to stack X LEFT))
584 ;; should have EX dimension
586 (ly:stencil-translate-axis stack 0.75 Y))))
590 (def-markup-command (filled-box layout props xext yext blot)
591 (number-pair? number-pair? number?)
592 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
596 (def-markup-command (whiteout layout props arg) (markup?)
597 "Provide a white underground for @var{arg}"
598 (let* ((stil (interpret-markup layout props
599 (make-with-color-markup black arg)))
601 (interpret-markup layout props
602 (make-with-color-markup
604 (make-filled-box-markup
605 (ly:stencil-extent stil X)
606 (ly:stencil-extent stil Y)
609 (ly:stencil-add white stil)))
611 ;; TODO: better syntax.
613 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
614 "Construct a note symbol, with stem. By using fractional values for
615 @var{dir}, you can obtain longer or shorter stems."
616 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
617 (size (chain-assoc-get 'font-size props 0))
618 (stem-length (* (magstep size) (max 3 (- log 1))))
619 (head-glyph (ly:font-get-glyph
621 (string-append "noteheads.s" (number->string (min log 2)))))
622 (stem-thickness 0.13)
623 (stemy (* dir stem-length))
624 (attachx (if (> dir 0)
625 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
627 (attachy (* dir 0.28))
628 (stem-glyph (and (> log 0)
630 (cons attachx (+ attachx stem-thickness))
631 (cons (min stemy attachy)
633 (/ stem-thickness 3))))
634 (dot (ly:font-get-glyph font "dots.dot"))
635 (dotwid (interval-length (ly:stencil-extent dot X)))
636 (dots (and (> dot-count 0)
637 (apply ly:stencil-add
639 (ly:stencil-translate-axis
640 dot (* (+ 1 (* 2 x)) dotwid) X))
641 (iota dot-count 1)))))
642 (flaggl (and (> log 2)
643 (ly:stencil-translate
644 (ly:font-get-glyph font
645 (string-append "flags."
646 (if (> dir 0) "u" "d")
647 (number->string log)))
648 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
650 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
651 (if (ly:stencil? stem-glyph)
652 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
653 (set! stem-glyph head-glyph))
654 (if (ly:stencil? dots)
657 (ly:stencil-translate-axis
659 (+ (if (and (> dir 0) (> log 2))
662 ;; huh ? why not necessary?
663 ;;(cdr (ly:stencil-extent head-glyph X))
670 (let ((divisor (log 2)))
671 (lambda (z) (inexact->exact (/ (log z) divisor)))))
673 (define (parse-simple-duration duration-string)
674 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
675 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
676 (if (and match (string=? duration-string (match:substring match 0)))
677 (let ((len (match:substring match 1))
678 (dots (match:substring match 2)))
679 (list (cond ((string=? len "breve") -1)
680 ((string=? len "longa") -2)
681 ((string=? len "maxima") -3)
682 (else (log2 (string->number len))))
683 (if dots (string-length dots) 0)))
684 (ly:error (_ "not a valid duration string: ~a") duration-string))))
686 (def-markup-command (note layout props duration dir) (string? number?)
687 "This produces a note with a stem pointing in @var{dir} direction, with
688 the @var{duration} for the note head type and augmentation dots. For
689 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
690 a shortened down stem."
691 (let ((parsed (parse-simple-duration duration)))
692 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
694 (def-markup-command (normal-size-super layout props arg) (markup?)
695 "Set @var{arg} in superscript with a normal font size."
696 (ly:stencil-translate-axis
697 (interpret-markup layout props arg)
698 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
700 (def-markup-command (super layout props arg) (markup?)
703 @cindex lowering text
705 @cindex translating text
707 @cindex @code{\\super}
710 Raising and lowering texts can be done with @code{\\super} and
713 @lilypond[verbatim,fragment,relative=1]
714 c1^\\markup { E \"=\" mc \\super \"2\" }
718 (ly:stencil-translate-axis
721 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
723 (* 0.5 (chain-assoc-get 'baseline-skip props))
726 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
727 "This translates an object. Its first argument is a cons of numbers
729 A \\translate #(cons 2 -3) @{ B C @} D
731 This moves `B C' 2 spaces to the right, and 3 down, relative to its
732 surroundings. This command cannot be used to move isolated scripts
733 vertically, for the same reason that @code{\\raise} cannot be used for
737 (ly:stencil-translate (interpret-markup layout props arg)
740 (def-markup-command (sub layout props arg) (markup?)
741 "Set @var{arg} in subscript."
742 (ly:stencil-translate-axis
745 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
747 (* -0.5 (chain-assoc-get 'baseline-skip props))
750 (def-markup-command (beam layout props width slope thickness)
751 (number? number? number?)
752 "Create a beam with the specified parameters."
753 (let* ((y (* slope width))
754 (yext (cons (min 0 y) (max 0 y)))
755 (half (/ thickness 2)))
761 (ly:output-def-lookup layout 'blotdiameter))
763 (cons (+ (- half) (car yext))
764 (+ half (cdr yext))))))
766 (def-markup-command (normal-size-sub layout props arg) (markup?)
767 "Set @var{arg} in subscript, in a normal font size."
768 (ly:stencil-translate-axis
769 (interpret-markup layout props arg)
770 (* -0.5 (chain-assoc-get 'baseline-skip props))
773 (def-markup-command (hbracket layout props arg) (markup?)
774 "Draw horizontal brackets around @var{arg}."
775 (let ((th 0.1) ;; todo: take from GROB.
776 (m (interpret-markup layout props arg)))
777 (bracketify-stencil m X th (* 2.5 th) th)))
779 (def-markup-command (bracket layout props arg) (markup?)
780 "Draw vertical brackets around @var{arg}."
781 (let ((th 0.1) ;; todo: take from GROB.
782 (m (interpret-markup layout props arg)))
783 (bracketify-stencil m Y th (* 2.5 th) th)))
785 ;; todo: fix negative space
786 (def-markup-command (hspace layout props amount) (number?)
787 "This produces a invisible object taking horizontal space.
789 \\markup @{ A \\hspace #2.0 B @}
791 will put extra space between A and B, on top of the space that is
792 normally inserted before elements on a line.
795 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
796 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
798 (def-markup-command (override layout props new-prop arg) (pair? markup?)
799 "Add the first argument in to the property list. Properties may be
800 any sort of property supported by @internalsref{font-interface} and
801 @internalsref{text-interface}, for example
804 \\override #'(font-family . married) \"bla\"
808 (interpret-markup layout (cons (list new-prop) props) arg))
811 (def-markup-command (fontsize layout props increment arg) (number? markup?)
812 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
814 (let* ((fs (chain-assoc-get 'font-size props 0))
815 (bs (chain-assoc-get 'baseline-skip props 2))
817 (cons 'baseline-skip (* bs (magstep increment)))
818 (cons 'font-size (+ fs increment )))))
820 (interpret-markup layout (cons entries props) arg)))
822 (def-markup-command (bigger layout props arg) (markup?)
823 "Increase the font size relative to current setting"
824 (interpret-markup layout props
825 `(,fontsize-markup 1 ,arg)))
827 (def-markup-command (smaller layout props arg) (markup?)
828 "Decrease the font size relative to current setting"
829 (interpret-markup layout props
830 `(,fontsize-markup -1 ,arg)))
832 (def-markup-command larger (markup?) bigger-markup)
834 (def-markup-command (box layout props arg) (markup?)
835 "Draw a box round @var{arg}. Looks at @code{thickness},
836 @code{box-padding} and @code{font-size} properties to determine line
837 thickness and padding around the markup."
838 (let* ((th (chain-assoc-get 'thickness props 0.1))
839 (size (chain-assoc-get 'font-size props 0))
840 (pad (* (magstep size)
841 (chain-assoc-get 'box-padding props 0.2)))
842 (m (interpret-markup layout props arg)))
843 (box-stencil m th pad)))
845 ;;FIXME: is this working?
846 (def-markup-command (strut layout props) ()
847 "Create a box of the same height as the space in the current font."
848 (let ((m (Text_interface::interpret_markup layout props " ")))
849 (ly:make-stencil (ly:stencil-expr m)
850 (ly:stencil-extent m X)
853 (define number->mark-letter-vector (make-vector 25 #\A))
858 (if (= i (- (char->integer #\I) (char->integer #\A)))
860 (vector-set! number->mark-letter-vector j
861 (integer->char (+ i (char->integer #\A)))))
863 (define number->mark-alphabet-vector (list->vector
864 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
866 (define (number->markletter-string vec n)
867 "Double letters for big marks."
868 (let* ((lst (vector-length vec)))
871 (string-append (number->markletter-string vec (1- (quotient n lst)))
872 (number->markletter-string vec (remainder n lst)))
873 (make-string 1 (vector-ref vec n)))))
875 (def-markup-command (markletter layout props num) (integer?)
876 "Make a markup letter for @var{num}. The letters start with A to Z
877 (skipping I), and continues with double letters."
878 (Text_interface::interpret_markup layout props
879 (number->markletter-string number->mark-letter-vector num)))
881 (def-markup-command (markalphabet layout props num) (integer?)
882 "Make a markup letter for @var{num}. The letters start with A to Z
883 and continues with double letters."
884 (Text_interface::interpret_markup layout props
885 (number->markletter-string number->mark-alphabet-vector num)))
887 (def-markup-command (bracketed-y-column layout props indices args)
889 "Make a column of the markups in @var{args}, putting brackets around
890 the elements marked in @var{indices}, which is a list of numbers."
891 (define (sublist lst start stop)
892 (take (drop lst start) (- (1+ stop) start)))
894 (define (stencil-list-extent ss axis)
896 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
897 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
899 (define (stack-stencils stencils bskip last-stencil)
901 ((null? stencils) '())
902 ((not (ly:stencil? last-stencil))
904 (stack-stencils (cdr stencils) bskip (car stencils))))
906 (let* ((orig (car stencils))
907 (dir (chain-assoc-get 'direction props DOWN))
908 (new (ly:stencil-moved-to-edge last-stencil Y dir
912 (cons new (stack-stencils (cdr stencils) bskip new))))))
914 (define (make-brackets stencils indices acc)
917 (pair? (cdr indices)))
918 (let* ((encl (sublist stencils (car indices) (cadr indices)))
919 (x-ext (stencil-list-extent encl X))
920 (y-ext (stencil-list-extent encl Y))
923 (protusion (* 2.5 thick))
925 (ly:stencil-translate-axis
926 (ly:bracket Y y-ext thick protusion)
927 (- (car x-ext) pad) X))
928 (rb (ly:stencil-translate-axis
929 (ly:bracket Y y-ext thick (- protusion))
930 (+ (cdr x-ext) pad) X)))
933 stencils (cddr indices)
946 (chain-assoc-get 'baseline-skip props))
947 (stacked (stack-stencils
948 (remove ly:stencil-empty? stencils) 1.25 #f))
949 (brackets (make-brackets stacked indices '())))
951 (apply ly:stencil-add
952 (append stacked brackets))))