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 (circle layout props arg) (markup?)
29 "Draw a circle around @var{arg}. Use @code{thickness},
30 @code{circle-padding} and @code{font-size} properties to determine line
31 thickness and padding around the markup."
32 (let* ((th (chain-assoc-get 'thickness props 0.1))
33 (size (chain-assoc-get 'font-size props 0))
36 (chain-assoc-get 'circle-padding props 0.2)))
37 (m (interpret-markup layout props arg)))
38 (circle-stencil m th pad)))
40 (def-markup-command (with-url layout props url arg) (string? markup?)
41 "Add a link to URL @var{url} around @var{arg}. This only works in
43 (let* ((stil (interpret-markup layout props arg))
44 (xextent (ly:stencil-extent stil X))
45 (yextent (ly:stencil-extent stil Y))
46 (old-expr (ly:stencil-expr stil))
47 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
48 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
52 (make-regexp "%%BoundingBox: ([0-9-]+) ([0-9-]+) ([0-9-]+) ([0-9-]+)"))
54 (define (get-postscript-bbox string)
55 "Extract the bbox from STRING, or return #f if not present."
57 ((match (regexp-exec bbox-regexp string)))
61 (string->number (match:substring match x)))
66 (def-markup-command (epsfile layout props file-name) (string?)
67 "Inline an EPS image. The image is scaled such that 10 PS units is
70 (if (ly:get-option 'safe)
71 (interpret-markup layout props "not allowed in safe")
73 ((contents (ly:gulp-file file-name))
74 (bbox (get-postscript-bbox contents))
77 (map (lambda (x) (/ x 10)) bbox)
79 (ly:warn (_ "can't find bounding box of `~a'")
94 (format "\n%%BeginDocument: ~a\n" file-name)
99 (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
100 (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
102 (ly:make-stencil "" '(0 . 0) '(0 . 0))))))
104 (def-markup-command (score layout props score) (ly:score?)
105 "Inline an image of music."
106 (let* ((output (ly:score-embedded-format score layout)))
108 (if (ly:music-output? output)
109 (ly:paper-system-stencil
110 (vector-ref (ly:paper-score-paper-systems output) 0))
112 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
115 (def-markup-command (simple layout props str) (string?)
116 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
117 @code{\\markup @{ \\simple #\"foo\" @}}."
118 (interpret-markup layout props str))
120 (def-markup-command (encoded-simple layout props sym str) (symbol? string?)
121 "A text string, encoded with encoding @var{sym}. See
122 @usermanref{Text encoding} for more information."
123 (Text_interface::interpret_string layout props sym str))
126 ;; TODO: use font recoding.
128 ;; (map make-word-markup (string-tokenize str)))))
130 (define-public empty-markup
131 (make-simple-markup ""))
134 (def-markup-command (postscript layout props str) (string?)
135 "This inserts @var{str} directly into the output as a PostScript
136 command string. Due to technicalities of the output backends,
137 different scales should be used for the @TeX{} and PostScript backend,
138 selected with @code{-f}.
141 For the TeX backend, the following string prints a rotated text
146 0 0 moveto /ecrm10 findfont
147 1.75 scalefont setfont 90 rotate (hello) show
151 The magical constant 1.75 scales from LilyPond units (staff spaces) to
154 For the postscript backend, use the following
157 gsave /ecrm10 findfont
158 10.0 output-scale div
159 scalefont setfont 90 rotate (hello) show grestore
164 (list 'embedded-ps str)
167 ;;(def-markup-command (fill-line layout props line-width markups)
168 ;; (number? markup-list?)
169 ;; no parser tag -- should make number? markuk-list? thingy
170 (def-markup-command (fill-line layout props markups)
172 "Put @var{markups} in a horizontal line of width @var{line-width}.
173 The markups are spaced/flushed to fill the entire line.
174 If there are no arguments, return an empty stencil.
176 (let* ((orig-stencils
177 (map (lambda (x) (interpret-markup layout props x))
181 (if (ly:stencil-empty? stc)
183 stc)) orig-stencils))
186 (if (ly:stencil-empty? stc)
188 (interval-length (ly:stencil-extent stc X))))
190 (text-width (apply + text-widths))
191 (word-count (length stencils))
192 (word-space (chain-assoc-get 'word-space props))
193 (line-width (chain-assoc-get 'linewidth props))
198 (/ (- line-width text-width) 2)
199 (/ (- line-width text-width) 2)))
202 (- line-width text-width)))
204 (get-fill-space word-count line-width text-widths))))
212 (line-stencils (if (= word-count 1)
219 (if (null? (remove ly:stencil-empty? orig-stencils))
221 (stack-stencils-padding-list X RIGHT fill-space-normal line-stencils))))
223 (define (get-fill-space word-count line-width text-widths)
224 "Calculate the necessary paddings between each two adjacent texts.
225 The lengths of all texts are stored in @var{text-widths}.
226 The normal formula for the padding between texts a and b is:
227 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
228 The first and last padding have to be calculated specially using the
229 whole length of the first or last text.
230 Return a list of paddings.
233 ;; special case first padding
234 ((= (length text-widths) word-count)
236 (- (- (/ line-width (1- word-count)) (car text-widths))
237 (/ (car (cdr text-widths)) 2))
238 (get-fill-space word-count line-width (cdr text-widths))))
239 ;; special case last padding
240 ((= (length text-widths) 2)
241 (list (- (/ line-width (1- word-count))
242 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
245 (- (/ line-width (1- word-count))
246 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
247 (get-fill-space word-count line-width (cdr text-widths))))))
249 (define (font-markup qualifier value)
250 (lambda (layout props arg)
251 (interpret-markup layout (prepend-alist-chain qualifier value props) arg)))
253 (def-markup-command (line layout props args) (markup-list?)
254 "Put @var{args} in a horizontal line. The property @code{word-space}
255 determines the space between each markup in @var{args}."
257 (chain-assoc-get 'word-space props)
258 (remove ly:stencil-empty?
259 (map (lambda (m) (interpret-markup layout props m)) args))))
261 (def-markup-command (fromproperty layout props symbol) (symbol?)
262 "Read the @var{symbol} from property settings, and produce a stencil
263 from the markup contained within. If @var{symbol} is not defined, it
264 returns an empty markup"
265 (let* ((m (chain-assoc-get symbol props)))
267 (interpret-markup layout props m)
268 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
271 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
272 "Apply the @var{procedure} markup command to
273 @var{arg}. @var{procedure} should take a single argument."
274 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
275 (set-object-property! anonymous-with-signature
278 (interpret-markup layout props (list anonymous-with-signature arg))))
281 (def-markup-command (combine layout props m1 m2) (markup? markup?)
282 "Print two markups on top of each other."
283 (let* ((s1 (interpret-markup layout props m1))
284 (s2 (interpret-markup layout props m2)))
285 (ly:stencil-add s1 s2)))
287 (def-markup-command (finger layout props arg) (markup?)
288 "Set the argument as small numbers."
289 (interpret-markup layout
290 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
293 (def-markup-command (fontsize layout props mag arg) (number? markup?)
294 "Set the relative font size, e.g.
296 A \\fontsize #2 @{ B C @} D
300 This will enlarge the B and the C by two steps.
304 (prepend-alist-chain 'font-size mag props)
307 (def-markup-command (magnify layout props sz arg) (number? markup?)
308 "Set the font magnification for the its argument. In the following
309 example, the middle A will be 10% larger:
311 A \\magnify #1.1 @{ A @} A
314 Note: magnification only works if a font-name is explicitly selected.
315 Use @code{\\fontsize} otherwise."
318 (prepend-alist-chain 'font-magnification sz props)
321 (def-markup-command (bold layout props arg) (markup?)
322 "Switch to bold font-series"
323 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
325 (def-markup-command (sans layout props arg) (markup?)
326 "Switch to the sans serif family"
327 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
329 (def-markup-command (number layout props arg) (markup?)
330 "Set font family to @code{number}, which yields the font used for
331 time signatures and fingerings. This font only contains numbers and
332 some punctuation. It doesn't have any letters. "
333 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
335 (def-markup-command (roman layout props arg) (markup?)
336 "Set font family to @code{roman}."
337 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
339 (def-markup-command (huge layout props arg) (markup?)
340 "Set font size to +2."
341 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
343 (def-markup-command (large layout props arg) (markup?)
344 "Set font size to +1."
345 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
347 (def-markup-command (normalsize layout props arg) (markup?)
348 "Set font size to default."
349 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
351 (def-markup-command (small layout props arg) (markup?)
352 "Set font size to -1."
353 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
355 (def-markup-command (tiny layout props arg) (markup?)
356 "Set font size to -2."
357 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
359 (def-markup-command (teeny layout props arg) (markup?)
360 "Set font size to -3."
361 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
363 (def-markup-command (caps layout props arg) (markup?)
364 "Set @code{font-shape} to @code{caps}."
365 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
367 ;(def-markup-command (latin-i layout props arg) (markup?)
368 ; "TEST latin1 encoding."
369 ; (interpret-markup layout (prepend-alist-chain 'font-shape 'latin1 props) arg))
371 (def-markup-command (dynamic layout props arg) (markup?)
372 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
373 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
374 normal words (like ``pi@`{u}'') should be done in a different font. The
375 recommend font for this is bold and italic"
377 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
379 (def-markup-command (italic layout props arg) (markup?)
380 "Use italic @code{font-shape} for @var{arg}. "
381 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
383 (def-markup-command (typewriter layout props arg) (markup?)
384 "Use @code{font-family} typewriter for @var{arg}."
386 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
388 (def-markup-command (upright layout props arg) (markup?)
389 "Set font shape to @code{upright}."
391 layout (prepend-alist-chain 'font-shape 'upright props) arg))
393 (def-markup-command (doublesharp layout props) ()
394 "Draw a double sharp symbol."
396 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
397 (def-markup-command (sesquisharp layout props) ()
398 "Draw a 3/2 sharp symbol."
399 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
401 (def-markup-command (sharp layout props) ()
402 "Draw a sharp symbol."
403 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
405 (def-markup-command (semisharp layout props) ()
406 "Draw a semi sharp symbol."
407 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
409 (def-markup-command (natural layout props) ()
410 "Draw a natural symbol."
411 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
413 (def-markup-command (semiflat layout props) ()
415 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
417 (def-markup-command (flat layout props) ()
418 "Draw a flat symbol."
419 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
421 (def-markup-command (sesquiflat layout props) ()
422 "Draw a 3/2 flat symbol."
423 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
425 (def-markup-command (doubleflat layout props) ()
426 "Draw a double flat symbol."
427 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
429 (def-markup-command (with-color layout props color arg) (color? markup?)
430 "Draw @var{arg} in color specified by @var{color}"
432 (let* ((stil (interpret-markup layout props arg)))
434 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
435 (ly:stencil-extent stil X)
436 (ly:stencil-extent stil Y))))
439 ;; TODO: should extract baseline-skip from each argument somehow..
441 (def-markup-command (column layout props args) (markup-list?)
442 "Stack the markups in @var{args} vertically. The property
443 @code{baseline-skip} determines the space between each markup in @var{args}."
445 -1 0.0 (chain-assoc-get 'baseline-skip props)
446 (remove ly:stencil-empty?
447 (map (lambda (m) (interpret-markup layout props m)) args))))
449 (def-markup-command (dir-column layout props args) (markup-list?)
450 "Make a column of args, going up or down, depending on the setting
451 of the @code{#'direction} layout property."
452 (let* ((dir (chain-assoc-get 'direction props)))
454 (if (number? dir) dir -1)
456 (chain-assoc-get 'baseline-skip props)
457 (map (lambda (x) (interpret-markup layout props x)) args))))
459 (def-markup-command (center-align layout props args) (markup-list?)
460 "Put @code{args} in a centered column. "
461 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
462 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
463 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
465 (def-markup-command (vcenter layout props arg) (markup?)
466 "Align @code{arg} to its Y center. "
467 (let* ((mol (interpret-markup layout props arg)))
468 (ly:stencil-aligned-to mol Y CENTER)))
470 (def-markup-command (hcenter layout props arg) (markup?)
471 "Align @code{arg} to its X center. "
472 (let* ((mol (interpret-markup layout props arg)))
473 (ly:stencil-aligned-to mol X CENTER)))
475 (def-markup-command (right-align layout props arg) (markup?)
476 "Align @var{arg} on its right edge. "
477 (let* ((m (interpret-markup layout props arg)))
478 (ly:stencil-aligned-to m X RIGHT)))
480 (def-markup-command (left-align layout props arg) (markup?)
481 "Align @var{arg} on its left edge. "
482 (let* ((m (interpret-markup layout props arg)))
483 (ly:stencil-aligned-to m X LEFT)))
485 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
486 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
487 (let* ((m (interpret-markup layout props arg)))
488 (ly:stencil-aligned-to m axis dir)))
490 (def-markup-command (halign layout props dir arg) (number? markup?)
491 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
492 left-aligned, while @code{+1} is right. Values in between interpolate
493 alignment accordingly."
494 (let* ((m (interpret-markup layout props arg)))
495 (ly:stencil-aligned-to m X dir)))
497 (def-markup-command (musicglyph layout props glyph-name) (string?)
498 "This is converted to a musical symbol, e.g. @code{\\musicglyph
499 #\"accidentals.0\"} will select the natural sign from the music font.
500 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
502 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
506 (def-markup-command (lookup layout props glyph-name) (string?)
507 "Lookup a glyph by name."
508 (ly:font-get-glyph (ly:paper-get-font layout props)
511 (def-markup-command (char layout props num) (integer?)
512 "Produce a single character, e.g. @code{\\char #65} produces the
514 (ly:get-glyph (ly:paper-get-font layout props) num))
516 (def-markup-command (lower layout props amount arg) (number? markup?)
518 Lower @var{arg}, by the distance @var{amount}.
519 A negative @var{amount} indicates raising, see also @code{\raise}.
521 (ly:stencil-translate-axis (interpret-markup layout props arg)
524 (def-markup-command (raise layout props amount arg) (number? markup?)
526 Raise @var{arg}, by the distance @var{amount}.
527 A negative @var{amount} indicates lowering, see also @code{\\lower}.
529 @lilypond[verbatim,fragment,relative=1]
530 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
532 The argument to @code{\\raise} is the vertical displacement amount,
533 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
534 raise objects in relation to their surrounding markups.
536 If the text object itself is positioned above or below the staff, then
537 @code{\\raise} cannot be used to move it, since the mechanism that
538 positions it next to the staff cancels any shift made with
539 @code{\\raise}. For vertical positioning, use the @code{padding}
540 and/or @code{extra-offset} properties. "
541 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
543 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
544 "Make a fraction of two markups."
545 (let* ((m1 (interpret-markup layout props arg1))
546 (m2 (interpret-markup layout props arg2)))
547 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
548 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
549 (let* ((x1 (ly:stencil-extent m1 X))
550 (x2 (ly:stencil-extent m2 X))
551 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
552 ;; should stack mols separately, to maintain LINE on baseline
553 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
555 (ly:stencil-aligned-to stack Y CENTER))
557 (ly:stencil-aligned-to stack X LEFT))
558 ;; should have EX dimension
560 (ly:stencil-translate-axis stack 0.75 Y))))
564 (def-markup-command (filled-box layout props xext yext blot)
565 (number-pair? number-pair? number?)
566 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
570 (def-markup-command (whiteout layout props arg) (markup?)
571 "Provide a white underground for @var{arg}"
572 (let* ((stil (interpret-markup layout props
573 (make-with-color-markup black arg)))
575 (interpret-markup layout props
576 (make-with-color-markup
578 (make-filled-box-markup
579 (ly:stencil-extent stil X)
580 (ly:stencil-extent stil Y)
583 (ly:stencil-add white stil)))
585 ;; TODO: better syntax.
587 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
588 "Construct a note symbol, with stem. By using fractional values for
589 @var{dir}, you can obtain longer or shorter stems."
590 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
591 (size (chain-assoc-get 'font-size props 0))
592 (stem-length (* (magstep size) (max 3 (- log 1))))
593 (head-glyph (ly:font-get-glyph
595 (string-append "noteheads.s" (number->string (min log 2)))))
596 (stem-thickness 0.13)
597 (stemy (* dir stem-length))
598 (attachx (if (> dir 0)
599 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
601 (attachy (* dir 0.28))
602 (stem-glyph (and (> log 0)
604 (cons attachx (+ attachx stem-thickness))
605 (cons (min stemy attachy)
607 (/ stem-thickness 3))))
608 (dot (ly:font-get-glyph font "dots.dot"))
609 (dotwid (interval-length (ly:stencil-extent dot X)))
610 (dots (and (> dot-count 0)
611 (apply ly:stencil-add
613 (ly:stencil-translate-axis
614 dot (* (+ 1 (* 2 x)) dotwid) X))
615 (iota dot-count 1)))))
616 (flaggl (and (> log 2)
617 (ly:stencil-translate
618 (ly:font-get-glyph font
619 (string-append "flags."
620 (if (> dir 0) "u" "d")
621 (number->string log)))
622 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
624 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
625 (if (ly:stencil? stem-glyph)
626 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
627 (set! stem-glyph head-glyph))
628 (if (ly:stencil? dots)
631 (ly:stencil-translate-axis
633 (+ (if (and (> dir 0) (> log 2))
636 ;; huh ? why not necessary?
637 ;;(cdr (ly:stencil-extent head-glyph X))
644 (let ((divisor (log 2)))
645 (lambda (z) (inexact->exact (/ (log z) divisor)))))
647 (define (parse-simple-duration duration-string)
648 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
649 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
650 (if (and match (string=? duration-string (match:substring match 0)))
651 (let ((len (match:substring match 1))
652 (dots (match:substring match 2)))
653 (list (cond ((string=? len "breve") -1)
654 ((string=? len "longa") -2)
655 ((string=? len "maxima") -3)
656 (else (log2 (string->number len))))
657 (if dots (string-length dots) 0)))
658 (ly:error (_ "not a valid duration string: ~a") duration-string))))
660 (def-markup-command (note layout props duration dir) (string? number?)
661 "This produces a note with a stem pointing in @var{dir} direction, with
662 the @var{duration} for the note head type and augmentation dots. For
663 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
664 a shortened down stem."
665 (let ((parsed (parse-simple-duration duration)))
666 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
668 (def-markup-command (normal-size-super layout props arg) (markup?)
669 "Set @var{arg} in superscript with a normal font size."
670 (ly:stencil-translate-axis
671 (interpret-markup layout props arg)
672 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
674 (def-markup-command (super layout props arg) (markup?)
677 @cindex lowering text
679 @cindex translating text
681 @cindex @code{\\super}
684 Raising and lowering texts can be done with @code{\\super} and
687 @lilypond[verbatim,fragment,relative=1]
688 c1^\\markup { E \"=\" mc \\super \"2\" }
692 (ly:stencil-translate-axis
695 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
697 (* 0.5 (chain-assoc-get 'baseline-skip props))
700 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
701 "This translates an object. Its first argument is a cons of numbers
703 A \\translate #(cons 2 -3) @{ B C @} D
705 This moves `B C' 2 spaces to the right, and 3 down, relative to its
706 surroundings. This command cannot be used to move isolated scripts
707 vertically, for the same reason that @code{\\raise} cannot be used for
711 (ly:stencil-translate (interpret-markup layout props arg)
714 (def-markup-command (sub layout props arg) (markup?)
715 "Set @var{arg} in subscript."
716 (ly:stencil-translate-axis
719 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
721 (* -0.5 (chain-assoc-get 'baseline-skip props))
724 (def-markup-command (beam layout props width slope thickness)
725 (number? number? number?)
726 "Create a beam with the specified parameters."
727 (let* ((y (* slope width))
728 (yext (cons (min 0 y) (max 0 y)))
729 (half (/ thickness 2)))
735 (ly:output-def-lookup layout 'blotdiameter))
737 (cons (+ (- half) (car yext))
738 (+ half (cdr yext))))))
740 (def-markup-command (normal-size-sub layout props arg) (markup?)
741 "Set @var{arg} in subscript, in a normal font size."
742 (ly:stencil-translate-axis
743 (interpret-markup layout props arg)
744 (* -0.5 (chain-assoc-get 'baseline-skip props))
747 (def-markup-command (hbracket layout props arg) (markup?)
748 "Draw horizontal brackets around @var{arg}."
749 (let ((th 0.1) ;; todo: take from GROB.
750 (m (interpret-markup layout props arg)))
751 (bracketify-stencil m X th (* 2.5 th) th)))
753 (def-markup-command (bracket layout props arg) (markup?)
754 "Draw vertical brackets around @var{arg}."
755 (let ((th 0.1) ;; todo: take from GROB.
756 (m (interpret-markup layout props arg)))
757 (bracketify-stencil m Y th (* 2.5 th) th)))
759 ;; todo: fix negative space
760 (def-markup-command (hspace layout props amount) (number?)
761 "This produces a invisible object taking horizontal space.
763 \\markup @{ A \\hspace #2.0 B @}
765 will put extra space between A and B, on top of the space that is
766 normally inserted before elements on a line.
769 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
770 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
772 (def-markup-command (override layout props new-prop arg) (pair? markup?)
773 "Add the first argument in to the property list. Properties may be
774 any sort of property supported by @internalsref{font-interface} and
775 @internalsref{text-interface}, for example
778 \\override #'(font-family . married) \"bla\"
782 (interpret-markup layout (cons (list new-prop) props) arg))
785 (def-markup-command (fontsize layout props increment arg) (number? markup?)
786 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
788 (let* ((fs (chain-assoc-get 'font-size props 0))
789 (bs (chain-assoc-get 'baseline-skip props 2))
791 (cons 'baseline-skip (* bs (magstep increment)))
792 (cons 'font-size (+ fs increment )))))
794 (interpret-markup layout (cons entries props) arg)))
796 (def-markup-command (bigger layout props arg) (markup?)
797 "Increase the font size relative to current setting"
798 (interpret-markup layout props
799 `(,fontsize-markup 1 ,arg)))
801 (def-markup-command (smaller layout props arg) (markup?)
802 "Decrease the font size relative to current setting"
803 (interpret-markup layout props
804 `(,fontsize-markup -1 ,arg)))
806 (def-markup-command larger (markup?) bigger-markup)
808 (def-markup-command (box layout props arg) (markup?)
809 "Draw a box round @var{arg}. Looks at @code{thickness},
810 @code{box-padding} and @code{font-size} properties to determine line
811 thickness and padding around the markup."
812 (let* ((th (chain-assoc-get 'thickness props 0.1))
813 (size (chain-assoc-get 'font-size props 0))
814 (pad (* (magstep size)
815 (chain-assoc-get 'box-padding props 0.2)))
816 (m (interpret-markup layout props arg)))
817 (box-stencil m th pad)))
819 ;;FIXME: is this working?
820 (def-markup-command (strut layout props) ()
821 "Create a box of the same height as the space in the current font."
822 (let ((m (Text_interface::interpret_markup layout props " ")))
823 (ly:make-stencil (ly:stencil-expr m)
824 (ly:stencil-extent m X)
827 (define number->mark-letter-vector (make-vector 25 #\A))
832 (if (= i (- (char->integer #\I) (char->integer #\A)))
834 (vector-set! number->mark-letter-vector j
835 (integer->char (+ i (char->integer #\A)))))
837 (define number->mark-alphabet-vector (list->vector
838 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
840 (define (number->markletter-string vec n)
841 "Double letters for big marks."
842 (let* ((lst (vector-length vec)))
845 (string-append (number->markletter-string vec (1- (quotient n lst)))
846 (number->markletter-string vec (remainder n lst)))
847 (make-string 1 (vector-ref vec n)))))
849 (def-markup-command (markletter layout props num) (integer?)
850 "Make a markup letter for @var{num}. The letters start with A to Z
851 (skipping I), and continues with double letters."
852 (Text_interface::interpret_markup layout props
853 (number->markletter-string number->mark-letter-vector num)))
855 (def-markup-command (markalphabet layout props num) (integer?)
856 "Make a markup letter for @var{num}. The letters start with A to Z
857 and continues with double letters."
858 (Text_interface::interpret_markup layout props
859 (number->markletter-string number->mark-alphabet-vector num)))
861 (def-markup-command (bracketed-y-column layout props indices args)
863 "Make a column of the markups in @var{args}, putting brackets around
864 the elements marked in @var{indices}, which is a list of numbers."
865 (define (sublist lst start stop)
866 (take (drop lst start) (- (1+ stop) start)))
868 (define (stencil-list-extent ss axis)
870 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
871 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
873 (define (stack-stencils stencils bskip last-stencil)
875 ((null? stencils) '())
876 ((not (ly:stencil? last-stencil))
878 (stack-stencils (cdr stencils) bskip (car stencils))))
880 (let* ((orig (car stencils))
881 (dir (chain-assoc-get 'direction props DOWN))
882 (new (ly:stencil-moved-to-edge last-stencil Y dir
886 (cons new (stack-stencils (cdr stencils) bskip new))))))
888 (define (make-brackets stencils indices acc)
891 (pair? (cdr indices)))
892 (let* ((encl (sublist stencils (car indices) (cadr indices)))
893 (x-ext (stencil-list-extent encl X))
894 (y-ext (stencil-list-extent encl Y))
897 (protusion (* 2.5 thick))
899 (ly:stencil-translate-axis
900 (ly:bracket Y y-ext thick protusion)
901 (- (car x-ext) pad) X))
902 (rb (ly:stencil-translate-axis
903 (ly:bracket Y y-ext thick (- protusion))
904 (+ (cdr x-ext) pad) X)))
907 stencils (cddr indices)
920 (chain-assoc-get 'baseline-skip props))
921 (stacked (stack-stencils
922 (remove ly:stencil-empty? stencils) 1.25 #f))
923 (brackets (make-brackets stacked indices '())))
925 (apply ly:stencil-add
926 (append stacked brackets))))