brechtm / rinohtype

The Python document processor
http://www.mos6581.org/rinohtype
GNU Affero General Public License v3.0
499 stars 59 forks source link

Citation definitions are not output when using sphinx #262

Closed alexfargus closed 3 years ago

alexfargus commented 3 years ago

When attempting to use citations with a sphinx document the citation definitions do not appear in the output. As far as I can tell this is only the case when using sphinx.

I have created a branch here to do some debugging and itentifed some issues in the method RinohBuilder.assemble_doctree() where the citation references do not get copied from tree to new_tree. However when the execution goes into rst.from_doctree() I have not yet been able to figure out what does wrong.

I created a new rst regression test that works as expected:

However a similar ones that uses sphinx does not:

I can see from the stylelogs that the Note(...) that is present in the rst_output is missing from the sphinx_output, so I think that this is being stripped somewhere. Can you suggest where to look next?

I have observed issue the issue on Windows 10 and Chromebook/Linux using rinoh 0.4.2 and on my test branch from master taken last week.

brechtm commented 3 years ago

Comparing the pseudoxml produced by plain docutils (rst2pseudoxml.py citation.rst) and Sphinx (sphinx-build -M pseudoxml tests_regression/sphinx/test-citations/ build/) shows that Sphinx produces plain reference nodes instead of citation_reference nodes (because citation nodes are mapped to footnotes, they only show up when properly referenced). I think CitationReferenceTransform is the cause for that. The LaTeX builder seems to undo this in its own CitationReferenceTransform.

Note that LaTeX builder collects all citations in a Bilbiography section in the back matter. Eventually, we should be doing something similar, with the exception that it should be configurable. It would be good to have this option for the plain docutils builder as well.

I also noticed that RinohTreePreprocessor.current_docname is None when its default_visit() processes the citation node. We may need to set self.current_docname = document['docname'] in __init__().

P.S. Way back I wrote https://github.com/brechtm/citeproc-py with the intention to use it in rinohtype for generating nicely formatted citations. This would use a BibTeX database file instead, however.