portal

Sam Ritchie 2023-06-03T16:31:51.730329Z

@djblue does a LaTeX viewer exist yet, using https://katex.org/ or mathjax?

djblue 2023-06-03T18:12:25.934549Z

Not that I am aware of

djblue 2023-06-03T21:39:26.898799Z

Is this something you are interested in building?

Sam Ritchie 2023-06-03T21:54:22.080829Z

Yeah I’m going to give it a go and see if I can get something basic working

djblue 2023-06-03T21:55:17.912079Z

Awesome! Let me know if you run into any issues πŸ‘

Sam Ritchie 2023-06-03T22:13:58.140079Z

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))

1
djblue 2023-06-03T22:15:50.462459Z

I think an issue you might run into is that strings don't support metadata πŸ€”

Sam Ritchie 2023-06-03T22:16:26.572629Z

yes for sure

Sam Ritchie 2023-06-03T22:16:58.502819Z

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

πŸ’― 1
Sam Ritchie 2023-06-03T22:17:38.143669Z

Sam Ritchie 2023-06-03T22:17:42.577629Z

that works but weirdly keeps the original text in there too

djblue 2023-06-03T22:18:11.204639Z

Any errors in the console?

Sam Ritchie 2023-06-03T22:19:05.188409Z

I bet I’m missing some CSS like last time

πŸ‘ 1
Sam Ritchie 2023-06-03T22:19:17.020149Z

Sam Ritchie 2023-06-03T22:19:37.479429Z

no errors, but the second form is katex-html and has that aria-hidden true flag

Sam Ritchie 2023-06-03T22:21:34.101949Z

Sam Ritchie 2023-06-03T22:21:35.879609Z

there we go, works with css

πŸš€ 1
djblue 2023-06-03T22:23:39.206179Z

I'm really happy the npm integration is just working awesome

Sam Ritchie 2023-06-03T22:26:23.390959Z

it’s amazing

Sam Ritchie 2023-06-03T22:26:44.316849Z

so either we require npm install katex here or inject the JS into the header

djblue 2023-06-03T22:29:53.852269Z

Are you saying for downstream users?

Sam Ritchie 2023-06-03T22:30:53.421329Z

Yeah that’s right

djblue 2023-06-03T22:38:22.770949Z

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

djblue 2023-06-03T22:40:09.655949Z

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

djblue 2023-06-03T22:43:36.178929Z

For example here is Portal hosting (via sci) another completely unrelated project I did πŸ˜†

Sam Ritchie 2023-06-03T22:47:19.167409Z

portal as a TeX REPL:

πŸ’― 9
2
πŸ™‡β€β™‚οΈ 1
πŸ™‡πŸ»β€β™‚οΈ 1
πŸŽ‰ 1
Sam Ritchie 2023-06-03T22:48:02.226429Z

@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?

djblue 2023-06-03T22:49:43.053129Z

Currently, the easiest place to do something like this is via a custom submit function. Does that type live on the jvm or js?

Sam Ritchie 2023-06-03T22:49:49.833419Z

on the JVM

Sam Ritchie 2023-06-03T22:50:07.798279Z

will custom submit cause problems for something like Clojure Notebooks?

djblue 2023-06-03T22:51:18.695689Z

Yeah, this wouldn't work with clojure notebooks. However, I'm open to adding extension points, just not sure what they are yet.

Sam Ritchie 2023-06-03T22:51:22.416139Z

I guess by β€œcause problems” I mean, is there a way to specify that clojure notebooks should use my custom submit function

Sam Ritchie 2023-06-03T22:51:25.153319Z

πŸ‘

Sam Ritchie 2023-06-03T22:52:06.822009Z

I guess we want something like middleware on the JVM side

Sam Ritchie 2023-06-03T22:52:22.481719Z

I’ve got to run for now but this was great, and so easy to add!!

πŸ‘ 1
djblue 2023-06-03T22:52:30.570969Z

https://clojurians.slack.com/archives/C0185BFLLSE/p1680283906008079 was a previous discussion