Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 HiTested 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 |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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 |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
... [show rest of quote] |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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? |
Loading... |
Reply to author |
Edit post |
Move post |
Delete this post |
Delete this post and replies |
Change post date |
Print post |
Permalink |
Raw mail |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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
|
Free forum by Nabble | Edit this page |