riboseinc / asciidoctor-bibliography

Citations in AsciiDoc
MIT License
30 stars 8 forks source link

Added nocite macro for phantom citations #90

Closed Fiech closed 5 years ago

Fiech commented 5 years ago

Hey,

I just stumpled upon this fantastic gem. I worked quite a bit on the asciidoctor-bibtex source in my own fork to get some of features (namely locale support, freely configurable locators and intermediate bibliographies) in, just to find out that your project already has implemented these (if I just've known...).

I now added a nocite macro (which would be my next feature addition for asciidoctor-bibtex) for these times you want to have something listed in the bibliography without explicitly citing them as text.

I have to admit, that I just found your code maybe half an hour ago and I do not yet fully grasp your structure, neither why nocite does not work, if it's not in the TEX_MACRO variable. So I did extend the case statement to catch the nocite before it goes into the render_texmacro_with_csl method. Well anyway, it does just work, even with bibliography::foo[] structure.

I am a bit surprised that it does, to be honest, without any faff... But maybe you can tell me a) why this works this way this and not without the inclusion in TEX_MACRO , b) if this is even a good way to implement this, and c) if there is a better way to do this altogether.

Maybe you're even inclined to accept the merge request. Seems to work just fine with me.

Best, Johannes

ronaldtse commented 5 years ago

@Fiech thank you for the contribution! On first glance it looks OK — will need to supplement some specs to ensure behavior stays stable.

@paolobrasolin do you have time to confirm/approve/supplement this? Thanks!

paolobrasolin commented 5 years ago

Thanks for your contribution @Fiech! This needs a test case and a small fix, but I'll provide them myself and close the issue asap.

By the way, your implementation is almost correct; all bookkeeping is done before the citations are rendered, so your patch just works. The correct place to add nocite would be MACRO_NAME_REGEXP (which holds all matchable macros) and not TEX_MACROS (which holds TeX macros that are rendered with a separate mechanism, see the important box in the docs fore more info).

ronaldtse commented 5 years ago

Thanks @paolobrasolin !