From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31141 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: Fri, 29 Jul 2022 07:58:24 -0700 (PDT) Message-ID: <0e10379f-d1c0-4024-b98a-5c7ba703f561n@googlegroups.com> References: <97765931b0a740ed8a84ba4337bed661@unibe.ch> <90c69f14-e16a-44d6-91ec-a6f6dca3ca45n@googlegroups.com> <8976ce00-3fbe-bf27-898f-0470cba1fec1@gmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_720_301492621.1659106704575" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1571"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCKOX6WY7EKBBEPLR6LQMGQETNZZGEI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Jul 29 16:58:32 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-yw1-f186.google.com ([209.85.128.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oHRRd-00007W-Mc for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 29 Jul 2022 16:58:29 +0200 Original-Received: by mail-yw1-f186.google.com with SMTP id 00721157ae682-322f9280fe0sf37301587b3.23 for ; Fri, 29 Jul 2022 07:58:29 -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=cHJ1s417pJCa9eKlC2sQ+xZ+geNrQcCIEfNu3ydd+KE=; b=Q5LQc+v05ZDyBJ2AVr23CJnYWmcW+KqPYCQ7MqluqOsjfxiAHKJHe/FpSABaYsj+qx aIh3l7WB3xkqWJ9ZugFvSHXN6aBsy2E2Int2p4kEPR2fnr7nUKEXtseFaaWy3OjN7q5p a92p1vwxCtgTzuqVm3SkHUTudB7YiYKvjPDSv1B6Lnijn98SQXsmhIXT50r+QgmNpQxB q/ZV9Vbw+DYiU58LJ3Mz3PT+HPQpM+oGkilprESHQVFzEePpTooioKDptQFz9oiqXrjS /cNQWN7XQbjlHGP1mqfp4G5vzEZftCrf1KVbcokf0fbSxY16tB6aFXqby5WI06cUni+U lqVw== 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=cHJ1s417pJCa9eKlC2sQ+xZ+geNrQcCIEfNu3ydd+KE=; b=YhmW6V5q+rmqzwddEZFeGiIZbu8jAl3GJRmCH9y9HyDnKVtf3xkSFFr0l/h1BAHdFv DcBLuHnuZxcGuUzXYfwpHMMUaDdxXqbL3Ts9c+eu0Dq6WS2M5g3wCU+o4E4IWdxfJfDN 5SfJ/vFkAFcOwLmpbh9njNt5GjyJQ+3NlZhiHlT01aTm/R6199GG9k13OmuZU2mSAvWI 8YJl1umsegLCbhBTKPhAOFGCvWy7Zycfcc5F/15Nr6d6ftQrclkqV9KT+B4PVwdfNVoU 2ErCjsTiGigBFv5zrL0UVSrGo4CDZTy4GE0FYe7pom9Sc6JI1I1+ZGqzjw8VBwbioZDb i8kA== 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=cHJ1s417pJCa9eKlC2sQ+xZ+geNrQcCIEfNu3ydd+KE=; b=N/cnnYTDP9796a6NVBPyMAvwEYUXL4hj4/OGb/u6Z0ZCsKp7RGw7gv2IW2DxoSwyhE Ffj1O/g/SvVtO7pAFqjooP5qFOt0mFEIvl4M2k65bkFCuIKM95S514F9wGcQO3hJ2Btt 55KIiHFqTQ9tr0rNxgFPddVYlv+TtFNngNtlLCjW8iDP1ZxU56bwxP6S+o7DAvpIInfa Rwf96d/sYOJcjT3rCkigJjA+xrm/UKCHo+KKsnKSlN9HaLiT6OO07T+7Fkz7xwb1FgNu UlCblozrAHSX1bLCEZujVH8JRVq295KvU8IqMgq1N/rTHPHDYoYP55gnQh30s93YNjFB OQmQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACgBeo1Z+A8E+0WBbbQZKtovpuZKBQlJu1QffIpqHeSWL8tW6ATN1Lc3 08A3oAYwEBFSCOxc0++rIig= X-Google-Smtp-Source: AA6agR4SIw8yDASPKRfLzTxUYNEaSsWnr3SDLhwRkqnUc4ZhcefK/EFInyPr/KT8EOM0sOROyWp3Bg== X-Received: by 2002:a25:2417:0:b0:675:a9b2:dad0 with SMTP id k23-20020a252417000000b00675a9b2dad0mr2776525ybk.489.1659106708637; Fri, 29 Jul 2022 07:58:28 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a81:4c07:0:b0:31f:56e8:aa58 with SMTP id z7-20020a814c07000000b0031f56e8aa58ls2399485ywa.9.-pod-prod-gmail; Fri, 29 Jul 2022 07:58:25 -0700 (PDT) X-Received: by 2002:a81:f93:0:b0:31f:531c:5499 with SMTP id 141-20020a810f93000000b0031f531c5499mr3421365ywp.509.1659106705133; Fri, 29 Jul 2022 07:58:25 -0700 (PDT) In-Reply-To: <8976ce00-3fbe-bf27-898f-0470cba1fec1-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:31141 Archived-At: ------=_Part_720_301492621.1659106704575 Content-Type: multipart/alternative; boundary="----=_Part_721_143531129.1659106704575" ------=_Part_721_143531129.1659106704575 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=20 the work Pandoc already has to take a string of Markdown and convert it to= =20 LaTeX. I'm using pandoc.write to attempt that, and it seems to be working= =20 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=20 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= =20 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 words,= =20 my writer is constructing a nice LaTeX string with what I want in it, and= =20 then discards it in favour of the normal Pandoc code, which is a little bit= =20 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 "SuppressAuthor"= then citetext =3D '\\cites*' elseif el.citations[1].mode =3D=3D "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 "SuppressAuthor"= then citetext =3D '\\cite*' elseif el.citations[1].mode =3D=3D "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, '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 .. '}' 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 `pandoc.stringify`= =20 > which takes any object and converts it into a string, and `pandoc.RawBloc= k`=20 > or `pandoc.RawInline` which convert a string into a raw block or inline,= =20 > 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= =20 > 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= =20 >> 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 to call= =20 >>> 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-footcite= .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 syntax=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 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 the= =20 >>> code below, but I must be missing some basic part of it because it does= n't=20 >>> do anything. I added a couple of print statements that never get execut= ed:=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 missing= =20 >>> here?=20 >>> On Wednesday, 27 July 2022 at 11:27:32 UTC+1 denis...-NSENcxR/0n0@public.gmane.org wrote:= =20 >>> What kind of example do you need? I only know about the examples in the= =20 >>> documentation.=20 >>> >>> I think this here is a nice one :=20 >>> >>> https://pandoc.org/lua-filters.html#modifying-pandocs-manual.txt-for-ma= n-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 current=20 >>> LaTeX writer as Lua code? Or is it just the Haskell code? (I once knew= =20 >>> 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 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 bui= ld=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 the=20 >>> unusual behaviour of the specific BibLaTeX bibliography style I'm using= . In=20 >>> that style, \textcite inside a footnote produces an unwanted result. \c= ite=20 >>> produces the expected output. I have generally just gone through and=20 >>> hand-edited my Pandoc-produced LaTeX files when they get to the final c= opy=20 >>> stage, but that's painful, and I also thought that maybe this is possib= le=20 >>> 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 fi= lter=20 >>> with this:=20 >>> >>> if FORMAT:match 'latex' then =20 >>> function=20 >>> >>> but what would the function be? If it is Footnote, then I don't really= =20 >>> want the AST, I want the LaTeX that forms the footnote contents, and I= =20 >>> 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 Google=20 >>> Groups "pandoc-discuss" group.=20 >>> To unsubscribe from this group and stop receiving emails from it, send= =20 >>> 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-4ca9-a05= d-2526b23c6f6dn%40googlegroups.com >>> < >>> https://groups.google.com/d/msgid/pandoc-discuss/bc06a6d8-9a34-4ca9-a05= d-2526b23c6f6dn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter>.= =20 >>> >>> --=20 >>> You received this message because you are subscribed to the Google=20 >>> Groups "pandoc-discuss" group.=20 >>> To unsubscribe from this group and stop receiving emails from it, send= =20 >>> 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-4fe9-b44= d-f288a8fef728n%40googlegroups.com >>> < >>> https://groups.google.com/d/msgid/pandoc-discuss/d25cee8b-7cb2-4fe9-b44= d-f288a8fef728n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter>.= =20 >>> >>> --=20 >>> You received this message because you are subscribed to the Google=20 >>> Groups "pandoc-discuss" group.=20 >>> To unsubscribe from this group and stop receiving emails from it, send= =20 >>> 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-44d6-91e= c-a6f6dca3ca45n%40googlegroups.com >>> < >>> https://groups.google.com/d/msgid/pandoc-discuss/90c69f14-e16a-44d6-91e= c-a6f6dca3ca45n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter>.= =20 >>> >>> >>> --=20 >>> You received this message because you are subscribed to the Google=20 >>> Groups "pandoc-discuss" group.=20 >>> To unsubscribe from this group and stop receiving emails from it, send= =20 >>> 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-4427-83a= e-6c79ba48ed5bn%40googlegroups.com >>> < >>> https://groups.google.com/d/msgid/pandoc-discuss/c4609f20-77f3-4427-83a= e-6c79ba48ed5bn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter>.= =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/a1e38719-d239-44af-84b0-= 67a1764dbb70n%40googlegroups.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/0e10379f-d1c0-4024-b98a-5c7ba703f561n%40googlegroups.com. ------=_Part_721_143531129.1659106704575 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for all the help - definitely getting somewhere now!
=
I guess what I want to avoid is replicating in my not-great-Lua c= ode all the work Pandoc already has to take a string of Markdown and conver= t it to LaTeX. I'm using pandoc.write to attempt that, and it seems to be w= orking 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:

```<= /div>
\cite[165

n.~9,

172]{Haran1982}
```

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


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

  &nb= sp;                 return pandoc.R= awInline('latex', citetext)

The output .tex file s= till has the normal Pandoc citations. In other words, my writer is construc= ting a nice LaTeX string with what I want in it, and then discards it in fa= vour of the normal Pandoc code, which is a little bit depressing.

Can anyone spot what I'm missing now?

<= div>Best,
Lyndon

```
function Wr= iter(doc, opts)
    local filter =3D {
     =   Note =3D function(el)
            = return el:walk {
               = Cite =3D function(el)
              =       -- processing logic
        &nb= sp;           local citetext =3D ""
  &nbs= p;                 if #el.citations= > 1 then
                &nb= sp;       if el.citations[1].mode =3D=3D "AuthorInText" then=
                    &= nbsp;       citetext =3D '\\textcites*'
    &nb= sp;                   elseif e= l.citations[1].mode =3D=3D "SuppressAuthor" then
      &n= bsp;                     = citetext =3D '\\cites*'
             =           elseif el.citations[1].mode =3D=3D "Nor= malCitation" then
               = ;             citetext =3D '\\cites'
 = ;                     &nb= sp; end
                  &= nbsp; else
                 = ;       if el.citations[1].mode =3D=3D "AuthorInText" then                    &nb= sp;       citetext =3D '\\textcite*'
     =                   elseif el.c= itations[1].mode =3D=3D "SuppressAuthor" then
       = ;                     cit= etext =3D '\\cite*'
              &nb= sp;         elseif el.citations[1].mode =3D=3D "NormalC= itation" then
                &n= bsp;           citetext =3D '\\cite'
  &nb= sp;                     e= nd
                   = end
                  &nbs= p; for _, c in pairs(el.citations) do
         =               if #c.prefix > 0 then<= br>                    &n= bsp;       local doc =3D pandoc.Pandoc(c.prefix)
  &= nbsp;                    =     local citeprefix =3D pandoc.write(doc, 'latex')
  &n= bsp;                     =     citetext =3D citetext .. '[' .. citeprefix .. ']'
  &= nbsp;                    = end
                  &nbs= p;     if #c.suffix > 0 then
        &n= bsp;                   local d= oc =3D pandoc.Pandoc(c.suffix)
           =                 local citesuffix = =3D pandoc.write(doc, 'latex')
           =                 citetext =3D citet= ext .. '[' .. citesuffix .. ']'
           = ;             end
      &nb= sp;                 citetext =3D ci= tetext .. '{' .. c.id .. '}'
            &= nbsp;           print(citetext)
    &= nbsp;               end
   =                 return pandoc.RawI= nline('latex', citetext)
             = ;   end
            }
   = ;     end
    }
    return pandoc.write= (doc:walk(filter), 'latex', opts)
end
```

<= div class=3D"gmail_quote">
On Friday,= 29 July 2022 at 10:49:18 UTC+1 suki...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
=20 =20 =20

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:
=20 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...-NSENcxR/0n0@public.gmane.org wrote:
That's the prob= lem. This is a writer, not a filter. So you need to call it via
-t latex-footcite.lua
________________________________________
Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 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/share/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...-NSENcxR/0n0@public.gmane.org wrote:
How do you run this ?
I=E2=80=99ve tested with 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Lyndon Drake
Gesendet: Donnerstag, 28. Juli 2022 19:17
An: pandoc-discuss <pandoc-...@googleg= roups.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"
local filter =3D {
Note =3D function(el)
return el:walk {
Cite =3D function(el)
-- processing logic
print "got further"
local citation =3D ""
if #el.citations > 1 then
if citations[1].mode =3D=3D "AuthorInText" then
citation =3D '\\textcites*'
elseif citations[1].mode =3D=3D "SuppressAuthor" th= en
citation =3D '\\cites*'
elseif citations[1].mode =3D=3D "NormalCitation" th= en
citation =3D '\\cites'
end
else
if citations[1].mode =3D=3D "AuthorInText" then
citation =3D '\\textcite*'
elseif citations[1].mode =3D=3D "SuppressAuthor" th= en
citation =3D '\\cite*'
elseif citations[1].mode =3D=3D "NormalCitation" th= en
citation =3D '\\cite'
end
end
for c in el.citations do
if c.prefix ~=3D "" then
citation =3D citation .. '[' .. c.prefix .. ']= 9;
end
if c.suffix ~=3D "" then
citation =3D citation .. '[' .. c.suffix .. ']= 9;
end
citation =3D citation .. '{' .. c.id<http:= //c.id> .. '}'
end
return pandoc.RawInline('latex', citation)
end
}
end
}
return pandoc.write(doc:walk(filter), '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...-NSENcxR/0n0@public.gmane.org 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://pand= oc.org/custom-writers.html#example-modified-markdown-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('latex', '\\cite[prenote][postnote]{key}')
end
}
end
}
return pandoc.write(doc:walk(filter), 'latex', opts)
end
```

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


Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Lyndon Drake
Gesendet: Dienstag, 26. Juli 2022 11:00
An: pandoc-discuss <pandoc-...@googleg= roups.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...-NSENcxR/0n0@public.gmane.org wrote:
I can't come up with a code example now, bit you can use the walk function (https://pandoc.org/lua-filters.ht= ml#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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 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 going to begin the filter with this:

if FORMAT:match 'latex' then <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 th= e 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" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discus..= .@googlegroups.com<mailto:pandoc-discus...@googl= egroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/bc06= a6d8-9a34-4ca9-a05d-2526b23c6f6dn%40googlegroups.com<https://groups.google.com/d/msgid/pand= oc-discuss/bc06a6d8-9a34-4ca9-a05d-2526b23c6f6dn%40googlegroups.com?utm_med= ium=3Demail&utm_source=3Dfooter>.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/d25c= ee8b-7cb2-4fe9-b44d-f288a8fef728n%40googlegroups.com<https://groups.google.com/d/msgid/pand= oc-discuss/d25cee8b-7cb2-4fe9-b44d-f288a8fef728n%40googlegroups.com?utm_med= ium=3Demail&utm_source=3Dfooter>.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/90c6= 9f14-e16a-44d6-91ec-a6f6dca3ca45n%40googlegroups.com<https://groups.google.com/d/msgid/pand= oc-discuss/90c69f14-e16a-44d6-91ec-a6f6dca3ca45n%40googlegroups.com?utm_med= ium=3Demail&utm_source=3Dfooter>.

--
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<mailto:pandoc-discus...@googl= egroups.com>.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/c460= 9f20-77f3-4427-83ae-6c79ba48ed5bn%40googlegroups.com<https://groups.google.com/d/msgid/pand= oc-discuss/c4609f20-77f3-4427-83ae-6c79ba48ed5bn%40googlegroups.com?utm_med= ium=3Demail&utm_source=3Dfooter>.
--
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-di= scus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.

--
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/0e10379f-d1c0-4024-b98a-5c7ba703f561n%40googlegroups.= com.
------=_Part_721_143531129.1659106704575-- ------=_Part_720_301492621.1659106704575--