Problem with numbering of listings in a book

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with numbering of listings in a book

siddjain
I am writing a book. I use source code blocks as described here:
https://asciidoctor.org/docs/asciidoc-writers-guide/#listing-and-source-code-blocks

but their numbering does not reset when I begin a new chapter.

In every chapter preface I have a

 :listing: 0

Is there some other attribute I need to set to reset the counter of code blocks?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

Alexander Schwartz
The counter for listings is accessible via listing-number. You can clear the attribute or set it to any other numeric value.

The following code snippet

:listing-caption: Listing

.First Listing
[source]
----
Hi
----

:!listing-number:

.Another Listing
[source]
----
Hi
----
leads to the following output
Listing 1. First Listing
Hi

Listing 1. Another Listing
Hi
Tested with Asciidoctor 2.0.10. The manual states: To reset a counter attribute, unset the corresponding attribute using an attribute entry. The attribute entry must be adjacent to a block or else it is ignored.
Alexander Schwartz (alexander.schwartz@gmx.net)
https://www.ahus1.de
Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

siddjain
Hi Alex,

Thanks.

This is working for me with one problem. I have a figure (or it could be a listing or table for that matter) in Chapter 2. It is correctly numbered as Figure 2.10 in that chapter, but when I try to reference it from Chapter 1 using <<chap2.adoc#the-figure>> the reference appears as Figure 1.10. So it does not insert the correct chapter number.

I have following preamble in the chapters

:xrefstyle: short
:listing-number: 0
:figure: 0
:figure-caption: Figure {chapter}.
:listing-caption: Listing {chapter}.
:table-caption: Table {chapter}.

the :listing-number: 0 is resetting listing counter to 0. Similarly :figure:0 resets the figure counter to 0.

and for chapter 1 I have

:chapter: 1

and for chapter 2 I have

:chapter: 2

in the preamble.

I suspect the bug has to do with the figure-caption I have inserted in the preamble.

How do I tell it to use the chapter number of the chapter that is being referenced instead of the chapter itself?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

David Jencks
How exactly are you specifying the caption?

I think the problem is what you suspect.  Attribute substitution isn’t as much of a “function” as at least I expect: they tend to be evaluated in context.  So perhaps when you reference from chapter one, Figure: {chapter} is evaluated with :chapter: 1.

I’m not sure how to solve the problem.

David Jencks

On Feb 24, 2020, at 2:48 PM, siddjain [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Hi Alex,

Thanks.

This is working for me with one problem. I have a figure (or it could be a listing or table for that matter) in Chapter 2. It is correctly numbered as Figure 2.10 in that chapter, but when I try to reference it from Chapter 1 using <<chap2.adoc#the-figure>> the reference appears as Figure 1.10. So it does not insert the correct chapter number.

I have following preamble in the chapters

:xrefstyle: short
:listing-number: 0
:figure: 0
:figure-caption: Figure {chapter}.
:listing-caption: Listing {chapter}.
:table-caption: Table {chapter}.

the :listing-number: 0 is resetting listing counter to 0. Similarly :figure:0 resets the figure counter to 0.

and for chapter 1 I have

:chapter: 1

and for chapter 2 I have

:chapter: 2

in the preamble.

I suspect the bug has to do with the figure-caption I have inserted in the preamble.

How do I tell it to use the chapter number of the chapter that is being referenced instead of the chapter itself?



If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Problem-with-numbering-of-listings-in-a-book-tp7663p7669.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

siddjain
I am not specifying the caption in the listing or figure itself. I have a preamble to the chapter where the captions are defined using these flags.

:figure-caption: Figure {chapter}.
:listing-caption: Listing {chapter}.
:table-caption: Table {chapter}.

= My Chapter Begins
Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

David Jencks
OK, I read up on this :-)

If at the beginning of chapter 2 you have

:figure-caption: Figure 2.

Does the reference in chapter 1 turn out correct?  I rather suspect it will still show Figure 1.10.  If that is the case, perhaps all you can do is around each figure reference have

:chapter: 2
<<chap2.adoc#the-figure>>
:chapter: 1

I think I recall Dan making a comment that some way of handling situations like this better is needed…. I didn’t understand at the time why :-)

Hope this helps and that someone else has a better solution.

David Jencks


On Feb 24, 2020, at 3:53 PM, siddjain [via Asciidoctor :: Discussion] <[hidden email]> wrote:

I am not specifying the caption in the listing or figure itself. I have a preamble to the chapter where the captions are defined using these flags.

:figure-caption: Figure {chapter}.
:listing-caption: Listing {chapter}.
:table-caption: Table {chapter}.

= My Chapter Begins


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Problem-with-numbering-of-listings-in-a-book-tp7663p7671.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

siddjain
Yes, that is what is happening. As you say:

I rather suspect it will still show Figure 1.10

so this is a bug in asciidoc? one thing about asciidoc is that I have a hard time understanding what is a bug in asciidoc and what is a bug in asciidoctor-pdf. Is there a way for me to determine that distinction?
Reply | Threaded
Open this post in threaded view
|

Re: Problem with numbering of listings in a book

David Jencks
Well, I think that the attribute substitution is working as designed, and that attribute substitution isn’t an appropriate way to solve your numbering problem.  I think you have a feature request for some kind of automatic multi-level numbering. :-)

David Jencks

On Feb 25, 2020, at 2:11 PM, siddjain [via Asciidoctor :: Discussion] <[hidden email]> wrote:

Yes, that is what is happening. As you say:

I rather suspect it will still show Figure 1.10

so this is a bug in asciidoc? one thing about asciidoc is that I have a hard time understanding what is a bug in asciidoc and what is a bug in asciidoctor-pdf. Is there a way for me to determine that distinction?


If you reply to this email, your message will be added to the discussion below:
https://discuss.asciidoctor.org/Problem-with-numbering-of-listings-in-a-book-tp7663p7676.html
To start a new topic under Asciidoctor :: Discussion, [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML