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 <isenguard@gmail.com> 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ör 30 juli 2022 15:54Lyndon Drake <isen...@gmail.com> 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, 30 July 2022 at 14:06:10 UTC+1 suki...@gmail.com 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ó:

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...@gmail.com 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 call 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ó:
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:

                    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)
    local filter = {
        Note = function(el)
            return el:walk {
                Cite = function(el)
                    -- processing logic
                    local citetext = ""
                    if #el.citations > 1 then
                        if el.citations[1].mode == "AuthorInText" then
                            citetext = '\\textcites*'
                        elseif el.citations[1].mode == "SuppressAuthor" then
                            citetext = '\\cites*'
                        elseif el.citations[1].mode == "NormalCitation" then
                            citetext = '\\cites'
                        end
                    else
                        if el.citations[1].mode == "AuthorInText" then
                            citetext = '\\textcite*'
                        elseif el.citations[1].mode == "SuppressAuthor" then
                            citetext = '\\cite*'
                        elseif el.citations[1].mode == "NormalCitation" then
                            citetext = '\\cite'
                        end
                    end
                    for _, c in pairs(el.citations) do
                        if #c.prefix > 0 then
                            local doc = pandoc.Pandoc(c.prefix)
                            local citeprefix = pandoc.write(doc, 'latex')
                            citetext = citetext .. '[' .. citeprefix .. ']'
                        end
                        if #c.suffix > 0 then
                            local doc = pandoc.Pandoc(c.suffix)
                            local citesuffix = pandoc.write(doc, 'latex')
                            citetext = citetext .. '[' .. citesuffix .. ']'
                        end
                        citetext = 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` 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ó:
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 problem. 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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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=/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’ve 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
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 = {
Note = function(el)
return el:walk {
Cite = function(el)
-- processing logic
print "got further"
local citation = ""
if #el.citations > 1 then
if citations[1].mode == "AuthorInText" then
citation = '\\textcites*'
elseif citations[1].mode == "SuppressAuthor" then
citation = '\\cites*'
elseif citations[1].mode == "NormalCitation" then
citation = '\\cites'
end
else
if citations[1].mode == "AuthorInText" then
citation = '\\textcite*'
elseif citations[1].mode == "SuppressAuthor" then
citation = '\\cite*'
elseif citations[1].mode == "NormalCitation" then
citation = '\\cite'
end
end
for c in el.citations do
if c.prefix ~= "" then
citation = citation .. '[' .. c.prefix .. ']'
end
if c.suffix ~= "" then
citation = citation .. '[' .. c.suffix .. ']'
end
citation = 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://pandoc.org/custom-writers.html#example-modified-markdown-writer

So, something like this here could be start:

```
function Writer(doc, opts)
local filter = {
Note = function(el)
return el:walk {
Cite = 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’t 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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
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.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-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> im Auftrag von Lyndon Drake <isen...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
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 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" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-discus...-/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-9a34-4ca9-a05d-2526b23c6f6dn%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-discus...-/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-7cb2-4fe9-b44d-f288a8fef728n%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-discus...-/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-e16a-44d6-91ec-a6f6dca3ca45n%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-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-discus...-/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-77f3-4427-83ae-6c79ba48ed5bn%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-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...-/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...-/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-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-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 pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhBDo-Ya3Wabo27CQd%3Dt6JGtkzmYOoqbcCW2tkK%3DGKd7FA%40mail.gmail.com.