portal 2023-06-03

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

1

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

πŸ’― 1

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

πŸ‘ 1

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

there we go, works with css

πŸš€ 1

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:

πŸ’― 9
2
πŸ™‡β€β™‚οΈ 1
πŸ™‡πŸ»β€β™‚οΈ 1
πŸŽ‰ 1

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

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

πŸ‘ 1