Nesting paper blocks

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Nesting paper blocks

Peter Crighton
Hello all,

I have my paper variables split up across separate files. Depending on the project I am working on, I need to include several of them. paperGlobal is always included, paperSize depends on the paper size I want to produce, and paperCategory depends on what type of project I am working on. I can use paperGlobal from inside paperSizeX, but to allow for flexibility it is not possible (or at least desirable) to nest them further and use paperSizeX inside of paperCategoryX.
See the commented line below for what I am trying to achieve, which is not possible. Is there any way to inject the content of a variable directly into the paper block like I am trying to do there?

\version "2.20.0"

paperGlobal = \paper {
  indent = 0
}

paperSizeOne = \paper {
  \paperGlobal
  line-width = 10 \cm
}

paperCategoryThree = \paper {
  system-system-spacing.basic-distance = 30
}

\paper {
  \paperSizeOne
  % \paperCategoryThree
}

\relative c' {
  c1 \break
  c1
}


Thanks,
Peter

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de
Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Kevin Barry
Hi Peter,

I accomplish something similar by putting paper definitions into
various .ily files. Then just include the ones I want with \include.
It seems it's OK to have multiple \paper blocks as a result of many
\includes. Have you tried that?

Kevin

On Thu, 19 Mar 2020 at 17:45, Peter Crighton <[hidden email]> wrote:

>
> Hello all,
>
> I have my paper variables split up across separate files. Depending on the project I am working on, I need to include several of them. paperGlobal is always included, paperSize depends on the paper size I want to produce, and paperCategory depends on what type of project I am working on. I can use paperGlobal from inside paperSizeX, but to allow for flexibility it is not possible (or at least desirable) to nest them further and use paperSizeX inside of paperCategoryX.
> See the commented line below for what I am trying to achieve, which is not possible. Is there any way to inject the content of a variable directly into the paper block like I am trying to do there?
>
> \version "2.20.0"
>
> paperGlobal = \paper {
>   indent = 0
> }
>
> paperSizeOne = \paper {
>   \paperGlobal
>   line-width = 10 \cm
> }
>
> paperCategoryThree = \paper {
>   system-system-spacing.basic-distance = 30
> }
>
> \paper {
>   \paperSizeOne
>   % \paperCategoryThree
> }
>
> \relative c' {
>   c1 \break
>   c1
> }
>
> Thanks,
> Peter
>
> --
> Peter Crighton | Musician & Music Engraver based in Mainz, Germany
> http://www.petercrighton.de

Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Knute Snortum
In reply to this post by Peter Crighton
Just so I am clear, you don't want to do something like this:

\version "2.20.0"

paperGlobal = \paper {
  indent = 0
}

paperGlobalLine = \paper {
  \paperGlobal
  line-width = 10 \cm
}

paperGlobalLineCategory = \paper {
  paperGlobalLine
  system-system-spacing.basic-distance = 30
}

\paper {
  \paperGlobalLineCategory
}

\relative c' {
  c1 \break
  c1
}


---
Knute Snortum
(via Gmail)


On Thu, Mar 19, 2020 at 10:44 AM Peter Crighton <[hidden email]> wrote:
Hello all,

I have my paper variables split up across separate files. Depending on the project I am working on, I need to include several of them. paperGlobal is always included, paperSize depends on the paper size I want to produce, and paperCategory depends on what type of project I am working on. I can use paperGlobal from inside paperSizeX, but to allow for flexibility it is not possible (or at least desirable) to nest them further and use paperSizeX inside of paperCategoryX.
See the commented line below for what I am trying to achieve, which is not possible. Is there any way to inject the content of a variable directly into the paper block like I am trying to do there?

\version "2.20.0"

paperGlobal = \paper {
  indent = 0
}

paperSizeOne = \paper {
  \paperGlobal
  line-width = 10 \cm
}

paperCategoryThree = \paper {
  system-system-spacing.basic-distance = 30
}

\paper {
  \paperSizeOne
  % \paperCategoryThree
}

\relative c' {
  c1 \break
  c1
}


Thanks,
Peter

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de
Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Peter Crighton
Let me better explain my file structure, which looks something like this with each .ily file prodviding a variable that is named after the file it is in:

