retorquere / zotero-better-bibtex

Make Zotero effective for us LaTeX holdouts
https://retorque.re/zotero-better-bibtex/
MIT License
5.4k stars 289 forks source link

Better CSL does not extract extra variables #2963

Closed nateclark-ucla closed 2 months ago

nateclark-ucla commented 2 months ago

Debug log ID

8HMFT7MM-refs-euc/6.7.226-7

What happened?

Hi there. Thanks so much for this terrific plugin! I'm trying to get add a postscript to BBT to export a CSL variable from the Extra field. However, any script I add is exported as as the field "postscript": [code]. I've included a short debug script in the debug example I uploaded.

I expect this has to do with the "ae:sql:get: undefined is not a string but a undefined" error, but I'm a total noob.

Thanks in advance for your guidance!

retorquere commented 2 months ago

I'm trying to get add a postscript to BBT to export a CSL variable from the Extra field. However, any script I add is exported as as the field "postscript": [code]. I've included a short debug script in the debug example I uploaded.

I can't yet reproduce this. I get the simple log message as expected. I don't yet know by what path this could end up as a field "postscript" in the output CSL. Can you send a new log and tick the "include cache" option?

I expect this has to do with the "ae:sql:get: undefined is not a string but a undefined" error

No relation.

nateclark-ucla commented 2 months ago

Debug log ID

K9FUKTI3-euc/6.7.226-7

Resubmitted with cache attached. Thanks!

retorquere commented 2 months ago

A debug build will drop here in a few minutes, please install it, export again, and send a new log.

github-actions[bot] commented 2 months ago

:robot: this is your friendly neighborhood build bot announcing test build 6.7.226.6867 ("logging")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.226.6867, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

nateclark-ucla commented 2 months ago

Debug log ID

R52FBFKP-euc/6.7.226.6867-7

retorquere commented 2 months ago

Can you reset the cache from the BBT preferences (under misc), export again, and send a new log?

nateclark-ucla commented 2 months ago

Debug log ID

K6J9AYUD-apse/6.7.226.6867-7

retorquere commented 2 months ago

I don't see the translator running. A new build will drop soon, please generate a new log from that.

github-actions[bot] commented 2 months ago

:robot: this is your friendly neighborhood build bot announcing test build 6.7.226.6870 ("log translator id")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.226.6870, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

nateclark-ucla commented 2 months ago

Debug log ID

NW6FZ38F-euc/6.7.226.6870-7

retorquere commented 2 months ago

NW6FZ38F-euc shows the CSL to be

{"id":"11spreadmoderndemocracy_","type":"article-journal","language":"en","source":"Zotero","title":"11. The spread of modern democracy","citation-key":"11spreadmoderndemocracy_"}

before and after the postscript has ran. A new build will drop soon, please generate a new log, but can you also post the actual output you are getting?

github-actions[bot] commented 2 months ago

:robot: this is your friendly neighborhood build bot announcing test build 6.7.226.6875 ("log final result")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.226.6875, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

nateclark-ucla commented 2 months ago

Debug log ID

JCYNWNHC-euc/6.7.226.6875-7

json attached. Thanks! Exported Items.json

retorquere commented 2 months ago

You are exporting as BetterBibTeX JSON, which is BBTs debug format (and it's also used for automation). You want Better CSL JSON.

nateclark-ucla commented 2 months ago

Thanks. I've set the export format to Better CSL JSON, and I don't see the postscript anymore.

But, I've tried adding my actual JS to the scripting section and I'm still not seeing my CSL variable ("GSCC") listed under the "notes" field. JSON attached. Exported Items.json

Here's the script I've added:

if (Translator.BetterBibTeX) { if (this.extraFields && this.extraFields.extra) { let citeCount = this.extraFields.extra.find(field => field.name === 'GSCC'); if (citeCount) { this.add({ name: 'GSCC', value: citeCount.value }); } } }

FYI, my ultimate goal is to get this field to show up in Obsidian using the Zotero Integration plugin.

retorquere commented 2 months ago

The script you posted will only do stuff in the Better BibTeX translator, and .add is specific to the TeX translators; CSL uses simple object manipulation. You want something like

if (Translator.BetterCSL) {
  if (extra.kv.GSCC) csl.GSCC = extra.kv.GSCC
}
retorquere commented 2 months ago

listed under the "notes" field.

I am not sure what you mean by this.

nateclark-ucla commented 2 months ago

listed under the "notes" field.

I am not sure what you mean by this.

In the JSON I see the CSL variable under "note":"GSCC: 0021819 \nmy-note: testing" which includes everything in the Extra field.

I tried the script

if (Translator.BetterCSL) {
  if (extra.kv.GSCC) csl.GSCC = extra.kv.GSCC
}

But that's not pulling it out. I looked at your Extra fields doc and the Scripting doc, but I'm lost. Should the code above be enough to pass a new CSL variable that's used in the Extra field?

retorquere commented 2 months ago

8HMFT7MM-refs-euc/6.7.226-7 does not contain a line

GSCC: something

so there's nothing to pull out.

retorquere commented 2 months ago

But there is an error somewhere. I'll look into it tomorrow.

github-actions[bot] commented 2 months ago

:robot: this is your friendly neighborhood build bot announcing test build 6.7.226.6896 ("testcase")

This update may name other issues, but the build just dropped here is for you; it just means problems already fixed in other issues have been folded into the work we are doing here. Install in Zotero by downloading test build 6.7.226.6896, opening the Zotero "Tools" menu, selecting "Add-ons", open the gear menu in the top right, and select "Install Add-on From File...".

retorquere commented 2 months ago

This will do it now:

if (Translator.BetterCSL) {
  if (extra.raw.gscc) csl.GSCC = extra.raw.gscc
}

the .kv variables only support equivalents of Zotero fields, the .raw fields have any colon-separated value in extra. Variable names are always lowercased.

nateclark-ucla commented 2 months ago

Thanks! GSCC is showing up in the json export.

Now I need to figure out how to get the Zotero Integration plugin to recognize it. For another day!