From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31183 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lyndon Drake Newsgroups: gmane.text.pandoc Subject: Re: Changing LaTeX output for citations inside footnotes Date: Sat, 6 Aug 2022 03:56:27 -0700 (PDT) Message-ID: <7404c6ef-789f-4fec-bf16-be469839b935n@googlegroups.com> References: <97765931b0a740ed8a84ba4337bed661@unibe.ch> <90c69f14-e16a-44d6-91ec-a6f6dca3ca45n@googlegroups.com> <8976ce00-3fbe-bf27-898f-0470cba1fec1@gmail.com> <0e10379f-d1c0-4024-b98a-5c7ba703f561n@googlegroups.com> <83a04bea-2e09-61d2-de0d-f399beb2ef79@gmail.com> <76a7fa0b-752b-496e-98a3-cc6ee8ef68b0n@googlegroups.com> <7ead9a3f-3aa9-fb2e-5ad5-c069d2aee315@gmail.com> <5d1a1315-d0df-4e28-b13b-8eb8e8d7f9c7n@googlegroups.com> <28ac6c29-817d-41b6-891e-915ea28bdf3bn@googlegroups.com> <1485f3b9-f893-c00d-6546-904732bf64ae@gmail.com> <67cbd620-a60e-2518-24fd-e618ece65d5c@gmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_756_1280909579.1659783387817" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13389"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCKOX6WY7EKBBXMRXGLQMGQE4TK5MXQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Aug 06 12:56:33 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-yw1-f187.google.com ([209.85.128.187]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oKHTs-0003HY-Jq for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 06 Aug 2022 12:56:32 +0200 Original-Received: by mail-yw1-f187.google.com with SMTP id 00721157ae682-31f5960500bsf40930817b3.14 for ; Sat, 06 Aug 2022 03:56:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc; bh=tLJfpsIWrtMYwAVB9jtuUd/PJ9goe95V0PafXYN98gc=; b=AOdFoR52goEznyMnBsRF6EdGlhGjcvbDp3nRkh5x5F51aujo+GiV+g3gOSNBq22Kzm VYNZZn+xwwRogpr+3Qcx9xUi+6WMMUUt0gjaoyT2xo/+L8gj0gK9lq+m+UcufvrVzDIK XdqNmdcfPUTHQcgqvf73e9bHiS40SXXRWCffhVrTe/cQvrxQ1qLZEJBxudnFkU8x8yfT onB0hlJsUaO3V0q1oC3XQp0dO85891sB2NQeZEcK4z+ZwezBwMIR5YSCoiKza9PfWAZP gkwUqAqL0itXdKoZprkRD4gkdpImeks0oLx2GSwuxND+rppzuW0322lje/NXyas4gSMp pEVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc; bh=tLJfpsIWrtMYwAVB9jtuUd/PJ9goe95V0PafXYN98gc=; b=cre8oAtVXW2M4+ab0hbBL7ozfnrdQHi0gcelgEvCp/gM6tWoD8eQxaUGBlD5Fwanm3 s5+lcbueuRr37Y8LJ+d5jNIL/bHEaQYPLgsXOrcHyUWWVttp3XjIuOedUEyAsBOXvFI/ jz1eZPHvCzD6MkCc3NheV1AXPfYpwA1KtP4m7lCyJDjscuGSNBd4SBM/I3+MmMcbbJQS 3pv4Mh+xwNRxf2NeLBQnmVh2TMRMown6G1qf7kDff7uwY17pt6EHLSsYg0mQUFA+p/GL 1jJlPUXf92tPb2eEILMZQWXiYbt6sfPmO8qayi+DKvPwpVV7CmzyZx3hiJD9Fa9ps2te yjOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc; bh=tLJfpsIWrtMYwAVB9jtuUd/PJ9goe95V0PafXYN98gc=; b=mHMCCYcdr3ANg+HqtP001IgYLSgowPjfALj5Xfx7RY0eQDcs0ZW5G32OLMuuQmrydF hS2xxOPND7pzAe5XcdVZrepeQWhRJPebGmQhaEG9Fkzhg65v1pQIeQSV+eIcSVnEzrWP DBwNGNTODGDzRwc0dqHVbxFwL/4J2roxyh5WYlTikIksuhSe7WOrbfe73ulofQbrFOMF 4o7I00EXW40EhiufJv+Wi7uvUWas66KudWWo4UY6DM+atdWijAscJ9RxEGWeMNEE3Mkz zRH1yitcMwxoLTt7x4EaUs+m6nXPYL5yPDCXLgdekfUfmNXCR51nLjS+ctizMapcs1JN FYNg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACgBeo2FQICFqWZ47gdwB5jC/dkAzzszm7KEyZBG/mrIDNEXZkqFEP19 qVdZKNMTxad9GUGWt8hgHhU= X-Google-Smtp-Source: AA6agR6FwVLSndmyRpgbM67/ZdtXZ1jHcifMU2qrzrrIu1ozoxu9X9GwzvggFs7BlrBXbJwjHv0m7g== X-Received: by 2002:a25:8a85:0:b0:671:715e:a1b0 with SMTP id h5-20020a258a85000000b00671715ea1b0mr8825686ybl.98.1659783391479; Sat, 06 Aug 2022 03:56:31 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a25:a4a1:0:b0:676:a8d8:fc2d with SMTP id g30-20020a25a4a1000000b00676a8d8fc2dls3874214ybi.10.-pod-prod-gmail; Sat, 06 Aug 2022 03:56:28 -0700 (PDT) X-Received: by 2002:a05:6902:1024:b0:677:3561:c5ed with SMTP id x4-20020a056902102400b006773561c5edmr8627224ybt.260.1659783388571; Sat, 06 Aug 2022 03:56:28 -0700 (PDT) In-Reply-To: <67cbd620-a60e-2518-24fd-e618ece65d5c-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> X-Original-Sender: isenguard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:31183 Archived-At: ------=_Part_756_1280909579.1659783387817 Content-Type: multipart/alternative; boundary="----=_Part_757_427954217.1659783387817" ------=_Part_757_427954217.1659783387817 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Well, below is the code as it is at the moment=E2=80=A6 I still need a Pand= oc=20 object to pass to pandoc.write, so even if I use blocks_to_inlines, I'm not= =20 sure what I'd then do to produce the output I'm after? ``` function Writer(doc, opts) local filter =3D { Note =3D function(el) return el:walk { Cite =3D function(el) -- processing logic local citetext =3D "" if #el.citations > 1 then if el.citations[1].mode =3D=3D "AuthorInText" then citetext =3D '\\cites' elseif el.citations[1].mode =3D=3D "SuppressAuthor"= then citetext =3D '\\parencites*' elseif el.citations[1].mode =3D=3D "NormalCitation"= then citetext =3D '\\parencites' end else if el.citations[1].mode =3D=3D "AuthorInText" then citetext =3D '\\cite' elseif el.citations[1].mode =3D=3D "SuppressAuthor"= then citetext =3D '\\parencite*' elseif el.citations[1].mode =3D=3D "NormalCitation"= then citetext =3D '\\parencite' end end for _, c in pairs(el.citations) do if #c.prefix > 0 then local doc =3D pandoc.Pandoc(c.prefix) local citeprefix =3D pandoc.write(doc, 'latex') citetext =3D citetext .. '[' .. citeprefix .. '= ]' end if #c.suffix > 0 then local doc =3D pandoc.Pandoc(c.suffix) local citesuffix =3D pandoc.write(doc, 'latex') citetext =3D citetext .. '[' .. citesuffix .. '= ]' end citetext =3D citetext .. '{' .. c.id .. '}' end citetext =3D citetext:gsub("\n+", " ") = =20 print(citetext) return pandoc.RawInline('latex', citetext) end } end } return pandoc.write(doc:walk(filter), 'latex', opts) end ``` On Friday, 5 August 2022 at 21:47:46 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > Woops, please ignore, I misunderstood doc as referring to the `doc` and= =20 > not a document. > > > El 05/08/2022 a las 22:43, Sukil Etxenike arizaleta escribi=C3=B3: > > I think `doc`'s fields and methods aren't documented, that's why I didn't= =20 > think of that. Good call! > > > El 05/08/2022 a las 16:36, BPJ escribi=C3=B3: > > But doc.blocks, which is the actual content of the doc, is a list of=20 > blocks, which you can pass to blocks_to_inlines. Don't forget to pass=20 > `{pandoc.Space()}` as the second argument! > > Den fre 5 aug. 2022 13:08Lyndon Drake skrev: > >> Not really, because the issue is that Pandoc returns a doc, not a list o= f=20 >> blocks. So blocks_to_inlines doesn't actually work. But the gsub trick= =20 >> works well enough to get around the issue, thankfully. >> >> On Monday, 1 August 2022 at 14:48:59 UTC+1 BP wrote: >> >>> Can you convert the blocks to inlines with blocks_to_inlines?=20 >>> >>> https://pandoc.org/lua-filters.html#pandoc.utils.blocks_to_inlines >>> >>> Den l=C3=B6r 30 juli 2022 15:54Lyndon Drake skrev: >>> >>>> Nice, the :gsub does the trick (once I replaced \n* with \n+).=20 >>>> >>>> Thanks again, really appreciate the help with all this. Hopefully I ca= n=20 >>>> start to build some more Lua filters/writers now. It's a great system= =20 >>>> (thanks John MacFarlane!). >>>> >>>> On Saturday, 30 July 2022 at 14:06:10 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >>>> >>>>> I believe you can't create a pandoc document without any block. Two= =20 >>>>> possibilities come to mind: >>>>> >>>>> 1. Round tripping: After fixing the citation, read it as LaTeX, and= =20 >>>>> maybe, run pandoc.utils.blocks_to_inlines. (Hey, I never said it woul= dn't=20 >>>>> be messy). May not work, even. >>>>> >>>>> 2. Simply delete all paragraph markers: in your case with:=20 >>>>> citetext:gsub("\n*", " ") >>>>> >>>>> Hth, >>>>> >>>>> Sukil >>>>> >>>>> >>>>> >>>>> El 30/07/2022 a las 14:39, Lyndon Drake escribi=C3=B3: >>>>> >>>>> Hi Sukil,=20 >>>>> >>>>> Thanks, you were quite correct about the second problem. I've amended= =20 >>>>> that and it now works, at least in the sense that it is altering the = output=20 >>>>> in the general way I want. >>>>> >>>>> On the first problem, I can just pandoc.stringify the prefix and=20 >>>>> suffix, and concatenate. The problem with that is I will then lose an= y=20 >>>>> Markdown formatting, which is not entirely uncommon in a prefix, and = even=20 >>>>> occasionally in a suffix. I can work around it for this document, I g= uess,=20 >>>>> by just being careful not to use any Markdown formatting in these=20 >>>>> instances, but I'd love to find a way to take a set of Inlines and co= nvert=20 >>>>> it to a format without adding a block. >>>>> >>>>> On Friday, 29 July 2022 at 19:04:51 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> For your first problem, when you do pandoc.write, as a minimum a=20 >>>>>> block is created, which, I believe, is normally a paragraph. So, don= 't call=20 >>>>>> pandoc.write. I guess you can concatenate the prefix, citation and s= uffix=20 >>>>>> and pass them to the pandoc.RawInline function.=20 >>>>>> >>>>>> >>>>>> For your second problem, I am guessing you are using --citeproc in= =20 >>>>>> your defaults file. If that is the case, try: 1) putting the default= s file=20 >>>>>> after the filter; or 2) specifying --citeproc manually, also after t= he=20 >>>>>> filter. >>>>>> >>>>>> Hth, >>>>>> >>>>>> Sukil >>>>>> >>>>>> >>>>>> El 29/07/2022 a las 16:58, Lyndon Drake escribi=C3=B3: >>>>>> >>>>>> Thanks for all the help - definitely getting somewhere now! >>>>>> >>>>>> I guess what I want to avoid is replicating in my not-great-Lua code= =20 >>>>>> all the work Pandoc already has to take a string of Markdown and con= vert it=20 >>>>>> to LaTeX. I'm using pandoc.write to attempt that, and it seems to be= =20 >>>>>> working to some degree. The code as it is now is below. I have two= =20 >>>>>> problems:=20 >>>>>> >>>>>> 1. This Markdown input [@Haran1982 165 n. 9, 172] gets converted by= =20 >>>>>> my calling of pandoc.write into: >>>>>> >>>>>> ``` >>>>>> \cite[165 >>>>>> >>>>>> n.~9, >>>>>> >>>>>> 172]{Haran1982} >>>>>> ``` >>>>>> >>>>>> and I can't figure out why the blank lines are turning up. I imagine= =20 >>>>>> I need to do something more clever with the Inlines? >>>>>> >>>>>> >>>>>> 2. Despite the fact that my output in the terminal shows that I am= =20 >>>>>> constructing the citetext variable as I am intending to, and I have = this=20 >>>>>> line of code: >>>>>> >>>>>> return pandoc.RawInline('latex', citetext) >>>>>> >>>>>> The output .tex file still has the normal Pandoc citations. In other= =20 >>>>>> words, my writer is constructing a nice LaTeX string with what I wan= t in=20 >>>>>> it, and then discards it in favour of the normal Pandoc code, which = is a=20 >>>>>> little bit depressing. >>>>>> >>>>>> Can anyone spot what I'm missing now? >>>>>> >>>>>> Best, >>>>>> Lyndon >>>>>> >>>>>> ``` >>>>>> function Writer(doc, opts) >>>>>> local filter =3D { >>>>>> Note =3D function(el) >>>>>> return el:walk { >>>>>> Cite =3D function(el) >>>>>> -- processing logic >>>>>> local citetext =3D "" >>>>>> if #el.citations > 1 then >>>>>> if el.citations[1].mode =3D=3D "AuthorInText= " then >>>>>> citetext =3D '\\textcites*' >>>>>> elseif el.citations[1].mode =3D=3D=20 >>>>>> "SuppressAuthor" then >>>>>> citetext =3D '\\cites*' >>>>>> elseif el.citations[1].mode =3D=3D=20 >>>>>> "NormalCitation" then >>>>>> citetext =3D '\\cites' >>>>>> end >>>>>> else >>>>>> if el.citations[1].mode =3D=3D "AuthorInText= " then >>>>>> citetext =3D '\\textcite*' >>>>>> elseif el.citations[1].mode =3D=3D=20 >>>>>> "SuppressAuthor" then >>>>>> citetext =3D '\\cite*' >>>>>> elseif el.citations[1].mode =3D=3D=20 >>>>>> "NormalCitation" then >>>>>> citetext =3D '\\cite' >>>>>> end >>>>>> end >>>>>> for _, c in pairs(el.citations) do >>>>>> if #c.prefix > 0 then >>>>>> local doc =3D pandoc.Pandoc(c.prefix) >>>>>> local citeprefix =3D pandoc.write(doc,= =20 >>>>>> 'latex') >>>>>> citetext =3D citetext .. '[' .. citepref= ix=20 >>>>>> .. ']' >>>>>> end >>>>>> if #c.suffix > 0 then >>>>>> local doc =3D pandoc.Pandoc(c.suffix) >>>>>> local citesuffix =3D pandoc.write(doc,= =20 >>>>>> 'latex') >>>>>> citetext =3D citetext .. '[' .. citesuff= ix=20 >>>>>> .. ']' >>>>>> end >>>>>> citetext =3D citetext .. '{' .. c.id .. '}' >>>>>> print(citetext) >>>>>> end >>>>>> return pandoc.RawInline('latex', citetext) >>>>>> end >>>>>> } >>>>>> end >>>>>> } >>>>>> return pandoc.write(doc:walk(filter), 'latex', opts) >>>>>> end >>>>>> ``` >>>>>> >>>>>> On Friday, 29 July 2022 at 10:49:18 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >>>>>> >>>>>>> I don't know, but the building blocks you'll need are=20 >>>>>>> `pandoc.stringify` which takes any object and converts it into a st= ring,=20 >>>>>>> and `pandoc.RawBlock` or `pandoc.RawInline` which convert a string = into a=20 >>>>>>> raw block or inline, and take the format as first argument and the = string=20 >>>>>>> as second. >>>>>>> >>>>>>> Hth, >>>>>>> >>>>>>> Sukil >>>>>>> >>>>>>> >>>>>>> El 29/07/2022 a las 10:58, Lyndon Drake escribi=C3=B3: >>>>>>> >>>>>>> So I have the citation prefix, which I guess I have to convert to a= =20 >>>>>>> valid LaTeX string. How can I take an Inlines and LaTeX-ify it to a= string? >>>>>>> >>>>>>> On Friday, 29 July 2022 at 09:51:35 UTC+1 Lyndon Drake wrote: >>>>>>> >>>>>>>> Ah yep, that works. Next thing is I have to debug my obviously=20 >>>>>>>> incorrect code :-) >>>>>>>> >>>>>>>> On Friday, 29 July 2022 at 06:44:22 UTC+1 denis...-NSENcxR/0n0@public.gmane.org wrote: >>>>>>>> >>>>>>>>> That's the problem. This is a writer, not a filter. So you need t= o=20 >>>>>>>>> call it via=20 >>>>>>>>> -t latex-footcite.lua=20 >>>>>>>>> ________________________________________=20 >>>>>>>>> Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im= =20 >>>>>>>>> Auftrag von Lyndon Drake =20 >>>>>>>>> Gesendet: Freitag, 29. Juli 2022 07:15:08=20 >>>>>>>>> An: pandoc-discuss=20 >>>>>>>>> Betreff: Re: Changing LaTeX output for citations inside footnotes= =20 >>>>>>>>> >>>>>>>>> My command line is:=20 >>>>>>>>> >>>>>>>>> pandoc -dbookends-latex --template=20 >>>>>>>>> /Users/lyndon/.local/share/pandoc/templates/book.latex=20 >>>>>>>>> --lua-filter=3D/Users/lyndon/.local/share/pandoc/filters/latex-fo= otcite.lua=20 >>>>>>>>> -s -o thesis_jeremiah_32.tex jer-32-thesis.md=20 >>>>>>>>> >>>>>>>>> It's definitely picking up the lua file because if I have a synta= x=20 >>>>>>>>> error, pandoc tells me. But I don't get any output.=20 >>>>>>>>> >>>>>>>>> On Thursday, 28 July 2022 at 21:32:06 UTC+1 denis...-NSENcxR/0n0@public.gmane.org=20 >>>>>>>>> wrote:=20 >>>>>>>>> How do you run this ?=20 >>>>>>>>> I=E2=80=99ve tested with a minimal markdown file :=20 >>>>>>>>> >>>>>>>>> ```markdown=20 >>>>>>>>> asdf=20 >>>>>>>>> ```=20 >>>>>>>>> >>>>>>>>> Run with :=20 >>>>>>>>> pandoc asdf.md -t mylatex.lua=20 >>>>>>>>> >>>>>>>>> Result :=20 >>>>>>>>> got here=20 >>>>>>>>> asdf=20 >>>>>>>>> >>>>>>>>> So, it prints the first print statement of the writer.=20 >>>>>>>>> >>>>>>>>> Denis=20 >>>>>>>>> >>>>>>>>> Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Im= =20 >>>>>>>>> Auftrag von Lyndon Drake=20 >>>>>>>>> Gesendet: Donnerstag, 28. Juli 2022 19:17=20 >>>>>>>>> An: pandoc-discuss =20 >>>>>>>>> Betreff: Re: Changing LaTeX output for citations inside footnotes= =20 >>>>>>>>> >>>>>>>>> Thanks for this - exactly what I needed. I've added my attempt at= =20 >>>>>>>>> the code below, but I must be missing some basic part of it becau= se it=20 >>>>>>>>> doesn't do anything. I added a couple of print statements that ne= ver get=20 >>>>>>>>> executed:=20 >>>>>>>>> >>>>>>>>> ```=20 >>>>>>>>> function Writer(doc, opts)=20 >>>>>>>>> print "got here"=20 >>>>>>>>> local filter =3D {=20 >>>>>>>>> Note =3D function(el)=20 >>>>>>>>> return el:walk {=20 >>>>>>>>> Cite =3D function(el)=20 >>>>>>>>> -- processing logic=20 >>>>>>>>> print "got further"=20 >>>>>>>>> local citation =3D ""=20 >>>>>>>>> if #el.citations > 1 then=20 >>>>>>>>> if citations[1].mode =3D=3D "AuthorInText" then=20 >>>>>>>>> citation =3D '\\textcites*'=20 >>>>>>>>> elseif citations[1].mode =3D=3D "SuppressAuthor" then=20 >>>>>>>>> citation =3D '\\cites*'=20 >>>>>>>>> elseif citations[1].mode =3D=3D "NormalCitation" then=20 >>>>>>>>> citation =3D '\\cites'=20 >>>>>>>>> end=20 >>>>>>>>> else=20 >>>>>>>>> if citations[1].mode =3D=3D "AuthorInText" then=20 >>>>>>>>> citation =3D '\\textcite*'=20 >>>>>>>>> elseif citations[1].mode =3D=3D "SuppressAuthor" then=20 >>>>>>>>> citation =3D '\\cite*'=20 >>>>>>>>> elseif citations[1].mode =3D=3D "NormalCitation" then=20 >>>>>>>>> citation =3D '\\cite'=20 >>>>>>>>> end=20 >>>>>>>>> end=20 >>>>>>>>> for c in el.citations do=20 >>>>>>>>> if c.prefix ~=3D "" then=20 >>>>>>>>> citation =3D citation .. '[' .. c.prefix .. ']'=20 >>>>>>>>> end=20 >>>>>>>>> if c.suffix ~=3D "" then=20 >>>>>>>>> citation =3D citation .. '[' .. c.suffix .. ']'=20 >>>>>>>>> end=20 >>>>>>>>> citation =3D citation .. '{' .. c.id .. '}'=20 >>>>>>>>> end=20 >>>>>>>>> return pandoc.RawInline('latex', citation)=20 >>>>>>>>> end=20 >>>>>>>>> }=20 >>>>>>>>> end=20 >>>>>>>>> }=20 >>>>>>>>> return pandoc.write(doc:walk(filter), 'latex', opts)=20 >>>>>>>>> end=20 >>>>>>>>> ```=20 >>>>>>>>> >>>>>>>>> Apologies for what must be a very basic question, but what am I= =20 >>>>>>>>> missing here?=20 >>>>>>>>> On Wednesday, 27 July 2022 at 11:27:32 UTC+1 denis...-NSENcxR/0n0@public.gmane.org=20 >>>>>>>>> wrote:=20 >>>>>>>>> What kind of example do you need? I only know about the examples= =20 >>>>>>>>> in the documentation.=20 >>>>>>>>> >>>>>>>>> I think this here is a nice one :=20 >>>>>>>>> >>>>>>>>> https://pandoc.org/lua-filters.html#modifying-pandocs-manual.txt-= for-man-pages=20 >>>>>>>>> >>>>>>>>> Or : the new style writer=20 >>>>>>>>> >>>>>>>>> https://pandoc.org/custom-writers.html#example-modified-markdown-= writer=20 >>>>>>>>> >>>>>>>>> So, something like this here could be start:=20 >>>>>>>>> >>>>>>>>> ```=20 >>>>>>>>> function Writer(doc, opts)=20 >>>>>>>>> local filter =3D {=20 >>>>>>>>> Note =3D function(el)=20 >>>>>>>>> return el:walk {=20 >>>>>>>>> Cite =3D function(el)=20 >>>>>>>>> -- processing logic=20 >>>>>>>>> return pandoc.RawInline('latex', '\\cite[prenote][postnote]{key}'= )=20 >>>>>>>>> end=20 >>>>>>>>> }=20 >>>>>>>>> end=20 >>>>>>>>> }=20 >>>>>>>>> return pandoc.write(doc:walk(filter), 'latex', opts)=20 >>>>>>>>> end=20 >>>>>>>>> ```=20 >>>>>>>>> >>>>>>>>> I don=E2=80=99t think you can get the current writer in Lua.=20 >>>>>>>>> >>>>>>>>> >>>>>>>>> Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Im= =20 >>>>>>>>> Auftrag von Lyndon Drake=20 >>>>>>>>> Gesendet: Dienstag, 26. Juli 2022 11:00=20 >>>>>>>>> An: pandoc-discuss =20 >>>>>>>>> Betreff: Re: Changing LaTeX output for citations inside footnotes= =20 >>>>>>>>> >>>>>>>>> Thanks for this. I can see how that could work.=20 >>>>>>>>> >>>>>>>>> Can you point me to another example that uses the walk function?= =20 >>>>>>>>> >>>>>>>>> Regarding a new-style Lua writer, is there a way to get the=20 >>>>>>>>> current LaTeX writer as Lua code? Or is it just the Haskell code?= (I once=20 >>>>>>>>> knew Haskell but that was rather a long time ago.)=20 >>>>>>>>> On Monday, 25 July 2022 at 22:02:38 UTC+1 denis...-NSENcxR/0n0@public.gmane.org=20 >>>>>>>>> wrote:=20 >>>>>>>>> I can't come up with a code example now, bit you can use the walk= =20 >>>>>>>>> function (https://pandoc.org/lua-filters.html#type-block:walk) to= =20 >>>>>>>>> modify the citations with a given mode inside notes. You'll need = to build=20 >>>>>>>>> the citation via Pandoc.RawInline=20 >>>>>>>>> Maybe that would be a good example of a new style Lua writer.=20 >>>>>>>>> ________________________________________=20 >>>>>>>>> Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im= =20 >>>>>>>>> Auftrag von Lyndon Drake =20 >>>>>>>>> Gesendet: Montag, 25. Juli 2022 21:46:28=20 >>>>>>>>> An: pandoc-discuss=20 >>>>>>>>> Betreff: Changing LaTeX output for citations inside footnotes=20 >>>>>>>>> >>>>>>>>> Hi,=20 >>>>>>>>> >>>>>>>>> So this is a slightly odd request, which really comes because of= =20 >>>>>>>>> the unusual behaviour of the specific BibLaTeX bibliography style= I'm=20 >>>>>>>>> using. In that style, \textcite inside a footnote produces an unw= anted=20 >>>>>>>>> result. \cite produces the expected output. I have generally just= gone=20 >>>>>>>>> through and hand-edited my Pandoc-produced LaTeX files when they = get to the=20 >>>>>>>>> final copy stage, but that's painful, and I also thought that may= be this is=20 >>>>>>>>> possible to do in a Lua filter.=20 >>>>>>>>> >>>>>>>>> But I don't quite know where to start - obviously this is a bit= =20 >>>>>>>>> different from the internal Pandoc citations. I'm going to begin = the filter=20 >>>>>>>>> with this:=20 >>>>>>>>> >>>>>>>>> if FORMAT:match 'latex' then < >>>>>>>>> https://pandoc.org/lua-filters.html#cb9-3> function=20 >>>>>>>>> >>>>>>>>> but what would the function be? If it is Footnote, then I don't= =20 >>>>>>>>> really want the AST, I want the LaTeX that forms the footnote con= tents, and=20 >>>>>>>>> I suppose then I can just replace any occurrences of the string \= textcite=20 >>>>>>>>> with the string \cite?=20 >>>>>>>>> >>>>>>>>> Any help would be awesome!=20 >>>>>>>>> >>>>>>>>> Best,=20 >>>>>>>>> Lyndon=20 >>>>>>>>> >>>>>>>>> --=20 >>>>>>>>> You received this message because you are subscribed to the Googl= e=20 >>>>>>>>> Groups "pandoc-discuss" group.=20 >>>>>>>>> To unsubscribe from this group and stop receiving emails from it,= =20 >>>>>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>>>>>>>> pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.=20 >>>>>>>>> To view this discussion on the web visit=20 >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/bc06a6d8-9a34-4c= a9-a05d-2526b23c6f6dn%40googlegroups.com >>>>>>>>> < >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/bc06a6d8-9a34-4c= a9-a05d-2526b23c6f6dn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfo= oter>.=20 >>>>>>>>> >>>>>>>>> --=20 >>>>>>>>> You received this message because you are subscribed to the Googl= e=20 >>>>>>>>> Groups "pandoc-discuss" group.=20 >>>>>>>>> To unsubscribe from this group and stop receiving emails from it,= =20 >>>>>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org=20 >>>>>>>>> To view this discussion on the web visit=20 >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/d25cee8b-7cb2-4f= e9-b44d-f288a8fef728n%40googlegroups.com >>>>>>>>> < >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/d25cee8b-7cb2-4f= e9-b44d-f288a8fef728n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfo= oter>.=20 >>>>>>>>> >>>>>>>>> --=20 >>>>>>>>> You received this message because you are subscribed to the Googl= e=20 >>>>>>>>> Groups "pandoc-discuss" group.=20 >>>>>>>>> To unsubscribe from this group and stop receiving emails from it,= =20 >>>>>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org=20 >>>>>>>>> To view this discussion on the web visit=20 >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/90c69f14-e16a-44= d6-91ec-a6f6dca3ca45n%40googlegroups.com >>>>>>>>> < >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/90c69f14-e16a-44= d6-91ec-a6f6dca3ca45n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfo= oter>.=20 >>>>>>>>> >>>>>>>>> >>>>>>>>> --=20 >>>>>>>>> You received this message because you are subscribed to the Googl= e=20 >>>>>>>>> Groups "pandoc-discuss" group.=20 >>>>>>>>> To unsubscribe from this group and stop receiving emails from it,= =20 >>>>>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>>>>>>>> pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.=20 >>>>>>>>> To view this discussion on the web visit=20 >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/c4609f20-77f3-44= 27-83ae-6c79ba48ed5bn%40googlegroups.com >>>>>>>>> < >>>>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/c4609f20-77f3-44= 27-83ae-6c79ba48ed5bn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfo= oter>.=20 >>>>>>>>> >>>>>>>>> >>>>>>>> --=20 >>>>>>> You received this message because you are subscribed to the Google= =20 >>>>>>> Groups "pandoc-discuss" group. >>>>>>> To unsubscribe from this group and stop receiving emails from it,= =20 >>>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>>>> >>>>>>> To view this discussion on the web visit=20 >>>>>>> https://groups.google.com/d/msgid/pandoc-discuss/a1e38719-d239-44af= -84b0-67a1764dbb70n%40googlegroups.com=20 >>>>>>> >>>>>>> . >>>>>>> >>>>>>> --=20 >>>>>> You received this message because you are subscribed to the Google= =20 >>>>>> Groups "pandoc-discuss" group. >>>>>> To unsubscribe from this group and stop receiving emails from it,=20 >>>>>> send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>>> >>>>>> To view this discussion on the web visit=20 >>>>>> https://groups.google.com/d/msgid/pandoc-discuss/0e10379f-d1c0-4024-= b98a-5c7ba703f561n%40googlegroups.com=20 >>>>>> >>>>>> . >>>>>> >>>>>> --=20 >>>>> You received this message because you are subscribed to the Google=20 >>>>> Groups "pandoc-discuss" group. >>>>> To unsubscribe from this group and stop receiving emails from it, sen= d=20 >>>>> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>> >>>>> To view this discussion on the web visit=20 >>>>> https://groups.google.com/d/msgid/pandoc-discuss/76a7fa0b-752b-496e-9= 8a3-cc6ee8ef68b0n%40googlegroups.com=20 >>>>> >>>>> . >>>>> >>>>> --=20 >>>> You received this message because you are subscribed to the Google=20 >>>> Groups "pandoc-discuss" group. >>>> To unsubscribe from this group and stop receiving emails from it, send= =20 >>>> an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> >>> To view this discussion on the web visit=20 >>>> https://groups.google.com/d/msgid/pandoc-discuss/5d1a1315-d0df-4e28-b1= 3b-8eb8e8d7f9c7n%40googlegroups.com=20 >>>> >>>> . >>>> >>> --=20 >> You received this message because you are subscribed to the Google Group= s=20 >> "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n=20 >> email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit=20 >> https://groups.google.com/d/msgid/pandoc-discuss/28ac6c29-817d-41b6-891e= -915ea28bdf3bn%40googlegroups.com=20 >> >> . >> > --=20 > You received this message because you are subscribed to the Google Groups= =20 > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an= =20 > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBDo-Ya3Wabo27CQd%= 3Dt6JGtkzmYOoqbcCW2tkK%3DGKd7FA%40mail.gmail.com=20 > > . > > --=20 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 e= mail 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/7404c6ef-789f-4fec-bf16-be469839b935n%40googlegroups.com. ------=_Part_757_427954217.1659783387817 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Well, below is the code as it is at the moment=E2=80=A6 I still need a Pand= oc object to pass to pandoc.write, so even if I use blocks_to_inlines, I'm = not sure what I'd then do to produce the output I'm after?

```
function Writer(doc, opts)
    local filter = =3D {
        Note =3D function(el)
   =         return el:walk {
       = ;         Cite =3D function(el)
     =               -- processing logic
&n= bsp;                   local c= itetext =3D ""
                &= nbsp;   if #el.citations > 1 then
        &n= bsp;               if el.citations[1].mo= de =3D=3D "AuthorInText" then
            =                 citetext =3D '\\cit= es'
                   = ;     elseif el.citations[1].mode =3D=3D "SuppressAuthor" then                    &nbs= p;       citetext =3D '\\parencites*'
     = ;                   elseif el.= citations[1].mode =3D=3D "NormalCitation" then
      &nbs= p;                     ci= tetext =3D '\\parencites'
            &nbs= p;           end
        &n= bsp;           else
       =                 if el.citations[1]= .mode =3D=3D "AuthorInText" then
          &nbs= p;                 citetext =3D '\\= cite'
                  &nb= sp;     elseif el.citations[1].mode =3D=3D "SuppressAuthor" then<= br>                    &n= bsp;       citetext =3D '\\parencite*'
    &nbs= p;                   elseif el= .citations[1].mode =3D=3D "NormalCitation" then
      &nb= sp;                     c= itetext =3D '\\parencite'
            &nbs= p;           end
        &n= bsp;           end
        =             for _, c in pairs(el.citations) d= o
                    =     if #c.prefix > 0 then
         = ;                   local doc = =3D pandoc.Pandoc(c.prefix)
            &n= bsp;               local citeprefix =3D = pandoc.write(doc, 'latex')
            &nb= sp;               citetext =3D citetext = .. '[' .. citeprefix .. ']'
            &n= bsp;           end
        =                 if #c.suffix > 0= then
                  &nb= sp;         local doc =3D pandoc.Pandoc(c.suffix)
&n= bsp;                     =       local citesuffix =3D pandoc.write(doc, 'latex')
&nb= sp;                     &= nbsp;     citetext =3D citetext .. '[' .. citesuffix .. ']'
&n= bsp;                     =   end
                 = ;       citetext =3D citetext .. '{' .. c.id .. '}'
 = ;                   end
&nb= sp;                   citetext= =3D citetext:gsub("\n+", " ")             &n= bsp;      
            &nbs= p;       print(citetext)
        &nbs= p;           return pandoc.RawInline('latex', cite= text)
                end
&nb= sp;           }
        end=
    }
    return pandoc.write(doc:walk(filter), = 'latex', opts)
end
```

On Friday, 5 August 2022 at 21:47:4= 6 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
=20 =20 =20

Woops, please ignore, I misunderstood doc as referring to the `doc` and not a document.


El 05/08/2022 a las 22:43, Sukil Etxenike arizaleta escribi=C3=B3:
=20

I think `doc`'s fields and methods aren't documented, that= 's why I didn't think of that. Good call!


El 05/08/2022 a las 16:36, BPJ escribi=C3=B3:
=20
But doc.blocks, which is the actual content of the doc, is a list of blocks, which you can pass to blocks_to_inlines. Don't forget to pass `{pandoc.Space()}` as the second argument!

Den fre 5 aug. 2022 13:08Lyndon Drake <isen...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Not really, because the issue is that Pandoc returns a doc, not a list of blocks. So blocks_to_inlines doesn't actually work. But the gsub trick works well enough to get around the issue, thankfully.

On Monday, 1 August 2022 at 14:48:59 UTC+1 BP wrote:
Can you convert the blocks to inlines with blocks_to_inlines?


Den l=C3=B6r 30 jul= i 2022 15:54Lyndon Drake <is= en...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Nice, the :gsub does the trick (once I replaced \n* with \n+).

Thanks again, really appreciate the help with all this. Hopefully I can start to build some more Lua filters/writers now. It's a great system (thanks John MacFarlane!).

On Saturday, 3= 0 July 2022 at 14:06:10 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:

I believe you can't create a pandoc document without any block. Two possibilities come to mind:

1. Round tripping: After fixing the citation, read it as LaTeX, and maybe, run pandoc.utils.blocks_to_inlines. (Hey, I never said it wouldn't be messy). May not work, even.

2. Simply delete all paragraph markers: in your case with: citetext:gsub("\n*", = " ")

Hth,

Sukil



El 30/07/2022 a las 14:39, Lyndon Drake escribi=C3=B3:

Hi Sukil,

Thanks, you were quite correct about the second problem. I've amended that and it now works, at least in the sense that it is altering the output in the general way I want.

On the first problem, I can just pandoc.stringify the prefix and suffix, and concatenate. The problem with that is I will then lose any Markdown formatting, which is not entirely uncommon in a prefix, and even occasionally in a suffix. I can work around it for this document, I guess, by just being careful not to use any Markdown formatting in these instances, but I'd love to find a way to take a set of Inlines and convert it to a format without adding a block.

On Friday, 29 July 2022 at 19:04:51 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:

Hi,

For your first problem, when you do pandoc.write, as a minimum a block is created, which, I believe, is normally a paragraph. So, don't cal= l pandoc.write. I guess you can concatenate the prefix, citation and suffix and pass them to the pandoc.RawInline function.


For your second problem, I am guessing you are using --citeproc in your defaults file. If that is the case, try: 1) putting the defaults file after the filter; or 2) specifying --citeproc manually, also after the filter.

