pietroppeter / nimib

nimib 🐳 - nim 👑 driven ⛵ publishing ✍
https://pietroppeter.github.io/nimib/
MIT License
182 stars 10 forks source link

LatexDSL integration #128

Open HugoGranstrom opened 2 years ago

HugoGranstrom commented 2 years ago

Inspired by nimiSlide forum post it would be nice if we could somehow allow the user to write latex using LatexDSL instead of writing it in a string. It would allow CT errors among other things. LatexDSL returns a string, so the easiest thing to try would be to just let Katex render it for us and hope it works. I haven't tried it out yet though.

pietroppeter commented 2 years ago

We use Katex mostly for equations, not sure if it supports also other elements like theorems and similar.

And I do not know if LatexDSL supports a particular api for stuff that usually ends up in an equation (stuff like \frac{1}{2} or \sin or similar).

So on the specific topic of this, not sure what would be the advantages.

On the general topic of latex, two evolutions I see are:

HugoGranstrom commented 2 years ago

OK yeah Latex is HUUUGE and Katex is only supporting a small subset of those. It would be hard to list everything it supports and prevent users from using unsupported features. But still, if you keep to the supported features of Katex, using LatexDSL would allow you to get meaningful compile-time errors instead of bad runtime errors as you described. So I still see potential for this, just that we must be very clear that they can only use the Katex-subset of features.

add a latex backend to be able to publish an article as both latex and html. This is actually a main target use case for backend refactoring that should come in 0.4. This in principle could use latexDSL in the implementation.

I only really see it useful for inlining Latex here, kinda like nbRawOutput allows us to inline HTML. Have you thought of any other use-cases there`

add a latex equation processor that works when rendering the document. It is a pity we leave to do that in JavaScript when it could be done earlier. Also it could able to manage errors better (I recently had an example where katex for some reason was not recognizing latex content and I did not receive any warning). An idea I had to have something easy to implement would be to try to use the Nim wrapper of duktape (a js minimal engine) to see if we can access katex from C code (and we might be able to handle better error messages).

Yeah the best thing would be a Nim Latex compiler similar to nim-markdown, but that seems like a very big undertaking. Duktape does sound really exciting though. Does sound like quite a bit of work as well, the wrapper seems quite low-level.

Vindaar commented 2 years ago

Just very quickly (we can discuss in more detail one of these days):

Given that KaTeX is very restrictive, that's actually a positive: it allows us to define a custom set of operations in the set of commands (https://github.com/Vindaar/LatexDSL/blob/master/src/latexdsl/valid_tex_commands.nim ; I have a version I still need to push that allows to essentially use a custom enum).

Also LatexDSL does not necessarily have to produce a runtime string. It can also generate a CT string!

HugoGranstrom commented 2 years ago

Ahh, that rings a bell somewhere back in my head :o It's still a lot of keywords still though :rofl: But I guess we could write a scraper to find them all from their website.

Also LatexDSL does not necessarily have to produce a runtime string. It can also generate a CT string!

Wow, didn't know :O That should speed-up templates with LatexDSL in them by a few % :sunglasses: