3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;; each markup function should have a doc string with
7 ;; syntax, description and example.
11 (def-markup-command (simple paper props str) (string?)
12 "A simple text-string; @code{\\markup @{ foo @}} is equivalent with
13 @code{\\markup @{ \\simple #\"foo\" @}}.
15 (interpret-markup paper props str))
17 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 (define (font-markup qualifier value)
21 (lambda (paper props arg)
22 (interpret-markup paper
23 (prepend-alist-chain qualifier value props)
28 (define-public empty-markup
29 (make-simple-markup ""))
31 (def-markup-command (line paper props args) (markup-list?)
32 "Put @var{args} in a horizontal line. The property @code{word-space} determines
33 the space between each markup in @var{args}.
36 (cdr (chain-assoc 'word-space props))
37 (map (lambda (m) (interpret-markup paper props m)) args)))
39 (def-markup-command (combine paper props m1 m2) (markup? markup?)
40 "Print two markups on top of each other."
42 (interpret-markup paper props m1)
43 (interpret-markup paper props m2)))
46 (def-markup-command (finger paper props arg) (markup?)
47 "Set the argument as small numbers."
48 (interpret-markup paper
49 (cons '((font-size . -4) (font-family . number)) props)
53 (def-markup-command (fontsize paper props mag arg) (number? markup?)
54 "This sets the relative font size, eg.
56 A \\fontsize #2 @{ B C @} D
60 This will enlarge the B and the C by two steps.
64 (prepend-alist-chain 'font-size mag props)
67 (def-markup-command (magnify paper props sz arg) (number? markup?)
68 "This sets the font magnification for the its argument. In the following
69 example, the middle A will be 10% larger:
71 A \\magnify #1.1 @{ A @} A
74 Note: magnification only works if a font-name is explicitly selected.
75 Use @code{\\fontsize} otherwise."
79 (prepend-alist-chain 'font-magnification sz props)
82 (def-markup-command (bold paper props arg) (markup?)
83 "Switch to bold font-series"
84 (interpret-markup paper (prepend-alist-chain 'font-series 'bold props) arg))
86 (def-markup-command (sans paper props arg) (markup?)
87 "Switch to the sans-serif family"
88 (interpret-markup paper (prepend-alist-chain 'font-family 'sans props) arg))
90 (def-markup-command (number paper props arg) (markup?)
91 "Set font family to @code{number}, which yields the font used for
92 time signatures and fingerings. This font only contains numbers and
93 some punctuation. It doesn't have any letters. "
94 (interpret-markup paper (prepend-alist-chain 'font-family 'number props) arg))
96 (def-markup-command (roman paper props arg) (markup?)
97 "Set font family to @code{roman}."
98 (interpret-markup paper (prepend-alist-chain 'font-family 'roman props) arg))
100 (def-markup-command (huge paper props arg) (markup?)
101 "Set font size to +2."
102 (interpret-markup paper (prepend-alist-chain 'font-size 2 props) arg))
104 (def-markup-command (large paper props arg) (markup?)
105 "Set font size to +1."
106 (interpret-markup paper (prepend-alist-chain 'font-size 1 props) arg))
108 (def-markup-command (normalsize paper props arg) (markup?)
109 "Set font size to default."
110 (interpret-markup paper (prepend-alist-chain 'font-size 0 props) arg))
112 (def-markup-command (small paper props arg) (markup?)
113 "Set font size to -1."
114 (interpret-markup paper (prepend-alist-chain 'font-size -1 props) arg))
116 (def-markup-command (tiny paper props arg) (markup?)
117 "Set font size to -2."
118 (interpret-markup paper (prepend-alist-chain 'font-size -2 props) arg))
120 (def-markup-command (teeny paper props arg) (markup?)
121 "Set font size to -3."
122 (interpret-markup paper (prepend-alist-chain 'font-size -3 props) arg))
124 (def-markup-command (caps paper props arg) (markup?)
125 "Set font shape to @code{caps}."
126 (interpret-markup paper (prepend-alist-chain 'font-shape 'caps props) arg))
128 (def-markup-command (dynamic paper props arg) (markup?)
129 "Use the dynamic font. This font only contains s, f, m, z, p, and
130 r. When producing phrases, like ``piu f'', the normal words (like
131 ``piu'') should be done in a different font. The recommend font for
132 this is bold and italic
135 paper (prepend-alist-chain 'font-family 'dynamic props) arg))
137 (def-markup-command (italic paper props arg) (markup?)
138 (interpret-markup paper (prepend-alist-chain 'font-shape 'italic props) arg))
140 (def-markup-command (typewriter paper props arg) (markup?)
142 paper (prepend-alist-chain 'font-family 'typewriter props) arg))
144 (def-markup-command (doublesharp paper props) ()
145 (interpret-markup paper props (markup #:musicglyph "accidentals-4")))
146 (def-markup-command (threeqsharp paper props) ()
147 (interpret-markup paper props (markup #:musicglyph "accidentals-3")))
148 (def-markup-command (sharp paper props) ()
149 (interpret-markup paper props (markup #:musicglyph "accidentals-2")))
150 (def-markup-command (semisharp paper props) ()
151 (interpret-markup paper props (markup #:musicglyph "accidentals-1")))
152 (def-markup-command (natural paper props) ()
153 (interpret-markup paper props (markup #:musicglyph "accidentals-0")))
154 (def-markup-command (semiflat paper props) ()
155 (interpret-markup paper props (markup #:musicglyph "accidentals--1")))
156 (def-markup-command (flat paper props) ()
157 (interpret-markup paper props (markup #:musicglyph "accidentals--2")))
158 (def-markup-command (threeqflat paper props) ()
159 (interpret-markup paper props (markup #:musicglyph "accidentals--3")))
160 (def-markup-command (doubleflat paper props) ()
161 (interpret-markup paper props (markup #:musicglyph "accidentals--4")))
164 (def-markup-command (column paper props args) (markup-list?)
166 -1 0.0 (cdr (chain-assoc 'baseline-skip props))
167 (map (lambda (m) (interpret-markup paper props m)) args)))
169 (def-markup-command (dir-column paper props args) (markup-list?)
170 "Make a column of args, going up or down, depending on the setting
171 of the #'direction layout property."
172 (let* ((dir (cdr (chain-assoc 'direction props))))
174 (if (number? dir) dir -1)
176 (cdr (chain-assoc 'baseline-skip props))
177 (map (lambda (x) (interpret-markup paper props x)) args))))
179 (def-markup-command (center paper props args) (markup-list?)
180 (let* ((mols (map (lambda (x) (interpret-markup paper props x)) args))
181 (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
182 (stack-lines -1 0.0 (cdr (chain-assoc 'baseline-skip props)) mols)))
184 (def-markup-command (right-align paper props arg) (markup?)
185 (let* ((m (interpret-markup paper props arg)))
186 (ly:stencil-align-to! m X RIGHT)
189 (def-markup-command (left-align paper props arg) (markup?)
190 (let* ((m (interpret-markup paper props arg)))
191 (ly:stencil-align-to! m X LEFT)
194 (def-markup-command (halign paper props dir arg) (number? markup?)
195 "Set horizontal alignment. @var{dir} = -1 is left, @var{dir} = 1 is
196 right, values in between vary alignment accordingly."
199 (let* ((m (interpret-markup paper props arg)))
200 (ly:stencil-align-to! m X dir)
203 (def-markup-command (musicglyph paper props glyph-name) (string?)
204 "This is converted to a musical symbol, e.g. @code{\\musicglyph
205 #\"accidentals-0\"} will select the natural sign from the music font.
206 See @usermanref{The Feta font} for a complete listing of the possible glyphs.
208 (ly:find-glyph-by-name
209 (ly:paper-get-font paper (cons '((font-name . ())
212 (font-family . music))
217 (def-markup-command (lookup paper props glyph-name) (string?)
218 "Lookup a glyph by name."
219 (ly:find-glyph-by-name (ly:paper-get-font paper props)
222 (def-markup-command (char paper props num) (integer?)
223 "This produces a single character, e.g. @code{\\char #65} produces the
225 (ly:get-glyph (ly:paper-get-font paper props) num))
227 (def-markup-command (raise paper props amount arg) (number? markup?)
229 This raises @var{arg}, by the distance @var{amount}.
230 A negative @var{amount} indicates lowering:
232 @lilypond[verbatim,fragment,relative=1,quote]
233 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
235 The argument to @code{\\raise} is the vertical displacement amount,
236 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
237 raise objects in relation to their surrounding markups.
239 If the text object itself is positioned above or below the staff, then
240 @code{\\raise} cannot be used to move it, since the mechanism that
241 positions it next to the staff cancels any shift made with
242 @code{\\raise}. For vertical positioning, use the @code{padding}
243 and/or @code{extra-offset} properties. "
246 (ly:stencil-translate-axis (interpret-markup paper props arg)
249 (def-markup-command (fraction paper props arg1 arg2) (markup? markup?)
250 "Make a fraction of two markups.
252 Syntax: \\fraction MARKUP1 MARKUP2."
253 (let* ((m1 (interpret-markup paper props arg1))
254 (m2 (interpret-markup paper props arg2)))
255 (ly:stencil-align-to! m1 X CENTER)
256 (ly:stencil-align-to! m2 X CENTER)
257 (let* ((x1 (ly:stencil-get-extent m1 X))
258 (x2 (ly:stencil-get-extent m2 X))
259 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
260 ;; should stack mols separately, to maintain LINE on baseline
261 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
262 (ly:stencil-align-to! stack Y CENTER)
263 (ly:stencil-align-to! stack X LEFT)
264 ;; should have EX dimension
266 (ly:stencil-translate-axis stack 0.75 Y))))
269 ;; TODO: better syntax.
271 (def-markup-command (note-by-number paper props log dot-count dir) (number? number? number?)
272 "Syntax: \\note-by-number #LOG #DOTS #DIR. By using fractional values
273 for DIR, you can obtain longer or shorter stems."
274 (let* ((font (ly:paper-get-font paper (cons '((font-family . music)) props)))
275 (stemlen (max 3 (- log 1)))
276 (headgl (ly:find-glyph-by-name
278 (string-append "noteheads-" (number->string (min log 2)))))
280 (stemy (* dir stemlen))
281 (attachx (if (> dir 0)
282 (- (cdr (ly:stencil-get-extent headgl X)) stemth)
284 (attachy (* dir 0.28))
285 (stemgl (and (> log 0)
287 (cons attachx (+ attachx stemth))
288 (cons (min stemy attachy)
291 (dot (ly:find-glyph-by-name font "dots-dot"))
292 (dotwid (interval-length (ly:stencil-get-extent dot X)))
293 (dots (and (> dot-count 0)
294 (apply ly:stencil-add
296 (ly:stencil-translate-axis
297 dot (* (+ 1 (* 2 x)) dotwid) X) )
298 (iota dot-count 1)))))
299 (flaggl (and (> log 2)
300 (ly:stencil-translate
301 (ly:find-glyph-by-name font
302 (string-append "flags-"
303 (if (> dir 0) "u" "d")
304 (number->string log)))
305 (cons (+ attachx (/ stemth 2)) stemy)))))
307 (set! stemgl (ly:stencil-add flaggl stemgl)))
308 (if (ly:stencil? stemgl)
309 (set! stemgl (ly:stencil-add stemgl headgl))
310 (set! stemgl headgl))
311 (if (ly:stencil? dots)
314 (ly:stencil-translate-axis dots
315 (+ (if (and (> dir 0) (> log 2))
318 ;; huh ? why not necessary?
319 ;;(cdr (ly:stencil-get-extent headgl X))
325 (use-modules (ice-9 regex))
328 (let ((divisor (log 2)))
329 (lambda (z) (inexact->exact (/ (log z) divisor)))))
331 (define (parse-simple-duration duration-string)
332 "Parse the `duration-string', eg ''4..'' or ''breve.'', and return a (log dots) list."
333 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
334 (if (and match (string=? duration-string (match:substring match 0)))
335 (let ((len (match:substring match 1))
336 (dots (match:substring match 2)))
337 (list (cond ((string=? len "breve") -1)
338 ((string=? len "longa") -2)
339 ((string=? len "maxima") -3)
340 (else (log2 (string->number len))))
341 (if dots (string-length dots) 0)))
342 (error "This is not a valid duration string:" duration-string))))
344 (def-markup-command (note paper props duration dir) (string? number?)
345 "This produces a note with a stem pointing in @var{dir} direction, with
346 the @var{duration} for the note head type and augmentation dots. For
347 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
348 a shortened down stem."
350 (let ((parsed (parse-simple-duration duration)))
351 (note-by-number-markup paper props (car parsed) (cadr parsed) dir)))
353 (def-markup-command (normal-size-super paper props arg) (markup?)
354 "A superscript which does not use a smaller font."
355 (ly:stencil-translate-axis (interpret-markup
358 (* 0.5 (cdr (chain-assoc 'baseline-skip props)))
361 (def-markup-command (super paper props arg) (markup?)
364 @cindex lowering text
366 @cindex translating text
368 @cindex @code{\\super}
371 Raising and lowering texts can be done with @code{\\super} and
374 @lilypond[verbatim,fragment,relative=1]
375 c1^\\markup { E \"=\" mc \\super \"2\" }
380 (ly:stencil-translate-axis
383 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
385 (* 0.5 (cdr (chain-assoc 'baseline-skip props)))
388 (def-markup-command (translate paper props offset arg) (number-pair? markup?)
389 "This translates an object. Its first argument is a cons of numbers
391 A \\translate #(cons 2 -3) @{ B C @} D
393 This moves `B C' 2 spaces to the right, and 3 down, relative to its
394 surroundings. This command cannot be used to move isolated scripts
395 vertically, for the same reason that @code{\\raise} cannot be used for
399 (ly:stencil-translate (interpret-markup paper props arg)
402 (def-markup-command (sub paper props arg) (markup?)
403 "Syntax: \\sub MARKUP."
404 (ly:stencil-translate-axis
407 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
409 (* -0.5 (cdr (chain-assoc 'baseline-skip props)))
412 (def-markup-command (normal-size-sub paper props arg) (markup?)
413 (ly:stencil-translate-axis
414 (interpret-markup paper props arg)
415 (* -0.5 (cdr (chain-assoc 'baseline-skip props)))
418 (def-markup-command (hbracket paper props arg) (markup?)
419 "Horizontal brackets around @var{arg}."
420 (let ((th 0.1) ;; todo: take from GROB.
421 (m (interpret-markup paper props arg)))
422 (bracketify-stencil m X th (* 2.5 th) th)))
424 (def-markup-command (bracket paper props arg) (markup?)
425 "Vertical brackets around @var{arg}."
426 (let ((th 0.1) ;; todo: take from GROB.
427 (m (interpret-markup paper props arg)))
428 (bracketify-stencil m Y th (* 2.5 th) th)))
430 ;; todo: fix negative space
431 (def-markup-command (hspace paper props amount) (number?)
432 "This produces a invisible object taking horizontal space.
434 \\markup @{ A \\hspace #2.0 B @}
436 will put extra space between A and B, on top of the space that is
437 normally inserted before elements on a line.
440 (ly:make-stencil "" (cons 0 amount) '(-1 . 1) )
441 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
443 (def-markup-command (override paper props new-prop arg) (pair? markup?)
444 "Add the first argument in to the property list. Properties may be
445 any sort of property supported by @internalsref{font-interface} and
446 @internalsref{text-interface}, for example
449 \\override #'(font-family . married) \"bla\"
453 (interpret-markup paper (cons (list new-prop) props) arg))
455 (def-markup-command (smaller paper props arg) (markup?)
456 "Decrease the font size relative to current setting"
457 (let* ((fs (chain-assoc-get 'font-size props 0))
458 (entry (cons 'font-size (- fs 1))))
459 (interpret-markup paper (cons (list entry) props) arg)))
462 (def-markup-command (bigger paper props arg) (markup?)
463 "Increase the font size relative to current setting"
464 (let* ((fs (chain-assoc-get 'font-size props 0))
465 (entry (cons 'font-size (+ fs 1))))
466 (interpret-markup paper (cons (list entry) props) arg)))
468 (def-markup-command larger (markup?)
471 (def-markup-command (box paper props arg) (markup?)
472 "Draw a box round @var{arg}"
476 (m (interpret-markup paper props arg)))
477 (box-stencil m th pad)))
479 (def-markup-command (strut paper props) ()
481 "Create a box of the same height as the space in the current font.
483 FIXME: is this working?
486 (let ((m (Text_item::interpret_markup paper props " ")))
487 (ly:stencil-set-extent! m X '(1000 . -1000))
490 (define number->mark-letter-vector (make-vector 25 #\A))
495 (if (= i (- (char->integer #\I) (char->integer #\A)))
497 (vector-set! number->mark-letter-vector j
498 (integer->char (+ i (char->integer #\A)))))
500 (define (number->markletter-string n)
501 "Double letters for big marks."
503 ((l (vector-length number->mark-letter-vector)))
506 (string-append (number->markletter-string (1- (quotient n l)))
507 (number->markletter-string (remainder n l)))
508 (make-string 1 (vector-ref number->mark-letter-vector n)))))
511 (def-markup-command (markletter paper props num) (integer?)
512 "Make a markup letter for @var{num}. The letters start with A to Z
513 (skipping I), and continues with double letters."
515 (Text_item::interpret_markup paper props (number->markletter-string num)))