[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Table of Contents - order by page
From: |
Thomas Morley |
Subject: |
Re: Table of Contents - order by page |
Date: |
Tue, 13 Dec 2016 01:33:18 +0100 |
2016-12-13 1:20 GMT+01:00 Thomas Morley <address@hidden>:
> 2016-12-12 2:20 GMT+01:00 Freddy Ouellette <address@hidden>:
>> The table of contents seems to list its items by the order in which they
>> were evaluated by the parser, and not by where they actually appear in the
>> book... Is there a way to avoid this?
>>
>> for example, even though partB comes AFTER partA in the book, and the PAGES
>> in the table of contents are right, partB comes listed first in the TOC
>> which is very annoying, simply because it was evaluated first.
>
>
>
> As far as I understand, then the toc-tems are stored in a list as soon
> as they are seen by the parser.
> The (simplified) list for your example would then look like
> (list "PART B" "PART A")
>
> The table-of-contents-markup-list-command works on this list in the
> order the entries appear. Though, the page-numbers are assigned and
> inserted with delay, _after_ the pages are calculated, i.e. at the
> very end of compilation.
> Thus you can't go back and reorder the table-of-content. Resulting in
> (usually) correct assignmens but appearing in unwanted order (at least
> in your example).
>
> Though, you can reorder the toc-items _before_ table-of-contents work on it.
> For your example one could do:
>
> partB =
> \bookpart {
> \tocItem "PART B"
> \new Staff {
> c4 d e f
> }
> }
>
> partA =
> \bookpart {
> \tocItem "PART A"
> \new Staff {
> c4 d e f
> }
> }
>
> %% Reorder (toc-items):
> %% To be done after all \tocItem-stuff is done and before table-of-contents is
> %% called
> #(let ((t-i (toc-items)))
> ;;;; (1)
> ;;;; watch the original toc-items:
> ;(write t-i)
>
> ;;;; (2)
> ;;;; reset the list, be aware: needs to be a procedure!
> ;;;; (2a)
> ;; doing it manually for each entry:
> ;(set!
> ; toc-items
> ; (lambda ()
> ; (list
> ; (second t-i)
> ; (first t-i))))
> ;;;; (2b)
> ;; in the simple example a reverse would do it already;
> ;(set!
> ; toc-items
> ; (lambda () (reverse t-i)))
> ;
> ;;;; (2c)
> ;; reorder alphabetical
> (set!
> toc-items
> (lambda () (sort t-i (lambda (p q) (string-ci<? (last p) (last q))))))
;; the above will fail sometimes, better to do:
(set!
toc-items
(lambda ()
(sort
t-i
(lambda (p q)
(string-ci<? (markup->string (last p)) (markup->string (last q)))))))
>
> ;;;; (3)
> ;;;; watch the result
> ;(write (toc-items))
> )
>
> \book {
> \bookpart {
>
> \markuplist \table-of-contents
> \paper {
> tocTitleMarkup = \markup \center-column {
> \italic "Contents"
> \vspace #0.3
> }
> tocItemMarkup = \markup {
> \fill-with-pattern
> #1 #RIGHT " . "
> \fromproperty #'toc:text
> \fromproperty #'toc:page
> }
> }
> }
> \bookpart { \partA }
> \bookpart { \partB }
> }
>
> Also, look at:
> http://lsr.di.unimi.it/LSR/Item?id=763
>
> For personal use I made some other codings of this kind, shout if interested.
> They all reorder the toc-items for different use-cases.
>
>
> HTH,
> Harm