riboseinc / asciidoctor-bibliography

Citations in AsciiDoc
MIT License
30 stars 8 forks source link

:bibliography-database: not set via asciidoctor-epub3 for included documents #104

Closed neontapir closed 5 years ago

neontapir commented 5 years ago

When using the asciidoctor-epub3 gem, if I define :bibliography-database: in the spine document, asciidoctor-bibliography fails to keep that value when parsing included documents. This leads to a crash as documented in issue #9.

asciidoctor-bibliography creates the bibliography as expected when generating HTML or PDF with asciidoctor. It also works as expected if I define :bibliography-database: in every included document, but that partially defeats the purpose of the include macro.

Here some sample script output, with the full path elided:

$ bundle exec asciidoctor-epub3 -r asciidoctor-bibliography sample.adoc
asciidoctor: FAILED: .../bibliography-sample/sample.adoc: Failed to load AsciiDoc document - asciidoctor: FAILED: .../bibliography-sample/sample-2.adoc: Failed to load AsciiDoc document - Option :bibliography-database: is mandatory.
A bibliographic database is required.
  Use --trace for backtrace
pddzaic commented 5 years ago

I have created an minimal working example to show this behavior. Let's assume the following structure:

test\
  - test.adoc
  - meta.adoc
  - References.bib

where the content is as follows:

References.bib

@Misc{ref-01,
  author    = {John Doe},
  title     = {{The Book without Title}},
  date      = {2018-09},
  doi       = {abc-123-def},
  publisher = {Oxford Press},
}

@Misc{ref-02,
  title     = {{Th title of the reference}},
  date      = {2018-01},
  doi       = {XYZ-S-12345},
  publisher = {Washington Post},
}

meta.adoc

:doc-type: book
:author: John Wayne
:email: pddzaic@gmail.com
:revnumber: 1.0
:revdate: {docdatetime}

The first compilation of test. adoc

//include:meta.adoc[]
:author: John Wayne
:email: pddzaic@gmail.com
:revnumber: 1.0
:revdate: {docdatetime}
:bibliography-database: References.bib
:bibliography-style: ieee

= My first document using asciidoctor-bibliography

In cite:[ref-01] and cite:[ref-02]

[bibliography]
== References
bibliography::[]

works fine.

This content of test.adoc

include:meta.adoc[]
:bibliography-database: References.bib
:bibliography-style: ieee

= My first document using asciidoctor-bibliography

In cite:[ref-01] and cite:[ref-02]

[bibliography]
== References
bibliography::[]

leads to an error:

Failed to load AsciiDoc document - Option :bibliography-database: is mandatory.
A bibliographic database is required.
  Use --trace for backtrace

The same error with meta.adoc:

:doc-type: book
:author: John Wayne
:email: pddzaic@gmail.com
:revnumber: 1.0
:revdate: {docdatetime}
:bibliography-database: References.bib
:bibliography-style: ieee

and adoc.test:

include:meta.adoc[]

= My first document using asciidoctor-bibliography

In cite:[ref-01] and cite:[ref-02]

[bibliography]
== References
bibliography::[]
neontapir commented 5 years ago

@pddzaic, thank you for reproducing the bug, that's amazing!

For anyone investigating, I confirmed the error also happens when the include macro in test.adoc follows the variable definitions, which is the typical use case.

ronaldtse commented 5 years ago

@neontapir @pddzaic thank you for the report and the reproducible case!

@paolobrasolin would you have time to look at this? Thanks!

paolobrasolin commented 5 years ago

@neontapir and @pddzaic thanks again for the report and the sample files!

I just released 0.10.3 to fix this issue. If you have the chance to test it, please let us know whether that works correctly for you too! 😄

pddzaic commented 5 years ago

Hi paolobrasolin

Back from vacation, I have tested the implementation.

On the first look: it works.

On the second look: Other thinks are broken now.

Let's assume the following file structure with two folders:

tbl
     tbl-001.adoc
src
     test.bib
     test.adoc

File test.bib:

@ARTICLE{test,
  author = {L[eslie] A. Aamport},
  title = {The Gnats and Gnus Document Preparation System},
  journal = {\mbox{G-Animal's} Journal},
  year = 1986,
}

File tbl-001.adoc:

[align="center"]
[%header%autowidth]
[col="<,<"]
|====
|Task ID|Description
|A|ABC
|B|DEF
|====

File test.adoc:

:doc-type: book
:author: I's m
:email: pddzaic@gmail.com
:revnumber: 1.0
:revdate: {docdatetime}
:bibliography-database: test.bib
:bibliography-style: ieee
:dir-tbl: ../tbl

= My first document using asciidoctor-bibliography

In cite:[test]

This works:

include::../tbl/tbl-001.adoc[]

// This does not work anymore:
// include::{dir-tbl}/tbl-001.adoc[]

[bibliography]
== References
bibliography::[]

Compiling C:\test\src>asciidoctor -r asciidoctor-bibliography test.adoc leads to the following error when uncommenting the two lines:

asciidoctor: ERROR: test.adoc: line 21: include file not found: C:/test/src/{dir-tbl}/tbl-001.adoc

The variable dir-tbl is not expanded anymore to ../tbl

Should I open a new issue on this?

paolobrasolin commented 5 years ago

Thanks for the report @pddzaic. I already narrowed down the problem and opened #109.