Dynamic Figure Indexing

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

Dynamic Figure Indexing

ellieborden
Is there a way to assign figure numbers dynamically using Asciidoctor?

I indexed them by section so, for example, the third figure in section 6 is captioned Figure 6.03.

The problem is that I currently have these captions hard-coded and if I want to insert a new section, I have to rename all of the figure captions and references within all of the following sections.

Here is my document for reference. 


Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Figure Indexing

mojavelinux
Administrator
You can write a tree processor that visits all the figures in a document and sets an explicit caption.

In fact, there's already an extension available that does something similar to what you are asking. See https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/autoxref-treeprocessor.rb

Cheers,

-Dan

On Sun, Oct 28, 2018 at 2:18 PM ellieborden [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Is there a way to assign figure numbers dynamically using Asciidoctor?

I indexed them by section so, for example, the third figure in section 6 is captioned Figure 6.03.

The problem is that I currently have these captions hard-coded and if I want to insert a new section, I have to rename all of the figure captions and references within all of the following sections.

Here is my document for reference. 





If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Dynamic-Figure-Indexing-tp6556.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Figure Indexing

ellieborden
Sorry, I don't think I understand.

I added lib/autoxref-treeprocessor.rb to my project and ran:

     asciidoctor -r ./lib/autoxref-treeprocessor.rb index.adoc

The document was processed, but the result is no different than if I had run Asciidoctor without the extension. I looked through the extension code, but am not very familiar with Asciidoctor's codebase or Ruby, so it is difficult to interpret what is happening.
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic Figure Indexing

mojavelinux
Administrator
That extension still needs some work. Here's generally how it works. If you pass the following document:

= Document Title
:doctype: book

== First Chapter

.Image in First Chapter
image::figure-a.png[]

== Second Chapter

.Image in Second Chapter
image::figure-b.png[]

You will get

Test Document

First Chapter

[figure-a]
Figure 1.1 Image in First Chapter

Second Chapter

[figure-b]
Figure 1.2 Image in Second Chapter

The numbering is not correct for the second figure. It should be Figure 2.1. But clearly it's showing that it is trying to make a two-part number. The key line in the extension is this one:

el.caption = replaced_caption

It's possible to change the caption (e.g., Figure 1.1) for any titled node in the document tree.

Feel free to open an issue in the extensions lab to get help from the community in using or improving that extension, or replacing it with a better one.

Cheers,

-Dan

On Sun, Oct 28, 2018 at 6:07 PM ellieborden [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Sorry, I don't think I understand.

I added lib/autoxref-treeprocessor.rb to my project and ran:

     asciidoctor -r ./lib/autoxref-treeprocessor.rb index.adoc

The document was processed, but the result is no different than if I had run Asciidoctor without the extension. I looked through the extension code, but am not very familiar with Asciidoctor's codebase or Ruby, so it is difficult to interpret what is happening.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Dynamic-Figure-Indexing-tp6556p6561.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux