Skip to content

Instantly share code, notes, and snippets.

@mcanouil
Created March 28, 2025 21:27
Show Gist options
  • Save mcanouil/03ee1341f71e477871175ec423255b98 to your computer and use it in GitHub Desktop.
Save mcanouil/03ee1341f71e477871175ec423255b98 to your computer and use it in GitHub Desktop.
Count citation and display the counts in log
# MIT License
# Copyright (c) 2025 Mickaël Canouil
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
local citation_count = {}
function Cite(cite)
for _, citation in ipairs(cite.citations) do
local id = citation.id
citation_count[id] = (citation_count[id] or 0) + 1
end
end
function Pandoc(doc)
quarto.log.output(citation_count)
end
@mcanouil
Copy link
Author

mcanouil commented Mar 29, 2025

Use the following to count only the citations (i.e., @author):

---
filters:
  - at: post-quarto
    path: count-cite.lua
---

Use the following to count all types of references (e.g., figures, tables, sections, etc.):

---
filters:
  - count-cite.lua
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment