public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua filter to change macro for figure caption md -> latex
@ 2023-11-19 20:06 'lukeflo' via pandoc-discuss
       [not found] ` <51ca8210-3d60-4d5d-9af2-04c85995deb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: 'lukeflo' via pandoc-discuss @ 2023-11-19 20:06 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3267 bytes --]

Hi everybody,

I have written a custom latex `.cls' file to establish a typesetting
workflow for the scientific journals of my research institute. The texts
should be written in Markdown and then be processed with `pandoc' to
LaTeX.

I already have an elaborated pandoc template to produce the LaTeX
preambel etc. So far its working great.

But for the figures I need the caption from the Markdown file to be set
with `\sidecaption' instead of `\caption' in LaTeX, as well as with an
optional argument (short-caption) for the image attribution in the list
of figures.

To get the latter working I use the following template from a GitHub
discussion in the [pandoc repo]:

┌────
│ PANDOC_VERSION:must_be_at_least '3.1'
│
│ if FORMAT:match 'latex' then
│   function Figure(f)
│     local short = f.content[1].content[1].attributes['short-caption']
│     if short and not f.caption.short then
│       f.caption.short = pandoc.Inlines(short)
│     end
│     return f
│   end
│ end
└────

That works without any flaws.

But now I need to figure out how to change the LaTeX macro used for the
caption. The older [approach of pre pandoc version 3.0 posted] by tarleb
is really intuitive and I could have easily adapted it to my needs. But
since pandoc 3.0 there is the new [/complex figures/] approach and, so
far, I couldn't figure out how to change the LaTeX macro used for the
captions with this new behaviour.

I tried something like that (Adapted from [here]:

┌────
│ if FORMAT:match 'latex' then
│   function RawBlock (raw)
│     local caption = raw.text:match('\\caption')
│     if caption then
│        raw:gsub('\\caption', '\\sidecaption')
│     end
│     return raw
│   end
│ end
└────

But nothing happened.

The main challenge for me are my more-or-less non-existing lua skills. I
just never had to use it for my daily tasks. I thought about using `awk'
or `sed' to edit the `.tex' file itself using a regex-substitution, but
that should remain an absolute stopgap, since it makes the whole
workflow less portable.

Thus, I'm hoping for a hint/a solution in form of a pandoc-lua script
which 1. helps me to achieve the goal, and 2. improve my understanding
of lua and the /complex figures/ approach for similar future tasks.

I appreciate any tipp!

Best,
Lukeflo

This question is also posted on StackOverFlow: 
https://stackoverflow.com/q/77504584/19647155

[pandoc repo]
<https://github.com/jgm/pandoc/issues/7915#issuecomment-1427113349>

[approach of pre pandoc version 3.0 posted]
<https://github.com/jgm/pandoc/issues/7915#issuecomment-1039370851>

[/complex figures/] <https://github.com/jgm/pandoc/releases?page=2>

[here] <https://stackoverflow.com/a/71296595/19647155>

-- 
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/51ca8210-3d60-4d5d-9af2-04c85995deb6n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 3929 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-12-12 10:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-19 20:06 Lua filter to change macro for figure caption md -> latex 'lukeflo' via pandoc-discuss
     [not found] ` <51ca8210-3d60-4d5d-9af2-04c85995deb6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-05 16:09   ` Julien Dutant
     [not found]     ` <f3fa2d12-6277-47c6-a3fc-b5fea1485600n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-08  7:35       ` 'lukeflo' via pandoc-discuss
     [not found]         ` <b565fdd5-8216-4596-a2ed-c75019aad172n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-11 10:33           ` 'lukeflo' via pandoc-discuss
     [not found]             ` <b419ae83-de83-4035-97cd-fb41cb6be647n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-11 10:36               ` 'lukeflo' via pandoc-discuss
     [not found]                 ` <32dfe8eb-98ac-40ee-92d7-162528add367n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-11 11:30                   ` 'William Lupton' via pandoc-discuss
     [not found]                     ` <CAEe_xxikobOS_G9x71nxtz0dr99VVhgBV8in=xKzXgh7JMaRcw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-12-11 14:53                       ` Pablo Serrati
     [not found]                         ` <CACTSqG5L4o7npfcUV1iGPMi5fbUrqgPc+5ttPQmZhNTFW7Vsng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2023-12-11 22:04                           ` 'lukeflo' via pandoc-discuss
     [not found]                             ` <78503784-88bd-4d34-b5f5-a8634d667ba0n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-12 10:16                               ` 'William Lupton' via pandoc-discuss

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).