This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-05
Channels
- # announcements (1)
- # babashka (61)
- # babashka-sci-dev (1)
- # beginners (54)
- # biff (17)
- # cider (4)
- # circleci (1)
- # clj-commons (39)
- # clj-kondo (26)
- # cljdoc (40)
- # clojure (41)
- # clojure-europe (32)
- # clojure-norway (4)
- # clojure-portugal (1)
- # clojure-uk (2)
- # clojurescript (59)
- # clr (69)
- # conjure (7)
- # cursive (22)
- # data-science (16)
- # datalevin (1)
- # datomic (19)
- # docker (31)
- # funcool (1)
- # honeysql (6)
- # hoplon (1)
- # hyperfiddle (41)
- # introduce-yourself (1)
- # juxt (2)
- # leiningen (5)
- # nbb (14)
- # nextjournal (38)
- # off-topic (47)
- # polylith (2)
- # rdf (5)
- # re-frame (4)
- # reitit (27)
- # releases (6)
- # scittle (10)
- # shadow-cljs (24)
- # sql (11)
- # squint (1)
- # tools-build (33)
- # tree-sitter (4)
- # vim (39)
I'm trying the nextjournal markdown component. Has anyone had any luck getting LaTeX formulae to render?
Hi @U07VBK5CJ nextjournal markdown is more about the document data structure, but has also a transformation layer into hiccup (which can be used both on clj and on cljs) which can be customized on a node-type based, this should be explained in the README: https://nextjournal.github.io/markdown/#/README.md
Hi @andrea712 - thank you for your reply. I did check the readme, but I was confused since it says "we parse LaTeX formulas", but I never saw any rendering being done at all, and of course LaTeX wasn't being parsed - the delimited blocks were just skipped. Other things that contributed to my confusion: • there's a direct dependency on markdown-it-texmath (leading me to believe it should be using it) • the "try it online" link in the github repo links to something that does render LaTeX markup, but there's a layer of code added to make it do so Anyway, I appreciate the help, and I do have it working now. I just didn't understand whether what I was seeing was correct behavior - it was - and wasn't sure exactly how to get what I wanted. At the very bottom of the linked README page, the example showing the transform with augmented hiccup renderers eventually got me there, along with the source code to the clerk viewer.
right, the built-in hiccup renderers in the markdown library are pretty basic and the demo uses components from yet another library (which will probably be deprecated in the future) https://github.com/nextjournal/viewers/blob/main/modules/viewer/src/nextjournal/viewer/markdown.cljs#L25-L41 and it’s not mentioned in the try notebook. So it’s probably truly confusing. The markdown-it-texmath is used as a markdown-it plugin for the parsing side, but not for rendering. We’re not using markdown-it for rendering html. Glad, you got it working in the end.
The documentation is a little sparse on this matter, unless there's something I'm missing.
The component is clearly detecting $
and $$
but I don't see any actual rendered math. Maybe there's some preamble I'm missing ...
I think I need to not just pass the hiccup to reagent, but to one of their renderers.
I see that clerk has some extra render-katex
and render-mathjax
stuff that was of course never mentioned in the markdown library.
I'm still trying to figure out how to make it work. I'll try to be as helpful as I can with feedback afterwards.
Yes, that's just difficult to understand given that the library does depend on markdown-it-texmath and indirectly on katex, and the "demo" is a demo using clerk, so of course it works with formulae. So I assumed it would be a bit more batteries included, but that is my mistake.
I was just trying to evaluate if it would be easier to use this markdown library instead of what I've done up util now, which is to use markdown-clj
and integrate with MathJax directly.
I just need to understand the viewer
code a little better (heh, maybe a lot better) in clerk and then that should provide me everything I need, I think.
@andrea712 is just out for lunch
Sorry, and to answer your question directly - I want to render it in a browser. Like, have markdown which defines a document with embedded formulae.
I have that working now in markdown-clj, and it seems like it will be easy with the nextjournal library as well. I just have to learn it a bit better.
so https://github.com/nextjournal/markdown/blob/main/src/nextjournal/markdown/transform.cljc#L87-L89 are the default formula -> hiccup renderers
What I'm puzzling through now is clerk's viewers and in particular where in the pipeline we get to :nextjournal.markdown/formula
...
I'm looking at the very nice parse tree coming out of the library, but it doesn't consist of namespaced keywords for the different categories, but rather just outputs :formula
(or :block-formula
or whatever).
I would expect namespaced keywords because they are present in this snippet from clerk's viewer:
;; formulas
{:name :nextjournal.markdown/formula
:transform-fn (comp :text ->value)
:render-fn '(fn [tex] (nextjournal.clerk.render/render-katex tex {:inline? true}))}
{:name :nextjournal.markdown/block-formula
:transform-fn (comp :text ->value)
:render-fn 'nextjournal.clerk.render/render-katex}
But I think that's related to what you just linked to, so I just have to wrap my head around it a bit more.
I think maybe if I add that katex
handling to md.transform/default-hiccup-renderers
that will work?
Ok - thank you for all your help. I need to digest this and give it a go and hopefully I will get it working.