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-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Im Auftrag von Lyndon Drake
Gesendet: Donnerstag, 28. Juli 2022 19:17
An: pandoc-discuss <pandoc-discuss-/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 .. '}'
                    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-...@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...-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...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/pandoc-discuss/d25cee8b-7cb2-4fe9-b44d-f288a8fef728n%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/90c69f14-e16a-44d6-91ec-a6f6dca3ca45n%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/b1e75d01e60647dc89b599683996c6b1%40unibe.ch.