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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 (def-markup-command (draw-circle layout props radius thickness fill)
28 (number? number? boolean?)
29 "A circle of radius @var{radius}, thickness @var{thickness} and
31 (make-circle-stencil radius thickness fill))
33 (def-markup-command (triangle layout props filled) (boolean?)
34 "A triangle, filled or not"
36 ((th (chain-assoc-get 'thickness props 0.1))
37 (size (chain-assoc-get 'font-size props 0))
40 (chain-assoc-get 'baseline-skip props 2))))
54 (def-markup-command (circle layout props arg) (markup?)
55 "Draw a circle around @var{arg}. Use @code{thickness},
56 @code{circle-padding} and @code{font-size} properties to determine line
57 thickness and padding around the markup."
58 (let* ((th (chain-assoc-get 'thickness props 0.1))
59 (size (chain-assoc-get 'font-size props 0))
62 (chain-assoc-get 'circle-padding props 0.2)))
63 (m (interpret-markup layout props arg)))
64 (circle-stencil m th pad)))
66 (def-markup-command (with-url layout props url arg) (string? markup?)
67 "Add a link to URL @var{url} around @var{arg}. This only works in
69 (let* ((stil (interpret-markup layout props arg))
70 (xextent (ly:stencil-extent stil X))
71 (yextent (ly:stencil-extent stil Y))
72 (old-expr (ly:stencil-expr stil))
73 (url-expr (list 'url-link url `(quote ,xextent) `(quote ,yextent))))
74 (ly:stencil-add (ly:make-stencil url-expr xextent yextent) stil)))
77 (def-markup-command (beam layout props width slope thickness)
78 (number? number? number?)
79 "Create a beam with the specified parameters."
80 (let* ((y (* slope width))
81 (yext (cons (min 0 y) (max 0 y)))
82 (half (/ thickness 2)))
87 width (+ (* width slope) (/ thickness -2))
88 width (+ (* width slope) (/ thickness 2))
90 ,(ly:output-def-lookup layout 'blotdiameter)
93 (cons (+ (- half) (car yext))
94 (+ half (cdr yext))))))
96 (def-markup-command (box layout props arg) (markup?)
97 "Draw a box round @var{arg}. Looks at @code{thickness},
98 @code{box-padding} and @code{font-size} properties to determine line
99 thickness and padding around the markup."
100 (let* ((th (chain-assoc-get 'thickness props 0.1))
101 (size (chain-assoc-get 'font-size props 0))
102 (pad (* (magstep size)
103 (chain-assoc-get 'box-padding props 0.2)))
104 (m (interpret-markup layout props arg)))
105 (box-stencil m th pad)))
107 (def-markup-command (filled-box layout props xext yext blot)
108 (number-pair? number-pair? number?)
109 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
113 (def-markup-command (whiteout layout props arg) (markup?)
114 "Provide a white underground for @var{arg}"
115 (let* ((stil (interpret-markup layout props
116 (make-with-color-markup black arg)))
118 (interpret-markup layout props
119 (make-with-color-markup
121 (make-filled-box-markup
122 (ly:stencil-extent stil X)
123 (ly:stencil-extent stil Y)
126 (ly:stencil-add white stil)))
128 (def-markup-command (pad-markup layout props padding arg) (number? markup?)
129 "Add space around a markup object."
132 ((stil (interpret-markup layout props arg))
133 (xext (ly:stencil-extent stil X))
134 (yext (ly:stencil-extent stil Y)))
137 (ly:stencil-expr stil)
138 (interval-widen xext padding)
139 (interval-widen yext padding))))
141 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
145 ;;FIXME: is this working?
146 (def-markup-command (strut layout props) ()
147 "Create a box of the same height as the space in the current font."
148 (let ((m (Text_interface::interpret_markup layout props " ")))
149 (ly:make-stencil (ly:stencil-expr m)
151 (ly:stencil-extent m X)
155 ;; todo: fix negative space
156 (def-markup-command (hspace layout props amount) (number?)
157 "This produces a invisible object taking horizontal space.
159 \\markup @{ A \\hspace #2.0 B @}
161 will put extra space between A and B, on top of the space that is
162 normally inserted before elements on a line.
165 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
166 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
169 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
170 ;; importing graphics.
171 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173 (def-markup-command (stencil layout props stil) (ly:stencil?)
178 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
180 (define (get-postscript-bbox string)
181 "Extract the bbox from STRING, or return #f if not present."
183 ((match (regexp-exec bbox-regexp string)))
187 (string->number (match:substring match x)))
192 (def-markup-command (epsfile layout props file-name) (string?)
193 "Inline an EPS image. The image is scaled such that 10 PS units is
196 (if (ly:get-option 'safe)
197 (interpret-markup layout props "not allowed in safe")
199 ((contents (ly:gulp-file file-name))
200 (bbox (get-postscript-bbox contents))
203 (map (lambda (x) (/ x 10)) bbox)
205 (ly:warning (_ "can't find bounding box of `~a'")
220 (format "\n%%BeginDocument: ~a\n" file-name)
225 (cons (list-ref scaled-bbox 0) (list-ref scaled-bbox 2))
226 (cons (list-ref scaled-bbox 1) (list-ref scaled-bbox 3)))
228 (ly:make-stencil "" '(0 . 0) '(0 . 0))))))
231 (def-markup-command (postscript layout props str) (string?)
232 "This inserts @var{str} directly into the output as a PostScript
233 command string. Due to technicalities of the output backends,
234 different scales should be used for the @TeX{} and PostScript backend,
235 selected with @code{-f}.
238 For the TeX backend, the following string prints a rotated text
243 0 0 moveto /ecrm10 findfont
244 1.75 scalefont setfont 90 rotate (hello) show
248 The magical constant 1.75 scales from LilyPond units (staff spaces) to
251 For the postscript backend, use the following
254 gsave /ecrm10 findfont
255 10.0 output-scale div
256 scalefont setfont 90 rotate (hello) show grestore
261 (list 'embedded-ps str)
265 (def-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 (def-markup-command (null layout props) ()
277 "An empty markup with extents of a single point"
281 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
283 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
285 (def-markup-command (simple layout props str) (string?)
286 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
287 @code{\\markup @{ \\simple #\"foo\" @}}."
288 (interpret-markup layout props str))
291 ;; TODO: use font recoding.
293 ;; (map make-word-markup (string-tokenize str)))))
295 (define-public empty-markup
296 (make-simple-markup ""))
298 ;; helper for justifying lines.
299 (define (get-fill-space word-count line-width text-widths)
300 "Calculate the necessary paddings between each two adjacent texts.
301 The lengths of all texts are stored in @var{text-widths}.
302 The normal formula for the padding between texts a and b is:
303 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
304 The first and last padding have to be calculated specially using the
305 whole length of the first or last text.
306 Return a list of paddings.
309 ((null? text-widths) '())
311 ;; special case first padding
312 ((= (length text-widths) word-count)
314 (- (- (/ line-width (1- word-count)) (car text-widths))
315 (/ (car (cdr text-widths)) 2))
316 (get-fill-space word-count line-width (cdr text-widths))))
317 ;; special case last padding
318 ((= (length text-widths) 2)
319 (list (- (/ line-width (1- word-count))
320 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
323 (- (/ line-width (1- word-count))
324 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
325 (get-fill-space word-count line-width (cdr text-widths))))))
327 (def-markup-command (fill-line layout props markups)
329 "Put @var{markups} in a horizontal line of width @var{line-width}.
330 The markups are spaced/flushed to fill the entire line.
331 If there are no arguments, return an empty stencil."
333 (let* ((orig-stencils
334 (map (lambda (x) (interpret-markup layout props x))
338 (if (ly:stencil-empty? stc)
340 stc)) orig-stencils))
343 (if (ly:stencil-empty? stc)
345 (interval-length (ly:stencil-extent stc X))))
347 (text-width (apply + text-widths))
348 (text-dir (chain-assoc-get 'text-direction props RIGHT))
349 (word-count (length stencils))
350 (word-space (chain-assoc-get 'word-space props))
351 (line-width (chain-assoc-get 'linewidth props))
356 (/ (- line-width text-width) 2)
357 (/ (- line-width text-width) 2)))
360 (- line-width text-width)))
362 (get-fill-space word-count line-width text-widths))))
370 (line-stencils (if (= word-count 1)
377 (if (= text-dir LEFT)
378 (set! line-stencils (reverse line-stencils)))
380 (if (null? (remove ly:stencil-empty? orig-stencils))
382 (stack-stencils-padding-list X
383 RIGHT fill-space-normal line-stencils))))
385 (def-markup-command (line layout props args) (markup-list?)
386 "Put @var{args} in a horizontal line. The property @code{word-space}
387 determines the space between each markup in @var{args}."
389 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
390 (space (chain-assoc-get 'word-space props))
391 (text-dir (chain-assoc-get 'text-direction props RIGHT))
395 (if (= text-dir LEFT)
396 (set! stencils (reverse stencils)))
401 (remove ly:stencil-empty? stencils))))
404 (define (wordwrap-stencils stencils
405 justify base-space line-width text-dir)
407 "Perform simple wordwrap, return stencil of each line."
409 (define space (if justify
411 ;; justify only stretches lines.
415 (define (take-list width space stencils
416 accumulator accumulated-width)
417 "Return (head-list . tail) pair, with head-list fitting into width"
419 (cons accumulator stencils)
421 ((first (car stencils))
422 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
423 (newwid (+ space first-wid accumulated-width))
427 (or (null? accumulator)
430 (take-list width space
432 (cons first accumulator)
434 (cons accumulator stencils))
442 ((line-break (take-list line-width space todo
444 (line-stencils (car line-break))
445 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
448 (line-word-space (cond
449 ((not justify) space)
451 ;; don't stretch last line of paragraph.
452 ;; hmmm . bug - will overstretch the last line in some case.
453 ((null? (cdr line-break))
455 ((null? line-stencils) 0.0)
456 ((null? (cdr line-stencils)) 0.0)
457 (else (/ space-left (1- (length line-stencils))))))
459 (line (stack-stencil-line
461 (if (= text-dir RIGHT)
462 (reverse line-stencils)
465 (if (pair? (cdr line-break))
466 (loop (cons line lines)
470 (if (= text-dir LEFT)
472 (ly:stencil-translate-axis line
473 (- line-width (interval-end (ly:stencil-extent line X)))
475 (reverse (cons line lines))
482 (define (wordwrap-markups layout props args justify)
484 ((baseline-skip (chain-assoc-get 'baseline-skip props))
485 (line-width (chain-assoc-get 'linewidth props))
486 (word-space (chain-assoc-get 'word-space props))
487 (text-dir (chain-assoc-get 'text-direction props RIGHT))
488 (lines (wordwrap-stencils
489 (remove ly:stencil-empty?
490 (map (lambda (m) (interpret-markup layout props m)) args))
491 justify word-space line-width
495 (stack-lines DOWN 0.0 baseline-skip lines)))
497 (def-markup-command (justify layout props args) (markup-list?)
498 "Like wordwrap, but with lines stretched to justify the margins.
499 Use @code{\\override #'(linewidth . X)} to set linewidth, where X
500 is the number of staff spaces."
502 (wordwrap-markups layout props args #t))
504 (def-markup-command (wordwrap layout props args) (markup-list?)
505 "Simple wordwrap. Use @code{\\override #'(linewidth . X)} to set
506 linewidth, where X is the number of staff spaces."
508 (wordwrap-markups layout props args #f))
510 (define (wordwrap-string layout props justify arg)
512 ((baseline-skip (chain-assoc-get 'baseline-skip props))
513 (line-width (chain-assoc-get 'linewidth props))
514 (word-space (chain-assoc-get 'word-space props))
516 (para-strings (regexp-split
517 (string-regexp-substitute "\r" "\n"
518 (string-regexp-substitute "\r\n" "\n" arg))
519 "\n[ \t\n]*\n[ \t\n]*"))
521 (text-dir (chain-assoc-get 'text-direction props RIGHT))
522 (list-para-words (map (lambda (str)
523 (regexp-split str "[ \t\n]+"))
525 (para-lines (map (lambda (words)
529 ly:stencil-empty? (map
531 (interpret-markup layout props x))
533 (lines (wordwrap-stencils stencils
542 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
545 (def-markup-command (wordwrap-string layout props arg) (string?)
546 "Wordwrap a string. Paragraphs may be separated with double newlines"
547 (wordwrap-string layout props #f arg))
549 (def-markup-command (justify-string layout props arg) (string?)
550 "Justify a string. Paragraphs may be separated with double newlines"
551 (wordwrap-string layout props #t arg))
554 (def-markup-command (wordwrap-field layout props symbol) (symbol?)
555 (let* ((m (chain-assoc-get symbol props)))
557 (interpret-markup layout props
558 (list wordwrap-string-markup m))
559 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
561 (def-markup-command (justify-field layout props symbol) (symbol?)
562 (let* ((m (chain-assoc-get symbol props)))
564 (interpret-markup layout props
565 (list justify-string-markup m))
566 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
570 (def-markup-command (combine layout props m1 m2) (markup? markup?)
571 "Print two markups on top of each other."
572 (let* ((s1 (interpret-markup layout props m1))
573 (s2 (interpret-markup layout props m2)))
574 (ly:stencil-add s1 s2)))
577 ;; TODO: should extract baseline-skip from each argument somehow..
579 (def-markup-command (column layout props args) (markup-list?)
580 "Stack the markups in @var{args} vertically. The property
581 @code{baseline-skip} determines the space between each markup in @var{args}."
583 -1 0.0 (chain-assoc-get 'baseline-skip props)
584 (remove ly:stencil-empty?
585 (map (lambda (m) (interpret-markup layout props m)) args))))
587 (def-markup-command (dir-column layout props args) (markup-list?)
588 "Make a column of args, going up or down, depending on the setting
589 of the @code{#'direction} layout property."
590 (let* ((dir (chain-assoc-get 'direction props)))
592 (if (number? dir) dir -1)
594 (chain-assoc-get 'baseline-skip props)
595 (map (lambda (x) (interpret-markup layout props x)) args))))
597 (def-markup-command (center-align layout props args) (markup-list?)
598 "Put @code{args} in a centered column. "
599 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
600 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
601 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
603 (def-markup-command (vcenter layout props arg) (markup?)
604 "Align @code{arg} to its Y center. "
605 (let* ((mol (interpret-markup layout props arg)))
606 (ly:stencil-aligned-to mol Y CENTER)))
608 (def-markup-command (hcenter layout props arg) (markup?)
609 "Align @code{arg} to its X center. "
610 (let* ((mol (interpret-markup layout props arg)))
611 (ly:stencil-aligned-to mol X CENTER)))
613 (def-markup-command (right-align layout props arg) (markup?)
614 "Align @var{arg} on its right edge. "
615 (let* ((m (interpret-markup layout props arg)))
616 (ly:stencil-aligned-to m X RIGHT)))
618 (def-markup-command (left-align layout props arg) (markup?)
619 "Align @var{arg} on its left edge. "
620 (let* ((m (interpret-markup layout props arg)))
621 (ly:stencil-aligned-to m X LEFT)))
623 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
624 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
625 (let* ((m (interpret-markup layout props arg)))
626 (ly:stencil-aligned-to m axis dir)))
628 (def-markup-command (halign layout props dir arg) (number? markup?)
629 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
630 left-aligned, while @code{+1} is right. Values in between interpolate
631 alignment accordingly."
632 (let* ((m (interpret-markup layout props arg)))
633 (ly:stencil-aligned-to m X dir)))
636 (def-markup-command (pad-around layout props amount arg) (number? markup?)
638 "Add padding @var{amount} all around @var{arg}. "
641 ((m (interpret-markup layout props arg))
642 (x (ly:stencil-extent m X))
643 (y (ly:stencil-extent m Y)))
646 (ly:make-stencil (ly:stencil-expr m)
647 (interval-widen x amount)
648 (interval-widen y amount))
652 (def-markup-command (pad-x layout props amount arg) (number? markup?)
654 "Add padding @var{amount} around @var{arg} in the X-direction. "
656 ((m (interpret-markup layout props arg))
657 (x (ly:stencil-extent m X))
658 (y (ly:stencil-extent m Y)))
661 (ly:make-stencil (ly:stencil-expr m)
662 (interval-widen x amount)
667 (def-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
669 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}. "
671 (let* ((m1 (interpret-markup layout props arg1))
672 (m2 (interpret-markup layout props arg2)))
674 (ly:stencil-combine-at-edge m1 axis dir m2 0.0 0.0)
677 (def-markup-command (transparent layout props arg) (markup?)
678 "Make the argument transparent"
680 ((m (interpret-markup layout props arg))
681 (x (ly:stencil-extent m X))
682 (y (ly:stencil-extent m Y)))
690 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
692 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
694 (def-markup-command (fromproperty layout props symbol) (symbol?)
695 "Read the @var{symbol} from property settings, and produce a stencil
696 from the markup contained within. If @var{symbol} is not defined, it
697 returns an empty markup"
698 (let* ((m (chain-assoc-get symbol props)))
700 (interpret-markup layout props m)
701 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
704 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
705 "Apply the @var{procedure} markup command to
706 @var{arg}. @var{procedure} should take a single argument."
707 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
708 (set-object-property! anonymous-with-signature
711 (interpret-markup layout props (list anonymous-with-signature arg))))
715 (def-markup-command (override layout props new-prop arg) (pair? markup?)
716 "Add the first argument in to the property list. Properties may be
717 any sort of property supported by @internalsref{font-interface} and
718 @internalsref{text-interface}, for example
721 \\override #'(font-family . married) \"bla\"
725 (interpret-markup layout (cons (list new-prop) props) arg))
727 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
729 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
732 (def-markup-command (bigger layout props arg) (markup?)
733 "Increase the font size relative to current setting"
734 (interpret-markup layout props
735 `(,fontsize-markup 1 ,arg)))
737 (def-markup-command (smaller layout props arg) (markup?)
738 "Decrease the font size relative to current setting"
739 (interpret-markup layout props
740 `(,fontsize-markup -1 ,arg)))
742 (def-markup-command larger (markup?) bigger-markup)
744 (def-markup-command (finger layout props arg) (markup?)
745 "Set the argument as small numbers."
746 (interpret-markup layout
747 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
751 (def-markup-command (fontsize layout props increment arg) (number? markup?)
752 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
754 (let* ((fs (chain-assoc-get 'font-size props 0))
755 (bs (chain-assoc-get 'baseline-skip props 2))
757 (cons 'baseline-skip (* bs (magstep increment)))
758 (cons 'font-size (+ fs increment )))))
760 (interpret-markup layout (cons entries props) arg)))
764 ;; FIXME -> should convert to font-size.
765 (def-markup-command (magnify layout props sz arg) (number? markup?)
766 "Set the font magnification for the its argument. In the following
767 example, the middle A will be 10% larger:
769 A \\magnify #1.1 @{ A @} A
772 Note: magnification only works if a font-name is explicitly selected.
773 Use @code{\\fontsize} otherwise."
776 (prepend-alist-chain 'font-magnification sz props)
779 (def-markup-command (bold layout props arg) (markup?)
780 "Switch to bold font-series"
781 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
783 (def-markup-command (sans layout props arg) (markup?)
784 "Switch to the sans serif family"
785 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
787 (def-markup-command (number layout props arg) (markup?)
788 "Set font family to @code{number}, which yields the font used for
789 time signatures and fingerings. This font only contains numbers and
790 some punctuation. It doesn't have any letters. "
791 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
793 (def-markup-command (roman layout props arg) (markup?)
794 "Set font family to @code{roman}."
795 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
797 (def-markup-command (huge layout props arg) (markup?)
798 "Set font size to +2."
799 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
801 (def-markup-command (large layout props arg) (markup?)
802 "Set font size to +1."
803 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
805 (def-markup-command (normalsize layout props arg) (markup?)
806 "Set font size to default."
807 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
809 (def-markup-command (small layout props arg) (markup?)
810 "Set font size to -1."
811 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
813 (def-markup-command (tiny layout props arg) (markup?)
814 "Set font size to -2."
815 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
817 (def-markup-command (teeny layout props arg) (markup?)
818 "Set font size to -3."
819 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
821 (def-markup-command (caps layout props arg) (markup?)
822 "Set @code{font-shape} to @code{caps}."
823 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
825 (def-markup-command (dynamic layout props arg) (markup?)
826 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
827 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
828 normal words (like ``pi@`{u}'') should be done in a different font. The
829 recommend font for this is bold and italic"
831 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
833 (def-markup-command (text layout props arg) (markup?)
834 "Use a text font instead of music symbol or music alphabet font."
837 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
841 (def-markup-command (italic layout props arg) (markup?)
842 "Use italic @code{font-shape} for @var{arg}. "
843 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
845 (def-markup-command (typewriter layout props arg) (markup?)
846 "Use @code{font-family} typewriter for @var{arg}."
848 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
850 (def-markup-command (upright layout props arg) (markup?)
851 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
853 layout (prepend-alist-chain 'font-shape 'upright props) arg))
855 (def-markup-command (medium layout props arg) (markup?)
856 "Switch to medium font-series (in contrast to bold)."
857 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
860 (def-markup-command (normal-text layout props arg) (markup?)
861 "Set all font related properties (except the size) to get the default normal text font, no matter what font was used earlier."
863 (interpret-markup layout
864 (cons '((font-family . roman) (font-shape . upright)
865 (font-series . medium) (font-encoding . latin1))
869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
873 (def-markup-command (doublesharp layout props) ()
874 "Draw a double sharp symbol."
876 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
878 (def-markup-command (sesquisharp layout props) ()
879 "Draw a 3/2 sharp symbol."
880 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
882 (def-markup-command (sharp layout props) ()
883 "Draw a sharp symbol."
884 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
886 (def-markup-command (semisharp layout props) ()
887 "Draw a semi sharp symbol."
888 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
890 (def-markup-command (natural layout props) ()
891 "Draw a natural symbol."
892 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
894 (def-markup-command (semiflat layout props) ()
896 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
898 (def-markup-command (flat layout props) ()
899 "Draw a flat symbol."
900 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
902 (def-markup-command (sesquiflat layout props) ()
903 "Draw a 3/2 flat symbol."
904 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
906 (def-markup-command (doubleflat layout props) ()
907 "Draw a double flat symbol."
908 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
910 (def-markup-command (with-color layout props color arg) (color? markup?)
911 "Draw @var{arg} in color specified by @var{color}"
913 (let* ((stil (interpret-markup layout props arg)))
915 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
916 (ly:stencil-extent stil X)
917 (ly:stencil-extent stil Y))))
920 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
922 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
925 (def-markup-command (arrow-head layout props axis direction filled)
926 (integer? ly:dir? boolean?)
927 "produce an arrow head in specified direction and axis. Use the filled head if @var{filled} is specified."
929 ((name (format "arrowheads.~a.~a~a"
936 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
940 (def-markup-command (musicglyph layout props glyph-name) (string?)
941 "This is converted to a musical symbol, e.g. @code{\\musicglyph
942 #\"accidentals.0\"} will select the natural sign from the music font.
943 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
945 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
949 (def-markup-command (lookup layout props glyph-name) (string?)
950 "Lookup a glyph by name."
951 (ly:font-get-glyph (ly:paper-get-font layout props)
954 (def-markup-command (char layout props num) (integer?)
955 "Produce a single character, e.g. @code{\\char #65} produces the
957 (ly:get-glyph (ly:paper-get-font layout props) num))
960 (define number->mark-letter-vector (make-vector 25 #\A))
965 (if (= i (- (char->integer #\I) (char->integer #\A)))
967 (vector-set! number->mark-letter-vector j
968 (integer->char (+ i (char->integer #\A)))))
970 (define number->mark-alphabet-vector (list->vector
971 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
973 (define (number->markletter-string vec n)
974 "Double letters for big marks."
975 (let* ((lst (vector-length vec)))
978 (string-append (number->markletter-string vec (1- (quotient n lst)))
979 (number->markletter-string vec (remainder n lst)))
980 (make-string 1 (vector-ref vec n)))))
982 (def-markup-command (markletter layout props num) (integer?)
983 "Make a markup letter for @var{num}. The letters start with A to Z
984 (skipping I), and continues with double letters."
985 (Text_interface::interpret_markup layout props
986 (number->markletter-string number->mark-letter-vector num)))
988 (def-markup-command (markalphabet layout props num) (integer?)
989 "Make a markup letter for @var{num}. The letters start with A to Z
990 and continues with double letters."
991 (Text_interface::interpret_markup layout props
992 (number->markletter-string number->mark-alphabet-vector num)))
995 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
997 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1000 ;; TODO: better syntax.
1002 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1003 "Construct a note symbol, with stem. By using fractional values for
1004 @var{dir}, you can obtain longer or shorter stems."
1005 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1006 (size (chain-assoc-get 'font-size props 0))
1007 (stem-length (* (magstep size) (max 3 (- log 1))))
1008 (head-glyph (ly:font-get-glyph
1010 (string-append "noteheads.s" (number->string (min log 2)))))
1011 (stem-thickness 0.13)
1012 (stemy (* dir stem-length))
1013 (attachx (if (> dir 0)
1014 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
1016 (attachy (* dir 0.28))
1017 (stem-glyph (and (> log 0)
1018 (ly:round-filled-box
1019 (cons attachx (+ attachx stem-thickness))
1020 (cons (min stemy attachy)
1021 (max stemy attachy))
1022 (/ stem-thickness 3))))
1023 (dot (ly:font-get-glyph font "dots.dot"))
1024 (dotwid (interval-length (ly:stencil-extent dot X)))
1025 (dots (and (> dot-count 0)
1026 (apply ly:stencil-add
1028 (ly:stencil-translate-axis
1029 dot (* (+ 1 (* 2 x)) dotwid) X))
1030 (iota dot-count 1)))))
1031 (flaggl (and (> log 2)
1032 (ly:stencil-translate
1033 (ly:font-get-glyph font
1034 (string-append "flags."
1035 (if (> dir 0) "u" "d")
1036 (number->string log)))
1037 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
1039 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1040 (if (ly:stencil? stem-glyph)
1041 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1042 (set! stem-glyph head-glyph))
1043 (if (ly:stencil? dots)
1046 (ly:stencil-translate-axis
1048 (+ (if (and (> dir 0) (> log 2))
1051 ;; huh ? why not necessary?
1052 ;;(cdr (ly:stencil-extent head-glyph X))
1059 (let ((divisor (log 2)))
1060 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1062 (define (parse-simple-duration duration-string)
1063 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1064 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1065 (if (and match (string=? duration-string (match:substring match 0)))
1066 (let ((len (match:substring match 1))
1067 (dots (match:substring match 2)))
1068 (list (cond ((string=? len "breve") -1)
1069 ((string=? len "longa") -2)
1070 ((string=? len "maxima") -3)
1071 (else (log2 (string->number len))))
1072 (if dots (string-length dots) 0)))
1073 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1075 (def-markup-command (note layout props duration dir) (string? number?)
1076 "This produces a note with a stem pointing in @var{dir} direction, with
1077 the @var{duration} for the note head type and augmentation dots. For
1078 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1079 a shortened down stem."
1080 (let ((parsed (parse-simple-duration duration)))
1081 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1086 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1088 (def-markup-command (lower layout props amount arg) (number? markup?)
1090 Lower @var{arg}, by the distance @var{amount}.
1091 A negative @var{amount} indicates raising, see also @code{\raise}.
1093 (ly:stencil-translate-axis (interpret-markup layout props arg)
1097 (def-markup-command (raise layout props amount arg) (number? markup?)
1099 Raise @var{arg}, by the distance @var{amount}.
1100 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1102 @lilypond[verbatim,fragment,relative=1]
1103 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
1105 The argument to @code{\\raise} is the vertical displacement amount,
1106 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1107 raise objects in relation to their surrounding markups.
1109 If the text object itself is positioned above or below the staff, then
1110 @code{\\raise} cannot be used to move it, since the mechanism that
1111 positions it next to the staff cancels any shift made with
1112 @code{\\raise}. For vertical positioning, use the @code{padding}
1113 and/or @code{extra-offset} properties. "
1114 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1116 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1117 "Make a fraction of two markups."
1118 (let* ((m1 (interpret-markup layout props arg1))
1119 (m2 (interpret-markup layout props arg2)))
1120 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1121 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1122 (let* ((x1 (ly:stencil-extent m1 X))
1123 (x2 (ly:stencil-extent m2 X))
1124 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
1125 ;; should stack mols separately, to maintain LINE on baseline
1126 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
1128 (ly:stencil-aligned-to stack Y CENTER))
1130 (ly:stencil-aligned-to stack X LEFT))
1131 ;; should have EX dimension
1133 (ly:stencil-translate-axis stack 0.75 Y))))
1139 (def-markup-command (normal-size-super layout props arg) (markup?)
1140 "Set @var{arg} in superscript with a normal font size."
1141 (ly:stencil-translate-axis
1142 (interpret-markup layout props arg)
1143 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1145 (def-markup-command (super layout props arg) (markup?)
1147 @cindex raising text
1148 @cindex lowering text
1150 @cindex translating text
1152 @cindex @code{\\super}
1155 Raising and lowering texts can be done with @code{\\super} and
1158 @lilypond[verbatim,fragment,relative=1]
1159 c1^\\markup { E \"=\" mc \\super \"2\" }
1163 (ly:stencil-translate-axis
1166 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1168 (* 0.5 (chain-assoc-get 'baseline-skip props))
1171 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
1172 "This translates an object. Its first argument is a cons of numbers
1174 A \\translate #(cons 2 -3) @{ B C @} D
1176 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1177 surroundings. This command cannot be used to move isolated scripts
1178 vertically, for the same reason that @code{\\raise} cannot be used for
1182 (ly:stencil-translate (interpret-markup layout props arg)
1185 (def-markup-command (sub layout props arg) (markup?)
1186 "Set @var{arg} in subscript."
1187 (ly:stencil-translate-axis
1190 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1192 (* -0.5 (chain-assoc-get 'baseline-skip props))
1195 (def-markup-command (normal-size-sub layout props arg) (markup?)
1196 "Set @var{arg} in subscript, in a normal font size."
1197 (ly:stencil-translate-axis
1198 (interpret-markup layout props arg)
1199 (* -0.5 (chain-assoc-get 'baseline-skip props))
1202 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1204 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1206 (def-markup-command (hbracket layout props arg) (markup?)
1207 "Draw horizontal brackets around @var{arg}."
1208 (let ((th 0.1) ;; todo: take from GROB.
1209 (m (interpret-markup layout props arg)))
1210 (bracketify-stencil m X th (* 2.5 th) th)))
1212 (def-markup-command (bracket layout props arg) (markup?)
1213 "Draw vertical brackets around @var{arg}."
1214 (let ((th 0.1) ;; todo: take from GROB.
1215 (m (interpret-markup layout props arg)))
1216 (bracketify-stencil m Y th (* 2.5 th) th)))
1218 (def-markup-command (bracketed-y-column layout props indices args)
1219 (list? markup-list?)
1220 "Make a column of the markups in @var{args}, putting brackets around
1221 the elements marked in @var{indices}, which is a list of numbers."
1222 (define (sublist lst start stop)
1223 (take (drop lst start) (- (1+ stop) start)))
1225 (define (stencil-list-extent ss axis)
1227 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1228 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1231 (define (stack-stencils-vertically stencils bskip last-stencil)
1233 ((null? stencils) '())
1234 ((not (ly:stencil? last-stencil))
1235 (cons (car stencils)
1236 (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1238 (let* ((orig (car stencils))
1239 (dir (chain-assoc-get 'direction props DOWN))
1240 (new (ly:stencil-moved-to-edge last-stencil Y dir
1244 (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1246 (define (make-brackets stencils indices acc)
1249 (pair? (cdr indices)))
1250 (let* ((encl (sublist stencils (car indices) (cadr indices)))
1251 (x-ext (stencil-list-extent encl X))
1252 (y-ext (stencil-list-extent encl Y))
1255 (protusion (* 2.5 thick))
1257 (ly:stencil-translate-axis
1258 (ly:bracket Y y-ext thick protusion)
1259 (- (car x-ext) pad) X))
1260 (rb (ly:stencil-translate-axis
1261 (ly:bracket Y y-ext thick (- protusion))
1262 (+ (cdr x-ext) pad) X)))
1265 stencils (cddr indices)
1278 (chain-assoc-get 'baseline-skip props))
1279 (stacked (stack-stencils-vertically
1280 (remove ly:stencil-empty? stencils) 1.25 #f))
1281 (brackets (make-brackets stacked indices '())))
1283 (apply ly:stencil-add
1284 (append stacked brackets))))
1287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1288 ;; size indications arrow
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;