Re: Toc with counter
Pierre Perol-Schneider writes: > How about : > > \version "2.19.82" > > #(set-default-paper-size "a6") > > #(define counter-alist '()) > > #(define-markup-command (counter layout props name) (string?) > "Increases and prints out the value of the given counter named @var{name}. > If the counter does not yet exist, it is initialized with 1." > (let* ((oldval (assoc-ref counter-alist name)) > (newval (if (number? oldval) (+ oldval 1) 1))) > (set! counter-alist (assoc-set! counter-alist name newval)) > (interpret-markup layout props > (markup (number->string (round newval)) > > \markup { > \column { > "counter :" > \fill-line { > \counter #"counter" \counter #"counter" \counter #"counter" > \counter #"counter" \counter #"counter" \counter #"counter" > \counter #"counter" > } > \null > "\pattern :" > \fill-line { \pattern #7 #X #7 \counter #"pattern" } > \null > "\fill-with-pattern :" > \fill-with-pattern #7 #RIGHT \counter #"fill-with-pattern" \null \null > } > } Too much unrelated clutter for a regtest. I committed something more to the point. -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
How about : \version "2.19.82" #(set-default-paper-size "a6") #(define counter-alist '()) #(define-markup-command (counter layout props name) (string?) "Increases and prints out the value of the given counter named @var{name}. If the counter does not yet exist, it is initialized with 1." (let* ((oldval (assoc-ref counter-alist name)) (newval (if (number? oldval) (+ oldval 1) 1))) (set! counter-alist (assoc-set! counter-alist name newval)) (interpret-markup layout props (markup (number->string (round newval)) \markup { \column { "counter :" \fill-line { \counter #"counter" \counter #"counter" \counter #"counter" \counter #"counter" \counter #"counter" \counter #"counter" \counter #"counter" } \null "\pattern :" \fill-line { \pattern #7 #X #7 \counter #"pattern" } \null "\fill-with-pattern :" \fill-with-pattern #7 #RIGHT \counter #"fill-with-pattern" \null \null } } 2018-07-02 23:47 GMT+02:00 David Kastrup : > Pierre Perol-Schneider writes: > > >> ... counter shows only pairs. > > " counter shows only even numbers"... sorry. > > Pierre > > This is an abomination. > > Tracker issue: 5365 (https://sourceforge.net/p/testlilyissues/issues/5365/ > ) > Rietveld issue: 357740043 (https://codereview.appspot.com/357740043) > Issue description: > Avoid multiple evaluation of markups \pattern \fill-with-pattern > For markup commands with side effects like counters, that could end > up being a nuisance. > > Want to write a nice concise regtest? > > -- > David Kastrup > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
Pierre Perol-Schneider writes: >> ... counter shows only pairs. > " counter shows only even numbers"... sorry. > Pierre This is an abomination. Tracker issue: 5365 (https://sourceforge.net/p/testlilyissues/issues/5365/) Rietveld issue: 357740043 (https://codereview.appspot.com/357740043) Issue description: Avoid multiple evaluation of markups \pattern \fill-with-pattern For markup commands with side effects like counters, that could end up being a nuisance. Want to write a nice concise regtest? -- David Kastrup ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
So here's my workaround (simply dividing de counter by 2) : \version "2.19.82" %% or 2.18 %%% Counter defs % => http://lsr.di.unimi.it/LSR/Item?id=543 #(define counter-alist '()) #(define-markup-command (counter layout props name) (string?) "Increases and prints out the value of the given counter named @var{name}. If the counter does not yet exist, it is initialized with 1." (let* ((oldval (assoc-ref counter-alist name)) (newval (if (number? oldval) (+ oldval 1) 1))) (set! counter-alist (assoc-set! counter-alist name newval)) (interpret-markup layout props ;; => here it goes : (markup (number->string (/ newval 2)) #(define-markup-command (setcounter layout props name value) (string? number?) "Set the given counter named @var{name} to the given @var{value} and prints out the value. The counter does not yet have to exist." (set! counter-alist (assoc-set! counter-alist name (- value 1))) (interpret-markup layout props (make-counter-markup name))) %% Test: \book { \bookpart { \markuplist \table-of-contents \paper { %% comment the following line: tocItemMarkup = \tocItemWithDotsMarkup } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } } Cheers, Pierre 2018-07-02 22:43 GMT+02:00 Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com>: > Pretty smart Saul. > However, dots are crossing the text so the output looks strange. > Cheers, > Pierre > > 2018-07-02 22:27 GMT+02:00 Saul Tobin : > >> Try this: >> >> tocItemWithDotsMarkupFixed = \markup { >> \fill-line { >> \fromproperty #'toc:text >> \fill-with-pattern #1 #RIGHT . "" \fromproperty #'toc:page >> } >> } >> >> \paper { >> tocItemMarkup = \tocItemWithDotsMarkupFixed >> } >> >> On Mon, Jul 2, 2018 at 12:57 PM Pierre Perol-Schneider < >> pierre.schneider.pa...@gmail.com> wrote: >> >>> Thank you Saul. >>> I understood that fill-with-pattern initiated the problem but could not >>> see why. So thank you for your detailed explanation. >>> Now, if someone has a workaround... >>> >>> Cheers, >>> Pierre >>> >>> 2018-07-02 21:12 GMT+02:00 Saul Tobin : >>> If I understand correctly, counter gets incremented whenever interpret-markup is called on a markup containing the counter. If you look in define-markup-commands.scm, \fill-line calls interpret-markup only once, but \fill-with-pattern calls interpret-markup twice, first to find out the width of the left and right text, then it calls interpret-markup again on the entire line. On Mon, Jul 2, 2018 at 9:01 AM Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com> wrote: > > ... counter shows only pairs. > " counter shows only even numbers"... sorry. > Pierre > > 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < > pierre.schneider.pa...@gmail.com>: > >> Hi All, >> >> I'd like to add a counter (LSR 543) in a table of content. >> However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. >> Any idea how to solve this ? >> >> Snippet : >> >> >> \version "2.19.82" %% or 2.18 >> >> %%% Counter defs >> % => http://lsr.di.unimi.it/LSR/Item?id=543 >> >> #(define counter-alist '()) >> >> #(define-markup-command (counter layout props name) (string?) >> "Increases and prints out the value of the given counter named >> @var{name}. >> If the counter does not yet exist, it is initialized with 1." >> (let* ((oldval (assoc-ref counter-alist name)) >> (newval (if (number? oldval) (+ oldval 1) 1))) >> (set! counter-alist (assoc-set! counter-alist name newval)) >> (interpret-markup layout props >> (markup (number->string newval) >> >> #(define-markup-command (setcounter layout props name value) (string? >> number?) >> "Set the given counter named @var{name} to the given @var{value} >> and prints >> out the value. The counter does not yet have to exist." >> (set! counter-alist (assoc-set! counter-alist name (- value 1))) >> (interpret-markup layout props (make-counter-markup name))) >> >> %% Test: >> >> \book { >> \bookpart { >> \markuplist \table-of-contents >> \paper { >> %% comment the following line: >> tocItemMarkup = \tocItemWithDotsMarkup >> } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> } >> >> >>
Re: Toc with counter
Pretty smart Saul. However, dots are crossing the text so the output looks strange. Cheers, Pierre 2018-07-02 22:27 GMT+02:00 Saul Tobin : > Try this: > > tocItemWithDotsMarkupFixed = \markup { > \fill-line { > \fromproperty #'toc:text > \fill-with-pattern #1 #RIGHT . "" \fromproperty #'toc:page > } > } > > \paper { > tocItemMarkup = \tocItemWithDotsMarkupFixed > } > > On Mon, Jul 2, 2018 at 12:57 PM Pierre Perol-Schneider < > pierre.schneider.pa...@gmail.com> wrote: > >> Thank you Saul. >> I understood that fill-with-pattern initiated the problem but could not >> see why. So thank you for your detailed explanation. >> Now, if someone has a workaround... >> >> Cheers, >> Pierre >> >> 2018-07-02 21:12 GMT+02:00 Saul Tobin : >> >>> If I understand correctly, counter gets incremented whenever >>> interpret-markup is called on a markup containing the counter. If you look >>> in define-markup-commands.scm, \fill-line calls interpret-markup only once, >>> but \fill-with-pattern calls interpret-markup twice, first to find out the >>> width of the left and right text, then it calls interpret-markup again on >>> the entire line. >>> >>> On Mon, Jul 2, 2018 at 9:01 AM Pierre Perol-Schneider < >>> pierre.schneider.pa...@gmail.com> wrote: >>> > ... counter shows only pairs. " counter shows only even numbers"... sorry. Pierre 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com>: > Hi All, > > I'd like to add a counter (LSR 543) in a table of content. > However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. > Any idea how to solve this ? > > Snippet : > > > \version "2.19.82" %% or 2.18 > > %%% Counter defs > % => http://lsr.di.unimi.it/LSR/Item?id=543 > > #(define counter-alist '()) > > #(define-markup-command (counter layout props name) (string?) > "Increases and prints out the value of the given counter named > @var{name}. > If the counter does not yet exist, it is initialized with 1." > (let* ((oldval (assoc-ref counter-alist name)) > (newval (if (number? oldval) (+ oldval 1) 1))) > (set! counter-alist (assoc-set! counter-alist name newval)) > (interpret-markup layout props > (markup (number->string newval) > > #(define-markup-command (setcounter layout props name value) (string? > number?) > "Set the given counter named @var{name} to the given @var{value} and > prints > out the value. The counter does not yet have to exist." > (set! counter-alist (assoc-set! counter-alist name (- value 1))) > (interpret-markup layout props (make-counter-markup name))) > > %% Test: > > \book { > \bookpart { > \markuplist \table-of-contents > \paper { > %% comment the following line: > tocItemMarkup = \tocItemWithDotsMarkup > } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > } > > > TIA, cheers, > Pierre > > > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user >>> >> ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
Try this: tocItemWithDotsMarkupFixed = \markup { \fill-line { \fromproperty #'toc:text \fill-with-pattern #1 #RIGHT . "" \fromproperty #'toc:page } } \paper { tocItemMarkup = \tocItemWithDotsMarkupFixed } On Mon, Jul 2, 2018 at 12:57 PM Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com> wrote: > Thank you Saul. > I understood that fill-with-pattern initiated the problem but could not > see why. So thank you for your detailed explanation. > Now, if someone has a workaround... > > Cheers, > Pierre > > 2018-07-02 21:12 GMT+02:00 Saul Tobin : > >> If I understand correctly, counter gets incremented whenever >> interpret-markup is called on a markup containing the counter. If you look >> in define-markup-commands.scm, \fill-line calls interpret-markup only once, >> but \fill-with-pattern calls interpret-markup twice, first to find out the >> width of the left and right text, then it calls interpret-markup again on >> the entire line. >> >> On Mon, Jul 2, 2018 at 9:01 AM Pierre Perol-Schneider < >> pierre.schneider.pa...@gmail.com> wrote: >> >>> > ... counter shows only pairs. >>> " counter shows only even numbers"... sorry. >>> Pierre >>> >>> 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < >>> pierre.schneider.pa...@gmail.com>: >>> Hi All, I'd like to add a counter (LSR 543) in a table of content. However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. Any idea how to solve this ? Snippet : \version "2.19.82" %% or 2.18 %%% Counter defs % => http://lsr.di.unimi.it/LSR/Item?id=543 #(define counter-alist '()) #(define-markup-command (counter layout props name) (string?) "Increases and prints out the value of the given counter named @var{name}. If the counter does not yet exist, it is initialized with 1." (let* ((oldval (assoc-ref counter-alist name)) (newval (if (number? oldval) (+ oldval 1) 1))) (set! counter-alist (assoc-set! counter-alist name newval)) (interpret-markup layout props (markup (number->string newval) #(define-markup-command (setcounter layout props name value) (string? number?) "Set the given counter named @var{name} to the given @var{value} and prints out the value. The counter does not yet have to exist." (set! counter-alist (assoc-set! counter-alist name (- value 1))) (interpret-markup layout props (make-counter-markup name))) %% Test: \book { \bookpart { \markuplist \table-of-contents \paper { %% comment the following line: tocItemMarkup = \tocItemWithDotsMarkup } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } \bookpart { \tocItem \markup { "Étude" \counter #"counter" } { c' } } } TIA, cheers, Pierre >>> ___ >>> lilypond-user mailing list >>> lilypond-user@gnu.org >>> https://lists.gnu.org/mailman/listinfo/lilypond-user >>> >> > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
Thank you Saul. I understood that fill-with-pattern initiated the problem but could not see why. So thank you for your detailed explanation. Now, if someone has a workaround... Cheers, Pierre 2018-07-02 21:12 GMT+02:00 Saul Tobin : > If I understand correctly, counter gets incremented whenever > interpret-markup is called on a markup containing the counter. If you look > in define-markup-commands.scm, \fill-line calls interpret-markup only once, > but \fill-with-pattern calls interpret-markup twice, first to find out the > width of the left and right text, then it calls interpret-markup again on > the entire line. > > On Mon, Jul 2, 2018 at 9:01 AM Pierre Perol-Schneider < > pierre.schneider.pa...@gmail.com> wrote: > >> > ... counter shows only pairs. >> " counter shows only even numbers"... sorry. >> Pierre >> >> 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < >> pierre.schneider.pa...@gmail.com>: >> >>> Hi All, >>> >>> I'd like to add a counter (LSR 543) in a table of content. >>> However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. >>> Any idea how to solve this ? >>> >>> Snippet : >>> >>> >>> \version "2.19.82" %% or 2.18 >>> >>> %%% Counter defs >>> % => http://lsr.di.unimi.it/LSR/Item?id=543 >>> >>> #(define counter-alist '()) >>> >>> #(define-markup-command (counter layout props name) (string?) >>> "Increases and prints out the value of the given counter named >>> @var{name}. >>> If the counter does not yet exist, it is initialized with 1." >>> (let* ((oldval (assoc-ref counter-alist name)) >>> (newval (if (number? oldval) (+ oldval 1) 1))) >>> (set! counter-alist (assoc-set! counter-alist name newval)) >>> (interpret-markup layout props >>> (markup (number->string newval) >>> >>> #(define-markup-command (setcounter layout props name value) (string? >>> number?) >>> "Set the given counter named @var{name} to the given @var{value} and >>> prints >>> out the value. The counter does not yet have to exist." >>> (set! counter-alist (assoc-set! counter-alist name (- value 1))) >>> (interpret-markup layout props (make-counter-markup name))) >>> >>> %% Test: >>> >>> \book { >>> \bookpart { >>> \markuplist \table-of-contents >>> \paper { >>> %% comment the following line: >>> tocItemMarkup = \tocItemWithDotsMarkup >>> } >>> } >>> \bookpart { >>> \tocItem \markup { "Étude" \counter #"counter" } >>> { c' } >>> } >>> \bookpart { >>> \tocItem \markup { "Étude" \counter #"counter" } >>> { c' } >>> } >>> \bookpart { >>> \tocItem \markup { "Étude" \counter #"counter" } >>> { c' } >>> } >>> } >>> >>> >>> TIA, cheers, >>> Pierre >>> >>> >>> >> ___ >> lilypond-user mailing list >> lilypond-user@gnu.org >> https://lists.gnu.org/mailman/listinfo/lilypond-user >> > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
If I understand correctly, counter gets incremented whenever interpret-markup is called on a markup containing the counter. If you look in define-markup-commands.scm, \fill-line calls interpret-markup only once, but \fill-with-pattern calls interpret-markup twice, first to find out the width of the left and right text, then it calls interpret-markup again on the entire line. On Mon, Jul 2, 2018 at 9:01 AM Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com> wrote: > > ... counter shows only pairs. > " counter shows only even numbers"... sorry. > Pierre > > 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < > pierre.schneider.pa...@gmail.com>: > >> Hi All, >> >> I'd like to add a counter (LSR 543) in a table of content. >> However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. >> Any idea how to solve this ? >> >> Snippet : >> >> >> \version "2.19.82" %% or 2.18 >> >> %%% Counter defs >> % => http://lsr.di.unimi.it/LSR/Item?id=543 >> >> #(define counter-alist '()) >> >> #(define-markup-command (counter layout props name) (string?) >> "Increases and prints out the value of the given counter named >> @var{name}. >> If the counter does not yet exist, it is initialized with 1." >> (let* ((oldval (assoc-ref counter-alist name)) >> (newval (if (number? oldval) (+ oldval 1) 1))) >> (set! counter-alist (assoc-set! counter-alist name newval)) >> (interpret-markup layout props >> (markup (number->string newval) >> >> #(define-markup-command (setcounter layout props name value) (string? >> number?) >> "Set the given counter named @var{name} to the given @var{value} and >> prints >> out the value. The counter does not yet have to exist." >> (set! counter-alist (assoc-set! counter-alist name (- value 1))) >> (interpret-markup layout props (make-counter-markup name))) >> >> %% Test: >> >> \book { >> \bookpart { >> \markuplist \table-of-contents >> \paper { >> %% comment the following line: >> tocItemMarkup = \tocItemWithDotsMarkup >> } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> \bookpart { >> \tocItem \markup { "Étude" \counter #"counter" } >> { c' } >> } >> } >> >> >> TIA, cheers, >> Pierre >> >> >> > ___ > lilypond-user mailing list > lilypond-user@gnu.org > https://lists.gnu.org/mailman/listinfo/lilypond-user > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: Toc with counter
> ... counter shows only pairs. " counter shows only even numbers"... sorry. Pierre 2018-07-02 17:23 GMT+02:00 Pierre Perol-Schneider < pierre.schneider.pa...@gmail.com>: > Hi All, > > I'd like to add a counter (LSR 543) in a table of content. > However, when 'tocItemWithDotsMarkup is set, counter shows only pairs. > Any idea how to solve this ? > > Snippet : > > > \version "2.19.82" %% or 2.18 > > %%% Counter defs > % => http://lsr.di.unimi.it/LSR/Item?id=543 > > #(define counter-alist '()) > > #(define-markup-command (counter layout props name) (string?) > "Increases and prints out the value of the given counter named > @var{name}. > If the counter does not yet exist, it is initialized with 1." > (let* ((oldval (assoc-ref counter-alist name)) > (newval (if (number? oldval) (+ oldval 1) 1))) > (set! counter-alist (assoc-set! counter-alist name newval)) > (interpret-markup layout props > (markup (number->string newval) > > #(define-markup-command (setcounter layout props name value) (string? > number?) > "Set the given counter named @var{name} to the given @var{value} and > prints > out the value. The counter does not yet have to exist." > (set! counter-alist (assoc-set! counter-alist name (- value 1))) > (interpret-markup layout props (make-counter-markup name))) > > %% Test: > > \book { > \bookpart { > \markuplist \table-of-contents > \paper { > %% comment the following line: > tocItemMarkup = \tocItemWithDotsMarkup > } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > \bookpart { > \tocItem \markup { "Étude" \counter #"counter" } > { c' } > } > } > > > TIA, cheers, > Pierre > > > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user