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