From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/33207 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Guillaume Dehaene Newsgroups: gmane.text.pandoc Subject: Re: User story: typst multiline math in pandoc markdown and pandoc AST Date: Fri, 20 Oct 2023 00:40:16 -0700 (PDT) Message-ID: References: <672a5917-b04d-4eb9-966d-75b54df97837n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_1323_1839782527.1697787616615" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34134"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBC7JVCW5SUMBBYO5ZCUQMGQEOKRICPA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Fri Oct 20 09:40:21 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oa1-f63.google.com ([209.85.160.63]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1qtk7J-0008fR-8W for gtp-pandoc-discuss@m.gmane-mx.org; Fri, 20 Oct 2023 09:40:21 +0200 Original-Received: by mail-oa1-f63.google.com with SMTP id 586e51a60fabf-1e9adea7a4csf830788fac.3 for ; Fri, 20 Oct 2023 00:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1697787620; x=1698392420; 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:references:in-reply-to:message-id:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=66VCfDCmlYyp5XXbEXRTZPA4wFLktG+ZVMcwN6e/n7s=; b=urOGQf7l8N0mh1STKO5cpvIFiJ1IfyPAMgEBtJjCcUEht2q9Kv2noxHFqDQ+6iaZrs z9CVwzqJS3X2O860807aGW70pg4sm0iTzl4np4YKxiYPeb71LuJ27v9XGYmg/nvn4Yym XI2ibw3ksQucwHdSimBrtF6NpAGP7HE0R4ZH74ciTxNNtnMDQik+WDZ9HoIOuUgQDMDd NkxhX252nOpZGAFr+G1van/6vf56GlnWbNXkrPflqe/EJcTw+PzLEanfRkyDEgq6v68n OVWIyJtB77Edq12OTQxPnGw3S3Ou+WJNT0g33p4d2RPfvo+gbOrPmHbkz2JH8y/r6cWW oenA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697787620; x=1698392420; 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:references:in-reply-to:message-id:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=66VCfDCmlYyp5XXbEXRTZPA4wFLktG+ZVMcwN6e/n7s=; b=XEJEfBVrquj9+UR1bGcE+06vGsQ+W5iN+LlEibdegKvCYQO6Jw78DRUQ2P/Gghq7q3 WjBrHkJ5jfV8952np7tjdJhoEGPAL+K0dYtduVJE1+Nrz0d5SepAiT/7hMmhWIAlQhP1 kwk6elJGA8bKYJe5Z3EqcSBNtwNFEf0ZXJ59nw9ZHL6xvRtAQLQ82/ePaJHxqvAiedWY JZQFfhJ7n23vidIbozFTsmvj5U1p6YAyyTa1KwdjvcuAOAwwPmxFD6eKG37W0VeszMBu KEW5x/EgI3YlbK3FpUt97Q5gqWGCnuDQ2Yj3uqaJ3Peb9obKTdjYXD28HrMNuyHICeka ZHSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697787620; x=1698392420; 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-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=66VCfDCmlYyp5XXbEXRTZPA4wFLktG+ZVMcwN6e/n7s=; b=IBw9joMPz4qqlJZH7HPw9JNSSwOKM10iFoY7wWltus1oLV4kMop0qw7KXJU1N+H37N cgeX6oX1ky4jqb2qLH8PBqqehw4OBvnv6o8bkUZjZH3DoazbhOnGbBU3nItOBIlnW/rN 3djg+R2SlG1vFK4aEpPTW6pvbecDq9GnNwKJzZ8flFkrIixcNMP2N07Cf/8QZ5/y9mCB H1/49/2vecACbLMm60NBRfgQOC+TRu0j1rAAJtlqMH48EeqhJEx2ssAtmifPtPcLBQje C2K8FFM2ut/tIjHhWZwMRi6ExQAwFTHqUM+8GErO99t9G/b2vB Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOJu0YzBy5/uWc5UFqfQ2Y6vw+PyxtHDuJKMj4VXplut/T3C3H0BudGR 2Z2O/LNHqtj3RqAR9UWgsSw= X-Google-Smtp-Source: AGHT+IHU9x7pZ8HFyCoepCde0S6AAChtYEe9Vb+uRHaxFV2RTe6gMKU4M79n6BUjE0zW/pCX4Wu+0g== X-Received: by 2002:a05:6870:1148:b0:1ea:eed:fd02 with SMTP id 8-20020a056870114800b001ea0eedfd02mr1029500oag.45.1697787620166; Fri, 20 Oct 2023 00:40:20 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:ed96:b0:1ba:cb89:5d4f with SMTP id fz22-20020a056870ed9600b001bacb895d4fls1589915oab.1.-pod-prod-09-us; Fri, 20 Oct 2023 00:40:17 -0700 (PDT) X-Received: by 2002:a05:6871:5c7:b0:1e9:9e47:9555 with SMTP id v7-20020a05687105c700b001e99e479555mr545419oan.11.1697787617339; Fri, 20 Oct 2023 00:40:17 -0700 (PDT) In-Reply-To: X-Original-Sender: guillaume.dehaene-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:33207 Archived-At: ------=_Part_1323_1839782527.1697787616615 Content-Type: multipart/alternative; boundary="----=_Part_1324_608169431.1697787616615" ------=_Part_1324_608169431.1697787616615 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you for your insight. 1. I'm not 100% satisfied with your solution since it does not work with=20 latex environments which open math-mode (such as a align). These produce=20 errors because of the double-opening of math-mode. It's also pretty=20 cumbersome compared to usual md. I see that this is how pandoc parses typst equations (I should have looked!= ) [ Math DisplayMath "\\begin{aligned}\n1 + 1 & =3D 2 \\\\\n1 + 1 & =3D=20 2\n\\end{aligned}" ] Is that now going to be the accepted format for multiline equations? 2. I had overlooked the possibility of writing a filter. The principle of the filter would then be: parse DisplayMath if there are & and/or \\ present, modify the block depending on writer: - latex, HTML: transform to align - everything else: transform to accepted format(??) \begin{aligned} Is that correct? If so, I'll start hacking at it in the near future. Best regards, Guillaume On Thursday, October 19, 2023 at 6:11:41=E2=80=AFPM UTC+2 John MacFarlane w= rote: > > Pandoc provides a solution for almost all of these. The only issue is= =20 > multi-line equations. > > A work-around I am aware of is to just use raw latex code like: > > ```latex > > \begin{align} > > 1 + 1 &=3D 2 \label{first_line} \\ > > 1 + 2 &=3D 3 \label{second_line} > > \end{align} > > ``` > > which works fine when exporting to both HTML and latex: it is added as= =20 > is to the HTML where it is parsed by both mathjax and katex. > > Note that there's another way to do this that will create a native Math= =20 > element in pandoc: > > $$ > \begin{aligned} > 1 + 1 &=3D 2 \\ > 1 + 2 &=3D 3 > \end{aligned} > $$ > > > > However, I propose that formatting equations like typst might be a good= =20 > way to make multiline math native to Pandoc, instead of piggy-backing on= =20 > raw latex. > >=20 > > Multiline equations could be written as in latex, wrapped in `$$ $$`: > > ``` > > $$ > > 1 + 1 &=3D 2 \\ > > 1 + 2 &=3D 3=20 > > $$ > > ``` > >=20 > > which could be parsed as a new DisplayMathMultiline type in the AST. > > (This is a mockup: I really don't understand how the AST is written) > > ``` > > [ Math DisplayMathMultiline > > [ > > Math DisplayMathLine ["1+1", "=3D2"] > > Math DisplayMathLine ["1+2", "=3D3"] > > ] > > ] > > ``` > >=20 > > This type can be written to: > > - HTML and latex: as an `align` block > > - typst: as a multiline math block > > - pandoc markdown: as a multiline math block > > - other: as multiple successive displayMath blocks > >=20 > > I do not see how modifying the AST in this way would produce an issue:= =20 > it's an additive feature as far as I can tell. > > Any change to our algebraic data types is a breaking change that would=20 > require modifications throughout the ecosystem (all writers and readers,= =20 > filters, etc.). That's why we're very conservative about such changes and= =20 > make them infrequently and only with very strong reasons. > > I suppose one possibility would be to parse this syntax into > > \begin{aligned} > 1 + 1 &=3D 2 \\ > 1 + 2 &=3D 3 > \end{aligned} > > which should work with all the formats you mention... > > You could even create a filter that does this, without changes to pandoc= =20 > itself. > > > --=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/daaf510b-50a3-4f9d-b7d5-58609d3821c6n%40googlegroups.com. ------=_Part_1324_608169431.1697787616615 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you for your insight.

1. I'm not 100% sati= sfied with your solution since it does not work with latex environments whi= ch open math-mode (such as a align). These produce errors because of the do= uble-opening of math-mode. It's also pretty cumbersome compared to usual md= .

I see that this is how pandoc parses typst equ= ations (I should have looked!)
= [ Math
Disp= layMath "\\begin{aligned}\n1 + 1 & =3D 2 \\\\\n1 + 1 & =3D 2\n\\end= {aligned}" ]
Is that now going to be the accepted format fo= r multiline equations?

2. I had overlooked the p= ossibility of writing a filter.
The principle of the filter would then= be:

parse DisplayMath
if there are &a= mp; and/or \\ present, modify the block
depending on writer:
- latex, HTML: transform to align
- everything else: transf= orm to accepted format(??) \begin{aligned}

Is th= at correct? If so, I'll start hacking at it in the near future.
<= br />
Best regards,
Guillaume
On Thursday, October 19, 2023= at 6:11:41=E2=80=AFPM UTC+2 John MacFarlane wrote:
> Pandoc provides a solution for = almost all of these. The only issue is multi-line equations.
> A work-around I am aware of is to just use raw latex code like:
> ```latex
> \begin{align}
> 1 + 1 &=3D 2 \label{first_line} \\
> 1 + 2 &=3D 3 \label{second_line}
> \end{align}
> ```
> which works fine when exporting to both HTML and latex: it is adde= d as is to the HTML where it is parsed by both mathjax and katex.

Note that there's another way to do this that will create a native = Math element in pandoc:

$$
\begin{aligned}
1 + 1 &=3D 2 \\
1 + 2 &=3D 3
\end{aligned}
$$


> However, I propose that formatting equations like typst might be a= good way to make multiline math native to Pandoc, instead of piggy-backing= on raw latex.
>=20
> Multiline equations could be written as in latex, wrapped in `$$ $= $`:
> ```
> $$
> 1 + 1 &=3D 2 \\
> 1 + 2 &=3D 3=20
> $$
> ```
>=20
> which could be parsed as a new DisplayMathMultiline type in the AS= T.
> (This is a mockup: I really don't understand how the AST is wr= itten)
> ```
> [ Math DisplayMathMultiline
> [
> Math DisplayMathLine ["1+1", "=3D2"]
> Math DisplayMathLine ["1+2", "=3D3"]
> ]
> ]
> ```
>=20
> This type can be written to:
> - HTML and latex: as an `align` block
> - typst: as a multiline math block
> - pandoc markdown: as a multiline math block
> - other: as multiple successive displayMath blocks
>=20
> I do not see how modifying the AST in this way would produce an is= sue: it's an additive feature as far as I can tell.

Any change to our algebraic data types is a breaking change that would = require modifications throughout the ecosystem (all writers and readers, fi= lters, etc.). That's why we're very conservative about such change= s and make them infrequently and only with very strong reasons.

I suppose one possibility would be to parse this syntax into

\begin{aligned}
1 + 1 &=3D 2 \\
1 + 2 &=3D 3
\end{aligned}

which should work with all the formats you mention...

You could even create a filter that does this, without changes to pand= oc itself.


--
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/daaf510b-50a3-4f9d-b7d5-58609d3821c6n%40googlegroups.= com.
------=_Part_1324_608169431.1697787616615-- ------=_Part_1323_1839782527.1697787616615--