Coder Social home page Coder Social logo

Comments (3)

jxxcarlson avatar jxxcarlson commented on July 30, 2024

Looking over the Asciidoctor source code, it seems to me that one needs to set @document.attributes['theorem-caption'] = Theorem for [env.theorem], and so on for each new env-role combination encountered. Predefined hash entries of this kind are made at https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/document.rb#L263, and this is also what is suggested by https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/document.rb#L263 .

I've made a stab at doing this in asciidoctor-latex, but so far have not succeeded.
Here is one attempt:

asciidoctor -r asciidoctor-latex -a stem=latexmath -a theorem-caption=Theorem -b html --verbose try-out/$1.adoc

from asciidoctor-latex.

mojavelinux avatar mojavelinux commented on July 30, 2024

There are two ways to get auto-numbered captions to work.

Option A: Use built-in behavior

  1. You must set a document-level attribute named theorem-caption to be used in front of the number (can be empty string) (do the assignment in a preprocessor)
  2. The block must have a title attribute (which you have done)
  3. The converter method must emit the caption as part of the title using the captioned_title method (see https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/converter/html5.rb#L360)

NOTE: The open block does not use the caption, so you'll need to override this behavior.

If you satisfy (1), then you shouldn't have to manually assign the caption as it's done automatically in the parser (see https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/parser.rb#L1099)

Option B: Use explicit assignment

Another option is to assign the caption explicitly (either to the @caption property or the title attribute) by cloning the logic in the assign_caption method. This is what I meant by using the built-in document counter (see https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/abstract_block.rb#L330).

You'd do something like this in the process method of the block extension:

env_name = roles.first
env_title = env_name.capitalize
caption_num = parent.document.counter_increment("#{env_name}-number", block)

caption = "#{env_title} #{caption_num}. "
block.assign_caption caption

# alternative approach, set title exactly how you want it
#attrs['title'] = "#{env_title} #{caption_num}"

You are probably better off just filling in the title attribute explicitly with exactly what you want it to display (the last line in the previous listing).

I hope that helps clear things up!

from asciidoctor-latex.

jxxcarlson avatar jxxcarlson commented on July 30, 2024

This is now done. Thanks @mojavelinux !

from asciidoctor-latex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.