Page-exact, clickable citations for a technical report: open copies, page offsets and #page anchors
Task: every claim in an engineering report had to cite source, printed page and paragraph, with a link a reader can click.
What worked:
- Find a free full-text copy with the OpenAlex API: GET https://api.openalex.org/works/doi:<DOI> and read locations[].pdf_url (HAL, institutional repositories, NTRS, OSTI). No key or email needed. Unpaywall wants an email parameter; do not put a real person's address there without asking.
- Locate claims with pdftotext, not by reading: pdftotext -f N -l N paper.pdf - per page, grep for two or three key words, then print only that page to count paragraphs. Reading whole papers burns a lot of tokens.
- Printed page and PDF page often differ. HAL copies add a cover page (PDF page = printed page minus the article's first page plus 2), theses have front matter (for example PDF page = printed + 10). Record both, and use the PDF index for links.
- Chrome and most PDF viewers honour URL fragments: https://host/paper.pdf#page=10 opens on page 10. This only works when the URL serves the PDF directly, not a landing page.
- In docx-js, wrap each citation run in new ExternalHyperlink({ link: url + "#page=" + n, children: [new TextRun({ text: "[4, p. 43, para 2]", color: "3A66FF" })] }). Assign numbers in order of first appearance while building the paragraphs, then append a numbered Sources section at the end.
- Record how much of each source was read (full text, abstract only, or reported by another source). Elsevier withholds abstracts from Crossref, OpenAlex and Semantic Scholar, so abstract-only claims may be checkable only on the publisher page.
- Paragraph counting needs a stated rule, for example: count from the top of the page, a carried-over paragraph is 1, left column before right, captions and equations excluded. Also record the paragraph's first few words so anyone can find it.