From: Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Markdown syntax can't handle BibLaTeX formatting
Date: Thu, 02 Nov 2017 22:22:49 +0100 [thread overview]
Message-ID: <87k1z84bpy.fsf@zeitkraut.de> (raw)
In-Reply-To: <20171102202200.GB25469@protagoras> (John MACFARLANE's message of "Thu, 2 Nov 2017 13:22:00 -0700")
John MACFARLANE <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> writes:
> Another approach could be to use pandoc-citeproc -y to
> convert the bibtex to pandoc markdown YAML and include
> this on the command line instead of specifying the bibtex
> file. A filter could then be added that acts before
> pandoc-citeproc and changes the citation ids in the metadata.
This is such a beautiful solution that I couldn't resist to code up a
proof-of-concept. The path to the bibtex file must be stored in the
*bibliography* yaml field:
```
bibliography: path/to/bibliography.bib
...
fix-bibkeys.lua:
function references_from_bibfile (filename)
local yaml = io.popen('pandoc-citeproc -y ' .. filename):read("*a")
return pandoc.read(yaml).meta.references
end
function Meta(meta)
local bibfile = meta.bibliography[1].text
local references = references_from_bibfile(bibfile)
-- modify keys, replace ???? with 0000
for k, v in pairs(references) do
references[k].id = v.id[1].text:gsub("%?%?%?%?", "0000")
end
meta.references = references
return meta
end
Run with
pandoc --lua-filter=fix-bibkeys.lua --filter=pandoc-citeproc …
> +++ Albert Krewinkel [Nov 02 17 21:02 ]:
>>distantflag <eksbjo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>>
>>> Thanks for your replies. I could of course change the bibkeys. But
>>> since I am generating them through export from Zotero I would like to
>>> do so now and again when adding citations to a text, not having to
>>> edit each and every faulty bibkey each time this export process is
>>> done.
>>
>>Another option could be to write a small script which replaces all
>>question marks with underscored or zeros in your bibtex keys. The script
>>could then be run each time the bib file is regenerated by Zotero. The
>>[bibtexparser] python library seems like a good fit for this, but a perl
>>or awk command might work as well.
>>
>>[bibtexparser]: https://bibtexparser.readthedocs.io
>>
>>> Albert Krewinkel: This script seems handy. Where do I place it?
>>
>>The script is best placed in a separate file, e.g. `citation-spans.lua`.
>>Pandoc must then be invoked with the additional parameter
>>`--lua-script=citation-spans.lua`.
>>
>> --
>>You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>>To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87po904ffv.fsf%40zeitkraut.de.
>>For more options, visit https://groups.google.com/d/optout.
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87k1z84bpy.fsf%40zeitkraut.de.
For more options, visit https://groups.google.com/d/optout.
next prev parent reply other threads:[~2017-11-02 21:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-01 13:25 distantflag
[not found] ` <90e14ff2-6cec-4dfe-9236-0998cf317b6c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-11-01 16:40 ` John MACFARLANE
2017-11-01 20:40 ` Albert Krewinkel
[not found] ` <87tvyd4trv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2017-11-02 7:39 ` distantflag
[not found] ` <cfc702fb-7389-4b78-88c8-0ec235ffa481-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-11-02 7:53 ` Björn Ekström
[not found] ` <5fdd83a6-e681-42bf-91b5-1216e605f76b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-11-02 19:22 ` John MACFARLANE
2017-11-02 20:02 ` Albert Krewinkel
[not found] ` <87po904ffv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2017-11-02 20:22 ` John MACFARLANE
2017-11-02 21:22 ` Albert Krewinkel [this message]
[not found] ` <87k1z84bpy.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2017-11-02 22:19 ` John MACFARLANE
2017-11-03 9:37 ` Björn Ekström
[not found] ` <1de89ee9-9064-4020-8419-4bcf7755cf9b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-11-03 9:56 ` Björn Ekström
[not found] ` <219efc35-d812-4b40-addd-adaed55955d8-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2017-11-03 18:51 ` Albert Krewinkel
[not found] ` <87bmkj42mv.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2017-11-04 7:04 ` Björn Ekström
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k1z84bpy.fsf@zeitkraut.de \
--to=albert+pandoc-9eawchwdxg8hfhg+jk9f0w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).