|-- editions
|   |-- categoryOne.ily
|   |-- categoryTwo.ily
|   |-- categoryThree.ily
|-- includes
|   |-- paperGlobal.ily
|   |-- paperSize
|   |-- |-- paperSizeOne.ily
|   |-- |-- paperSizeTwo.ily
|   |-- |-- paperSizeThree.ily
|   |-- paperCategory
|   |-- |-- paperCategoryOne.ily
|   |-- |-- paperCategoryTwo.ily
|   |-- |-- paperCategoryThree.ily

The score.ly could look like:

\version "2.20.0"
\include "editions/categoryOne.ily"
\include "editions/categoryTwo.ily"
\include "includes/paperGlobal.ily"
\include "includes/paperSize/paperSizeTwo.ily"
\include "includes/paperSize/paperSizeThree.ily"
\include "includes/paperCategory/paperCategoryOne.ily"
\include "includes/paperCategory/paperCategoryTwo.ily"

\book {
  \score {
    \categoryOne
  }
  \paper {
    % including these three variables does not work, but I need their contents all combined
    \paperGlobal
    \paperSizeTwo
    \paperCategoryOne
  }
}

\book {
  \score {
    \categoryOne
  }
  \paper {
    % different paper size for this edition
    \paperGlobal
    \paperSizeThree
    \paperCategoryOne
  }
}

\book {
  \score {
    \categoryTwo
  }
  \paper {
    % different category for this edition
    \paperGlobal
    \paperSizeThree
    \paperCategoryTwo
  }
}

With categories being different types of scores I want to do for the same song (namely music sheets with all the music, including notes, chords and lyrics; chord sheets with only chord symbols; and lyric sheets with just lyrics and chords).

So I need to be flexible with what paper variables I choose for each book. I can include just those that I need, but I still need to access a combination of them. That’s why chaining them all together does not work. \paperCategoryOne in one case would need to include \paperSizeOne, but in another case \paperSizeTwo. \paperGlobal needs to be included always, which is no problem; I can just include that into all the \paperSize variables, for example.

So far, all the \paperX variables are \paper blocks in themselves. Ideally, there would be a way to just inject the literal content of a variable inside a paper block, so this would work:

someVariable = {
  indent = 0
}
\paper {
  \someVariable
}

But I don’t know if that’s possible. Maybe all it needs is some other syntax around the content of someVariable, other than curly braces, or it is possible with some Scheme magic, but I’m out of ideas.

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de


On Thu, 19 Mar 2020 at 22:29, Kevin Barry <[hidden email]> wrote:
Hi Peter,

I accomplish something similar by putting paper definitions into
various .ily files. Then just include the ones I want with \include.
It seems it's OK to have multiple \paper blocks as a result of many
\includes. Have you tried that?

Kevin

 
On Thu, 19 Mar 2020 at 22:30, Knute Snortum <[hidden email]> wrote:
Just so I am clear, you don't want to do something like this:

\version "2.20.0"

paperGlobal = \paper {
  indent = 0
}

paperGlobalLine = \paper {
  \paperGlobal
  line-width = 10 \cm
}

paperGlobalLineCategory = \paper {
  paperGlobalLine
  system-system-spacing.basic-distance = 30
}

\paper {
  \paperGlobalLineCategory
}

\relative c' {
  c1 \break
  c1
}


---
Knute Snortum
(via Gmail)


On Thu, Mar 19, 2020 at 10:44 AM Peter Crighton <[hidden email]> wrote:
Hello all,

I have my paper variables split up across separate files. Depending on the project I am working on, I need to include several of them. paperGlobal is always included, paperSize depends on the paper size I want to produce, and paperCategory depends on what type of project I am working on. I can use paperGlobal from inside paperSizeX, but to allow for flexibility it is not possible (or at least desirable) to nest them further and use paperSizeX inside of paperCategoryX.
See the commented line below for what I am trying to achieve, which is not possible. Is there any way to inject the content of a variable directly into the paper block like I am trying to do there?

\version "2.20.0"

paperGlobal = \paper {
  indent = 0
}

paperSizeOne = \paper {
  \paperGlobal
  line-width = 10 \cm
}

paperCategoryThree = \paper {
  system-system-spacing.basic-distance = 30
}

\paper {
  \paperSizeOne
  % \paperCategoryThree
}

\relative c' {
  c1 \break
  c1
}


