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 501 forks source link

Footer line selection via attribute does not work #2372

Closed r0ckarong closed 1 year ago

r0ckarong commented 1 year ago

The documentation for the running content states this:

"If you reference an attribute which is not defined, all the text on that same line in the running content will be dropped. This feature allows you to have alternate lines that are selected when all the attribute references are satisfied. "

I'm trying to use this feature to produce a variety of documents from the same style template. Some have subtitles, some don't and I want to represent title and subtitle in the footer for those documents that have both.

My template states this:

footer:
  recto:
    left:
      content: |
        {document-title} +
        {document-title} | {document-subtitle} +
        {revnumber} | {revdate}

I would expect the second line to be dropped when there is no document-subtitle present. However, what is being generated is a stub of the line:

image

Generating the same document with the subtitle, the second line is printed correctly.

image

Using release 2.3.3

r0ckarong commented 1 year ago

Isn't there some way to access the document-subtitle as an attribute from the document? This would make it a lot easier to work around and just build a string that you can reference in the footer.

mojavelinux commented 1 year ago

The document-subtitle attribute is always defined. It just happens to have an empty value. If there's no subtitle, then the value is empty string. Notice there is no exception on this page: https://docs.asciidoctor.org/pdf-converter/latest/theme/add-running-content/#attribute-references So this behavior is correct.

Isn't there some way to access the document-subtitle as an attribute from the document?

No there is not. It's not a feature of AsciiDoc, only Asciidoctor PDF. However, you could set an attribute to indicate that you have specified a subtitle.

:subtitle-defined:

Then you can reference that attribute in the line in the running content.

If you need further assistance, please ask in the project chat at https://chat.asciidoctor.org.

mojavelinux commented 1 year ago

Another thing you can do is set the subtitle attribute and use it in the document title line:

:subtitle: Subtitle Here
= Title: {subtitle}

Just an idea.