From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/33342 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "'lukeflo' via pandoc-discuss" Newsgroups: gmane.text.pandoc Subject: Lua filter to change macro for figure caption md -> latex Date: Sun, 19 Nov 2023 12:06:56 -0800 (PST) Message-ID: <51ca8210-3d60-4d5d-9af2-04c85995deb6n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1294_2104258434.1700424416979" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12544"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD7NXUVXXUBBBYWV5GVAMGQE3GMODPY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun Nov 19 21:07:04 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f186.google.com ([209.85.167.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1r4o4N-00035q-N7 for gtp-pandoc-discuss@m.gmane-mx.org; Sun, 19 Nov 2023 21:07:03 +0100 Original-Received: by mail-oi1-f186.google.com with SMTP id 5614622812f47-3b2df828525sf4413674b6e.3 for ; Sun, 19 Nov 2023 12:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1700424422; x=1701029222; darn=m.gmane-mx.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:x-original-sender :mime-version:subject:message-id:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=NbFZxP1pgnndimyag07YL16u2ncXJ5NeiY1pbPPqHO4=; b=d/O0n3C8aNQ+OvExGjrXfQf9NhVkqvRnCscDOABm3AHvBXprbsn/EgajED8TLOPBBA 5R93PIVUMyCgibaW2D7GBfXU5Mluth4q399el+RInGokSqwi4cT5N8Uvjm1VVMOaABur iMxNRgn9FWXe8+jiI3pw5Nqw71ojXiAPSuhERMaRmeWuVP6jRai67CC9oN1H4ORpUWoh l9Yv4Au9rNa+jslif5p5zIOQQ9r0EPmfb7ZzsQ7YdWEeFQzVppcXAvjD2vyApIURQdbK Z5QF+30ssq5w3SuGp95eXkaC0fX57NDc+ymDV5aQr5GGS4ksqoL9eDy+xCGJY/+bs8oI Z74g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700424422; x=1701029222; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-sender:mime-version:subject:message-id:to:from:date :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NbFZxP1pgnndimyag07YL16u2ncXJ5NeiY1pbPPqHO4=; b=rfp137D9SrhkWc17iEeZcqQfDLbvYUvmQd1fcRbvrTyTsIZ2f6vcy40gLf8BLEAwl9 NzWDJCgJv46uM6S3P9UQHEZP/0aosfOMgnfNNh6/kMfDJ3+NbkzNGCXVsL3BZ0+vtY1Q 1MXxngI953m+3QghZG4OQEaeZzXiXo0cg0I/3Vu3tMqTxWrLuLrQVD/zg+LVuEHNN2zU oUq2c+C3u8QYn1LfvPYhIKlj4Xg6IGFkJ/q8RjrFAjKkxZanZ4MORnzudH330ly0mZgF DWbUc+WhaM8CUF482dlzw+U7D6YTuip4ULWnSM3CwfeAMdeZEhxQMQGdQ9KN5dlv/RRo e4 X-Gm-Message-State: AOJu0YzsbOtHJgbPdxjkwJcHb9gPVwYqnd/W8abvukTB42TZYYN8Q61L 8tK4HgwJPJKouaZUkrZHjiI= X-Google-Smtp-Source: AGHT+IFGdDAWJO8wcF9X0cB5Ow16d+/7t9rEJoJMSZzs/HCFTz07D+tDAKWldPHF17W3jmaTRYSnWg== X-Received: by 2002:a05:6808:10d6:b0:3ab:8e86:fc26 with SMTP id s22-20020a05680810d600b003ab8e86fc26mr9082671ois.46.1700424422545; Sun, 19 Nov 2023 12:07:02 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6a00:2d01:b0:690:d40b:b5d6 with SMTP id fa1-20020a056a002d0100b00690d40bb5d6ls1276679pfb.2.-pod-prod-01-us; Sun, 19 Nov 2023 12:06:58 -0800 (PST) X-Received: by 2002:a63:e513:0:b0:5bd:8bc2:7095 with SMTP id r19-20020a63e513000000b005bd8bc27095mr1161973pgh.10.1700424417735; Sun, 19 Nov 2023 12:06:57 -0800 (PST) X-Original-Sender: k.flo.west-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org X-Original-From: lukeflo Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:33342 Archived-At: ------=_Part_1294_2104258434.1700424416979 Content-Type: multipart/alternative; boundary="----=_Part_1295_1479890404.1700424416979" ------=_Part_1295_1479890404.1700424416979 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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]: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 PANDOC_VERSION:must_be_at_least '3.1' =E2=94=82 =E2=94=82 if FORMAT:match 'latex' then =E2=94=82 function Figure(f) =E2=94=82 local short =3D f.content[1].content[1].attributes['short-cap= tion'] =E2=94=82 if short and not f.caption.short then =E2=94=82 f.caption.short =3D pandoc.Inlines(short) =E2=94=82 end =E2=94=82 return f =E2=94=82 end =E2=94=82 end =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 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]: =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80 =E2=94=82 if FORMAT:match 'latex' then =E2=94=82 function RawBlock (raw) =E2=94=82 local caption =3D raw.text:match('\\caption') =E2=94=82 if caption then =E2=94=82 raw:gsub('\\caption', '\\sidecaption') =E2=94=82 end =E2=94=82 return raw =E2=94=82 end =E2=94=82 end =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80 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:=20 https://stackoverflow.com/q/77504584/19647155 [pandoc repo] [approach of pre pandoc version 3.0 posted] [/complex figures/] [here] --=20 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 e= mail 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. ------=_Part_1295_1479890404.1700424416979 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi everybody,

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

