markdown - Generate Bibliography file from multiple files with Pandoc
问题描述
I have several chapters with citations. My citation file is in bibtex format. I would like to create a formatted bibliography that includes all the citations from the chapters in a single file (publisher prefers DOCX). How can I do this?
解决方案
If the bibtex file contains no additional citations, then it would be sufficient to have a small nocite.md
Markdown file to generate the bibliography:
---
nocite: '@*'
---
# Bibliography
Calling pandoc --output=bibliography.docx --bibliography YOUR_BIBTEX.bib nocite.md
will generate a docx file with formatted entries for all items in YOUR_BIBTEX.bib
.
The more general case is that the bibtex file contains additional entries which should be omitted from the bibliography. One will need a way to limit output to citations used in the document(s). A good method is to use a Lua filter to rewrite the document as needed.
-- save this file as "bib-only.lua"
local cites = {}
-- collect all citations
function Cite (cite)
table.insert(cites, cite)
end
-- use citations, but omit rest of the document
function Pandoc (doc)
doc.meta.nocite = cites
doc.blocks = {}
return doc
end
Running
pandoc --lua-filter bib-only.lua -o bib.docx chapter1.md chapter2.md chapter3.md
should give the desired output.
推荐阅读
- regex - Bash / 正则表达式转换
- html - HTML/CSS - 两个具有单一渐变背景但有一个粘性元素的 div
- formal-verification - 为什么我不能从 Dafny 的幽灵场中调用(非静态)引理?
- mysql - Laravel db query with now()
- routing - Angular 6重新加载参数更改页面
- wordpress - Woocommerce Klarna 结帐布局修改
- java - 为什么“i”的值打印 3 次,在插入排序算法中应该只打印 1 次
- python - 模糊匹配 R 或 Python 中的两列
- java - 这个 UML 图中的这个包外观图标是什么意思?
- android - AdRequest isTestDevice 在 Android 8 上的发布版本中返回 false