From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32009 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 19:54:25 -0800 Message-ID: <8FE474B9-67DE-4F0A-96FF-8DB5B522133D@gmail.com> References: <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA@gmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12045"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDW7ZIEHTIIBB5G2TWPAMGQEB3CJZOY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Jan 18 04:54:32 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-il1-f186.google.com ([209.85.166.186]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pHzWx-0002xD-S5 for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 18 Jan 2023 04:54:31 +0100 Original-Received: by mail-il1-f186.google.com with SMTP id r6-20020a92cd86000000b00304b2d1c2d7sf24350788ilb.11 for ; Tue, 17 Jan 2023 19:54:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674014070; cv=pass; d=google.com; s=arc-20160816; b=Nd8amBqGpDxN+blAdNqRb4qLM16CW8KnC3d+V+MI8uhbNxUHRQgoratzCeg8VZNIJJ ixs2ZAPaZ8VGsWw+9qx9TDBpB0Q8kp8iHWPB2AJ6RjrLMDj1asMlDShMIyCZx7BCxFWG z2YtmS8JOGgOnbk9/gZPQ9lYjRfZPBb4gQXDuRjvFS9+VsmPazN1azR5Og0hITTt5PVq e1NG2J2URREh05U5j5G/LLpHkxwOy3bt9SJjaIlVmzhf3/Yt6Asu07F2QbbTHJ5OEEAZ QSvCJxB+hnupMe3syA6jfUsvzrhikH8+gIrxLIcN8S9dq5muHsxqpxbfnA3jdgKFKnUD 73pQ== 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:content-transfer-encoding:from :sender:dkim-signature:dkim-signature; bh=Wu4H7c47/dH0NsPOq70NrT/72NFE+OxvfWqjKo0fpWo=; b=WzDL8Z1jGw7OdjGMwICu9p+sh07rnYI608XvGGcrsQa0BKxOPTV0Hp/ayQVPxpQhgk c5KllhdouHgdhs4C8ulGsv2IUHkLSgmD6X1qrEkCeEZmw1VKrm987k/fPfAZr2SFz6Wl NowwsJbgitwr5/WrnNykysksBHDOC6Zs8vA6YVMpCRa4Fpen5mnfDAjgFc8BU3RWbcrm 9gKWlzpOxLJYdrIc90o7oUtoSLIpxbljkmo2rWJmdkJR7UfIDGf+V3AwApoNjrTT+yg3 DQuk4PrEfp+0BZKixYsl8a/MdgRexiGhizhI615fVcziW29BWNDSJ5oItavli92+4bFA p59Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lgwl77HC; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::430 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 :content-transfer-encoding:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Wu4H7c47/dH0NsPOq70NrT/72NFE+OxvfWqjKo0fpWo=; b=OA30u46BJ8Y0zwMJQb8pdQ54UpdqaGDuFghDIA9s/h3p2UJdvsAFUCu8xbUCj73uvI NZdQhIzSzZeIYGpmmWp7S1p3SH84JP44FtdZHvXSQ1YDs5bDjN+UEdOUd5G3B1Ahrs2o +1xCs+DpZaKj7vBT0K4gZyViH119ftGiUoc1HID5olkJN10MkgLogBP+cO5VJ6bV82ER yTv3tpUtTef2PUqlR6muLQ1AIRBDpbbakZKSbWo+4/6muYjvRlksqJAtvU6SU9vEJx2c 78e+ngyHUdpNtps8jso8Cm30y+DPXQkOBZBaCwIlMIfX5LyRCAw9d8A0U+VKF+/l8 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 :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=Wu4H7c47/dH0NsPOq70NrT/72NFE+OxvfWqjKo0fpWo=; b=AwcX/4XmYWLedoEM3/OfUZ9G/3r72d6qKF3spzaDVDK8LLGEGuytazYNHCQC2+J4hn FEQqdrbftZTd7GpXBxNSLqwlNfCOYETMVSf108Rn0V637rUXPMvRUzB05/6YGjzd65A9 c52QI4IHYcSmFmVE7uuxx5C57hM2NxX571R9lhLzgvoe7Md/AEXOwpatxswOnQjhRf3z WGzcQiqXSVY6lKrd3Q+dDXfRESK6KoLtKg8c5FVlPO05bdkG82dY/MVeiNXdGKYSQ1M6 fnvGwxHHiyFdIUADEafdcsCsb/oZBbA1vZ6DJH/DWN1YwS3BRZGV5FmuqXzW+cAUGZBn i 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 :content-transfer-encoding:from:x-gm-message-state:sender:from:to:cc :subject:date:message-id:reply-to; bh=Wu4H7c47/dH0NsPOq70NrT/72NFE+OxvfWqjKo0fpWo=; b=pRlY/8XhTnk6VRYWVjyUAFoDzmyuLK6AzK+ZdjDcMkr8IzXAuP4bHeFxlrBHhihPWp vprYo5mRf/Eb+DjnSPX2x/W/uZlZOul8qhSRxTYZ1oSMWrTAIU0+eRNatkyE5JtF0MWm KyRBDh8urXZ/W9+14Y6dN0ieTdasuTU1hSbSyI0e2R3XqCny0mCBwfgCTW4fxKgvMAB2 lvU5MEqoLcBymiiQKGUSnBEh/inpPEMc9noGX9HtW4LqjR/jxXH+eqBaj1PWIxAUWrnR oyQnWBJ06RNZ899DTs2W Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AFqh2koO8jFiwQ3S0WeaTRnNA0Gll/l4Fx+7GwZVNG+Y7aIuVfIhCKY5 BjiT5/9ljys12jXnhqnArek= X-Google-Smtp-Source: AMrXdXtWWE0eSU9FeA4v8RBRYYOPKKD6uv5MS86LP0qlje/SRndZU0DN7DpZBqO7V3RpOW7cbJAflw== X-Received: by 2002:a05:6e02:f03:b0:30e:eecb:169b with SMTP id x3-20020a056e020f0300b0030eeecb169bmr498867ilj.246.1674014070618; Tue, 17 Jan 2023 19:54:30 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a6b:7f0c:0:b0:6de:dad2:59ac with SMTP id l12-20020a6b7f0c000000b006dedad259acls3250838ioq.4.-pod-prod-gmail; Tue, 17 Jan 2023 19:54:28 -0800 (PST) X-Received: by 2002:a6b:6704:0:b0:6e0:2988:dd98 with SMTP id b4-20020a6b6704000000b006e02988dd98mr4373772ioc.2.1674014068167; Tue, 17 Jan 2023 19:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674014068; cv=none; d=google.com; s=arc-20160816; b=Hxr9m+0Ihftkp+27wL7797tafntWHH8w1cw+8to15whnN0N5IGBp4CSPYtDIhvWhsK BX+CRCRzDOEckk9ZBJ7QlKFVcO2R+5ChIytqrJfs1sYYHA9zcFtKOl01Aah2omCUjTV9 xSV7rVDAANAgB2wy6fYBKBuntUZLT0Yiv20dy6g32uZVpssiBi2+wY/ERcWeFxDeI3Dq oPRLZY3LyDvAUJvydbRLwuDzhkSNE93bNmLYQF5siSH2mzcTjyjnFdd1SjLwULWaiYi1 2SR+R/yfk1nPJ5+YCRUXY/wTth8KzHklJiKz/FsBonQDjNKPJ77uPxsJq08Nw56XohCA sbrw== 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 :content-transfer-encoding:from:dkim-signature; bh=50g/nuapwurX1pOltfbe64PE1kzgbfYiLw1L7Uq4rxw=; b=oATjZ+48zx+go7Fa+gYJrFS/h7D4YtOZLy7RXBnkbPX1nmBwqMnTcRDONnCUzpIlGC 2LBRBPRY+JAkZL9+/nCKI7EVYDP6DG3dW3unKbIKzDeA0kD/7nBxKJC/9O5SDM4lZtbi GK9pQeadwLphnLEWwa7eoAOLgiCTKMfcWeTR8on5csUgzNx2vlSr4bZi1BidJ8w4/TDW IAzUM0WElraV1S390gZ5/6pJI1hXmCeL2l0fWX0DRGdoiRgUNCPeaeajfqbNOK7xjGTx 1ugGP32WP9WZPgRK8zVKcFGslpoMpxdW63OywLYl9PAHL7CjXwQ/Q0cJSrtPZshcqWGS SUcg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lgwl77HC; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::430 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-pf1-x430.google.com (mail-pf1-x430.google.com. [2607:f8b0:4864:20::430]) by gmr-mx.google.com with ESMTPS id h8-20020a5d80c8000000b006e02ea7519csi3196684ior.4.2023.01.17.19.54.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 19:54:28 -0800 (PST) Received-SPF: pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::430 as permitted sender) client-ip=2607:f8b0:4864:20::430; Original-Received: by mail-pf1-x430.google.com with SMTP id c85so21902640pfc.8 for ; Tue, 17 Jan 2023 19:54:28 -0800 (PST) X-Received: by 2002:a05:6a00:3390:b0:58c:6ba1:58dd with SMTP id cm16-20020a056a00339000b0058c6ba158ddmr6218563pfb.11.1674014067158; Tue, 17 Jan 2023 19:54:27 -0800 (PST) Original-Received: from smtpclient.apple ([2601:644:4780:3350:2d7d:6e83:304f:7f3d]) by smtp.gmail.com with ESMTPSA id x186-20020a6231c3000000b0058bcb42dd1asm6511273pfx.111.2023.01.17.19.54.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2023 19:54:26 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) 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=lgwl77HC; spf=pass (google.com: domain of fiddlosopher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2607:f8b0:4864:20::430 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:32009 Archived-At: Yes, if the markdown source includes the macro definitions, the macros in m= ath will be expanded by the parser. > On Jan 17, 2023, at 4:50 PM, bapt a wrote: >=20 > I see, thanks. If I'm understanding this correctly, pandoc already perfor= ms such macro expansions (for non-latex output), so the only thing preventi= ng 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://g= ithub.com/quarto-dev/quarto-cli/discussions/1045). > It's therefore more of a Quarto feature, to make sure the macros are copi= ed over with each chapter, but there's no need for an elaborate filter to i= mplement this. >=20 > Many thanks, >=20 > baptiste >=20 >=20 >=20 > 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. >=20 > pandoc -f latex -t native > \newcommand{\pie}{\pi} > $\pie^2$ > ^D > [ Para [ Math InlineMath "\\pi^2" ] ] >=20 >> 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 macro= s (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document b= efore rendering it.=20 >> For example, with Quarto being used to produce a book in both pdf and ht= ml formats, the macros stored in a file `_macros.tex` are processed differe= ntly 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 boo= k/website).=20 >>=20 >> An alternative that sounds quite robust would be to run something like d= e-macro (https://www.ctan.org/tex-archive/support/de-macro) on the source d= ocument before it is rendered: the macros are still used for convenience of= writing in the input file, but they get expanded explicitly before LaTeX o= r Mathjax is asked to render. >>=20 >> Unfortunately, de-macro is a Python script, and might be a little fragil= e as it processes whole documents with regex. I wonder if achieving the sam= e thing would be easier with a Lua filter in pandoc? Presumably, having alr= eady all the equations isolated in the AST makes life a bit easier, and I b= elieve there is already a mechanism in pandoc to process and expand `\newco= mmand` directives for non-latex output. Is this mechanism available to a Lu= a 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 Group= s "pandoc-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send a= n email to pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit https://groups.google.com/d/msg= id/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com. >=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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgi= d/pandoc-discuss/b1e37c1b-8529-4374-b16c-bfc8f0e44213n%40googlegroups.com. --=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/8FE474B9-67DE-4F0A-96FF-8DB5B522133D%40gmail.com.