Hth,

Sukil


El 29/07/2022 a las 16:58, Lyndon Drake escribi=C3=B3:
Thanks for all the help - definitely getting somewhere now!

I guess what I want to avoid is replicating in my not-great-Lua code all the work Pandoc already has to take a string of Markdown and convert it to LaTeX. I'm using pandoc.write to attempt that, and it seems to be working to some degree. The code as it is now is below. I have two problems:

1. This Markdown input [@Haran1982 165 n. 9, 172] gets converted by my calling of pandoc.write into:

```
\cite[165

n.~9,

172]{Haran1982}
```

and I can't figure out why the blank lines are turning up. I imagine I need to do something more clever with the Inlines?


2. Despite the fact that my output in the terminal shows that I am constructing the citetext variable as I am intending to, and I have this line of code:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return pandoc.RawInline('latex', citetext)

The output .tex file still has the normal Pandoc citations. In other words, my writer is constructing a nice LaTeX string with what I want in it, and then discards it in favour of the normal Pandoc code, which is a little bit depressing.

Can anyone spot what I'm missing now?

Best,
Lyndon

```
function Writer(doc, opts)
=C2=A0 =C2=A0 local filter =3D { =C2=A0 =C2=A0 =C2=A0 =C2=A0 Note = =3D function(el)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 return el:walk {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 Cite =3D function(el)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -- processing logic
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local citetext =3D ""
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if #el.citations > 1 then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if el.citations[1].mode =3D=3D "AuthorInText" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\textcites*'=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 elseif el.citations[1].mode =3D=3D "SuppressAuthor" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\cites*'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 elseif el.citations[1].mode =3D=3D "NormalCitation" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\cites'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if el.citations[1].mode =3D=3D "AuthorInText" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\textcite*'<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 elseif el.citations[1].mode =3D=3D "SuppressAuthor" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\cite*'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 elseif el.citations[1].mode =3D=3D "NormalCitation" then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D '\\cite'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for _, c in pairs(el.citations) do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if #c.prefix > 0 then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local doc =3D pandoc.Pandoc(c.prefix)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local citeprefix =3D pandoc.write(doc, 'latex')<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D citetext .. '['= ; .. citeprefix .. ']'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if #c.suffix > 0 then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local doc =3D pandoc.Pandoc(c.suffix)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 local citesuffix =3D pandoc.write(doc, 'latex')<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D citetext .. '['= ; .. citesuffix .. ']'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 citetext =3D citetext .. '{' .. c.id .. '}'
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print(citetext)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return pandoc.RawInline('latex', citetext)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 end
=C2=A0 =C2=A0 }
=C2=A0 =C2=A0 return pandoc.write(doc:walk(filter), 'latex', opts)
end
```

