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)
120 #`(line-width . ,(* width-ratio
121 (or (chain-assoc-get 'line-width props)
122 (ly:output-def-lookup layout 'line-width))))
125 #(define-markup-list-command (line-width-ratio-lines layout props width-ratio args)
126 (number? markup-list?)
127 (interpret-markup-list layout props
128 (make-override-lines-markup-list
129 (cons 'line-width (* width-ratio
130 (chain-assoc-get 'line-width props)))
133 #(define-markup-list-command (with-line-width-ratio layout props width-ratio args)
134 (number? markup-list?)
135 (let* ((line-width (chain-assoc-get 'line-width props))
136 (new-line-width (* width-ratio line-width))
137 (indent (* 0.5 (- line-width new-line-width)))
138 (stencils (interpret-markup-list layout
139 (cons `((line-width . ,new-line-width)) props)
141 (interpret-markup-list layout props
142 (map (lambda (stencil)
143 (markup #:hspace indent #:stencil stencil))
146 #(define-markup-command (force-line-width-ratio layout props ratio arg)
148 (let* ((new-line-width (* ratio (chain-assoc-get 'line-width props)))
149 (line-stencil (interpret-markup layout props
150 (markup #:override (cons 'line-width new-line-width)
154 (interval-length (ly:stencil-extent line-stencil X))))))
155 (interpret-markup layout props (markup #:concat (#:stencil line-stencil #:hspace gap)))))
157 #(define-markup-list-command (two-column-lines layout props col1 col2)
158 (markup-list? markup-list?)
159 (interpret-markup-list layout props
160 (make-column-lines-markup-list
162 (let map-on-lists ((col1 col1)
164 (if (and (null? col1) (null? col2))
166 (let ((line-col1 (if (null? col1) "" (car col1)))
167 (line-col2 (if (null? col2) "" (car col2)))
168 (rest-col1 (if (null? col1) '() (cdr col1)))
169 (rest-col2 (if (null? col2) '() (cdr col2))))
173 #:force-line-width-ratio 0.45 line-col1
175 #:force-line-width-ratio 0.45 line-col2
178 (map-on-lists rest-col1 rest-col2))))))))
180 #(define-markup-command (tacet-lyrics layout props score text)
181 (markup? markup-list?)
182 #:properties ((column-number 2))
186 \fontsize #-2 \override #`(column-number . ,column-number)
187 \column\page-columns {
188 \fontsize #2 \line { \hspace #10 Tacet $score }
194 #(define-markup-command (tacet layout props num) (number?)
195 (let ((score (ly:make-score
198 'elements (list (make-music
199 'MultiMeasureRestMusic
200 'duration (ly:make-duration 0 0 num))
203 'context-type 'Timing
207 'symbol 'whichBar)))))))
208 (ly:score-add-output-def! score #{ \layout {
215 \override StaffSymbol.staff-space = #(magstep -4)
219 \remove "Time_signature_engraver"
220 \remove "Clef_engraver"
221 \override StaffSymbol.line-count = #1
222 \override StaffSymbol.transparent = ##t
223 \override MultiMeasureRest #'expand-limit = #2
228 #{ \markup { \hspace #10 Tacet
229 \with-dimensions #'(-1 . 1) #'(-1 . 2) $(make-score-markup score) } #})))
231 #(define-markup-command (lyrics layout props text)
233 #:properties ((column-number 2))
237 \fontsize #-2 \override #`(column-number . ,column-number)
238 \column\page-columns { $text } } #}))
240 #(define-markup-list-command (indented-lines layout props indent args)
241 (number? markup-list?)
242 (let* ((new-line-width (- (chain-assoc-get 'line-width props) indent))
243 (lines (interpret-markup-list layout
244 (cons `((line-width . ,new-line-width)) props)
246 (interpret-markup-list layout props
248 (markup #:hspace indent #:stencil line))
251 #(define-markup-list-command (wordwrap-center-lines layout props args)
253 (map (lambda (stencil)
254 (interpret-markup layout props (markup #:fill-line (#:stencil stencil))))
255 (interpret-markup-list layout props (make-wordwrap-lines-markup-list args))))
257 #(define-markup-list-command (centered-lines layout props args)
259 (let ((baseline-skip (chain-assoc-get 'baseline-skip props)))
260 (space-lines baseline-skip
261 (interpret-markup-list layout props
262 (map (lambda (arg) (markup #:fill-line (arg)))
265 #(define-markup-list-command (fontsize-lines layout props increment args)
266 (number? markup-list?)
267 #:properties ((font-size 0)
270 (interpret-markup-list layout
271 (cons `((baseline-skip . ,(* baseline-skip (magstep increment)))
272 (word-space . ,(* word-space (magstep increment)))
273 (font-size . ,(+ font-size increment)))
277 #(define-markup-list-command (abs-fontsize-lines layout props size args)
278 (number? markup-list?)
279 (let* ((ref-size (ly:output-def-lookup layout 'text-font-size 12))
280 (text-props (list (ly:output-def-lookup layout 'text-font-defaults)))
281 (ref-word-space (chain-assoc-get 'word-space text-props 0.6))
282 (ref-baseline (chain-assoc-get 'baseline-skip text-props 3))
283 (magnification (/ size ref-size)))
284 (interpret-markup-list layout
285 (cons `((baseline-skip . ,(* magnification ref-baseline))
286 (word-space . ,(* magnification ref-word-space))
287 (font-size . ,(magnification->font-size magnification)))
291 #(define-markup-command (wordwrap-center layout props args) (markup-list?)
292 (interpret-markup layout props
294 (make-wordwrap-center-lines-markup-list args))))
296 #(define (page-ref-aux layout props label gauge next)
297 (let* ((gauge-stencil
298 (interpret-markup layout props
299 (make-concat-markup (list gauge next))))
300 (x-ext (ly:stencil-extent gauge-stencil X))
301 (y-ext (ly:stencil-extent gauge-stencil Y)))
303 `(delay-stencil-evaluation
304 ,(delay (ly:stencil-expr
305 (let* ((table (ly:output-def-lookup layout 'label-page-table))
306 (label-page (and (list? table) (assoc label table)))
307 (page-number (and label-page (cdr label-page)))
308 (page-markup (if page-number
309 (markup #:page-link page-number
310 #:concat ((format "~a" page-number)
312 (markup #:concat ("?" next))))
313 (page-stencil (interpret-markup layout props page-markup))
314 (gap (- (interval-length x-ext)
315 (interval-length (ly:stencil-extent page-stencil X)))))
316 (interpret-markup layout props
317 (markup #:concat (page-markup #:hspace gap)))))))
321 #(define-markup-command (page-refI layout props label next)
323 (page-ref-aux layout props label "0" next))
325 #(define-markup-command (page-refII layout props label next)
327 (page-ref-aux layout props label "00" next))
329 #(define-markup-command (page-refIII layout props label next)
331 (page-ref-aux layout props label "000" next))
333 #(define-markup-command (super layout props arg) (markup?)
334 (ly:stencil-translate-axis
337 (cons `((font-size . ,(- (chain-assoc-get 'font-size props 0) 3))) props)
339 (* 0.25 (chain-assoc-get 'baseline-skip props))
342 #(define-markup-list-command (paragraph layout props text) (markup-list?)
343 (let ((indentation (markup #:pad-to-box (cons 0 3) (cons 0 0) #:null)))
344 (interpret-markup-list layout props
345 (make-justified-lines-markup-list (cons indentation text)))))
347 #(define-markup-list-command (columns paper props text) (markup-list?)
348 (interpret-markup-list paper props
349 (make-column-lines-markup-list text)))
351 #(define-markup-command (separation-line layout props width) (number?)
352 (interpret-markup layout props
353 (markup #:fill-line (#:draw-line (cons (/ (* 20 width) (*staff-size*)) 0)))))
355 #(define-markup-command (sep layout props) ()
356 (interpret-markup layout props
357 (markup #:pad-around 1 #:fill-line (#:draw-line '(50 . 0)))))
359 #(define-markup-command (boxed-justify layout props text) (markup-list?)
360 (interpret-markup layout props
361 (make-override-markup '(box-padding . 1)
364 (make-justified-lines-markup-list text))))))
366 #(define-markup-command (after-system layout props arg) (markup?)
367 (let ((stencil (interpret-markup layout props arg)))
368 (ly:make-stencil (ly:stencil-expr (ly:stencil-aligned-to stencil Y DOWN))
369 (ly:stencil-extent stencil X)
372 %%% Guile does not deal with accented letters
373 #(use-modules (ice-9 regex))
374 %%;; actually defined below, in a closure
375 #(define-public string-upper-case #f)
376 #(define accented-char-upper-case? #f)
377 #(define accented-char-lower-case? #f)
379 %%;; an accented character is seen as two characters by guile
380 #(let ((lower-case-accented-string "éèêëáàâäíìîïóòôöúùûüçœæ")
381 (upper-case-accented-string "ÉÈÊËÁÀÂÄÍÌÎÏÓÒÔÖÚÙÛÜÇŒÆ"))
382 (define (group-by-2 chars result)
383 (if (or (null? chars) (null? (cdr chars)))
385 (group-by-2 (cddr chars)
386 (cons (string (car chars) (cadr chars))
388 (let ((lower-case-accented-chars
389 (group-by-2 (string->list lower-case-accented-string) (list)))
390 (upper-case-accented-chars
391 (group-by-2 (string->list upper-case-accented-string) (list))))
392 (set! string-upper-case
394 (define (replace-chars str froms tos)
397 (replace-chars (regexp-substitute/global #f (car froms) str
398 'pre (car tos) 'post)
401 (string-upcase (replace-chars str
402 lower-case-accented-chars
403 upper-case-accented-chars))))
404 (set! accented-char-upper-case?
405 (lambda (char1 char2)
406 (member (string char1 char2) upper-case-accented-chars string=?)))
407 (set! accented-char-lower-case?
408 (lambda (char1 char2)
409 (member (string char1 char2) lower-case-accented-chars string=?)))))
411 #(define-markup-command (smallCaps layout props text) (markup?)
412 "Turn @code{text}, which should be a string, to small caps.
414 \\markup \\small-caps \"Text between double quotes\"
416 (define (string-list->markup strings lower)
417 (let ((final-string (string-upper-case
418 (apply string-append (reverse strings)))))
420 (markup #:fontsize -2 final-string)
422 (define (make-small-caps rest-chars currents current-is-lower prev-result)
423 (if (null? rest-chars)
424 (make-concat-markup (reverse! (cons (string-list->markup
425 currents current-is-lower)
427 (let* ((ch1 (car rest-chars))
428 (ch2 (and (not (null? (cdr rest-chars))) (cadr rest-chars)))
429 (this-char-string (string ch1))
430 (is-lower (char-lower-case? ch1))
431 (next-rest-chars (cdr rest-chars)))
432 (cond ((and ch2 (accented-char-lower-case? ch1 ch2))
433 (set! this-char-string (string ch1 ch2))
435 (set! next-rest-chars (cddr rest-chars)))
436 ((and ch2 (accented-char-upper-case? ch1 ch2))
437 (set! this-char-string (string ch1 ch2))
439 (set! next-rest-chars (cddr rest-chars))))
440 (if (or (and current-is-lower is-lower)
441 (and (not current-is-lower) (not is-lower)))
442 (make-small-caps next-rest-chars
443 (cons this-char-string currents)
446 (make-small-caps next-rest-chars
447 (list this-char-string)
451 (cons (string-list->markup
452 currents current-is-lower)
454 (interpret-markup layout props
456 (make-small-caps (string->list text) (list) #f (list))
459 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
460 %%% Character lists, inline quoted scores, etc.
463 #(define-music-function (parser location bar-num) (number?)
464 #{ \override Score.BarNumber #'break-visibility = #'#(#f #f #t)
466 \set Score.currentBarNumber = #bar-num #})
469 \override Score.StaffSymbol #'staff-space = #(magstep -3)
470 \set Score . fontSize = #-3
471 \override BassFigure.font-size = #-1
474 quoteLayout = \layout {
477 \context { \Staff \remove "Time_signature_engraver" }
478 \context { \Voice \override Script #'avoid-slur = #'outside }
481 \override StaffGrouper.staff-staff-spacing.basic-distance = #1
482 \override BarNumber.break-visibility = #'#(#f #f #t)
486 tinyLayout = \layout {
489 \override StaffSymbol #'staff-space = #(magstep -2)
492 \context { \FiguredBass \override BassFigure.font-size = #-2 }
495 tinyQuoteLayout = \layout {
499 \override StaffSymbol #'staff-space = #(magstep -3)
502 \context { \FiguredBass \override BassFigure.font-size = #-3 }
505 quoteEmptyLayout = \layout {
508 \context { \Score skipBars = ##t }
511 \remove "Time_signature_engraver"
512 \remove "Clef_engraver"
513 \remove "Staff_symbol_engraver"
514 \override MultiMeasureRest #'expand-limit = #2
518 smallLayout = \layout {
520 \Staff fontSize = #-1
521 \override StaffSymbol.staff-space = #(magstep -1)
523 \context { \Lyrics fontSize = #-1 }
524 \context { \FiguredBass \override BassFigure.font-size = #-1 }
525 \context { \Voice \override Script.avoid-slur = #'outside }
526 \context { \CueVoice \override Script.avoid-slur = #'outside }
529 \override NonMusicalPaperColumn.line-break-permission = #'allow
530 \override NonMusicalPaperColumn.page-break-permission = #'allow
534 onlyNotesLayout = \layout {
538 \remove "Time_signature_engraver"
539 \remove "Clef_engraver"
540 \remove "Staff_symbol_engraver"
542 \context { \Score \remove "Bar_number_engraver" }
545 #(define-markup-command (character-ambitus layout props old-clef new-clef ambitus)
546 (string? string? ly:music?)
547 (let* ((low-pitch (ly:music-property
548 (car (ly:music-property ambitus 'elements))
550 (high-pitch (ly:music-property
551 (cadr (ly:music-property ambitus 'elements))
555 'elements (list (make-music
557 'duration (ly:make-duration 2 0 1 1)
561 'duration (ly:make-duration 2 0 1 1)
562 'pitch high-pitch))))
563 (score #{ \markup { \null \raise#1 \score {
566 \set Staff.forceClef = ##t \clef $new-clef s8
575 \override Clef #'full-size-change = ##t
576 \remove "Bar_engraver"
580 \remove "Stem_engraver"
584 \override StaffSymbol #'staff-space = #(magstep -2)
586 \override NonMusicalPaperColumn #'line-break-permission = ##f
590 (score-stencil (interpret-markup layout props score)))
591 (ly:make-stencil (ly:stencil-expr score-stencil)
592 (ly:stencil-extent score-stencil X)
595 #(define-markup-command (character-two-columns layout props col1 col2)
597 #:properties ((word-space 0.6)
598 (character-width-ratio 10/30)
599 (ambitus-width-ratio 4/30))
603 \override #`(character-width-ratio . ,character-width-ratio)
604 \override #`(ambitus-width-ratio . ,ambitus-width-ratio)
607 \override #`(word-space . ,word-space) $col1
609 \override #`(word-space . ,word-space) $col2
613 #(define-markup-command (character-three-columns layout props col1 col2 col3)
614 (markup? markup? markup?)
615 #:properties ((word-space 0.6))
618 (markup (#:concat (#:override `(word-space . ,word-space) col1
620 #:override `(word-space . ,word-space) col2
622 #:override `(word-space . ,word-space) col3)))))
624 #(define-markup-command (sline layout props args) (markup-list?)
625 (interpret-markup layout props
626 (make-line-markup (cons (make-hspace-markup 4) args))))
629 #(define-markup-command (verse layout props syllab-count words)
630 (number? markup-list?)
633 (if (< syllab-count 12)
634 (make-line-markup (cons (make-hspace-markup (* 1.5 (- 12 syllab-count)))
636 (make-line-markup words))))
641 footnote-auto-numbering = ##t
642 footnote-numbering-function =
644 (markup #:small #:box (number->string (+ 1 num))))
645 footnote-separator-markup = \markup\override #'(span-factor . 1/4) \draw-hline
646 footnote-padding = 2\mm
647 footnote-footer-padding = 1\mm
650 #(define (make-footnote-here-music offset note)
651 (make-music 'FootnoteEvent
652 'X-offset (car offset)
653 'Y-offset (cdr offset)
654 'automatically-numbered #t
655 'text (make-null-markup)
656 'footnote-text note))
658 #(define-music-function (parser this-location offset note)
659 (number-pair? markup?)
661 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
662 ^\markup\transparent\box "1" #})
665 #(define-music-function (parser this-location offset note)
666 (number-pair? markup?)
668 (if (symbol? (ly:get-option 'part))
669 (make-music 'Music 'void #t)
670 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
671 ^\markup\transparent\box "1" #}))
673 footnoteHereNoSpace =
674 #(define-music-function (parser this-location offset note)
675 (number-pair? markup?)
677 #{ <>-\tweak footnote-music #(make-footnote-here-music offset note)
682 #(define-music-function (parser this-location text)
685 \once\override TextSpanner.bound-details.left.stencil-align-dir-y = #CENTER
686 \once\override TextSpanner.bound-details.left.text =
687 \markup\whiteout { $text \hspace #1 }
688 \once\override TextSpanner.bound-details.left-broken.text = \markup\transparent t %##f