Deutsches Lilypond Forum (Archiv)

Allgemein => Fragen zu Funktionen => Thema gestartet von: Heinz am Mittwoch, 11. Januar 2012, 18:25

Titel: Inhaltsverzeichnis modifizieren
Beitrag von: Heinz am Mittwoch, 11. Januar 2012, 18:25
Hallo zusammen,

ich möchte ein Inhaltsverzeichnis erstellen und verändern (mit 2.14.2).
Nach NR 3.2.4 kann man die Einträge formatieren:
tocItemMarkup = \markup \large \fill-line {
    \fromproperty #'toc:text \fromproperty #'toc:page
  }
Klappt soweit.
Gepunktete Linien kann man auch einfügen mit:
tocItemMarkup = \tocItemWithDotsMarkup
Aber wie kann man beides kombinieren? tocItemMarkup überschreibt sich wohl jeweils…

Weiß jemand Rat?

Fragt Heinz.
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Heinz am Mittwoch, 11. Januar 2012, 20:32
Habe es inzwischen herausgefunden:
Erst ist tocItemWithDotsMarkup (aus /ly/toc-init.ly kopiert) zu editieren - hier beispielhaft \huge eingefügt:
tocItemWithDotsMarkup = \markup \huge \fill-with-pattern #1 #RIGHT .
  \fromproperty #'toc:text \fromproperty #'toc:page

Dann
tocItemMarkup = \tocItemWithDotsMarkup
Und das war´s dann!

Heinz.
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Mittwoch, 11. Januar 2012, 20:47
Hallo Heinz,

im Allgemeinen ist es keine gute Idee die internen Dateien zu verändern, denn nach einiger Zeit weiß man nicht mehr was man wo und wie verändert hat. Und es überlebt ein upgrade auch nicht. Dein Beispiel (\huge einzufügen) wäre auch anders umzusetzen gewesen.
Allerdings habe ich im Moment überhaupt keine Vorstellung was Du erreichen möchtest.
Vielleicht kannst Du mal ein Beispiel mit einem Textverarbeitungsprogramm erstellen und posten.

Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Heinz am Donnerstag, 12. Januar 2012, 17:10
Hallo Harm,

zur Erläuterung:

ich wollte die Darstellung des Inhaltsverzeichnisses anders gestalten und formatieren. Im NR 3.2.4 (Version 2.14.2) habe ich gelesen:
Zitat
Die Standardformatierungselemente sind tocTitleMarkup um die Überschrift zu formatieren und tocItemMarkup um die einzelnen Inhaltselemente zu formatieren, bestehend aus dem Titelelement und einer Seitenzahl. Die Variablen können durch den Benutzer geändert werden:

\paper {
  %% Übersetzung der Inhaltsverzeichnisüberschrift nach französisch:
  tocTitleMarkup = \markup \huge \column {
    \fill-line { \null "Table des matières" \null }
    \hspace #1
  }
  %% hier größere Schriftarten
  tocItemMarkup = \markup \large \fill-line {
    \fromproperty #'toc:text \fromproperty #'toc:page
  }
}

D. h. tocItemMarkup aus der toc-init.ly wird hier neu definiert.

Dann: wenn man eine gepunktete Linie einfügen will:

Zitat
Die Zeile zwischen dem Inhalt und der Seitenzahl kann mit einer gepunkteten Linie gefüllt werden:

    \header { tagline = ##f }
    \paper {
      tocItemMarkup = \tocItemWithDotsMarkup
    }

Nur wußte ich zunächst nicht, wie ich gepunktete Linien  u n d  eine andere Formatierung hinkriegen kann. Dann habe ich gemerkt, daß man auch tocItemWithDotsMarkup neu definieren kann.

Wahrscheinlich für die Könner sowieso klar, aber ich brauchte doch einen Moment, um es herauszufinden... :)

Nebenbei: die alphabetische Sortierung des Inhaltsverzeichnisses ist wohl noch nicht vorgesehen, oder? Ich habe den alphabetischen Index gefunden:
https://liarchiv.joonet.de/index.php?topic=863.msg4784#msg4784 (https://liarchiv.joonet.de/index.php?topic=863.msg4784#msg4784)

Allerdings weiß ich nicht, wie man damit ein alphabetisch nach Titeln sortiertes Inhaltsverzeichnis (keinen Index) erzeugen kann.
Falls jemand dazu eine Idee hat...?

Liebe Grüße,
Heinz.
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Freitag, 13. Januar 2012, 00:43
Hallo Heinz,

folgendes erzeugt ein normales Inhaltsverzeichnis und ein alphabetisch sortiertes. (Lösch was Du nicht brauchst.) Dazu habe ich den Code den Du hier im Forum ja schon gefunden hattest etwas verändert.

\version "2.14.2"

