Working With Citations - JonasEngstrom/overleaf-article-template GitHub Wiki
Keeping BibLaTeX Cite Keys
While developing a document, it can be faster and easier to let RStudio format the references. By default the file vancouver-superscript.csl is used to guide the formatting, but it can be replaced with a desired format from for example the Zotero Style Repository.
When it comes time to publish it can however be desirable to keep the BibLaTeX cite keys and format the references and bibliography on Overleaf or supplying the *.bib file directly to the publisher and having them deal with formatting. To make this easy the template includes the file preserve-cite-keys.csl that puts placeholders around the cite keys in the manuscript. A git pre-commit hook in the overleaf submodule then replaces the placeholders with the appropriate LaTeX code.
To use the CSL file, make sure that the line csl: vancouver-superscript.csl is commented out and uncomment the line csl: preserve-cite-keys.csl in the YAML section at the top of the R Markdown file. The pre-commit hook will take care of the rest. Note that the BibLaTeX style defaults to Vancouver. This can be changed in the LaTeX code or the pre-commit hook.
Using Zotero to Make Life Simpler
If you opt to sync references.bib with Zotero (as described on the page Setup: New Article) you can facilitate citing further by installing the Better BibTeX plugin in Zotero and changing the following settings:
- Open Settings from the Zotero menu and go the Better BibTex category.
- Set the Citation key formula to
zotero.clean. - Set the Quick-Copy/drag-and-drop citations under Quick-Copy to Pandoc citation.
- Check the Surround Pandoc citations with brackets checkbox.
- Go to the Export category.
- Set the Item Format to Better BibTeX Citation Key Quick Copy.
You might also have to select all papers and right click and select the Better BibTeX submenu, followed by Unpin BibTeX key and then Refresh BibTeX key to get the same BibTeX keys on your local computer as on Zotero online, which is what syncs to Overleaf.
NB! Be careful when unpinning BibTeX keys if you have previous papers using your synced Zotero library or if you have custom cite keys in your library, as unpinning might break those links.
Now you should be able to select the papers you want to cite in Zotero, press Cmd + Shift + C, and then paste the references straight into your R Markdown document. This should then work with your synced references. Just remember to press the Refresh button for the references.bib file in the Overleaf web interface and run ./sync.sh to download the reference information locally.