From: bapt a <auguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: custom writer to Excalidraw?
Date: Wed, 25 Jan 2023 23:59:16 -0800 (PST) [thread overview]
Message-ID: <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n@googlegroups.com> (raw)
[-- 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 --]
next reply other threads:[~2023-01-26 7:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-26 7:59 bapt a [this message]
[not found] ` <63e0951a-4e4c-45b9-8656-0b1d9bd069f6n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-29 21:55 ` bapt a
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=63e0951a-4e4c-45b9-8656-0b1d9bd069f6n@googlegroups.com \
--to=auguieba-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).