On Friday, 29 July 2022 at 10:49:18 UTC+1 suki...@gm= ail.com wrote:

I don't know, but the building blocks you'll need are `pandoc.stringify` which takes any object and converts it into a string, and `pandoc.RawBlock` or `pandoc.RawInline` which convert a string into a raw block or inline, and take the format as first argument and the string as second.

Hth,

Sukil


El 29/07/2022 a las 10:58, Lyndon Drake escribi=C3=B3:
So I have the citation prefix, which I guess I have to convert to a valid LaTeX string. How can I take an Inlines and LaTeX-ify it to a string?

On Friday, 29 July 2022 at 09:51:35 UTC+1 Lyndon Drake wrote:
Ah yep, that works. Next thing is I have to debug my obviously incorrect code :-)

On Friday, 29 July 2022 at 06:44:22 UTC+1 denis...@= unibe.ch wrote:
That's the problem. This is a writer, not a filter. So you need to call it via
-t latex-footcite.lua
________________________________________
Von: pandoc-..= .@googlegroups.com <pandoc-..= .@googlegroups.com> im Auftrag von Lyndon Drake <isen...@g= mail.com>
Gesendet: Freitag, 29. Juli 2022 07:15:08
An: pandoc-discuss
Betreff: Re: Changing LaTeX output for citations inside footnotes

