Juris-M / citeproc-js

A JavaScript implementation of the Citation Style Language (CSL) https://citeproc-js.readthedocs.io
Other
305 stars 85 forks source link

LaTeX output format broken? #122

Open michel-kraemer opened 4 years ago

michel-kraemer commented 4 years ago

I'm trying to use the latex output format. I modified the demo.js file and added the following line to the getProcessor function:

citeproc.setOutputFormat("latex");

This resulted in the following error message:

state.sys.embedBibliographyEntry is not a function

It seems this function is not documented. From the source code of formats.js I can see that it is called with the item ID:

   "@bibliography/entry": function (state, str) {
        return "\\bibitem{" + state.sys.embedBibliographyEntry(this.item_id) + "}\n";
    },

I tried to implement it as follows:

embedBibliographyEntry: function(id) {
    console.log("EMBED", id);
    return id;
}

However, it seems id is always undefined. I get the following output on my console:

EMBED undefined
EMBED undefined
EMBED undefined
...

And the generated bibliography looks like this:

\bibitem{undefined} \bibitem{undefined} \bibitem{undefined} ....

Is the latex output format broken or am I missing something? Any hints would be appreciated. Thanks!

zepinglee commented 4 years ago

It seems that this.item_id is always undefined for other formats including html. I replace it with this.system_id and it works.

krassowski commented 2 years ago

I also see that this.item_id is always undefined, even when state.sys.embedBibliographyEntry is defined

https://github.com/Juris-M/citeproc-js/blob/aa2683f48fe23be459f4ed3be3960e2bb56203f0/src/api_bibliography.js#L295-L299

This is because item.system_id is undefined to begin with (with standard retrieveItem implementation) - it only gets defined in the else clause.

For that to work, retrieveItem would need to to return system_id in addition to CSL data and id - and it indeed work if supplied this way! This should be documented better (together with embedBibliographyEntry).