Autor Thema: Inhaltsverzeichnis in eine eigene Datei ausgeben (ausgelagerter Thread)  (Gelesen 1653 mal)

Manuela

  • Member
Da ich Probleme hatte, das Inhaltsverzeichnis per Adobe Acrobat Reader in eine Textdatei zu übertragen, hat Harm hier eine Lösung gepostet, die das Inhaltsverzeichnis in eine seperate Textdatei ausgibt.

Der Vollständigkeit halber erlaube ich mir, den Code nochmals zu posten

\version "2.18.2"

#(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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
               (format #f "~a, ~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 "page, text, label\n" outfile))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        (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))
}

{
\tocItem "auf Seite 1"
c'1
\pageBreak
\tocItem "auf Seite 2"
d'
\pageBreak
\tocItem "auf Seite 3"
e'
}

Ich habe es bereits ausprobiert, klappt super!!!

"text" und "page" habe ich vertauscht, ich möchte zuerst die Überschrift und dann die Zeilennumer haben.
Mit "label" kann man sicher auch noch was Sinnvolles anfangen, ich muss nur noch rauskriegen was.  ;)

harm6

  • Member
Re: Inhaltsverzeichnis in eine eigene Datei ausgeben (ausgelagerter Thread)
« Antwort #1 am: Dienstag, 25. Oktober 2016, 23:02 »
Die labels, toc99 und ähnliche, werden benutzt um in der label-table die Einträge zu identifizieren und nachher korrekt zuzuordnen.
Du hast ja schon den "Alphabetischen Index" benutzt, iirc. Dort fändest Du in der lable-table eben nicht nur "toc..."-Einträge sondern auch andere, die dann später selektiert werden.

Im übrigen kann man mit `page-post-process' noch viel mehr anstellen. Allerdings alles als post-process.

Gruß,
  Harm

Manuela

  • Member
Re: Inhaltsverzeichnis in eine eigene Datei ausgeben (ausgelagerter Thread)
« Antwort #2 am: Donnerstag, 27. Oktober 2016, 07:56 »
Sehe ich das richtig, dass ich mit \label #'abc einen derartigen Eintrag erzeuge?

harm6

  • Member
Re: Inhaltsverzeichnis in eine eigene Datei ausgeben (ausgelagerter Thread)
« Antwort #3 am: Donnerstag, 27. Oktober 2016, 21:04 »
Zitat
Sehe ich das richtig, dass ich mit \label #'abc einen derartigen Eintrag erzeuge?

Probiers aus:

\version "2.18.2"

#(define (oly:create-toc-file layout pages)
  (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
(write-me "label-page-table \n" label-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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
               (format #f "~a, ~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 "page, text, label\n" outfile))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        (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))
}

{
\tocItem "auf Seite 1"
c'1
\pageBreak
\tocItem "auf Seite 2"
d'
\pageBreak
\tocItem "auf Seite 3"
e'
\label #'abc
}

->
Zitat von: Terminal
label-page-table
((abc . 3) (toc99 . 3) (toc99 . 2) (toc98 . 2) (toc98 . 1) (toc97 . 1))


Gruß,
  Harm