My command line is:

pandoc -dbookends-latex --template /Users/lyndon/.local/sh= are/pandoc/templates/book.latex --lua-filter=3D/Users/lyndon/.local/share/pandoc/filters/latex-footcite.lua -s -o thesis_jeremiah_32.tex jer-32-thesis.md

It's definitely picking up the lua file because if I have a syntax error, pandoc tells me. But I don't get any output.

On Thursday, 28 July 2022 at 21:32:06 UTC+1 denis...@= unibe.ch wrote:
How do you run this ?
I=E2=80=99ve tested wit= h a minimal markdown file :

```markdown
asdf
```

Run with :
pandoc asdf.md -t mylatex.lua

Result :
got here
asdf

So, it prints the first print statement of the writer.

Denis

Von: pandoc-..= .@googlegroups.com <pandoc-..= .@googlegroups.com> Im Auftrag von Lyndon Drake
Gesendet: Donnerstag, 28. Juli 2022 19:17
An: pandoc-discuss <pandoc-..= .@googlegroups.com>
Betreff: Re: Changing LaTeX output for citations inside footnotes

Thanks for this - exactly what I needed. I've added my attempt at the code below, but I must be missing some basic part of it because it doesn't do anything. I added a couple of print statements that never get executed:

```
function Writer(doc, opts)
print "got here&qu= ot;
local filter =3D {
Note =3D function(el)
return el:walk {
Cite =3D function(el)
-- processing logic
print "got further= "
local citation =3D &quo= t;"
if #el.citations > 1 then
if citations[1].mode =3D=3D "AuthorInTe= xt" then
citation =3D '\\textcites*' =
elseif citations[1].mode =3D= =3D "SuppressAuthor&qu= ot; then
citation =3D '\\cites*'
elseif citations[1].mode =3D= =3D "NormalCitation&qu= ot; then
citation =3D '\\cit= es'
end
else
if citations[1].mode =3D=3D "AuthorInTe= xt" then
citation =3D '\\textcite*' <= br> elseif citations[1].mode =3D= =3D "SuppressAuthor&qu= ot; then
citation =3D '\\cit= e*'
elseif citations[1].mode =3D= =3D "NormalCitation&qu= ot; then
citation =3D '\\cit= e'
end
end
for c in el.citations do
if c.prefix ~=3D "= " then
citation =3D citation .. '[' .. c.pre= fix .. ']'
end
if c.suffix ~=3D "= " then
citation =3D citation .. '[' .. c.suf= fix .. ']'
end
citation =3D citation .. '{' .. c.id<http://c.id> .. '}'
end
return pandoc.RawInline('l= atex', citation)
end
}
end
}
return pandoc.write(doc:walk(f= ilter), 'latex', opts) =
end
```

