From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/32109 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: bapt a Newsgroups: gmane.text.pandoc Subject: Re: custom writer to Excalidraw? Date: Sun, 29 Jan 2023 13:55:27 -0800 (PST) Message-ID: <0a3ce059-8b1b-4e51-9818-adeeb25527aan@googlegroups.com> References: <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5174_466867795.1675029327244" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26698"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDG3FYUYQUCBBUGW3OPAMGQEV7IM25Q-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sun Jan 29 22:55:32 2023 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oo1-f57.google.com ([209.85.161.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pMFe8-0006iv-6l for gtp-pandoc-discuss@m.gmane-mx.org; Sun, 29 Jan 2023 22:55:32 +0100 Original-Received: by mail-oo1-f57.google.com with SMTP id n65-20020a4a5344000000b005174a86ea9csf365078oob.23 for ; Sun, 29 Jan 2023 13:55:32 -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=PiEnvD8dHAfBk0U7OQYYprOnsT4AVVwf8j7SbTB/qnk=; b=IfPNwX7QRTJ5Y0zfuWLii61ndQttGl+PYjFGBI8SpvUN0HHs1GaevC6k77XfMBfvHC 7TcXYCgcTExPK2gF0ogV+hqsbBoAvN1P0sQsypQLHLs0eTnG344tHt8KSfwQ89lcYs+n bqccNV5HYTIVfZJwXQwrCXb/+aPQj6udv4tnsJmSUGO8nyRxWxIbRLwmCMmJqgLcJsvE jRwWRdY2QeoijLqfdkAZTiwb7e8sGy9EaN5iHkiRxRQnYZISvPbcjbJCXyFNzAGY3LRF KGtJlWKfNnCdiITfA292HjZxXbiGRY0eUdkfiIRBqFZziBPqEcxwgWm4/WMjxsAtCszL zrSw== 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=PiEnvD8dHAfBk0U7OQYYprOnsT4AVVwf8j7SbTB/qnk=; b=FFUwkujbGaWL2vzvK7hAdOITyWuyU8j3/YqEVWFvVUpvtheGn0xBpBYj6iw6uGpBut 2/3dNDMWj2we1Mr7pJJgUadDqNPp80Gv44hs0P9rVECC2G7wL6qB7ucdMCN4DNr85/ex Anu9poNPwbnFoBt+DHxc8OSqENsbX+ifJr8PCuir+7YViwZvEaDRN2annUSDoyG36ksz kTy6yx5cD1ahTpV3wD+zWFwE2XwFFSI/9AyJsDEu65ysu/25wuGG7HDD10BEGCoyWGwX RSSwZWHEZIr+O9jq6L3Nyjs2VfXB8GlhVWD2kiOCP2ZgT/JMiGiKRxOhSxwIqeBYbvVw 7pWg== 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=PiEnvD8dHAfBk0U7OQYYprOnsT4AVVwf8j7SbTB/qnk=; b=i//GVuHcGytoYSxnCBohifGrQVWiXmP7J/OLhX+o1FoDq0Bif6uYEmuEbI6oHddWct K4kIj0NsHeg9x3JlyH5JNRiphOX9PwMuXytj1Mjvu5HPnR0IVJedLDzZOWL21Cz2L99K dzG0+zGGo+fExtTNwQ2AnQ88N+7kR7sx9RM4r5eStzyNGRK2YqO+xPmgBTCQl7grHqPI 59GQ9IgGGZyLptzZuQgSQFWVP38Ztu2vSxfc09NMxgcO/rCn2m+dwZ5B9Cry3HwW4Was 3cQlo/GhsNypmfnx+11Vg1KadY0/Zz2yglwvzMHcY9VKm/6uZPK2HDFYXF7BAMBAYe+p MTvA== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AO0yUKXOPsZCnqu69Juu84mOjBhgZcxz8fh+D6fP054TkYTieoUc0RhF cQZ6XWFYpBs8pfS86xJSUz0= X-Google-Smtp-Source: AK7set/mVTcQ3za1Nos75KVX8P/AM5sHHtnW4Jt0E5PCY3hAEV6h1aJUlvpKX1e37LuDKOEai2if3A== X-Received: by 2002:aca:b354:0:b0:378:70f:bbd3 with SMTP id c81-20020acab354000000b00378070fbbd3mr358524oif.40.1675029331061; Sun, 29 Jan 2023 13:55:31 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6870:5687:b0:150:4546:6415 with SMTP id p7-20020a056870568700b0015045466415ls4478683oao.11.-pod-prod-gmail; Sun, 29 Jan 2023 13:55:28 -0800 (PST) X-Received: by 2002:a05:6870:3842:b0:144:6d8b:c318 with SMTP id z2-20020a056870384200b001446d8bc318mr3452013oal.98.1675029327975; Sun, 29 Jan 2023 13:55:27 -0800 (PST) In-Reply-To: <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@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:32109 Archived-At: ------=_Part_5174_466867795.1675029327244 Content-Type: multipart/alternative; boundary="----=_Part_5175_87263262.1675029327244" ------=_Part_5175_87263262.1675029327244 Content-Type: text/plain; charset="UTF-8" For anyone curious about this, I've updated the R scripts and detailed a bit more my workflow at https://tinyurl.com/ba-quarto-excalidraw (with example at https://github.com/baptiste/quarto-excalidraw/) The retrieval of bounding boxes from Mathjax-produced SVGs is a slight complication, but it's optional (the boxes will refresh when re-rendered by Mathjax in Excalidraw). Best, baptiste On Thursday, 26 January 2023 at 20:59:17 UTC+13 bapt a wrote: > Hi, > > I'd like to extract all math equations from my lecture notes (and > potentially images too, at some stage) and produce a json file suitable for > Excalidraw, so that students could reorganise them, sketch notes > collaboratively, etc.: > > https://math.preview.excalidraw.com/ > > [image: Screenshot 2023-01-26 at 20.34.57.png] > > (note that this is using a user-contributed extension*; the plain version > of Excalidraw does not support Mathjax or Asciimath). > > From an equation like this in the source document (beamer tex): > > ``` > \[\begin{aligned} > \nabla\cdot\mathbf{D}&= \rho_f\\ > \nabla\cdot\mathbf{B}&= 0\\ > \nabla\times\mathbf{E}&= -\frac{\partial\mathbf{B}}{\partial t}\\ > \nabla\times\mathbf{H}&= \frac{\partial\mathbf{D}}{\partial t} + > \mathbf{J}_f > \end{aligned}\] > ``` > > the full json file suitable for import in Excalidraw looks like: > > ``` > { > "type": "excalidraw", > "version": 2, > "source": "https://math.preview.excalidraw.com", > "elements": [ > { > "type": "text", > "version": 104, > "versionNonce": 669974443, > "isDeleted": false, > "id": "iL0y7olLhWzLKVTzIffR1", > "fillStyle": "hachure", > "strokeWidth": 1, > "strokeStyle": "solid", > "roughness": 1, > "opacity": 100, > "angle": 0, > "x": 418, > "y": -186, > "strokeColor": "#000000", > "backgroundColor": "transparent", > "width": 202, > "height": 169, > "seed": 1021462275, > "groupIds": [], > "roundness": null, > "boundElements": [], > "updated": 1674718443076, > "link": null, > "locked": false, > "subtype": "math", > "customData": { > "useTex": true, > "mathOnly": true, > "ariaLabel": "\\begin{aligned} \\nabla\\cdot\\mathbf{D}&= \\rho_f\\\\ \\ > nabla\\cdot\\mathbf{B}&= 0\\\\ \\nabla\\times\\mathbf{E}&= -\\frac{\\ > partial\\mathbf{B}}{\\partial t}\\\\ \\nabla\\times\\mathbf{H}&= \\frac{\\ > partial\\mathbf{D}}{\\partial t} + \\mathbf{J}_f \\end{aligned}" > }, > "fontSize": 20, > "fontFamily": 2, > "text": "\\begin{aligned}\n\\nabla\\cdot\\mathbf{D}&= \\rho_f\\\\\n\\nabla > \\cdot\\mathbf{B}&= 0\\\\\n\\nabla\\times\\mathbf{E}&= -\\frac{\\partial\\ > mathbf{B}}{\\partial t}\\\\\n\\nabla\\times\\mathbf{H}&= \\frac{\\partial > \\mathbf{D}}{\\partial t} + \\mathbf{J}_f\n\\end{aligned}", > "baseline": 91, > "textAlign": "left", > "verticalAlign": "top", > "containerId": null, > "originalText": "\\begin{aligned}\n\\nabla\\cdot\\mathbf{D}&= \\rho_f > \\\\\n\\nabla\\cdot\\mathbf{B}&= 0\\\\\n\\nabla\\times\\mathbf{E}&= -\\ > frac{\\partial\\mathbf{B}}{\\partial t}\\\\\n\\nabla\\times\\mathbf{H}&= > \\frac{\\partial\\mathbf{D}}{\\partial t} + \\mathbf{J}_f\n\\end{aligned}" > }, > { > "type": "text", > "version": 111, > "versionNonce": 1291434347, > "isDeleted": false, > "id": "xzGehwC0igI1rh-jYddgb", > "fillStyle": "hachure", > "strokeWidth": 1, > "strokeStyle": "solid", > "roughness": 1, > "opacity": 100, > "angle": 0, > "x": 754, > "y": 32, > "strokeColor": "#000000", > "backgroundColor": "transparent", > "width": 194, > "height": 24, > "seed": 315800227, > "groupIds": [], > "roundness": null, > "boundElements": [], > "updated": 1674718439209, > "link": null, > "locked": false, > "subtype": "math", > "customData": { > "useTex": true, > "mathOnly": true, > "ariaLabel": "\\mathbf{F}= q\\left(\\mathbf{E}+ \\mathbf{v}\\times \\ > mathbf{B}\\right)" > }, > "fontSize": 20, > "fontFamily": 2, > "text": "\\mathbf{F}= q\\left(\\mathbf{E}+ \\mathbf{v}\\times \\mathbf{B} > \\right)", > "baseline": 18, > "textAlign": "left", > "verticalAlign": "top", > "containerId": null, > "originalText": "\\mathbf{F}= q\\left(\\mathbf{E}+ \\mathbf{v}\\times \\ > mathbf{B}\\right)" > } > ], > "appState": { > "gridSize": null, > "viewBackgroundColor": "#ffffff" > }, > "files": {} > } > ``` > > Obviously there isn't a one-to-one mapping between a typical input > document and what's possible or even desirable in a whiteboard context, but > for the limited scope of producing a bunch of equations automatically, it > would be very nice to have a pandoc writer. > > At the moment I'm using a lua filter someone kindly contributed on this > mailing list, to simply extract all maths from an input file, > > ``` > _ENV = pandoc > local math_elements = List{} > return { > -- first document pass > {Math = function (m) > > local comment = "math start" > math_elements:insert(comment) > math_elements:insert(m) > end}, > -- second document pass > {Pandoc = function (_) return Pandoc(math_elements:map(Plain)) end}, > } > ``` > > I then use a custom script (I wrote it in R since I'm more fluent in it) > to produce suitable json ( > https://github.com/baptiste/minixcali/blob/main/R/elements.R#L227) > > It works, but I feel this last step should really be implemented as a > custom Writer, especially if other people want to try this; unfortunately, > my lua skills are currently very limited. Any pointers / starter / > suggestions would be much appreciated! > > Best regards, > > baptiste > > > > *: fantastic work by user DanielJGeiger, > https://github.com/excalidraw/excalidraw/pull/6037 > -- 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/0a3ce059-8b1b-4e51-9818-adeeb25527aan%40googlegroups.com. ------=_Part_5175_87263262.1675029327244 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
For anyone curious about this, I've updated the R scripts and detailed= a bit more my workflow at https://tinyurl.com/ba-quarto-excalidraw (with e= xample at https://github.com/baptiste/quarto-excalidraw/)

<= /div>
The retrieval of bounding boxes from Mathjax-produced SVGs is a s= light complication, but it's optional (the boxes will refresh when re-rende= red by Mathjax in Excalidraw).

Best,
<= br />
baptiste

On Thursday, 26 January 2023 at 20:59:17 U= TC+13 bapt a wrote:
Hi,

I'd like to extract all math e= quations from my lecture notes (and potentially images too, at some stage) = and produce a json file suitable for Excalidraw, so that students could reo= rganise them, sketch notes collaboratively, etc.:

<= div>https://math.previ= ew.excalidraw.com/

3D"Screenshot

(note that this is using a user-contributed extension*; the plain ver= sion of Excalidraw does not support Mathjax or Asciimath).=C2=A0
=
From an equation like this in the source document (beamer te= x):

```
\[\begin{aligne= d}
\nabla\cdot\mathbf{D}&=3D \rho_f\\
\nabla\cdot\mathbf{B}&=3D 0\\
\nabla\times\mathbf{E}&=3D -\fr= ac{\partial\mathbf{B}}{\partial t}\\
\nabla\times= \mathbf{H}&=3D \frac{\partial\mathbf{D}}{\partial t} + \mathbf{J}_f<= /span>
\end{aligned}= \]
```

<= /span>
the full json file suitable for import in Excalidraw= looks like:

```<= /div>
{
<= span> "type": "excal= idraw",
"versi= on": 2,
"ele= ments": [
{
<= span> "type": "t= ext",
"ver= sion": 104,
"versionNonce": = 669974443,
"isD= eleted": false,
"id": "= iL0y7olLhWzLKVTzIffR1",
"fillStyle": "hachure&quo= t;,
"strokeWidt= h": 1,
= "strokeStyle": "= solid",
"r= oughness": 1,
= "opacity": 100= ,
"angle"<= /span>: 0,
"x": 418,=
"y": -186,
"stroke= Color": "#000000",
"backgroundColor"<= span>: "transparent",
= "width": 202,
"height": 169,
"seed": 1021462275,
"groupIds"<= span>: [],
"roundness"<= /span>: null,
= "boundElements": [],
<= span> "updated": 1674= 718443076,
"lin= k": null,
"locked": false,
"subtype": "math",
<= span> "customData": {
=
"useTex": true,
"mat= hOnly": true,
= "ariaLabel": "\\begin{aligned} \\nabla\\cdot\\mathbf{= D}&=3D \\rho_f\\\\ = \\nabla\\cdot\\mathbf{B}&=3D 0\\\\ = \\nabla\\times\\<= /span>mathbf{E}&=3D -\\frac{\\partial\\mathbf{B}}{\\partial t}\\\\ \\nabla\\times\\mathbf{H}&=3D \\frac{\\<= span>partial\\mathbf{D}}{\\partial t} + \\mathbf{J}_f \\end{aligned}"
},
"fontSize": 20,
"fontFamil= y": 2,
= "text": "= \\begin{aligned}\n\\nabla\\cdot\\mathbf{D}&=3D \\rho_f\\\\\n\\nabla\\cdot\\mathbf{B}&=3D 0<= /span>\\\\\n\\nabla\\times\\mathbf{E}&=3D -\\frac= {\\partial\\mathbf{B}}{= \\partial t}\\\\\n\\nab= la\\times\\mathbf{H}&am= p;=3D \\frac{\\partial<= /span>\\mathbf{D}}{\\partial t= } + \\mathbf{J}_f\n\\en= d{aligned}",
&q= uot;baseline": 91,
=
"textAlign": "left",
"verticalAlign": "top",
"containerId"= : null,
= "originalText": "\\begin{aligned}\n\\nabla<= /span>\\cdot\\mathbf{D}&= =3D \\rho_f\\\\\n\\nabl= a\\cdot\\mathbf{B}&= =3D 0\\\\\n\\nabla\\tim= es\\mathbf{E}&=3D -\\frac{\\partial\\mathb= f{B}}{\\partial t}\\\\\n\\nabla\\times\\mathbf= {H}&=3D \\frac{\\pa= rtial\\mathbf{D}}{\\par= tial t} + \\mathbf{J}_f\n\\end{aligned}"
},
{
"type": "text",
= "version": 111,
"versionNonce": 1291434347,
= "isDeleted": false,
"id"<= span>: "xzGehwC0igI1rh-jYddgb",<= /div>
"fillStyle": "hachure",
"strokeWidth": 1= ,
"strokeStyle"<= span>: "solid",
= "roughness": 1,
"opacity": 100,
"angle": 0,=
"x": 754,
"y"= : 32,
<= /span>"strokeColor": "#00000= 0",
"backg= roundColor": "transparent"<= span>,
"width": 194,
"height": 24,
"seed": 315800227,
"= groupIds": [],
= "roundness": null,<= /div>
"boundElements": = [],
"updated": 1674718439209,
= "link": null,=
"locked":= false,
"subtype": "math",
"customData"= : {
"useTex": true,
= "mathOnly": true,
"ariaLabel": "\\mathbf{F}=3D q\\left(\\mathbf{E}+ = \\mathbf{v}\\times \\mathbf{B}\\right)"
},
"fon= tSize": 20,
"fontFamily": 2<= /span>,
"text": "\\mathbf{F}=3D q\\left(\\mathbf{E}+ \\mathbf{v}\\times \\mathbf{B}\\right)"= ,
"baseline": 18,
"textAlign": "left",
"verticalAlign&q= uot;: "top",
<= div> "containerId": <= span>null
,
"ori= ginalText": "\\mathbf{F}=3D q\\left(\\mathbf{E}+ \\mathbf{v}\\times \\mathbf{B}\\r= ight)"
}
],=
"appState": {=
"gridSize": null,
"vie= wBackgroundColor": "#ffffff"
},
"files&qu= ot;: {}
}
```

Obviously there isn't a one-to-one mapping between a typical input d= ocument and what's possible or even desirable in a whiteboard context, = but for the limited scope of producing a bunch of equations automatically, = it would be very nice to have a pandoc writer.
=
At the moment I'm using a lua filter someon= e kindly contributed on this mailing list, to simply extract all maths from= an input file,

```=
_ENV<= span> =3D pandoc
local math_elements =3D List{}
return {
-- first= document pass
{Math =3D <= /span>function (m)
local comment =3D "math start"
= math_elements:insert= (comment)
math_elements:insert(m= )
end},
-- second document pass
{<= span>Pandoc =3D function (_) return Pandoc(math_elements:map(Plain)) end},
}
```

I then use a custom script (I= wrote it in R since I'm more fluent in it) to produce suitable json (<= a href=3D"https://github.com/baptiste/minixcali/blob/main/R/elements.R#L227= " target=3D"_blank" rel=3D"nofollow" data-saferedirecturl=3D"https://www.go= ogle.com/url?hl=3Den-GB&q=3Dhttps://github.com/baptiste/minixcali/blob/= main/R/elements.R%23L227&source=3Dgmail&ust=3D1675115167696000&= usg=3DAOvVaw0bRhEfP7FwhA3Hb-Mf8p2H">https://github.com/baptiste/minixcali/b= lob/main/R/elements.R#L227)

=
It works, but I feel this last step= should really be implemented as a custom Writer, especially if other peopl= e want to try this; unfortunately, my lua skills are currently very limited= . Any pointers / starter / suggestions would be much appreciated!

B= est regards,

baptiste



*: fantastic work by user DanielJGeiger, https://= github.com/excalidraw/excalidraw/pull/6037

--
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/0a3ce059-8b1b-4e51-9818-adeeb25527aan%40googlegroups.= com.
------=_Part_5175_87263262.1675029327244-- ------=_Part_5174_466867795.1675029327244--