I already have an elaborated pa= ndoc template to produce the LaTeX
preambel etc. So far its working gr= eat.

But for the figures I need the caption from the Markdown fi= le to be set
with `\sidecaption' instead of `\caption' in LaTeX, as we= ll as with an
optional argument (short-caption) for the image attribut= ion in the list
of figures.

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

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80
=E2=94=82 PA= NDOC_VERSION:must_be_at_least '3.1'
=E2=94=82
=E2=94=82 if FORMAT= :match 'latex' then
=E2=94=82 =C2=A0 function Figure(f)
=E2=94=82= =C2=A0 =C2=A0 local short =3D f.content[1].content[1].attributes['short-ca= ption']
=E2=94=82 =C2=A0 =C2=A0 if short and not f.caption.short then<= br />=E2=94=82 =C2=A0 =C2=A0 =C2=A0 f.caption.short =3D pandoc.Inlines(shor= t)
=E2=94=82 =C2=A0 =C2=A0 end
=E2=94=82 =C2=A0 =C2=A0 return f=E2=94=82 =C2=A0 end
=E2=94=82 end
=E2=94=94=E2=94=80=E2=94= =80=E2=94=80=E2=94=80

That works without any flaws.

B= ut 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 tarlebis 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, s= o
far, I couldn't figure out how to change the LaTeX macro used for th= e
captions with this new behaviour.

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

=E2=94=8C=E2=94=80=E2=94=80=E2=94=80= =E2=94=80
=E2=94=82 if FORMAT:match 'latex' then
=E2=94=82 =C2=A0= function RawBlock (raw)
=E2=94=82 =C2=A0 =C2=A0 local caption =3D raw= .text:match('\\caption')
=E2=94=82 =C2=A0 =C2=A0 if caption then
= =E2=94=82 =C2=A0 =C2=A0 =C2=A0 =C2=A0raw:gsub('\\caption', '\\sidecaption')=
=E2=94=82 =C2=A0 =C2=A0 end
=E2=94=82 =C2=A0 =C2=A0 return raw=E2=94=82 =C2=A0 end
=E2=94=82 end
=E2=94=94=E2=94=80=E2=94= =80=E2=94=80=E2=94=80

But nothing happened.

The main = challenge for me are my more-or-less non-existing lua skills. I
just n= ever 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
t= hat should remain an absolute stopgap, since it makes the whole
workfl= ow 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.c= om/jgm/pandoc/issues/7915#issuecomment-1039370851>

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

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

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@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.
------=_Part_1295_1479890404.1700424416979-- ------=_Part_1294_2104258434.1700424416979--