From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32007 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: John MacFarlane Newsgroups: gmane.text.pandoc Subject: Re: latex macros expansion as a Lua filter? Date: Tue, 17 Jan 2023 13:06:52 -0800 Message-ID: <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA@gmail.com> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_F7CF60F3-FD9A-40A1-B338-2FCFB2A33FAC" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34989"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDW7ZIEHTIIBB4M3TSPAMGQEN6FIKAY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Jan 17 22:07:02 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-pf1-f184.google.com ([209.85.210.184]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pHtAb-0008ry-Nr for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 17 Jan 2023 22:07:01 +0100 Original-Received: by mail-pf1-f184.google.com with SMTP id k20-20020aa792d4000000b0058347d2f5e3sf14515591pfa.15 for ; Tue, 17 Jan 2023 13:07:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1673989620; cv=pass; d=google.com; s=arc-20160816; b=pRIVSkV1G2sPZ9Rds2BsAiVeszveDdEZzIa2iVXPg7S2llwNTt8s3D7a64Z42H5vMq i21LwitveK7BrsECKW/Ru/MiRGu55LUnBzzR33ObYCofgMvXefd+/kaNvksbm+OLNHqJ DTH3yqV36cslGKNcFvnZJdk+IyCv5NH6/E4Ts8FUJpZyuPvk3HCBd5qRgHmiHWMV35Hz +OwpNVGuFWliekO/abmDJ1wwt6kZYLr5T9nNX9oQjBVdfmARO7k3jIGQ8+ymAlG3oZl/ hvh7+wjHk68OR8xzabGwzaKafh4WFMLr0BgZJIxFPQuU7yDwalWi9GB7qAR++JE+MBZY 1Uhg== 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:reply-to:message-id:in-reply-to:to :references:date:subject:mime-version:from:sender:dkim-signature :dkim-signature; bh=7d2fev3j0IJqDsohGyFtOKEussO+fDs/nGuAZRYeg+o=; b=yXiJBIocOUH13lAkH5peAywnUZKYzaEW5u5PrIJQq6DpZdnprvo/DHurKat+3HXlTq uGD37eDfcLfwZGFfY4HXYFn7LY9/gDRT+SxVDCMbZC8tzdhqZaM85uNs+g4UB6kyT8r2 0iuiFsYti+/YVkYF59ccicltLuXeP+13ol+7uFigde5G1Rg3AWYN5FqMsUsJdB3YbHw0 we3a/rergUwZmElhb6X8805z9gGIpuWKUXC+WILTcLGkK7TpmvjwphiM6cHnRqJ7HfxQ f3pQFHqEDawTtvdBA/zy/1C22mM8qfrH3sgJdX8FTvYnRpC9avbIw1dbztNeBQU8pPN/ yrvw== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qafNkb1S; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:message-id :in-reply-to:to:references:date:subject:mime-version:from:sender :from:to:cc:subject:date:message-id:reply-to; bh=7d2fev3j0IJqDsohGyFtOKEussO+fDs/nGuAZRYeg+o=; b=JAEDt8KRPu6i1rUgweZXfk8/SXhzTIlcav5Z2c4iYBYvwtSBLMMxSkA5NACMGCUT6F qzRrZ33oJFuj2YvUx1q03KviXC0y3YfJyFPOoCj14l7ZC9HlzVppKNzaqhijyifRymcj fd4dlJV79Xne4E7mFg78l0fDHPyUM+mz4D6YjxLem1TwHLwlBDpvhXSgRF3tKiuEZXIW Ru5wvpKID8aYOpqwu4j85ZfztVRG3sSTZDnlvw4TyCxnqrkGxrGrrepZ66dBABFUJvaK 7WnNaZbbRlFlD8joLO7oIsjco8HMafk6jWijTq/PAwF366+ONvVlt1zZsBpK2GKI0Zoh PBRA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:message-id :in-reply-to:to:references:date:subject:mime-version:from:from:to:cc :subject:date:message-id:reply-to; bh=7d2fev3j0IJqDsohGyFtOKEussO+fDs/nGuAZRYeg+o=; b=ZScR0UZG+jkYyhHwUrce0PQZsDttHA71y0nCCu77gMqQ8Adi8qBaWSo9zQpN5Zxw7O ipMBvxCJjvJQ+xDG8cH6nlZaQb3ypH04znVopx3ooPz6/aZA84rEVygqBMqj/AP73Eg7 wWpCYq0DUjJpzHXpoUZox0zvFtMlM7ukNgHv4da+DGbLEcOGf6zQUmtd4Wo3Cy8mfGyP KdD46//PSJyNQGNn+7INKEmjV6JYVFVXmL92ynoqQbTEwHp19b/n26vDQcTVwvXe3fnl F/kLVh1gb/NX6I2o55+0IKKE7Jd/8Vkw6+wzhyCNZ6jnqxgto7WA1fbuS30xxUm0PwcB THOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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-authentication-results:x-original-sender:message-id :in-reply-to:to:references:date:subject:mime-version:from :x-gm-message-state:sender:from:to:cc:subject:date:message-id :reply-to; bh=7d2fev3j0IJqDsohGyFtOKEussO+fDs/nGuAZRYeg+o=; b=2vcXJbuKHt5B4buoy3oScPDFHsMwE+7QkqZPdBGM65ju8RHhm18cRfqvSDBacDMU2r 1cTry08pOB+PlwOV+1XuaCESyzikRTqsywGyaxJfqGq2FlolMPaa2AvGqPxeKinYyIlT sfPgVRZjIlCld7j/EMwWyHqB2Dil+Q1FDXL/MPDhlBKqabqKLRmljk1XUHu1gTt4g/W5 hy5GJUNt6CoG+jWiXzeF7q0gLX6ZJ09L/tgfOzjIBas/0hPGhuDwPDdgjjFfNT3rI9QI yvS9DDtVeMy+3UeR/kHKuvNUURIKHK4QwTtauLhGlbF17t Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2krSzlggYMEsZrHe/ALYW5rGawl700DgqRXF9FcK0vjUOnVcWAXn 1eKrJ+2WcVuS1qyBM76FS+g= X-Google-Smtp-Source: AMrXdXtskLeuHu92Bsw/tcNvGkThm4xsohoy+hs4c8T01xru230jjHFP8h5odm4XDtUAxxCs3rfPKQ== X-Received: by 2002:a17:902:7c15:b0:193:3589:4385 with SMTP id x21-20020a1709027c1500b0019335894385mr396968pll.70.1673989620407; Tue, 17 Jan 2023 13:07:00 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a17:90b:1013:b0:226:42ea:28cc with SMTP id gm19-20020a17090b101300b0022642ea28ccls984360pjb.0.-pod-preprod-gmail; Tue, 17 Jan 2023 13:06:56 -0800 (PST) X-Received: by 2002:a17:90b:2349:b0:226:7fcb:c215 with SMTP id ms9-20020a17090b234900b002267fcbc215mr4822080pjb.17.1673989616759; Tue, 17 Jan 2023 13:06:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673989616; cv=none; d=google.com; s=arc-20160816; b=vBmGHmJcVRaTIkmz9ao3TZy+yOLZkJzRQQ2yjV2hSsL/rQhnieH8J2ZhqU1v3k7kUe BWnLt37EoiOZB7XmjvTNZZNAyl47en2q3r8z0mf0wRxat8kptdLW2D6g2H+X/a2M9ojb R1uGtQwP9/xKWZlyH7PWwRBC1hTXS26s1j2eZnH3cI1aXjE7ofP89dzer+CYWFBcyytT 6untlDLwSR/Z7A7BqD7nLlFcxCwAMaibiZBLrtc2WmdYMggT27+9G9By3+Wqaf4mj7hJ mafs0w+gLNwf/4g8RveXHe9X5RWMxqrFIqxV6cxMxbXvDtqrSt+qoY9wLc2Cw+84ojEo 0yCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:in-reply-to:to:references:date:subject:mime-version:from :dkim-signature; bh=Fja5J+1aS35KqLN54E8YGSeGQCe6Pma+UGL9I3+c8EE=; b=fF6TgqHk75dvtwihAfbZV8hJec1jpSI8QwY7bf7yZwuyPb4s1fvX/IDJZKKOGBEwAe a1VZgqTb9B/Lvmy273+fafRqi0NvIw7Vzx3H5xGaNmBR6F1J8+8wjghrKxKpdK4Phq6M NtPp/1nwwU2dpFCHzjSoVys32MGOQveQ3U9uHTUmLAuC8k/ctvVtHfdvU9IyqE17aAdy XL/xX31LywjKzKwfQhJxGv1G4px/1I1LuZho5kTcwkruGcJktei0q3ZNl/l9tXS7eBWk v/9P/D990pK4nOYYjnQ0NtS1ec5ok9QfxkYkW1elKSPtLEe6lg1x439wn656L8fcylk/ +2gg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qafNkb1S; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com. [2607:f8b0:4864:20::636]) by gmr-mx.google.com with ESMTPS id p19-20020a17090adf9300b0022673858f16si932227pjv.1.2023.01.17.13.06.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 13:06:56 -0800 (PST) Received-SPF: pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) client-ip=2607:f8b0:4864:20::636; Original-Received: by mail-pl1-x636.google.com with SMTP id b17so27321076pld.7 for ; Tue, 17 Jan 2023 13:06:56 -0800 (PST) X-Received: by 2002:a17:902:b587:b0:193:6520:73a4 with SMTP id a7-20020a170902b58700b00193652073a4mr4791880pls.61.1673989616038; Tue, 17 Jan 2023 13:06:56 -0800 (PST) Original-Received: from smtpclient.apple (protagoras.phil.berkeley.edu. [128.32.252.45]) by smtp.gmail.com with ESMTPSA id im15-20020a170902bb0f00b001943d58268csm15283878plb.55.2023.01.17.13.06.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 13:06:55 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.13) X-Original-Sender: fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=qafNkb1S; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::636 as permitted sender) smtp.mailfrom=fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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:32007 Archived-At: --Apple-Mail=_F7CF60F3-FD9A-40A1-B338-2FCFB2A33FAC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Well, you could use the Lua =E2=80=98read=E2=80=99 function to read in a sn= ippet consisting of the macro definitions + the math. e.g. pandoc -f latex -t native \newcommand{\pie}{\pi} $\pie^2$ ^D [ Para [ Math InlineMath "\\pi^2" ] ] > On Jan 17, 2023, at 11:17 AM, bapt a wrote: >=20 > Hi, >=20 > I've found it useful in some situations to expand all custom LaTeX macros= (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document be= fore rendering it.=20 > For example, with Quarto being used to produce a book in both pdf and htm= l formats, the macros stored in a file `_macros.tex` are processed differen= tly in the LaTeX path (simply including `_macros.tex` in the preamble) and = in the Html version (where Mathjax needs to be given such macros for every = page that it renders; it doesn't work to provide it once for the whole book= /website).=20 >=20 > An alternative that sounds quite robust would be to run something like de= -macro (https://www.ctan.org/tex-archive/support/de-macro) on the source do= cument before it is rendered: the macros are still used for convenience of = writing in the input file, but they get expanded explicitly before LaTeX or= Mathjax is asked to render. >=20 > Unfortunately, de-macro is a Python script, and might be a little fragile= as it processes whole documents with regex. I wonder if achieving the same= thing would be easier with a Lua filter in pandoc? Presumably, having alre= ady all the equations isolated in the AST makes life a bit easier, and I be= lieve there is already a mechanism in pandoc to process and expand `\newcom= mand` directives for non-latex output. Is this mechanism available to a Lua= filter that could be used in a Quarto workflow? >=20 > Many thanks, >=20 > baptiste >=20 >=20 >=20 >=20 >=20 > --=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= email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org . > To view this discussion on the web visit https://groups.google.com/d/msgi= d/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com <= https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29= bae4777811n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter>. --=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/2951DE27-E21B-4C3B-BFEA-BF370ECF50EA%40gmail.com. --Apple-Mail=_F7CF60F3-FD9A-40A1-B338-2FCFB2A33FAC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="UTF-8" Well, you could use the Lu= a =E2=80=98read=E2=80=99 function to read in a snippet consisting of the ma= cro definitions + the math.
e.g.

pandoc -f latex -t native
\newcommand{\pie}{\pi}
$\pie^2$
^D
[ Para [ Math InlineMath "\\pi^2" ] ]

On Jan 17, 2023,= at 11:17 AM, bapt a <a= uguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

Hi,

=
I've found it useful in some situations to expand all= custom LaTeX macros (such as `\newcommand{\Curl}{\nabla\times}`, for examp= le) in a document before rendering it.
For example, with Quarto being used to produce a book in both pdf and html= formats, the macros stored in a file `_macros.tex` are processed different= ly in the LaTeX path (simply including `_macros.tex` in the preamble) and i= n the Html version (where Mathjax needs to be given such macros for every p= age that it renders; it doesn't work to provide it once for the whole book/= website).

An alternative that sounds quite robust would be to run something = like de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the = source document before it is rendered: the macros are still used for conven= ience of writing in the input file, but they get expanded explicitly before= LaTeX or Mathjax is asked to render.

<= /div>
Unfortunately, de-macro is a Python script, and might = be a little fragile as it processes whole documents with regex. I wonder if= achieving the same thing would be easier with a Lua filter in pandoc? Pres= umably, having already all the equations isolated in the AST makes life a b= it easier, and I believe there is already a mechanism in pandoc to process = and expand `\newcommand` directives for non-latex output. Is this mechanism= available to a Lua filter that could be used in a Quarto workflow?

Many thanks,

baptiste


=


<= div class=3D"">
--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://grou= ps.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%= 40googlegroups.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://groups.google.com/d/msgid/p= andoc-discuss/2951DE27-E21B-4C3B-BFEA-BF370ECF50EA%40gmail.com.
--Apple-Mail=_F7CF60F3-FD9A-40A1-B338-2FCFB2A33FAC--