#(define-public (add-index-item! markup-symbol text sorttext) #f)
#(define-public (index-items) #f)

#(let ((index-item-list (list)))
   (set! add-index-item!
   (lambda (markup-symbol text sorttext)
     (let ((label (gensym "index")))
       (set! index-item-list
       ;; We insert index items sorted from the beginning on and do
       ;; not sort them later - this saves pretty much computing time
       (insert-alphabetical-sorted! (list label markup-symbol text sorttext)
       index-item-list))
       (make-music 'EventChord
         'page-marker #t
         'page-label label
         'elements (list (make-music 'LabelEvent
         'page-label label))))))
   (set! index-items (lambda ()
         index-item-list)))

#(define (insert-alphabetical-sorted! iitem ilist)
  (if
    (null? ilist) (list iitem)
    (if
      (string-ci<? (cadddr iitem) (cadddr (car ilist))) (cons iitem ilist)
      (cons (car ilist) (insert-alphabetical-sorted! iitem (cdr ilist))))))

\paper {
  tocTitleMarkup = \markup  \column {
            \vspace #2
            \fill-line { \null \fontsize #5 "Inhaltsverzeichnis" \null }
            \vspace #1
  }
  tocItemMarkup = \tocItemWithDotsMarkup
  indexTitleMarkup = \markup \column {
            \vspace #2
            \fill-line { \null \fontsize #5 "Alphabetisches InhaltsVerzeichnis" \null }
            \vspace #1
  }
  indexItemMarkup = \markup \large \fill-line {
          \fill-with-pattern #1 #RIGHT .
          \fromproperty #'index:text
          \fromproperty #'index:page
  }
}

#(define-markup-list-command (index layout props) ()
  ( _i "Outputs an alphabetical sorted index, using the paper
  variable @code{indexTitleMarkup} for its title, then the list of
  lines built using the @code{indexItem} music function
  Usage: @code{\\markuplines \\index}" )
  (cons (interpret-markup layout props
        (ly:output-def-lookup layout 'indexTitleMarkup))
  (space-lines (chain-assoc-get 'baseline-skip props)
        (map (lambda (index-item)
         (let ((label (car index-item))
         (index-markup (cadr index-item))
         (text (caddr index-item)))
           (interpret-markup
             layout
             (cons (list (cons 'index:page
              (markup #:page-ref label "XXX" "?"))
             (cons 'index:text text))
             props)
             (ly:output-def-lookup layout index-markup))))
       (index-items)))))

indexItem =
#(define-music-function (parser location sorttext) (markup?)
   "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup."
   (let ((text sorttext))
   (add-index-item! 'indexItemMarkup text sorttext)))

% ---------------------------------------------------------------

\version "2.14.2"

mus = { c'1 }

\book {
        \bookpart {
        \markuplines \table-of-contents
        }
        \bookpart {
        \markuplines \index
        }
        \bookpart {
        \tocItem \markup { zStück 1 }
        \indexItem "zStück 1"
        \new Staff \mus
        }
        \bookpart {
        \tocItem \markup { bStück 2 }
        \indexItem "bStück 2"
        \new Staff \mus
        }
        \bookpart {
        \tocItem \markup { xStück 3 }
        \indexItem "xStück 3"
        \new Staff \mus
        }
        \bookpart {
        \tocItem \markup { cStück 4 }
        \indexItem "cStück 4" 
        \new Staff \mus
        }
        \bookpart {
        \tocItem \markup { aStück 5 }
        \indexItem "aStück 5"
        \new Staff \mus
        }
}

HTH,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Mittwoch, 18. Januar 2012, 02:30
Hallo,

hier noch eine Fassung wie ich sie bevorzugen würde.

Der Code liefert ein normales Inhaltsverzeichnes, ein alphabetisch geordnetes und einen alphabetisch sortierten Index mit Initialen. Die Einträge sind verlinkt, sodas beim anklicken zur entsprechenden Seite im book gesprungen wird. Alle Verzeichnisse benutzen drei Kolumnen: Stück - Komponist - Seite.

Die Anwendung sollte sich aus dem Code ergeben (hoffe ich, wenn nicht, dann fragen). Was ich nicht hinbekommen habe, ist das Einfügen von gepunkteten Linien (d.h. es geht schon, hat aber nicht zu einem überzeugenden Ergebnis geführt und es wäre dann auch hard-coded und keine bloße Option mehr)


\version "2.14.2"

% Thanks to Jan-Peter Vogt
% http://old.nabble.com/v2.15.24%3A-void-%2C-scheme--or-music-function-in-toc-section--td33144901.html

% Code taken from toc-init.ly and modified
% see also: http://lsr.dsi.unimi.it/LSR/Item?id=763

\pointAndClickOff

#(use-modules (srfi srfi-1))

#(define (delete-eq-cdr lst)
        "In einer Liste von Listen werden Einträge gelöscht,
  falls der cdr des (aufeinanderfolgenden) Listenelements identisch ist.
  eg. '((a 1 2 3)
        (b 1 2 3)
        (c 1 2 3)
        (d 2 3 4))
       
   -> '((c 1 2 3)
        (d 2 3 4))
 "
        (fold-right (lambda (elem ret)
                  (if (equal? (cdr elem) (cdr (first ret)))
                      ret
                      (cons elem ret)))
          (list (last lst))
          lst))
         
% nach: http://lsr.dsi.unimi.it/LSR/Snippet?id=464

#(define-markup-command (columns layout props text) (markup?)
  (let* ((text-rev (if (string? text)
                       text
                       (markup->string text)))
         (arg (if (= (string-length text-rev) 1)
                  (string-append text-rev "#")
                  text-rev))
         (args (string-split arg #\#))
         ;; currently not used!
         (line-width (/ (chain-assoc-get 'line-width props
                (ly:output-def-lookup layout 'line-width))
              (max (length args) 1))))
        (interpret-markup layout props
          (make-line-markup (map (lambda (line)
                         (markup
                           ;#:box
                           #:pad-to-box `(0 . 31) '(0 . 2)
                           #:override `(50 . 50)
                           line))
                 args)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% CUSTOMTOC

#(define-public (add-customtoc-item! markup-symbol text . lab)
  #f)
#(define-public (customtoc-items)
  #f)

#(let ((customtoc-item-list (list)))
     (set! add-customtoc-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "customtoc"))))
                    (set! customtoc-item-list
                      (cons (list label markup-symbol text)
                            customtoc-item-list))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! customtoc-items (lambda ()
               (reverse customtoc-item-list))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ABCTOC

#(define-public (add-abctoc-item! markup-symbol text . lab) #f)
#(define-public (abctoc-items) #f)

#(let ((abctoc-item-list (list)))
     (set! add-abctoc-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "abctoc"))))
                    (set! abctoc-item-list
                      ;; We insert index items sorted from the beginning on and do
                      ;; not sort them later - this saves pretty much computing time
                      (insert-alphabetical-sorted! (list label markup-symbol text)
                        abctoc-item-list))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! abctoc-items (lambda ()
               abctoc-item-list)))

#(define (insert-alphabetical-sorted! iitem ilist)
        (if
          (null? ilist) (list iitem)
          (if
            (string-ci<? (caddr iitem) (caddr (car ilist))) (cons iitem ilist)
            (cons (car ilist) (insert-alphabetical-sorted! iitem (cdr ilist))))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% INDEX

#(define-public (add-index-item! markup-symbol text . lab) #f)
#(define-public (index-items) #f)

#(let ((index-item-list (list)))
     (set! add-index-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "index"))))
                    (set! index-item-list
                      ;; We insert index items sorted from the beginning on and do
                      ;; not sort them later - this saves pretty much computing time
                      (delete-eq-cdr (insert-alphabetical-sorted! (list label markup-symbol text)
                          index-item-list)))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! index-items (lambda ()
               index-item-list)))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PAPER

\paper {
  customTocTitleMarkup = \markup  \column {
    \vspace #2
    \fill-line { \null \fontsize #5  "Inhaltsverzeichnis" \null }
    \vspace #3
  }
  customTocItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'customtoc:text 
      \fromproperty #'customtoc:page
    }
  }
 
 
  abctocTitleMarkup = \markup \column {
    \vspace #2
    \fill-line { \null \fontsize #5 "Alphabetisches Inhaltsverzeichnis" \null }
    \vspace #3
  }
  abcTocItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'abctoc:text
      \fromproperty #'abctoc:page
    }
  }
 
  indexTitleMarkup = \markup \column {
    \vspace #2
    \fill-line { \null \fontsize #5 "Alphabetischer Index" \null }
    \vspace #3
  }
  indexItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'index:text
      \fromproperty #'index:page }
    \hspace #5
  }
  indexSectionMarkup = \markup { \hspace #6 \override #'(baseline-skip . 1) \column  {
      \vspace #0.7
      \fill-line { \bold \fontsize #3 \fromproperty #'index:text \null }
      \null
    }
  }
 
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% custom-table-of-contents

#(define-markup-list-command (custom-table-of-contents layout props) ()
  ( _i "Outputs the table of contents, using the paper variable
@code{tocTitleMarkup} for its title, then the list of lines
built using the @code{tocItem} music function
Usage: @code{\\markuplist \\table-of-contents}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'customTocTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (customtoc-item)
                       (let ((label (car customtoc-item))
                             (customtoc-markup (cadr customtoc-item))
                             (text (caddr customtoc-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'customtoc:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'customtoc:text (markup #:with-link label #:columns text))
                                          (cons 'customtoc:label label))
                                    props)
                              (ly:output-def-lookup layout customtoc-markup))))
               (customtoc-items)))))
               
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% abc-table-of-contents

#(define-markup-list-command (abc-table-of-contents layout props) ()
  ( _i "Outputs an alphabetical sorted index, using the paper
  variable @code{indexTitleMarkup} for its title, then the list of
  lines built using the @code{indexItem} music function
  Usage: @code{\\markuplines \\index}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'abctocTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (abctoc-item)
                       (let ((label (car abctoc-item))
                             (abctoc-markup (cadr abctoc-item))
                             (text (caddr abctoc-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'abctoc:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'abctoc:text (markup #:with-link label #:columns text))
                                          (cons 'abctoc:label label)
                                    )
                                    props)
                              (ly:output-def-lookup layout abctoc-markup))))
               (abctoc-items)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% index

#(define-markup-list-command (index layout props) ()
  ( _i "Outputs an alphabetical sorted index, using the paper
  variable @code{indexTitleMarkup} for its title, then the list of
  lines built using the @code{indexItem} music function
  Usage: @code{\\markuplines \\index}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'indexTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (index-item)
                       (let ((label (car index-item))
                             (index-markup (cadr index-item))
                             (text (caddr index-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'index:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'index:text (markup #:with-link label #:columns text))
                                          (cons 'indextoc:label label)
                                    )
                                    props)
                              (ly:output-def-lookup layout index-markup))))
               (index-items)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
abcTocItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the alphabetical table of content,
    using the @code{abcTocItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-abctoc-item! 'abcTocItemMarkup new-text)))

indexItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-index-item! 'indexItemMarkup new-text)))   

indexSection =
#(define-music-function (parser location text) (markup?)
  "Add a section line to the alphabetical index, using @code{indexSectionMarkup} paper variable
   markup. This can be used to divide the alphabetical index into different sections,
   one section for each first letter."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-index-item! 'indexSectionMarkup new-text)))

customTocItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the table of content,
    using the @code{customTocItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-customtoc-item! 'customTocItemMarkup new-text)))
%}

indexItems =
#(define-music-function (parser location text) (markup?)
  (let* ((text-rev (if (string? text)
                       text
                       (markup->string text)))
         
         (args (string-split text-rev #\#))
         (initial (string-upcase (substring (car args) 0 1)))
         (label (gensym "index-item")))
        (add-abctoc-item! 'abcTocItemMarkup text-rev label)
        (add-index-item! 'indexItemMarkup text-rev label)
        (add-index-item! 'indexSectionMarkup initial label)
        (add-customtoc-item! 'customTocItemMarkup text-rev label)))

% ------- test

mus = { \key c\minor \time 2/4 r8 g'[ g' g'] ees'2 }

\book {
  \bookpart {
    \markuplines
    %\markuplist  % 2.15.24
    \custom-table-of-contents
            }
  \bookpart {
    \markuplines
    %\markuplist  % 2.15.24
    \abc-table-of-contents
            }
  \bookpart {
    \indexItems "Symphony No. 5#Ludwig van Beethoven"
    \new Staff { \mus }
            }
    \bookpart {
    \indexItems "Te Deum#M.A. Charpentier"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Concerto#A. Vivaldi"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Magnificat#J.S. Bach"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Stabat Mater#Pergolesi"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Cosi fan tutte#W.A. Mozart"
    \new Staff \mus
  }
  \bookpart {
    \indexItems "Alphabetischer Index"   
    \markuplines
    %\markuplist % 2.15.24
    \index
  }
}


Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: fairsein am Donnerstag, 12. April 2012, 17:43
Hallo,

Ich habe mal eine Frage zu dem Inhaltsverzeichnis. Wie kann man im Inhaltsverzeichnis Titel und Interpret tauschen?

Gruß fairsein
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Donnerstag, 12. April 2012, 19:25
Zitat von: fairsein
Wie kann man im Inhaltsverzeichnis Titel und Interpret tauschen?

Nun, falls Du meine Definition aus meinem letzten post in diesem Threads benutzten willst, so vertausche beide Angaben.

\indexItems "Cosi fan tutte#W.A. Mozart"

wird dann zu:

\indexItems "W.A. Mozart#Cosi fan tutte"


Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: fairsein am Donnerstag, 12. April 2012, 22:00
Ich wollte das aber nur im ersten Inhaltsverzeichnis, wo nach Seiten geordnet wird tauschen und das Alphabetische Inhaltsverzeichnis nach Singtitel sortiert lassen, so wie es jetzt berets ist..

Tut mir Leid, dass ich mich nicht konkret genug ausgedrückt haben.

Gruß fairsein
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Freitag, 13. April 2012, 03:03
So?

->Anhang

Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: complanar am Freitag, 13. April 2012, 09:46
Hallo harm, du hast ja den Code von mir verändert,

Dazu habe ich den Code den Du hier im Forum ja schon gefunden hattest etwas verändert.

#(define (insert-alphabetical-sorted! iitem ilist)
  (if
    (null? ilist) (list iitem)
    (if
      (string-ci<? (cadddr iitem) (cadddr (car ilist))) (cons iitem ilist)
      (cons (car ilist) (insert-alphabetical-sorted! iitem (cdr ilist))))))


indexItem =
#(define-music-function (parser location sorttext) (markup?)
   "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup."
   (let ((text sorttext))
   (add-index-item! 'indexItemMarkup text sorttext)))

% ---------------------------------------------------------------

In diesem Zusammenhang möchte ich auf etwas hinweisen, das du möglicherweise übersehen hast. Wenn du direkt nach dem normalen Text sortieren lässt (so wie du indexItem umdefiniert hast), dann gibt es Probleme bei der Sortierung, da die in der Funktion insert-alphabetical-sorted! "string-ci>" zum Sortieren verwendet wird und dieser Vergleich das Markup nicht korrekt sortiert, wenn Sonderzeichen, weitere Markupbefehle usw. enthalten sind. Wenn du das so machst, dann solltest du vorher das Markup in einen String umwandeln, also z.B. so:


indexItem =
#(define-music-function (parser location sorttext) (markup?)
   "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup."
   (let ((text (markup->string sorttext)))
   (add-index-item! 'indexItemMarkup text sorttext)))

Das erste Argument von \indexItem ist dann überflüssig. Ich hatte es mit Absicht hinzugefügt, damit man auch thematisch sortierte Inhaltsverzeichnisse hinzufügen kann, deren Sortierstring dann ja dann vom eigentlichen angezeigten Eintrag abweichen muss.

Grüße, complanar
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Samstag, 14. April 2012, 11:36
Hallo complanar,

Zitat
Hallo harm, du hast ja den Code von mir verändert, [...]

Vielen Dank für Deinen ursprünglichen Code. Er hat mir sehr weitergeholfen.

Zitat
In diesem Zusammenhang möchte ich auf etwas hinweisen, das du möglicherweise übersehen hast. Wenn du direkt nach dem normalen Text sortieren lässt (so wie du indexItem umdefiniert hast), dann gibt es Probleme bei der Sortierung, da die in der Funktion insert-alphabetical-sorted! "string-ci>" zum Sortieren verwendet wird und dieser Vergleich das Markup nicht korrekt sortiert, wenn Sonderzeichen, weitere Markupbefehle usw. enthalten sind. Wenn du das so machst, dann solltest du vorher das Markup in einen String umwandeln, [...]

Völlig richtig. Das hatte ich in meinem Post vom 13.1.2012 tatsächlich übersehen. Im Code vom 18.1. ist es allerdings schon korrigiert.


Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Jolander am Montag, 29. April 2013, 10:42
Leider haut mir die aktuelle Version beim vorliegenden Code

ein paar Fehlermedungen um die Ohren!

Analysieren...
c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:84:16: Fehler: Ungültige Fluchtsequenz: »\markuplines«
           
                \markuplines \table-of-contents

c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:84:16: Fehler: syntax error, unexpected STRING
           
                \markuplines \table-of-contents

c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:84:29: Fehler: Ungültige Fluchtsequenz: »\table-of-contents«
           \markuplines
                             \table-of-contents

c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:87:16: Fehler: Ungültige Fluchtsequenz: »\markuplines«
           
                \markuplines \index

c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:87:16: Fehler: syntax error, unexpected STRING
           
                \markuplines \index

c:/users/guido/appdata/local/temp/frescobaldi-j7u6hb/tmp1zsusd/document.ly:87:29: Fehler: Ungültige Fluchtsequenz: »\index«
           \markuplines
                             \index

Interpretation der Musik...


Dargestellt werden nur ein paar Noten und fertig.

Ich habe den hier eingestellten Code mit copy und past übernommen nund weder ergänzt noch verändert

Was muss ich wo ändern?

Gruß Guido
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Be-3 am Montag, 29. April 2013, 11:30
Hallo Guido,

ich weiß zwar nicht genau, welchen der hier bereits eingestellen Codes Du meinst, kann mir aber denken, wo der Hund im Pfeffer liegt:
Mittlerweile wurde \markuplines komplett gestrichen und heißt jetzt \markuplist.

Da Du offensichtlich Frescobaldi benutzt, gibt es dort für solche Fälle im Tools-Menü auch die convert-ly-Funktion, die versionsspezifische Anpassungen automatisch vornimmt. Natürlich geht das auch ohne Frescobaldi, und zwar über die Kommandozeile wie hier beschrieben (http://www.lilypond.org/doc/v2.16/Documentation/usage/invoking-convert_002dly.de.html).

Viele Grüße
Torsten
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Jolander am Montag, 29. April 2013, 13:01
Geht, Klasse!

nachstehend der aktuallisierte Code:
\version "2.16.0"

% Thanks to Jan-Peter Vogt
% http://old.nabble.com/v2.15.24%3A-void-%2C-scheme--or-music-function-in-toc-section--td33144901.html

% Code taken from toc-init.ly and modified
% see also: http://lsr.dsi.unimi.it/LSR/Item?id=763

\pointAndClickOff

#(use-modules (srfi srfi-1))

#(define (delete-eq-cdr lst)
        "In einer Liste von Listen werden Einträge gelöscht,
  falls der cdr des (aufeinanderfolgenden) Listenelements identisch ist.
  eg. '((a 1 2 3)
        (b 1 2 3)
        (c 1 2 3)
        (d 2 3 4))
       
   -> '((c 1 2 3)
        (d 2 3 4))
 "
        (fold-right (lambda (elem ret)
                  (if (equal? (cdr elem) (cdr (first ret)))
                      ret
                      (cons elem ret)))
          (list (last lst))
          lst))
         
% nach: http://lsr.dsi.unimi.it/LSR/Snippet?id=464

#(define-markup-command (columns layout props text) (markup?)
  (let* ((text-rev (if (string? text)
                       text
                       (markup->string text)))
         (arg (if (= (string-length text-rev) 1)
                  (string-append text-rev "#")
                  text-rev))
         (args (string-split arg #\#))
         ;; currently not used!
         (line-width (/ (chain-assoc-get 'line-width props
                (ly:output-def-lookup layout 'line-width))
              (max (length args) 1))))
        (interpret-markup layout props
          (make-line-markup (map (lambda (line)
                         (markup
                           ;#:box
                           #:pad-to-box `(0 . 31) '(0 . 2)
                           #:override `(50 . 50)
                           line))
                 args)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% CUSTOMTOC

#(define-public (add-customtoc-item! markup-symbol text . lab)
  #f)
#(define-public (customtoc-items)
  #f)

#(let ((customtoc-item-list (list)))
     (set! add-customtoc-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "customtoc"))))
                    (set! customtoc-item-list
                      (cons (list label markup-symbol text)
                            customtoc-item-list))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! customtoc-items (lambda ()
               (reverse customtoc-item-list))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ABCTOC

#(define-public (add-abctoc-item! markup-symbol text . lab) #f)
#(define-public (abctoc-items) #f)

#(let ((abctoc-item-list (list)))
     (set! add-abctoc-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "abctoc"))))
                    (set! abctoc-item-list
                      ;; We insert index items sorted from the beginning on and do
                      ;; not sort them later - this saves pretty much computing time
                      (insert-alphabetical-sorted! (list label markup-symbol text)
                        abctoc-item-list))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! abctoc-items (lambda ()
               abctoc-item-list)))

#(define (insert-alphabetical-sorted! iitem ilist)
        (if
          (null? ilist) (list iitem)
          (if
            (string-ci<? (caddr iitem) (caddr (car ilist))) (cons iitem ilist)
            (cons (car ilist) (insert-alphabetical-sorted! iitem (cdr ilist))))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% INDEX

#(define-public (add-index-item! markup-symbol text . lab) #f)
#(define-public (index-items) #f)

#(let ((index-item-list (list)))
     (set! add-index-item!
       (lambda (markup-symbol text . lab)
               (let ((label (if (> (length lab) 0) (car lab) (gensym "index"))))
                    (set! index-item-list
                      ;; We insert index items sorted from the beginning on and do
                      ;; not sort them later - this saves pretty much computing time
                      (delete-eq-cdr (insert-alphabetical-sorted! (list label markup-symbol text)
                          index-item-list)))
                    (make-music 'EventChord
                      'page-marker #t
                      'page-label label
                      'elements (list (make-music 'LabelEvent
                              'page-label label))))))
     (set! index-items (lambda ()
               index-item-list)))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PAPER

\paper {
  customTocTitleMarkup = \markup  \column {
    \vspace #2
    \fill-line { \null \fontsize #5  "Inhaltsverzeichnis" \null }
    \vspace #3
  }
  customTocItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'customtoc:text 
      \fromproperty #'customtoc:page
    }
  }
 
 
  abctocTitleMarkup = \markup \column {
    \vspace #2
    \fill-line { \null \fontsize #5 "Alphabetisches Inhaltsverzeichnis" \null }
    \vspace #3
  }
  abcTocItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'abctoc:text
      \fromproperty #'abctoc:page
    }
  }
 
  indexTitleMarkup = \markup \column {
    \vspace #2
    \fill-line { \null \fontsize #5 "Alphabetischer Index" \null }
    \vspace #3
  }
  indexItemMarkup = \markup { \hspace #6 \large \override #'(line-width . 100) \fill-line {
      \fromproperty #'index:text
      \fromproperty #'index:page }
    \hspace #5
  }
  indexSectionMarkup = \markup { \hspace #6 \override #'(baseline-skip . 1) \column  {
      \vspace #0.7
      \fill-line { \bold \fontsize #3 \fromproperty #'index:text \null }
      \null
    }
  }
 
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% custom-table-of-contents

#(define-markup-list-command (custom-table-of-contents layout props) ()
  ( _i "Outputs the table of contents, using the paper variable
@code{tocTitleMarkup} for its title, then the list of lines
built using the @code{tocItem} music function
Usage: @code{\\markuplist \\table-of-contents}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'customTocTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (customtoc-item)
                       (let ((label (car customtoc-item))
                             (customtoc-markup (cadr customtoc-item))
                             (text (caddr customtoc-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'customtoc:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'customtoc:text (markup #:with-link label #:columns text))
                                          (cons 'customtoc:label label))
                                    props)
                              (ly:output-def-lookup layout customtoc-markup))))
               (customtoc-items)))))
               
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% abc-table-of-contents

#(define-markup-list-command (abc-table-of-contents layout props) ()
  ( _i "Outputs an alphabetical sorted index, using the paper
  variable @code{indexTitleMarkup} for its title, then the list of
  lines built using the @code{indexItem} music function
  Usage: @code{\\markuplist \\index}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'abctocTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (abctoc-item)
                       (let ((label (car abctoc-item))
                             (abctoc-markup (cadr abctoc-item))
                             (text (caddr abctoc-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'abctoc:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'abctoc:text (markup #:with-link label #:columns text))
                                          (cons 'abctoc:label label)
                                    )
                                    props)
                              (ly:output-def-lookup layout abctoc-markup))))
               (abctoc-items)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% index

#(define-markup-list-command (index layout props) ()
  ( _i "Outputs an alphabetical sorted index, using the paper
  variable @code{indexTitleMarkup} for its title, then the list of
  lines built using the @code{indexItem} music function
  Usage: @code{\\markuplist \\index}" )
  (cons (interpret-markup layout props
          (ly:output-def-lookup layout 'indexTitleMarkup))
        (space-lines (chain-assoc-get 'baseline-skip props)
          (map (lambda (index-item)
                       (let ((label (car index-item))
                             (index-markup (cadr index-item))
                             (text (caddr index-item)))
                            (interpret-markup
                              layout
                              (cons (list (cons 'index:page
                                            (markup #:with-link label #:page-ref label "XXX" "?"))
                                          (cons 'index:text (markup #:with-link label #:columns text))
                                          (cons 'indextoc:label label)
                                    )
                                    props)
                              (ly:output-def-lookup layout index-markup))))
               (index-items)))))

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
abcTocItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the alphabetical table of content,
    using the @code{abcTocItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-abctoc-item! 'abcTocItemMarkup new-text)))

indexItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the alphabetical index, using the @code{indexItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-index-item! 'indexItemMarkup new-text)))   

indexSection =
#(define-music-function (parser location text) (markup?)
  "Add a section line to the alphabetical index, using @code{indexSectionMarkup} paper variable
   markup. This can be used to divide the alphabetical index into different sections,
   one section for each first letter."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-index-item! 'indexSectionMarkup new-text)))

customTocItem =
#(define-music-function (parser location text) (markup?)
  "Add a line to the table of content,
    using the @code{customTocItemMarkup} paper variable markup."
  (let* ((new-text (if (string? text)
                       text
                       (markup->string text))))
        (add-customtoc-item! 'customTocItemMarkup new-text)))
%}

indexItems =
#(define-music-function (parser location text) (markup?)
  (let* ((text-rev (if (string? text)
                       text
                       (markup->string text)))
         
         (args (string-split text-rev #\#))
         (initial (string-upcase (substring (car args) 0 1)))
         (label (gensym "index-item")))
        (add-abctoc-item! 'abcTocItemMarkup text-rev label)
        (add-index-item! 'indexItemMarkup text-rev label)
        (add-index-item! 'indexSectionMarkup initial label)
        (add-customtoc-item! 'customTocItemMarkup text-rev label)))

% ------- test

mus = { \key c\minor \time 2/4 r8 g'[ g' g'] ees'2 }

\book {
  \bookpart {
    \markuplist
    %\markuplist  % 2.15.24
    \custom-table-of-contents
            }
  \bookpart {
    \markuplist
    %\markuplist  % 2.15.24
    \abc-table-of-contents
            }
  \bookpart {
    \indexItems "Symphony No. 5#Ludwig van Beethoven"
    \new Staff { \mus }
            }
    \bookpart {
    \indexItems "Te Deum#M.A. Charpentier"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Concerto#A. Vivaldi"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Magnificat#J.S. Bach"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Stabat Mater#Pergolesi"
    \new Staff \mus
            }
    \bookpart {
    \indexItems "Cosi fan tutte#W.A. Mozart"
    \new Staff \mus
  }
  \bookpart {
    \indexItems "Alphabetischer Index"   
    \markuplist
    %\markuplist % 2.15.24
    \index
  }
}
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Jolander am Dienstag, 6. August 2013, 10:10
Und er macht ein schönes Inhaltsverzeichnis....

nur nach einer halben DIN A4 Seite des Alphabetischen Index fügt Lilypond einen Seitenumbruch an.

Habe ich was Übersehnen?

Gruß und Danke Guido
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Dienstag, 13. August 2013, 22:48
Hallo Jolander,

Zitat von: Jolander
Und er macht ein schönes Inhaltsverzeichnis....
nur nach einer halben DIN A4 Seite des Alphabetischen Index fügt Lilypond einen Seitenumbruch an.
Habe ich was Übersehnen?

ich habe ein bißchen rumprobiert, aber ich konnte Dein Problem nicht nachstellen.
Kannst Du einen Beispiel-COde posten?

Gruß,
  Harm
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: Jolander am Freitag, 16. August 2013, 11:51
Hallo Harm,

danke für die Antwort.

Eigentlich habe ich hier jetzt einen Beispielcode posten wollen damit es deutlicher wird. Da ich mich dabei noch mal ein wenig mit meinem Inhaltsverzeichnis beschäftigen musste hat sich das Problem via plötzlicher Geistesblitz behoben.

Es lag an der Grundeinstellung im \book Bereich. Dort habe ich, damit die Notenzeilen gleichmäßig auf den einzelnen Seiten verteilen, in der \paper - Umgebung folgendes definiert:

ragged-bottom = ##f          %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat
ragged-last-bottom = ##f   %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat

dabei habe ich vergessen, das sich dieses auf alle Seiten des \book auswirkt.

Mein Lösungsansatz ist nun, das was ich vorne anschalte ich für mein Inhaltsverzeichnis wieder abschalten muss. Sieht als Code bei mir dann so aus, wobei  page-count=#1 im Moment dazu dient, die zwei Titel die auf eine 2te Seite rutschen (die Erste ist jetzt tatsächlich voll  ;) ) noch mit auf die 1te Seite gedruckt werden
:
%Alphabetischer Index 
  \bookpart {
     \paper {
     right-margin =1.0\cm %rechter Rand
     left-margin = 1.0\cm %linker Rand
     page-count = #1  %Anzahl der Blätter (bei Einzelstimmen)
     ragged-bottom = ##t %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat
       }
    \indexItems "Alphabetischer Index"   
    \markuplist
    %\markuplist % 2.15.24
    \index
  }

 
} %Bläserheft Ende


Ich hoffe, ich liege mit meinem Ansatz nicht ganz daneben?

Gruß
Guido

 
Titel: Re: Inhaltsverzeichnis modifizieren
Beitrag von: harm6 am Freitag, 16. August 2013, 12:36
Hallo Guido,

Zitat von: Jolander
Eigentlich habe ich hier jetzt einen Beispielcode posten wollen damit es deutlicher wird. Da ich mich dabei noch mal ein wenig mit meinem Inhaltsverzeichnis beschäftigen musste hat sich das Problem via plötzlicher Geistesblitz behoben.
Genau das ist einer der Gründe warum man immer einen (minimalen) Beispiel-Code posten sollte. Wenn man gezwungen ist das Problem auf das wirklich notwendige zu reduzieren kommt man doch recht häufig drauf, was falsch/schlecht war. ;)


Zitat von: Jolander
Es lag an der Grundeinstellung im \book Bereich. Dort habe ich, damit die Notenzeilen gleichmäßig auf den einzelnen Seiten verteilen, in der \paper - Umgebung folgendes definiert:

ragged-bottom = ##f          %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat
ragged-last-bottom = ##f   %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat

dabei habe ich vergessen, das sich dieses auf alle Seiten des \book auswirkt.

Mein Lösungsansatz ist nun, das was ich vorne anschalte ich für mein Inhaltsverzeichnis wieder abschalten muss.
[...]
Ich hoffe, ich liege mit meinem Ansatz nicht ganz daneben?

Sieht gut aus (ohne es selbst kompiliert zu haben).
Natürlich stimmt der Kommentar hier nicht mehr.:
Zitat
     ragged-bottom = ##t %Verteilt die Notenreihen gleichmßig auf das definierte Papierformat
;)

Gruß,
  Harm