Make TOC entries available to LaTeX

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

Make TOC entries available to LaTeX

Urs Liska-3

Hi all,

I'm preparing an automated edition process using LuaLaTeX, Pandoc and LilyPond.

After some experimentation I have come to the conclusion that I'll have to insert the multi-movement score as a single PDF created by LilyPond (but through lyluatex to make use of caching and the layout mechanics).

I first had used lyluatex's facility to include the score's system by system and print all the titles with LaTeX, but this didn't work out - for the first time I realized that lilypond-book-preamble.ly makes the vertical staff-staff spacing as tight as possible, which often makes the page layout pretty bad. Creating the movements separately is not an option either because not all movements will start on a new page.

So now I have included a multi-movement score in the LaTeX document and don't know how to add TOC entries (in LaTeX) for the movements. I can see two possible ways, but don't know if they are really possible and if so how to approach them:

  • Is it possible to insert something in the PDF output that LaTeX can pick up as TOC entries?
    (actually I doubt this is possible, but since it would be the easiest way I thought I'd ask anyway)
  • Can I reliably retrieve the current page number of a given score's title block?
    With that information I could write them to a log file and read that later in LaTeX.

TIA
Urs

PS: I don't know if it matters but the file is produced using ly:book-process etc.


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Jan-Peter Voigt
Hi Urs, I don't know either how to extract the toc from the PDF. But it should be easy to write the toc into some text file. Recently I did something similar to provide that info to those who compiled a book in inDesign.
I will extract it later, when I am back at my Workstation.

Jan-Peter

Am 19. April 2018 16:19:49 MESZ schrieb Urs Liska <[hidden email]>:

Hi all,

I'm preparing an automated edition process using LuaLaTeX, Pandoc and LilyPond.

After some experimentation I have come to the conclusion that I'll have to insert the multi-movement score as a single PDF created by LilyPond (but through lyluatex to make use of caching and the layout mechanics).

I first had used lyluatex's facility to include the score's system by system and print all the titles with LaTeX, but this didn't work out - for the first time I realized that lilypond-book-preamble.ly makes the vertical staff-staff spacing as tight as possible, which often makes the page layout pretty bad. Creating the movements separately is not an option either because not all movements will start on a new page.

So now I have included a multi-movement score in the LaTeX document and don't know how to add TOC entries (in LaTeX) for the movements. I can see two possible ways, but don't know if they are really possible and if so how to approach them:

  • Is it possible to insert something in the PDF output that LaTeX can pick up as TOC entries?
    (actually I doubt this is possible, but since it would be the easiest way I thought I'd ask anyway)
  • Can I reliably retrieve the current page number of a given score's title block?
    With that information I could write them to a log file and read that later in LaTeX.

TIA
Urs

PS: I don't know if it matters but the file is produced using ly:book-process etc.


--
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Thomas Morley-2
In reply to this post by Urs Liska-3
2018-04-19 16:19 GMT+02:00 Urs Liska <[hidden email]>:

> Hi all,
>
> I'm preparing an automated edition process using LuaLaTeX, Pandoc and
> LilyPond.
>
> After some experimentation I have come to the conclusion that I'll have to
> insert the multi-movement score as a single PDF created by LilyPond (but
> through lyluatex to make use of caching and the layout mechanics).
>
> I first had used lyluatex's facility to include the score's system by system
> and print all the titles with LaTeX, but this didn't work out - for the
> first time I realized that lilypond-book-preamble.ly makes the vertical
> staff-staff spacing as tight as possible, which often makes the page layout
> pretty bad. Creating the movements separately is not an option either
> because not all movements will start on a new page.
>
> So now I have included a multi-movement score in the LaTeX document and
> don't know how to add TOC entries (in LaTeX) for the movements. I can see
> two possible ways, but don't know if they are really possible and if so how
> to approach them:
>
> Is it possible to insert something in the PDF output that LaTeX can pick up
> as TOC entries?
> (actually I doubt this is possible, but since it would be the easiest way I
> thought I'd ask anyway)
> Can I reliably retrieve the current page number of a given score's title
> block?
> With that information I could write them to a log file and read that later
> in LaTeX.
>
> TIA
> Urs
>
> PS: I don't know if it matters but the file is produced using
> ly:book-process etc.



Doesn't
http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
do what you want?

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Jan-Peter Voigt
Hi Urs,

the OLY way is the way to go, but for inspiration I share my little hack
that was doing its job quite well on short notice.

Jan-Peter

Am 19.04.2018 um 23:23 schrieb Thomas Morley:

> 2018-04-19 16:19 GMT+02:00 Urs Liska <[hidden email]>:
>> Hi all,
>>
>> I'm preparing an automated edition process using LuaLaTeX, Pandoc and
>> LilyPond.
>>
>> After some experimentation I have come to the conclusion that I'll have to
>> insert the multi-movement score as a single PDF created by LilyPond (but
>> through lyluatex to make use of caching and the layout mechanics).
>>
>> I first had used lyluatex's facility to include the score's system by system
>> and print all the titles with LaTeX, but this didn't work out - for the
>> first time I realized that lilypond-book-preamble.ly makes the vertical
>> staff-staff spacing as tight as possible, which often makes the page layout
>> pretty bad. Creating the movements separately is not an option either
>> because not all movements will start on a new page.
>>
>> So now I have included a multi-movement score in the LaTeX document and
>> don't know how to add TOC entries (in LaTeX) for the movements. I can see
>> two possible ways, but don't know if they are really possible and if so how
>> to approach them:
>>
>> Is it possible to insert something in the PDF output that LaTeX can pick up
>> as TOC entries?
>> (actually I doubt this is possible, but since it would be the easiest way I
>> thought I'd ask anyway)
>> Can I reliably retrieve the current page number of a given score's title
>> block?
>> With that information I could write them to a log file and read that later
>> in LaTeX.
>>
>> TIA
>> Urs
>>
>> PS: I don't know if it matters but the file is produced using
>> ly:book-process etc.
>
>
>
> Doesn't
> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
> do what you want?
>
> Cheers,
>    Harm
>
> _______________________________________________
> lilypond-user mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/lilypond-user
>

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

export-toc.ly (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3
In reply to this post by Thomas Morley-2

Hi Harm


Am 19.04.2018 um 23:23 schrieb Thomas Morley:
2018-04-19 16:19 GMT+02:00 Urs Liska [hidden email]:
Hi all,

I'm preparing an automated edition process using LuaLaTeX, Pandoc and
LilyPond.

After some experimentation I have come to the conclusion that I'll have to
insert the multi-movement score as a single PDF created by LilyPond (but
through lyluatex to make use of caching and the layout mechanics).

I first had used lyluatex's facility to include the score's system by system
and print all the titles with LaTeX, but this didn't work out - for the
first time I realized that lilypond-book-preamble.ly makes the vertical
staff-staff spacing as tight as possible, which often makes the page layout
pretty bad. Creating the movements separately is not an option either
because not all movements will start on a new page.

So now I have included a multi-movement score in the LaTeX document and
don't know how to add TOC entries (in LaTeX) for the movements. I can see
two possible ways, but don't know if they are really possible and if so how
to approach them:

Is it possible to insert something in the PDF output that LaTeX can pick up
as TOC entries?
(actually I doubt this is possible, but since it would be the easiest way I
thought I'd ask anyway)
Can I reliably retrieve the current page number of a given score's title
block?
With that information I could write them to a log file and read that later
in LaTeX.

TIA
Urs

PS: I don't know if it matters but the file is produced using
ly:book-process etc.


Doesn't
http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
do what you want?

Thank you, yes, this is what I needed, and finally I got the time to make it work.
I must admit I wouldn't have thought about looking in the *usage* manual for that information.

On closer inspection of the code I have some questions about it.

%%%
#(define (oly:create-toc-file layout pages)
  (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
    (if (not (null? label-table))
      (let* ((format-line (lambda (toc-item)
             (let* ((label (car toc-item))
                    (text  (caddr toc-item))
                    (label-page (and (list? label-table)
                                     (assoc label label-table)))
                    (page (and label-page (cdr label-page))))
               (format #f "~a, section, 1, {~a}, ~a" page text label))))
             (formatted-toc-items (map format-line (toc-items)))
             (whole-string (string-join formatted-toc-items ",\n"))
             (output-name (ly:parser-output-name))
             (outfilename (format "~a.toc" output-name))
             (outfile (open-output-file outfilename)))
        (if (output-port? outfile)
            (display whole-string outfile)
            (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
        (close-output-port outfile)))))

\paper {
  #(define (page-post-process layout pages) (oly:create-toc-file layout pages))
}
%%%
1)
If I see correctly the inner let* will only be evaluated if 'label-page-table has successfully been found and is not empty.
If this object is not found or if there are no TOC entries in the file label-table will be an empty list, right?
If that's true the (and (list? label-table) ... is redundant, isn't it?

2)
Assuming the TOC items are created using \tocItem then it should be guaranteed that there is the same label present as key in both label-table and one of the (toc-items) sublists. So (IISC) several further checks could be removed additionally (or am I missing something?):
             (let* ((label (car toc-item))
                    (text  (caddr toc-item))
                    (page (assoc-ref label-table label)))
should be sufficient? Therefore the whole function could be written as

#(define (oly:create-toc-file layout pages)
  (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
    (if (not (null? label-table))
      (let* ((format-line (lambda (toc-item)
             (let* ((label (car toc-item))
                    (text  (caddr toc-item))
                    (page (assoc-ref label-table label)))
               (format #f "~a, section, 1, {~a}, ~a" page text label))))
             (formatted-toc-items (map format-line (toc-items)))
             (whole-string (string-join formatted-toc-items ",\n"))
             (output-name (ly:parser-output-name))
             (outfilename (format "~a.toc" output-name))
             (outfile (open-output-file outfilename)))
        (if (output-port? outfile)
            (display whole-string outfile)
            (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
        (close-output-port outfile)))))
3)
I think the inclusion in the TeX TOC can (now?) be done in a simpler way using the catchfile package:

\documentclass{article}
\usepackage{pdfpages,catchfile}
\newcommand\includelilypond[1]{%
  \begingroup
    \CatchFileDef\currentlilypondtoc{#1.toc}{}
    \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
  \expandafter\endgroup\x
}
\begin{document}
\tableofcontents
\includelilypond{test}
\end{document}

(Answer from https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)

There's only one issue: The TOC will create wrong entries when LilyPond's first page number is not 1. So there should actually be an offset in place.
How can I read the value of the first-page-number variable to set up this offset?

Best
Urs

Cheers,
  Harm


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Thomas Morley-2
2018-04-25 16:00 GMT+02:00 Urs Liska <[hidden email]>:

> Hi Harm
>
>
> Am 19.04.2018 um 23:23 schrieb Thomas Morley:
>
> 2018-04-19 16:19 GMT+02:00 Urs Liska <[hidden email]>:
>
> Hi all,
>
> I'm preparing an automated edition process using LuaLaTeX, Pandoc and
> LilyPond.
>
> After some experimentation I have come to the conclusion that I'll have to
> insert the multi-movement score as a single PDF created by LilyPond (but
> through lyluatex to make use of caching and the layout mechanics).
>
> I first had used lyluatex's facility to include the score's system by system
> and print all the titles with LaTeX, but this didn't work out - for the
> first time I realized that lilypond-book-preamble.ly makes the vertical
> staff-staff spacing as tight as possible, which often makes the page layout
> pretty bad. Creating the movements separately is not an option either
> because not all movements will start on a new page.
>
> So now I have included a multi-movement score in the LaTeX document and
> don't know how to add TOC entries (in LaTeX) for the movements. I can see
> two possible ways, but don't know if they are really possible and if so how
> to approach them:
>
> Is it possible to insert something in the PDF output that LaTeX can pick up
> as TOC entries?
> (actually I doubt this is possible, but since it would be the easiest way I
> thought I'd ask anyway)
> Can I reliably retrieve the current page number of a given score's title
> block?
> With that information I could write them to a log file and read that later
> in LaTeX.
>
> TIA
> Urs
>
> PS: I don't know if it matters but the file is produced using
> ly:book-process etc.
>
>
> Doesn't
> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
> do what you want?
>
>
> Thank you, yes, this is what I needed, and finally I got the time to make it
> work.
> I must admit I wouldn't have thought about looking in the *usage* manual for
> that information.
>
> On closer inspection of the code I have some questions about it.

I'll try to answer ...

> %%%
> #(define (oly:create-toc-file layout pages)
>   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
>     (if (not (null? label-table))
>       (let* ((format-line (lambda (toc-item)
>              (let* ((label (car toc-item))
>                     (text  (caddr toc-item))
>                     (label-page (and (list? label-table)
>                                      (assoc label label-table)))
>                     (page (and label-page (cdr label-page))))
>                (format #f "~a, section, 1, {~a}, ~a" page text label))))
>              (formatted-toc-items (map format-line (toc-items)))
>              (whole-string (string-join formatted-toc-items ",\n"))
>              (output-name (ly:parser-output-name))
>              (outfilename (format "~a.toc" output-name))
>              (outfile (open-output-file outfilename)))
>         (if (output-port? outfile)
>             (display whole-string outfile)
>             (ly:warning (_ "Unable to open output file ~a for the TOC
> information") outfilename))
>         (close-output-port outfile)))))
>
> \paper {
>   #(define (page-post-process layout pages) (oly:create-toc-file layout
> pages))
> }
> %%%
>
> 1)
> If I see correctly the inner let* will only be evaluated if
> 'label-page-table has successfully been found and is not empty.
> If this object is not found or if there are no TOC entries in the file
> label-table will be an empty list, right?
> If that's true the (and (list? label-table) ... is redundant, isn't it?

Yep.

> 2)
> Assuming the TOC items are created using \tocItem then it should be
> guaranteed that there is the same label present as key in both label-table
> and one of the (toc-items) sublists. So (IISC) several further checks could
> be removed additionally (or am I missing something?):
>
>              (let* ((label (car toc-item))
>                     (text  (caddr toc-item))
>                     (page (assoc-ref label-table label)))
>
> should be sufficient? Therefore the whole function could be written as

Being always paranoid, I would do some thorough testings.

> #(define (oly:create-toc-file layout pages)
>   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
>     (if (not (null? label-table))
>       (let* ((format-line (lambda (toc-item)
>              (let* ((label (car toc-item))
>                     (text  (caddr toc-item))
>                     (page (assoc-ref label-table label)))
>                (format #f "~a, section, 1, {~a}, ~a" page text label))))
>              (formatted-toc-items (map format-line (toc-items)))
>              (whole-string (string-join formatted-toc-items ",\n"))
>              (output-name (ly:parser-output-name))
>              (outfilename (format "~a.toc" output-name))
>              (outfile (open-output-file outfilename)))
>         (if (output-port? outfile)
>             (display whole-string outfile)
>             (ly:warning (_ "Unable to open output file ~a for the TOC
> information") outfilename))
>         (close-output-port outfile)))))
>
> 3)
> I think the inclusion in the TeX TOC can (now?) be done in a simpler way
> using the catchfile package:
>
> \documentclass{article}
> \usepackage{pdfpages,catchfile}
> \newcommand\includelilypond[1]{%
>   \begingroup
>     \CatchFileDef\currentlilypondtoc{#1.toc}{}
>
> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>   \expandafter\endgroup\x
> }
> \begin{document}
> \tableofcontents
> \includelilypond{test}
> \end{document}
>
>
> (Answer from
> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>
> There's only one issue: The TOC will create wrong entries when LilyPond's
> first page number is not 1. So there should actually be an offset in place.
> How can I read the value of the first-page-number variable to set up this
> offset?

page-post-process has the layout-variable.
(ly:output-def-lookup layout 'first-page-number) should do the trick.

>
> Best
> Urs
>

HTH,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3
Hi Harm,

thanks for looking into this.


Am 25.04.2018 um 23:13 schrieb Thomas Morley:

> 2018-04-25 16:00 GMT+02:00 Urs Liska <[hidden email]>:
> ...
>> 2)
>> Assuming the TOC items are created using \tocItem then it should be
>> guaranteed that there is the same label present as key in both label-table
>> and one of the (toc-items) sublists. So (IISC) several further checks could
>> be removed additionally (or am I missing something?):
>>
>>               (let* ((label (car toc-item))
>>                      (text  (caddr toc-item))
>>                      (page (assoc-ref label-table label)))
>>
>> should be sufficient? Therefore the whole function could be written as
> Being always paranoid, I would do some thorough testings.

OK, I've found the case where my assumption would break. A rare (and
pointless) case but an existing one:

%%%
#(define (oly:create-toc-file layout pages)
    (format #t "label-page-table:\n~a\n" (ly:output-def-lookup layout 'label-page-table))
    (format #t "toc-items:\n~a\n" (toc-items)))

\paper {
   #(define (page-post-process layout pages) (oly:create-toc-file layout pages))
}


\tocItem \markup "A TOC entry"
{
   c'
}

\tocItem \markup "Another TOC entry"
%%%


The \tocItem without anything following it will create an entry in the
toc-items list but no label. So this second simplification won't work
reliably.

> ...
>
>> 3)
>> I think the inclusion in the TeX TOC can (now?) be done in a simpler way
>> using the catchfile package:
>>
>> \documentclass{article}
>> \usepackage{pdfpages,catchfile}
>> \newcommand\includelilypond[1]{%
>>    \begingroup
>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>
>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>    \expandafter\endgroup\x
>> }
>> \begin{document}
>> \tableofcontents
>> \includelilypond{test}
>> \end{document}
>>
>>
>> (Answer from
>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>
>> There's only one issue: The TOC will create wrong entries when LilyPond's
>> first page number is not 1. So there should actually be an offset in place.
>> How can I read the value of the first-page-number variable to set up this
>> offset?
> page-post-process has the layout-variable.
> (ly:output-def-lookup layout 'first-page-number) should do the trick.

Thanks, this works.
What do you think: this example code is much easier to understand than
the one currently in the manual. Should I propose an update?

Urs

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Thomas Morley-2
In reply to this post by Thomas Morley-2
2018-04-25 23:13 GMT+02:00 Thomas Morley <[hidden email]>:

>> There's only one issue: The TOC will create wrong entries when LilyPond's
>> first page number is not 1. So there should actually be an offset in place.
>> How can I read the value of the first-page-number variable to set up this
>> offset?
>
> page-post-process has the layout-variable.
> (ly:output-def-lookup layout 'first-page-number) should do the trick.

Rethinking this ...
With the code above you'll catch the first-page-number of the
book_part_ not the entire book.

You need to find the topmost parent layout and look for first-page-number there:

%% slightly changed `book-first-page' from define-markup-comands
#(define-public (get-book-first-page layout)
  "Return the @code{'first-page-number} of the entire book"
  (define (ancestor layout)
    "Return the topmost layout ancestor"
    (let ((parent (ly:output-def-parent layout)))
      (if (not (ly:output-def? parent))
          layout
          (ancestor parent))))
  (ly:output-def-lookup (ancestor layout) 'first-page-number))

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Thomas Morley-2
In reply to this post by Urs Liska-3
2018-04-26 8:48 GMT+02:00 Urs Liska <[hidden email]>:

> Hi Harm,
>
> thanks for looking into this.
>
>
> Am 25.04.2018 um 23:13 schrieb Thomas Morley:
>>
>> 2018-04-25 16:00 GMT+02:00 Urs Liska <[hidden email]>:
>> ...
>>>
>>> 2)
>>> Assuming the TOC items are created using \tocItem then it should be
>>> guaranteed that there is the same label present as key in both
>>> label-table
>>> and one of the (toc-items) sublists. So (IISC) several further checks
>>> could
>>> be removed additionally (or am I missing something?):
>>>
>>>               (let* ((label (car toc-item))
>>>                      (text  (caddr toc-item))
>>>                      (page (assoc-ref label-table label)))
>>>
>>> should be sufficient? Therefore the whole function could be written as
>>
>> Being always paranoid, I would do some thorough testings.
>
>
> OK, I've found the case where my assumption would break. A rare (and
> pointless) case but an existing one:
>
> %%%
> #(define (oly:create-toc-file layout pages)
>    (format #t "label-page-table:\n~a\n" (ly:output-def-lookup layout
> 'label-page-table))
>    (format #t "toc-items:\n~a\n" (toc-items)))
>
> \paper {
>   #(define (page-post-process layout pages) (oly:create-toc-file layout
> pages))
> }
>
>
> \tocItem \markup "A TOC entry"
> {
>   c'
> }
>
> \tocItem \markup "Another TOC entry"
> %%%
>
>
> The \tocItem without anything following it will create an entry in the
> toc-items list but no label. So this second simplification won't work
> reliably.

I think I've seen usecases for this. So better be prepared to deal with it.

>
>> ...
>>
>>> 3)
>>> I think the inclusion in the TeX TOC can (now?) be done in a simpler way
>>> using the catchfile package:
>>>
>>> \documentclass{article}
>>> \usepackage{pdfpages,catchfile}
>>> \newcommand\includelilypond[1]{%
>>>    \begingroup
>>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>
>>>
>>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>>    \expandafter\endgroup\x
>>> }
>>> \begin{document}
>>> \tableofcontents
>>> \includelilypond{test}
>>> \end{document}
>>>
>>>
>>> (Answer from
>>>
>>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>>
>>> There's only one issue: The TOC will create wrong entries when LilyPond's
>>> first page number is not 1. So there should actually be an offset in
>>> place.
>>> How can I read the value of the first-page-number variable to set up this
>>> offset?
>>
>> page-post-process has the layout-variable.
>> (ly:output-def-lookup layout 'first-page-number) should do the trick.
>
>
> Thanks, this works.
> What do you think: this example code is much easier to understand than the
> one currently in the manual. Should I propose an update?


Would be very nice.
You noticed my other mail about relying on "ancester-layout"?
Should be implemented as well.

Though, I don't have the knowledge to judge the Tex-coding.

Cheers,
  Harm

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2
In reply to this post by Urs Liska-3


Il giorno gio 26 apr 2018 alle 8:48, Urs Liska <[hidden email]>
ha scritto:

>> [...]
>>
>>> 3)
>>> I think the inclusion in the TeX TOC can (now?) be done in a
>>> simpler way
>>> using the catchfile package:
>>>
>>> \documentclass{article}
>>> \usepackage{pdfpages,catchfile}
>>> \newcommand\includelilypond[1]{%
>>>    \begingroup
>>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>
>>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>>    \expandafter\endgroup\x
>>> }
>>> \begin{document}
>>> \tableofcontents
>>> \includelilypond{test}
>>> \end{document}
>>>
>>>
>>> (Answer from
>>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>>
>>> There's only one issue: The TOC will create wrong entries when
>>> LilyPond's
>>> first page number is not 1. So there should actually be an offset
>>> in place.
>>> How can I read the value of the first-page-number variable to set
>>> up this
>>> offset?
>> page-post-process has the layout-variable.
>> (ly:output-def-lookup layout 'first-page-number) should do the trick.
>
> Thanks, this works.
> What do you think: this example code is much easier to understand
> than the one currently in the manual. Should I propose an update?
>

+1 for the update!

Urs, can you show a minimal example using the first-page-number?
How do you use it all the above in combination with lyluatex?

I have an almost finished book to give to a guitarist tomorrow!

Thanks in advance
Federico




_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3


Am 24.05.2018 um 08:52 schrieb Federico Bruni:

>
>
> Il giorno gio 26 apr 2018 alle 8:48, Urs Liska <[hidden email]>
> ha scritto:
>>> [...]
>>>
>>>> 3)
>>>> I think the inclusion in the TeX TOC can (now?) be done in a
>>>> simpler way
>>>> using the catchfile package:
>>>>
>>>> \documentclass{article}
>>>> \usepackage{pdfpages,catchfile}
>>>> \newcommand\includelilypond[1]{%
>>>>    \begingroup
>>>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>>
>>>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>>>
>>>>    \expandafter\endgroup\x
>>>> }
>>>> \begin{document}
>>>> \tableofcontents
>>>> \includelilypond{test}
>>>> \end{document}
>>>>
>>>>
>>>> (Answer from
>>>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>>>
>>>>
>>>> There's only one issue: The TOC will create wrong entries when
>>>> LilyPond's
>>>> first page number is not 1. So there should actually be an offset
>>>> in place.
>>>> How can I read the value of the first-page-number variable to set
>>>> up this
>>>> offset?
>>> page-post-process has the layout-variable.
>>> (ly:output-def-lookup layout 'first-page-number) should do the trick.
>>
>> Thanks, this works.
>> What do you think: this example code is much easier to understand
>> than the one currently in the manual. Should I propose an update?
>>
>
> +1 for the update!
>
> Urs, can you show a minimal example using the first-page-number?

This is the function as it ended up in my project files:

% Print table of contents entries to <basename>.toc
% Based on
% http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
% Pointed to by "Thomas Morley"
#(define (oly:create-toc-file layout pages)
    (let*
     ((label-table (ly:output-def-lookup layout 'label-page-table))
      (toc-items (toc-items)))
     (if (not (null? label-table))
         (let*
          ( ;; We need a page-offset so entries are offset to begin with p.1
            ;; (for use in \includepdf)
           (page-offset (- (ly:output-def-lookup layout 'first-page-number) 1))
           (format-line
            (lambda (toc-item)
              (let*
               ((label (car toc-item))
                (text  (caddr toc-item))
                (page (- (assoc-ref label-table label) page-offset)))
               (format #f "~a,subsection,2,{~a},~a" page text label))))
           (formatted-toc-items (map format-line toc-items))
           (whole-string (string-join formatted-toc-items ",\n"))
           (output-name (ly:parser-output-name))
           (outfilename (format "~a.toc" output-name))
           (outfile (open-output-file outfilename)))
          (if (output-port? outfile)
              (display whole-string outfile)
              (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
          (close-output-port outfile)))))

page-offset calculates the offset of the first-page-number versus '1'
and subtracts that from the actual page number of the TOC entry. That
means when your score starts on page 16 a TOC item on the third page of
the score will still get a TOC entry with page 3, and \includepdf will
generate the appropriate TOC entry in the enclosing LaTeX document.

> How do you use it all the above in combination with lyluatex?

I think this should be transparent. lyluatex will assign an arbitrary
first page number (i.e. the page it assumes the score will start), then
the above function will offset the TOC entries to be based on "1", and
\includepdf will translate them back to whatever page they'll *actually*
happen to be on in the end.

Partly related to that but actually for a different reason I have added
an option 'first-page-number' to lyluatex with which you can force the
first-page-number value passed to LilyPond. For the use case described
above this is not relevant but I wanted to mention it anyway (it's only
in the Git repo, not on CTAN/TeXLive, ATM).  The reason for this is that
there may be circumstances where when calling lyluatex you don't have
any idea about the page it will eventually end on. In the project I'm
working on I use an initial .tex file to *generate* the LilyPond scores
and *generate* an intermediate .tex file where the scores will
eventually be included. So when calling LilyPond there is no notion of a
"current page number" for where the score will eventually be. I want the
scores to always start on the right page, so I pass "1" as the first
page number and have the intermediate .tex file conditionally insert an
empty page.

Best
Urs

>
> I have an almost finished book to give to a guitarist tomorrow!
>
> Thanks in advance
> Federico
>
>
>


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2


Il giorno gio 24 mag 2018 alle 9:09, Urs Liska <[hidden email]>
ha scritto:

>
>
> Am 24.05.2018 um 08:52 schrieb Federico Bruni:
>>
>>
>> Il giorno gio 26 apr 2018 alle 8:48, Urs Liska
>> <[hidden email]> ha scritto:
>>>> [...]
>>>>
>>>>> 3)
>>>>> I think the inclusion in the TeX TOC can (now?) be done in a
>>>>> simpler way
>>>>> using the catchfile package:
>>>>>
>>>>> \documentclass{article}
>>>>> \usepackage{pdfpages,catchfile}
>>>>> \newcommand\includelilypond[1]{%
>>>>>    \begingroup
>>>>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>>>
>>>>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>>>> 
>>>>>    \expandafter\endgroup\x
>>>>> }
>>>>> \begin{document}
>>>>> \tableofcontents
>>>>> \includelilypond{test}
>>>>> \end{document}
>>>>>
>>>>>
>>>>> (Answer from
>>>>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>>>> 
>>>>>
>>>>> There's only one issue: The TOC will create wrong entries when
>>>>> LilyPond's
>>>>> first page number is not 1. So there should actually be an offset
>>>>> in place.
>>>>> How can I read the value of the first-page-number variable to set
>>>>> up this
>>>>> offset?
>>>> page-post-process has the layout-variable.
>>>> (ly:output-def-lookup layout 'first-page-number) should do the
>>>> trick.
>>>
>>> Thanks, this works.
>>> What do you think: this example code is much easier to understand
>>> than the one currently in the manual. Should I propose an update?
>>>
>>
>> +1 for the update!
>>
>> Urs, can you show a minimal example using the first-page-number?
>
> This is the function as it ended up in my project files:
>
> % Print table of contents entries to <basename>.toc
> % Based on
> %
> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
> % Pointed to by "Thomas Morley"
> #(define (oly:create-toc-file layout pages)
>    (let*
>     ((label-table (ly:output-def-lookup layout 'label-page-table))
>      (toc-items (toc-items)))
>     (if (not (null? label-table))
>         (let*
>          ( ;; We need a page-offset so entries are offset to begin
> with p.1
>            ;; (for use in \includepdf)
>           (page-offset (- (ly:output-def-lookup layout
> 'first-page-number) 1))
>           (format-line
>            (lambda (toc-item)
>              (let*
>               ((label (car toc-item))
>                (text  (caddr toc-item))
>                (page (- (assoc-ref label-table label) page-offset)))
>               (format #f "~a,subsection,2,{~a},~a" page text label))))
>           (formatted-toc-items (map format-line toc-items))
>           (whole-string (string-join formatted-toc-items ",\n"))
>           (output-name (ly:parser-output-name))
>           (outfilename (format "~a.toc" output-name))
>           (outfile (open-output-file outfilename)))
>          (if (output-port? outfile)
>              (display whole-string outfile)
>              (ly:warning (_ "Unable to open output file ~a for the
> TOC information") outfilename))
>          (close-output-port outfile)))))
>
> page-offset calculates the offset of the first-page-number versus '1'
> and subtracts that from the actual page number of the TOC entry. That
> means when your score starts on page 16 a TOC item on the third page
> of the score will still get a TOC entry with page 3, and \includepdf
> will generate the appropriate TOC entry in the enclosing LaTeX
> document.
>
>> How do you use it all the above in combination with lyluatex?
>
> I think this should be transparent. lyluatex will assign an arbitrary
> first page number (i.e. the page it assumes the score will start),
> then the above function will offset the TOC entries to be based on
> "1", and \includepdf will translate them back to whatever page
> they'll *actually* happen to be on in the end.
>

Thanks for the detailed explanation.

However, I cannot make it work with lyluatex.
You wrote that you wanted to use lyluatex to include the lilypond file
(not the PDF), in order to use the cache system.




_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3


Am 24. Mai 2018 14:55:37 MESZ schrieb Federico Bruni <[hidden email]>:

>
>
>Il giorno gio 24 mag 2018 alle 9:09, Urs Liska <[hidden email]>
>ha scritto:
>>
>>
>> Am 24.05.2018 um 08:52 schrieb Federico Bruni:
>>>
>>>
>>> Il giorno gio 26 apr 2018 alle 8:48, Urs Liska
>>> <[hidden email]> ha scritto:
>>>>> [...]
>>>>>
>>>>>> 3)
>>>>>> I think the inclusion in the TeX TOC can (now?) be done in a
>>>>>> simpler way
>>>>>> using the catchfile package:
>>>>>>
>>>>>> \documentclass{article}
>>>>>> \usepackage{pdfpages,catchfile}
>>>>>> \newcommand\includelilypond[1]{%
>>>>>>    \begingroup
>>>>>>      \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>>>>
>>>>>>
>\edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>
>>>>>> 
>>>>>>    \expandafter\endgroup\x
>>>>>> }
>>>>>> \begin{document}
>>>>>> \tableofcontents
>>>>>> \includelilypond{test}
>>>>>> \end{document}
>>>>>>
>>>>>>
>>>>>> (Answer from
>>>>>>
>https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>
>>>>>> 
>>>>>>
>>>>>> There's only one issue: The TOC will create wrong entries when
>>>>>> LilyPond's
>>>>>> first page number is not 1. So there should actually be an offset
>
>>>>>> in place.
>>>>>> How can I read the value of the first-page-number variable to set
>
>>>>>> up this
>>>>>> offset?
>>>>> page-post-process has the layout-variable.
>>>>> (ly:output-def-lookup layout 'first-page-number) should do the
>>>>> trick.
>>>>
>>>> Thanks, this works.
>>>> What do you think: this example code is much easier to understand
>>>> than the one currently in the manual. Should I propose an update?
>>>>
>>>
>>> +1 for the update!
>>>
>>> Urs, can you show a minimal example using the first-page-number?
>>
>> This is the function as it ended up in my project files:
>>
>> % Print table of contents entries to <basename>.toc
>> % Based on
>> %
>>
>http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
>> % Pointed to by "Thomas Morley"
>> #(define (oly:create-toc-file layout pages)
>>    (let*
>>     ((label-table (ly:output-def-lookup layout 'label-page-table))
>>      (toc-items (toc-items)))
>>     (if (not (null? label-table))
>>         (let*
>>          ( ;; We need a page-offset so entries are offset to begin
>> with p.1
>>            ;; (for use in \includepdf)
>>           (page-offset (- (ly:output-def-lookup layout
>> 'first-page-number) 1))
>>           (format-line
>>            (lambda (toc-item)
>>              (let*
>>               ((label (car toc-item))
>>                (text  (caddr toc-item))
>>                (page (- (assoc-ref label-table label) page-offset)))
>>               (format #f "~a,subsection,2,{~a},~a" page text
>label))))
>>           (formatted-toc-items (map format-line toc-items))
>>           (whole-string (string-join formatted-toc-items ",\n"))
>>           (output-name (ly:parser-output-name))
>>           (outfilename (format "~a.toc" output-name))
>>           (outfile (open-output-file outfilename)))
>>          (if (output-port? outfile)
>>              (display whole-string outfile)
>>              (ly:warning (_ "Unable to open output file ~a for the
>> TOC information") outfilename))
>>          (close-output-port outfile)))))
>>
>> page-offset calculates the offset of the first-page-number versus '1'
>
>> and subtracts that from the actual page number of the TOC entry. That
>
>> means when your score starts on page 16 a TOC item on the third page
>> of the score will still get a TOC entry with page 3, and \includepdf
>> will generate the appropriate TOC entry in the enclosing LaTeX
>> document.
>>
>>> How do you use it all the above in combination with lyluatex?
>>
>> I think this should be transparent. lyluatex will assign an arbitrary
>
>> first page number (i.e. the page it assumes the score will start),
>> then the above function will offset the TOC entries to be based on
>> "1", and \includepdf will translate them back to whatever page
>> they'll *actually* happen to be on in the end.
>>
>
>Thanks for the detailed explanation.
>
>However, I cannot make it work with lyluatex.
>You wrote that you wanted to use lyluatex to include the lilypond file
>(not the PDF), in order to use the cache system.

I'm not sure this is what you need, but you should look up raw-pdf and the section about wrapping commands in the manual.

the
urs

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2


Il giorno gio 24 mag 2018 alle 18:22, Urs Liska <[hidden email]>
ha scritto:

>
>
> Am 24. Mai 2018 14:55:37 MESZ schrieb Federico Bruni
> <[hidden email]>:
>>
>>
>> Il giorno gio 24 mag 2018 alle 9:09, Urs Liska
>> <[hidden email]>
>> ha scritto:
>>>
>>>
>>>  Am 24.05.2018 um 08:52 schrieb Federico Bruni:
>>>>
>>>>
>>>>  Il giorno gio 26 apr 2018 alle 8:48, Urs Liska
>>>>  <[hidden email]> ha scritto:
>>>>>>  [...]
>>>>>>
>>>>>>>  3)
>>>>>>>  I think the inclusion in the TeX TOC can (now?) be done in a
>>>>>>>  simpler way
>>>>>>>  using the catchfile package:
>>>>>>>
>>>>>>>  \documentclass{article}
>>>>>>>  \usepackage{pdfpages,catchfile}
>>>>>>>  \newcommand\includelilypond[1]{%
>>>>>>>     \begingroup
>>>>>>>       \CatchFileDef\currentlilypondtoc{#1.toc}{}
>>>>>>>
>>>>>>>
>> \edef\x{\noexpand\includepdf[pages=-,addtotoc={\currentlilypondtoc}]{#1.pdf}}
>>
>>>>>>>  
>>>>>>>     \expandafter\endgroup\x
>>>>>>>  }
>>>>>>>  \begin{document}
>>>>>>>  \tableofcontents
>>>>>>>  \includelilypond{test}
>>>>>>>  \end{document}
>>>>>>>
>>>>>>>
>>>>>>>  (Answer from
>>>>>>>
>> https://tex.stackexchange.com/questions/428239/merge-in-manual-toc-entries-in-a-lualatex-document)
>>
>>>>>>>  
>>>>>>>
>>>>>>>  There's only one issue: The TOC will create wrong entries when
>>>>>>>  LilyPond's
>>>>>>>  first page number is not 1. So there should actually be an
>>>>>>> offset
>>
>>>>>>>  in place.
>>>>>>>  How can I read the value of the first-page-number variable to
>>>>>>> set
>>
>>>>>>>  up this
>>>>>>>  offset?
>>>>>>  page-post-process has the layout-variable.
>>>>>>  (ly:output-def-lookup layout 'first-page-number) should do the
>>>>>>  trick.
>>>>>
>>>>>  Thanks, this works.
>>>>>  What do you think: this example code is much easier to understand
>>>>>  than the one currently in the manual. Should I propose an
>>>>> update?
>>>>>
>>>>
>>>>  +1 for the update!
>>>>
>>>>  Urs, can you show a minimal example using the first-page-number?
>>>
>>>  This is the function as it ended up in my project files:
>>>
>>>  % Print table of contents entries to <basename>.toc
>>>  % Based on
>>>  %
>>>
>> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
>>>  % Pointed to by "Thomas Morley"
>>>  #(define (oly:create-toc-file layout pages)
>>>     (let*
>>>      ((label-table (ly:output-def-lookup layout 'label-page-table))
>>>       (toc-items (toc-items)))
>>>      (if (not (null? label-table))
>>>          (let*
>>>           ( ;; We need a page-offset so entries are offset to begin
>>>  with p.1
>>>             ;; (for use in \includepdf)
>>>            (page-offset (- (ly:output-def-lookup layout
>>>  'first-page-number) 1))
>>>            (format-line
>>>             (lambda (toc-item)
>>>               (let*
>>>                ((label (car toc-item))
>>>                 (text  (caddr toc-item))
>>>                 (page (- (assoc-ref label-table label)
>>> page-offset)))
>>>                (format #f "~a,subsection,2,{~a},~a" page text
>> label))))
>>>            (formatted-toc-items (map format-line toc-items))
>>>            (whole-string (string-join formatted-toc-items ",\n"))
>>>            (output-name (ly:parser-output-name))
>>>            (outfilename (format "~a.toc" output-name))
>>>            (outfile (open-output-file outfilename)))
>>>           (if (output-port? outfile)
>>>               (display whole-string outfile)
>>>               (ly:warning (_ "Unable to open output file ~a for the
>>>  TOC information") outfilename))
>>>           (close-output-port outfile)))))
>>>
>>>  page-offset calculates the offset of the first-page-number versus
>>> '1'
>>
>>>  and subtracts that from the actual page number of the TOC entry.
>>> That
>>
>>>  means when your score starts on page 16 a TOC item on the third
>>> page
>>>  of the score will still get a TOC entry with page 3, and
>>> \includepdf
>>>  will generate the appropriate TOC entry in the enclosing LaTeX
>>>  document.
>>>
>>>>  How do you use it all the above in combination with lyluatex?
>>>
>>>  I think this should be transparent. lyluatex will assign an
>>> arbitrary
>>
>>>  first page number (i.e. the page it assumes the score will start),
>>>  then the above function will offset the TOC entries to be based on
>>>  "1", and \includepdf will translate them back to whatever page
>>>  they'll *actually* happen to be on in the end.
>>>
>>
>> Thanks for the detailed explanation.
>>
>> However, I cannot make it work with lyluatex.
>> You wrote that you wanted to use lyluatex to include the lilypond
>> file
>> (not the PDF), in order to use the cache system.
>
> I'm not sure this is what you need, but you should look up raw-pdf
> and the section about wrapping commands in the manual.
>
> the
> urs

I've read the sections "Providing raw filenames" and "Wrapping Raw PDF
Filenames" of lyluatex manual and I'm still scratching my head...
Nevermind, I'll use the \includelilypond command of the Usage manual.












_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2
In reply to this post by Urs Liska-3


Il giorno gio 24 mag 2018 alle 9:09, Urs Liska <[hidden email]>
ha scritto:

>
> This is the function as it ended up in my project files:
>
> % Print table of contents entries to <basename>.toc
> % Based on
> %
> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
> % Pointed to by "Thomas Morley"
> #(define (oly:create-toc-file layout pages)
>    (let*
>     ((label-table (ly:output-def-lookup layout 'label-page-table))
>      (toc-items (toc-items)))
>     (if (not (null? label-table))
>         (let*
>          ( ;; We need a page-offset so entries are offset to begin
> with p.1
>            ;; (for use in \includepdf)
>           (page-offset (- (ly:output-def-lookup layout
> 'first-page-number) 1))
>           (format-line
>            (lambda (toc-item)
>              (let*
>               ((label (car toc-item))
>                (text  (caddr toc-item))
>                (page (- (assoc-ref label-table label) page-offset)))
>               (format #f "~a,subsection,2,{~a},~a" page text label))))
>           (formatted-toc-items (map format-line toc-items))
>           (whole-string (string-join formatted-toc-items ",\n"))
>           (output-name (ly:parser-output-name))
>           (outfilename (format "~a.toc" output-name))
>           (outfile (open-output-file outfilename)))
>          (if (output-port? outfile)
>              (display whole-string outfile)
>              (ly:warning (_ "Unable to open output file ~a for the
> TOC information") outfilename))
>          (close-output-port outfile)))))
>
> page-offset calculates the offset of the first-page-number versus '1'
> and subtracts that from the actual page number of the TOC entry. That
> means when your score starts on page 16 a TOC item on the third page
> of the score will still get a TOC entry with page 3, and \includepdf
> will generate the appropriate TOC entry in the enclosing LaTeX
> document.

I get an error:

Drawing systems....brani.ly:35:23: In procedure - in expression (-
(assoc-ref label-table label) page-offset):
brani.ly:35:23: Wrong type argument in position 1: #f

The offending line is:

(page (- (assoc-ref label-table label) page-offset)))




_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3


Am 25. Mai 2018 07:48:58 MESZ schrieb Federico Bruni <[hidden email]>:

>
>
>Il giorno gio 24 mag 2018 alle 9:09, Urs Liska <[hidden email]>
>ha scritto:
>>
>> This is the function as it ended up in my project files:
>>
>> % Print table of contents entries to <basename>.toc
>> % Based on
>> %
>>
>http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
>> % Pointed to by "Thomas Morley"
>> #(define (oly:create-toc-file layout pages)
>>    (let*
>>     ((label-table (ly:output-def-lookup layout 'label-page-table))
>>      (toc-items (toc-items)))
>>     (if (not (null? label-table))
>>         (let*
>>          ( ;; We need a page-offset so entries are offset to begin
>> with p.1
>>            ;; (for use in \includepdf)
>>           (page-offset (- (ly:output-def-lookup layout
>> 'first-page-number) 1))
>>           (format-line
>>            (lambda (toc-item)
>>              (let*
>>               ((label (car toc-item))
>>                (text  (caddr toc-item))
>>                (page (- (assoc-ref label-table label) page-offset)))
>>               (format #f "~a,subsection,2,{~a},~a" page text
>label))))
>>           (formatted-toc-items (map format-line toc-items))
>>           (whole-string (string-join formatted-toc-items ",\n"))
>>           (output-name (ly:parser-output-name))
>>           (outfilename (format "~a.toc" output-name))
>>           (outfile (open-output-file outfilename)))
>>          (if (output-port? outfile)
>>              (display whole-string outfile)
>>              (ly:warning (_ "Unable to open output file ~a for the
>> TOC information") outfilename))
>>          (close-output-port outfile)))))
>>
>> page-offset calculates the offset of the first-page-number versus '1'
>
>> and subtracts that from the actual page number of the TOC entry. That
>
>> means when your score starts on page 16 a TOC item on the third page
>> of the score will still get a TOC entry with page 3, and \includepdf
>> will generate the appropriate TOC entry in the enclosing LaTeX
>> document.
>
>I get an error:
>
>Drawing systems....brani.ly:35:23: In procedure - in expression (-
>(assoc-ref label-table label) page-offset):
>brani.ly:35:23: Wrong type argument in position 1: #f
>
>The offending line is:
>
>(page (- (assoc-ref label-table label) page-offset)))

Can you tell what toc-item contains by inserting a display between the lambda and let lines immediately before that line?

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2


Il giorno ven 25 mag 2018 alle 7:55, Urs Liska <[hidden email]>
ha scritto:

>
>
> Am 25. Mai 2018 07:48:58 MESZ schrieb Federico Bruni
> <[hidden email]>:
>>
>>
>> Il giorno gio 24 mag 2018 alle 9:09, Urs Liska
>> <[hidden email]>
>> ha scritto:
>>>
>>>  This is the function as it ended up in my project files:
>>>
>>>  % Print table of contents entries to <basename>.toc
>>>  % Based on
>>>  %
>>>
>> http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
>>>  % Pointed to by "Thomas Morley"
>>>  #(define (oly:create-toc-file layout pages)
>>>     (let*
>>>      ((label-table (ly:output-def-lookup layout 'label-page-table))
>>>       (toc-items (toc-items)))
>>>      (if (not (null? label-table))
>>>          (let*
>>>           ( ;; We need a page-offset so entries are offset to begin
>>>  with p.1
>>>             ;; (for use in \includepdf)
>>>            (page-offset (- (ly:output-def-lookup layout
>>>  'first-page-number) 1))
>>>            (format-line
>>>             (lambda (toc-item)
>>>               (let*
>>>                ((label (car toc-item))
>>>                 (text  (caddr toc-item))
>>>                 (page (- (assoc-ref label-table label)
>>> page-offset)))
>>>                (format #f "~a,subsection,2,{~a},~a" page text
>> label))))
>>>            (formatted-toc-items (map format-line toc-items))
>>>            (whole-string (string-join formatted-toc-items ",\n"))
>>>            (output-name (ly:parser-output-name))
>>>            (outfilename (format "~a.toc" output-name))
>>>            (outfile (open-output-file outfilename)))
>>>           (if (output-port? outfile)
>>>               (display whole-string outfile)
>>>               (ly:warning (_ "Unable to open output file ~a for the
>>>  TOC information") outfilename))
>>>           (close-output-port outfile)))))
>>>
>>>  page-offset calculates the offset of the first-page-number versus
>>> '1'
>>
>>>  and subtracts that from the actual page number of the TOC entry.
>>> That
>>
>>>  means when your score starts on page 16 a TOC item on the third
>>> page
>>>  of the score will still get a TOC entry with page 3, and
>>> \includepdf
>>>  will generate the appropriate TOC entry in the enclosing LaTeX
>>>  document.
>>
>> I get an error:
>>
>> Drawing systems....brani.ly:35:23: In procedure - in expression (-
>> (assoc-ref label-table label) page-offset):
>> brani.ly:35:23: Wrong type argument in position 1: #f
>>
>> The offending line is:
>>
>> (page (- (assoc-ref label-table label) page-offset)))
>
> Can you tell what toc-item contains by inserting a display between
> the lambda and let lines immediately before that line?
I have a minimal example, see attachment.
The problem is triggered by wrapping each \tocItem within a \bookpart
block (instead of the implicit \book, which works fine).

Here's what display shows:

Drawing systems.../home/fede/tmp/lilypond/toc-latex/test.ly:18:15: In
procedure memoization in expression (let* (# # #) (format #f
"~a,subsection,2,{~a},~a" ...)):
/home/fede/tmp/lilypond/toc-latex/test.ly:18:15: In file
"/home/fede/tmp/lilypond/toc-latex/test.ly", line 19: Bad binding
(display text (caddr toc-item)) in expression (let* ((label (car
toc-item)) (display text (caddr toc-item)) (page (- (assoc-ref
label-table label) page-offset))) (format #f "~a,subsection,2,{~a},~a"
page text label)).







_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

test.ly (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3

Hi Federico,


Am 25.05.2018 um 08:28 schrieb Federico Bruni:


Il giorno ven 25 mag 2018 alle 7:55, Urs Liska [hidden email] ha scritto:


Am 25. Mai 2018 07:48:58 MESZ schrieb Federico Bruni [hidden email]:


Il giorno gio 24 mag 2018 alle 9:09, Urs Liska [hidden email]
ha scritto:

 This is the function as it ended up in my project files:

 % Print table of contents entries to <basename>.toc
 % Based on
 %

http://lilypond.org/doc/v2.19/Documentation/usage-big-page#sharing-the-table-of-contents
 % Pointed to by "Thomas Morley"
 #(define (oly:create-toc-file layout pages)
    (let*
     ((label-table (ly:output-def-lookup layout 'label-page-table))
      (toc-items (toc-items)))
     (if (not (null? label-table))
         (let*
          ( ;; We need a page-offset so entries are offset to begin
 with p.1
            ;; (for use in \includepdf)
           (page-offset (- (ly:output-def-lookup layout
 'first-page-number) 1))
           (format-line
            (lambda (toc-item)
              (let*
               ((label (car toc-item))
                (text  (caddr toc-item))
                (page (- (assoc-ref label-table label) page-offset)))
               (format #f "~a,subsection,2,{~a},~a" page text
label))))
           (formatted-toc-items (map format-line toc-items))
           (whole-string (string-join formatted-toc-items ",\n"))
           (output-name (ly:parser-output-name))
           (outfilename (format "~a.toc" output-name))
           (outfile (open-output-file outfilename)))
          (if (output-port? outfile)
              (display whole-string outfile)
              (ly:warning (_ "Unable to open output file ~a for the
 TOC information") outfilename))
          (close-output-port outfile)))))

 page-offset calculates the offset of the first-page-number versus '1'

 and subtracts that from the actual page number of the TOC entry. That

 means when your score starts on page 16 a TOC item on the third page
 of the score will still get a TOC entry with page 3, and \includepdf
 will generate the appropriate TOC entry in the enclosing LaTeX
 document.

I get an error:

Drawing systems....brani.ly:35:23: In procedure - in expression (-
(assoc-ref label-table label) page-offset):
brani.ly:35:23: Wrong type argument in position 1: #f

The offending line is:

(page (- (assoc-ref label-table label) page-offset)))

Can you tell what toc-item contains by inserting a display between the lambda and let lines immediately before that line?

I have a minimal example, see attachment.
The problem is triggered by wrapping each \tocItem within a \bookpart block (instead of the implicit \book, which works fine).

Here's what display shows:

Drawing systems.../home/fede/tmp/lilypond/toc-latex/test.ly:18:15: In procedure memoization in expression (let* (# # #) (format #f "~a,subsection,2,{~a},~a" ...)):
/home/fede/tmp/lilypond/toc-latex/test.ly:18:15: In file "/home/fede/tmp/lilypond/toc-latex/test.ly", line 19: Bad binding (display text (caddr toc-item)) in expression (let* ((label (car toc-item)) (display text (caddr toc-item)) (page (- (assoc-ref label-table label) page-offset))) (format #f "~a,subsection,2,{~a},~a" page text label)).


This is because you didn't place the (display between the lines with "lambda" and "let".

But I did some experiments, and I identified the problem but can't give you a solution.

When you have separate bookparts it seems the "label tables" are separate, so you have two label tables with one entry each. It seems they are associated with the corresponding "output definitions", but the function receives only one of them. When I print the contents of both toc-item and the label table I get the following results:

(toc99 tocItemMarkup A TOC entry)

((toc99 . 20))

(toc100 tocItemMarkup Another TOC entry)

((toc99 . 20))


which indicates one or several issues along the way which I hope someone else will be able to clarify (and suggest a solution).

Best
Urs
But the function is

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Urs Liska-3
In reply to this post by Federico Bruni-2



Am 25.05.2018 um 07:44 schrieb Federico Bruni:
...

How do you use it all the above in combination with lyluatex?

 I think this should be transparent. lyluatex will assign an arbitrary

 first page number (i.e. the page it assumes the score will start),
 then the above function will offset the TOC entries to be based on
 "1", and \includepdf will translate them back to whatever page
 they'll *actually* happen to be on in the end.


Thanks for the detailed explanation.

However, I cannot make it work with lyluatex.
You wrote that you wanted to use lyluatex to include the lilypond file
(not the PDF), in order to use the cache system.

I'm not sure this is what you need, but you should look up raw-pdf and the section about wrapping commands in the manual.

the
urs

I've read the sections "Providing raw filenames" and "Wrapping Raw PDF Filenames" of lyluatex manual and I'm still scratching my head...
Nevermind, I'll use the \includelilypond command of the Usage manual.



This last comment about using \lilypondfile "instead" makes me think you got something wrong about the idea of the raw-pdf option. I don't really see what you want to achieve, and maybe this isn't even relevant to your use case. However, I'd like to clarify that.

Generally what happens when you pass LilyPond code to lyluatex is the following (and it basically doesn't matter if you use \lily, the environment or \lilypondfile:

  • The LilyPond code is passed on to the Lua module
  • There it is processed, and a Score is compiled using LilyPond
  • In that proces a filename is generated from the hashed contents of the score
  • Finally some sort of a \includegraphics or \includepdf command is "written" back to LaTeX, using the generated hash name.
    When Lua  "writes" back to the TeX domain this is what LaTeX "sees" for its typesetting procedure. That means the LilyPond code is essentially replaced with the code to include the resulting score.

However, there are contexts where you need more control over how the score is integrated into the text document. For example when you want to provide a custom figure environment and wrap the score in it. Or when you want to make use of a .toc file you created here. Or when you don't want to immediately include the score but just use lyluatex to create and cache the scores, for example in order to produce a set of parts from one input document.

In that case you can use the option raw-pdf. This does the following:

  • Process the LilyPond code and create the score (as above)
  • Generate the hash filename (as above)
  • Do *not* write back the code to include the score in the current document!
  • Instead write back code that populates the macro \lyscore{} with the cached filename (there are further options for multiple pages/systems, but for now the basic functionality is sufficient)

Once the lyluatex command has completed you can access the filename of the current score through \lyscore{}, e.g.

    \includepdf[pages=-]{lyscore{}}

and start creating your custom solutions from there.

HTH
Urs


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Make TOC entries available to LaTeX

Federico Bruni-2
In reply to this post by Urs Liska-3


Il giorno ven 25 mag 2018 alle 8:42, Urs Liska <[hidden email]>
ha scritto:

> [...]
>
> But I did some experiments, and I identified the problem but can't
> give you a solution.
>
> When you have separate bookparts it seems the "label tables" are
> separate, so you have two label tables with one entry each. It seems
> they are associated with the corresponding "output definitions", but
> the function receives only one of them. When I print the contents of
> both toc-item and the label table I get the following results:
>
> (toc99 tocItemMarkup A TOC entry)
> ((toc99 . 20))
>
> (toc100 tocItemMarkup Another TOC entry)
> ((toc99 . 20))
>
> which indicates one or several issues along the way which I hope
> someone else will be able to clarify (and suggest a solution).
>

For now I've found a workaround.
As I was using bookparts only to have page breaks and a header for each
part, I've added manual \pageBreak(s) and moved the header blocks
within the score blocks of each part and set print-all-headers to true.

Now everything works almost fine.
The last problem left is that the toc items of the included lilypond
file are treated as subsections, while the other items in my
markdown/latex file are sections; so the titles of the parts from the
lilypond file are nested within the last section of the main file. I'd
like them to be indipendent sections.

Is it clear? I may provide a minimal example if you need it...
Any idea for a solution?

Thanks in advance
Federico




_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
12