Sample: Manage citations in a Word document using your Word add-in
Citation management is an important aspect of documents, particularly in academia and education. Each citation style has its own guidelines for how citations should be marked in a document as well as where and how the sources should be noted. Such styles include APA and MLA.
This article features a sample add-in that manages citations in a Word document. The add-in displays the references loaded from a .bib file that the user selects to cite in their document.
Prerequisites
- Visual Studio Code.
- Office connected to a Microsoft 365 subscription (including Office on the web).
- Node.js version 16 or greater.
- npm version 8 or greater.
Run the sample code
The sample code for this article is named Manage citations in a Word document. To run the sample, follow the instructions in the readme.
Key steps in the sample
- The user chooses a local .bib file that contains the references they'd like to cite.
- The add-in reads the .bib file then displays the bibliography references in the task pane. The sample uses @orcid/bibtexParseJs to parse the .bib file.
- The user chooses the appropriate reference then inserts it at the cursor's location (or at the end of selected text) in the document.
- The add-in adds a reference mark at that location in the document and adds the reference to an endnote. All endnotes are automatically listed at the end of the document.
Make it yours
The following are a few suggestions for how you could tailor this sample to your scenario.
Manage user settings
Enable single sign-on (SSO) in an Office Add-in to support persisting user data and settings across multiple documents. If your service provides or hosts the bibliography library, an authorized user can access and select from that bibliography in their document.
You can also persist add-in state and settings in the user's current document.
Caution
Don't store sensitive information such as authentication tokens or connection strings. Properties in the document aren't encrypted or protected.
Use footnotes
List the references in footnotes at the end of the page instead of endnotes, according to the citation style.
Alternatively, allow the user to choose where they'd like the references to be displayed. If so, you can update the add-in to persist the user's preference using a document property or as part of their authenticated experience.
Update citation style
Update the citation style used to display the references in the endnotes (or footnotes).
Alternatively, provide various style options then allow the user to choose. If so, you can update the add-in to persist the user's preference using a document property or as part of their authenticated experience.
Replace bibtexParseJs
Replace the .bib file parser @orcid/bibtexParseJs with your own or another available parser, especially if this option doesn't provide the functionality you need for your solution.
See also
Office Add-ins