asciidoctor / asciidoctor-extensions-lab

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.
Other
104 stars 101 forks source link

Add list of tables and list of figures #111

Closed igagis closed 10 months ago

igagis commented 8 years ago

In many documents it is needed to have list of figures and list of tables right below table of contents. Would be good to have this feature in asciidoctor-pdf

GeniusWaxer commented 8 years ago

I would like to have this feature as well.

As of now I've found a workaround where I create a counter for the figures and lists respectively and set the id of them to Figure-{counter:image-number} and Table-{counter:table-number}. The list of figures can then be created manually by using <<Figure-1, Figure 1>><<Figure-1>>

Ex:

= My AsciiDoc
:counter: image-counter: 0
:counter: table-number: 0

image::image001.png[title="My Image", id="Figure-{counter:image-number}"]

[title="My table", id="Table-{counter:table-number}", options="header"]
|===
|Col 1            | Col 2
|Row 1 Cell 1     | Row 1 Cell 2
|Row 2 Cell 1     | Row 2 Cell 2
|===

== List of Figures

<<Figure-1, Figure 1>><<Figure-1>>

== List of Tables

<<Table-1, Table 1>><<Table-1>>

Which should render similar to this:

My AsciiDoc

My Image Figure 1. My Image

Col 1 Col 2
Row 1 Cell 1 Row 1 Cell 2
Row 2 Cell 1 Row 2 Cell 2

Table 1. My Table

List of Figures

[Figure 1 My Image](#My Image)

List of Tables

[Table 1 My Table](#My Table)

NOTE: The counters can NOT be named figure-number and table-number since those two counters already exists for the automatic numbering of figures and tables.

Hope this helps for now.

igagis commented 8 years ago

Unfortunately, looks like there's no way to have also page numbers in the lists of tables and figures, but good workaround for now.

GeekMustHave commented 7 years ago

I also would like to vote for this feature to be added to ASCIIDoctor.

My comrades who use Word keep poking me about this. "We can do it, you can't"

mojavelinux commented 7 years ago

My comrades who use Word keep poking me about this. "We can do it, you can't"

They would be wrong. You can do just about anything in Asciidoctor. Sometimes, it just takes some custom programming. Something Word does not have. We win in that argument every time ;)

All we are talking about here is out of the box behavior.

GeekMustHave commented 7 years ago

Preaching to the choir.... I see good things in the future for ASCIIDoctor

On Wed, Oct 5, 2016 at 3:40 PM, Dan Allen notifications@github.com wrote:

My comrades who use Word keep poking me about this. "We can do it, you can't"

They would be wrong. You can do just about anything in Asciidoctor. Sometimes, it just takes some custom programming. Something Word does not have. We win in that argument every time ;)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/asciidoctor/asciidoctor-pdf/issues/456#issuecomment-251777247, or mute the thread https://github.com/notifications/unsubscribe-auth/AOZQQXesPf65rMxO0iIjDdS9Ft9Y_b41ks5qw_0ZgaJpZM4Imfq4 .

----***---- John Schuster Senior Consultant... 517 927 7400

This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately.

1marc1 commented 7 years ago

Agreed: we need the ability to have a table of tables and a table of figures that works in much the same way as a table of contents.

Perhaps something like: :toc: :tot: :tof:

Marc.

znerd commented 6 years ago

It would be nice if the concept could be expanded to any kind of list.

E.g. I have a document that contains requirements. It would be nice if I can list all the requirements in a Requirements Index appendix, with references to the location of the requirements.

UraniumKnight commented 6 years ago

This feature would be very welcome. My company requires us to have a list of tables and figures in our documents and I have implemented a "solution" using the extension framework and ruby magic, but it's quite ugly. It would be so nice to have this as an actual feature.

Buzzardo commented 6 years ago