Thanks,
Peter

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de
Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

David Wright
On Fri 20 Mar 2020 at 12:50:23 (+0100), Peter Crighton wrote:

> So I need to be flexible with what paper variables I choose for each book.
> I can include just those that I need, but I still need to access a
> combination of them. That’s why chaining them all together does not work.
> \paperCategoryOne in one case would need to include \paperSizeOne, but in
> another case \paperSizeTwo. \paperGlobal needs to be included always, which
> is no problem; I can just include that into all the \paperSize variables,
> for example.
>
> So far, all the \paperX variables are \paper blocks in themselves. Ideally,
> there would be a way to just inject the literal content of a variable
> inside a paper block, so this would work:
>
> someVariable = {
>   indent = 0
> }
> \paper {
>   \someVariable
> }
>
> But I don’t know if that’s possible. Maybe all it needs is some other
> syntax around the content of someVariable, other than curly braces, or it
> is possible with some Scheme magic, but I’m out of ideas.

To tackle a problem like this, I'd start from the source file
…/lilypond/usr/share/lilypond/current/ly/paper-defaults-init.ly
and build a generalised \paper file with all the variables you use
within it. All the literals (like 0, 10, 30, …) would be in a form
suitable for substitution by whatever method you choose.

For a shell "here-document", that would be shell variables, like
$Indent, $Linewidth, etc. If substitution was done with a stream
editor, or a scripting language like Python, you could choose
any strings that don't otherwise occur, such as %%%INDENT%%%, etc.

So you perform the substitution by any means you like, producing
a single, ephemeral paper.ily file which you include in your LP
source file, compile with LP, and throw away.

> With categories being different types of scores I want to do for the same
> song (namely music sheets with all the music, including notes, chords and
> lyrics; chord sheets with only chord symbols; and lyric sheets with just
> lyrics and chords).

As you're now running LP with a script, your script(s) could
automatically build several paper.ly files in turn, and rerun
LP to produce different formats.

You can extend this in any way you like, dealing with other parts
of the LP source that might need to be altered. For example, I have
a script that typesets psalms, and it modifies the source files of
the Anglican chants (which always contain a   \transpose f f   line),
transposing them into mutually compatible keys before compiling them
into a document for that particular church service.

IOW, use a scripting language to script, and LP to typeset music.

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Peter Crighton
On Fri, 20 Mar 2020 at 15:22, David Wright <[hidden email]> wrote:
On Fri 20 Mar 2020 at 12:50:23 (+0100), Peter Crighton wrote:

> So I need to be flexible with what paper variables I choose for each book.
> I can include just those that I need, but I still need to access a
> combination of them. That’s why chaining them all together does not work.
> \paperCategoryOne in one case would need to include \paperSizeOne, but in
> another case \paperSizeTwo. \paperGlobal needs to be included always, which
> is no problem; I can just include that into all the \paperSize variables,
> for example.
>
> So far, all the \paperX variables are \paper blocks in themselves. Ideally,
> there would be a way to just inject the literal content of a variable
> inside a paper block, so this would work:
>
> someVariable = {
>   indent = 0
> }
> \paper {
>   \someVariable
> }
>
> But I don’t know if that’s possible. Maybe all it needs is some other
> syntax around the content of someVariable, other than curly braces, or it
> is possible with some Scheme magic, but I’m out of ideas.

To tackle a problem like this, I'd start from the source file
…/lilypond/usr/share/lilypond/current/ly/paper-defaults-init.ly
and build a generalised \paper file with all the variables you use
within it. All the literals (like 0, 10, 30, …) would be in a form
suitable for substitution by whatever method you choose.

For a shell "here-document", that would be shell variables, like
$Indent, $Linewidth, etc. If substitution was done with a stream
editor, or a scripting language like Python, you could choose
any strings that don't otherwise occur, such as %%%INDENT%%%, etc.

So you perform the substitution by any means you like, producing
a single, ephemeral paper.ily file which you include in your LP
source file, compile with LP, and throw away.

Sounds like a good approach. I was meaning to brush up on my Python anyway.
 
> With categories being different types of scores I want to do for the same
> song (namely music sheets with all the music, including notes, chords and
> lyrics; chord sheets with only chord symbols; and lyric sheets with just
> lyrics and chords).

