From: "'Thomas J.' via pandoc-discuss" <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Citeproc/Order of filters being called
Date: Wed, 29 Nov 2023 10:29:14 -0800 (PST) [thread overview]
Message-ID: <ee97eefb-cb70-4bf9-859c-e75448438894n@googlegroups.com> (raw)
In-Reply-To: <CAEe_xxid8YRTLJKC=8jvD2ps4a7YoQe=ZS3DMMt0VJ3d0e-04Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 2701 bytes --]
Thanks for the feedback! I simply was not aware of the fact that every
@<WORD> string is apparently automatically converted into a Cite block in
the AST, even without using citeproc (?). Anyhow, being aware of this fixed
the problem. I've attached the filter, if someone is interested. It is
still very raw and only for HTML (adding latex shouldnt be a huge problem
though).
Thanks again for the help!
With best wishes,
Thomas
William Lupton schrieb am Mittwoch, 29. November 2023 um 15:49:45 UTC+1:
> From the information given, I think that the AST must still contain a
> fig:fig1 citation after your filter has run. Are you able to share your
> filter?
>
> On Wed, 29 Nov 2023 at 13:28, 'Thomas J.' via pandoc-discuss <
> pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> wrote:
>
>> Hi everyone,
>>
>> Since pandoc-fignos isn't working anymore (at least, with my Pandoc
>> version), I have written a Lua filter that basically does what fignos does,
>> namely replacing tags such as @fig:fig1 with anchors/refs to the figures in
>> html/latex. Now, if I am trying to use this filter without citeproc,
>> everthing works as expected. The moment I use --citeproc, I get the error
>> message "fig:fig1 citation not found" and I have no link in my output file.
>> I am actually calling the lua filter BEFORE --citeproc in the command
>> line...
>>
>> pandoc --lua-filter=filter/pandoc-figref.lua --citeproc --number-sections
>> --from markdown --template=templates/phimisci-1-5.html --bibliography=
>> $BIBLIOGRAPHY --csl=csl/apa7-single-spaced.csl yaml/gen-metadata.yaml
>> article/$1 article/$2 -o $HTMLFILE
>>
>> What am I missing? Thanks for the help!
>>
>> Best wishes,
>> Thomas
>>
>> --
>> 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...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/pandoc-discuss/15e09292-83a1-4e28-ba84-d0c518be709dn%40googlegroups.com
>> <https://groups.google.com/d/msgid/pandoc-discuss/15e09292-83a1-4e28-ba84-d0c518be709dn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/ee97eefb-cb70-4bf9-859c-e75448438894n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 5083 bytes --]
[-- Attachment #2: pandoc-figref.lua --]
[-- Type: application/octet-stream, Size: 3894 bytes --]
-- filter to reference images/figures in text
-- inspired by pandoc-fignos (works with fignos @fig:<label> syntax)
-- currently only conversion to PDF & HTML
-- tested with Pandoc 3.1
-- written by Thomas Jurczyk
-- GLOBAL VARIABLES
-- table to store fig-refs found
Figref_Table = {}
-- counter for figure numbering
Counter = 1
-- HELPER FUNCTIONS
--- Function to add a Figure str pandoc.Inline Element to a pandoc.Caption
-- @param caption The pandoc.Plain block from the figure.caption.long element.
-- @return The new figure.caption.long.Plain block now starting with with 'Figure <NUMBER>: '.
function addFigureTagToCaption(plain)
-- add a "Figure <NUMBER>:" tag at the beginning of a caption
table.insert(plain.content, 1, pandoc.Str("Figure"))
table.insert(plain.content, 2, pandoc.Space())
table.insert(plain.content, 3, pandoc.Str(Counter .. ":"))
table.insert(plain.content, 4 ,pandoc.Space())
return plain
end
--- Function to find the index of an element in a table. This function is used in setRefsToFigure().
-- @param element The element searched for in the table.
-- @param table The table in which the element is searched for.
-- @return (str|nil) The index as a STRING. nil if element has not been found.
function findIndex(element, table)
for index, entry in ipairs(table) do
if entry == element then
return tostring(index)
end
end
return nil
end
---Function to replace a string that matches a figure id with HTML/LaTeX links/refs.
-- @param The plain string from Cite.citations[1].id
-- @return (pandoc.RawInline|nil)
function stringReplacementRef(word)
if tableContains(Figref_Table, word) then
local referenceNumber = findIndex(word, Figref_Table)
if FORMAT:match "html" then
return pandoc.RawInline('html', '<a href="#'..word..'">'..referenceNumber..'</a>')
--TODO: add LaTeX reference
end
else
return nil
end
end
--- Function to check if an element (here: the identifier used in the fig-reference) is in a table (here: the globale table with all found figure identifiers).
-- @param table The table (= global Figref_Table).
-- @param element The element to search for (=the identifier used in the in-text reference).
-- @return (bool) true or false
function tableContains(table, element)
for _,value in ipairs(table) do
if value == element then
return true
end
end
return false
end
-- MAIN FUNCTIONS
--- Checks every pandoc.Figure for identifiers; if one was found, add it to global Figref_Table
-- @param figure The pandoc.Figure element.
-- @return (nil | pandoc.Figure). New pandoc.Figure element if identifier was found, else nil.
function figureParser(figure)
-- only exchange caption if output format is 'html' -> LaTeX automatically adds figure-tags like "Figure 1:" to captions
if figure.identifier then
-- add identifier to global id-collection (used to find in-text refs)
table.insert(Figref_Table, Counter, figure.identifier)
-- change figure caption in AST: add "Figure <NO>: " to caption
if FORMAT:match "html" then
figure.caption.long = figure.caption.long:walk {
Plain=addFigureTagToCaption
}
end
-- increase global Counter
Counter = Counter + 1
return figure
else
return nil
end
end
--- Function to replace the in-text figure reference (such as @fig:fig1), which is wrapped in a pandoc.Cite element, with the matching link syntax of the output format (HTML/LaTeX).
-- @param word The pandoc.Cite element.
-- @return (nil|pandoc.RawInline) pandoc.RawInline if reference was found. Else nil.
function setRefsToFigure(cite)
return stringReplacementRef(cite.citations[1].id)
end
return {
{Figure=figureParser},
{Cite=setRefsToFigure}
}
next prev parent reply other threads:[~2023-11-29 18:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 13:28 'Thomas J.' via pandoc-discuss
[not found] ` <15e09292-83a1-4e28-ba84-d0c518be709dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-11-29 14:49 ` 'William Lupton' via pandoc-discuss
[not found] ` <CAEe_xxid8YRTLJKC=8jvD2ps4a7YoQe=ZS3DMMt0VJ3d0e-04Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-11-29 18:29 ` 'Thomas J.' via pandoc-discuss [this message]
[not found] ` <ee97eefb-cb70-4bf9-859c-e75448438894n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-11-30 9:56 ` 'Thomas J.' via pandoc-discuss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ee97eefb-cb70-4bf9-859c-e75448438894n@googlegroups.com \
--to=pandoc-discuss-/jypxa39uh5tlh3mbocffw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).