We are considering adding a List of Tables, a List of Figures, and (most importantly for Spring) a List of Code Examples. We want Asciidoctor to auto-generate those for us. Otherwise, the maintenance cost is too high for our team. (We don't dare rely on manually updating such things, because we have many books and many authors.)

schulle877 commented 5 years ago

I also implemented some ruby magic to do this:

This is my ruby function to create a toi. text is the whole adoc, which contains a META-Placeholder for inserting the list. bTable is a switch between table format and a list. logger is the global logger.

def create_table_of_images(text, bTable = true, logger)
  x = text.split(/\r?\n|\r/).grep(/Image-/).grep(/(image-counter|image-number)/).count
  logger.debug("Found " + x.to_s + " images")
  list = ""
  i=0
  x.times do
    i = i+1
    list +="|" if bTable
    list +="<<Image-"+i.to_s+">>"
    list +=" +" if !bTable
    list +="\n" if i< x
  end
  if list == ""
    list +="|{nbsp}" if bTable
  end
  text.gsub! /\|\$\{META_TABLEOFIMAGES\}[\|]{0,}/,list
  text
end

This is how my adoc-toi-placeholder looks like:

[discrete]
== Images
[stripes=none, frame=none, grid=none]
|===
|${META_TABLEOFIMAGES}
|===

As you can see, it is only a list of references.

To use the references you must define an image-id using an image-counter:

# document header
:counter: image-number: 0 # initializes the image counter
:figure-caption!: Image # turns off the automatic caption
...
image::picture.jpg[title="Image {counter:image-number}: This is a nice image", id="Image-{image-number}"]

I hope I have no typos, because I copied some snippets out of my whole script. You can also do the same stuff with tables or whatever you like. I have a separate function for tables too.

lurch commented 4 years ago

@mojavelinux

You can do just about anything in Asciidoctor. Sometimes, it just takes some custom programming.

...which assumes that the person using Asciidoctor is also a (Ruby) programmer, which might not always be the case :stuck_out_tongue_winking_eye: :laughing: (I do, of course, appreciate all the effort you put in to Asciidoctor :heart: )

@GeniusWaxer When I try your workaround in a book doctype PDF, it then lists "List of Figures" as Chapter 1 and "List of Tables" as Chapter 2, and my "Introduction" gets bumped up to Chapter 3 :slightly_frowning_face: I'm a bit of an Asciidoctor newbie so is there any way I can tell it not to allocate a chapter-number for "List of Figures" and "List of Tables"? (just like it doesn't display a chapter-number next to the "Table of Contents")

lurch commented 4 years ago

To answer my own question...

is there any way I can tell it not to allocate a chapter-number for "List of Figures" and "List of Tables"?

This can be done using :sectnums!: https://asciidoctor.org/docs/user-manual/#numbering

mojavelinux commented 4 years ago

which assumes that the person using Asciidoctor is also a (Ruby) programmer, which might not always be the case

I understand that. But you have the freedom to hire someone to do what you want. So my point still stands. I volunteer to work on this, so I do what I'm willing to do.

mojavelinux commented 4 years ago

I think this issue needs to be moved to the extensions lab. It's not specifically related to Asciidoctor PDF. If the extension generates a section with references and adds it to the parsed document, the converter will add that output. And then you can include it regardless of output format.

mojavelinux commented 4 years ago

This can be done using :sectnums!: asciidoctor.org/docs/user-manual/#numbering

If you're working at the API level, you can also set the numbered property on the section to false.

lurch commented 4 years ago

OffTopic:

I think this issue needs to be moved to the extensions lab.

Seems as though transferring the issue to a different repo unsubscribed me from notifications, even though I'd previously commented on this issue :frowning_face: So for the benefit of other commenters on this issue who may want to re-subscribe to notifications... ping @igagis @GeniusWaxer @GeekMustHave @1marc1 @znerd @UraniumKnight @Buzzardo @schulle877

OnTopic:

I don't know Ruby, and @GeniusWaxer 's solution didn't quite work for me as I have :xrefstyle: short enabled, so I've written a Python script which scans my source adoc for lines like:

.Caption for this table
[#tab-id_for_this_table]

and then writes

<<tab-id_for_this_table>> . . . . <<tab-id_for_this_table, Caption for this table>> +

into list_of_tables.adoc which I then include:: into my main adoc. Bit of an ugly solution, but it works for now :wink:

Alwinator commented 2 years ago

I have added a "list of figures" extension (see PR), time-wise and knowledge-wise I didn't manage to implement links, but it is the first step :)

mojavelinux commented 2 years ago

I would encourage you to create a separate repository and publish the code there. This repository has gotten completely out of hand. It was meant only to be a lab to show how extensions can be used. It's not meant to be the source of extensions for this project. I don't plan to merge additional PRs into this repository for full-fledged features.

Alwinator commented 2 years ago

No problem :) You can find my new extension here: https://github.com/Alwinator/asciidoctor-lists

mojavelinux commented 2 years ago

Fantastic! And nice work!

Alwinator commented 2 years ago

Thanks! :)

Alwinator commented 2 years ago

@Buzzardo I have added a feature to asciidoctor-lists which allows lists of code snippets! I hope you like it.

mojavelinux commented 2 years ago

@Alwinator If you haven't already, I invite you to join the project chat at https://asciidoctor.zulipchat.com where you can share news about this extension to a broader audience.

Alwinator commented 2 years ago

@mojavelinux That would be great! I already have an account. In which stream/channel should I share my news?

ggrossetie commented 2 years ago

@Alwinator you can use the "contrib releases" topic in the #annouce stream: https://asciidoctor.zulipchat.com/#narrow/stream/279652-announce.C2.A0.F0.9F.93.A2/topic/contrib.20releases

bai-yi-bai commented 1 year ago

Hello, To fully adopt AsciiDoctor/AsciiDoctor-PDF, I need an LoF and LoT which has the same look-and-feel as the ToC. Since I am only a low-level Ruby programmer, I found and funded a developer off Fiverr.com to take the existing ToC generator in AsciiDoctor-PDF's converter.rb and modify it to produce a LoF. From the beginning, my intention was to open source this code and give it to the AsciiDoctor community to carry across the finish line. (I don't know how to package this into an extension, nor do I intend to).

I can discuss this further on the https://asciidoctor.zulipchat.com, or wherever is appropriate. Edit Created https://asciidoctor.zulipchat.com/#narrow/stream/288690-users.2Fasciidoctor-pdf/topic/Code.3A.20List.20of.20Figures.20similar.20to.20ToC

I have posted the .rb file to my personal github here: https://github.com/bai-yi-bai/asciidoctor-pdf-list-of-figures/blob/main/LoF/lof_extension_render_like_toc.rb

Copying from the notes I posted in the file:

This LoF has these features:

- Provides a similar look-and-feel to the existing built-in ToC (it was built upon it).
- The page number is displayed.

Known issues:

- The Figure signifier, "Figure" is not printed.
- The Figure counter, "Figure 1" is not printed.
- The ability to add whitespace between the signifier, counter, and title would be nice
- This extension only works with a specific Figure title syntax. It is unclear what syntax this is. 

Following-up on the syntax issue. I provided the developer some test files which did not print the page number, it printed "?" with this:

image::image_file.ext[title='Title']

Through testing, I found that this syntax worked:

[[Title, Title]]
image::image_file.ext[title='Title']

I'm still not sure what the correct syntax for referencing a figure is (including the figure signifier, caption/title, or page number) perhaps this is a discussion better suited to the zulipchat.

I hope that a similar approach can be used to generate a List of Tables, and List of Examples. I'm not sure if 'hooking in' to the ToC generator will work... not all documents will include an LoT, an LoF, and an LoE.

mojavelinux commented 10 months ago

Since this became a community extension, I'm going to close this issue as there is no reason to duplicate it here.

See https://github.com/Alwinator/asciidoctor-lists

bai-yi-bai commented 8 months ago

A solution is now available: https://gitlab.com/baiyibai/asciidoctor-pdf-lofte