1 ;;;; define-markup-commands.scm -- markup commands
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2000--2004 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.
14 (def-markup-command (word paper props str) (string?)
16 (interpret-markup paper props str))
18 (def-markup-command (simple paper props str) (string?)
19 "A simple text-string; @code{\\markup @{ foo @}} is equivalent with
20 @code{\\markup @{ \\simple #\"foo\" @}}."
21 (let ((toks (string-tokenize str)))
22 (interpret-markup paper props
24 (map make-word-markup toks)))
27 (define (font-markup qualifier value)
28 (lambda (paper props arg)
29 (interpret-markup paper
30 (prepend-alist-chain qualifier value props)
33 (define-public empty-markup
34 (make-simple-markup ""))
36 (def-markup-command (line paper props args) (markup-list?)
37 "Put @var{args} in a horizontal line. The property @code{word-space} determines
38 the space between each markup in @var{args}.
41 (cdr (chain-assoc 'word-space props))
42 (map (lambda (m) (interpret-markup paper props m)) args)))
44 (def-markup-command (combine paper props m1 m2) (markup? markup?)
45 "Print two markups on top of each other."
47 (interpret-markup paper props m1)
48 (interpret-markup paper props m2)))
51 (def-markup-command (finger paper props arg) (markup?)
52 "Set the argument as small numbers."
53 (interpret-markup paper
54 (cons '((font-size . -4) (font-family . number)) props)
58 (def-markup-command (fontsize paper props mag arg) (number? markup?)
59 "This sets the relative font size, eg.
61 A \\fontsize #2 @{ B C @} D
65 This will enlarge the B and the C by two steps.
69 (prepend-alist-chain 'font-size mag props)
72 (def-markup-command (magnify paper props sz arg) (number? markup?)
73 "This sets the font magnification for the its argument. In the following
74 example, the middle A will be 10% larger:
76 A \\magnify #1.1 @{ A @} A
79 Note: magnification only works if a font-name is explicitly selected.
80 Use @code{\\fontsize} otherwise."
84 (prepend-alist-chain 'font-magnification sz props)
87 (def-markup-command (bold paper props arg) (markup?)
88 "Switch to bold font-series"
89 (interpret-markup paper (prepend-alist-chain 'font-series 'bold props) arg))
91 (def-markup-command (sans paper props arg) (markup?)
92 "Switch to the sans-serif family"
93 (interpret-markup paper (prepend-alist-chain 'font-family 'sans props) arg))
95 (def-markup-command (number paper props arg) (markup?)
96 "Set font family to @code{number}, which yields the font used for
97 time signatures and fingerings. This font only contains numbers and
98 some punctuation. It doesn't have any letters. "
99 (interpret-markup paper (prepend-alist-chain 'font-family 'number props) arg))
101 (def-markup-command (roman paper props arg) (markup?)
102 "Set font family to @code{roman}."
103 (interpret-markup paper (prepend-alist-chain 'font-family 'roman props) arg))
105 (def-markup-command (huge paper props arg) (markup?)
106 "Set font size to +2."
107 (interpret-markup paper (prepend-alist-chain 'font-size 2 props) arg))
109 (def-markup-command (large paper props arg) (markup?)
110 "Set font size to +1."
111 (interpret-markup paper (prepend-alist-chain 'font-size 1 props) arg))
113 (def-markup-command (normalsize paper props arg) (markup?)
114 "Set font size to default."
115 (interpret-markup paper (prepend-alist-chain 'font-size 0 props) arg))
117 (def-markup-command (small paper props arg) (markup?)
118 "Set font size to -1."
119 (interpret-markup paper (prepend-alist-chain 'font-size -1 props) arg))
121 (def-markup-command (tiny paper props arg) (markup?)
122 "Set font size to -2."
123 (interpret-markup paper (prepend-alist-chain 'font-size -2 props) arg))
125 (def-markup-command (teeny paper props arg) (markup?)
126 "Set font size to -3."
127 (interpret-markup paper (prepend-alist-chain 'font-size -3 props) arg))
129 (def-markup-command (caps paper props arg) (markup?)
130 "Set font shape to @code{caps}."
131 (interpret-markup paper (prepend-alist-chain 'font-shape 'caps props) arg))
133 (def-markup-command (dynamic paper props arg) (markup?)
134 "Use the dynamic font. This font only contains s, f, m, z, p, and
135 r. When producing phrases, like ``piu f'', the normal words (like
136 ``piu'') should be done in a different font. The recommend font for
137 this is bold and italic
140 paper (prepend-alist-chain 'font-family 'dynamic props) arg))
142 (def-markup-command (italic paper props arg) (markup?)
143 (interpret-markup paper (prepend-alist-chain 'font-shape 'italic props) arg))
145 (def-markup-command (typewriter paper props arg) (markup?)
147 paper (prepend-alist-chain 'font-family 'typewriter props) arg))
149 (def-markup-command (upright paper props arg) (markup?)
150 "Set font shape to @code{upright}."
152 paper (prepend-alist-chain 'font-shape 'upright props) arg))
154 (def-markup-command (doublesharp paper props) ()
155 (interpret-markup paper props (markup #:musicglyph "accidentals-4")))
156 (def-markup-command (threeqsharp paper props) ()
157 (interpret-markup paper props (markup #:musicglyph "accidentals-3")))
158 (def-markup-command (sharp paper props) ()
159 (interpret-markup paper props (markup #:musicglyph "accidentals-2")))
160 (def-markup-command (semisharp paper props) ()
161 (interpret-markup paper props (markup #:musicglyph "accidentals-1")))
162 (def-markup-command (natural paper props) ()
163 (interpret-markup paper props (markup #:musicglyph "accidentals-0")))
164 (def-markup-command (semiflat paper props) ()
165 (interpret-markup paper props (markup #:musicglyph "accidentals--1")))
166 (def-markup-command (flat paper props) ()
167 (interpret-markup paper props (markup #:musicglyph "accidentals--2")))
168 (def-markup-command (threeqflat paper props) ()
169 (interpret-markup paper props (markup #:musicglyph "accidentals--3")))
170 (def-markup-command (doubleflat paper props) ()
171 (interpret-markup paper props (markup #:musicglyph "accidentals--4")))
174 (def-markup-command (column paper props args) (markup-list?)
176 -1 0.0 (cdr (chain-assoc 'baseline-skip props))
177 (map (lambda (m) (interpret-markup paper props m)) args)))
179 (def-markup-command (dir-column paper props args) (markup-list?)
180 "Make a column of args, going up or down, depending on the setting
181 of the #'direction layout property."
182 (let* ((dir (cdr (chain-assoc 'direction props))))
184 (if (number? dir) dir -1)
186 (cdr (chain-assoc 'baseline-skip props))
187 (map (lambda (x) (interpret-markup paper props x)) args))))
189 (def-markup-command (center paper props args) (markup-list?)
190 (let* ((mols (map (lambda (x) (interpret-markup paper props x)) args))
191 (cmols (map (lambda (x) (ly:stencil-align-to! x X CENTER)) mols)))
192 (stack-lines -1 0.0 (cdr (chain-assoc 'baseline-skip props)) mols)))
194 (def-markup-command (right-align paper props arg) (markup?)
195 (let* ((m (interpret-markup paper props arg)))
196 (ly:stencil-align-to! m X RIGHT)
199 (def-markup-command (left-align paper props arg) (markup?)
200 (let* ((m (interpret-markup paper props arg)))
201 (ly:stencil-align-to! m X LEFT)
204 (def-markup-command (halign paper props dir arg) (number? markup?)
205 "Set horizontal alignment. @var{dir} = -1 is left, @var{dir} = 1 is
206 right, values in between vary alignment accordingly."
209 (let* ((m (interpret-markup paper props arg)))
210 (ly:stencil-align-to! m X dir)
213 (def-markup-command (musicglyph paper props glyph-name) (string?)
214 "This is converted to a musical symbol, e.g. @code{\\musicglyph
215 #\"accidentals-0\"} will select the natural sign from the music font.
216 See @usermanref{The Feta font} for a complete listing of the possible glyphs.
218 (ly:find-glyph-by-name
219 (ly:paper-get-font paper (cons '((font-name . ())
222 (font-family . music))
227 (def-markup-command (lookup paper props glyph-name) (string?)
228 "Lookup a glyph by name."
229 (ly:find-glyph-by-name (ly:paper-get-font paper props)
232 (def-markup-command (char paper props num) (integer?)
233 "This produces a single character, e.g. @code{\\char #65} produces the
235 (ly:get-glyph (ly:paper-get-font paper props) num))
237 (def-markup-command (raise paper props amount arg) (number? markup?)
239 This raises @var{arg}, by the distance @var{amount}.
240 A negative @var{amount} indicates lowering:
242 @lilypond[verbatim,fragment,relative=1,quote]
243 c1^\\markup { C \\small \\raise #1.0 \\bold { \"9/7+\" }}
245 The argument to @code{\\raise} is the vertical displacement amount,
246 measured in (global) staff spaces. @code{\\raise} and @code{\\super}
247 raise objects in relation to their surrounding markups.
249 If the text object itself is positioned above or below the staff, then
250 @code{\\raise} cannot be used to move it, since the mechanism that
251 positions it next to the staff cancels any shift made with
252 @code{\\raise}. For vertical positioning, use the @code{padding}
253 and/or @code{extra-offset} properties. "
256 (ly:stencil-translate-axis (interpret-markup paper props arg)
259 (def-markup-command (fraction paper props arg1 arg2) (markup? markup?)
260 "Make a fraction of two markups.
262 Syntax: \\fraction MARKUP1 MARKUP2."
263 (let* ((m1 (interpret-markup paper props arg1))
264 (m2 (interpret-markup paper props arg2)))
265 (ly:stencil-align-to! m1 X CENTER)
266 (ly:stencil-align-to! m2 X CENTER)
267 (let* ((x1 (ly:stencil-get-extent m1 X))
268 (x2 (ly:stencil-get-extent m2 X))
269 (line (ly:round-filled-box (interval-union x1 x2) '(-0.05 . 0.05) 0.0))
270 ;; should stack mols separately, to maintain LINE on baseline
271 (stack (stack-lines -1 0.2 0.6 (list m1 line m2))))
272 (ly:stencil-align-to! stack Y CENTER)
273 (ly:stencil-align-to! stack X LEFT)
274 ;; should have EX dimension
276 (ly:stencil-translate-axis stack 0.75 Y))))
279 ;; TODO: better syntax.
281 (def-markup-command (note-by-number paper props log dot-count dir) (number? number? number?)
282 "Syntax: \\note-by-number #LOG #DOTS #DIR. By using fractional values
283 for DIR, you can obtain longer or shorter stems."
284 (let* ((font (ly:paper-get-font paper (cons '((font-family . music)) props)))
285 (stemlen (max 3 (- log 1)))
286 (headgl (ly:find-glyph-by-name
288 (string-append "noteheads-" (number->string (min log 2)))))
290 (stemy (* dir stemlen))
291 (attachx (if (> dir 0)
292 (- (cdr (ly:stencil-get-extent headgl X)) stemth)
294 (attachy (* dir 0.28))
295 (stemgl (and (> log 0)
297 (cons attachx (+ attachx stemth))
298 (cons (min stemy attachy)
301 (dot (ly:find-glyph-by-name font "dots-dot"))
302 (dotwid (interval-length (ly:stencil-get-extent dot X)))
303 (dots (and (> dot-count 0)
304 (apply ly:stencil-add
306 (ly:stencil-translate-axis
307 dot (* (+ 1 (* 2 x)) dotwid) X) )
308 (iota dot-count 1)))))
309 (flaggl (and (> log 2)
310 (ly:stencil-translate
311 (ly:find-glyph-by-name font
312 (string-append "flags-"
313 (if (> dir 0) "u" "d")
314 (number->string log)))
315 (cons (+ attachx (/ stemth 2)) stemy)))))
317 (set! stemgl (ly:stencil-add flaggl stemgl)))
318 (if (ly:stencil? stemgl)
319 (set! stemgl (ly:stencil-add stemgl headgl))
320 (set! stemgl headgl))
321 (if (ly:stencil? dots)
324 (ly:stencil-translate-axis dots
325 (+ (if (and (> dir 0) (> log 2))
328 ;; huh ? why not necessary?
329 ;;(cdr (ly:stencil-get-extent headgl X))
335 (use-modules (ice-9 regex))
338 (let ((divisor (log 2)))
339 (lambda (z) (inexact->exact (/ (log z) divisor)))))
341 (define (parse-simple-duration duration-string)
342 "Parse the `duration-string', eg ''4..'' or ''breve.'', and return a (log dots) list."
343 (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string)))
344 (if (and match (string=? duration-string (match:substring match 0)))
345 (let ((len (match:substring match 1))
346 (dots (match:substring match 2)))
347 (list (cond ((string=? len "breve") -1)
348 ((string=? len "longa") -2)
349 ((string=? len "maxima") -3)
350 (else (log2 (string->number len))))
351 (if dots (string-length dots) 0)))
352 (error "This is not a valid duration string:" duration-string))))
354 (def-markup-command (note paper props duration dir) (string? number?)
355 "This produces a note with a stem pointing in @var{dir} direction, with
356 the @var{duration} for the note head type and augmentation dots. For
357 example, @code{\\note #\"4.\" #-0.75} creates a dotted quarter note, with
358 a shortened down stem."
360 (let ((parsed (parse-simple-duration duration)))
361 (note-by-number-markup paper props (car parsed) (cadr parsed) dir)))
363 (def-markup-command (normal-size-super paper props arg) (markup?)
364 "A superscript which does not use a smaller font."
365 (ly:stencil-translate-axis (interpret-markup
368 (* 0.5 (cdr (chain-assoc 'baseline-skip props)))
371 (def-markup-command (super paper props arg) (markup?)
374 @cindex lowering text
376 @cindex translating text
378 @cindex @code{\\super}
381 Raising and lowering texts can be done with @code{\\super} and
384 @lilypond[verbatim,fragment,relative=1]
385 c1^\\markup { E \"=\" mc \\super \"2\" }
390 (ly:stencil-translate-axis
393 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
395 (* 0.5 (cdr (chain-assoc 'baseline-skip props)))
398 (def-markup-command (translate paper props offset arg) (number-pair? markup?)
399 "This translates an object. Its first argument is a cons of numbers
401 A \\translate #(cons 2 -3) @{ B C @} D
403 This moves `B C' 2 spaces to the right, and 3 down, relative to its
404 surroundings. This command cannot be used to move isolated scripts
405 vertically, for the same reason that @code{\\raise} cannot be used for
409 (ly:stencil-translate (interpret-markup paper props arg)
412 (def-markup-command (sub paper props arg) (markup?)
413 "Syntax: \\sub MARKUP."
414 (ly:stencil-translate-axis
417 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
419 (* -0.5 (cdr (chain-assoc 'baseline-skip props)))
422 (def-markup-command (normal-size-sub paper props arg) (markup?)
423 (ly:stencil-translate-axis
424 (interpret-markup paper props arg)
425 (* -0.5 (cdr (chain-assoc 'baseline-skip props)))
428 (def-markup-command (hbracket paper props arg) (markup?)
429 "Horizontal brackets around @var{arg}."
430 (let ((th 0.1) ;; todo: take from GROB.
431 (m (interpret-markup paper props arg)))
432 (bracketify-stencil m X th (* 2.5 th) th)))
434 (def-markup-command (bracket paper props arg) (markup?)
435 "Vertical brackets around @var{arg}."
436 (let ((th 0.1) ;; todo: take from GROB.
437 (m (interpret-markup paper props arg)))
438 (bracketify-stencil m Y th (* 2.5 th) th)))
440 ;; todo: fix negative space
441 (def-markup-command (hspace paper props amount) (number?)
442 "This produces a invisible object taking horizontal space.
444 \\markup @{ A \\hspace #2.0 B @}
446 will put extra space between A and B, on top of the space that is
447 normally inserted before elements on a line.
450 (ly:make-stencil "" (cons 0 amount) '(-1 . 1) )
451 (ly:make-stencil "" (cons amount amount) '(-1 . 1))))
453 (def-markup-command (override paper props new-prop arg) (pair? markup?)
454 "Add the first argument in to the property list. Properties may be
455 any sort of property supported by @internalsref{font-interface} and
456 @internalsref{text-interface}, for example
459 \\override #'(font-family . married) \"bla\"
463 (interpret-markup paper (cons (list new-prop) props) arg))
465 (def-markup-command (smaller paper props arg) (markup?)
466 "Decrease the font size relative to current setting"
467 (let* ((fs (chain-assoc-get 'font-size props 0))
468 (entry (cons 'font-size (- fs 1))))
469 (interpret-markup paper (cons (list entry) props) arg)))
472 (def-markup-command (bigger paper props arg) (markup?)
473 "Increase the font size relative to current setting"
474 (let* ((fs (chain-assoc-get 'font-size props 0))
475 (entry (cons 'font-size (+ fs 1))))
476 (interpret-markup paper (cons (list entry) props) arg)))
478 (def-markup-command larger (markup?)
481 (def-markup-command (box paper props arg) (markup?)
482 "Draw a box round @var{arg}"
486 (m (interpret-markup paper props arg)))
487 (box-stencil m th pad)))
489 (def-markup-command (strut paper props) ()
491 "Create a box of the same height as the space in the current font.
493 FIXME: is this working?
496 (let ((m (Text_item::interpret_markup paper props " ")))
497 (ly:stencil-set-extent! m X '(1000 . -1000))
500 (define number->mark-letter-vector (make-vector 25 #\A))
505 (if (= i (- (char->integer #\I) (char->integer #\A)))
507 (vector-set! number->mark-letter-vector j
508 (integer->char (+ i (char->integer #\A)))))
510 (define (number->markletter-string n)
511 "Double letters for big marks."
513 ((l (vector-length number->mark-letter-vector)))
516 (string-append (number->markletter-string (1- (quotient n l)))
517 (number->markletter-string (remainder n l)))
518 (make-string 1 (vector-ref number->mark-letter-vector n)))))
521 (def-markup-command (markletter paper props num) (integer?)
522 "Make a markup letter for @var{num}. The letters start with A to Z
523 (skipping I), and continues with double letters."
525 (Text_item::interpret_markup paper props (number->markletter-string num)))