Closed rongcuid closed 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.
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?
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.
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/ ?
I'd certainly be open to including this example on the use cases page. Would you like to submit a pull request?
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?
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?
PR filed: #2439
I cannot get authors in the output PDF.
Test file: