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: Federico Bruni
Subject: Re: Make TOC entries available to LaTeX
Date: Fri, 25 May 2018 07:44:41 +0200



Il giorno gio 24 mag 2018 alle 18:22, Urs Liska <address@hidden> ha scritto:


Am 24. Mai 2018 14:55:37 MESZ schrieb Federico Bruni <address@hidden>:


Il giorno gio 24 mag 2018 alle 9:09, Urs Liska <address@hidden>
ha scritto:


 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.


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.














reply via email to

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