lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: horizontal line separator in column markup (as in fraction or polych


From: Thomas Morley
Subject: Re: horizontal line separator in column markup (as in fraction or polychord)
Date: Sun, 5 Feb 2012 13:55:19 +0100

Hi,

2012/2/3 Thomas Morley <address@hidden>:
> Hi,
>
> 2012/2/2 Xavier Scheuer <address@hidden>:
>> On 2 February 2012 22:23, Jean-Alexis Montignies <address@hidden> wrote:
>>> Hi,
>>>
>>> I'm trying to write a polychord markup that looks like a mathematical 
>>> fraction.
>>>
>>> May be I've overlooked something, but I didn't found a way to draw a
>>> horizontal line between to text lines of a column.
>>> I'm using:
>>>
>>> \markup {\override #`(direction . ,UP) \dir-column
>>>      { "C"
>>>        \draw-line #'(3 . 0)
>>>        "Db" }
>>> }
>>>
>>> But then I have too many vertical space between Db and the separator
>>> and I have to hardcode the length of the line.
>>>
>>> Any suggestion?
>>
>> Why not simply
>>
>>  \chords {
>>    c1:/des
>>  }
>>
>> ?
>>
>> Cheers,
>> Xavier
>>
>> --
>> Xavier Scheuer <address@hidden>
>>
>> _______________________________________________
>> lilypond-user mailing list
>> address@hidden
>> https://lists.gnu.org/mailman/listinfo/lilypond-user
>
> an idea:
>
> \version "2.14.2"
>
> #(define-markup-command (custom-column layout props args)
>  (markup-list?)
>   ;#:properties ((direction)
>   ;(baseline-skip))
>
>  (let* ((args-length-ls (sort (map (lambda (x)
>                        (interval-length
>                           (ly:stencil-extent
>                              (interpret-markup layout props x)
>                            X)))
>                        args)
>                          >))
>        ; baseline-skip is hard-coded!
>        ; if you change this don't forget to change 0.65
>        ; in: #:translate (cons 0 (* 0.65 baseline-skip))
>        (baseline-skip 1.2)
>        (ln-mrkp (markup #:translate (cons 0 (* 0.65 baseline-skip))
>                         #:draw-line (cons (car args-length-ls) 0)))
>        (new-args (list (car args) ln-mrkp (cadr args))))
>        ; direction is hard-coded!
>  (stack-lines -1 ;(if (number? direction) direction -1)
>               0.0
>               baseline-skip
>               (interpret-markup-list layout props new-args))))
>
> \markup {
>        \custom-column { "C" "Db" }
>        \custom-column { "Ees" "Disis" }
>        \custom-column { "a" "Whatsever" }
> }
>
> HTH,
>  Harm

further testing showed some problems, while changing fontsize and it
was limited to two elements of a markup-list.

I now come up with:

\version "2.14.2"

#(define (insert-elt l1 l2 elt)
 "Inserts a new element between every element of list l1
  and outputs this as new list l2.
  While starting, l2 is supposed to be '() "
  (set! l2 (reverse (append (list elt (car l1)) l2)))
  (if (= 1 (length (cdr l1)))
    (append l2 (last-pair l1))
    (insert-elt (cdr l1) (reverse l2) elt)))

#(define-markup-command (dir-column-line layout props direction args)
  (number? markup-list?)
  (let* ((args-length-ls (sort (map (lambda (x)
                        (interval-length
                           (ly:stencil-extent
                              (interpret-markup layout props x)
                            X)))
                        args)
                          >))
         ; baseline-skip is hard-coded!
         (baseline-skip 0.4)
         (ln-mrkp (markup #:draw-line (cons (car args-length-ls) 0)
                          #:vcenter
                          #:vspace 0.2))
         (new-args (insert-elt args '() ln-mrkp)))
  (stack-lines (if (number? direction) direction -1)
               0.0
               baseline-skip
               (interpret-markup-list layout props new-args))))

%------- test

text¹ = \markup {
                \dir-column-line #-1 {
                        \bold "/dir-column-line #-1:"
                        "stacking down"
                        elements
                        with
                        \fontsize #2 "arbitrary"
                        number
                        of
                        entities.
                }
}

text² = \markup \fontsize #-4 {
                \dir-column-line #1 {
                        \line { 1 reverse order! }
                        \line { 2 in }
                        \line { 3 stacked up }
                        \line { 4 are }
                        \line { 5 elements }
                        \line { 6 \italic various }
                        \line { \bold "/dir-column-line #1" }
                }
}

text³ = \markup \fontsize #4 {
                \dir-column-line #-1 {
                        \fontsize #3 \bold "Example:"
                        This
                        "is a"
                        clef
                        \concat { \musicglyph #"clefs.G" "," }
                        a
                        \with-color #red "treble-clef."
                }
}

%{
\markup {
        \fill-line {
                \null
                \text¹
                \text²
                \text³
                \null
        }
}

\markup \vspace #4
%}

\relative c' {
        \textLengthOn
        c1^\text¹
        d^\text²
        e^\text³
%        c1_\text¹
%        d_\text²
%        e_\text³
}



It's now possible to use an arbitrary number of elements.
The direction isn't hard-coded, so you have to specify it.
It should work with any additional fontsize-change.

Regards,
  Harm

P.S Some parts of the test are commented to receive a smaller image.

Attachment: dir-column-line.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]