* Making a lua filter for short captions
@ 2018-01-20 6:47 Greg Tucker-Kellogg
[not found] ` <4be256f9-981f-4c16-92af-33bb4e3a1c40-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 2+ messages in thread
From: Greg Tucker-Kellogg @ 2018-01-20 6:47 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1887 bytes --]
I'm trying to create a lua filter for short captions with latex output, so
they can be used in `\listoffigures`. I have a filter that sort of kind of
works for figures,
but it's obliterating other attributes (including the #fig needed for
pandoc-crossref). I I'd like to fix this filter
to preserve the other attributes, and would appreciate any guidance on
doing so.
I understand there is no current way to set attributes on tables, so that
would have to be manual.
local utils = require 'pandoc.utils'
function Para (figure)
if FORMAT =="latex" then
if #figure.content == 1 and figure.content[1].t == 'Image' then
local img = figure.content[1]
if img.caption and img.attributes['short-caption'] then
local short = img.attributes['short-caption']
local long = utils.stringify(img.caption)
return pandoc.Plain {
pandoc.RawInline('tex',"\\begin{figure}\n"),
pandoc.RawInline('tex','\\centering\n'),
pandoc.RawInline('tex',string.format("\\includegraphics{%s}\n",img.src)),
pandoc.RawInline('tex',string.format('\\caption[%s]{%s}\n',short,long)),
pandoc.RawInline('tex',"\\end{figure}\n")
}
end
end
end
end
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4be256f9-981f-4c16-92af-33bb4e3a1c40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[-- Attachment #1.2: Type: text/html, Size: 4115 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Making a lua filter for short captions
[not found] ` <4be256f9-981f-4c16-92af-33bb4e3a1c40-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2018-01-20 9:40 ` Albert Krewinkel
0 siblings, 0 replies; 2+ messages in thread
From: Albert Krewinkel @ 2018-01-20 9:40 UTC (permalink / raw)
To: Greg Tucker-Kellogg; +Cc: pandoc-discuss
If you keep the normal Image element in your output, then pandoc will
take care of image attributes, e.g.:
⋮
return pandoc.Plain {
pandoc.RawInline('tex', '\\begin{figure}\n'),
img,
pandoc.RawInline('tex', '\\end{figure}\n'),
}
⋮
This way one can still leverage pandoc's LaTeX writer functionality
while getting more control over the output.
I wrote a short-caption filter some month ago; I'd write it a bit
differently nowadays:
https://gist.github.com/tarleb/a57366474bbeef4c4c388adc19e85a41
A clean and working filter would be a good addition to
https://github.com/pandoc/lua-filters. Please consider making a pull
request when you get your filter working.
Greg Tucker-Kellogg <gtuckerkellogg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> I'm trying to create a lua filter for short captions with latex output, so they can be used in `\listoffigures`. I have a filter that sort of kind of works for figures,
> but it's obliterating other attributes (including the #fig needed for pandoc-crossref). I I'd like to fix this filter
> to preserve the other attributes, and would appreciate any guidance on doing so.
>
> I understand there is no current way to set attributes on tables, so that would have to be manual.
>
> local utils = require 'pandoc.utils'
>
> function Para (figure)
> if FORMAT =="latex" then
> if #figure.content == 1 and figure.content[1].t == 'Image' then
> local img = figure.content[1]
> if img.caption and img.attributes['short-caption'] then
> local short = img.attributes['short-caption']
> local long = utils.stringify(img.caption)
> return pandoc.Plain {
> pandoc.RawInline('tex',"\\begin{figure}\n"),
> pandoc.RawInline('tex','\\centering\n'),
> pandoc.RawInline('tex',string.format("\\includegraphics{%s}\n",img.src)),
> pandoc.RawInline('tex',string.format('\\caption[%s]{%s}\n',short,long)),
> pandoc.RawInline('tex',"\\end{figure}\n")
> }
> end
> end
> end
> end
--
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124
--
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 post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/87efmkvpep.fsf%40zeitkraut.de.
For more options, visit https://groups.google.com/d/optout.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-20 9:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-20 6:47 Making a lua filter for short captions Greg Tucker-Kellogg
[not found] ` <4be256f9-981f-4c16-92af-33bb4e3a1c40-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2018-01-20 9:40 ` Albert Krewinkel
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).