Dear John, 

many many thanks, You helped me a lot. I almost there - and as always almost makes a difference...

At the moment, having 

From [@andy2020] we can see that...

in in.docx, and Your snippet in cite.lua, when I run:
pandoc in.docx --lua-filter=cite.lua --filter pandoc-citeproc --bibliography mylibrary.bib -o out.docx

I get out.docx as:
(Kaelbling, Littman, and Moore 1996)
Kaelbling, Leslie Pack, Michael L. Littman, and Andrew W. Moore. 1996. “Reinforcement Learning: A Survey.” Journal of Artificial Intelligence Research 4: 237–85.

So, the only thing left is citation [@andy2020], but all other texts are gone...

Sorry for bothering You, but what should I do to just replace [@andy2020] with reference and create Bibliography at the end, but having all other texts intact?

Many thanks for the support, 

Andy

PS. I spent some time on pandoc-lua page, but didn't make it...


W dniu środa, 25 marca 2020 21:21:51 UTC+1 użytkownik John MacFarlane napisał:

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...-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-...@googlegroups.com.
> 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/23e7c785-0f67-4b15-92b6-5c05cf2be2f7%40googlegroups.com.