Scrapping bibliography data from the TOC of a PDF book

Thans for @gglick for his comment on my [RTF to Latex converter] (RTF to Latex converter), I am now encourage to post my other useful macro. As an academic, this is another routine that I use to simplify my workflow.

The purpose is to collect references from the table of contents of a PDF book. First, I you need to have the reference data of the book in Jabref. it must contain a citation key.
09: scrapping references from Table of contents.kmmacros (20.6 KB)

  1. Select the Book references in Jabref and hit CNTR+C to send the CiteKey of the book to a named clipboard: Copy to Key.kmmacros (4.6 KB). This macro does a little processing of the extracting the year from the citation key: and keep both the citation key and the year in separate named clipboards (called Key and RefYear).

  2. Open the PDF and start to copy the Title, Author and Page of the reference: in that order: Title-->Author-->Page. Copy a maximum of 8 references (= 23 clipboards).

  3. Hit CMD+ALT+9 (activates Jabref and asks for input).

  4. insert the number of references copied (1-8)

The macro inserts the references as in-collection: crossrefing them to the book. CrossREf is what links the incollections to the parent book. The page numbers are calculated.

It is a highly error prone macro. I would appreciate if somebody can improve it.

Okay @Desalegn, don't get too used to this :slightly_smiling_face: but I've taken a crack at this macro as well:

§Reference Macros.kmmacros (25.7 KB)

I attempted to improve it by eliminating the reliance on clipboard histories and the need for manual input as to how many times the macro should paste a reference collection. Using the companion macros included in that macro file, I tried to set it up so that you can copy titles, authors, and page numbers in any order you like (though the scrapping references macro does still assume that they're all copied in equal number, i.e. one title, author, and pair of page numbers for each reference collection) by assembling each category in its own variable. Once you invoke the scrapping references macro to copy the reference info, a window now pops up to show you all the references you've copied and verify that everything is in order. Confirm them, and the macro loops through the title, author, and pages variables and adds them to reference collections automatically, then pastes them once the last variable is empty.

Here's the "confirm references" window with my test data:


And here's what the macro produces:

@Incollection{,
title = {Into The Water},
author = {Paula Hawkins},
pages = {12–24},
crossref = {Lorem Ipsum},
year = {1982}
}
@Incollection{,
title = {Dragon Teeth},
author = {Michael Crichton},
pages = {24–36},
crossref = {Lorem Ipsum},
year = {1982}
}
@Incollection{,
title = {The Handmaid’s Tale},
author = {Margaret Atwood},
pages = {36-48},
crossref = {Lorem Ipsum},
year = {1982}
}

The goal with this rewrite is for you to be able to copy as many sets of references as you like, much more than 8 if you want, and to have them all formatted and pasted as collections automatically, without the need for you to keep track of how many times you've copied what and without the uncertainty that comes from relying strictly on clipboard history.

(Incidentally, the reason I used pipes as a delimiter for the title variable is because, as far as I know, very few book titles contain them, so this way you should be able to copy titles with commas, colons, semi-colons, slashes, and anything else and still have them be cross-referenced correctly. Author names and page numbers, on the other hand, never contain commas, so I thought it was safe to use them for delimiters in those categories)

I can't promise I'll be able to spend a significant amount of time on another macro like this, but if you run into any issues with this one, let me know and I'll see if I can fix them. I hope this helps with your work, and to better show you the kind of automation possibilities KM offers!

1 Like

Thank you so much @gglick. I will carefully look at this and be back to you.

1 Like