Apologies for what must be a very basic question, but what am I missing here?
On Wednesday, 27 July 2022 at 11:27:32 UTC+1 denis...@= unibe.ch wrote:
What kind of example do you need? I only know about the examples in the documentation.

I think this here is a nice one :
https://pandoc.org/lua-filters.html#modifying-pandocs-= manual.txt-for-man-pages

Or : the new style writer
https://pandoc.org/custom-writers.html#example-modified-markd= own-writer

So, something like this here could be start:

```
function Writer(doc, opts)
local filter =3D {
Note =3D function(el)
return el:walk {
Cite =3D function(el)
-- processing logic
return pandoc.RawInline('l= atex', '\\cite[prenote][postnote]{key}')
end
}
end
}
return pandoc.write(doc:walk(f= ilter), 'latex', opts) =
end
```

I don=E2=80=99t think y= ou can get the current writer in Lua.


Von: pandoc-..= .@googlegroups.com <pandoc-..= .@googlegroups.com> Im Auftrag von Lyndon Drake
Gesendet: Dienstag, 26. Juli 2022 11:00
An: pandoc-discuss <pandoc-..= .@googlegroups.com>
Betreff: Re: Changing LaTeX output for citations inside footnotes

Thanks for this. I can see how that could work.

Can you point me to another example that uses the walk function?

