3

My issue

I have a lilypond snippet (i.e. some music staffs) embedded within a document containing text.

My question: How to make the snippet justified, i.e. that its size matches the \textwidth?

In other terms, how to make the blue lines match the red ones in following example:

MWE

My trials

Of course, I am not using the quote option of \lilypondfile. A similar question is reported in the lilypond mailing list, but the solution is to manually adjust the line-width that is imho not satisfactory.

I tried \lilypondfile[line-width=\linewidth] (and with \textwidth). I tried also to print the value of \linewidth ( i.e. to have in the .lytex document following line: \lipsum[1] \the\linewidth) and then report the value into the line-width option. But each time, the blue and red lines are still not matching.


MWE

The related MWE is:

  • lytex file

    \documentclass{scrartcl}
    
        \usepackage{lipsum}
    
    \begin{document}
    
        \lipsum[1]
        \lilypondfile[noindent]{myFile.ly}        
        \lipsum[2]
    
    \end{document}
    
  • The related myFile.ly

    \version "2.18.2"
    
    \paper {
      left-margin = 0
      indent = 0
    }
    
    %% MUSIQUE %%
    melodieRepeat =
        {
            \once \override Score.RehearsalMark.font-size = #2
            \override Score.BarNumber.break-visibility = ##(#f #f #f)
                 r4 e'8 e' e' e' f' g'
                 g' g' r g' g' g' f' e'
                 c'4 r16 c' c' c' c'8 c' d' e'
                 g' g' r4 r8 c'' a' f'
        }
    
    %% PAROLES %%
    
    mylyrics = 
        \lyricmode{
                Vers les Hom -- mes sans lu  --  | miè --  re, Al --  lez por -- ter la | paix, Et cette a -- mi -- tié qui é -- | 
                clair -- e, Por -- tez l'a -- 
        }
    
    %% PARTITION %%
    \score {
        \layout {
        indent = #0
        }
        \new ChoirStaff
        <<
            \new Voice = "melodie"
                <<
                \key c \major
                \time 4/4
                \clef treble
                \melodieRepeat
                >>
            \new Lyrics \lyricsto "melodie" {
                \mylyrics 
            }
        >>
    }
    
  • Compiling workflow

    I'm following this workflow.

ebosi
  • 11,692
  • Did you try indent = ##f for your .ly file? – Josh N. Dec 03 '15 at 17:10
  • Well, even with \layout { indent = #f left-margin = 0pt right-margin = 0pt ragged-right = #f check-consistency = #f } in my .ly file, the issue remains the same. (fyi, in my "real" document - and not the MWE - \lilypondfile[line-width=\linewidth] gives an error.) – ebosi Dec 04 '15 at 08:17

1 Answers1

2

It appears that lilypond-book explicitly adds a little bit of padding around examples (4mm at the moment), and lilypond adds it's own padding on the left-hand side for braces and line numbers. If you know that you won't be using braces, line numbers, or anything else to the left of the staff, you can try this (kind of hacky) solution.

In the preamble to your lytex document add the following:

\def\preLilyPondExample{\hspace*{-3mm}}
\newcommand{\betweenLilyPondSystem}[1]{\linebreak\hspace*{-3mm}}

and in the \paper block in myFile.ly add the line

line-width = #(+ line-width (* mm 4))

Like I said, this feels pretty hacky, but I think it gets pretty close to your desired appearance.

Ben
  • 195
  • "hacky" indeed, but it works! thx! – ebosi Jan 25 '16 at 10:13
  • questions: 1) why are you mentioning 4mm of padding, but remove only 3mm via \hspace ? 2) Where did you got the length of 4mm from? By measuring it, or in the documentation? – ebosi Jan 25 '16 at 10:15
  • 1
    If you look at the .ly files generated by lilypond-book, it adds 4mm of space by reducing the line-width by 1mm + 3mm in :

    line-width = #(- line-width (* mm 3.000000) (* mm 1)).

    And in looking into this issue, I came across the \hspace suggestion here:

    https://lists.gnu.org/archive/html/lilypond-user/2007-08/msg00427.html

    Since it seemed to work, I didn't look into it further, but I wasn't able to find any official documentation about it.

    – Ben Feb 02 '16 at 14:16