asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.14k stars 500 forks source link

No author in output #1883

Closed rongcuid closed 3 years ago

rongcuid commented 3 years ago

I cannot get authors in the output PDF.

$ asciidoctor-pdf --version
Asciidoctor PDF 1.5.4 using Asciidoctor 2.0.12 [https://asciidoctor.org]
Runtime Environment (ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]) (lc:UTF-8 fs:UTF-8 in:UTF-8 ex:UTF-8)

Test file:

= Test Document
Author <email@example.org>

Contents
mojavelinux commented 3 years ago

The authors are only shown when the document has a title page. You can add a title page either by setting the title-page attribute in the document header or setting the doctype to book.

rongcuid commented 3 years ago

OK, but I think it is also a valid use to have author displayed without a title page. When I have a one-page document, I don't necessarily want a separate title page. Maybe turn this into a feature request?

mojavelinux commented 3 years ago

This has already been reported as #988. Feel free to follow-up there. Note, however, that it is not a feature I will be working on, so the implementation will have to come from the community.

das-g commented 1 year ago

Based on https://github.com/asciidoctor/asciidoctor-pdf/issues/66#issuecomment-1128562591, https://github.com/asciidoctor/asciidoctor-pdf/issues/988#issuecomment-1128579996 and quite some trail and error, I've come up with

pdf-converter-article-title-with-author-and-date.rb

class PDFConverterArticleTitleWithAuthorAndDate < (Asciidoctor::Converter.for 'pdf')
  register_for 'pdf'

  def ink_general_heading doc, title, opts
    return super unless opts[:role] == :doctitle
    theme_font :heading_doctitle do
      ink_prose title, align: :center
    end
    revremark = doc.attributes['revremark']
    if doc.author or doc.revdate or revremark
      theme_font :base do
        author_date_separator = (doc.author and doc.revdate) ? " – " : ""
        revremark_separator = ((doc.author or doc.revdate) and revremark) ? " | " : ""
        ink_prose "#{doc.author}#{author_date_separator}#{doc.revdate}#{revremark_separator}#{revremark}", align: :center 
      end
    end
    theme_margin :heading_doctitle, :bottom
  end
end

which adds author, revdate and revremark information to articles without a separate title page when used with

asciidoctor-pdf -r ./pdf-converter-article-title-with-author-and-date.rb path/to/your_document.adoc

Does this look reasonable? Can it be improved or be made more general (e.g. to support multiple authors)?

Would it make sense to add something like this to https://docs.asciidoctor.org/pdf-converter/latest/extend/use-cases/ ?

mojavelinux commented 1 year ago

I'd certainly be open to including this example on the use cases page. Would you like to submit a pull request?

das-g commented 1 year ago

Would you like to submit a pull request?

Sure. Where on that page should it go? Is there any particular order to the sections there?

mojavelinux commented 1 year ago

I would recommend using your best judgement. Probably near an extension that works on a similar aspect. That's what I would end up doing. Maybe after Custom title page?

das-g commented 1 year ago

PR filed: #2439