Regarding a new-style Lua writer, is there a way to get the current LaTeX writer as Lua code? Or is it just the Haskell code? (I once knew Haskell but that was rather a long time ago.)
On Monday, 25 July 2022 at 22:02:38 UTC+1 denis...@= unibe.ch wrote:
I can't come up wit= h a code example now, bit you can use the walk function (https:= //pandoc.org/lua-filters.html#type-block:walk) to modify the citations with a given mode inside notes. You'll need to build the citation via Pandoc.RawInline
Maybe that would be a good example of a new style Lua writer.
________________________________________
Von: pandoc-..= .@googlegroups.com <pandoc-..= .@googlegroups.com> im Auftrag von Lyndon Drake <isen...@g= mail.com>
Gesendet: Montag, 25. Juli 2022 21:46:28
An: pandoc-discuss
Betreff: Changing LaTeX output for citations inside footnotes

Hi,

So this is a slightly odd request, which really comes because of the unusual behaviour of the specific BibLaTeX bibliography style I'm using. In that style, \textcite inside a footnote produces an unwanted result. \cite produces the expected output. I have generally just gone through and hand-edited my Pandoc-produced LaTeX files when they get to the final copy stage, but that's painful, and I also thought that maybe this is possible to do in a Lua filter.

But I don't quite know where to start - obviously this is a bit different from the internal Pandoc citations. I'm goin= g to begin the filter with this:

if FORMAT:match 'latex' then &l= t;https://pandoc.= org/lua-filters.html#cb9-3> function

but what would the function be? If it is Footnote, then I don't really want the AST, I want the LaTeX that forms the footnote contents, and I suppose then I can just replace any occurrences of the string \textcite with the string \cite?

Any help would be awesome!

Best,
Lyndon

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss&qu= ot; group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/bc06a6d8-9a34-4ca9-a05d-2526b23c6f6dn%40googlegroups.= com<https://groups.google.com/d/msgid/pandoc-discuss/bc06a6d8-9a3= 4-4ca9-a05d-2526b23c6f6dn%40googlegroups.com?utm_medium=3Demail&utm_sou= rce=3Dfooter>.
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss&qu= ot; group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/d25cee8b-7cb2-4fe9-b44d-f288a8fef728n%40googlegroups.= com<https://groups.google.com/d/msgid/pandoc-discuss/d25cee8b-7cb= 2-4fe9-b44d-f288a8fef728n%40googlegroups.com?utm_medium=3Demail&utm_sou= rce=3Dfooter>.
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss&qu= ot; group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/90c69f14-e16a-44d6-91ec-a6f6dca3ca45n%40googlegroups.= com<https://groups.google.com/d/msgid/pandoc-discuss/90c69f14-e16= a-44d6-91ec-a6f6dca3ca45n%40googlegroups.com?utm_medium=3Demail&utm_sou= rce=3Dfooter>.

--
You received this message because you are subscribed to the Google Groups "pandoc-discuss&qu= ot; group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/c4609f20-77f3-4427-83ae-6c79ba48ed5bn%40googlegroups.= com<https://groups.google.com/d/msgid/pandoc-discuss/c4609f20-77f= 3-4427-83ae-6c79ba48ed5bn%40googlegroups.com?utm_medium=3Demail&utm_sou= rce=3Dfooter>.
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" grou= p.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc= -discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
--
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-discus.= ..@googlegroups.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-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org= .
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.<= br> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discus...-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
--
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-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/p= andoc-discuss/28ac6c29-817d-41b6-891e-915ea28bdf3bn%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 pan= doc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups= .google.com/d/msgid/pandoc-discuss/CADAJKhBDo-Ya3Wabo27CQd%3Dt6JGtkzmYOoqbc= CW2tkK%3DGKd7FA%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d= /msgid/pandoc-discuss/7404c6ef-789f-4fec-bf16-be469839b935n%40googlegroups.= com.
------=_Part_757_427954217.1659783387817-- ------=_Part_756_1280909579.1659783387817--