1 %%% markup.ily -- generic markup commands
3 %%% Author: Nicolas Sceaux <nicolas.sceaux@free.fr>
8 %%% like \hspace, but for vertical space
10 %%% \smallCaps <string>
11 %%% like built-in \smallCaps, but dealing with accented letters
13 %%% \when-property <symbol> <markup>
14 %%% if symbol is find in properties, interpret the markup
15 %%% otherwise, return an empty stencil
17 %%% \line-width-ratio <ratio> <markup>
18 %%% interpret markup with a line-width set to current line-width * ratio
21 %%% build a copyight line, using the maintainer and copyrightYear
24 %%% \wordwrap-center <markup-list>
25 %%% like wordwrap, but center align the lines
27 %%% Markup lines commands
28 %%% =====================
29 %%% \wordwrap-center-lines <markup-list>
30 %%% make a markup list composed centered lines of text.
32 %%% Redefinition of \column, \justify and \wordwrap
33 %%% to fix spacing around blocks
34 #(define-markup-command (column layout props args) (markup-list?)
35 #:properties ((baseline-skip))
36 (let ((arg-stencils (interpret-markup-list layout props args)))
37 (stack-lines DOWN 0.0 0
38 (space-lines baseline-skip
39 (remove ly:stencil-empty? arg-stencils)))))
41 #(define-markup-command (justify layout props args)
43 #:properties ((baseline-skip)
44 wordwrap-internal-markup-list)
47 (space-lines baseline-skip
48 (wordwrap-internal-markup-list layout props #t args))))
50 #(define-markup-command (wordwrap layout props args)
52 #:properties ((baseline-skip)
53 wordwrap-internal-markup-list)
56 (space-lines baseline-skip
57 (wordwrap-internal-markup-list layout props #f args))))
62 #(define-markup-command (vspace layout props amount) (number?)
63 "This produces a invisible object taking vertical space."
64 (let ((amount (* amount 3.0)))
66 (ly:make-stencil "" (cons -1 1) (cons 0 amount))
67 (ly:make-stencil "" (cons -1 1) (cons amount amount)))))
69 #(define-markup-command (copyright layout props) ()
70 (let* ((maintainer (chain-assoc-get 'header:maintainer props))
71 (this-year (+ 1900 (tm:year (gmtime (current-time)))))
72 (year (string->number (or (chain-assoc-get 'header:copyrightYear props)
73 (number->string this-year)))))
74 (interpret-markup layout props
76 (if (= year this-year)
77 (format #f "~a" this-year)
78 (format #f "~a-~a" year this-year))
81 #(define-markup-command (today layout props) ()
82 (let ((today (gmtime (current-time))))
83 (interpret-markup layout props
85 (+ 1900 (tm:year today))
89 #(define-markup-command (today-french layout props) ()
90 (let* ((date (gmtime (current-time)))
91 (months '#("janvier" "février" "mars" "avril"
92 "mai" "juin" "juillet" "août"
93 "septembre" "octobre" "novembre"
95 (day (if (= (tm:mday date) 1)
96 (markup (#:concat ("1" #:super "er")))
97 (number->string (tm:mday date))))
98 (month (vector-ref months (tm:mon date)))
99 (year (number->string (+ 1900 (tm:year date)))))
101 layout props (markup day month year))))
103 #(define-markup-command (when-property layout props symbol markp) (symbol? markup?)
104 (if (chain-assoc-get symbol props)
105 (interpret-markup layout props markp)
106 (ly:make-stencil '() '(1 . -1) '(1 . -1))))
108 #(define-markup-command (apply-fromproperty layout props fn symbol)
110 (let ((m (chain-assoc-get symbol props)))
112 (interpret-markup layout props (fn m))
115 #(define-markup-command (line-width-ratio layout props width-ratio arg)
117 (interpret-markup layout props
118 (markup #:override (cons 'line-width (* width-ratio
119 (chain-assoc-get 'line-width props)))
122 #(define-markup-list-command (line-width-ratio-lines layout props width-ratio args)
123 (number? markup-list?)
124 (interpret-markup-list layout props
125 (make-override-lines-markup-list
126 (cons 'line-width (* width-ratio
127 (chain-assoc-get 'line-width props)))
130 #(define-markup-list-command (with-line-width-ratio layout props width-ratio args)
131 (number? markup-list?)
132 (let* ((line-width (chain-assoc-get 'line-width props))
133 (new-line-width (* width-ratio line-width))
134 (indent (* 0.5 (- line-width new-line-width)))
135 (stencils (interpret-markup-list layout
136 (cons `((line-width . ,new-line-width)) props)
138 (interpret-markup-list layout props
139 (map (lambda (stencil)
140 (markup #:hspace indent #:stencil stencil))
143 #(define-markup-command (force-line-width-ratio layout props ratio arg)
145 (let* ((new-line-width (* ratio (chain-assoc-get 'line-width props)))
146 (line-stencil (interpret-markup layout props
147 (markup #:override (cons 'line-width new-line-width)
151 (interval-length (ly:stencil-extent line-stencil X))))))
152 (interpret-markup layout props (markup #:concat (#:stencil line-stencil #:hspace gap)))))
154 #(define-markup-list-command (two-column-lines layout props col1 col2)
155 (markup-list? markup-list?)
156 (interpret-markup-list layout props
157 (make-column-lines-markup-list
159 (let map-on-lists ((col1 col1)
161 (if (and (null? col1) (null? col2))
163 (let ((line-col1 (if (null? col1) "" (car col1)))
164 (line-col2 (if (null? col2) "" (car col2)))
165 (rest-col1 (if (null? col1) '() (cdr col1)))
166 (rest-col2 (if (null? col2) '() (cdr col2))))
170 #:force-line-width-ratio 0.45 line-col1
172 #:force-line-width-ratio 0.45 line-col2
175 (map-on-lists rest-col1 rest-col2))))))))
177 #(define-markup-command (tacet-lyrics layout props score text)
178 (markup? markup-list?)
179 #:properties ((column-number 2))
183 \fontsize #-2 \override #`(column-number . ,column-number)
184 \column\page-columns {
185 \fontsize #2 \line { \hspace #10 Tacet $score }
191 #(define-markup-command (tacet layout props num) (number?)
192 (let ((score (ly:make-score
195 'elements (list (make-music
196 'MultiMeasureRestMusic
197 'duration (ly:make-duration 0 0 num))
200 'context-type 'Timing
204 'symbol 'whichBar)))))))
205 (ly:score-add-output-def! score #{ \layout {
208 \context { \Score skipBars = ##t }
211 \remove "Time_signature_engraver"
212 \remove "Clef_engraver"
213 \override StaffSymbol.line-count = #1
214 \override StaffSymbol.transparent = ##t
215 \override MultiMeasureRest #'expand-limit = #2
220 #{ \markup { \hspace #10 Tacet $(make-score-markup score) } #})))
222 #(define-markup-command (lyrics layout props text)
224 #:properties ((column-number 2))
228 \fontsize #-2 \override #`(column-number . ,column-number)
229 \column\page-columns { $text } } #}))
231 #(define-markup-list-command (indented-lines layout props indent args)
232 (number? markup-list?)
233 (let* ((new-line-width (- (chain-assoc-get 'line-width props) indent))
234 (lines (interpret-markup-list layout
235 (cons `((line-width . ,new-line-width)) props)
237 (interpret-markup-list layout props
239 (markup #:hspace indent #:stencil line))
242 #(define-markup-list-command (wordwrap-center-lines layout props args)
244 (map (lambda (stencil)
245 (interpret-markup layout props (markup #:fill-line (#:stencil stencil))))
246 (interpret-markup-list layout props (make-wordwrap-lines-markup-list args))))
248 #(define-markup-list-command (centered-lines layout props args)
250 (let ((baseline-skip (chain-assoc-get 'baseline-skip props)))
251 (space-lines baseline-skip
252 (interpret-markup-list layout props
253 (map (lambda (arg) (markup #:fill-line (arg)))
256 #(define-markup-list-command (fontsize-lines layout props increment args)
257 (number? markup-list?)
258 #:properties ((font-size 0)
261 (interpret-markup-list layout
262 (cons `((baseline-skip . ,(* baseline-skip (magstep increment)))
263 (word-space . ,(* word-space (magstep increment)))
264 (font-size . ,(+ font-size increment)))
268 #(define-markup-list-command (abs-fontsize-lines layout props size args)
269 (number? markup-list?)
270 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
271 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
272 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
273 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
274 (magnification (/ size ref-size)))
275 (interpret-markup-list layout
276 (cons `((baseline-skip . ,(* magnification ref-baseline))
277 (word-space . ,(* magnification ref-word-space))
278 (font-size . ,(magnification->font-size magnification)))
282 #(define-markup-command (wordwrap-center layout props args) (markup-list?)
283 (interpret-markup layout props
285 (make-wordwrap-center-lines-markup-list args))))
287 #(define (page-ref-aux layout props label gauge next)
288 (let* ((gauge-stencil
289 (interpret-markup layout props
290 (make-concat-markup (list gauge next))))
291 (x-ext (ly:stencil-extent gauge-stencil X))
292 (y-ext (ly:stencil-extent gauge-stencil Y)))
294 `(delay-stencil-evaluation
295 ,(delay (ly:stencil-expr
296 (let* ((table (ly:output-def-lookup layout 'label-page-table))
297 (label-page (and (list? table) (assoc label table)))
298 (page-number (and label-page (cdr label-page)))
299 (page-markup (if page-number
300 (markup #:page-link page-number
301 #:concat ((format "~a" page-number)
303 (markup #:concat ("?" next))))
304 (page-stencil (interpret-markup layout props page-markup))
305 (gap (- (interval-length x-ext)
306 (interval-length (ly:stencil-extent page-stencil X)))))
307 (interpret-markup layout props
308 (markup #:concat (page-markup #:hspace gap)))))))
312 #(define-markup-command (page-refI layout props label next)
314 (page-ref-aux layout props label "0" next))
316 #(define-markup-command (page-refII layout props label next)
318 (page-ref-aux layout props label "00" next))
320 #(define-markup-command (page-refIII layout props label next)
322 (page-ref-aux layout props label "000" next))
324 #(define-markup-command (super layout props arg) (markup?)
325 (ly:stencil-translate-axis
328 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
330 (* 0.25 (chain-assoc-get 'baseline-skip props))
333 #(define-markup-list-command (paragraph layout props text) (markup-list?)
334 (let ((indentation (markup #:pad-to-box (cons 0 3) (cons 0 0) #:null)))
335 (interpret-markup-list layout props
336 (make-justified-lines-markup-list (cons indentation text)))))
338 #(define-markup-list-command (columns paper props text) (markup-list?)
339 (interpret-markup-list paper props
340 (make-column-lines-markup-list text)))
342 #(define-markup-command (separation-line layout props width) (number?)
343 (interpret-markup layout props
344 (markup #:fill-line (#:draw-line (cons (/ (* 20 width) (*staff-size*)) 0)))))
346 #(define-markup-command (sep layout props) ()
347 (interpret-markup layout props
348 (markup #:pad-around 1 #:fill-line (#:draw-line '(50 . 0)))))
350 #(define-markup-command (boxed-justify layout props text) (markup-list?)
351 (interpret-markup layout props
352 (make-override-markup '(box-padding . 1)
355 (make-justified-lines-markup-list text))))))
357 #(define-markup-command (after-system layout props arg) (markup?)
358 (let ((stencil (interpret-markup layout props arg)))
359 (ly:make-stencil (ly:stencil-expr (ly:stencil-aligned-to stencil Y DOWN))
360 (ly:stencil-extent stencil X)
363 %%% Guile does not deal with accented letters
364 #(use-modules (ice-9 regex))
365 %%;; actually defined below, in a closure
366 #(define-public string-upper-case #f)
367 #(define accented-char-upper-case? #f)
368 #(define accented-char-lower-case? #f)
370 %%;; an accented character is seen as two characters by guile
371 #(let ((lower-case-accented-string "éèêëáàâäíìîïóòôöúùûüçœæ")
372 (upper-case-accented-string "ÉÈÊËÁÀÂÄÍÌÎÏÓÒÔÖÚÙÛÜÇŒÆ"))
373 (define (group-by-2 chars result)
374 (if (or (null? chars) (null? (cdr chars)))
376 (group-by-2 (cddr chars)
377 (cons (string (car chars) (cadr chars))
379 (let ((lower-case-accented-chars
380 (group-by-2 (string->list lower-case-accented-string) (list)))
381 (upper-case-accented-chars
382 (group-by-2 (string->list upper-case-accented-string) (list))))
383 (set! string-upper-case
385 (define (replace-chars str froms tos)
388 (replace-chars (regexp-substitute/global #f (car froms) str
389 'pre (car tos) 'post)
392 (string-upcase (replace-chars str
393 lower-case-accented-chars
394 upper-case-accented-chars))))
395 (set! accented-char-upper-case?
396 (lambda (char1 char2)
397 (member (string char1 char2) upper-case-accented-chars string=?)))
398 (set! accented-char-lower-case?
399 (lambda (char1 char2)
400 (member (string char1 char2) lower-case-accented-chars string=?)))))
402 #(define-markup-command (smallCaps layout props text) (markup?)
403 "Turn @code{text}, which should be a string, to small caps.
405 \\markup \\small-caps \"Text between double quotes\"
407 (define (string-list->markup strings lower)
408 (let ((final-string (string-upper-case
409 (apply string-append (reverse strings)))))
411 (markup #:fontsize -2 final-string)
413 (define (make-small-caps rest-chars currents current-is-lower prev-result)
414 (if (null? rest-chars)
415 (make-concat-markup (reverse! (cons (string-list->markup
416 currents current-is-lower)
418 (let* ((ch1 (car rest-chars))
419 (ch2 (and (not (null? (cdr rest-chars))) (cadr rest-chars)))
420 (this-char-string (string ch1))
421 (is-lower (char-lower-case? ch1))
422 (next-rest-chars (cdr rest-chars)))
423 (cond ((and ch2 (accented-char-lower-case? ch1 ch2))
424 (set! this-char-string (string ch1 ch2))
426 (set! next-rest-chars (cddr rest-chars)))
427 ((and ch2 (accented-char-upper-case? ch1 ch2))
428 (set! this-char-string (string ch1 ch2))
430 (set! next-rest-chars (cddr rest-chars))))
431 (if (or (and current-is-lower is-lower)
432 (and (not current-is-lower) (not is-lower)))
433 (make-small-caps next-rest-chars
434 (cons this-char-string currents)
437 (make-small-caps next-rest-chars
438 (list this-char-string)
442 (cons (string-list->markup
443 currents current-is-lower)
445 (interpret-markup layout props
447 (make-small-caps (string->list text) (list) #f (list))
450 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
451 %%% Character lists, inline quoted scores, etc.
454 #(define-music-function (parser location bar-num) (number?)
455 #{ \override Score.BarNumber #'break-visibility = #'#(#f #f #t)
457 \set Score.currentBarNumber = #bar-num #})
460 \override Score.StaffSymbol #'staff-space = #(magstep -3)
461 \set Score . fontSize = #-3
464 quoteLayout = \layout {
467 \context { \Staff \remove "Time_signature_engraver" }
468 \context { \Voice \override Script #'avoid-slur = #'outside }
471 \override StaffGrouper.staff-staff-spacing.basic-distance = #1
472 \override BarNumber.break-visibility = #'#(#f #f #t)
476 tinyLayout = \layout {
479 \override StaffSymbol #'staff-space = #(magstep -2)
482 \context { \FiguredBass \override BassFigure.font-size = #-2 }
485 tinyQuoteLayout = \layout {
489 \override StaffSymbol #'staff-space = #(magstep -3)
492 \context { \FiguredBass \override BassFigure.font-size = #-3 }
495 quoteEmptyLayout = \layout {
498 \context { \Score skipBars = ##t }
501 \remove "Time_signature_engraver"
502 \remove "Clef_engraver"
503 \remove "Staff_symbol_engraver"
504 \override MultiMeasureRest #'expand-limit = #2
508 smallLayout = \layout {
510 \Staff fontSize = #-1
511 \override StaffSymbol.staff-space = #(magstep -1)
513 \context { \Lyrics fontSize = #-1 }
514 \context { \FiguredBass \override BassFigure.font-size = #-1 }
515 \context { \Voice \override Script.avoid-slur = #'outside }
516 \context { \CueVoice \override Script.avoid-slur = #'outside }
519 \override NonMusicalPaperColumn.line-break-permission = #'allow
520 \override NonMusicalPaperColumn.page-break-permission = #'allow
524 onlyNotesLayout = \layout {
528 \remove "Time_signature_engraver"
529 \remove "Clef_engraver"
530 \remove "Staff_symbol_engraver"
532 \context { \Score \remove "Bar_number_engraver" }
535 characterLayout = \layout {
537 line-width = #(if (eqv? #t (ly:get-option 'ancient-style))
543 \override Clef #'full-size-change = ##t
544 \remove "Bar_engraver"
548 \remove "Stem_engraver"
553 #(define-music-function (parser location clef1 clef2 low-note high-note)
554 (string? string? ly:music? ly:music?)
555 (let* ((low-pitch (ly:music-property low-note 'pitch))
556 (high-pitch (ly:music-property high-note 'pitch))
559 'elements (list (make-music
561 'duration (ly:make-duration 2 0 1 1)
565 'duration (ly:make-duration 2 0 1 1)
566 'pitch high-pitch)))))
567 (if (eqv? #t (ly:get-option 'ancient-style))
568 #{ \new Staff { \clef $clef1 $chord } #}
571 \set Staff.forceClef = ##t
572 \clef $clef2 s8. $chord s2
576 #(define-markup-command (character-ambitus layout props name ambitus)
578 #:properties ((character-width-ratio 16/20)
579 (ambitus-width-ratio 3/20))
583 (interpret-markup layout props
585 #:force-line-width-ratio ambitus-width-ratio
586 #:vcenter #:fill-line (#:null #:left-align ambitus)
588 #:force-line-width-ratio character-width-ratio
589 #:vcenter #:smallCaps name)))))
591 #(define-markup-command (character-two-columns layout props col1 col2)
593 #:properties ((word-space 0.6)
594 (character-width-ratio 10/30)
595 (ambitus-width-ratio 4/30))
599 \override #`(character-width-ratio . ,character-width-ratio)
600 \override #`(ambitus-width-ratio . ,ambitus-width-ratio)
603 \override #`(word-space . ,word-space) $col1
605 \override #`(word-space . ,word-space) $col2
609 #(define-markup-command (character-three-columns layout props col1 col2 col3)
610 (markup? markup? markup?)
611 #:properties ((word-space 0.6))
614 (markup (#:concat (#:override `(word-space . ,word-space) col1
616 #:override `(word-space . ,word-space) col2
618 #:override `(word-space . ,word-space) col3)))))
620 #(define-markup-command (sline layout props args) (markup-list?)
621 (interpret-markup layout props
622 (make-line-markup (cons (make-hspace-markup 4) args))))
625 #(define-markup-command (verse layout props syllab-count words)
626 (number? markup-list?)
629 (if (< syllab-count 12)
630 (make-line-markup (cons (make-hspace-markup (* 1.5 (- 12 syllab-count)))
632 (make-line-markup words))))
637 footnote-auto-numbering = ##t
638 footnote-numbering-function =
640 (markup #:small #:box (number->string (+ 1 num))))
641 footnote-separator-markup = \markup\override #'(span-factor . 1/4) \draw-hline
642 footnote-padding = 2\mm
643 footnote-footer-padding = 1\mm
646 #(define (make-footnote-here-music offset note)
647 (make-music 'FootnoteEvent
648 'X-offset (car offset)
649 'Y-offset (cdr offset)
650 'automatically-numbered #t
651 'text (make-null-markup)
652 'footnote-text note))
654 #(define-music-function (parser this-location offset note)
655 (number-pair? markup?)
657 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
658 ^\markup\transparent\box "1" #})
661 #(define-music-function (parser this-location offset note)
662 (number-pair? markup?)
664 (if (symbol? (ly:get-option 'part))
665 (make-music 'Music 'void #t)
666 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
667 ^\markup\transparent\box "1" #}))
669 footnoteHereNoSpace =
670 #(define-music-function (parser this-location offset note)
671 (number-pair? markup?)
673 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
678 #(define-music-function (parser this-location text)
681 \once\override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER
682 \once\override TextSpanner.bound-details.left.text =
683 \markup\whiteout { $text \hspace #1 }
684 \once\override TextSpanner.bound-details.left-broken.text = \markup\transparent t %##f