public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>
To: Andrzej Wodecki
	<andrzej.wodecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	pandoc-discuss
	<pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: generate bibliography from citations keys in docx?
Date: Wed, 25 Mar 2020 13:21:34 -0700	[thread overview]
Message-ID: <m2wo78rxrl.fsf@johnmacfarlane.net> (raw)
In-Reply-To: <db7c031a-9b53-42e5-b073-f70fa0c16de1-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>


function Str(el)
  local citekey = el.text:match("[[]@(%w+)[]]")
  local citation = pandoc.Citation(citekey, 'NormalCitation')
  return pandoc.Cite({pandoc.Str(citekey)},
                     {citation})
end

Andrzej Wodecki <andrzej.wodecki-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> DearJohn, 
>
> many thanks. I've tried, and with:
>
> pandoc in.docx --filter pandoc-citeproc --bibliography mylibrary.bib -t 
> native
>
> I get
>
> [Para [Str "From",Space,Str "[@andy2020]",Space,Str ...
>
> as you suggested. I've looked at: https://pandoc.org/lua-filters.html
> and successfully run the first example "smallcaps.lua". But here I'm stuck: 
> I don't know how to write the filter for 
> Str "[@ > Cite "[
> replacement.
>
> If its not a problem, I would appreciate any tip/help, or just a snippet,
>
> many thanks in advance, 
>
> Andy
>
>
> W dniu środa, 25 marca 2020 17:36:06 UTC+1 użytkownik John MacFarlane 
> napisał:
>>
>>
>> You could use a lua filter. 
>>
>> If you do `pandoc your.docx -t native` you'll see how pandoc 
>> parses these faux markdown citations. 
>>
>> If they appear as 
>>
>> Str "[@jones]" 
>>
>> then you could use a filter to replace any Str elements 
>> fitting this pattern with a Cite element.  I can't explain 
>> the whole thing here -- if you want to pursue this, see 
>> the lua filter docs on the website. 
>>
>> Andrzej Wodecki <andrzej...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>> writes: 
>>
>> > The reason I have citation keys in MS Word is a consequence of my 
>> original 
>> > workflow: 
>> > Scrivener > markdown > pandoc-citeproc > MS Word, BTW described here: 
>> > 
>> https://medium.com/@andrzej.wodecki/scrivener-for-scientific-writing-setup-af5edf4482b8 
>> > 
>> > But at the final stage of my writings I escaped from Scrivener (export 
>> to 
>> > MS Word), with only citation keys left in my doc. 
>> > If only I start from scratch in MS Word that wouldn't be a problem, 
>> but... 
>> > 
>> > My temporary workaround (very primitive, but works) is: 
>> > 1. docx > pandoc > markdown 
>> > 2. markdown: replace all \@ by @ 
>> > 3. markdown > pandoc-citeproc > docx 
>> > 
>> > Anyway, if you have any ideas for anything smarter would be nice to hear 
>> :) 
>> > 
>> > Yours, 
>> > 
>> > Andy 
>> > 
>> > 
>> > W dniu środa, 25 marca 2020 14:11:06 UTC+1 użytkownik Joseph napisał: 
>> >> 
>> >> 
>> >> On 3/25/20 8:01 AM, Andrzej Wodecki wrote: 
>> >> > Second trial   
>> >> > with in.docx: 
>> >> 
>> >> Pandoc doesn't expect to find markdown (including pandoc's citation 
>> >> syntax) in a Word file. That only works in markdown files (and perhaps 
>> org 
>> >> files). So when it sees a citation in word->markdown, it takes it 
>> >> literally, and escapes the brackets so it remains so in the markdown. 
>> >> 
>> >> Perhaps someone else can recommend a configuration that won't escape 
>> >> citation syntax, allowing you to go to markdown, and then from that 
>> back to 
>> >> Word. 
>> >> 
>> >> This seems convoluted though. If you're using Zotero, why not use the 
>> Word 
>> >> plugin for that? Or, why not stay in markdown as your source document? 
>> >> 
>> >> 
>> > 
>> > -- 
>> > 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/pandoc-discuss/7e7dfd7e-1bf1-4557-a5f0-e686d48e2438%40googlegroups.com. 
>>
>>
>
> -- 
> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/db7c031a-9b53-42e5-b073-f70fa0c16de1%40googlegroups.com.

-- 
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2wo78rxrl.fsf%40johnmacfarlane.net.


  parent reply	other threads:[~2020-03-25 20:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 12:01 Andrzej Wodecki
     [not found] ` <4d035407-d692-4ada-ac1a-b2668c8c80bc-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-03-25 13:10   ` Joseph Reagle
     [not found]     ` <30f53079-9e7a-2046-f458-b23f9736ac48-T1oY19WcHSwdnm+yROfE0A@public.gmane.org>
2020-03-25 16:14       ` Andrzej Wodecki
     [not found]         ` <7e7dfd7e-1bf1-4557-a5f0-e686d48e2438-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-03-25 16:35           ` John MacFarlane
     [not found]             ` <m28sjotmsv.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2020-03-25 17:09               ` Andrzej Wodecki
     [not found]                 ` <db7c031a-9b53-42e5-b073-f70fa0c16de1-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-03-25 20:21                   ` John MacFarlane [this message]
     [not found]                     ` <m2wo78rxrl.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2020-03-26  6:13                       ` Andrzej Wodecki
     [not found]                         ` <23e7c785-0f67-4b15-92b6-5c05cf2be2f7-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-03-26 16:35                           ` John MacFarlane
     [not found]                             ` <m2imirm5uo.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2020-03-27  5:34                               ` Andrzej Wodecki
     [not found]                                 ` <371930ea-0898-4ab1-a3dc-ad0af946fd30-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-05-24  3:02                                   ` Ioan Muntean

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=m2wo78rxrl.fsf@johnmacfarlane.net \
    --to=jgm-tvlzxgkolnx2fbvcvol8/a@public.gmane.org \
    --cc=andrzej.wodecki-Re5JQEeQqe8AvxtiuMwx3w@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).