From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32008 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: bapt a Newsgroups: gmane.text.pandoc Subject: Re: latex macros expansion as a Lua filter? Date: Tue, 17 Jan 2023 16:50:09 -0800 (PST) Message-ID: References: <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA@gmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_12462_2107802767.1674003009155" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21541"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDG3FYUYQUCBBQUETWPAMGQERD3WO3I-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jan 18 01:50:14 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f61.google.com ([209.85.160.61]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pHweb-0005Sa-OT for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 18 Jan 2023 01:50:13 +0100 Original-Received: by mail-oa1-f61.google.com with SMTP id 586e51a60fabf-15f0a1b7764sf2636475fac.0 for ; Tue, 17 Jan 2023 16:50:13 -0800 (PST) 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-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=30yY7PFU6VQiH8YU+y0+irZsaKsl3oCjGyiWeALCF14=; b=JJEpQcV+oIV5zzUZiMVHqQZ4TsMB/PqJ1dgMvvSGq4gFBdnZ9A7smawgXkhO+Ui0rw S57FClYSUzAXTsWpmrFZPw3ttYt0TfShKjMCfODKKMbvR8ifCGctvBclNiHeZfRJe/yi h3uD0LDR4ha6NGLX2gPzJhMhbwbdnY9vN1S444kPunoDj4nE2X1MYVGNHVDSV2/GTnrb QKtfsmbpLjKxOlIJ37rfmvmYOCfrkmCMEJTw/T85YUE8119XTx7QWtdio2dMrygh0fFy pwF+ymx4hAlVIWVrCn6kWSrdC/Rl+2vEirfzpV4KyN2aDVspSHUoQLdbdEKTshXZwzrc Oseg== 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-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=30yY7PFU6VQiH8YU+y0+irZsaKsl3oCjGyiWeALCF14=; b=OviGt3KM/gUYR+i/CubVoTDYvkGhcYlaTQFJjLXoCS1ryL81TTjUguA6cZDr3xKSqb 1phIfrmJRENeDOV5r9SzBlk9tZmi0NMtW6LK1FV0x8OSR5LZK4iLQfmoF7FSVj/aLgey OQPLsu7Xg75Rft9ds4sDnOT4l3SdHXUN8Aw/W/Etd5/AbX+qgWlGtbLHjanHA+6oW+Rd P04PTqA6SkWcPTkPp2d7jcnLGsGnJDaS6YBpWhjTAVH+oxRQphVtimZM54hTvxShpGX+ jGcQ1FriU47MSGYkviVcSZp9R8BhjgUhXQ/8Wzht5E4yIp4NFozfzofhsbSN+c+sAHuI hkYw== 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-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=30yY7PFU6VQiH8YU+y0+irZsaKsl3oCjGyiWeALCF14=; b=tx2f2OTrmZc6l4DcDc9TdCMsowa+TUBAD8Z5zDNpU6J43VYNNCkTsMYWWj7ANjpowJ qmEhZgA9+f3Sbo0MIsxwYGRA+YnRPUuRZDzAdAqAN6808ssZZacV4GT6ZBCVHdCkKPxm BeZySB8WSl/M2hSqcr53x0EP9H1KIPdpSog+fJAhr4ssuO7LAPqK1VTXfVqJjAwvQPKI 14Z2w/JDleqpkRULD1hov+8u50Sw2ilQEWAlkLKEAR9nvajAv4YwWCEzYH0OwKSYDpRX EmzFcosvfEs/3EdraGZ4MOjzPGQlRrQQXjp/HYJeugvwwyhixAR8EVnAZv9xzKNw4H1G 0/HQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2kqN4vWH2Gssgh1auJE66odAKZL+CAozsLzQWoOmyqkeeOqbbwci rDpwakjb/GgrbAbO0cmhKfA= X-Google-Smtp-Source: AMrXdXvRQVrNXXaWsnmPwTGaxSDw+52b2/oNWvLQ1QVWvl6IH0gfOo6VqWrmtk2aikR4vO3HNH7J/g== X-Received: by 2002:a05:6870:8e0d:b0:15f:289:6478 with SMTP id lw13-20020a0568708e0d00b0015f02896478mr321619oab.132.1674003012220; Tue, 17 Jan 2023 16:50:12 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:3a2a:b0:150:5959:52ad with SMTP id du42-20020a0568703a2a00b00150595952adls6995167oab.3.-pod-prod-gmail; Tue, 17 Jan 2023 16:50:10 -0800 (PST) X-Received: by 2002:a05:6870:44d3:b0:15b:8862:3208 with SMTP id t19-20020a05687044d300b0015b88623208mr379413oai.28.1674003009838; Tue, 17 Jan 2023 16:50:09 -0800 (PST) In-Reply-To: <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> X-Original-Sender: auguieba-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:32008 Archived-At: ------=_Part_12462_2107802767.1674003009155 Content-Type: multipart/alternative; boundary="----=_Part_12463_1743141757.1674003009155" ------=_Part_12463_1743141757.1674003009155 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I see, thanks. If I'm understanding this correctly, pandoc already performs= =20 such macro expansions (for non-latex output), so the only thing preventing= =20 it in the context of a Quarto html book is that one needs to include the=20 macros alongside each chapter, as they are processed separately=20 (https://github.com/quarto-dev/quarto-cli/discussions/1045). It's therefore more of a Quarto feature, to make sure the macros are copied= =20 over with each chapter, but there's no need for an elaborate filter to=20 implement this. Many thanks, baptiste On Wednesday, 18 January 2023 at 10:07:00 UTC+13 fiddlosopher wrote: > Well, you could use the Lua =E2=80=98read=E2=80=99 function to read in a = snippet=20 > 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: > > Hi, > > I've found it useful in some situations to expand all custom LaTeX macros= =20 > (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document= =20 > before rendering it.=20 > For example, with Quarto being used to produce a book in both pdf and htm= l=20 > formats, the macros stored in a file `_macros.tex` are processed=20 > differently in the LaTeX path (simply including `_macros.tex` in the=20 > preamble) and in the Html version (where Mathjax needs to be given such= =20 > macros for every page that it renders; it doesn't work to provide it once= =20 > for the whole book/website).=20 > > An alternative that sounds quite robust would be to run something like=20 > de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the=20 > source document before it is rendered: the macros are still used for=20 > convenience of writing in the input file, but they get expanded explicitl= y=20 > before LaTeX or Mathjax is asked to render. > > Unfortunately, de-macro is a Python script, and might be a little fragile= =20 > as it processes whole documents with regex. I wonder if achieving the sam= e=20 > thing would be easier with a Lua filter in pandoc? Presumably, having=20 > already all the equations isolated in the AST makes life a bit easier, an= d=20 > I believe there is already a mechanism in pandoc to process and expand=20 > `\newcommand` directives for non-latex output. Is this mechanism availabl= e=20 > to a Lua filter that could be used in a Quarto workflow? > > Many thanks, > > baptiste > > > > > > --=20 > You received this message because you are subscribed to the Google Groups= =20 > "pandoc-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an= =20 > email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit=20 > https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-= 29bae4777811n%40googlegroups.com=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 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/b1e37c1b-8529-4374-b16c-bfc8f0e44213n%40googlegroups.com. ------=_Part_12463_1743141757.1674003009155 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I see, thanks. If I'm understanding this correctly, pandoc already per= forms such macro expansions (for non-latex output), so the only thing preve= nting it in the context of a Quarto html book is that one needs to include = the macros alongside each chapter, as they are processed separately (https:= //github.com/quarto-dev/quarto-cli/discussions/1045).
It's theref= ore more of a Quarto feature, to make sure the macros are copied over with = each chapter, but there's no need for an elaborate filter to implement this= .

Many thanks,

baptis= te



On Wednesday, 18 January 2023 = at 10:07:00 UTC+13 fiddlosopher wrote:
Well, you could use the Lua =E2=80=98read=E2=80=99 function= to read in a snippet consisting of the macro definitions + the math.
e= .g.

pandoc -f latex -t native
\ne= wcommand{\pie}{\pi}
$\pie^2$
^D
[ Para [ Math InlineMath "\\pi^2" ] ]
<= div>
On Jan 17, 2023, at 11:17 AM, bapt a <augu...-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 Qua= rto being used to produce a book in both pdf and html formats, the macros s= tored in a file `_macros.tex` are processed differently in the LaTeX path (= simply including `_macros.tex` in the preamble) and in the Html version (wh= ere Mathjax needs to be given such macros for every page that it renders; i= t doesn't work to provide it once for the whole book/website).

An alternative that sounds quite robust would be to r= un something like de-macro (https://www.ctan.org/tex-archive/support/d= e-macro) on the source document before it is rendered: the macros are s= till used for convenience of writing in the input file, but they get expand= ed explicitly before LaTeX or Mathjax is asked to render.

Unfortunately, de-macro is a Python script, and might be a little f= ragile as it processes whole documents with regex. I wonder if achieving th= e same thing would be easier with a Lua filter in pandoc? Presumably, havin= g already all the equations isolated in the AST makes life a bit easier, an= d 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





--
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-discus...@googleg= roups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a5d780b= 9-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/pandoc-discuss/b1e37c1b-8529-4374-b16c-bfc8f0e44213n%40googlegroups.= com.
------=_Part_12463_1743141757.1674003009155-- ------=_Part_12462_2107802767.1674003009155--