@djblue does a LaTeX viewer exist yet, using https://katex.org/ or mathjax?
Not that I am aware of
Is this something you are interested in building?
Yeah Iβm going to give it a go and see if I can get something basic working
Awesome! Let me know if you run into any issues π
This is close @djblue
(ns emmy.portal.tex
(:require ["katex" :as k]
[portal.ui.api :as p]))
(defn tex [text]
[:span
{:dangerouslySetInnerHTML
{:__html
(.renderToString katex text
#js {:throwOnError false
:displayMode true})}}])
(p/register-viewer!
{:name :emmy.portal/tex
:component tex
:predicate (constantly true)})
and then load via
(-> (io/resource "emmy/portal/tex.cljs")
(slurp)
(p/eval-str))I think an issue you might run into is that strings don't support metadata π€
yes for sure
that stops me from sending a default, but once this is working I can render Emmy expressions (which carry metadata) this way with the rpc call approach
that works but weirdly keeps the original text in there too
Any errors in the console?
I bet Iβm missing some CSS like last time
no errors, but the second form is katex-html and has that aria-hidden true flag
there we go, works with css
I'm really happy the npm integration is just working awesome
itβs amazing
so either we require npm install katex here or inject the JS into the header
Are you saying for downstream users?
Yeah thatβs right
Yeah, I think those two work for now π I think in the future it might be cool if npm deps (only the modules your code needs) could be embedded into your jar π€ Users wouldn't need npm or be connected to the internet after the jar is downloaded
That plus something like self-hosted cljs or cherryjs and most of Portal itself becomes an extension to some minimal bootstrap code to get everything kicked off
For example here is Portal hosting (via sci) another completely unrelated project I did π
portal as a TeX REPL:
@djblue one thing that WOULD be nice would be to be able to specify default viewers for some type like emmy.expression/Literal without having the instances having to carry around metadata. can I do that somehow?
configure some list of predicate => default?
Currently, the easiest place to do something like this is via a custom submit function. Does that type live on the jvm or js?
on the JVM
will custom submit cause problems for something like Clojure Notebooks?
https://cljdoc.org/d/djblue/portal/0.41.0/doc/guides/default-viewer
Yeah, this wouldn't work with clojure notebooks. However, I'm open to adding extension points, just not sure what they are yet.
I guess by βcause problemsβ I mean, is there a way to specify that clojure notebooks should use my custom submit function
π
I guess we want something like middleware on the JVM side
Iβve got to run for now but this was great, and so easy to add!!
https://clojurians.slack.com/archives/C0185BFLLSE/p1680283906008079 was a previous discussion