As you're now running LP with a script, your script(s) could
automatically build several paper.ly files in turn, and rerun
LP to produce different formats.

You can extend this in any way you like, dealing with other parts
of the LP source that might need to be altered. For example, I have
a script that typesets psalms, and it modifies the source files of
the Anglican chants (which always contain a   \transpose f f   line),
transposing them into mutually compatible keys before compiling them
into a document for that particular church service.

I haven’t run LilyPond with scripts before. If there’s any documentation or code examples I should look at, I’d appreciate being pointed in the right direction.
 
IOW, use a scripting language to script, and LP to typeset music.

Sound advice. 

Thanks,
Peter

--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de
Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Timothy Lanfear
On 20/03/2020 16:17, Peter Crighton wrote:

> Sounds like a good approach. I was meaning to brush up on my Python
> anyway.
>
>     > With categories being different types of scores I want to do for
>     the same
>     > song (namely music sheets with all the music, including notes,
>     chords and
>     > lyrics; chord sheets with only chord symbols; and lyric sheets
>     with just
>     > lyrics and chords).
>
>     As you're now running LP with a script, your script(s) could
>     automatically build several paper.ly <http://paper.ly> files in
>     turn, and rerun
>     LP to produce different formats.
>
>     You can extend this in any way you like, dealing with other parts
>     of the LP source that might need to be altered. For example, I have
>     a script that typesets psalms, and it modifies the source files of
>     the Anglican chants (which always contain a   \transpose f f   line),
>     transposing them into mutually compatible keys before compiling them
>     into a document for that particular church service.
>
>
> I haven’t run LilyPond with scripts before. If there’s any
> documentation or code examples I should look at, I’d appreciate being
> pointed in the right direction.
>
>     IOW, use a scripting language to script, and LP to typeset music.
>
>
> Sound advice.
>
On the other hand, does an approach like this help?

\version "2.20.0"

basicdistance = #(define-scheme-function (n) (integer?)
   #{ \paper { system-system-spacing.basic-distance = #n } #})

linewidth = #(define-scheme-function (n) (integer?)
   #{ \paper { line-width = #(ly:cm n) } #})

\paper {
   indent = 0
}

\linewidth 10
\basicdistance 30
\new Staff {
   \relative c' {
     c1 \break
     c1
   }
}



--
Timothy Lanfear, Bristol, UK.


Timothy Lanfear, Bristol, UK.
Reply | Threaded
Open this post in threaded view
|

Re: Nesting paper blocks

Peter Crighton
On Fri, 20 Mar 2020 at 23:04, Timothy Lanfear <[hidden email]> wrote:
On 20/03/2020 16:17, Peter Crighton wrote:
> I haven’t run LilyPond with scripts before. If there’s any
> documentation or code examples I should look at, I’d appreciate being
> pointed in the right direction.
>
>     IOW, use a scripting language to script, and LP to typeset music.
>
>
> Sound advice.
>
On the other hand, does an approach like this help?

\version "2.20.0"

basicdistance = #(define-scheme-function (n) (integer?)
   #{ \paper { system-system-spacing.basic-distance = #n } #})

linewidth = #(define-scheme-function (n) (integer?)
   #{ \paper { line-width = #(ly:cm n) } #})

\paper {
   indent = 0
}

\linewidth 10
\basicdistance 30
\new Staff {
   \relative c' {
     c1 \break
     c1
   }
}

Actually, what Kevin wrote earlier works for me, contrary to what I thought at first.

On Thu, 19 Mar 2020 at 22:29, Kevin Barry <[hidden email]> wrote:
I accomplish something similar by putting paper definitions into
various .ily files. Then just include the ones I want with \include.
It seems it's OK to have multiple \paper blocks as a result of many
\includes. Have you tried that?

I think when I first tried it, in the included files I still had variables defined as a paper block and not _just_ the paper block inside them. Something like this works well:

\book {
  \score { … }
  \include "paperI.ily"
  \include "paperII.ily"
  \include "paperIII.ily"
}

Where the included paper files are just a paper block:

\paper {
  …
}

So, thanks all around! I still probably will look into the script thing in the future, that seems handy for producing several PDFs from the same source.
 
--
Peter Crighton | Musician & Music Engraver based in Mainz, Germany
http://www.petercrighton.de