lilypond-user
[Top][All Lists]
Advanced

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

Re: Make TOC entries available to LaTeX


From: Urs Liska
Subject: Re: Make TOC entries available to LaTeX
Date: Thu, 24 May 2018 09:09:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0



Am 24.05.2018 um 08:52 schrieb Federico Bruni:


Il giorno gio 26 apr 2018 alle 8:48, Urs Liska <address@hidden> 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







reply via email to

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