1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2006 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 'blot-diameter)
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."
101 (let* ((th (chain-assoc-get 'thickness props 0.1))
102 (size (chain-assoc-get 'font-size props 0))
103 (pad (* (magstep size)
104 (chain-assoc-get 'box-padding props 0.2)))
105 (m (interpret-markup layout props arg)))
106 (box-stencil m th pad)))
108 (def-markup-command (filled-box layout props xext yext blot)
109 (number-pair? number-pair? number?)
110 "Draw a box with rounded corners of dimensions @var{xext} and @var{yext}."
114 (def-markup-command (whiteout layout props arg) (markup?)
115 "Provide a white underground for @var{arg}"
116 (let* ((stil (interpret-markup layout props
117 (make-with-color-markup black arg)))
119 (interpret-markup layout props
120 (make-with-color-markup
122 (make-filled-box-markup
123 (ly:stencil-extent stil X)
124 (ly:stencil-extent stil Y)
127 (ly:stencil-add white stil)))
129 (def-markup-command (pad-markup layout props padding arg) (number? markup?)
130 "Add space around a markup object."
133 ((stil (interpret-markup layout props arg))
134 (xext (ly:stencil-extent stil X))
135 (yext (ly:stencil-extent stil Y)))
138 (ly:stencil-expr stil)
139 (interval-widen xext padding)
140 (interval-widen yext padding))))
142 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146 ;;FIXME: is this working?
147 (def-markup-command (strut layout props) ()
148 "Create a box of the same height as the space in the current font."
149 (let ((m (ly:text-interface::interpret-markup layout props " ")))
150 (ly:make-stencil (ly:stencil-expr m)
152 (ly:stencil-extent m X)
156 ;; todo: fix negative space
157 (def-markup-command (hspace layout props amount) (number?)
158 "This produces a invisible object taking horizontal space.
160 \\markup @{ A \\hspace #2.0 B @}
162 will put extra space between A and B, on top of the space that is
163 normally inserted before elements on a line.
166 (ly:make-stencil "" (cons 0 amount) '(-1 . 1))
167 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
170 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
171 ;; importing graphics.
172 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
174 (def-markup-command (stencil layout props stil) (ly:stencil?)
179 (make-regexp "%%BoundingBox:[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)[ \t]+([0-9-]+)"))
181 (define (get-postscript-bbox string)
182 "Extract the bbox from STRING, or return #f if not present."
184 ((match (regexp-exec bbox-regexp string)))
188 (string->number (match:substring match x)))
193 (def-markup-command (epsfile layout props axis size file-name) (number? number? string?)
194 "Inline an EPS image. The image is scaled along @var{axis} to
197 (if (ly:get-option 'safe)
198 (interpret-markup layout props "not allowed in safe")
199 (eps-file->stencil axis size file-name)
202 (def-markup-command (postscript layout props str) (string?)
203 "This inserts @var{str} directly into the output as a PostScript
204 command string. Due to technicalities of the output backends,
205 different scales should be used for the @TeX{} and PostScript backend,
206 selected with @code{-f}.
209 For the TeX backend, the following string prints a rotated text
214 0 0 moveto /ecrm10 findfont
215 1.75 scalefont setfont 90 rotate (hello) show
219 The magical constant 1.75 scales from LilyPond units (staff spaces) to
222 For the postscript backend, use the following
225 gsave /ecrm10 findfont
226 10.0 output-scale div
227 scalefont setfont 90 rotate (hello) show grestore
232 (list 'embedded-ps str)
236 (def-markup-command (score layout props score) (ly:score?)
237 "Inline an image of music."
238 (let* ((output (ly:score-embedded-format score layout)))
240 (if (ly:music-output? output)
241 (paper-system-stencil
242 (vector-ref (ly:paper-score-paper-systems output) 0))
244 (ly:warning (_"no systems found in \\score markup, does it have a \\layout block?"))
247 (def-markup-command (null layout props) ()
248 "An empty markup with extents of a single point"
252 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
254 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
256 (def-markup-command (simple layout props str) (string?)
257 "A simple text string; @code{\\markup @{ foo @}} is equivalent with
258 @code{\\markup @{ \\simple #\"foo\" @}}."
259 (interpret-markup layout props str))
262 ;; TODO: use font recoding.
264 ;; (map make-word-markup (string-tokenize str)))))
266 (define-public empty-markup
267 (make-simple-markup ""))
269 ;; helper for justifying lines.
270 (define (get-fill-space word-count line-width text-widths)
271 "Calculate the necessary paddings between each two adjacent texts.
272 The lengths of all texts are stored in @var{text-widths}.
273 The normal formula for the padding between texts a and b is:
274 padding = line-width/(word-count - 1) - (length(a) + length(b))/2
275 The first and last padding have to be calculated specially using the
276 whole length of the first or last text.
277 Return a list of paddings.
280 ((null? text-widths) '())
282 ;; special case first padding
283 ((= (length text-widths) word-count)
285 (- (- (/ line-width (1- word-count)) (car text-widths))
286 (/ (car (cdr text-widths)) 2))
287 (get-fill-space word-count line-width (cdr text-widths))))
288 ;; special case last padding
289 ((= (length text-widths) 2)
290 (list (- (/ line-width (1- word-count))
291 (+ (/ (car text-widths) 2) (car (cdr text-widths)))) 0))
294 (- (/ line-width (1- word-count))
295 (/ (+ (car text-widths) (car (cdr text-widths))) 2))
296 (get-fill-space word-count line-width (cdr text-widths))))))
298 (def-markup-command (fill-line layout props markups)
300 "Put @var{markups} in a horizontal line of width @var{line-width}.
301 The markups are spaced/flushed to fill the entire line.
302 If there are no arguments, return an empty stencil."
304 (let* ((orig-stencils
305 (map (lambda (x) (interpret-markup layout props x))
309 (if (ly:stencil-empty? stc)
311 stc)) orig-stencils))
314 (if (ly:stencil-empty? stc)
316 (interval-length (ly:stencil-extent stc X))))
318 (text-width (apply + text-widths))
319 (text-dir (chain-assoc-get 'text-direction props RIGHT))
320 (word-count (length stencils))
321 (word-space (chain-assoc-get 'word-space props))
322 (line-width (chain-assoc-get 'line-width props))
327 (/ (- line-width text-width) 2)
328 (/ (- line-width text-width) 2)))
331 (- line-width text-width)))
333 (get-fill-space word-count line-width text-widths))))
341 (line-stencils (if (= word-count 1)
348 (if (= text-dir LEFT)
349 (set! line-stencils (reverse line-stencils)))
351 (if (null? (remove ly:stencil-empty? orig-stencils))
353 (stack-stencils-padding-list X
354 RIGHT fill-space-normal line-stencils))))
356 (def-markup-command (line layout props args) (markup-list?)
357 "Put @var{args} in a horizontal line. The property @code{word-space}
358 determines the space between each markup in @var{args}."
360 ((stencils (map (lambda (m) (interpret-markup layout props m)) args))
361 (space (chain-assoc-get 'word-space props))
362 (text-dir (chain-assoc-get 'text-direction props RIGHT))
365 (if (= text-dir LEFT)
366 (set! stencils (reverse stencils)))
371 (remove ly:stencil-empty? stencils))))
374 (define (wordwrap-stencils stencils
375 justify base-space line-width text-dir)
377 "Perform simple wordwrap, return stencil of each line."
379 (define space (if justify
381 ;; justify only stretches lines.
385 (define (take-list width space stencils
386 accumulator accumulated-width)
387 "Return (head-list . tail) pair, with head-list fitting into width"
389 (cons accumulator stencils)
391 ((first (car stencils))
392 (first-wid (cdr (ly:stencil-extent (car stencils) X)))
393 (newwid (+ space first-wid accumulated-width))
397 (or (null? accumulator)
400 (take-list width space
402 (cons first accumulator)
404 (cons accumulator stencils))
412 ((line-break (take-list line-width space todo
414 (line-stencils (car line-break))
415 (space-left (- line-width (apply + (map (lambda (x) (cdr (ly:stencil-extent x X)))
418 (line-word-space (cond
419 ((not justify) space)
421 ;; don't stretch last line of paragraph.
422 ;; hmmm . bug - will overstretch the last line in some case.
423 ((null? (cdr line-break))
425 ((null? line-stencils) 0.0)
426 ((null? (cdr line-stencils)) 0.0)
427 (else (/ space-left (1- (length line-stencils))))))
429 (line (stack-stencil-line
431 (if (= text-dir RIGHT)
432 (reverse line-stencils)
435 (if (pair? (cdr line-break))
436 (loop (cons line lines)
440 (if (= text-dir LEFT)
442 (ly:stencil-translate-axis line
443 (- line-width (interval-end (ly:stencil-extent line X)))
445 (reverse (cons line lines))
452 (define (wordwrap-markups layout props args justify)
454 ((baseline-skip (chain-assoc-get 'baseline-skip props))
455 (line-width (chain-assoc-get 'line-width props))
456 (word-space (chain-assoc-get 'word-space props))
457 (text-dir (chain-assoc-get 'text-direction props RIGHT))
458 (lines (wordwrap-stencils
459 (remove ly:stencil-empty?
460 (map (lambda (m) (interpret-markup layout props m)) args))
461 justify word-space line-width
465 (stack-lines DOWN 0.0 baseline-skip lines)))
467 (def-markup-command (justify layout props args) (markup-list?)
468 "Like wordwrap, but with lines stretched to justify the margins.
469 Use @code{\\override #'(line-width . X)} to set line-width, where X
470 is the number of staff spaces."
472 (wordwrap-markups layout props args #t))
474 (def-markup-command (wordwrap layout props args) (markup-list?)
475 "Simple wordwrap. Use @code{\\override #'(line-width . X)} to set
476 line-width, where X is the number of staff spaces."
478 (wordwrap-markups layout props args #f))
480 (define (wordwrap-string layout props justify arg)
482 ((baseline-skip (chain-assoc-get 'baseline-skip props))
483 (line-width (chain-assoc-get 'line-width props))
484 (word-space (chain-assoc-get 'word-space props))
486 (para-strings (regexp-split
487 (string-regexp-substitute "\r" "\n"
488 (string-regexp-substitute "\r\n" "\n" arg))
489 "\n[ \t\n]*\n[ \t\n]*"))
491 (text-dir (chain-assoc-get 'text-direction props RIGHT))
492 (list-para-words (map (lambda (str)
493 (regexp-split str "[ \t\n]+"))
495 (para-lines (map (lambda (words)
499 ly:stencil-empty? (map
501 (interpret-markup layout props x))
503 (lines (wordwrap-stencils stencils
512 (stack-lines DOWN 0.0 baseline-skip (apply append para-lines))))
515 (def-markup-command (wordwrap-string layout props arg) (string?)
516 "Wordwrap a string. Paragraphs may be separated with double newlines"
517 (wordwrap-string layout props #f arg))
519 (def-markup-command (justify-string layout props arg) (string?)
520 "Justify a string. Paragraphs may be separated with double newlines"
521 (wordwrap-string layout props #t arg))
524 (def-markup-command (wordwrap-field layout props symbol) (symbol?)
525 (let* ((m (chain-assoc-get symbol props)))
527 (interpret-markup layout props
528 (list wordwrap-string-markup m))
529 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
531 (def-markup-command (justify-field layout props symbol) (symbol?)
532 - (let* ((m (chain-assoc-get symbol props)))
534 (interpret-markup layout props
535 (list justify-string-markup m))
536 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
540 (def-markup-command (combine layout props m1 m2) (markup? markup?)
541 "Print two markups on top of each other."
542 (let* ((s1 (interpret-markup layout props m1))
543 (s2 (interpret-markup layout props m2)))
544 (ly:stencil-add s1 s2)))
547 ;; TODO: should extract baseline-skip from each argument somehow..
549 (def-markup-command (column layout props args) (markup-list?)
550 "Stack the markups in @var{args} vertically. The property
551 @code{baseline-skip} determines the space between each markup in @var{args}."
554 ((arg-stencils (map (lambda (m) (interpret-markup layout props m)) args))
555 (skip (chain-assoc-get 'baseline-skip props)))
560 (remove ly:stencil-empty? arg-stencils))))
563 (def-markup-command (dir-column layout props args) (markup-list?)
564 "Make a column of args, going up or down, depending on the setting
565 of the @code{#'direction} layout property."
566 (let* ((dir (chain-assoc-get 'direction props)))
568 (if (number? dir) dir -1)
570 (chain-assoc-get 'baseline-skip props)
571 (map (lambda (x) (interpret-markup layout props x)) args))))
573 (def-markup-command (center-align layout props args) (markup-list?)
574 "Put @code{args} in a centered column. "
575 (let* ((mols (map (lambda (x) (interpret-markup layout props x)) args))
576 (cmols (map (lambda (x) (ly:stencil-aligned-to x X CENTER)) mols)))
578 (stack-lines -1 0.0 (chain-assoc-get 'baseline-skip props) cmols)))
580 (def-markup-command (vcenter layout props arg) (markup?)
581 "Align @code{arg} to its Y center. "
582 (let* ((mol (interpret-markup layout props arg)))
583 (ly:stencil-aligned-to mol Y CENTER)))
585 (def-markup-command (hcenter layout props arg) (markup?)
586 "Align @code{arg} to its X center. "
587 (let* ((mol (interpret-markup layout props arg)))
588 (ly:stencil-aligned-to mol X CENTER)))
590 (def-markup-command (right-align layout props arg) (markup?)
591 "Align @var{arg} on its right edge. "
592 (let* ((m (interpret-markup layout props arg)))
593 (ly:stencil-aligned-to m X RIGHT)))
595 (def-markup-command (left-align layout props arg) (markup?)
596 "Align @var{arg} on its left edge. "
597 (let* ((m (interpret-markup layout props arg)))
598 (ly:stencil-aligned-to m X LEFT)))
600 (def-markup-command (general-align layout props axis dir arg) (integer? number? markup?)
601 "Align @var{arg} in @var{axis} direction to the @var{dir} side."
602 (let* ((m (interpret-markup layout props arg)))
603 (ly:stencil-aligned-to m axis dir)))
605 (def-markup-command (halign layout props dir arg) (number? markup?)
606 "Set horizontal alignment. If @var{dir} is @code{-1}, then it is
607 left-aligned, while @code{+1} is right. Values in between interpolate
608 alignment accordingly."
609 (let* ((m (interpret-markup layout props arg)))
610 (ly:stencil-aligned-to m X dir)))
614 (def-markup-command (with-dimensions layout props x y arg) (number-pair? number-pair? markup?)
615 "Set the dimensions of @var{arg} to @var{x} and @var{y}."
617 (let* ((m (interpret-markup layout props arg)))
618 (ly:make-stencil (ly:stencil-expr m) x y)))
621 (def-markup-command (pad-around layout props amount arg) (number? markup?)
623 "Add padding @var{amount} all around @var{arg}. "
626 ((m (interpret-markup layout props arg))
627 (x (ly:stencil-extent m X))
628 (y (ly:stencil-extent m Y)))
631 (ly:make-stencil (ly:stencil-expr m)
632 (interval-widen x amount)
633 (interval-widen y amount))
637 (def-markup-command (pad-x layout props amount arg) (number? markup?)
639 "Add padding @var{amount} around @var{arg} in the X-direction. "
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)
652 (def-markup-command (put-adjacent layout props arg1 axis dir arg2) (markup? integer? ly:dir? markup?)
654 "Put @var{arg2} next to @var{arg1}, without moving @var{arg1}. "
656 (let* ((m1 (interpret-markup layout props arg1))
657 (m2 (interpret-markup layout props arg2)))
659 (ly:stencil-combine-at-edge m1 axis dir m2 0.0 0.0)
662 (def-markup-command (transparent layout props arg) (markup?)
663 "Make the argument transparent"
665 ((m (interpret-markup layout props arg))
666 (x (ly:stencil-extent m X))
667 (y (ly:stencil-extent m Y)))
675 (def-markup-command (pad-to-box layout props x-ext y-ext arg) (number-pair? number-pair? markup?)
676 "Make @var{arg} take at least @var{x-ext}, @var{y-ext} space"
679 ((m (interpret-markup layout props arg))
680 (x (ly:stencil-extent m X))
681 (y (ly:stencil-extent m Y)))
683 (ly:make-stencil (ly:stencil-expr m)
684 (interval-union x-ext x)
685 (interval-union y-ext y))))
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
693 (def-markup-command (fromproperty layout props symbol) (symbol?)
694 "Read the @var{symbol} from property settings, and produce a stencil
695 from the markup contained within. If @var{symbol} is not defined, it
696 returns an empty markup"
697 (let* ((m (chain-assoc-get symbol props)))
699 (interpret-markup layout props m)
700 (ly:make-stencil '() '(1 . -1) '(1 . -1)))))
703 (def-markup-command (on-the-fly layout props procedure arg) (symbol? markup?)
704 "Apply the @var{procedure} markup command to
705 @var{arg}. @var{procedure} should take a single argument."
706 (let* ((anonymous-with-signature (lambda (layout props arg) (procedure layout props arg))))
707 (set-object-property! anonymous-with-signature
710 (interpret-markup layout props (list anonymous-with-signature arg))))
714 (def-markup-command (override layout props new-prop arg) (pair? markup?)
715 "Add the first argument in to the property list. Properties may be
716 any sort of property supported by @internalsref{font-interface} and
717 @internalsref{text-interface}, for example
720 \\override #'(font-family . married) \"bla\"
724 (interpret-markup layout (cons (list new-prop) props) arg))
726 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
728 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
730 (def-markup-command (verbatim-file layout props name) (string?)
731 "Read the contents of a file, and include verbatimly"
735 (if (ly:get-option 'safe)
736 "verbatim-file disabled in safe mode"
738 ((str (ly:gulp-file name))
739 (lines (string-split str #\nl)))
741 (make-typewriter-markup
742 (make-column-markup lines)))
745 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
747 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
750 (def-markup-command (bigger layout props arg) (markup?)
751 "Increase the font size relative to current setting"
752 (interpret-markup layout props
753 `(,fontsize-markup 1 ,arg)))
755 (def-markup-command (smaller layout props arg) (markup?)
756 "Decrease the font size relative to current setting"
757 (interpret-markup layout props
758 `(,fontsize-markup -1 ,arg)))
760 (def-markup-command larger (markup?) bigger-markup)
762 (def-markup-command (finger layout props arg) (markup?)
763 "Set the argument as small numbers."
764 (interpret-markup layout
765 (cons '((font-size . -5) (font-encoding . fetaNumber)) props)
769 (def-markup-command (fontsize layout props increment arg) (number? markup?)
770 "Add @var{increment} to the font-size. Adjust baseline skip accordingly."
772 (let* ((fs (chain-assoc-get 'font-size props 0))
773 (bs (chain-assoc-get 'baseline-skip props 2))
775 (cons 'baseline-skip (* bs (magstep increment)))
776 (cons 'font-size (+ fs increment )))))
778 (interpret-markup layout (cons entries props) arg)))
782 ;; FIXME -> should convert to font-size.
783 (def-markup-command (magnify layout props sz arg) (number? markup?)
784 "Set the font magnification for the its argument. In the following
785 example, the middle A will be 10% larger:
787 A \\magnify #1.1 @{ A @} A
790 Note: magnification only works if a font-name is explicitly selected.
791 Use @code{\\fontsize} otherwise."
794 (prepend-alist-chain 'font-magnification sz props)
797 (def-markup-command (bold layout props arg) (markup?)
798 "Switch to bold font-series"
799 (interpret-markup layout (prepend-alist-chain 'font-series 'bold props) arg))
801 (def-markup-command (sans layout props arg) (markup?)
802 "Switch to the sans serif family"
803 (interpret-markup layout (prepend-alist-chain 'font-family 'sans props) arg))
805 (def-markup-command (number layout props arg) (markup?)
806 "Set font family to @code{number}, which yields the font used for
807 time signatures and fingerings. This font only contains numbers and
808 some punctuation. It doesn't have any letters. "
809 (interpret-markup layout (prepend-alist-chain 'font-encoding 'fetaNumber props) arg))
811 (def-markup-command (roman layout props arg) (markup?)
812 "Set font family to @code{roman}."
813 (interpret-markup layout (prepend-alist-chain 'font-family 'roman props) arg))
815 (def-markup-command (huge layout props arg) (markup?)
816 "Set font size to +2."
817 (interpret-markup layout (prepend-alist-chain 'font-size 2 props) arg))
819 (def-markup-command (large layout props arg) (markup?)
820 "Set font size to +1."
821 (interpret-markup layout (prepend-alist-chain 'font-size 1 props) arg))
823 (def-markup-command (normalsize layout props arg) (markup?)
824 "Set font size to default."
825 (interpret-markup layout (prepend-alist-chain 'font-size 0 props) arg))
827 (def-markup-command (small layout props arg) (markup?)
828 "Set font size to -1."
829 (interpret-markup layout (prepend-alist-chain 'font-size -1 props) arg))
831 (def-markup-command (tiny layout props arg) (markup?)
832 "Set font size to -2."
833 (interpret-markup layout (prepend-alist-chain 'font-size -2 props) arg))
835 (def-markup-command (teeny layout props arg) (markup?)
836 "Set font size to -3."
837 (interpret-markup layout (prepend-alist-chain 'font-size -3 props) arg))
839 (def-markup-command (caps layout props arg) (markup?)
840 "Set @code{font-shape} to @code{caps}."
841 (interpret-markup layout (prepend-alist-chain 'font-shape 'caps props) arg))
843 (def-markup-command (dynamic layout props arg) (markup?)
844 "Use the dynamic font. This font only contains @b{s}, @b{f}, @b{m},
845 @b{z}, @b{p}, and @b{r}. When producing phrases, like ``pi@`{u} @b{f}'', the
846 normal words (like ``pi@`{u}'') should be done in a different font. The
847 recommend font for this is bold and italic"
849 layout (prepend-alist-chain 'font-encoding 'fetaDynamic props) arg))
851 (def-markup-command (text layout props arg) (markup?)
852 "Use a text font instead of music symbol or music alphabet font."
855 (interpret-markup layout (prepend-alist-chain 'font-encoding 'latin1 props)
859 (def-markup-command (italic layout props arg) (markup?)
860 "Use italic @code{font-shape} for @var{arg}. "
861 (interpret-markup layout (prepend-alist-chain 'font-shape 'italic props) arg))
863 (def-markup-command (typewriter layout props arg) (markup?)
864 "Use @code{font-family} typewriter for @var{arg}."
866 layout (prepend-alist-chain 'font-family 'typewriter props) arg))
868 (def-markup-command (upright layout props arg) (markup?)
869 "Set font shape to @code{upright}. This is the opposite of @code{italic}."
871 layout (prepend-alist-chain 'font-shape 'upright props) arg))
873 (def-markup-command (medium layout props arg) (markup?)
874 "Switch to medium font-series (in contrast to bold)."
875 (interpret-markup layout (prepend-alist-chain 'font-series 'medium props)
878 (def-markup-command (normal-text layout props arg) (markup?)
879 "Set all font related properties (except the size) to get the default normal text font, no matter what font was used earlier."
881 (interpret-markup layout
882 (cons '((font-family . roman) (font-shape . upright)
883 (font-series . medium) (font-encoding . latin1))
887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
889 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
891 (def-markup-command (doublesharp layout props) ()
892 "Draw a double sharp symbol."
894 (interpret-markup layout props (markup #:musicglyph "accidentals.4")))
896 (def-markup-command (sesquisharp layout props) ()
897 "Draw a 3/2 sharp symbol."
898 (interpret-markup layout props (markup #:musicglyph "accidentals.3")))
900 (def-markup-command (sharp layout props) ()
901 "Draw a sharp symbol."
902 (interpret-markup layout props (markup #:musicglyph "accidentals.2")))
904 (def-markup-command (semisharp layout props) ()
905 "Draw a semi sharp symbol."
906 (interpret-markup layout props (markup #:musicglyph "accidentals.1")))
908 (def-markup-command (natural layout props) ()
909 "Draw a natural symbol."
910 (interpret-markup layout props (markup #:musicglyph "accidentals.0")))
912 (def-markup-command (semiflat layout props) ()
914 (interpret-markup layout props (markup #:musicglyph "accidentals.M1")))
916 (def-markup-command (flat layout props) ()
917 "Draw a flat symbol."
918 (interpret-markup layout props (markup #:musicglyph "accidentals.M2")))
920 (def-markup-command (sesquiflat layout props) ()
921 "Draw a 3/2 flat symbol."
922 (interpret-markup layout props (markup #:musicglyph "accidentals.M3")))
924 (def-markup-command (doubleflat layout props) ()
925 "Draw a double flat symbol."
926 (interpret-markup layout props (markup #:musicglyph "accidentals.M4")))
928 (def-markup-command (with-color layout props color arg) (color? markup?)
929 "Draw @var{arg} in color specified by @var{color}"
931 (let* ((stil (interpret-markup layout props arg)))
933 (ly:make-stencil (list 'color color (ly:stencil-expr stil))
934 (ly:stencil-extent stil X)
935 (ly:stencil-extent stil Y))))
938 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
940 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
943 (def-markup-command (arrow-head layout props axis direction filled)
944 (integer? ly:dir? boolean?)
945 "produce an arrow head in specified direction and axis. Use the filled head if @var{filled} is specified."
947 ((name (format "arrowheads.~a.~a~a"
954 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
958 (def-markup-command (musicglyph layout props glyph-name) (string?)
959 "This is converted to a musical symbol, e.g. @code{\\musicglyph
960 #\"accidentals.0\"} will select the natural sign from the music font.
961 See @usermanref{The Feta font} for a complete listing of the possible glyphs."
963 (ly:paper-get-font layout (cons '((font-encoding . fetaMusic))
967 (def-markup-command (lookup layout props glyph-name) (string?)
968 "Lookup a glyph by name."
969 (ly:font-get-glyph (ly:paper-get-font layout props)
972 (def-markup-command (char layout props num) (integer?)
973 "Produce a single character, e.g. @code{\\char #65} produces the
975 (ly:get-glyph (ly:paper-get-font layout props) num))
978 (define number->mark-letter-vector (make-vector 25 #\A))
983 (if (= i (- (char->integer #\I) (char->integer #\A)))
985 (vector-set! number->mark-letter-vector j
986 (integer->char (+ i (char->integer #\A)))))
988 (define number->mark-alphabet-vector (list->vector
989 (map (lambda (i) (integer->char (+ i (char->integer #\A)))) (iota 26))))
991 (define (number->markletter-string vec n)
992 "Double letters for big marks."
993 (let* ((lst (vector-length vec)))
996 (string-append (number->markletter-string vec (1- (quotient n lst)))
997 (number->markletter-string vec (remainder n lst)))
998 (make-string 1 (vector-ref vec n)))))
1000 (def-markup-command (markletter layout props num) (integer?)
1001 "Make a markup letter for @var{num}. The letters start with A to Z
1002 (skipping I), and continues with double letters."
1003 (ly:text-interface::interpret-markup layout props
1004 (number->markletter-string number->mark-letter-vector num)))
1006 (def-markup-command (markalphabet layout props num) (integer?)
1007 "Make a markup letter for @var{num}. The letters start with A to Z
1008 and continues with double letters."
1009 (ly:text-interface::interpret-markup layout props
1010 (number->markletter-string number->mark-alphabet-vector num)))
1014 (def-markup-command (slashed-digit layout props num) (integer?)
1015 "A feta number, with slash. This is for use in the context of
1016 figured bass notation"
1018 ((mag (magstep (chain-assoc-get 'font-size props 0)))
1021 (chain-assoc-get 'thickness props 0.16)))
1023 (number-stencil (interpret-markup layout
1024 (prepend-alist-chain 'font-encoding 'fetaNumber props)
1025 (number->string num)))
1026 (num-x (interval-widen (ly:stencil-extent number-stencil X)
1028 (num-y (ly:stencil-extent number-stencil Y))
1033 ,(car num-x) ,(- (interval-center num-y) dy)
1034 ,(cdr num-x) ,(+ (interval-center num-y) dy))
1038 (ly:stencil-add number-stencil
1040 ((= num 5) (ly:stencil-translate slash-stencil
1041 ;;(cons (* mag -0.05) (* mag 0.42))
1042 (cons (* mag -0.00) (* mag -0.07))
1045 ((= num 7) (ly:stencil-translate slash-stencil
1046 ;;(cons (* mag -0.05) (* mag 0.42))
1047 (cons (* mag -0.00) (* mag -0.15))
1051 (else slash-stencil)))
1054 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1055 ;; the note command.
1056 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1059 ;; TODO: better syntax.
1061 (def-markup-command (note-by-number layout props log dot-count dir) (number? number? number?)
1062 "Construct a note symbol, with stem. By using fractional values for
1063 @var{dir}, you can obtain longer or shorter stems."
1064 (let* ((font (ly:paper-get-font layout (cons '((font-encoding . fetaMusic)) props)))
1065 (size (chain-assoc-get 'font-size props 0))
1066 (stem-length (* (magstep size) (max 3 (- log 1))))
1067 (head-glyph (ly:font-get-glyph
1069 (string-append "noteheads.s" (number->string (min log 2)))))
1070 (stem-thickness 0.13)
1071 (stemy (* dir stem-length))
1072 (attachx (if (> dir 0)
1073 (- (cdr (ly:stencil-extent head-glyph X)) stem-thickness)
1075 (attachy (* dir 0.28))
1076 (stem-glyph (and (> log 0)
1077 (ly:round-filled-box
1078 (cons attachx (+ attachx stem-thickness))
1079 (cons (min stemy attachy)
1080 (max stemy attachy))
1081 (/ stem-thickness 3))))
1082 (dot (ly:font-get-glyph font "dots.dot"))
1083 (dotwid (interval-length (ly:stencil-extent dot X)))
1084 (dots (and (> dot-count 0)
1085 (apply ly:stencil-add
1087 (ly:stencil-translate-axis
1088 dot (* (+ 1 (* 2 x)) dotwid) X))
1089 (iota dot-count 1)))))
1090 (flaggl (and (> log 2)
1091 (ly:stencil-translate
1092 (ly:font-get-glyph font
1093 (string-append "flags."
1094 (if (> dir 0) "u" "d")
1095 (number->string log)))
1096 (cons (+ attachx (/ stem-thickness 2)) stemy)))))
1098 (set! stem-glyph (ly:stencil-add flaggl stem-glyph)))
1099 (if (ly:stencil? stem-glyph)
1100 (set! stem-glyph (ly:stencil-add stem-glyph head-glyph))
1101 (set! stem-glyph head-glyph))
1102 (if (ly:stencil? dots)
1105 (ly:stencil-translate-axis
1107 (+ (if (and (> dir 0) (> log 2))
1110 ;; huh ? why not necessary?
1111 ;;(cdr (ly:stencil-extent head-glyph X))
1118 (let ((divisor (log 2)))
1119 (lambda (z) (inexact->exact (/ (log z) divisor)))))
1121 (define (parse-simple-duration duration-string)
1122 "Parse the `duration-string', e.g. ''4..'' or ''breve.'', and return a (log dots) list."
1123 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
1124 (if (and match (string=? duration-string (match:substring match 0)))
1125 (let ((len (match:substring match 1))
1126 (dots (match:substring match 2)))
1127 (list (cond ((string=? len "breve") -1)
1128 ((string=? len "longa") -2)
1129 ((string=? len "maxima") -3)
1130 (else (log2 (string->number len))))
1131 (if dots (string-length dots) 0)))
1132 (ly:error (_ "not a valid duration string: ~a") duration-string))))
1134 (def-markup-command (note layout props duration dir) (string? number?)
1135 "This produces a note with a stem pointing in @var{dir} direction, with
1136 the @var{duration} for the note head type and augmentation dots. For
1137 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
1138 a shortened down stem."
1139 (let ((parsed (parse-simple-duration duration)))
1140 (note-by-number-markup layout props (car parsed) (cadr parsed) dir)))
1143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1147 (def-markup-command (lower layout props amount arg) (number? markup?)
1149 Lower @var{arg}, by the distance @var{amount}.
1150 A negative @var{amount} indicates raising, see also @code{\\raise}.
1152 (ly:stencil-translate-axis (interpret-markup layout props arg)
1156 (def-markup-command (raise layout props amount arg) (number? markup?)
1158 Raise @var{arg}, by the distance @var{amount}.
1159 A negative @var{amount} indicates lowering, see also @code{\\lower}.
1161 @lilypond[verbatim,fragment,relative=1]
1162 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
1164 The argument to @code{\\raise} is the vertical displacement amount,
1165 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
1166 raise objects in relation to their surrounding markups.
1168 If the text object itself is positioned above or below the staff, then
1169 @code{\\raise} cannot be used to move it, since the mechanism that
1170 positions it next to the staff cancels any shift made with
1171 @code{\\raise}. For vertical positioning, use the @code{padding}
1172 and/or @code{extra-offset} properties. "
1173 (ly:stencil-translate-axis (interpret-markup layout props arg) amount Y))
1175 (def-markup-command (fraction layout props arg1 arg2) (markup? markup?)
1176 "Make a fraction of two markups."
1177 (let* ((m1 (interpret-markup layout props arg1))
1178 (m2 (interpret-markup layout props arg2)))
1179 (set! m1 (ly:stencil-aligned-to m1 X CENTER))
1180 (set! m2 (ly:stencil-aligned-to m2 X CENTER))
1181 (let* ((x1 (ly:stencil-extent m1 X))
1182 (x2 (ly:stencil-extent m2 X))
1183 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
1184 ;; should stack mols separately, to maintain LINE on baseline
1185 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
1187 (ly:stencil-aligned-to stack Y CENTER))
1189 (ly:stencil-aligned-to stack X LEFT))
1190 ;; should have EX dimension
1192 (ly:stencil-translate-axis stack 0.75 Y))))
1198 (def-markup-command (normal-size-super layout props arg) (markup?)
1199 "Set @var{arg} in superscript with a normal font size."
1200 (ly:stencil-translate-axis
1201 (interpret-markup layout props arg)
1202 (* 0.5 (chain-assoc-get 'baseline-skip props)) Y))
1204 (def-markup-command (super layout props arg) (markup?)
1206 @cindex raising text
1207 @cindex lowering text
1209 @cindex translating text
1211 @cindex @code{\\super}
1214 Raising and lowering texts can be done with @code{\\super} and
1217 @lilypond[verbatim,fragment,relative=1]
1218 c1^\\markup { E \"=\" mc \\super \"2\" }
1222 (ly:stencil-translate-axis
1225 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1227 (* 0.5 (chain-assoc-get 'baseline-skip props))
1230 (def-markup-command (translate layout props offset arg) (number-pair? markup?)
1231 "This translates an object. Its first argument is a cons of numbers
1233 A \\translate #(cons 2 -3) @{ B C @} D
1235 This moves `B C' 2 spaces to the right, and 3 down, relative to its
1236 surroundings. This command cannot be used to move isolated scripts
1237 vertically, for the same reason that @code{\\raise} cannot be used for
1241 (ly:stencil-translate (interpret-markup layout props arg)
1244 (def-markup-command (sub layout props arg) (markup?)
1245 "Set @var{arg} in subscript."
1246 (ly:stencil-translate-axis
1249 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
1251 (* -0.5 (chain-assoc-get 'baseline-skip props))
1254 (def-markup-command (normal-size-sub layout props arg) (markup?)
1255 "Set @var{arg} in subscript, in a normal font size."
1256 (ly:stencil-translate-axis
1257 (interpret-markup layout props arg)
1258 (* -0.5 (chain-assoc-get 'baseline-skip props))
1261 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1263 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1265 (def-markup-command (hbracket layout props arg) (markup?)
1266 "Draw horizontal brackets around @var{arg}."
1267 (let ((th 0.1) ;; todo: take from GROB.
1268 (m (interpret-markup layout props arg)))
1269 (bracketify-stencil m X th (* 2.5 th) th)))
1271 (def-markup-command (bracket layout props arg) (markup?)
1272 "Draw vertical brackets around @var{arg}."
1273 (let ((th 0.1) ;; todo: take from GROB.
1274 (m (interpret-markup layout props arg)))
1275 (bracketify-stencil m Y th (* 2.5 th) th)))
1277 (def-markup-command (bracketed-y-column layout props indices args)
1278 (list? markup-list?)
1279 "Make a column of the markups in @var{args}, putting brackets around
1280 the elements marked in @var{indices}, which is a list of numbers.
1284 ;; DROPME? This command is a relic from the old figured bass implementation.
1287 (define (sublist lst start stop)
1288 (take (drop lst start) (- (1+ stop) start)))
1290 (define (stencil-list-extent ss axis)
1292 (apply min (map (lambda (x) (car (ly:stencil-extent x axis))) ss))
1293 (apply max (map (lambda (x) (cdr (ly:stencil-extent x axis))) ss))))
1296 (define (stack-stencils-vertically stencils bskip last-stencil)
1298 ((null? stencils) '())
1299 ((not (ly:stencil? last-stencil))
1300 (cons (car stencils)
1301 (stack-stencils-vertically (cdr stencils) bskip (car stencils))))
1303 (let* ((orig (car stencils))
1304 (dir (chain-assoc-get 'direction props DOWN))
1305 (new (ly:stencil-moved-to-edge last-stencil Y dir
1309 (cons new (stack-stencils-vertically (cdr stencils) bskip new))))))
1311 (define (make-brackets stencils indices acc)
1314 (pair? (cdr indices)))
1315 (let* ((encl (sublist stencils (car indices) (cadr indices)))
1316 (x-ext (stencil-list-extent encl X))
1317 (y-ext (stencil-list-extent encl Y))
1320 (protusion (* 2.5 thick))
1322 (ly:stencil-translate-axis
1323 (ly:bracket Y y-ext thick protusion)
1324 (- (car x-ext) pad) X))
1325 (rb (ly:stencil-translate-axis
1326 (ly:bracket Y y-ext thick (- protusion))
1327 (+ (cdr x-ext) pad) X)))
1330 stencils (cddr indices)
1343 (chain-assoc-get 'baseline-skip props))
1344 (stacked (stack-stencils-vertically
1345 (remove ly:stencil-empty? stencils) 1.25 #f))
1346 (brackets (make-brackets stacked indices '())))
1348 (apply ly:stencil-add
1349 (append stacked brackets))))
1352 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1353 ;; size indications arrow
1354 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;