From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29876 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: BPJ Newsgroups: gmane.text.pandoc Subject: Re: filter to inject raw TeX command based on header attributes Date: Fri, 31 Dec 2021 12:52:54 +0100 Message-ID: References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000019037005d46fd0bb" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21905"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBCWMVYEK54FRBH66XOHAMGQEOCTVVIQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Dec 31 12:53:06 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wr1-f64.google.com ([209.85.221.64]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n3GT3-0005We-L8 for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 31 Dec 2021 12:53:05 +0100 Original-Received: by mail-wr1-f64.google.com with SMTP id v15-20020adf8b4f000000b001a24c46d6cesf7490401wra.15 for ; Fri, 31 Dec 2021 03:53:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1640951584; cv=pass; d=google.com; s=arc-20160816; b=i0RY4mPm2BIMexTsiqYW1YDXtZ49GBTzktJcP3UBkAILhjgg0eOcwGWYP1GsuDg1wl YgD8vpUacd/lWJ6PU55uLSkUeEO4fHz1kRrRCKAfLGhCTAswvICOG+1diXd9wtMrrJdc PA3lNa33MQWypck1UhsNNDvZjKqNCXhtENYBAaBQszQgj1MvQER5XSxznrXKn5oAHvCz GGQU66/iPeBokqKY7JB0wCDnWRhLinRTtdtxbboxqfOBx2R+qvPTgMYrDn5v3D5WoD0f y9+Cft8lgCjJ8YYsGHTyY0o0yIzVcaFGcEOddFENVOuYLpIXs01BndN3+0ywm2rWi4K0 OkyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:sender:dkim-signature; bh=IVp7iKYYGrTkdC2gIIMHSx+Gvxx1kerchPeX+pFy5CA=; b=yGbtUuvSxBHsjLnV4tmJnMgh0Ln9BCjvex8LClXrONK9qRlduUOh2usvKOQiql6jD1 50/1nmP3wuA5rdTgXJjdsk/WsPsFXiZKNdXHNMnQcvnX4nTGccpRgZhYe+CpXnaHuHuh talQVHjBwGkWmZbaSjzeTqDjGHnLo1rI1opJcK3mY4d4fupaxILdmwOMlAcegsX3CvAo 6nfED6k5tyZ6Z9afhaxoNRUdxtLVJUjCBdWNjO2bKqu1d5PwDr83gQaEpO4zACB5jAYD 2R7P/xxVXsy9O1CAryJdKKMZgAqS9gxHd329f58ndjkx5GGQxJMPSGQj7TH88wI+PLLE eZaQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.170 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:mime-version:references:in-reply-to:reply-to:from:date :message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=IVp7iKYYGrTkdC2gIIMHSx+Gvxx1kerchPeX+pFy5CA=; b=HA3HkSKbEb31RbSs79oU2RvxC6iP6LJ/jx1Vn3tqxekbBEygFt9zJlo2k3vrnhUh04 WlGU0BFPnNvp088kK/QxBQCtuwJP+FKS+9n8KIqOxkPIUt6EyprPZ+gnVJOzxdf9O292 VeEF5dYWyRFycO81Hrw3iHO7QjXVLFoiRDPNba8G/La+PlhjXs4d8slFGCcJJnhXVRHX MRFp1EpaCWoqKpGnAPvRH0W7nUfECgpMkt8ZOfyOrouDxkgu2Yzc93PLYObbaFXYaw+3 yRPNJGycY9cC+OSDutygG/wr5NkAjCeFDJftwuI15ANaEgaMYV+WNxXAAGAAzVAiitxq xiSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:mime-version:references:in-reply-to :reply-to:from:date:message-id:subject:to:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=IVp7iKYYGrTkdC2gIIMHSx+Gvxx1kerchPeX+pFy5CA=; b=R3/9Q/HdfdJ23Q//0yh0TrL/vSlaX3aA6LikjkU1DcaXCvRoBJOwVgYREbw35jUdHw BNooNu7FkZlGzWT6ArdQzrU6Q8Y8ZSMNoQhLWtZBoZ7YdswZ1qd9fgiNO8YCeDg9PMUA DLhEVx5C7vSNUW2vynt8vNM3N72l9Hror2g4qc3Ju7ePMK8jHvho7mw+TlwJ73OYWowh xhCqZJGtu00V3KBnR57qYG/chFjGlzHd6Q0K6aRHn25kYQWdJsq5o9Wi3FMwQ4kY0F3m surf3qXSLNy7RO0negvtKQkR371DpvJNuOd6alT9NHuFnVcTWdm83iPm7IHwFxQbRLOc avHA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533nlieX3tT7Yr77J4C/E2yZKw+iqDs+CSRq0nxuK12c4j7/hl/G DZ5Z7y45OvAYXpZai5kRPBc= X-Google-Smtp-Source: ABdhPJyK9I3yGjpnu58Kk0RJB0Gc/MSVism4Q/vgqymRbRnbEj2sGNOWRlGMdGFWn6rUllSajkRktQ== X-Received: by 2002:adf:e88d:: with SMTP id d13mr29175021wrm.204.1640951584784; Fri, 31 Dec 2021 03:53:04 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a5d:5082:: with SMTP id a2ls90561wrt.1.gmail; Fri, 31 Dec 2021 03:53:02 -0800 (PST) X-Received: by 2002:a05:6000:12d0:: with SMTP id l16mr28228973wrx.466.1640951582206; Fri, 31 Dec 2021 03:53:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640951582; cv=none; d=google.com; s=arc-20160816; b=aFscGDgZumzUj/E7ZF53KZKoKn5sK3FStMZPXbacES04WaXVB1qVdPsPoPJ+P2bGrz 7EyDaCO6/jknrBvtihZwb0/LP2DxhwsGPedfu3QMIxbTBJl7nDR/B4VEBW6blH4lEWH1 D0XPr9Z464ViYkrkfJoBbY1rvfMRrDg0VfM/NVxsjLg0rSCYCQkF8M1Nr5gfepKp0U20 NmOTNbLf80gDJ+6KqJwgnv3uqtZI+k2Nh0DT+nXqFbcswtA2sIUpz8S4zZbcQQ+F7BXk PV5Q0o9lbjIbz1lKsEZUqdKzRs6hzgKyiCK6agimdv96JQoUX/jNzTkj0zZ9lnDlXSVl cvkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version; bh=vVUuIIi3SOIRPD6krsbbEk5wTqpI4x+Cv+z0GMYEQXs=; b=arqYEegM6twGlYaZVwySxYfuT476WIuaQueUS+hVbpfU1HjwRR1WkMNx621BmH6hW2 7+B2cddmAukHsahAVpBQk/3xzTgMHZ+gEeJoylRkd4Saz79fWlRgr9csZYy1QlvJh117 MTiMfEnDhqZmaQO/k9dTOkT0E7gZ18LpIjj05Z6Dzh+YRKC21SBfiuO5y5EuAyTpW/iq WMZx7bGoTvnNGhIlOnR+MOmDqzYLkeB2KxAqWh1SfKrVo7sGi2wDTpw4fWrvzFALDrqF Iuvge1BuWIUryJedPaRLibwXScNHSEDtlsIyFxVTStjoU6+PhSb25yIiTPd6knVweypi IwmA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.170 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Original-Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by gmr-mx.google.com with ESMTPS id j23si2207212wms.4.2021.12.31.03.53.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 Dec 2021 03:53:02 -0800 (PST) Received-SPF: pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.170 as permitted sender) client-ip=209.85.208.170; Original-Received: by mail-lj1-f170.google.com with SMTP id h15so31351353ljh.12 for ; Fri, 31 Dec 2021 03:53:02 -0800 (PST) X-Received: by 2002:a2e:5756:: with SMTP id r22mr29507100ljd.71.1640951581310; Fri, 31 Dec 2021 03:53:01 -0800 (PST) In-Reply-To: X-Original-Sender: melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 209.85.208.170 as permitted sender) smtp.mailfrom=melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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:29876 Archived-At: --00000000000019037005d46fd0bb Content-Type: text/plain; charset="UTF-8" I think I mentioned this recently but a useful trick when using a filter to convert most code spans/blocks into raws or something else is to use a dummy class `.code` on those which don't have any other class(es) and shouldn't be converted: ``````lua local function no_code_class (it) return it ~= 'code' end function Code (elem) -- Skip if it has any classes if 0 < #elem.classes then -- Remove the 'code' class elem.classes = elem.classes:filter(no_code_class) return elem else -- Do whatever you want with a "bare" Code e.g. return pandoc.RawInline(SOME_FORMAT, elem.text) end end `````` Den ons 29 dec. 2021 21:46bapt auguie skrev: > Excellent, I managed to adapt it and it works a charm! > > Thanks, > > b. > > On Wed, 29 Dec 2021 at 20:42, John MacFarlane wrote: > >> bapt auguie writes: >> >> > I would like to walk the AST, and immediately after headers with a >> specific >> > attribute, inject a \renewcommand{} based on the header's attributes, >> such >> > as (dummy example), >> > >> > \renewcommand\subsection[1]{\textbf{#1}} >> >> This is pretty easy. You would have a function >> >> function Header(el) >> local attr = el.attributes >> -- you can do attr['foo'] to get the value of the 'foo' attribute >> -- now create a string with the macro: >> local macro = ... >> return { el, pandoc.RawBlock("latex", macro) } >> end >> >> You can fill in the blanks. >> >> -- > 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/CAGCXF2_r6G_sMQWmxyXKA5i29gRFLtOG5Z-WowKXkHASThsGqQ%40mail.gmail.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CADAJKhDE3NyVp%3DCDNczGtUkOd2mPjw6zdxRRdYd5xzgOKmLXNA%40mail.gmail.com. --00000000000019037005d46fd0bb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think I mentioned this recently but a= useful trick when using a filter to convert most code spans/blocks into ra= ws or something else is to use a dummy class `.code` on those which don'= ;t have any other class(es) and shouldn't be converted:

``````lua
loca= l function no_code_class (it) return it ~=3D 'code' end

function Code (elem)
=C2=A0 -- Skip if it has any classes
=C2= =A0 if 0 < #elem.classes then
=C2=A0 =C2=A0 -- Re= move the 'code' class
=C2=A0 =C2=A0 elem.cla= sses =3D elem.classes:filter(no_code_class)
=C2=A0 = =C2=A0 return elem
=C2=A0 else
=C2=A0 =C2=A0 -- Do whatever you want with a "bare" Code e.g.
=C2=A0 =C2=A0 return pandoc.RawInline(SOME_FORMAT, el= em.text)
=C2=A0 end
end
=
``````
=C2=A0 =C2=A0=C2=A0

De= n ons 29 dec. 2021 21:46bapt auguie <auguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> skrev:
Excellent, I managed to adapt it and it works a charm!

Thanks,

b.
<= /div>
O= n Wed, 29 Dec 2021 at 20:42, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wro= te:
bapt auguie = <auguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I would like to walk the AST, and immediately after headers with a spe= cific
> attribute, inject a \renewcommand{} based on the header's attribut= es, such
> as (dummy example),
>
> \renewcommand\subsection[1]{\textbf{#1}}

This is pretty easy.=C2=A0 You would have a function

function Header(el)
=C2=A0 local attr =3D el.attributes
=C2=A0 -- you can do attr['foo'] to get the value of the 'foo&#= 39; attribute
=C2=A0 -- now create a string with the macro:
=C2=A0 local macro =3D ...
=C2=A0 return { el, pandoc.RawBlock("latex", macro) }
end

You can fill in the blanks.

--
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 pandoc-discuss+unsubscribe-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.org= m.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/= CAGCXF2_r6G_sMQWmxyXKA5i29gRFLtOG5Z-WowKXkHASThsGqQ%40mail.gmail.com.

--
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://group= s.google.com/d/msgid/pandoc-discuss/CADAJKhDE3NyVp%3DCDNczGtUkOd2mPjw6zdxRR= dYd5xzgOKmLXNA%40mail.gmail.com.
--00000000000019037005d46fd0bb--