Lua patterns have a nice feature for this, try '\\cite%b{}'

This should match everything between the starting and closing curly braces.

Sandra Martin <sandrushba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> hat am 26.08.2022 21:23 CEST geschrieben:

Hi Bastien,

Thank you for your quick reply! I got it to work with: "\\cite{%w+}"

The only left is that this only matches one reference but doesn't work when there's multiple, for example "\cite{reference, referecen2, reference3}"

I've been playing around with "\\cite{%w+%p?%s?%w+}" but I can't get it to work with the space after the comma. Would you know a solution?

Thanks a lot!!

Bastien Dumont schrieb am Freitag, 26. August 2022 um 19:41:08 UTC+2:

In `"\\cite[{](%w+)[}]"`, `(%w+)` is a capture. When the pattern in string.match() specifies a capture, it is returned instead of the whole match, so `citekey` has the value of the *content* of `\cite{...}` instead of the whole macro. I guess that it should work if you remove the parentheses.

Le Friday 26 August 2022 à 10:08:50AM, Sandra Martin a écrit :
> Hello all,
>
> I have trouble writing the correct lua filter for my pandoc conversion of docx
> to latex.
>
> In short, I have citations in the format "\cite{reference}" (csl style from
> Better Bibtex) in my docx file, which I would like to preserve and keep
> unchanged during pandoc conversion.
>
> When calling "pandoc --to=native test.docx", I see that pandoc reads these
> entries as strings and I've tried writing filters with pandoc.RawInline to
> preserve these strings. However, using for instance this function keeps the
> reference keys but gets rid of all the latex formatting (the backslash and the
> curly brackets):
> function Str(el)
> local citekey = el.text:match("\\cite[{](%w+)[}]")
> if citekey then
> return pandoc.RawInline('latex', citekey)
> end
> end
>
> How do I keep my latex-styled reference strings as they are during pandoc
> conversion?
>
> Thanks in advance!
> Sandra
>
> --
> 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/0df70b72-8e13-4e1c-986f-6a54ef352f6cn%40googlegroups.com <http://40googlegroups.com>.
>
> References:
>
> [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/0df70b72-8e13-4e1c-986f-6a54ef352f6cn%40googlegroups.com?utm_medium=email&utm_source=footer

--
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 <mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7fc77e34-86e4-48a2-8642-e226d1ae08ben%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/7fc77e34-86e4-48a2-8642-e226d1ae08ben%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

--
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/36B1ABBF-804C-4785-BB14-E29AEE6423E4%40zeitkraut.de.