jlegewie / zotfile

Zotero plugin to manage your attachments: automatically rename, move, and attach PDFs (or other files) to Zotero items, sync PDFs from your Zotero library to your (mobile) PDF reader (e.g. an iPad, Android tablet, etc.), and extract PDF annotations.
4.03k stars 280 forks source link

option to change cite-format #175

Open jlegewie opened 9 years ago

jlegewie commented 9 years ago

Is there a way to change the cite-format, when using the 'Extract Annotations' feature?

I have found the option to do some adjustments in extensions.zotfile.pdfExtraction.formatAnnotationNote, but the %(cite) variable does not seem to be configurable?

Right now it comes out as "%(author) %(year):%(page)" and I would like it to be "%(author), %(year), p. %(page)" instead (APA-style) (exampled with fictitious variables, but I hope it makes sense).

I.e. "Clegg et al, 2005, p. 150" instead of "Clegg et al 2005:150".

But I seem to have hit a wall, so any pointers or hints, would be greatly appreciated.

boegh commented 9 years ago

Sorry for not adding the issue directly on Github (I wasn't aware it was a request), and for forgetting to ask the following on the Zotero Forum, but I was wondering if this was the same as/related to #95 ?

jlegewie commented 9 years ago

Yes, you are right. I closed the other one.

jlegewie commented 9 years ago

Just some notes if anyone wants to look into this.

Currently, the cite key is hard coded on line https://github.com/jlegewie/zotfile/blob/master/chrome/content/zotfile/zotfile.js#L3743 zz.replaceWildcard(item, "%a %y:").replace(/_(?!.*_)/," and ").replace(/_/g,", ") is the relevant part. It first uses the replaceWildcard function and then formats the author string with and and ,.

Also add option to format the cite key as plain-text scannable citations "scannable citations".

notehound commented 7 years ago

For Zotfile 5.0.6 the following changes can be applied to line 223 in pdfAnnotations.js

The line cited by Joscha (above) is slightly different in Zotfile 5: cite = this.getPref("pdfExtraction.NoteFullCite") ? this.Wildcards.replaceWildcard(item, "%a %y:").replace(/(?!.*)/," and ").replace(/_/g,", ") : "p. ",

To get extracted annotations with a more specific citation style, replace that line as follows:

// APA: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " APA FullCite ", this.Wildcards.replaceWildcard(item, "%a, %y").replace(/_(?!.*_)/," & ").replace(/_/g,", ") + ", p. ") : (str_title += " APA PageCite ","p. "), // or Harvard: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " Harvard FullCite ", this.Wildcards.replaceWildcard(item, "%a, %y").replace(/_(?!.*_)/," and ").replace(/_/g,", ") + ", p. ") : (str_title += " Harvard PageCite ","p. "), // or MLA: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " MLA FullCite ", this.Wildcards.replaceWildcard(item, "%a").replace(/_(?!.*_)/," and ").replace(/_/g,", ") + " ") : (str_title += " MLA PageCite ",""), // etc.

Modify yourself or use xpi files in attached zip file based on Zotfile version 5.0.6 - a customised "Scannable Cite" version is also included in the zip file. zotfile-5.0.6-fx-customised.zip

notehound commented 4 years ago

Customised APA version of Zotfile 5.0.16 attached.

  1. Uninstall Zotfile
  2. Download attached file and rename file extension from zip to xpi and install as a Zotero Add-on
  3. Change "Automatic Updates" for this customised Zotfile version to "off" zotfile-5.0.16_APA.zip
Schmedu commented 4 years ago

Hey @notehound thanks for your replies! Could you please exaggerate how to change the line to have a scannable cite?

Thanks in advance

For Zotfile 5.0.6 the following changes can be applied to line 223 in pdfAnnotations.js

The line cited by Joscha (above) is slightly different in Zotfile 5: cite = this.getPref("pdfExtraction.NoteFullCite") ? this.Wildcards.replaceWildcard(item, "%a %y:").replace(/(?!.*)/," and ").replace(/_/g,", ") : "p. ",

To get extracted annotations with a more specific citation style, replace that line as follows:

// APA: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " APA FullCite ", this.Wildcards.replaceWildcard(item, "%a, %y").replace(/_(?!.*_)/," & ").replace(/_/g,", ") + ", p. ") : (str_title += " APA PageCite ","p. "), // or Harvard: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " Harvard FullCite ", this.Wildcards.replaceWildcard(item, "%a, %y").replace(/_(?!.*_)/," and ").replace(/_/g,", ") + ", p. ") : (str_title += " Harvard PageCite ","p. "), // or MLA: cite = this.getPref("pdfExtraction.NoteFullCite") ? (str_title += " MLA FullCite ", this.Wildcards.replaceWildcard(item, "%a").replace(/_(?!.*_)/," and ").replace(/_/g,", ") + " ") : (str_title += " MLA PageCite ",""), // etc.

Modify yourself or use xpi files in attached zip file based on Zotfile version 5.0.6 - a customised "Scannable Cite" version is also included in the zip file. zotfile-5.0.6-fx-customised.zip

Mugurlu28 commented 4 years ago

Hello How can i rename file extension from zip to xpi? Thanks.

Mugurlu28 commented 4 years ago

Hello scannable cite version does not work. Can you help me about that?

notehound commented 4 years ago

Apologies for my late responses to posts last month. @Schmedu To extract to scannable cite format using zotfile-5.0.16 change pdfAnnotations.js lines as follows:

replace line 217 (optional for clarity): str_title = this.ZFgetString('extraction.noteTitle'), with: str_title = this.ZFgetString('extraction.noteTitle') + " Scannable Cite ",

replace line 226: cite = this.getPref("pdfExtraction.NoteFullCite") ? this.Wildcards.replaceWildcard(item, "%a %y:").replace(/_(?!.*_)/," and ").replace(/_/g,", ") : "p. ", with: cite = " | " + this.Wildcards.replaceWildcard(item, "%a, %y").replace(/_(?!.*_)/," & ").replace(/_/g,", ") + " |p. ",

insert above line 257: // link with: page = page + "| |zu:" + lib + ":" + item.key;

I have already done this in the attached zip file.

@Mugurlu28 - To rename the file from .zip tp .xpi you need to make the file extensions visible in File Explorer (Windows) or Finder (Mac). The file attached here is customised from the latest version of Zotfile which means it will now work with the current version of Zotero.

zotfile-5.0.16.fx scannableCite.zip

Mugurlu28 commented 4 years ago

Hello notehound Thank you very much. But it does not work in word document. Can you please give me your email address?

notehound commented 4 years ago

Hi @Mugurlu28

Scannable Cite does not work with Word.

See: https://zotero-odf-scan.github.io/zotero-odf-scan/

"RTF/ODF-Scan requires Zotero, LibreOffice and Zotero's LibreOffice plugin."

Mugurlu28 commented 4 years ago

Is there a way to make it work with Word?

notehound commented 4 years ago

@Schmedu @Mugurlu28

Apologies - one last tweak to get annotations in Scannable Cite format:

  1. Go to Zotero>Edit>Preferences>Advanced>Config Editor
  2. search for "extensions.zotfile.pdfExtraction.formatAnnotationHighlight"
  3. Change <p>"%(content)" (%(cite))</p> to <p>"%(content)" {%(cite)}</p>
notehound commented 4 years ago

Is there a way to make it work with Word?

You can add scannable citations in word but you must save your Word doc as odt then open the file in Libre Office. You then use the RTF/ODF-Scan for Zotero add-on in Libre Office to generate in-text citations and bibliography in your chosen format.