* custom writer to Excalidraw? @ 2023-01-26 7:59 bapt a [not found] ` <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 2+ messages in thread From: bapt a @ 2023-01-26 7:59 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 5111 bytes --] 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/63e0951a-4e4c-45b9-8656-0b1d9bd069f6n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 17284 bytes --] [-- Attachment #2: Screenshot 2023-01-26 at 20.34.57.png --] [-- Type: image/png, Size: 36877 bytes --] ^ permalink raw reply [flat|nested] 2+ messages in thread
[parent not found: <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: custom writer to Excalidraw? [not found] ` <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2023-01-29 21:55 ` bapt a 0 siblings, 0 replies; 2+ messages in thread From: bapt a @ 2023-01-29 21:55 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 5906 bytes --] 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. [-- Attachment #1.2: Type: text/html, Size: 20319 bytes --] ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-29 21:55 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-01-26 7:59 custom writer to Excalidraw? bapt a [not found] ` <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2023-01-29 21:55 ` bapt a
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).