Three-sided box: Difference between revisions
Appearance
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series |
mNo edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
This example shows how to add a markup command to get a three sided box around some text (or other markup). | This example shows how to add a markup command to get a three-sided box around some text (or other markup). | ||
<lilypond version="2.24"> | <lilypond version="2.24"> | ||
% New command to add a three sided box, with sides north, west and south | % New command to add a three-sided box, with sides north, west, and south. | ||
% Based on the box-stencil command defined in scm/stencil.scm | % Based on the `box-stencil` command defined in `scm/stencil.scm`. | ||
% Note that ";;" is used to comment a line in Scheme | % Note that ";;" is used to comment a line in Scheme. | ||
#(define-public (NWS-box-stencil stencil thickness padding) | #(define-public (NWS-box-stencil stencil thickness padding) | ||
"Add a box around STENCIL, producing a new stencil." | "Add a box around STENCIL, producing a new stencil." | ||
| Line 18: | Line 18: | ||
stencil)) | stencil)) | ||
% The corresponding markup command, based on the \box command defined | % The corresponding markup command, based on the `\box` command defined | ||
% in scm/define-markup-commands.scm | % in `scm/define-markup-commands.scm`. | ||
#(define-markup-command (NWS-box layout props arg) (markup?) | #(define-markup-command (NWS-box layout props arg) (markup?) | ||
#:properties ((thickness 0.1) (font-size 0) (box-padding 0.2)) | #:properties ((thickness 0.1) (font-size 0) (box-padding 0.2)) | ||
"Draw a box round | "Draw a box round ARG. | ||
thickness and padding around the markup." | Look at THICKNESS, BOX-PADDING, and FONT-SIZE properties to determine | ||
line thickness and padding around the markup." | |||
(let ((pad (* (magstep font-size) box-padding)) | (let ((pad (* (magstep font-size) box-padding)) | ||
(m (interpret-markup layout props arg))) | (m (interpret-markup layout props arg))) | ||
(NWS-box-stencil m thickness pad))) | (NWS-box-stencil m thickness pad))) | ||
\relative c' { | \relative c' { | ||
| Line 37: | Line 37: | ||
</lilypond> | </lilypond> | ||
[[Category:Text]] | [[Category:Text]] | ||
[[Category:Scheme]] | [[Category:Scheme]] | ||
[[Category:Rhythms]] | [[Category:Rhythms]] | ||
[[Category:Included in the official documentation]] | [[Category:Included in the official documentation]] | ||
[[Category:Snippet]] | |||
Latest revision as of 19:22, 30 November 2025
This example shows how to add a markup command to get a three-sided box around some text (or other markup).
\version "2.24"
% New command to add a three-sided box, with sides north, west, and south.
% Based on the `box-stencil` command defined in `scm/stencil.scm`.
% Note that ";;" is used to comment a line in Scheme.
#(define-public (NWS-box-stencil stencil thickness padding)
"Add a box around STENCIL, producing a new stencil."
(let* ((x-ext (interval-widen (ly:stencil-extent stencil X) padding))
(y-ext (interval-widen (ly:stencil-extent stencil Y) padding))
(y-rule (make-filled-box-stencil (cons 0 thickness) y-ext))
(x-rule (make-filled-box-stencil
(interval-widen x-ext thickness) (cons 0 thickness))))
;; (set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule padding))
(set! stencil (ly:stencil-combine-at-edge stencil X LEFT y-rule padding))
(set! stencil (ly:stencil-combine-at-edge stencil Y UP x-rule 0.0))
(set! stencil (ly:stencil-combine-at-edge stencil Y DOWN x-rule 0.0))
stencil))
% The corresponding markup command, based on the `\box` command defined
% in `scm/define-markup-commands.scm`.
#(define-markup-command (NWS-box layout props arg) (markup?)
#:properties ((thickness 0.1) (font-size 0) (box-padding 0.2))
"Draw a box round ARG.
Look at THICKNESS, BOX-PADDING, and FONT-SIZE properties to determine
line thickness and padding around the markup."
(let ((pad (* (magstep font-size) box-padding))
(m (interpret-markup layout props arg)))
(NWS-box-stencil m thickness pad)))
\relative c' {
c1^\markup { \NWS-box ABCD }
c1^\markup { \NWS-box \note {4} #1.0 }
}